Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +17 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; Loading Loading @@ -109,6 +110,9 @@ public class AdapterService extends Service { private static final String ACTION_ALARM_WAKEUP = "com.android.bluetooth.btservice.action.ALARM_WAKEUP"; static final String BLUETOOTH_BTSNOOP_ENABLE_PROPERTY = "persist.bluetooth.btsnoopenable"; private boolean mSnoopLogSettingAtEnable = false; public static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; public static final String BLUETOOTH_PRIVILEGED = android.Manifest.permission.BLUETOOTH_PRIVILEGED; Loading Loading @@ -598,6 +602,18 @@ public class AdapterService extends Service { } mCallbacks.finishBroadcast(); } // Turn the Adapter all the way off if we are disabling and the snoop log setting changed. if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON) { mSnoopLogSettingAtEnable = SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false); } else if (newState == BluetoothAdapter.STATE_BLE_ON && prevState != BluetoothAdapter.STATE_OFF) { boolean snoopLogSetting = SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false); if (mSnoopLogSettingAtEnable != snoopLogSetting) { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF); } } } void cleanup() { Loading Loading @@ -2429,6 +2445,7 @@ public class AdapterService extends Service { writer.println(); mAdapterProperties.dump(fd, writer, args); writer.println("mSnoopLogSettingAtEnable = " + mSnoopLogSettingAtEnable); writer.println(); mAdapterStateMachine.dump(fd, writer, args); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.os.Binder; import android.os.Looper; import android.os.PowerManager; import android.os.Process; import android.os.SystemProperties; import android.os.UserManager; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; Loading Loading @@ -409,4 +410,54 @@ public class AdapterServiceTest { Assert.assertFalse(mAdapterService.isEnabled()); } /** * Test: Toggle snoop logging setting * Check whether the AdapterService restarts fully */ @Test public void testSnoopLoggingChange() { String snoopSetting = SystemProperties.get(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, ""); SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "false"); doEnable(0, false); Assert.assertTrue(mAdapterService.isEnabled()); Assert.assertFalse( SystemProperties.getBoolean(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, true)); SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "true"); mAdapterService.disable(); verifyStateChange(BluetoothAdapter.STATE_ON, BluetoothAdapter.STATE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); // Stop PBAP and PAN verify(mMockContext, timeout(ONE_SECOND_MS).times(5)).startService(any()); mAdapterService.onProfileServiceStateChanged(mMockService, BluetoothAdapter.STATE_OFF); mAdapterService.onProfileServiceStateChanged(mMockService2, BluetoothAdapter.STATE_OFF); verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1, CONTEXT_SWITCH_MS); // Don't call onBrEdrDown(). The Adapter should turn itself off. verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); // Stop GATT verify(mMockContext, timeout(ONE_SECOND_MS).times(6)).startService(any()); mAdapterService.onProfileServiceStateChanged(mMockGattService, BluetoothAdapter.STATE_OFF); verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF, 1, CONTEXT_SWITCH_MS); Assert.assertFalse(mAdapterService.isEnabled()); // Restore earlier setting SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, snoopSetting); } } Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +17 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; Loading Loading @@ -109,6 +110,9 @@ public class AdapterService extends Service { private static final String ACTION_ALARM_WAKEUP = "com.android.bluetooth.btservice.action.ALARM_WAKEUP"; static final String BLUETOOTH_BTSNOOP_ENABLE_PROPERTY = "persist.bluetooth.btsnoopenable"; private boolean mSnoopLogSettingAtEnable = false; public static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN; public static final String BLUETOOTH_PRIVILEGED = android.Manifest.permission.BLUETOOTH_PRIVILEGED; Loading Loading @@ -598,6 +602,18 @@ public class AdapterService extends Service { } mCallbacks.finishBroadcast(); } // Turn the Adapter all the way off if we are disabling and the snoop log setting changed. if (newState == BluetoothAdapter.STATE_BLE_TURNING_ON) { mSnoopLogSettingAtEnable = SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false); } else if (newState == BluetoothAdapter.STATE_BLE_ON && prevState != BluetoothAdapter.STATE_OFF) { boolean snoopLogSetting = SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false); if (mSnoopLogSettingAtEnable != snoopLogSetting) { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF); } } } void cleanup() { Loading Loading @@ -2429,6 +2445,7 @@ public class AdapterService extends Service { writer.println(); mAdapterProperties.dump(fd, writer, args); writer.println("mSnoopLogSettingAtEnable = " + mSnoopLogSettingAtEnable); writer.println(); mAdapterStateMachine.dump(fd, writer, args); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.os.Binder; import android.os.Looper; import android.os.PowerManager; import android.os.Process; import android.os.SystemProperties; import android.os.UserManager; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; Loading Loading @@ -409,4 +410,54 @@ public class AdapterServiceTest { Assert.assertFalse(mAdapterService.isEnabled()); } /** * Test: Toggle snoop logging setting * Check whether the AdapterService restarts fully */ @Test public void testSnoopLoggingChange() { String snoopSetting = SystemProperties.get(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, ""); SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "false"); doEnable(0, false); Assert.assertTrue(mAdapterService.isEnabled()); Assert.assertFalse( SystemProperties.getBoolean(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, true)); SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, "true"); mAdapterService.disable(); verifyStateChange(BluetoothAdapter.STATE_ON, BluetoothAdapter.STATE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); // Stop PBAP and PAN verify(mMockContext, timeout(ONE_SECOND_MS).times(5)).startService(any()); mAdapterService.onProfileServiceStateChanged(mMockService, BluetoothAdapter.STATE_OFF); mAdapterService.onProfileServiceStateChanged(mMockService2, BluetoothAdapter.STATE_OFF); verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1, CONTEXT_SWITCH_MS); // Don't call onBrEdrDown(). The Adapter should turn itself off. verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1, CONTEXT_SWITCH_MS); // Stop GATT verify(mMockContext, timeout(ONE_SECOND_MS).times(6)).startService(any()); mAdapterService.onProfileServiceStateChanged(mMockGattService, BluetoothAdapter.STATE_OFF); verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF, 1, CONTEXT_SWITCH_MS); Assert.assertFalse(mAdapterService.isEnabled()); // Restore earlier setting SystemProperties.set(AdapterService.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, snoopSetting); } }