diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-04-26 23:52:05 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-04-26 23:52:05 +0000 |
commit | 4f896dcee93f4054ad505f3f70aadd530a68455c (patch) | |
tree | 48042713a104fe757ac54642823528995a17d828 /service | |
parent | 3a7d1334697959faee0d646f9ba22cdf38d592ba (diff) | |
parent | 9d0e9a553a93a76b1a5590a85f065b1175af933e (diff) |
Merge "ScanRequestProxy: Clear scan request timestamps on app removal" into pi-dev
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/ScanRequestProxy.java | 37 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 4 |
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 646fa5858..0a9a446ab 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 + ", " @@ -401,4 +410,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); |