diff options
author | David Su <dysu@google.com> | 2019-11-04 16:13:35 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-11-04 16:13:35 -0800 |
commit | 38c73d1403c26982e37f420d86581e96fc8c7289 (patch) | |
tree | d2a21e4b1787ef30065bbc95e7d4f15e575a61ae | |
parent | f040130ae9ae527f59bca8def381a026023614fb (diff) | |
parent | ccffa4a350fb26d7e1a5ff96ca3825db97f5c4c9 (diff) |
Accept either MAINLINE_NETWORK_STACK or NETWORK_STACK permission.
am: ccffa4a350
Change-Id: Ib9cbd921f7ccaea4056219c535108bbb71bd1a81
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 12 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 15 |
2 files changed, 19 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 2d15af53c..bd3a520a0 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -58,6 +58,7 @@ import android.database.ContentObserver; import android.net.DhcpInfo; import android.net.DhcpResults; import android.net.Network; +import android.net.NetworkStack; import android.net.NetworkUtils; import android.net.Uri; import android.net.ip.IpClientUtil; @@ -786,8 +787,15 @@ public class WifiServiceImpl extends BaseWifiService { } private void enforceNetworkStackPermission() { - mContext.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK, - "WifiService"); + // TODO(b/142554155): Only check for MAINLINE_NETWORK_STACK permission + boolean granted = mContext.checkCallingOrSelfPermission( + android.Manifest.permission.NETWORK_STACK) + == PackageManager.PERMISSION_GRANTED; + if (granted) { + return; + } + mContext.enforceCallingOrSelfPermission( + NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, "WifiService"); } private void enforceAccessPermission() { diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 9a3bd75be..95e4869a7 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -85,6 +85,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; import android.content.res.Resources; +import android.net.NetworkStack; import android.net.Uri; import android.net.wifi.IDppCallback; import android.net.wifi.INetworkRequestMatchCallback; @@ -1209,9 +1210,10 @@ public class WifiServiceImplTest { */ @Test(expected = SecurityException.class) public void testStartSoftApWithoutPermissionThrowsException() throws Exception { - doThrow(new SecurityException()).when(mContext) - .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_STACK), - eq("WifiService")); + when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK)) + .thenReturn(PackageManager.PERMISSION_DENIED); + doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission( + eq(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK), any()); mWifiServiceImpl.startSoftAp(null); } @@ -1244,9 +1246,10 @@ public class WifiServiceImplTest { */ @Test(expected = SecurityException.class) public void testStopSoftApWithoutPermissionThrowsException() throws Exception { - doThrow(new SecurityException()).when(mContext) - .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_STACK), - eq("WifiService")); + when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK)) + .thenReturn(PackageManager.PERMISSION_DENIED); + doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission( + eq(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK), any()); mWifiServiceImpl.stopSoftAp(); } |