summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-03-30 11:24:41 -0700
committerRoshan Pius <rpius@google.com>2018-04-26 10:46:01 -0700
commit9d0e9a553a93a76b1a5590a85f065b1175af933e (patch)
treee21def289813a9d37e8c1885c22b3c5bad9997c5 /service
parentdc30605b09e3fa6e4753a2f5388bdc3f2f31914a (diff)
ScanRequestProxy: Clear scan request timestamps on app removal
Ensure we cleanup any scan request timestamps stored on removal of the app. Note: Apps have the same package name across multiple users, but they have different UID's allocated. So, modify the timestamps cache in ScanRequestProxy to store both the package name and the uid. Bug: 77588735 Test: Manually Verified app removal cleans up the throttling timestamps (using the Android power team's scan app) Test: Unit tests Change-Id: I7d82d7a742ac4d0ec299adca115648f8786f96ae
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ScanRequestProxy.java37
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java4
2 files changed, 34 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/ScanRequestProxy.java b/service/java/com/android/server/wifi/ScanRequestProxy.java
index b9e48ea56..d9071bd83 100644
--- a/service/java/com/android/server/wifi/ScanRequestProxy.java
+++ b/service/java/com/android/server/wifi/ScanRequestProxy.java
@@ -16,6 +16,7 @@
package com.android.server.wifi;
+import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.Context;
@@ -28,6 +29,7 @@ import android.os.UserHandle;
import android.os.WorkSource;
import android.util.ArrayMap;
import android.util.Log;
+import android.util.Pair;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.util.WifiPermissionsUtil;
@@ -90,7 +92,10 @@ public class ScanRequestProxy {
// Timestamps for the last scan requested by any background app.
private long mLastScanTimestampForBgApps = 0;
// Timestamps for the list of last few scan requests by each foreground app.
- private final ArrayMap<String, LinkedList<Long>> mLastScanTimestampsForFgApps = new ArrayMap();
+ // Keys in the map = Pair<Uid, PackageName> of the app.
+ // Values in the map = List of the last few scan request timestamps from the app.
+ private final ArrayMap<Pair<Integer, String>, LinkedList<Long>> mLastScanTimestampsForFgApps =
+ new ArrayMap();
// Scan results cached from the last full single scan request.
private final List<ScanResult> mLastScanResults = new ArrayList<>();
// Common scan listener for scan requests.
@@ -246,11 +251,14 @@ public class ScanRequestProxy {
}
}
- private LinkedList<Long> getOrCreateScanRequestTimestampsForForegroundApp(String packageName) {
- LinkedList<Long> scanRequestTimestamps = mLastScanTimestampsForFgApps.get(packageName);
+ private LinkedList<Long> getOrCreateScanRequestTimestampsForForegroundApp(
+ int callingUid, String packageName) {
+ Pair<Integer, String> uidAndPackageNamePair = Pair.create(callingUid, packageName);
+ LinkedList<Long> scanRequestTimestamps =
+ mLastScanTimestampsForFgApps.get(uidAndPackageNamePair);
if (scanRequestTimestamps == null) {
scanRequestTimestamps = new LinkedList<>();
- mLastScanTimestampsForFgApps.put(packageName, scanRequestTimestamps);
+ mLastScanTimestampsForFgApps.put(uidAndPackageNamePair, scanRequestTimestamps);
}
return scanRequestTimestamps;
}
@@ -261,9 +269,10 @@ public class ScanRequestProxy {
* The throttle limit allows a max of {@link #SCAN_REQUEST_THROTTLE_MAX_IN_TIME_WINDOW_FG_APPS}
* in {@link #SCAN_REQUEST_THROTTLE_TIME_WINDOW_FG_APPS_MS} window.
*/
- private boolean shouldScanRequestBeThrottledForForegroundApp(String packageName) {
+ private boolean shouldScanRequestBeThrottledForForegroundApp(
+ int callingUid, String packageName) {
LinkedList<Long> scanRequestTimestamps =
- getOrCreateScanRequestTimestampsForForegroundApp(packageName);
+ getOrCreateScanRequestTimestampsForForegroundApp(callingUid, packageName);
long currentTimeMillis = mClock.getElapsedSinceBootMillis();
// First evict old entries from the list.
trimPastScanRequestTimesForForegroundApp(scanRequestTimestamps, currentTimeMillis);
@@ -324,7 +333,7 @@ public class ScanRequestProxy {
mWifiMetrics.incrementExternalBackgroundAppOneshotScanRequestsThrottledCount();
}
} else {
- isThrottled = shouldScanRequestBeThrottledForForegroundApp(packageName);
+ isThrottled = shouldScanRequestBeThrottledForForegroundApp(callingUid, packageName);
if (isThrottled) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Foreground scan app request [" + callingUid + ", "
@@ -398,4 +407,18 @@ public class ScanRequestProxy {
mLastScanTimestampForBgApps = 0;
mLastScanTimestampsForFgApps.clear();
}
+
+ /**
+ * Clear any scan timestamps being stored for the app.
+ *
+ * @param uid Uid of the package.
+ * @param packageName Name of the package.
+ */
+ public void clearScanRequestTimestampsForApp(@NonNull String packageName, int uid) {
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "Clearing scan request timestamps for uid=" + uid + ", packageName="
+ + packageName);
+ }
+ mLastScanTimestampsForFgApps.remove(Pair.create(uid, packageName));
+ }
}
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index cb3628b98..3f566c355 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2449,6 +2449,10 @@ public class WifiServiceImpl extends IWifiManager.Stub {
}
String pkgName = uri.getSchemeSpecificPart();
mWifiStateMachine.removeAppConfigs(pkgName, uid);
+ // Call the method in WSM thread.
+ mWifiStateMachineHandler.post(() -> {
+ mScanRequestProxy.clearScanRequestTimestampsForApp(pkgName, uid);
+ });
}
}
}, intentFilter);