Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe05349d authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I96afc0dc,Ic9e2b337

* changes:
  Run java format on BluetoothManagerServiceTest
  Clean constructor from default assigned value
parents a282d335 556eebb6
Loading
Loading
Loading
Loading
+21 −35
Original line number Diff line number Diff line
@@ -194,21 +194,24 @@ class BluetoothManagerService {

    // Locks are not provided for mName and mAddress.
    // They are accessed in handler or broadcast receiver, same thread context.
    private String mAddress;
    private String mName;
    private String mAddress = null;
    private String mName = null;
    private final ContentResolver mContentResolver;
    private final RemoteCallbackList<IBluetoothManagerCallback> mCallbacks;
    private final RemoteCallbackList<IBluetoothStateChangeCallback> mStateChangeCallbacks;
    private IBinder mBluetoothBinder;
    private final RemoteCallbackList<IBluetoothManagerCallback> mCallbacks =
            new RemoteCallbackList<IBluetoothManagerCallback>();
    private final RemoteCallbackList<IBluetoothStateChangeCallback> mStateChangeCallbacks =
            new RemoteCallbackList<IBluetoothStateChangeCallback>();
    private IBinder mBluetoothBinder = null;
    private final BluetoothServiceBinder mBinder;

    private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();

    @GuardedBy("mBluetoothLock")
    private IBluetooth mBluetooth;
    private IBluetooth mBluetooth = null;

    private IBluetoothGatt mBluetoothGatt;
    private boolean mBinding;
    private boolean mUnbinding;
    private IBluetoothGatt mBluetoothGatt = null;
    private boolean mBinding = false;
    private boolean mUnbinding = false;
    private List<Integer> mSupportedProfileList = new ArrayList<>();

    private BluetoothModeChangeHelper mBluetoothModeChangeHelper;
@@ -221,7 +224,7 @@ class BluetoothManagerService {

    // used inside handler thread
    private boolean mQuietEnable = false;
    private boolean mEnable;
    private boolean mEnable = false;
    private boolean mShutdownInProgress = false;

    private static String timeToLog(long timestamp) {
@@ -258,22 +261,23 @@ class BluetoothManagerService {

    private final LinkedList<ActiveLog> mActiveLogs = new LinkedList<>();
    private final LinkedList<Long> mCrashTimestamps = new LinkedList<>();
    private int mCrashes;
    private int mCrashes = 0;
    private long mLastEnabledTime;

    // configuration from external IBinder call which is used to
    // synchronize with broadcast receiver.
    private boolean mQuietEnableExternal;
    private boolean mEnableExternal;
    private boolean mQuietEnableExternal = false;
    private boolean mEnableExternal = false;

    // Map of apps registered to keep BLE scanning on.
    private Map<IBinder, ClientDeathRecipient> mBleApps =
            new ConcurrentHashMap<IBinder, ClientDeathRecipient>();

    private int mState;
    private final HandlerThread mBluetoothHandlerThread;
    private final BluetoothHandler mHandler;
    private int mErrorRecoveryRetryCounter;
    private int mState = BluetoothAdapter.STATE_OFF;
    private final HandlerThread mBluetoothHandlerThread =
            BluetoothServerProxy.getInstance().createHandlerThread("BluetoothManagerService");
    @VisibleForTesting private final BluetoothHandler mHandler;
    private int mErrorRecoveryRetryCounter = 0;

    private final boolean mIsHearingAidProfileSupported;

@@ -615,32 +619,14 @@ class BluetoothManagerService {
                        "UserManager system service cannot be null");

        mBinder = new BluetoothServiceBinder(this, context, mUserManager);
        mBluetoothHandlerThread = BluetoothServerProxy.getInstance()
                .createHandlerThread("BluetoothManagerService");
        mBluetoothHandlerThread.start();

        mHandler = BluetoothServerProxy.getInstance().newBluetoothHandler(
                new BluetoothHandler(mBluetoothHandlerThread.getLooper()));

        mCrashes = 0;
        mBluetooth = null;
        mBluetoothBinder = null;
        mBluetoothGatt = null;
        mBinding = false;
        mUnbinding = false;
        mEnable = false;
        mState = BluetoothAdapter.STATE_OFF;
        mQuietEnableExternal = false;
        mEnableExternal = false;
        mAddress = null;
        mName = null;
        mErrorRecoveryRetryCounter = 0;
        mContentResolver = context.getContentResolver();

        // Observe BLE scan only mode settings change.
        registerForBleScanModeChange();
        mCallbacks = new RemoteCallbackList<IBluetoothManagerCallback>();
        mStateChangeCallbacks = new RemoteCallbackList<IBluetoothStateChangeCallback>();

        mBluetoothNotificationManager = new BluetoothNotificationManager(mContext);

+34 −26
Original line number Diff line number Diff line
@@ -49,16 +49,16 @@ public class BluetoothManagerServiceTest {
    static int sTimeout = 3000;
    BluetoothManagerService mManagerService;
    Context mContext;
    @Mock
    BluetoothServerProxy mBluetoothServerProxy;
    @Mock
    BluetoothManagerService.BluetoothHandler mHandler;
    @Mock BluetoothServerProxy mBluetoothServerProxy;
    @Mock BluetoothManagerService.BluetoothHandler mHandler;
    HandlerThread mHandlerThread;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mContext = spy(new ContextWrapper(
        mContext =
                spy(
                        new ContextWrapper(
                                InstrumentationRegistry.getInstrumentation().getTargetContext()));
        mHandlerThread = new HandlerThread("BluetoothManagerServiceTest");
    }
@@ -69,8 +69,9 @@ public class BluetoothManagerServiceTest {
    }

    private void createBluetoothManagerService() {
        doReturn(mock(Intent.class)).when(mContext).registerReceiverForAllUsers(any(), any(),
                eq(null), eq(null));
        doReturn(mock(Intent.class))
                .when(mContext)
                .registerReceiverForAllUsers(any(), any(), eq(null), eq(null));
        BluetoothServerProxy.setInstanceForTesting(mBluetoothServerProxy);
        // Mock the handler to avoid handle message & to terminate the thread after
        // test
@@ -78,10 +79,12 @@ public class BluetoothManagerServiceTest {
        doReturn(mHandler).when(mBluetoothServerProxy).newBluetoothHandler(any());

        // Mock these functions so security errors won't throw
        doReturn("name").when(mBluetoothServerProxy).settingsSecureGetString(any(),
                eq(Settings.Secure.BLUETOOTH_NAME));
        doReturn("00:11:22:33:44:55").when(mBluetoothServerProxy).settingsSecureGetString(any(),
                eq(Settings.Secure.BLUETOOTH_ADDRESS));
        doReturn("name")
                .when(mBluetoothServerProxy)
                .settingsSecureGetString(any(), eq(Settings.Secure.BLUETOOTH_NAME));
        doReturn("00:11:22:33:44:55")
                .when(mBluetoothServerProxy)
                .settingsSecureGetString(any(), eq(Settings.Secure.BLUETOOTH_ADDRESS));
        mManagerService = new BluetoothManagerService(mContext);
    }

@@ -91,10 +94,12 @@ public class BluetoothManagerServiceTest {
        // Spy UserManager so we can mimic the case when restriction settings changed
        UserManager userManager = mock(UserManager.class);
        doReturn(userManager).when(mContext).getSystemService(UserManager.class);
        doReturn(true).when(userManager).hasUserRestrictionForUser(
                eq(UserManager.DISALLOW_BLUETOOTH), any());
        doReturn(false).when(userManager).hasUserRestrictionForUser(
                eq(UserManager.DISALLOW_BLUETOOTH_SHARING), any());
        doReturn(true)
                .when(userManager)
                .hasUserRestrictionForUser(eq(UserManager.DISALLOW_BLUETOOTH), any());
        doReturn(false)
                .when(userManager)
                .hasUserRestrictionForUser(eq(UserManager.DISALLOW_BLUETOOTH_SHARING), any());
        createBluetoothManagerService();

        // Check if disable message sent once for system user only
@@ -102,13 +107,13 @@ public class BluetoothManagerServiceTest {

        // test run on user -1, should not turning Bluetooth off
        mManagerService.onUserRestrictionsChanged(UserHandle.CURRENT);
        verify(mBluetoothServerProxy, timeout(sTimeout).times(0)).handlerSendWhatMessage(mHandler,
                BluetoothManagerService.MESSAGE_DISABLE);
        verify(mBluetoothServerProxy, timeout(sTimeout).times(0))
                .handlerSendWhatMessage(mHandler, BluetoothManagerService.MESSAGE_DISABLE);

        // called from SYSTEM user, should try to toggle Bluetooth off
        mManagerService.onUserRestrictionsChanged(UserHandle.SYSTEM);
        verify(mBluetoothServerProxy, timeout(sTimeout)).handlerSendWhatMessage(mHandler,
                BluetoothManagerService.MESSAGE_DISABLE);
        verify(mBluetoothServerProxy, timeout(sTimeout))
                .handlerSendWhatMessage(mHandler, BluetoothManagerService.MESSAGE_DISABLE);
    }

    @Test
@@ -117,14 +122,17 @@ public class BluetoothManagerServiceTest {
        mManagerService.setBluetoothModeChangeHelper(new BluetoothModeChangeHelper(mContext));

        // Change the apm enhancement enabled value to 0
        Settings.Global.putInt(mContext.getContentResolver(),
                "apm_enhancement_enabled", 0);
        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
                "apm_enhancement_enabled",  0)).isEqualTo(0);
        Settings.Global.putInt(mContext.getContentResolver(), "apm_enhancement_enabled", 0);
        assertThat(
                        Settings.Global.getInt(
                                mContext.getContentResolver(), "apm_enhancement_enabled", 0))
                .isEqualTo(0);

        // Confirm that apm enhancement enabled value has been updated to 1
        mManagerService.loadApmEnhancementStateFromResource();
        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
                "apm_enhancement_enabled",  0)).isEqualTo(1);
        assertThat(
                        Settings.Global.getInt(
                                mContext.getContentResolver(), "apm_enhancement_enabled", 0))
                .isEqualTo(1);
    }
}