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

Commit 648d7dff authored by William Escande's avatar William Escande
Browse files

Fix legacy test to use the new Looper

We no-longer need to hack the handler and we can now use TestLooper
method

Bug: 262605980
Test: atest ServiceBluetoothTests
Change-Id: I400a8baaaf0a5d49ad243eb3c80ce2a96a24133c
parent ec058650
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2731,7 +2731,7 @@ class BluetoothManagerService {
    }

    private void sendDisableMsg(int reason, String packageName) {
        BluetoothServerProxy.getInstance().handlerSendWhatMessage(mHandler, MESSAGE_DISABLE);
        mHandler.sendEmptyMessage(MESSAGE_DISABLE);
        addActiveLog(reason, packageName, false);
    }

+0 −4
Original line number Diff line number Diff line
@@ -67,8 +67,4 @@ class BluetoothServerProxy {
    int getBluetoothPersistedState(ContentResolver resolver, int defaultValue) {
        return Settings.Global.getInt(resolver, Settings.Global.BLUETOOTH_ON, defaultValue);
    }

    boolean handlerSendWhatMessage(BluetoothManagerService.BluetoothHandler handler, int what) {
        return handler.sendMessage(handler.obtainMessage(what));
    }
}
+1 −5
Original line number Diff line number Diff line
@@ -182,17 +182,13 @@ public class BluetoothManagerServiceTest {
                .hasUserRestrictionForUser(eq(UserManager.DISALLOW_BLUETOOTH_SHARING), any());

        // Check if disable message sent once for system user only
        // Since Message object is recycled after processed, use proxy function to get what value

        // test run on user -1, should not turning Bluetooth off
        mManagerService.onUserRestrictionsChanged(UserHandle.CURRENT);
        verify(mBluetoothServerProxy, times(0))
                .handlerSendWhatMessage(any(), eq(BluetoothManagerService.MESSAGE_DISABLE));
        assertThat(mLooper.nextMessage()).isNull();

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