Merge "Wi-Fi panel doesn't need to check permission" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0077129094
@@ -624,4 +624,10 @@
|
||||
|
||||
<!-- Whether to enable the advanced vpn feature. The default is not to. -->
|
||||
<bool name="config_advanced_vpn_enabled">false</bool>
|
||||
|
||||
<!-- An array of uid name for which packages exempt from Wi-Fi permission check. -->
|
||||
<string-array name="config_exempt_wifi_permission_uid_name" translatable="false">
|
||||
<item>@string/config_settingsintelligence_package_name</item>
|
||||
<item>android.uid.system:1000</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@@ -109,7 +109,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
|
||||
// If external calling package doesn't have Wi-Fi permission.
|
||||
final boolean isPermissionGranted =
|
||||
Utils.isSettingsIntelligence(mContext) || isPermissionGranted(mContext);
|
||||
isCallerExemptUid(mContext) || isPermissionGranted(mContext);
|
||||
ListBuilder listBuilder = getListBuilder(isWifiEnabled, null /* wifiSliceItem */,
|
||||
isPermissionGranted);
|
||||
// If the caller doesn't have the permission granted, just return a slice without a toggle.
|
||||
@@ -156,6 +156,21 @@ public class WifiSlice implements CustomSliceable {
|
||||
return userManager.isGuestUser();
|
||||
}
|
||||
|
||||
private boolean isCallerExemptUid(Context context) {
|
||||
final String[] allowedUidNames = context.getResources().getStringArray(
|
||||
R.array.config_exempt_wifi_permission_uid_name);
|
||||
final String uidName =
|
||||
context.getPackageManager().getNameForUid(Binder.getCallingUid());
|
||||
Log.d(TAG, "calling uid name : " + uidName);
|
||||
|
||||
for (String allowedUidName : allowedUidNames) {
|
||||
if (TextUtils.equals(uidName, allowedUidName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isPermissionGranted(Context settingsContext) {
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
final String callingPackage = settingsContext.getPackageManager()
|
||||
|
@@ -103,6 +103,7 @@ public class ContextualWifiSliceTest {
|
||||
mContext.getString(R.string.config_settingsintelligence_package_name);
|
||||
ShadowBinder.setCallingUid(1);
|
||||
when(mPackageManager.getPackagesForUid(1)).thenReturn(new String[]{siPackageName});
|
||||
when(mPackageManager.getNameForUid(1)).thenReturn(siPackageName);
|
||||
ShadowWifiSlice.setWifiPermissible(true);
|
||||
mWifiSlice = new ContextualWifiSlice(mContext);
|
||||
}
|
||||
|
@@ -114,6 +114,7 @@ public class WifiSliceTest {
|
||||
mSIPackageName = mContext.getString(R.string.config_settingsintelligence_package_name);
|
||||
ShadowBinder.setCallingUid(USER_ID);
|
||||
when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{mSIPackageName});
|
||||
when(mPackageManager.getNameForUid(USER_ID)).thenReturn(mSIPackageName);
|
||||
ShadowWifiSlice.setWifiPermissible(true);
|
||||
mWifiSlice = new WifiSlice(mContext, mWifiRestriction);
|
||||
}
|
||||
@@ -148,6 +149,7 @@ public class WifiSliceTest {
|
||||
@Test
|
||||
public void getWifiSlice_fromSIPackage_shouldHaveTitleAndToggle() {
|
||||
when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{mSIPackageName});
|
||||
when(mPackageManager.getNameForUid(USER_ID)).thenReturn(mSIPackageName);
|
||||
ShadowWifiSlice.setWifiPermissible(false);
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
@@ -163,6 +165,7 @@ public class WifiSliceTest {
|
||||
@Test
|
||||
public void getWifiSlice_notFromSIPackageAndWithWifiPermission_shouldHaveTitleAndToggle() {
|
||||
when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{"com.test"});
|
||||
when(mPackageManager.getNameForUid(USER_ID)).thenReturn("com.test");
|
||||
ShadowWifiSlice.setWifiPermissible(true);
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
@@ -177,6 +180,7 @@ public class WifiSliceTest {
|
||||
@Test
|
||||
public void getWifiSlice_notFromSIPackageAndWithoutWifiPermission_shouldReturnNoToggle() {
|
||||
when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{"com.test"});
|
||||
when(mPackageManager.getNameForUid(USER_ID)).thenReturn("com.test");
|
||||
ShadowWifiSlice.setWifiPermissible(false);
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
Reference in New Issue
Block a user