diff options
author | David Su <dysu@google.com> | 2019-10-11 19:02:07 +0000 |
---|---|---|
committer | David Su <dysu@google.com> | 2019-11-01 20:25:15 -0700 |
commit | ccffa4a350fb26d7e1a5ff96ca3825db97f5c4c9 (patch) | |
tree | 8fa8a866ce41acbd18cedbbff90eeb7d7114808d | |
parent | 26e83c9a0ebd8466285451cbd258249b149aa064 (diff) |
Accept either MAINLINE_NETWORK_STACK or NETWORK_STACK permission.
Accept both permissions until tethering has been moved to the
MAINLINE_NETWORK_STACK permission, then stop checking for
NETWORK_STACK permission.
Bug: 142372871
Test: compiles
Change-Id: I0c431e27ea6f5d46ebf9e32c283040889bd48056
Merged-In: I0c431e27ea6f5d46ebf9e32c283040889bd48056
-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 cf5dcea97..685bb479e 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; @@ -785,8 +786,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 e286e339b..a92043624 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; @@ -1127,9 +1128,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); } @@ -1150,9 +1152,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(); } |