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

Commit 76eb0a5b authored by Jeff Brown's avatar Jeff Brown Committed by Android Git Automerger
Browse files

am 6d098d40: Merge "Fix order of operations while pulsing the ambient display." into lmp-dev

* commit '6d098d406305bb6f34d48ce6035ba3920659a805':
  Fix order of operations while pulsing the ambient display.
parents 044af2d4 7858a1b5
Loading
Loading
Loading
Loading
+43 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.doze;

import android.annotation.NonNull;

/**
 * Interface the doze service uses to communicate with the rest of system UI.
 */
public interface DozeHost {
    void addCallback(@NonNull Callback callback);
    void removeCallback(@NonNull Callback callback);
    void startDozing(@NonNull Runnable ready);
    void pulseWhileDozing(@NonNull PulseCallback callback);
    void stopDozing();
    boolean isPowerSaveActive();

    public interface Callback {
        void onNewNotifications();
        void onBuzzBeepBlinked();
        void onNotificationLight(boolean on);
        void onPowerSaveChanged(boolean active);
    }

    public interface PulseCallback {
        void onPulseStarted();
        void onPulseFinished();
    }
}
 No newline at end of file
+101 −95
Original line number Original line Diff line number Diff line
@@ -27,7 +27,6 @@ import android.hardware.SensorManager;
import android.hardware.TriggerEvent;
import android.hardware.TriggerEvent;
import android.hardware.TriggerEventListener;
import android.hardware.TriggerEventListener;
import android.media.AudioAttributes;
import android.media.AudioAttributes;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager;
import android.os.Vibrator;
import android.os.Vibrator;
import android.service.dreams.DreamService;
import android.service.dreams.DreamService;
@@ -53,10 +52,9 @@ public class DozeService extends DreamService {


    private final String mTag = String.format(TAG + ".%08x", hashCode());
    private final String mTag = String.format(TAG + ".%08x", hashCode());
    private final Context mContext = this;
    private final Context mContext = this;
    private final Handler mHandler = new Handler();
    private final DozeParameters mDozeParameters = new DozeParameters(mContext);
    private final DozeParameters mDozeParameters = new DozeParameters(mContext);


    private Host mHost;
    private DozeHost mHost;
    private SensorManager mSensors;
    private SensorManager mSensors;
    private TriggerSensor mSigMotionSensor;
    private TriggerSensor mSigMotionSensor;
    private TriggerSensor mPickupSensor;
    private TriggerSensor mPickupSensor;
@@ -64,9 +62,9 @@ public class DozeService extends DreamService {
    private PowerManager.WakeLock mWakeLock;
    private PowerManager.WakeLock mWakeLock;
    private AlarmManager mAlarmManager;
    private AlarmManager mAlarmManager;
    private boolean mDreaming;
    private boolean mDreaming;
    private boolean mPulsing;
    private boolean mBroadcastReceiverRegistered;
    private boolean mBroadcastReceiverRegistered;
    private boolean mDisplayStateSupported;
    private boolean mDisplayStateSupported;
    private int mDisplayStateWhenOn;
    private boolean mNotificationLightOn;
    private boolean mNotificationLightOn;
    private boolean mPowerSaveActive;
    private boolean mPowerSaveActive;
    private long mNotificationPulseTime;
    private long mNotificationPulseTime;
@@ -81,6 +79,8 @@ public class DozeService extends DreamService {
    protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) {
    protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) {
        super.dumpOnHandler(fd, pw, args);
        super.dumpOnHandler(fd, pw, args);
        pw.print("  mDreaming: "); pw.println(mDreaming);
        pw.print("  mDreaming: "); pw.println(mDreaming);
        pw.print("  mPulsing: "); pw.println(mPulsing);
        pw.print("  mWakeLock: held="); pw.println(mWakeLock.isHeld());
        pw.print("  mHost: "); pw.println(mHost);
        pw.print("  mHost: "); pw.println(mHost);
        pw.print("  mBroadcastReceiverRegistered: "); pw.println(mBroadcastReceiverRegistered);
        pw.print("  mBroadcastReceiverRegistered: "); pw.println(mBroadcastReceiverRegistered);
        pw.print("  mSigMotionSensor: "); pw.println(mSigMotionSensor);
        pw.print("  mSigMotionSensor: "); pw.println(mSigMotionSensor);
@@ -100,7 +100,7 @@ public class DozeService extends DreamService {


        if (getApplication() instanceof SystemUIApplication) {
        if (getApplication() instanceof SystemUIApplication) {
            final SystemUIApplication app = (SystemUIApplication) getApplication();
            final SystemUIApplication app = (SystemUIApplication) getApplication();
            mHost = app.getComponent(Host.class);
            mHost = app.getComponent(DozeHost.class);
        }
        }
        if (mHost == null) Log.w(TAG, "No doze service host found.");
        if (mHost == null) Log.w(TAG, "No doze service host found.");


@@ -113,10 +113,10 @@ public class DozeService extends DreamService {
                mDozeParameters.getPulseOnPickup(), mDozeParameters.getVibrateOnPickup());
                mDozeParameters.getPulseOnPickup(), mDozeParameters.getVibrateOnPickup());
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag);
        mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag);
        mWakeLock.setReferenceCounted(true);
        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        mDisplayStateSupported = mDozeParameters.getDisplayStateSupported();
        mDisplayStateSupported = mDozeParameters.getDisplayStateSupported();
        mDisplayStateWhenOn = mDisplayStateSupported ? Display.STATE_DOZE : Display.STATE_ON;
        turnDisplayOff();
        mDisplayOff.run();
    }
    }


    @Override
    @Override
