Merge "Add user-switching observer to AttentionDetector" into qt-dev
This commit is contained in:
@@ -19,6 +19,8 @@ package com.android.server.power;
|
||||
import static android.provider.Settings.System.ADAPTIVE_SLEEP;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.SynchronousUserSwitchObserver;
|
||||
import android.attention.AttentionManagerInternal;
|
||||
import android.attention.AttentionManagerInternal.AttentionCallbackInternal;
|
||||
import android.content.ContentResolver;
|
||||
@@ -28,6 +30,7 @@ import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManagerInternal;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
@@ -54,6 +57,8 @@ public class AttentionDetector {
|
||||
private static final String TAG = "AttentionDetector";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private boolean mIsSettingEnabled;
|
||||
|
||||
/**
|
||||
@@ -132,6 +137,7 @@ public class AttentionDetector {
|
||||
}
|
||||
|
||||
public void systemReady(Context context) {
|
||||
mContext = context;
|
||||
updateEnabledFromSettings(context);
|
||||
mPackageManager = context.getPackageManager();
|
||||
mContentResolver = context.getContentResolver();
|
||||
@@ -141,6 +147,13 @@ public class AttentionDetector {
|
||||
mMaxAttentionApiTimeoutMillis = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_attentionApiTimeout);
|
||||
|
||||
try {
|
||||
final UserSwitchObserver observer = new UserSwitchObserver();
|
||||
ActivityManager.getService().registerUserSwitchObserver(observer, TAG);
|
||||
} catch (RemoteException e) {
|
||||
// Shouldn't happen since in-process.
|
||||
}
|
||||
|
||||
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.ADAPTIVE_SLEEP),
|
||||
false, new ContentObserver(new Handler()) {
|
||||
@@ -326,4 +339,11 @@ public class AttentionDetector {
|
||||
mRequested.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
private final class UserSwitchObserver extends SynchronousUserSwitchObserver {
|
||||
@Override
|
||||
public void onUserSwitching(int newUserId) throws RemoteException {
|
||||
updateEnabledFromSettings(mContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user