Merge "Bluetooth: stop pairing service correctly" am: 4e32e87e57
am: b7c50119e5
am: 912c74e02e
Change-Id: Ib822796906d81baad9a4b731a057b7ae14d7a355
This commit is contained in:
@@ -80,6 +80,7 @@ public final class BluetoothPairingService extends Service {
|
|||||||
Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), Cancelled.");
|
Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), Cancelled.");
|
||||||
}
|
}
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
stopSelf();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -89,6 +90,12 @@ public final class BluetoothPairingService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
if (intent == null) {
|
||||||
|
Log.e(TAG, "Can't start: null intent!");
|
||||||
|
stopSelf();
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
Notification.Builder builder = new Notification.Builder(this)
|
Notification.Builder builder = new Notification.Builder(this)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
|
.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
|
||||||
@@ -99,6 +106,12 @@ public final class BluetoothPairingService extends Service {
|
|||||||
|
|
||||||
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
|
|
||||||
|
if (mDevice.getBondState() != BluetoothDevice.BOND_BONDING) {
|
||||||
|
Log.w(TAG, "Device " + mDevice + " not bonding: " + mDevice.getBondState());
|
||||||
|
stopSelf();
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
|
String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
|
||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name)) {
|
||||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
@@ -119,7 +132,7 @@ public final class BluetoothPairingService extends Service {
|
|||||||
registerReceiver(mCancelReceiver, filter);
|
registerReceiver(mCancelReceiver, filter);
|
||||||
|
|
||||||
startForeground(NOTIFICATION_ID, builder.getNotification());
|
startForeground(NOTIFICATION_ID, builder.getNotification());
|
||||||
return START_STICKY;
|
return START_REDELIVER_INTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user