Loading android/app/src/com/android/bluetooth/btservice/ProfileService.java +8 −9 Original line number Diff line number Diff line Loading @@ -54,10 +54,10 @@ public abstract class ProfileService extends Service { //Profile services will not be automatically restarted. //They must be explicitly restarted by AdapterService private static final int PROFILE_SERVICE_MODE = Service.START_NOT_STICKY; protected final String mName; protected BluetoothAdapter mAdapter; protected AdapterService mAdapterService; protected IProfileServiceBinder mBinder; private BluetoothAdapter mAdapter; private IProfileServiceBinder mBinder; private final String mName; private AdapterService mAdapterService; private BroadcastReceiver mUserSwitchedReceiver; private boolean mProfileStarted = false; Loading Loading @@ -208,17 +208,13 @@ public abstract class ProfileService extends Service { @Override public void onDestroy() { if (mAdapterService != null) { mAdapterService.removeProfile(this); } cleanup(); if (mBinder != null) { mBinder.cleanup(); mBinder = null; } super.onDestroy(); mAdapter = null; super.onDestroy(); } private void doStart() { Loading Loading @@ -283,6 +279,9 @@ public abstract class ProfileService extends Service { if (!stop()) { Log.e(mName, "Unable to stop profile"); } if (mAdapterService != null) { mAdapterService.removeProfile(this); } if (mUserSwitchedReceiver != null) { getApplicationContext().unregisterReceiver(mUserSwitchedReceiver); mUserSwitchedReceiver = null; Loading android/app/src/com/android/bluetooth/gatt/GattService.java +2 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,7 @@ public class GattService extends ProfileService { private final Map<Integer, List<BluetoothGattService>> mGattClientDatabases = new HashMap<>(); private BluetoothAdapter mAdapter; private AdvertiseManager mAdvertiseManager; private PeriodicScanManager mPeriodicScanManager; private ScanManager mScanManager; Loading Loading @@ -192,6 +193,7 @@ public class GattService extends ProfileService { Log.d(TAG, "start()"); } initializeNative(); mAdapter = BluetoothAdapter.getDefaultAdapter(); mAppOps = getSystemService(AppOpsManager.class); mAdvertiseManager = new AdvertiseManager(this, AdapterService.getAdapterService()); mAdvertiseManager.start(); Loading android/app/src/com/android/bluetooth/opp/BluetoothOppService.java +3 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,8 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti boolean mAcceptNewConnections; private BluetoothAdapter mAdapter; private static final String INVISIBLE = BluetoothShare.VISIBILITY + "=" + BluetoothShare.VISIBILITY_HIDDEN; Loading Loading @@ -206,6 +208,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(mBluetoothReceiver, filter); mAdapter = BluetoothAdapter.getDefaultAdapter(); synchronized (BluetoothOppService.this) { if (mAdapter == null) { Log.w(TAG, "Local BT device is not enabled"); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -188,4 +188,30 @@ public class ProfileServiceTest { profileNumber += 1; } } /** * Test: Start and stop a single profile repeatedly and verify that the profile services are * registered and unregistered accordingly. */ @Test public void testProfileServiceRegisterUnregister() throws TimeoutException { int profileNumber = 0; for (Class profile : mProfiles) { for (int i = 0; i < NUM_REPEATS; i++) { setProfileState(profile, BluetoothAdapter.STATE_ON); ArgumentCaptor<ProfileService> start = ArgumentCaptor.forClass(ProfileService.class); verify(mMockAdapterService, timeout(PROFILE_START_MILLIS).times( NUM_REPEATS * profileNumber + i + 1)).addProfile( start.capture()); setProfileState(profile, BluetoothAdapter.STATE_OFF); ArgumentCaptor<ProfileService> stop = ArgumentCaptor.forClass(ProfileService.class); verify(mMockAdapterService, timeout(PROFILE_START_MILLIS).times( NUM_REPEATS * profileNumber + i + 1)).removeProfile( stop.capture()); Assert.assertEquals(start.getValue(), stop.getValue()); } profileNumber += 1; } } } Loading
android/app/src/com/android/bluetooth/btservice/ProfileService.java +8 −9 Original line number Diff line number Diff line Loading @@ -54,10 +54,10 @@ public abstract class ProfileService extends Service { //Profile services will not be automatically restarted. //They must be explicitly restarted by AdapterService private static final int PROFILE_SERVICE_MODE = Service.START_NOT_STICKY; protected final String mName; protected BluetoothAdapter mAdapter; protected AdapterService mAdapterService; protected IProfileServiceBinder mBinder; private BluetoothAdapter mAdapter; private IProfileServiceBinder mBinder; private final String mName; private AdapterService mAdapterService; private BroadcastReceiver mUserSwitchedReceiver; private boolean mProfileStarted = false; Loading Loading @@ -208,17 +208,13 @@ public abstract class ProfileService extends Service { @Override public void onDestroy() { if (mAdapterService != null) { mAdapterService.removeProfile(this); } cleanup(); if (mBinder != null) { mBinder.cleanup(); mBinder = null; } super.onDestroy(); mAdapter = null; super.onDestroy(); } private void doStart() { Loading Loading @@ -283,6 +279,9 @@ public abstract class ProfileService extends Service { if (!stop()) { Log.e(mName, "Unable to stop profile"); } if (mAdapterService != null) { mAdapterService.removeProfile(this); } if (mUserSwitchedReceiver != null) { getApplicationContext().unregisterReceiver(mUserSwitchedReceiver); mUserSwitchedReceiver = null; Loading
android/app/src/com/android/bluetooth/gatt/GattService.java +2 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,7 @@ public class GattService extends ProfileService { private final Map<Integer, List<BluetoothGattService>> mGattClientDatabases = new HashMap<>(); private BluetoothAdapter mAdapter; private AdvertiseManager mAdvertiseManager; private PeriodicScanManager mPeriodicScanManager; private ScanManager mScanManager; Loading Loading @@ -192,6 +193,7 @@ public class GattService extends ProfileService { Log.d(TAG, "start()"); } initializeNative(); mAdapter = BluetoothAdapter.getDefaultAdapter(); mAppOps = getSystemService(AppOpsManager.class); mAdvertiseManager = new AdvertiseManager(this, AdapterService.getAdapterService()); mAdvertiseManager.start(); Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppService.java +3 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,8 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti boolean mAcceptNewConnections; private BluetoothAdapter mAdapter; private static final String INVISIBLE = BluetoothShare.VISIBILITY + "=" + BluetoothShare.VISIBILITY_HIDDEN; Loading Loading @@ -206,6 +208,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(mBluetoothReceiver, filter); mAdapter = BluetoothAdapter.getDefaultAdapter(); synchronized (BluetoothOppService.this) { if (mAdapter == null) { Log.w(TAG, "Local BT device is not enabled"); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -188,4 +188,30 @@ public class ProfileServiceTest { profileNumber += 1; } } /** * Test: Start and stop a single profile repeatedly and verify that the profile services are * registered and unregistered accordingly. */ @Test public void testProfileServiceRegisterUnregister() throws TimeoutException { int profileNumber = 0; for (Class profile : mProfiles) { for (int i = 0; i < NUM_REPEATS; i++) { setProfileState(profile, BluetoothAdapter.STATE_ON); ArgumentCaptor<ProfileService> start = ArgumentCaptor.forClass(ProfileService.class); verify(mMockAdapterService, timeout(PROFILE_START_MILLIS).times( NUM_REPEATS * profileNumber + i + 1)).addProfile( start.capture()); setProfileState(profile, BluetoothAdapter.STATE_OFF); ArgumentCaptor<ProfileService> stop = ArgumentCaptor.forClass(ProfileService.class); verify(mMockAdapterService, timeout(PROFILE_START_MILLIS).times( NUM_REPEATS * profileNumber + i + 1)).removeProfile( stop.capture()); Assert.assertEquals(start.getValue(), stop.getValue()); } profileNumber += 1; } } }