summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-08-01 16:42:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-08-01 16:42:29 +0000
commitc630bd543106df72cc22eca1fe3e58fea4107090 (patch)
tree7b16b45a42b98dd1f27ebd9a5b926104ebe67ace /service
parent6b0af0a4dfa297b7cf7c72a544f0f5120f8bc789 (diff)
parent73cf4e7594368d0bb2688867a7c055a58bf078db (diff)
Merge "ScanRequestProxy: Add a setting to toggle wifi scan throttling"
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ScanRequestProxy.java65
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
2 files changed, 64 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/ScanRequestProxy.java b/service/java/com/android/server/wifi/ScanRequestProxy.java
index 900d85095..d9bbe15ee 100644
--- a/service/java/com/android/server/wifi/ScanRequestProxy.java
+++ b/service/java/com/android/server/wifi/ScanRequestProxy.java
@@ -21,12 +21,15 @@ import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
+import android.database.ContentObserver;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiScanner;
import android.os.Binder;
+import android.os.Handler;
import android.os.UserHandle;
import android.os.WorkSource;
+import android.provider.Settings;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
@@ -82,6 +85,8 @@ public class ScanRequestProxy {
private final WifiPermissionsUtil mWifiPermissionsUtil;
private final WifiMetrics mWifiMetrics;
private final Clock mClock;
+ private final FrameworkFacade mFrameworkFacade;
+ private final ThrottleEnabledSettingObserver mThrottleEnabledSettingObserver;
private WifiScanner mWifiScanner;
// Verbose logging flag.
@@ -150,9 +155,57 @@ public class ScanRequestProxy {
}
};
+ /**
+ * Observer for scan throttle enable settings changes.
+ * This is enabled by default. Will be toggled off via adb command or a developer settings
+ * toggle by the user to disable all scan throttling.
+ */
+ private class ThrottleEnabledSettingObserver extends ContentObserver {
+ private boolean mThrottleEnabled = true;
+
+ ThrottleEnabledSettingObserver(Handler handler) {
+ super(handler);
+ }
+
+ /**
+ * Register for any changes to the scan throttle setting.
+ */
+ public void initialize() {
+ mFrameworkFacade.registerContentObserver(mContext,
+ Settings.Global.getUriFor(Settings.Global.WIFI_SCAN_THROTTLE_ENABLED),
+ true, this);
+ mThrottleEnabled = getValue();
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "Scan throttle enabled " + mThrottleEnabled);
+ }
+ }
+
+ /**
+ * Check if throttling is enabled or not.
+ *
+ * @return true if throttling is enabled, false otherwise.
+ */
+ public boolean isEnabled() {
+ return mThrottleEnabled;
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ mThrottleEnabled = getValue();
+ Log.i(TAG, "Scan throttle enabled " + mThrottleEnabled);
+ }
+
+ private boolean getValue() {
+ return mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1) == 1;
+ }
+ }
+
ScanRequestProxy(Context context, AppOpsManager appOpsManager, ActivityManager activityManager,
WifiInjector wifiInjector, WifiConfigManager configManager,
- WifiPermissionsUtil wifiPermissionUtil, WifiMetrics wifiMetrics, Clock clock) {
+ WifiPermissionsUtil wifiPermissionUtil, WifiMetrics wifiMetrics, Clock clock,
+ FrameworkFacade frameworkFacade, Handler handler) {
mContext = context;
mAppOps = appOpsManager;
mActivityManager = activityManager;
@@ -161,6 +214,8 @@ public class ScanRequestProxy {
mWifiPermissionsUtil = wifiPermissionUtil;
mWifiMetrics = wifiMetrics;
mClock = clock;
+ mFrameworkFacade = frameworkFacade;
+ mThrottleEnabledSettingObserver = new ThrottleEnabledSettingObserver(handler);
}
/**
@@ -177,6 +232,8 @@ public class ScanRequestProxy {
private boolean retrieveWifiScannerIfNecessary() {
if (mWifiScanner == null) {
mWifiScanner = mWifiInjector.getWifiScanner();
+ // Start listening for throttle settings change after we retrieve scanner instance.
+ mThrottleEnabledSettingObserver.initialize();
}
return mWifiScanner != null;
}
@@ -402,8 +459,10 @@ public class ScanRequestProxy {
boolean fromSettingsOrSetupWizard =
mWifiPermissionsUtil.checkNetworkSettingsPermission(callingUid)
|| mWifiPermissionsUtil.checkNetworkSetupWizardPermission(callingUid);
- // Check and throttle scan request from apps without NETWORK_SETTINGS permission.
- if (!fromSettingsOrSetupWizard
+ // Check and throttle scan request unless,
+ // a) App has either NETWORK_SETTINGS or NETWORK_SETUP_WIZARD permission.
+ // b) Throttling has been disabled by user.
+ if (!fromSettingsOrSetupWizard && mThrottleEnabledSettingObserver.isEnabled()
&& shouldScanRequestBeThrottledForApp(callingUid, packageName)) {
Log.i(TAG, "Scan request from " + packageName + " throttled");
sendScanResultFailureBroadcastToPackage(packageName);
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 5412a5204..ba288505e 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -253,7 +253,8 @@ public class WifiInjector {
(AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE),
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE),
this, mWifiConfigManager,
- mWifiPermissionsUtil, mWifiMetrics, mClock);
+ mWifiPermissionsUtil, mWifiMetrics, mClock, mFrameworkFacade,
+ new Handler(clientModeImplLooper));
mSarManager = new SarManager(mContext, makeTelephonyManager(), clientModeImplLooper,
mWifiNative, new SystemSensorManager(mContext, clientModeImplLooper),
mWifiMetrics);