Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98f05dd5 authored by Yi Jiang's avatar Yi Jiang Committed by android-build-merger
Browse files

Merge "Merge "Add user-switching observer to AttentionDetector" into qt-dev...

Merge "Merge "Add user-switching observer to AttentionDetector" into qt-dev am: 58280191" into qt-dev-plus-aosp
am: bd51fabf

Change-Id: Ieacff918d2d01240e06aa49dcc70c3f560ddf5ee
parents 167ed8cb bd51fabf
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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);
        }
    }
}