Loading packages/SystemUI/src/com/android/systemui/dock/DockManager.java 0 → 100644 +60 −0 Original line number 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); } } packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java 0 → 100644 +144 −0 Original line number 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; } } } packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,8 @@ public class DozeFactory { new DozeScreenState(wrappedService, handler, params, wakeLock), createDozeScreenBrightness(context, wrappedService, sensorManager, host, params, handler), new DozeWallpaperState(context) new DozeWallpaperState(context), new DozeDockHandler(context, machine, host, config, handler) }); return machine; Loading packages/SystemUI/src/com/android/systemui/doze/DozeHost.java +5 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,11 @@ public interface DozeHost { void onIgnoreTouchWhilePulsing(boolean ignore); /** * Leaves pulsing state, going back to ambient UI. */ void stopPulsing(); interface Callback { /** * Called when a high priority notification is added. Loading packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +4 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ public class DozeLog { private static final int SIZE = Build.IS_DEBUGGABLE ? 400 : 50; 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_INTENT = 0; Loading @@ -44,7 +44,8 @@ public class DozeLog { 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_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; Loading Loading @@ -211,6 +212,7 @@ public class DozeLog { case PULSE_REASON_SENSOR_PICKUP: return "pickup"; case PULSE_REASON_SENSOR_DOUBLE_TAP: return "doubletap"; case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress"; case PULSE_REASON_DOCKING: return "docking"; case REASON_SENSOR_WAKE_UP: return "wakeup"; default: throw new IllegalArgumentException("bad reason: " + pulseReason); } Loading Loading
packages/SystemUI/src/com/android/systemui/dock/DockManager.java 0 → 100644 +60 −0 Original line number 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); } }
packages/SystemUI/src/com/android/systemui/doze/DozeDockHandler.java 0 → 100644 +144 −0 Original line number 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; } } }
packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java +2 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,8 @@ public class DozeFactory { new DozeScreenState(wrappedService, handler, params, wakeLock), createDozeScreenBrightness(context, wrappedService, sensorManager, host, params, handler), new DozeWallpaperState(context) new DozeWallpaperState(context), new DozeDockHandler(context, machine, host, config, handler) }); return machine; Loading
packages/SystemUI/src/com/android/systemui/doze/DozeHost.java +5 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,11 @@ public interface DozeHost { void onIgnoreTouchWhilePulsing(boolean ignore); /** * Leaves pulsing state, going back to ambient UI. */ void stopPulsing(); interface Callback { /** * Called when a high priority notification is added. Loading
packages/SystemUI/src/com/android/systemui/doze/DozeLog.java +4 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ public class DozeLog { private static final int SIZE = Build.IS_DEBUGGABLE ? 400 : 50; 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_INTENT = 0; Loading @@ -44,7 +44,8 @@ public class DozeLog { 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_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; Loading Loading @@ -211,6 +212,7 @@ public class DozeLog { case PULSE_REASON_SENSOR_PICKUP: return "pickup"; case PULSE_REASON_SENSOR_DOUBLE_TAP: return "doubletap"; case PULSE_REASON_SENSOR_LONG_PRESS: return "longpress"; case PULSE_REASON_DOCKING: return "docking"; case REASON_SENSOR_WAKE_UP: return "wakeup"; default: throw new IllegalArgumentException("bad reason: " + pulseReason); } Loading