diff options
| author | 2016-06-08 14:32:42 +0000 | |
|---|---|---|
| committer | 2016-06-08 14:32:43 +0000 | |
| commit | 464f7e498365340e76a5b9dfcf2235d9c93eafc0 (patch) | |
| tree | cce19029099db0e9da2f70c0a39489df24423eaa | |
| parent | 002ccec5c104e1c7b86fbfc3af8fd9b26342ce56 (diff) | |
| parent | 967b5815fb55e25419dcfdcf2144cce513123a61 (diff) | |
Merge "Fix #29073394: Need to bind to scorer after user is unlocked." into nyc-dev
| -rw-r--r-- | services/core/java/com/android/server/NetworkScoreService.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java index 3745e0b4a1f5..83d6344c95b0 100644 --- a/services/core/java/com/android/server/NetworkScoreService.java +++ b/services/core/java/com/android/server/NetworkScoreService.java @@ -17,10 +17,12 @@ package com.android.server; import android.Manifest.permission; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.net.INetworkScoreCache; @@ -67,6 +69,20 @@ public class NetworkScoreService extends INetworkScoreService.Stub { private NetworkScorerPackageMonitor mPackageMonitor; private ScoringServiceConnection mServiceConnection; + private BroadcastReceiver mUserIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); + if (DBG) Log.d(TAG, "Received " + action + " for userId " + userId); + if (userId == UserHandle.USER_NULL) return; + + if (Intent.ACTION_USER_UNLOCKED.equals(action)) { + onUserUnlocked(userId); + } + } + }; + /** * Clears scores when the active scorer package is no longer valid and * manages the service connection. @@ -138,6 +154,11 @@ public class NetworkScoreService extends INetworkScoreService.Stub { public NetworkScoreService(Context context) { mContext = context; mScoreCaches = new HashMap<>(); + IntentFilter filter = new IntentFilter(Intent.ACTION_USER_UNLOCKED); + // TODO: Need to update when we support per-user scorers. http://b/23422763 + mContext.registerReceiverAsUser( + mUserIntentReceiver, UserHandle.SYSTEM, filter, null /* broadcastPermission*/, + null /* scheduler */); } /** Called when the system is ready to run third-party code but before it actually does so. */ @@ -164,6 +185,11 @@ public class NetworkScoreService extends INetworkScoreService.Stub { bindToScoringServiceIfNeeded(); } + private void onUserUnlocked(int userId) { + registerPackageMonitorIfNeeded(); + bindToScoringServiceIfNeeded(); + } + private void registerPackageMonitorIfNeeded() { if (DBG) Log.d(TAG, "registerPackageMonitorIfNeeded"); NetworkScorerAppData scorer = NetworkScorerAppManager.getActiveScorer(mContext); @@ -216,6 +242,8 @@ public class NetworkScoreService extends INetworkScoreService.Stub { // Make sure the connection is connected (idempotent) mServiceConnection.connect(mContext); + } else { // otherwise make sure it isn't bound. + unbindFromScoringServiceIfNeeded(); } } |