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

Commit aef19af3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Launch AoD override the settings"

parents 6ad63c39 2fc027d4
Loading
Loading
Loading
Loading
+60 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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.dock;

/**
 * Allows an app to handle dock events
 */
public interface DockManager {

    /**
     * Uninitialized / unknow dock states
     */
    int STATE_NONE = 0;
    /**
     * The state for docking
     */
    int STATE_DOCKING = 1;
    /**
     * The state for undocking
     */
    int STATE_UNDOCKING = 2;

    /**
     * Add a dock event listener into manager
     *
     * @param callback A  {@link #DockEventListener} which want to add
     */
    void addListener(DockEventListener callback);

    /**
     * Remove the added listener from dock manager
     *
     * @param callback A {@link #DockEventListener} which want to remove
     */
    void removeListener(DockEventListener callback);

    /** Callback for receiving dock events */
    interface DockEventListener {
        /**
         * Override to handle dock events
         *
         * Events reference: {@link #DockState}
         */
        void onEvent(int event);
    }
}
+144 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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.content.Context;
import android.os.Handler;
import android.util.Log;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.dock.DockManager;

import java.io.PrintWriter;

/**
 * Handles dock events for ambient state changes.
 */
public class DozeDockHandler implements DozeMachine.Part {

    private static final String TAG = "DozeDockHandler";
    private static final boolean DEBUG = DozeService.DEBUG;

    private final Context mContext;
    private final DozeMachine mMachine;
    private final DozeHost mDozeHost;
    private final AmbientDisplayConfiguration mConfig;
    private final Handler mHandler;
    private final DockEventListener mDockEventListener = new DockEventListener();
    private final DockManager mDockManager;

    private boolean mDocking;

    public DozeDockHandler(Context context, DozeMachine machine, DozeHost dozeHost,
            AmbientDisplayConfiguration config, Handler handler) {
        mContext = context;
        mMachine = machine;
        mDozeHost = dozeHost;
        mConfig = config;
        mHandler = handler;
        mDockManager = SysUiServiceProvider.getComponent(context, DockManager.class);
    }

    @Override
    public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
        switch (newState) {
            case INITIALIZED:
                mDockEventListener.register();
                break;
            case DOZE:
            case DOZE_AOD:
                mHandler.post(() -> requestPulse());
                break;
            case FINISH:
                mDockEventListener.unregister();
                break;
            default:
        }
    }

    private void requestPulse() {
        if (!mDocking || mDozeHost.isPulsingBlocked() || !canPulse()) {
            return;
        }

        mMachine.requestPulse(DozeLog.PULSE_REASON_DOCKING);
    }

    private boolean canPulse() {
        return mMachine.getState() == DozeMachine.State.DOZE
                || mMachine.getState() == DozeMachine.State.DOZE_AOD;
    }

    private void requestPulseOutNow() {
        final DozeMachine.State state = mMachine.getState();
        final int pulseReason = mMachine.getPulseReason();

        if ((state == DozeMachine.State.DOZE_PULSING
                || state == DozeMachine.State.DOZE_REQUEST_PULSE)
                && pulseReason == DozeLog.PULSE_REASON_DOCKING) {
            mDozeHost.stopPulsing();
        }
    }

    @Override
    public void dump(PrintWriter pw) {
        pw.print(" DozeDockTriggers docking="); pw.println(mDocking);
    }

    private class DockEventListener implements DockManager.DockEventListener {
        private boolean mRegistered;

        @Override
        public void onEvent(int event) {
            if (DEBUG) Log.d(TAG, "dock event = " + event);
            switch (event) {
                case DockManager.STATE_DOCKING:
                    mDocking = true;
                    requestPulse();
                    break;
                case DockManager.STATE_UNDOCKING:
                    mDocking = false;
                    requestPulseOutNow();
                    break;
                default:
                    // no-op
            }
        }

        void register() {
            if (mRegistered) {
                return;
            }

            if (mDockManager != null) {
                mDockManager.addListener(this);
            }
            mRegistered = true;
        }

        void unregister() {
            if (!mRegistered) {
                return;
            }
            if (mDockManager != null) {
                mDockManager.removeListener(this);
            }
            mRegistered = false;
        }
    }
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -68,7 +68,8 @@ public class DozeFactory {
                new DozeScreenState(wrappedService, handler, params, wakeLock),
                new DozeScreenState(wrappedService, handler, params, wakeLock),
                createDozeScreenBrightness(context, wrappedService, sensorManager, host, params,
                createDozeScreenBrightness(context, wrappedService, sensorManager, host, params,
                        handler),
                        handler),
                new DozeWallpaperState(context)
                new DozeWallpaperState(context),
                new DozeDockHandler(context, machine, host, config, handler)
        });
        });


        return machine;
        return machine;
+5 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,11 @@ public interface DozeHost {


    void onIgnoreTouchWhilePulsing(boolean ignore);
    void onIgnoreTouchWhilePulsing(boolean ignore);


    /**
     * Leaves pulsing state, going back to ambient UI.
     */
    void stopPulsing();

    interface Callback {
    interface Callback {
        /**
        /**
         * Called when a high priority notification is added.
         * Called when a high priority notification is added.
+4 −2
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ public class DozeLog {
    private static final int SIZE = Build.IS_DEBUGGABLE ? 400 : 50;
    private static final int SIZE = Build.IS_DEBUGGABLE ? 400 : 50;
    static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");
    static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");


    private static final int REASONS = 7;
    private static final int REASONS = 8;


    public static final int PULSE_REASON_NONE = -1;
    public static final int PULSE_REASON_NONE = -1;
    public static final int PULSE_REASON_INTENT = 0;
    public static final int PULSE_REASON_INTENT = 0;
@@ -44,7 +44,8 @@ public class DozeLog {
    public static final int PULSE_REASON_SENSOR_PICKUP = 3;
    public static final int PULSE_REASON_SENSOR_PICKUP = 3;
    public static final int PULSE_REASON_SENSOR_DOUBLE_TAP = 4;
    public static final int PULSE_REASON_SENSOR_DOUBLE_TAP = 4;
    public static final int PULSE_REASON_SENSOR_LONG_PRESS = 5;
    public static final int PULSE_REASON_SENSOR_LONG_PRESS = 5;
    public static final int REASON_SENSOR_WAKE_UP = 6;
    public static final int PULSE_REASON_DOCKING = 6;
    public static final int REASON_SENSOR_WAKE_UP = 7;


    private static boolean sRegisterKeyguardCallback = true;
    private static boolean sRegisterKeyguardCallback = true;


@@ -211,6 +212,7 @@ public class DozeLog {
            case PULSE_REASON_SENSOR_PICKUP: return "pickup";
            case PULSE_REASON_SENSOR_PICKUP: return "pickup";
            case PULSE_REASON_SENSOR_DOUBLE_TAP: return "doubletap";
            case PULSE_REASON_SENSOR_DOUBLE_TAP: return "doubletap";
            case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress";
            case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress";
            case PULSE_REASON_DOCKING: return "docking";
            case REASON_SENSOR_WAKE_UP: return "wakeup";
            case REASON_SENSOR_WAKE_UP: return "wakeup";
            default: throw new IllegalArgumentException("bad reason: " + pulseReason);
            default: throw new IllegalArgumentException("bad reason: " + pulseReason);
        }
        }
Loading