diff options
author | Wei Wang <weiwa@google.com> | 2017-08-18 13:55:33 -0700 |
---|---|---|
committer | Wei Wang <weiwa@google.com> | 2017-08-18 16:13:36 -0700 |
commit | bd8bc092b6e2edfae44629390ac653c49047c235 (patch) | |
tree | 702d6978c328246208f6f860500114b6831afd0a | |
parent | 529bed806618e5232cad35492307796cf1165dac (diff) |
Fix Rtt unit tests failures due to permission checks.
Bug: 64819280
Test: wifi unit tests.
Change-Id: Ia52b1516f6e09c609bb26709715c7977d07119a1
-rw-r--r-- | service/java/com/android/server/wifi/RttService.java | 3 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/RttServiceTest.java | 22 |
2 files changed, 22 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/RttService.java b/service/java/com/android/server/wifi/RttService.java index 2ea94576b..b96c1862b 100644 --- a/service/java/com/android/server/wifi/RttService.java +++ b/service/java/com/android/server/wifi/RttService.java @@ -745,9 +745,6 @@ public final class RttService extends SystemService { // Returns whether the client has location permission. private boolean checkLocationPermission(ClientInfo clientInfo) { - if (clientInfo.mPackageName == null) { - return false; - } return mWifiInjector.getWifiPermissionsUtil().checkCallersLocationPermission( clientInfo.mPackageName, clientInfo.mUid); } diff --git a/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java b/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java index b2b40e226..7300cb256 100644 --- a/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/RttServiceTest.java @@ -41,6 +41,7 @@ import android.os.test.TestLooper; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.util.test.BidirectionalAsyncChannel; +import com.android.server.wifi.util.WifiPermissionsUtil; import org.junit.After; import org.junit.Before; @@ -69,6 +70,8 @@ public class RttServiceTest { WifiInjector mWifiInjector; @Mock IWificond mWificond; + @Mock + WifiPermissionsUtil mWifiPermissionsUtil; RttService.RttServiceImpl mRttServiceImpl; ArgumentCaptor<BroadcastReceiver> mBroadcastReceiverCaptor = ArgumentCaptor @@ -80,6 +83,9 @@ public class RttServiceTest { mLooper = new TestLooper(); when(mWifiInjector.makeWificond()).thenReturn(mWificond); when(mWifiInjector.getWifiNative()).thenReturn(mWifiNative); + when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil); + when(mWifiPermissionsUtil.checkCallersLocationPermission(any(), anyInt())) + .thenReturn(true); mRttServiceImpl = new RttService.RttServiceImpl(mContext, mLooper.getLooper(), mWifiInjector); mRttServiceImpl.startService(); @@ -271,6 +277,22 @@ public class RttServiceTest { } /** + * Test RTT fails without proper location permission + */ + @Test + public void testEnableResponderFailureNoPermission() throws Exception { + when(mWifiPermissionsUtil.checkCallersLocationPermission(any(), anyInt())) + .thenReturn(false); + startWifi(); + Handler handler = mock(Handler.class); + BidirectionalAsyncChannel channel = connectChannel(handler); + Message message = sendEnableResponder(channel, handler, CLIENT_KEY1, null); + // RTT operations failed without proper permission. + assertEquals("expected permission denied, but got " + message.what, + RttManager.REASON_PERMISSION_DENIED, message.arg1); + } + + /** * Test RTT ranging with empty RttParams. */ @Test |