package com.ubtrobot.jimu.bluetooth.view; import android.app.Activity; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.util.Log; import com.ubtrobot.jimu.bluetooth.ConnectionState; import com.ubtrobot.jimu.bluetooth.ConnectionStateListener; import com.ubtrobot.jimu.bluetooth.JimuBluetoothManager; import com.ubtrobot.jimu.bluetooth.base.BluetoothLib; import com.ubtrobot.log.ALog; import java.util.Timer; import java.util.TimerTask; /* loaded from: classes2.dex */ public class BluetoothActivity extends Activity { private static final String e = BluetoothActivity.class.getSimpleName(); private Timer a = new Timer(); private String b = null; private ConnectionStateListener c = new ConnectionStateListener() { // from class: com.ubtrobot.jimu.bluetooth.view.BluetoothActivity.2 @Override // com.ubtrobot.jimu.bluetooth.ConnectionStateListener public void onConnectionStateChange(String str, ConnectionState connectionState) { ALog.a(BluetoothActivity.e).d(str + "Bluetooth state changed, new ConnectionState:" + connectionState); if (str == null) { return; } if (connectionState == ConnectionState.STATE_CONNECTED || connectionState == ConnectionState.STATE_DISCONNECTED) { BluetoothActivity.this.finish(); } } }; private final BroadcastReceiver d = new BroadcastReceiver() { // from class: com.ubtrobot.jimu.bluetooth.view.BluetoothActivity.3 @Override // android.content.BroadcastReceiver public void onReceive(Context context, Intent intent) { char c; String action = intent.getAction(); ALog.a(BluetoothActivity.e).d("Receive bluetooth broadcast action: " + action); int hashCode = action.hashCode(); if (hashCode != -223687943) { if (hashCode == 2116862345 && action.equals("android.bluetooth.device.action.BOND_STATE_CHANGED")) { c = 0; } c = 65535; } else { if (action.equals("android.bluetooth.device.action.PAIRING_REQUEST")) { c = 1; } c = 65535; } if (c != 0) { return; } BluetoothDevice bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"); Log.w(BluetoothActivity.e, "蓝牙设备的状态" + bluetoothDevice.getBondState()); switch (bluetoothDevice.getBondState()) { case 10: Log.w(BluetoothActivity.e, "取消配对"); BluetoothActivity.this.finish(); break; case 11: Log.w(BluetoothActivity.e, "正在配对......"); break; case 12: Log.w(BluetoothActivity.e, "完成配对"); BluetoothActivity.this.finish(); break; } } }; @Override // android.app.Activity public void onCreate(Bundle bundle) { ALog.a(e).d("===== onCreate ======= "); super.onCreate(bundle); String stringExtra = getIntent().getStringExtra("MacAddr"); if (stringExtra != null) { ALog.a(e).d("Bluetooth connect " + stringExtra); BluetoothLib.d().a(stringExtra); this.b = stringExtra; JimuBluetoothManager.d().a(this.c); this.a.schedule(new TimerTask() { // from class: com.ubtrobot.jimu.bluetooth.view.BluetoothActivity.1 @Override // java.util.TimerTask, java.lang.Runnable public void run() { Log.i(BluetoothActivity.e, "Timeout and finish BluetoothActivity!"); BluetoothActivity.this.finish(); } }, 15000L); } else { finish(); } IntentFilter intentFilter = new IntentFilter("android.bluetooth.device.action.PAIRING_REQUEST"); intentFilter.addAction("android.bluetooth.device.action.BOND_STATE_CHANGED"); intentFilter.addAction("android.bluetooth.device.action.ACL_CONNECTED"); intentFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"); intentFilter.addAction("android.bluetooth.device.action.ACL_DISCONNECTED"); intentFilter.addAction("android.bluetooth.adapter.action.STATE_CHANGED"); intentFilter.addAction("android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED"); registerReceiver(this.d, intentFilter); } @Override // android.app.Activity public void onDestroy() { ALog.a(e).d("======= onDestroy ========"); if (this.b != null) { JimuBluetoothManager.d().b(this.c); } unregisterReceiver(this.d); this.a.cancel(); super.onDestroy(); } @Override // android.app.Activity public void onResume() { ALog.a(e).d("===== onResume ======= "); super.onResume(); } }