diff options
-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 |