Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +16 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ public class AdapterService extends Service { private long mEnergyUsedTotalVoltAmpSecMicro; private final SparseArray<UidTraffic> mUidTraffic = new SparseArray<>(); private final ArrayList<String> mStartedProfiles = new ArrayList<>(); private final ArrayList<ProfileService> mRegisteredProfiles = new ArrayList<>(); private final ArrayList<ProfileService> mRunningProfiles = new ArrayList<>(); Loading Loading @@ -305,6 +306,16 @@ public class AdapterService extends Service { mHandler.sendMessage(m); } /** * Confirm whether the ProfileService is started expectedly. * * @param string the service simple name. * @return true if the service is started expectedly, false otherwise. */ public boolean isStartedProfile(String serviceSampleName) { return mStartedProfiles.contains(serviceSampleName); } private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1; private static final int MESSAGE_PROFILE_SERVICE_REGISTERED = 2; private static final int MESSAGE_PROFILE_SERVICE_UNREGISTERED = 3; Loading Loading @@ -878,6 +889,11 @@ public class AdapterService extends Service { } private void setProfileServiceState(Class service, int state) { if (state == BluetoothAdapter.STATE_ON) { mStartedProfiles.add(service.getSimpleName()); } else if (state == BluetoothAdapter.STATE_OFF) { mStartedProfiles.remove(service.getSimpleName()); } Intent intent = new Intent(this, service); intent.putExtra(EXTRA_ACTION, ACTION_SERVICE_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE, state); Loading android/app/src/com/android/bluetooth/btservice/ProfileService.java +8 −0 Original line number Diff line number Diff line Loading @@ -228,6 +228,10 @@ public abstract class ProfileService extends Service { Log.w(mName, "Could not add this profile because AdapterService is null."); return; } if (!mAdapterService.isStartedProfile(mName)) { Log.w(mName, "Unexpectedly do Start, don't start"); return; } mAdapterService.addProfile(this); IntentFilter filter = new IntentFilter(); Loading Loading @@ -269,6 +273,10 @@ public abstract class ProfileService extends Service { } private void doStop() { if (mAdapterService == null || mAdapterService.isStartedProfile(mName)) { Log.w(mName, "Unexpectedly do Stop, don't stop."); return; } if (!mProfileStarted) { Log.w(mName, "doStop() called, but the profile is not running."); } Loading android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ public class A2dpServiceTest { TestUtils.setAdapterService(mAdapterService); doReturn(MAX_CONNECTED_AUDIO_DEVICES).when(mAdapterService).getMaxConnectedAudioDevices(); doReturn(true).when(mAdapterService).isStartedProfile(anyString()); doReturn(false).when(mAdapterService).isQuietModeEnabled(); doReturn(mDatabaseManager).when(mAdapterService).getDatabase(); Loading Loading @@ -125,6 +126,7 @@ public class A2dpServiceTest { if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_a2dp)) { return; } doReturn(false).when(mAdapterService).isStartedProfile(anyString()); stopService(); mTargetContext.unregisterReceiver(mA2dpIntentReceiver); mConnectionStateChangedQueue.clear(); Loading android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ public class A2dpSinkServiceTest { MockitoAnnotations.initMocks(this); TestUtils.setAdapterService(mAdapterService); doReturn(mDatabaseManager).when(mAdapterService).getDatabase(); doReturn(true).when(mAdapterService).isStartedProfile(anyString()); setMaxConnectedAudioDevices(1); TestUtils.startService(mServiceRule, A2dpSinkService.class); mService = A2dpSinkService.getA2dpSinkService(); Loading @@ -76,6 +77,7 @@ public class A2dpSinkServiceTest { if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_a2dp_sink)) { return; } doReturn(false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.stopService(mServiceRule, A2dpSinkService.class); mService = A2dpSinkService.getA2dpSinkService(); Assert.assertNull(mService); Loading android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ */ package com.android.bluetooth.avrcpcontroller; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; import android.bluetooth.BluetoothAdapter; import android.content.Context; Loading Loading @@ -56,6 +59,7 @@ public class AvrcpControllerServiceTest { .getBoolean(R.bool.profile_supported_avrcp_controller)); MockitoAnnotations.initMocks(this); TestUtils.setAdapterService(mAdapterService); doReturn(true).when(mAdapterService).isStartedProfile(anyString()); TestUtils.startService(mServiceRule, AvrcpControllerService.class); mService = AvrcpControllerService.getAvrcpControllerService(); Assert.assertNotNull(mService); Loading @@ -69,6 +73,7 @@ public class AvrcpControllerServiceTest { if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_avrcp_controller)) { return; } doReturn(false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.stopService(mServiceRule, AvrcpControllerService.class); mService = AvrcpControllerService.getAvrcpControllerService(); Assert.assertNull(mService); Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +16 −0 Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ public class AdapterService extends Service { private long mEnergyUsedTotalVoltAmpSecMicro; private final SparseArray<UidTraffic> mUidTraffic = new SparseArray<>(); private final ArrayList<String> mStartedProfiles = new ArrayList<>(); private final ArrayList<ProfileService> mRegisteredProfiles = new ArrayList<>(); private final ArrayList<ProfileService> mRunningProfiles = new ArrayList<>(); Loading Loading @@ -305,6 +306,16 @@ public class AdapterService extends Service { mHandler.sendMessage(m); } /** * Confirm whether the ProfileService is started expectedly. * * @param string the service simple name. * @return true if the service is started expectedly, false otherwise. */ public boolean isStartedProfile(String serviceSampleName) { return mStartedProfiles.contains(serviceSampleName); } private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1; private static final int MESSAGE_PROFILE_SERVICE_REGISTERED = 2; private static final int MESSAGE_PROFILE_SERVICE_UNREGISTERED = 3; Loading Loading @@ -878,6 +889,11 @@ public class AdapterService extends Service { } private void setProfileServiceState(Class service, int state) { if (state == BluetoothAdapter.STATE_ON) { mStartedProfiles.add(service.getSimpleName()); } else if (state == BluetoothAdapter.STATE_OFF) { mStartedProfiles.remove(service.getSimpleName()); } Intent intent = new Intent(this, service); intent.putExtra(EXTRA_ACTION, ACTION_SERVICE_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE, state); Loading
android/app/src/com/android/bluetooth/btservice/ProfileService.java +8 −0 Original line number Diff line number Diff line Loading @@ -228,6 +228,10 @@ public abstract class ProfileService extends Service { Log.w(mName, "Could not add this profile because AdapterService is null."); return; } if (!mAdapterService.isStartedProfile(mName)) { Log.w(mName, "Unexpectedly do Start, don't start"); return; } mAdapterService.addProfile(this); IntentFilter filter = new IntentFilter(); Loading Loading @@ -269,6 +273,10 @@ public abstract class ProfileService extends Service { } private void doStop() { if (mAdapterService == null || mAdapterService.isStartedProfile(mName)) { Log.w(mName, "Unexpectedly do Stop, don't stop."); return; } if (!mProfileStarted) { Log.w(mName, "doStop() called, but the profile is not running."); } Loading
android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ public class A2dpServiceTest { TestUtils.setAdapterService(mAdapterService); doReturn(MAX_CONNECTED_AUDIO_DEVICES).when(mAdapterService).getMaxConnectedAudioDevices(); doReturn(true).when(mAdapterService).isStartedProfile(anyString()); doReturn(false).when(mAdapterService).isQuietModeEnabled(); doReturn(mDatabaseManager).when(mAdapterService).getDatabase(); Loading Loading @@ -125,6 +126,7 @@ public class A2dpServiceTest { if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_a2dp)) { return; } doReturn(false).when(mAdapterService).isStartedProfile(anyString()); stopService(); mTargetContext.unregisterReceiver(mA2dpIntentReceiver); mConnectionStateChangedQueue.clear(); Loading
android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkServiceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ public class A2dpSinkServiceTest { MockitoAnnotations.initMocks(this); TestUtils.setAdapterService(mAdapterService); doReturn(mDatabaseManager).when(mAdapterService).getDatabase(); doReturn(true).when(mAdapterService).isStartedProfile(anyString()); setMaxConnectedAudioDevices(1); TestUtils.startService(mServiceRule, A2dpSinkService.class); mService = A2dpSinkService.getA2dpSinkService(); Loading @@ -76,6 +77,7 @@ public class A2dpSinkServiceTest { if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_a2dp_sink)) { return; } doReturn(false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.stopService(mServiceRule, A2dpSinkService.class); mService = A2dpSinkService.getA2dpSinkService(); Assert.assertNull(mService); Loading
android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerServiceTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ */ package com.android.bluetooth.avrcpcontroller; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; import android.bluetooth.BluetoothAdapter; import android.content.Context; Loading Loading @@ -56,6 +59,7 @@ public class AvrcpControllerServiceTest { .getBoolean(R.bool.profile_supported_avrcp_controller)); MockitoAnnotations.initMocks(this); TestUtils.setAdapterService(mAdapterService); doReturn(true).when(mAdapterService).isStartedProfile(anyString()); TestUtils.startService(mServiceRule, AvrcpControllerService.class); mService = AvrcpControllerService.getAvrcpControllerService(); Assert.assertNotNull(mService); Loading @@ -69,6 +73,7 @@ public class AvrcpControllerServiceTest { if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_avrcp_controller)) { return; } doReturn(false).when(mAdapterService).isStartedProfile(anyString()); TestUtils.stopService(mServiceRule, AvrcpControllerService.class); mService = AvrcpControllerService.getAvrcpControllerService(); Assert.assertNull(mService); Loading