Fix #29073394: Need to bind to scorer after user is unlocked.
Scoring apps aren't required to be encryption aware so they may not be discovered and bound to when the PM is queried during bootup. To fix this we perform discovery after ACTION_USER_UNLOCKED is seen. BUG: 29073394 Change-Id: Ic423f3f06f42932724e5f7cc53ede3be1c4f2f13
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user