Hide apps with NETWORK_SETTINGS from special wifi settings
A recent change is made in the wifi framework to allow apps with NETWORK_SETTINGS permission to bypass checks for the CHANGE_WIFI_STATE permission. Remove apps with NETWORK_SETTINGS permission from the list because turning off CHANGE_WIFI_STATE for those apps will not do anything. Bug: 78228349 Test: compile, robo test Manual test: flash go to Settings -> Apps & notifications -> Advanced -> Special app access -> Wi-Fi control Verify that the "Settings" app is no longer in the list Top right corner -> show system Verify that "System UI" is no longer in the list Change-Id: Ia430a6fb4d5dee534a03609ad1877976204935b2
This commit is contained in:
@@ -20,6 +20,7 @@ import android.Manifest;
|
|||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.settings.applications.AppStateAppOpsBridge;
|
import com.android.settings.applications.AppStateAppOpsBridge;
|
||||||
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
|
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
@@ -37,6 +38,7 @@ public class AppStateChangeWifiStateBridge extends AppStateAppOpsBridge {
|
|||||||
private static final String TAG = "AppStateChangeWifiStateBridge";
|
private static final String TAG = "AppStateChangeWifiStateBridge";
|
||||||
private static final int APP_OPS_OP_CODE = AppOpsManager.OP_CHANGE_WIFI_STATE;
|
private static final int APP_OPS_OP_CODE = AppOpsManager.OP_CHANGE_WIFI_STATE;
|
||||||
private static final String PM_CHANGE_WIFI_STATE = Manifest.permission.CHANGE_WIFI_STATE;
|
private static final String PM_CHANGE_WIFI_STATE = Manifest.permission.CHANGE_WIFI_STATE;
|
||||||
|
private static final String PM_NETWORK_SETTINGS = Manifest.permission.NETWORK_SETTINGS;
|
||||||
|
|
||||||
private static final String[] PM_PERMISSIONS = {
|
private static final String[] PM_PERMISSIONS = {
|
||||||
PM_CHANGE_WIFI_STATE
|
PM_CHANGE_WIFI_STATE
|
||||||
@@ -86,6 +88,17 @@ public class AppStateChangeWifiStateBridge extends AppStateAppOpsBridge {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WifiSettingsState wifiSettingsState = (WifiSettingsState) info.extraInfo;
|
WifiSettingsState wifiSettingsState = (WifiSettingsState) info.extraInfo;
|
||||||
|
if (wifiSettingsState.packageInfo != null) {
|
||||||
|
final String[] requestedPermissions
|
||||||
|
= wifiSettingsState.packageInfo.requestedPermissions;
|
||||||
|
if (ArrayUtils.contains(requestedPermissions, PM_NETWORK_SETTINGS)) {
|
||||||
|
/*
|
||||||
|
* NETWORK_SETTINGS permission trumps CHANGE_WIFI_CONFIG, so remove this from
|
||||||
|
* the list.
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return wifiSettingsState.permissionDeclared;
|
return wifiSettingsState.permissionDeclared;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -16,6 +16,10 @@
|
|||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.Manifest;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||||
@@ -66,4 +70,14 @@ public class AppStateChangeWifiStateBridgeTest {
|
|||||||
mEntry.extraInfo = mState;
|
mEntry.extraInfo = mState;
|
||||||
assertThat(mFilter.filterApp(mEntry)).isFalse();
|
assertThat(mFilter.filterApp(mEntry)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFilterApp_networkSettingsGranted_returnFalse() {
|
||||||
|
mState.permissionDeclared = true;
|
||||||
|
mState.packageInfo = mock(PackageInfo.class);
|
||||||
|
mState.packageInfo.requestedPermissions
|
||||||
|
= new String[]{ Manifest.permission.NETWORK_SETTINGS };
|
||||||
|
mEntry.extraInfo = mState;
|
||||||
|
assertThat(mFilter.filterApp(mEntry)).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user