Loading services/tests/vibrator/src/com/android/server/vibrator/VibratorControlServiceTest.java +8 −6 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ public class VibratorControlServiceTest { @Mock private PackageManagerInternal mPackageManagerInternalMock; private TestLooper mTestLooper; private FakeVibratorController mFakeVibratorController; private VibratorControlService mVibratorControlService; private VibrationSettings mVibrationSettings; Loading @@ -74,6 +75,7 @@ public class VibratorControlServiceTest { @Before public void setUp() throws Exception { mTestLooper = new TestLooper(); when(mPackageManagerInternalMock.getSystemUiServiceComponent()) .thenReturn(new ComponentName("", "")); LocalServices.removeServiceForTest(PackageManagerInternal.class); Loading @@ -83,7 +85,7 @@ public class VibratorControlServiceTest { mVibrationSettings = new VibrationSettings( ApplicationProvider.getApplicationContext(), new Handler(testLooper.getLooper())); mFakeVibratorController = new FakeVibratorController(); mFakeVibratorController = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControlService = new VibratorControlService(new VibratorControllerHolder(), mMockVibrationScaler, mVibrationSettings, mLock); } Loading @@ -108,13 +110,13 @@ public class VibratorControlServiceTest { @Test public void testUnregisterVibratorController_providingAnInvalidController_ignoresRequest() throws RemoteException { FakeVibratorController fakeController1 = new FakeVibratorController(); FakeVibratorController fakeController2 = new FakeVibratorController(); mVibratorControlService.registerVibratorController(fakeController1); mVibratorControlService.unregisterVibratorController(fakeController2); FakeVibratorController controller1 = new FakeVibratorController(mTestLooper.getLooper()); FakeVibratorController controller2 = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControlService.registerVibratorController(controller1); mVibratorControlService.unregisterVibratorController(controller2); verifyZeroInteractions(mMockVibrationScaler); assertThat(fakeController1.isLinkedToDeath).isTrue(); assertThat(controller1.isLinkedToDeath).isTrue(); } @Test Loading services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerHolderTest.java +11 −10 Original line number Diff line number Diff line Loading @@ -18,23 +18,26 @@ package com.android.server.vibrator; import static com.google.common.truth.Truth.assertThat; import android.os.RemoteException; import android.os.test.TestLooper; import org.junit.Before; import org.junit.Test; public class VibratorControllerHolderTest { private final FakeVibratorController mFakeVibratorController = new FakeVibratorController(); private TestLooper mTestLooper; private FakeVibratorController mFakeVibratorController; private VibratorControllerHolder mVibratorControllerHolder; @Before public void setUp() throws Exception { mTestLooper = new TestLooper(); mFakeVibratorController = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControllerHolder = new VibratorControllerHolder(); } @Test public void testSetVibratorController_linksVibratorControllerToDeath() throws RemoteException { public void testSetVibratorController_linksVibratorControllerToDeath() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); assertThat(mVibratorControllerHolder.getVibratorController()) .isEqualTo(mFakeVibratorController); Loading @@ -42,8 +45,7 @@ public class VibratorControllerHolderTest { } @Test public void testSetVibratorController_setControllerToNull_unlinksVibratorControllerToDeath() throws RemoteException { public void testSetVibratorController_setControllerToNull_unlinksVibratorControllerToDeath() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); mVibratorControllerHolder.setVibratorController(null); assertThat(mFakeVibratorController.isLinkedToDeath).isFalse(); Loading @@ -51,8 +53,7 @@ public class VibratorControllerHolderTest { } @Test public void testBinderDied_withValidController_unlinksVibratorControllerToDeath() throws RemoteException { public void testBinderDied_withValidController_unlinksVibratorControllerToDeath() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); mVibratorControllerHolder.binderDied(mFakeVibratorController); assertThat(mFakeVibratorController.isLinkedToDeath).isFalse(); Loading @@ -60,10 +61,10 @@ public class VibratorControllerHolderTest { } @Test public void testBinderDied_withInvalidController_ignoresRequest() throws RemoteException { public void testBinderDied_withInvalidController_ignoresRequest() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); FakeVibratorController imposterVibratorController = new FakeVibratorController(); FakeVibratorController imposterVibratorController = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControllerHolder.binderDied(imposterVibratorController); assertThat(mFakeVibratorController.isLinkedToDeath).isTrue(); assertThat(mVibratorControllerHolder.getVibratorController()) Loading services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java +115 −109 File changed.Preview size limit exceeded, changes collapsed. Show changes services/tests/vibrator/utils/com/android/server/vibrator/FakeVibratorController.java +29 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,10 @@ package com.android.server.vibrator; import android.annotation.NonNull; import android.frameworks.vibrator.IVibratorController; import android.frameworks.vibrator.VibrationParam; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.os.VibrationAttributes; Loading @@ -28,17 +31,42 @@ import android.os.VibrationAttributes; */ public final class FakeVibratorController extends IVibratorController.Stub { private final Handler mHandler; private VibratorControlService mVibratorControlService; private VibrationParam[] mRequestResult = new VibrationParam[0]; public boolean isLinkedToDeath = false; public boolean didRequestVibrationParams = false; public int requestVibrationType = VibrationAttributes.USAGE_UNKNOWN; public long requestTimeoutInMillis = 0; public FakeVibratorController(Looper looper) { mHandler = new Handler(looper); } public void setVibratorControlService(VibratorControlService service) { mVibratorControlService = service; } public void setRequestResult(VibrationParam... params) { mRequestResult = params; } @Override public void requestVibrationParams(int vibrationType, long timeoutInMillis, IBinder iBinder) public void requestVibrationParams(int vibrationType, long timeoutInMillis, IBinder token) throws RemoteException { didRequestVibrationParams = true; requestVibrationType = vibrationType; requestTimeoutInMillis = timeoutInMillis; mHandler.post(() -> { if (mVibratorControlService != null) { try { mVibratorControlService.onRequestVibrationParamsComplete(token, mRequestResult); } catch (RemoteException e) { throw new RuntimeException(e); } } }); } @Override Loading Loading
services/tests/vibrator/src/com/android/server/vibrator/VibratorControlServiceTest.java +8 −6 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ public class VibratorControlServiceTest { @Mock private PackageManagerInternal mPackageManagerInternalMock; private TestLooper mTestLooper; private FakeVibratorController mFakeVibratorController; private VibratorControlService mVibratorControlService; private VibrationSettings mVibrationSettings; Loading @@ -74,6 +75,7 @@ public class VibratorControlServiceTest { @Before public void setUp() throws Exception { mTestLooper = new TestLooper(); when(mPackageManagerInternalMock.getSystemUiServiceComponent()) .thenReturn(new ComponentName("", "")); LocalServices.removeServiceForTest(PackageManagerInternal.class); Loading @@ -83,7 +85,7 @@ public class VibratorControlServiceTest { mVibrationSettings = new VibrationSettings( ApplicationProvider.getApplicationContext(), new Handler(testLooper.getLooper())); mFakeVibratorController = new FakeVibratorController(); mFakeVibratorController = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControlService = new VibratorControlService(new VibratorControllerHolder(), mMockVibrationScaler, mVibrationSettings, mLock); } Loading @@ -108,13 +110,13 @@ public class VibratorControlServiceTest { @Test public void testUnregisterVibratorController_providingAnInvalidController_ignoresRequest() throws RemoteException { FakeVibratorController fakeController1 = new FakeVibratorController(); FakeVibratorController fakeController2 = new FakeVibratorController(); mVibratorControlService.registerVibratorController(fakeController1); mVibratorControlService.unregisterVibratorController(fakeController2); FakeVibratorController controller1 = new FakeVibratorController(mTestLooper.getLooper()); FakeVibratorController controller2 = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControlService.registerVibratorController(controller1); mVibratorControlService.unregisterVibratorController(controller2); verifyZeroInteractions(mMockVibrationScaler); assertThat(fakeController1.isLinkedToDeath).isTrue(); assertThat(controller1.isLinkedToDeath).isTrue(); } @Test Loading
services/tests/vibrator/src/com/android/server/vibrator/VibratorControllerHolderTest.java +11 −10 Original line number Diff line number Diff line Loading @@ -18,23 +18,26 @@ package com.android.server.vibrator; import static com.google.common.truth.Truth.assertThat; import android.os.RemoteException; import android.os.test.TestLooper; import org.junit.Before; import org.junit.Test; public class VibratorControllerHolderTest { private final FakeVibratorController mFakeVibratorController = new FakeVibratorController(); private TestLooper mTestLooper; private FakeVibratorController mFakeVibratorController; private VibratorControllerHolder mVibratorControllerHolder; @Before public void setUp() throws Exception { mTestLooper = new TestLooper(); mFakeVibratorController = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControllerHolder = new VibratorControllerHolder(); } @Test public void testSetVibratorController_linksVibratorControllerToDeath() throws RemoteException { public void testSetVibratorController_linksVibratorControllerToDeath() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); assertThat(mVibratorControllerHolder.getVibratorController()) .isEqualTo(mFakeVibratorController); Loading @@ -42,8 +45,7 @@ public class VibratorControllerHolderTest { } @Test public void testSetVibratorController_setControllerToNull_unlinksVibratorControllerToDeath() throws RemoteException { public void testSetVibratorController_setControllerToNull_unlinksVibratorControllerToDeath() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); mVibratorControllerHolder.setVibratorController(null); assertThat(mFakeVibratorController.isLinkedToDeath).isFalse(); Loading @@ -51,8 +53,7 @@ public class VibratorControllerHolderTest { } @Test public void testBinderDied_withValidController_unlinksVibratorControllerToDeath() throws RemoteException { public void testBinderDied_withValidController_unlinksVibratorControllerToDeath() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); mVibratorControllerHolder.binderDied(mFakeVibratorController); assertThat(mFakeVibratorController.isLinkedToDeath).isFalse(); Loading @@ -60,10 +61,10 @@ public class VibratorControllerHolderTest { } @Test public void testBinderDied_withInvalidController_ignoresRequest() throws RemoteException { public void testBinderDied_withInvalidController_ignoresRequest() { mVibratorControllerHolder.setVibratorController(mFakeVibratorController); FakeVibratorController imposterVibratorController = new FakeVibratorController(); FakeVibratorController imposterVibratorController = new FakeVibratorController(mTestLooper.getLooper()); mVibratorControllerHolder.binderDied(imposterVibratorController); assertThat(mFakeVibratorController.isLinkedToDeath).isTrue(); assertThat(mVibratorControllerHolder.getVibratorController()) Loading
services/tests/vibrator/src/com/android/server/vibrator/VibratorManagerServiceTest.java +115 −109 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/tests/vibrator/utils/com/android/server/vibrator/FakeVibratorController.java +29 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,10 @@ package com.android.server.vibrator; import android.annotation.NonNull; import android.frameworks.vibrator.IVibratorController; import android.frameworks.vibrator.VibrationParam; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.os.VibrationAttributes; Loading @@ -28,17 +31,42 @@ import android.os.VibrationAttributes; */ public final class FakeVibratorController extends IVibratorController.Stub { private final Handler mHandler; private VibratorControlService mVibratorControlService; private VibrationParam[] mRequestResult = new VibrationParam[0]; public boolean isLinkedToDeath = false; public boolean didRequestVibrationParams = false; public int requestVibrationType = VibrationAttributes.USAGE_UNKNOWN; public long requestTimeoutInMillis = 0; public FakeVibratorController(Looper looper) { mHandler = new Handler(looper); } public void setVibratorControlService(VibratorControlService service) { mVibratorControlService = service; } public void setRequestResult(VibrationParam... params) { mRequestResult = params; } @Override public void requestVibrationParams(int vibrationType, long timeoutInMillis, IBinder iBinder) public void requestVibrationParams(int vibrationType, long timeoutInMillis, IBinder token) throws RemoteException { didRequestVibrationParams = true; requestVibrationType = vibrationType; requestTimeoutInMillis = timeoutInMillis; mHandler.post(() -> { if (mVibratorControlService != null) { try { mVibratorControlService.onRequestVibrationParamsComplete(token, mRequestResult); } catch (RemoteException e) { throw new RuntimeException(e); } } }); } @Override Loading