diff --git a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java index b557e65ddc..4948c22c3d 100644 --- a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java +++ b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java @@ -16,6 +16,7 @@ package com.android.server.thread; +import static android.Manifest.permission.ACCESS_NETWORK_STATE; import static android.net.thread.ActiveOperationalDataset.CHANNEL_PAGE_24_GHZ; import static android.net.thread.ThreadNetworkController.STATE_DISABLED; import static android.net.thread.ThreadNetworkController.STATE_ENABLED; @@ -25,7 +26,6 @@ import static android.net.thread.ThreadNetworkManager.DISALLOW_THREAD_NETWORK; import static android.net.thread.ThreadNetworkManager.PERMISSION_THREAD_NETWORK_PRIVILEGED; import static com.android.server.thread.openthread.IOtDaemon.ErrorCode.OT_ERROR_INVALID_STATE; -import static com.android.testutils.TestPermissionUtil.runAsShell; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; @@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -130,6 +131,11 @@ public final class ThreadNetworkControllerServiceTest { MockitoAnnotations.initMocks(this); mContext = spy(ApplicationProvider.getApplicationContext()); + doNothing() + .when(mContext) + .enforceCallingOrSelfPermission( + eq(PERMISSION_THREAD_NETWORK_PRIVILEGED), anyString()); + mTestLooper = new TestLooper(); final Handler handler = new Handler(mTestLooper.getLooper()); NetworkProvider networkProvider = @@ -174,9 +180,7 @@ public final class ThreadNetworkControllerServiceTest { final IOperationReceiver mockReceiver = mock(IOperationReceiver.class); mFakeOtDaemon.setJoinException(new RemoteException("ot-daemon join() throws")); - runAsShell( - PERMISSION_THREAD_NETWORK_PRIVILEGED, - () -> mService.join(DEFAULT_ACTIVE_DATASET, mockReceiver)); + mService.join(DEFAULT_ACTIVE_DATASET, mockReceiver); mTestLooper.dispatchAll(); verify(mockReceiver, never()).onSuccess(); @@ -188,9 +192,7 @@ public final class ThreadNetworkControllerServiceTest { mService.initialize(); final IOperationReceiver mockReceiver = mock(IOperationReceiver.class); - runAsShell( - PERMISSION_THREAD_NETWORK_PRIVILEGED, - () -> mService.join(DEFAULT_ACTIVE_DATASET, mockReceiver)); + mService.join(DEFAULT_ACTIVE_DATASET, mockReceiver); // Here needs to call Testlooper#dispatchAll twices because TestLooper#moveTimeForward // operates on only currently enqueued messages but the delayed message is posted from // another Handler task. @@ -274,9 +276,7 @@ public final class ThreadNetworkControllerServiceTest { mService.initialize(); CompletableFuture setEnabledFuture = new CompletableFuture<>(); - runAsShell( - PERMISSION_THREAD_NETWORK_PRIVILEGED, - () -> mService.setEnabled(true, newOperationReceiver(setEnabledFuture))); + mService.setEnabled(true, newOperationReceiver(setEnabledFuture)); mTestLooper.dispatchAll(); var thrown = assertThrows(ExecutionException.class, () -> setEnabledFuture.get());