@@ -128,32 +128,39 @@ public class DozeService extends DreamService {
    @Override
    @Override
    public void onDreamingStarted() {
    public void onDreamingStarted() {
        super.onDreamingStarted();
        super.onDreamingStarted();
        mPowerSaveActive = mHost != null && mHost.isPowerSaveActive();

        if (mHost == null) {
            finish();
            return;
        }

        mPowerSaveActive = mHost.isPowerSaveActive();
        if (DEBUG) Log.d(mTag, "onDreamingStarted canDoze=" + canDoze() + " mPowerSaveActive="
        if (DEBUG) Log.d(mTag, "onDreamingStarted canDoze=" + canDoze() + " mPowerSaveActive="
                + mPowerSaveActive);
                + mPowerSaveActive);
        if (mPowerSaveActive) {
        if (mPowerSaveActive) {
            finishToSavePower();
            finishToSavePower();
            return;
            return;
        }
        }

        mDreaming = true;
        mDreaming = true;
        listenForPulseSignals(true);
        listenForPulseSignals(true);
        rescheduleNotificationPulse(false /*predicate*/);  // cancel any pending pulse alarms
        rescheduleNotificationPulse(false /*predicate*/);  // cancel any pending pulse alarms
        requestDoze();
    }


    public void stayAwake(long millis) {
        // Ask the host to get things ready to start dozing.
        if (mDreaming && millis > 0) {
        // Once ready, we call startDozing() at which point the CPU may suspend
            if (DEBUG) Log.d(mTag, "stayAwake millis=" + millis);
        // and we will need to acquire a wakelock to do work.
            mWakeLock.acquire(millis);
        mHost.startDozing(new Runnable() {
            setDozeScreenState(mDisplayStateWhenOn);
            @Override
            rescheduleOff(millis);
            public void run() {
                if (mDreaming) {
                    startDozing();

                    // From this point until onDreamingStopped we will need to hold a
                    // wakelock whenever we are doing work.  Note that we never call
                    // stopDozing because can we just keep dozing until the bitter end.
                }
                }
            }
            }

        });
    private void rescheduleOff(long millis) {
        if (DEBUG) Log.d(TAG, "rescheduleOff millis=" + millis);
        mHandler.removeCallbacks(mDisplayOff);
        mHandler.postDelayed(mDisplayOff, millis);
    }
    }


    @Override
    @Override
@@ -161,37 +168,52 @@ public class DozeService extends DreamService {
        if (DEBUG) Log.d(mTag, "onDreamingStopped isDozing=" + isDozing());
        if (DEBUG) Log.d(mTag, "onDreamingStopped isDozing=" + isDozing());
        super.onDreamingStopped();
        super.onDreamingStopped();


        mDreaming = false;
        if (mHost == null) {
        if (mWakeLock.isHeld()) {
            return;
            mWakeLock.release();
        }
        }

        mDreaming = false;
        listenForPulseSignals(false);
        listenForPulseSignals(false);
        dozingStopped();

        mHandler.removeCallbacks(mDisplayOff);
        // Tell the host that it's over.
        mHost.stopDozing();
    }
    }


    private void requestPulse() {
        if (mHost != null && mDreaming && !mPulsing) {
            // Let the host know we want to pulse.  Wait for it to be ready, then
            // turn the screen on.  When finished, turn the screen off again.
            // Here we need a wakelock to stay awake until the pulse is finished.
            mWakeLock.acquire();
            mPulsing = true;
            mHost.pulseWhileDozing(new DozeHost.PulseCallback() {
                @Override
                @Override
    public void startDozing() {
                public void onPulseStarted() {
        if (DEBUG) Log.d(mTag, "startDozing");
                    if (mPulsing && mDreaming) {
        super.startDozing();
                        turnDisplayOn();
                    }
                }
                }


    private void requestDoze() {
                @Override
        if (mHost != null) {
                public void onPulseFinished() {
            mHost.requestDoze(this);
                    if (mPulsing && mDreaming) {
                        mPulsing = false;
                        turnDisplayOff();
                        mWakeLock.release();
                    }
                    }
                }
                }

            });
    private void requestPulse() {
        if (mHost != null) {
            mHost.requestPulse(this);
        }
        }
    }
    }


    private void dozingStopped() {
    private void turnDisplayOff() {
        if (mHost != null) {
        if (DEBUG) Log.d(TAG, "Display off");
            mHost.dozingStopped(this);
        setDozeScreenState(Display.STATE_OFF);
    }
    }

    private void turnDisplayOn() {
        if (DEBUG) Log.d(TAG, "Display on");
        setDozeScreenState(mDisplayStateSupported ? Display.STATE_DOZE : Display.STATE_ON);
    }
    }


    private void finishToSavePower() {
    private void finishToSavePower() {
@@ -222,7 +244,6 @@ public class DozeService extends DreamService {
    }
    }


    private void listenForNotifications(boolean listen) {
    private void listenForNotifications(boolean listen) {
        if (mHost == null) return;
        if (listen) {
        if (listen) {
            resetNotificationResets();
            resetNotificationResets();
            mHost.addCallback(mHostCallback);
            mHost.addCallback(mHostCallback);
@@ -256,8 +277,10 @@ public class DozeService extends DreamService {


    private PendingIntent notificationPulseIntent(long instance) {
    private PendingIntent notificationPulseIntent(long instance) {
        return PendingIntent.getBroadcast(mContext, 0,
        return PendingIntent.getBroadcast(mContext, 0,
                new Intent(NOTIFICATION_PULSE_ACTION).setPackage(getPackageName())
                new Intent(NOTIFICATION_PULSE_ACTION)
                        .putExtra(EXTRA_INSTANCE, instance),
                        .setPackage(getPackageName())
                        .putExtra(EXTRA_INSTANCE, instance)
                        .setFlags(Intent.FLAG_RECEIVER_FOREGROUND),
                PendingIntent.FLAG_UPDATE_CURRENT);
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    }


@@ -304,14 +327,6 @@ public class DozeService extends DreamService {
        return sb.append(']').toString();
        return sb.append(']').toString();
    }
    }


    private final Runnable mDisplayOff = new Runnable() {
        @Override
        public void run() {
            if (DEBUG) Log.d(TAG, "Display off");
            setDozeScreenState(Display.STATE_OFF);
        }
    };

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
@@ -329,7 +344,7 @@ public class DozeService extends DreamService {
        }
        }
    };
    };


    private final Host.Callback mHostCallback = new Host.Callback() {
    private final DozeHost.Callback mHostCallback = new DozeHost.Callback() {
        @Override
        @Override
        public void onNewNotifications() {
        public void onNewNotifications() {
            if (DEBUG) Log.d(mTag, "onNewNotifications");
            if (DEBUG) Log.d(mTag, "onNewNotifications");
@@ -361,22 +376,6 @@ public class DozeService extends DreamService {
        }
        }
    };
    };


    public interface Host {
        void addCallback(Callback callback);
        void removeCallback(Callback callback);
        void requestDoze(DozeService dozeService);
        void requestPulse(DozeService dozeService);
        void dozingStopped(DozeService dozeService);
        boolean isPowerSaveActive();

        public interface Callback {
            void onNewNotifications();
            void onBuzzBeepBlinked();
            void onNotificationLight(boolean on);
            void onPowerSaveChanged(boolean active);
        }
    }

    private class TriggerSensor extends TriggerEventListener {
    private class TriggerSensor extends TriggerEventListener {
        private final Sensor mSensor;
        private final Sensor mSensor;
        private final boolean mConfigured;
        private final boolean mConfigured;
@@ -409,15 +408,19 @@ public class DozeService extends DreamService {


        @Override
        @Override
        public void onTrigger(TriggerEvent event) {
        public void onTrigger(TriggerEvent event) {
            mWakeLock.acquire();
            try {
                if (DEBUG) Log.d(mTag, "onTrigger: " + triggerEventToString(event));
                if (DEBUG) Log.d(mTag, "onTrigger: " + triggerEventToString(event));
                if (mDebugVibrate) {
                if (mDebugVibrate) {
                final Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
                    final Vibrator v = (Vibrator) mContext.getSystemService(
                            Context.VIBRATOR_SERVICE);
                    if (v != null) {
                    if (v != null) {
                        v.vibrate(1000, new AudioAttributes.Builder()
                        v.vibrate(1000, new AudioAttributes.Builder()
                                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                                .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build());
                                .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build());
                    }
                    }
                }
                }

                requestPulse();
                requestPulse();
                setListening(true);  // reregister, this sensor only fires once
                setListening(true);  // reregister, this sensor only fires once


@@ -434,6 +437,9 @@ public class DozeService extends DreamService {
                if (mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) {
                if (mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) {
                    DozeLog.tracePickupPulse(withinVibrationThreshold);
                    DozeLog.tracePickupPulse(withinVibrationThreshold);
                }
                }
            } finally {
                mWakeLock.release();
            }
        }
        }
    }
    }
}
}
+32 −45
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import static com.android.systemui.statusbar.phone.BarTransitions.MODE_WARNING;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
import android.animation.TimeInterpolator;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.IActivityManager;
@@ -117,8 +118,8 @@ import com.android.systemui.DemoMode;
import com.android.systemui.EventLogTags;
import com.android.systemui.EventLogTags;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.doze.DozeService;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.qs.QSPanel;
import com.android.systemui.qs.QSPanel;
import com.android.systemui.statusbar.ActivatableNotificationView;
import com.android.systemui.statusbar.ActivatableNotificationView;
@@ -593,7 +594,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        startKeyguard();
        startKeyguard();


        mDozeServiceHost = new DozeServiceHost();
        mDozeServiceHost = new DozeServiceHost();
        putComponent(DozeService.Host.class, mDozeServiceHost);
        putComponent(DozeHost.class, mDozeServiceHost);
        putComponent(PhoneStatusBar.class, this);
        putComponent(PhoneStatusBar.class, this);


        setControllerUsers();
        setControllerUsers();
@@ -4005,8 +4006,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    }
    }


    public void wakeUpIfDozing(long time) {
    public void wakeUpIfDozing(long time) {
        if (mDozeServiceHost != null && mDozeServiceHost.isDozing()
        if (mDozing && mScrimController.isPulsing()) {
                && mScrimController.isPulsing()) {
            PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            pm.wakeUp(time);
            pm.wakeUp(time);
        }
        }
@@ -4038,7 +4038,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
        }
    }
    }


    private final class DozeServiceHost implements DozeService.Host {
    private final class DozeServiceHost implements DozeHost {
        // Amount of time to allow to update the time shown on the screen before releasing
        // Amount of time to allow to update the time shown on the screen before releasing
        // the wakelock.  This timeout is design to compensate for the fact that we don't
        // the wakelock.  This timeout is design to compensate for the fact that we don't
        // currently have a way to know when time display contents have actually been
        // currently have a way to know when time display contents have actually been
@@ -4048,16 +4048,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
        private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
        private final H mHandler = new H();
        private final H mHandler = new H();


        private DozeService mCurrentDozeService;

        @Override
        @Override
        public String toString() {
        public String toString() {
            return "PSB.DozeServiceHost[mCallbacks=" + mCallbacks.size() + " mCurrentDozeService="
            return "PSB.DozeServiceHost[mCallbacks=" + mCallbacks.size() + "]";
                    + mCurrentDozeService + "]";
        }

        public boolean isDozing() {
            return mCurrentDozeService != null;
        }
        }


        public void firePowerSaveChanged(boolean active) {
        public void firePowerSaveChanged(boolean active) {
@@ -4085,32 +4078,28 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
        }


        @Override
        @Override
        public void addCallback(Callback callback) {
        public void addCallback(@NonNull Callback callback) {
            mCallbacks.add(callback);
            mCallbacks.add(callback);
        }
        }


        @Override
        @Override
        public void removeCallback(Callback callback) {
        public void removeCallback(@NonNull Callback callback) {
            mCallbacks.remove(callback);
            mCallbacks.remove(callback);
        }
        }


        @Override
        @Override
        public void requestDoze(DozeService dozeService) {
        public void startDozing(@NonNull Runnable ready) {
            if (dozeService == null) return;
            mHandler.obtainMessage(H.MSG_START_DOZING, ready).sendToTarget();
            mHandler.obtainMessage(H.REQUEST_DOZE, dozeService).sendToTarget();
        }
        }


        @Override
        @Override
        public void requestPulse(DozeService dozeService) {
        public void pulseWhileDozing(@NonNull PulseCallback callback) {
            if (dozeService == null) return;
            mHandler.obtainMessage(H.MSG_PULSE_WHILE_DOZING, callback).sendToTarget();
            dozeService.stayAwake(PROCESSING_TIME);
            mHandler.obtainMessage(H.REQUEST_PULSE, dozeService).sendToTarget();
        }
        }


        @Override
        @Override
        public void dozingStopped(DozeService dozeService) {
        public void stopDozing() {
            if (dozeService == null) return;
            mHandler.obtainMessage(H.MSG_STOP_DOZING).sendToTarget();
            mHandler.obtainMessage(H.DOZING_STOPPED, dozeService).sendToTarget();
        }
        }


        @Override
        @Override
@@ -4118,26 +4107,20 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            return mBatteryController != null && mBatteryController.isPowerSave();
            return mBatteryController != null && mBatteryController.isPowerSave();
        }
        }


        private void handleRequestDoze(DozeService dozeService) {
        private void handleStartDozing(@NonNull Runnable ready) {
            mCurrentDozeService = dozeService;
            if (!mDozing) {
            if (!mDozing) {
                mDozing = true;
                mDozing = true;
                DozeLog.traceDozing(mContext, mDozing);
                DozeLog.traceDozing(mContext, mDozing);
                updateDozingState();
                updateDozingState();
            }
            }
            mCurrentDozeService.startDozing();
            ready.run();
        }
        }


        private void handleRequestPulse(DozeService dozeService) {
        private void handlePulseWhileDozing(@NonNull PulseCallback callback) {
            if (!dozeService.equals(mCurrentDozeService)) return;
            mScrimController.pulse(callback);
            final long stayAwake = mScrimController.pulse();
            mCurrentDozeService.stayAwake(stayAwake);
        }
        }


        private void handleDozingStopped(DozeService dozeService) {
        private void handleStopDozing() {
            if (dozeService.equals(mCurrentDozeService)) {
                mCurrentDozeService = null;
            }
            if (mDozing) {
            if (mDozing) {
                mDozing = false;
                mDozing = false;
                DozeLog.traceDozing(mContext, mDozing);
                DozeLog.traceDozing(mContext, mDozing);
@@ -4146,18 +4129,22 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }
        }


        private final class H extends Handler {
        private final class H extends Handler {
            private static final int REQUEST_DOZE = 1;
            private static final int MSG_START_DOZING = 1;
            private static final int REQUEST_PULSE = 2;
            private static final int MSG_PULSE_WHILE_DOZING = 2;
            private static final int DOZING_STOPPED = 3;
            private static final int MSG_STOP_DOZING = 3;


            @Override
            @Override
            public void handleMessage(Message msg) {
            public void handleMessage(Message msg) {
                if (msg.what == REQUEST_DOZE) {
                switch (msg.what) {
                    handleRequestDoze((DozeService) msg.obj);
                    case MSG_START_DOZING:
                } else if (msg.what == REQUEST_PULSE) {
                        handleStartDozing((Runnable) msg.obj);
                    handleRequestPulse((DozeService) msg.obj);
                        break;
                } else if (msg.what == DOZING_STOPPED) {
                    case MSG_PULSE_WHILE_DOZING:
                    handleDozingStopped((DozeService) msg.obj);
                        handlePulseWhileDozing((PulseCallback) msg.obj);
                        break;
                    case MSG_STOP_DOZING:
                        handleStopDozing();
                        break;
                }
                }
            }
            }
        }
        }
+43 −14
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.content.Context;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Color;
import android.util.Log;
import android.util.Log;
@@ -29,6 +30,7 @@ import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.Interpolator;


import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.statusbar.BackDropView;
import com.android.systemui.statusbar.BackDropView;
import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.ScrimView;
@@ -68,7 +70,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener {
    private Runnable mOnAnimationFinished;
    private Runnable mOnAnimationFinished;
    private boolean mAnimationStarted;
    private boolean mAnimationStarted;
    private boolean mDozing;
    private boolean mDozing;
    private long mPulseEndTime;
    private DozeHost.PulseCallback mPulseCallback;
    private final Interpolator mInterpolator = new DecelerateInterpolator();
    private final Interpolator mInterpolator = new DecelerateInterpolator();
    private final Interpolator mLinearOutSlowInInterpolator;
    private final Interpolator mLinearOutSlowInInterpolator;
    private BackDropView mBackDropView;
    private BackDropView mBackDropView;
@@ -139,25 +141,48 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener {
    }
    }


    /** When dozing, fade screen contents in and out using the front scrim. */
    /** When dozing, fade screen contents in and out using the front scrim. */
    public long pulse() {
    public void pulse(@NonNull DozeHost.PulseCallback callback) {
        if (!mDozing) return 0;
        if (callback == null) {
        final long now = System.currentTimeMillis();
            throw new IllegalArgumentException("callback must not be null");
        if (DEBUG) Log.d(TAG, "pulse mPulseEndTime=" + mPulseEndTime + " now=" + now);
        }
        if (mPulseEndTime != 0 && mPulseEndTime > now) return mPulseEndTime - now;

        if (!mDozing || mPulseCallback != null) {
            // Pulse suppressed.
            mPulseCallback.onPulseFinished();
            return;
        }

        // Begin pulse.  Note that it's very important that the pulse finished callback
        // be invoked when we're done so that the caller can drop the pulse wakelock.
        mPulseCallback = callback;
        mScrimInFront.post(mPulseIn);
        mScrimInFront.post(mPulseIn);
        mPulseEndTime = now + mDozeParameters.getPulseDuration();
        return mPulseEndTime - now;
    }
    }


    public boolean isPulsing() {
    public boolean isPulsing() {
        return mDozing && mPulseEndTime != 0;
        return mPulseCallback != null;
    }
    }


    private void cancelPulsing() {
    private void cancelPulsing() {
        if (DEBUG) Log.d(TAG, "Cancel pulsing");
        if (DEBUG) Log.d(TAG, "Cancel pulsing");

        if (mPulseCallback != null) {
            mScrimInFront.removeCallbacks(mPulseIn);
            mScrimInFront.removeCallbacks(mPulseIn);
            mScrimInFront.removeCallbacks(mPulseOut);
            mScrimInFront.removeCallbacks(mPulseOut);
        mPulseEndTime = 0;
            pulseFinished();
        }
    }

    private void pulseStarted() {
        if (mPulseCallback != null) {
            mPulseCallback.onPulseStarted();
        }
    }

    private void pulseFinished() {
        if (mPulseCallback != null) {
            mPulseCallback.onPulseFinished();
            mPulseCallback = null;
        }
    }
    }


    private void scheduleUpdate() {
    private void scheduleUpdate() {
@@ -265,7 +290,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener {
        anim.setStartDelay(mAnimationDelay);
        anim.setStartDelay(mAnimationDelay);
        anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION);
        anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION);
        anim.addListener(new AnimatorListenerAdapter() {
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            @Override
            public void onAnimationEnd(Animator animation) {
            public void onAnimationEnd(Animator animation) {
                if (mOnAnimationFinished != null) {
                if (mOnAnimationFinished != null) {
@@ -309,6 +333,9 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener {
            mAnimateChange = true;
            mAnimateChange = true;
            mOnAnimationFinished = mPulseInFinished;
            mOnAnimationFinished = mPulseInFinished;
            setScrimColor(mScrimInFront, 0);
            setScrimColor(mScrimInFront, 0);

            // Signal that the pulse is ready to turn the screen on and draw.
            pulseStarted();
        }
        }
    };
    };


@@ -339,7 +366,9 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener {
        public void run() {
        public void run() {
            if (DEBUG) Log.d(TAG, "Pulse out finished");
            if (DEBUG) Log.d(TAG, "Pulse out finished");
            DozeLog.tracePulseFinish();
            DozeLog.tracePulseFinish();
            mPulseEndTime = 0;

            // Signal that the pulse is all finished so we can turn the screen off now.
            pulseFinished();
        }
        }
    };
    };