1 /*
2  * Copyright (C) 2022 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.systemui.statusbar.phone;
18 
19 import static com.android.wm.shell.transition.Transitions.ENABLE_SHELL_TRANSITIONS;
20 
21 import android.annotation.Nullable;
22 import android.app.ActivityOptions;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.pm.PackageManager;
26 import android.os.Bundle;
27 import android.os.UserHandle;
28 import android.view.MotionEvent;
29 import android.view.RemoteAnimationAdapter;
30 import android.view.View;
31 import android.window.RemoteTransition;
32 import android.window.SplashScreen;
33 
34 import androidx.annotation.NonNull;
35 import androidx.lifecycle.Lifecycle;
36 import androidx.lifecycle.LifecycleOwner;
37 
38 import com.android.internal.annotations.VisibleForTesting;
39 import com.android.keyguard.AuthKeyguardMessageArea;
40 import com.android.systemui.Dumpable;
41 import com.android.systemui.animation.ActivityLaunchAnimator;
42 import com.android.systemui.display.data.repository.DisplayMetricsRepository;
43 import com.android.systemui.navigationbar.NavigationBarView;
44 import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
45 import com.android.systemui.qs.QSPanelController;
46 import com.android.systemui.shared.system.RemoteAnimationRunnerCompat;
47 import com.android.systemui.statusbar.NotificationPresenter;
48 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
49 import com.android.systemui.util.Compile;
50 
51 import java.io.PrintWriter;
52 
53 /** */
54 public interface CentralSurfaces extends Dumpable, LifecycleOwner {
55     boolean MULTIUSER_DEBUG = false;
56     // Should match the values in PhoneWindowManager
57     String SYSTEM_DIALOG_REASON_KEY = "reason";
58     String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
59     String SYSTEM_DIALOG_REASON_DREAM = "dream";
60     String SYSTEM_DIALOG_REASON_SCREENSHOT = "screenshot";
61     String TAG = "CentralSurfaces";
62     boolean DEBUG = false;
63     boolean SPEW = false;
64     boolean DEBUG_GESTURES = false;
65     boolean DEBUG_MEDIA_FAKE_ARTWORK = false;
66     boolean DEBUG_CAMERA_LIFT = false;
67     boolean DEBUG_WINDOW_STATE = false;
68     boolean DEBUG_WAKEUP_DELAY = Compile.IS_DEBUG;
69     boolean SHOW_LOCKSCREEN_MEDIA_ARTWORK = true;
70     String ACTION_FAKE_ARTWORK = "fake_artwork";
71     int FADE_KEYGUARD_START_DELAY = 100;
72     int FADE_KEYGUARD_DURATION = 300;
73     int FADE_KEYGUARD_DURATION_PULSING = 96;
74     long[] CAMERA_LAUNCH_GESTURE_VIBRATION_TIMINGS =
75             new long[]{20, 20, 20, 20, 100, 20};
76     int[] CAMERA_LAUNCH_GESTURE_VIBRATION_AMPLITUDES =
77             new int[]{39, 82, 139, 213, 0, 127};
78 
79     /** If true, the lockscreen will show a distinct wallpaper */
80     boolean ENABLE_LOCKSCREEN_WALLPAPER = true;
81     // Time after we abort the launch transition.
82     long LAUNCH_TRANSITION_TIMEOUT_MS = 5000;
83     int MSG_DISMISS_KEYBOARD_SHORTCUTS_MENU = 1027;
84 
85     static final boolean CLOSE_PANEL_WHEN_EMPTIED = true;
86 
viewInfo(View v)87     static String viewInfo(View v) {
88         return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom()
89                 + ") " + v.getWidth() + "x" + v.getHeight() + "]";
90     }
91 
dumpBarTransitions( PrintWriter pw, String var, @Nullable BarTransitions transitions)92     static void dumpBarTransitions(
93             PrintWriter pw, String var, @Nullable BarTransitions transitions) {
94         pw.print("  ");
95         pw.print(var);
96         pw.print(".BarTransitions.mMode=");
97         if (transitions != null) {
98             pw.println(BarTransitions.modeToString(transitions.getMode()));
99         } else {
100             pw.println("Unknown");
101         }
102     }
103 
104     /**
105      * Returns an ActivityOptions bundle created using the given parameters.
106      *
107      * @param displayId The ID of the display to launch the activity in. Typically this would
108      *                  be the display the status bar is on.
109      * @param animationAdapter The animation adapter used to start this activity, or {@code null}
110      *                         for the default animation.
111      */
getActivityOptions(int displayId, @Nullable RemoteAnimationAdapter animationAdapter)112     static Bundle getActivityOptions(int displayId,
113             @Nullable RemoteAnimationAdapter animationAdapter) {
114         ActivityOptions options = getDefaultActivityOptions(animationAdapter);
115         options.setLaunchDisplayId(displayId);
116         options.setCallerDisplayId(displayId);
117         options.setPendingIntentBackgroundActivityLaunchAllowed(true);
118         return options.toBundle();
119     }
120 
121     /**
122      * Returns an ActivityOptions bundle created using the given parameters.
123      *
124      * @param displayId         The ID of the display to launch the activity in. Typically this
125      *                          would be the
126      *                          display the status bar is on.
127      * @param animationAdapter  The animation adapter used to start this activity, or {@code null}
128      *                          for the default animation.
129      * @param isKeyguardShowing Whether keyguard is currently showing.
130      * @param eventTime         The event time in milliseconds since boot, not including sleep. See
131      *                          {@link ActivityOptions#setSourceInfo}.
132      */
getActivityOptions(int displayId, @Nullable RemoteAnimationAdapter animationAdapter, boolean isKeyguardShowing, long eventTime)133     static Bundle getActivityOptions(int displayId,
134             @Nullable RemoteAnimationAdapter animationAdapter, boolean isKeyguardShowing,
135             long eventTime) {
136         ActivityOptions options = getDefaultActivityOptions(animationAdapter);
137         options.setSourceInfo(isKeyguardShowing ? ActivityOptions.SourceInfo.TYPE_LOCKSCREEN
138                 : ActivityOptions.SourceInfo.TYPE_NOTIFICATION, eventTime);
139         options.setLaunchDisplayId(displayId);
140         options.setCallerDisplayId(displayId);
141         options.setPendingIntentBackgroundActivityLaunchAllowed(true);
142         return options.toBundle();
143     }
144 
getDefaultActivityOptions( @ullable RemoteAnimationAdapter animationAdapter)145     static ActivityOptions getDefaultActivityOptions(
146             @Nullable RemoteAnimationAdapter animationAdapter) {
147         ActivityOptions options;
148         if (animationAdapter != null) {
149             if (ENABLE_SHELL_TRANSITIONS) {
150                 options = ActivityOptions.makeRemoteTransition(
151                         new RemoteTransition(
152                                 RemoteAnimationRunnerCompat.wrap(animationAdapter.getRunner()),
153                                 animationAdapter.getCallingApplication(), "SysUILaunch"));
154             } else {
155                 options = ActivityOptions.makeRemoteAnimation(animationAdapter);
156             }
157         } else {
158             options = ActivityOptions.makeBasic();
159         }
160         options.setSplashScreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_SOLID_COLOR);
161         return options;
162     }
163 
164     /**
165      * @return a PackageManager for userId or if userId is < 0 (USER_ALL etc) then
166      * return PackageManager for mContext
167      */
getPackageManagerForUser(Context context, int userId)168     static PackageManager getPackageManagerForUser(Context context, int userId) {
169         Context contextForUser = context;
170         // UserHandle defines special userId as negative values, e.g. USER_ALL
171         if (userId >= 0) {
172             try {
173                 // Create a context for the correct user so if a package isn't installed
174                 // for user 0 we can still load information about the package.
175                 contextForUser =
176                         context.createPackageContextAsUser(context.getPackageName(),
177                                 Context.CONTEXT_RESTRICTED,
178                                 new UserHandle(userId));
179             } catch (PackageManager.NameNotFoundException e) {
180                 // Shouldn't fail to find the package name for system ui.
181             }
182         }
183         return contextForUser.getPackageManager();
184     }
185 
start()186     void start();
187 
updateIsKeyguard()188     boolean updateIsKeyguard();
189 
updateIsKeyguard(boolean forceStateChange)190     boolean updateIsKeyguard(boolean forceStateChange);
191 
192     @NonNull
193     @Override
getLifecycle()194     Lifecycle getLifecycle();
195 
196     /** Get the Keyguard Message Area that displays auth messages. */
getKeyguardMessageArea()197     AuthKeyguardMessageArea getKeyguardMessageArea();
198 
getStatusBarHeight()199     int getStatusBarHeight();
200 
isLaunchingActivityOverLockscreen()201     boolean isLaunchingActivityOverLockscreen();
202 
onKeyguardViewManagerStatesUpdated()203     void onKeyguardViewManagerStatesUpdated();
204 
isPulsing()205     boolean isPulsing();
206 
isOccluded()207     boolean isOccluded();
208 
isDeviceInVrMode()209     boolean isDeviceInVrMode();
210 
getPresenter()211     NotificationPresenter getPresenter();
212 
213     /**
214      * Used to dispatch initial touch events before crossing the threshold to pull down the
215      * notification shade. After that, since the launcher window is set to slippery, input
216      * frameworks take care of routing the events to the notification shade.
217      */
onInputFocusTransfer(boolean start, boolean cancel, float velocity)218     void onInputFocusTransfer(boolean start, boolean cancel, float velocity);
219 
220     /**
221      * Dispatches status bar motion event to the notification shade. This is different from
222      * {@link #onInputFocusTransfer(boolean, boolean, float)} as it doesn't rely on setting the
223      * launcher window slippery to allow the frameworks to route those events after passing the
224      * initial threshold.
225      */
onStatusBarTrackpadEvent(MotionEvent event)226     default void onStatusBarTrackpadEvent(MotionEvent event) {}
227 
228     /** */
getCommandQueuePanelsEnabled()229     boolean getCommandQueuePanelsEnabled();
230 
231     /** */
getStatusBarWindowState()232     int getStatusBarWindowState();
233 
getBiometricUnlockController()234     BiometricUnlockController getBiometricUnlockController();
235 
showWirelessChargingAnimation(int batteryLevel)236     void showWirelessChargingAnimation(int batteryLevel);
237 
checkBarModes()238     void checkBarModes();
239 
updateBubblesVisibility()240     void updateBubblesVisibility();
241 
setInteracting(int barWindow, boolean interacting)242     void setInteracting(int barWindow, boolean interacting);
243 
244     @Override
dump(PrintWriter pwOriginal, String[] args)245     void dump(PrintWriter pwOriginal, String[] args);
246 
247     /** @deprecated Use {@link DisplayMetricsRepository} instead. */
248     @Deprecated
getDisplayWidth()249     float getDisplayWidth();
250 
251     /** @deprecated Use {@link DisplayMetricsRepository} instead. */
252     @Deprecated
getDisplayHeight()253     float getDisplayHeight();
254 
readyForKeyguardDone()255     void readyForKeyguardDone();
256 
showKeyguard()257     void showKeyguard();
258 
hideKeyguard()259     boolean hideKeyguard();
260 
showKeyguardImpl()261     void showKeyguardImpl();
262 
fadeKeyguardAfterLaunchTransition(Runnable beforeFading, Runnable endRunnable, Runnable cancelRunnable)263     void fadeKeyguardAfterLaunchTransition(Runnable beforeFading,
264             Runnable endRunnable, Runnable cancelRunnable);
265 
startLaunchTransitionTimeout()266     void startLaunchTransitionTimeout();
267 
hideKeyguardImpl(boolean forceStateChange)268     boolean hideKeyguardImpl(boolean forceStateChange);
269 
keyguardGoingAway()270     void keyguardGoingAway();
271 
setKeyguardFadingAway(long startTime, long delay, long fadeoutDuration)272     void setKeyguardFadingAway(long startTime, long delay, long fadeoutDuration);
273 
finishKeyguardFadingAway()274     void finishKeyguardFadingAway();
275 
userActivity()276     void userActivity();
277 
endAffordanceLaunch()278     void endAffordanceLaunch();
279 
280     /** Should the keyguard be hidden immediately in response to a back press/gesture. */
shouldKeyguardHideImmediately()281     boolean shouldKeyguardHideImmediately();
282 
showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction, Runnable cancelAction)283     void showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction,
284             Runnable cancelAction);
285 
286     // TODO: Figure out way to remove these.
getNavigationBarView()287     NavigationBarView getNavigationBarView();
288 
isOverviewEnabled()289     boolean isOverviewEnabled();
290 
showPinningEnterExitToast(boolean entering)291     void showPinningEnterExitToast(boolean entering);
292 
showPinningEscapeToast()293     void showPinningEscapeToast();
294 
setBouncerShowing(boolean bouncerShowing)295     void setBouncerShowing(boolean bouncerShowing);
296 
getWakefulnessState()297     int getWakefulnessState();
298 
isScreenFullyOff()299     boolean isScreenFullyOff();
300 
showScreenPinningRequest(int taskId, boolean allowCancel)301     void showScreenPinningRequest(int taskId, boolean allowCancel);
302 
303     @Nullable
getEmergencyActionIntent()304     Intent getEmergencyActionIntent();
305 
isCameraAllowedByAdmin()306     boolean isCameraAllowedByAdmin();
307 
isGoingToSleep()308     boolean isGoingToSleep();
309 
notifyBiometricAuthModeChanged()310     void notifyBiometricAuthModeChanged();
311 
setTransitionToFullShadeProgress(float transitionToFullShadeProgress)312     void setTransitionToFullShadeProgress(float transitionToFullShadeProgress);
313 
314     /**
315      * Sets the amount of progress to the bouncer being fully hidden/visible. 1 means the bouncer
316      * is fully hidden, while 0 means the bouncer is visible.
317      */
setPrimaryBouncerHiddenFraction(float expansion)318     void setPrimaryBouncerHiddenFraction(float expansion);
319 
320     @VisibleForTesting
updateScrimController()321     void updateScrimController();
322 
isKeyguardShowing()323     boolean isKeyguardShowing();
324 
shouldIgnoreTouch()325     boolean shouldIgnoreTouch();
326 
isDeviceInteractive()327     boolean isDeviceInteractive();
328 
awakenDreams()329     void awakenDreams();
330 
clearNotificationEffects()331     void clearNotificationEffects();
332 
isBouncerShowing()333     boolean isBouncerShowing();
334 
isBouncerShowingScrimmed()335     boolean isBouncerShowingScrimmed();
336 
isBouncerShowingOverDream()337     boolean isBouncerShowingOverDream();
338 
isKeyguardSecure()339     boolean isKeyguardSecure();
340 
updateNotificationPanelTouchState()341     void updateNotificationPanelTouchState();
342 
getRotation()343     int getRotation();
344 
345     @VisibleForTesting
setBarStateForTest(int state)346     void setBarStateForTest(int state);
347 
showTransientUnchecked()348     void showTransientUnchecked();
349 
clearTransient()350     void clearTransient();
351 
acquireGestureWakeLock(long time)352     void acquireGestureWakeLock(long time);
353 
setAppearance(int appearance)354     boolean setAppearance(int appearance);
355 
getBarMode()356     int getBarMode();
357 
resendMessage(int msg)358     void resendMessage(int msg);
359 
resendMessage(Object msg)360     void resendMessage(Object msg);
361 
setLastCameraLaunchSource(int source)362     void setLastCameraLaunchSource(int source);
363 
setLaunchCameraOnFinishedGoingToSleep(boolean launch)364     void setLaunchCameraOnFinishedGoingToSleep(boolean launch);
365 
setLaunchCameraOnFinishedWaking(boolean launch)366     void setLaunchCameraOnFinishedWaking(boolean launch);
367 
setLaunchEmergencyActionOnFinishedGoingToSleep(boolean launch)368     void setLaunchEmergencyActionOnFinishedGoingToSleep(boolean launch);
369 
setLaunchEmergencyActionOnFinishedWaking(boolean launch)370     void setLaunchEmergencyActionOnFinishedWaking(boolean launch);
371 
getQSPanelController()372     QSPanelController getQSPanelController();
373 
374     /** @deprecated Use {@link DisplayMetricsRepository} instead. */
375     @Deprecated
getDisplayDensity()376     float getDisplayDensity();
377 
extendDozePulse()378     void extendDozePulse();
379 
380     public static class KeyboardShortcutsMessage {
381         final int mDeviceId;
382 
KeyboardShortcutsMessage(int deviceId)383         KeyboardShortcutsMessage(int deviceId) {
384             mDeviceId = deviceId;
385         }
386     }
387 
388     /**
389      * Sets launching activity over LS state in central surfaces.
390      */
setIsLaunchingActivityOverLockscreen(boolean isLaunchingActivityOverLockscreen)391     void setIsLaunchingActivityOverLockscreen(boolean isLaunchingActivityOverLockscreen);
392 
393     /**
394      * Gets an animation controller from a notification row.
395      */
getAnimatorControllerFromNotification( ExpandableNotificationRow associatedView)396     ActivityLaunchAnimator.Controller getAnimatorControllerFromNotification(
397             ExpandableNotificationRow associatedView);
398 }
399