summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2016-07-26 18:32:26 -0700
committerColin Cross <ccross@android.com>2016-11-14 18:36:08 -0800
commit154bcdd91306505f3c52cffaba296384f6468427 (patch)
treee6c22fb31aa1a8ca386d40fb6464831160ce5488
parentdd7cd9cf6cdfac8253d936d28abf54fce7332d86 (diff)
Add WiFi toggle prompts - wifi
If permission review is enabled toggling WiFi on or off results in a user prompt to collect a consent. This applies only to legacy apps, i.e. ones that don't support runtime permissions as they target SDK 22. bug:28715749 Original-Change-Id: Ie60ae91bd8e9c67a3e14a2820055234f669df1df Change-Id: Id2aeae2739af3a73ef06cd092d936a4b01523ed6 (cherry picked from commit dcf967aa402a4ab1a79c727aea934b8013c1fa6a)
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java78
1 files changed, 74 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 56772e4a4..0d9f41390 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -35,6 +35,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
@@ -69,6 +70,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
+import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.SystemClock;
@@ -161,6 +163,8 @@ public class WifiServiceImpl extends IWifiManager.Stub {
private WifiPermissionsUtil mWifiPermissionsUtil;
+ private final boolean mPermissionReviewRequired;
+
/**
* Handles client connections
*/
@@ -338,6 +342,11 @@ public class WifiServiceImpl extends IWifiManager.Stub {
mWifiController = mWifiInjector.getWifiController();
mWifiBackupRestore = mWifiInjector.getWifiBackupRestore();
mWifiPermissionsUtil = mWifiInjector.getWifiPermissionsUtil();
+
+ mPermissionReviewRequired = Build.PERMISSIONS_REVIEW_REQUIRED
+ || context.getResources().getBoolean(
+ com.android.internal.R.bool.config_permissionReviewRequired);
+
enableVerboseLoggingInternal(getVerboseLoggingLevel());
}
@@ -399,7 +408,13 @@ public class WifiServiceImpl extends IWifiManager.Stub {
// If we are already disabled (could be due to airplane mode), avoid changing persist
// state here
- if (wifiEnabled) setWifiEnabled(wifiEnabled);
+ if (wifiEnabled) {
+ try {
+ setWifiEnabled(mContext.getPackageName(), wifiEnabled);
+ } catch (RemoteException e) {
+ /* ignore - local call */
+ }
+ }
}
public void handleUserSwitch(int userId) {
@@ -560,7 +575,8 @@ public class WifiServiceImpl extends IWifiManager.Stub {
* started or is already in the queue.
*/
@Override
- public synchronized boolean setWifiEnabled(boolean enable) {
+ public synchronized boolean setWifiEnabled(String packageName, boolean enable)
+ throws RemoteException {
enforceChangePermission();
Slog.d(TAG, "setWifiEnabled: " + enable + " pid=" + Binder.getCallingPid()
+ ", uid=" + Binder.getCallingUid());
@@ -569,7 +585,6 @@ public class WifiServiceImpl extends IWifiManager.Stub {
* Caller might not have WRITE_SECURE_SETTINGS,
* only CHANGE_WIFI_STATE is enforced
*/
-
long ident = Binder.clearCallingIdentity();
try {
if (! mSettingsStore.handleWifiToggled(enable)) {
@@ -580,6 +595,26 @@ public class WifiServiceImpl extends IWifiManager.Stub {
Binder.restoreCallingIdentity(ident);
}
+
+ if (mPermissionReviewRequired) {
+ final int wiFiEnabledState = getWifiEnabledState();
+ if (enable) {
+ if (wiFiEnabledState == WifiManager.WIFI_STATE_DISABLING
+ || wiFiEnabledState == WifiManager.WIFI_STATE_DISABLED) {
+ if (startConsentUiIfNeeded(packageName, Binder.getCallingUid(),
+ WifiManager.ACTION_REQUEST_ENABLE)) {
+ return true;
+ }
+ }
+ } else if (wiFiEnabledState == WifiManager.WIFI_STATE_ENABLING
+ || wiFiEnabledState == WifiManager.WIFI_STATE_ENABLED) {
+ if (startConsentUiIfNeeded(packageName, Binder.getCallingUid(),
+ WifiManager.ACTION_REQUEST_DISABLE)) {
+ return true;
+ }
+ }
+ }
+
mWifiController.sendMessage(CMD_WIFI_TOGGLED);
return true;
}
@@ -1351,6 +1386,37 @@ public class WifiServiceImpl extends IWifiManager.Stub {
}
};
+ private boolean startConsentUiIfNeeded(String packageName,
+ int callingUid, String intentAction) throws RemoteException {
+ if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) {
+ return false;
+ }
+ try {
+ // Validate the package only if we are going to use it
+ ApplicationInfo applicationInfo = mContext.getPackageManager()
+ .getApplicationInfoAsUser(packageName,
+ PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
+ UserHandle.getUserId(callingUid));
+ if (applicationInfo.uid != callingUid) {
+ throw new SecurityException("Package " + callingUid
+ + " not in uid " + callingUid);
+ }
+
+ // Legacy apps in permission review mode trigger a user prompt
+ if (applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
+ Intent intent = new Intent(intentAction);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+ intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
+ mContext.startActivity(intent);
+ return true;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new RemoteException(e.getMessage());
+ }
+ return false;
+ }
+
/**
* Observes settings changes to scan always mode.
*/
@@ -1606,7 +1672,11 @@ public class WifiServiceImpl extends IWifiManager.Stub {
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) {
// Enable wifi
- setWifiEnabled(true);
+ try {
+ setWifiEnabled(mContext.getOpPackageName(), true);
+ } catch (RemoteException e) {
+ /* ignore - local call */
+ }
// Delete all Wifi SSIDs
List<WifiConfiguration> networks = getConfiguredNetworks();
if (networks != null) {