From bd8bc092b6e2edfae44629390ac653c49047c235 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Fri, 18 Aug 2017 13:55:33 -0700 Subject: Fix Rtt unit tests failures due to permission checks. Bug: 64819280 Test: wifi unit tests. Change-Id: Ia52b1516f6e09c609bb26709715c7977d07119a1 --- .../java/com/android/server/wifi/RttService.java | 3 --- .../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 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(); @@ -270,6 +276,22 @@ public class RttServiceTest { verifyNoMoreInteractions(mWifiNative); } + /** + * 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. */ -- cgit v1.2.3