1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.policy; 18 19 import android.annotation.Nullable; 20 import android.os.SystemClock; 21 22 import com.android.internal.annotations.Keep; 23 import com.android.server.LocalServices; 24 25 /** Policy controlling the decision and execution of window-related wake ups. */ 26 @Keep 27 public interface WindowWakeUpPolicyInternal { 28 29 /** 30 * A delegate that can choose to intercept Input-related wake ups. 31 * 32 * <p>This delegate is not meant to control policy decisions on whether or not to wake up. The 33 * policy makes that decision, and forwards the wake up request to the delegate as necessary. 34 * Therefore, the role of the delegate is to handle the actual "waking" of the device in 35 * response to the respective input event. 36 */ 37 @Keep 38 interface InputWakeUpDelegate { 39 /** 40 * Wakes up the device in response to a key event. 41 * 42 * @param eventTime the timestamp of the event in {@link SystemClock#uptimeMillis()}. 43 * @param keyCode the {@link android.view.KeyEvent} key code of the key event. 44 * @param isDown {@code true} if the event's action is {@link KeyEvent#ACTION_DOWN}. 45 * @return {@code true} if the delegate handled the wake up. {@code false} if the delegate 46 * decided not to handle the wake up. The policy will execute the wake up in this case. 47 */ wakeUpFromKey(long eventTime, int keyCode, boolean isDown)48 boolean wakeUpFromKey(long eventTime, int keyCode, boolean isDown); 49 /** 50 * Wakes up the device in response to a motion event. 51 * 52 * @param eventTime the timestamp of the event in {@link SystemClock#uptimeMillis()}. 53 * @param source the {@link android.view.InputDevice} source that caused the event. 54 * @param isDown {@code true} if the event's action is {@link MotionEvent#ACTION_DOWN}. 55 * @return {@code true} if the delegate handled the wake up. {@code false} if the delegate 56 * decided not to handle the wake up. The policy will execute the wake up in this case. 57 */ wakeUpFromMotion(long eventTime, int source, boolean isDown)58 boolean wakeUpFromMotion(long eventTime, int source, boolean isDown); 59 } 60 61 /** 62 * Allows injecting a delegate for controlling input-based wake ups. 63 * 64 * <p>A delegate can be injected to the policy by system_server components only, and should be 65 * done via the {@link LocalServices} interface. 66 * 67 * <p>There can at most be one active delegate. If there's no delegate set (or if a {@code null} 68 * delegate is set), the policy will handle waking up the device in response to input events. 69 * 70 * @param delegate an implementation of {@link InputWakeUpDelegate} that handles input-based 71 * wake up requests. {@code null} to let the policy handle these wake ups. 72 */ 73 @Keep setInputWakeUpDelegate(@ullable InputWakeUpDelegate delegate)74 void setInputWakeUpDelegate(@Nullable InputWakeUpDelegate delegate); 75 } 76