• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.pm.PackageManager;
25 import android.os.Bundle;
26 import android.os.UserHandle;
27 import android.view.MotionEvent;
28 import android.view.RemoteAnimationAdapter;
29 import android.view.View;
30 import android.window.RemoteTransition;
31 import android.window.SplashScreen;
32 
33 import androidx.annotation.NonNull;
34 import androidx.lifecycle.Lifecycle;
35 import androidx.lifecycle.LifecycleOwner;
36 
37 import com.android.internal.annotations.VisibleForTesting;
38 import com.android.keyguard.AuthKeyguardMessageArea;
39 import com.android.systemui.CoreStartable;
40 import com.android.systemui.Dumpable;
41 import com.android.systemui.animation.ActivityTransitionAnimator;
42 import com.android.systemui.animation.RemoteAnimationRunnerCompat;
43 import com.android.systemui.display.data.repository.DisplayMetricsRepository;
44 import com.android.systemui.navigationbar.views.NavigationBarView;
45 import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
46 import com.android.systemui.qs.QSPanelController;
47 import com.android.systemui.shared.statusbar.phone.BarTransitions;
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, CoreStartable {
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_POWER_BUTTON_GESTURE = 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 
186     /** Default impl for CoreStartable. */
start()187     default void start() {}
188 
updateIsKeyguard()189     boolean updateIsKeyguard();
190 
updateIsKeyguard(boolean forceStateChange)191     boolean updateIsKeyguard(boolean forceStateChange);
192 
193     @NonNull
194     @Override
getLifecycle()195     Lifecycle getLifecycle();
196 
197     /** Get the Keyguard Message Area that displays auth messages. */
getKeyguardMessageArea()198     AuthKeyguardMessageArea getKeyguardMessageArea();
199 
isLaunchingActivityOverLockscreen()200     boolean isLaunchingActivityOverLockscreen();
201 
202     /**
203      * Whether an activity launch over lockscreen is causing the shade to be dismissed.
204      */
isDismissingShadeForActivityLaunch()205     boolean isDismissingShadeForActivityLaunch();
206 
onKeyguardViewManagerStatesUpdated()207     void onKeyguardViewManagerStatesUpdated();
208 
209     /**  */
getCommandQueuePanelsEnabled()210     boolean getCommandQueuePanelsEnabled();
211 
showWirelessChargingAnimation(int batteryLevel)212     void showWirelessChargingAnimation(int batteryLevel);
213 
checkBarModes()214     void checkBarModes();
215 
updateBubblesVisibility()216     void updateBubblesVisibility();
217 
setInteracting(int barWindow, boolean interacting)218     void setInteracting(int barWindow, boolean interacting);
219 
220     /** @deprecated Use {@link DisplayMetricsRepository} instead. */
221     @Deprecated
getDisplayWidth()222     float getDisplayWidth();
223 
224     /** @deprecated Use {@link DisplayMetricsRepository} instead. */
225     @Deprecated
getDisplayHeight()226     float getDisplayHeight();
227 
showKeyguard()228     void showKeyguard();
229 
hideKeyguard()230     boolean hideKeyguard();
231 
showKeyguardImpl()232     void showKeyguardImpl();
233 
fadeKeyguardAfterLaunchTransition(Runnable beforeFading, Runnable endRunnable, Runnable cancelRunnable)234     void fadeKeyguardAfterLaunchTransition(Runnable beforeFading,
235             Runnable endRunnable, Runnable cancelRunnable);
236 
startLaunchTransitionTimeout()237     void startLaunchTransitionTimeout();
238 
hideKeyguardImpl(boolean forceStateChange)239     boolean hideKeyguardImpl(boolean forceStateChange);
240 
keyguardGoingAway()241     void keyguardGoingAway();
242 
setKeyguardFadingAway(long startTime, long delay, long fadeoutDuration)243     void setKeyguardFadingAway(long startTime, long delay, long fadeoutDuration);
244 
finishKeyguardFadingAway()245     void finishKeyguardFadingAway();
246 
userActivity()247     void userActivity();
248 
endAffordanceLaunch()249     void endAffordanceLaunch();
250 
251     /** Should the keyguard be hidden immediately in response to a back press/gesture. */
shouldKeyguardHideImmediately()252     boolean shouldKeyguardHideImmediately();
253 
showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction, Runnable cancelAction)254     void showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction,
255             Runnable cancelAction);
256 
257     // TODO: Figure out way to remove these.
getNavigationBarView()258     NavigationBarView getNavigationBarView();
259 
setBouncerShowing(boolean bouncerShowing)260     void setBouncerShowing(boolean bouncerShowing);
261 
isScreenFullyOff()262     boolean isScreenFullyOff();
263 
isGoingToSleep()264     boolean isGoingToSleep();
265 
notifyBiometricAuthModeChanged()266     void notifyBiometricAuthModeChanged();
267 
setTransitionToFullShadeProgress(float transitionToFullShadeProgress)268     void setTransitionToFullShadeProgress(float transitionToFullShadeProgress);
269 
270     /**
271      * Sets the amount of progress to the bouncer being fully hidden/visible. 1 means the bouncer
272      * is fully hidden, while 0 means the bouncer is visible.
273      */
setPrimaryBouncerHiddenFraction(float expansion)274     void setPrimaryBouncerHiddenFraction(float expansion);
275 
276     @VisibleForTesting
updateScrimController()277     void updateScrimController();
278 
shouldIgnoreTouch()279     boolean shouldIgnoreTouch();
280 
isDeviceInteractive()281     boolean isDeviceInteractive();
282 
awakenDreams()283     void awakenDreams();
284 
285     /**
286      * Handle a touch event while dreaming or on the glanceable hub when the touch was initiated
287      * within a prescribed swipeable area. This method is provided for cases where swiping in
288      * certain areas should be handled by CentralSurfaces instead (e.g. swiping hub open, opening
289      * the notification shade over dream or hub).
290      */
handleExternalShadeWindowTouch(MotionEvent event)291     void handleExternalShadeWindowTouch(MotionEvent event);
292 
isBouncerShowing()293     boolean isBouncerShowing();
294 
isBouncerShowingScrimmed()295     boolean isBouncerShowingScrimmed();
296 
updateNotificationPanelTouchState()297     void updateNotificationPanelTouchState();
298 
getRotation()299     int getRotation();
300 
301     @VisibleForTesting
setBarStateForTest(int state)302     void setBarStateForTest(int state);
303 
acquireGestureWakeLock(long time)304     void acquireGestureWakeLock(long time);
305 
resendMessage(int msg)306     void resendMessage(int msg);
307 
resendMessage(Object msg)308     void resendMessage(Object msg);
309 
setLastCameraLaunchSource(int source)310     void setLastCameraLaunchSource(int source);
311 
setLaunchCameraOnFinishedGoingToSleep(boolean launch)312     void setLaunchCameraOnFinishedGoingToSleep(boolean launch);
313 
setLaunchCameraOnFinishedWaking(boolean launch)314     void setLaunchCameraOnFinishedWaking(boolean launch);
315     /**
316      * Notifies SysUI to launch wallet when device finishes sleeping.
317      */
setLaunchWalletOnFinishedGoingToSleep(boolean launch)318     void setLaunchWalletOnFinishedGoingToSleep(boolean launch);
319 
320     /**
321      * Notifies SysUI to launch wallet when device finishes waking.
322      */
setLaunchWalletOnFinishedWaking(boolean launch)323     void setLaunchWalletOnFinishedWaking(boolean launch);
324 
setLaunchEmergencyActionOnFinishedGoingToSleep(boolean launch)325     void setLaunchEmergencyActionOnFinishedGoingToSleep(boolean launch);
326 
setLaunchEmergencyActionOnFinishedWaking(boolean launch)327     void setLaunchEmergencyActionOnFinishedWaking(boolean launch);
328 
getQSPanelController()329     QSPanelController getQSPanelController();
330 
331     /** @deprecated Use {@link DisplayMetricsRepository} instead. */
332     @Deprecated
getDisplayDensity()333     float getDisplayDensity();
334 
335     /**
336      * Forwards touch events to communal hub
337      */
handleCommunalHubTouch(MotionEvent event)338     void handleCommunalHubTouch(MotionEvent event);
339 
340     public static class KeyboardShortcutsMessage {
341         final int mDeviceId;
342 
KeyboardShortcutsMessage(int deviceId)343         KeyboardShortcutsMessage(int deviceId) {
344             mDeviceId = deviceId;
345         }
346     }
347 
348     /**
349      * Sets launching activity over LS state in central surfaces.
350      */
setIsLaunchingActivityOverLockscreen( boolean isLaunchingActivityOverLockscreen, boolean dismissShade)351     void setIsLaunchingActivityOverLockscreen(
352             boolean isLaunchingActivityOverLockscreen, boolean dismissShade);
353 
354     /**
355      * Gets an animation controller from a notification row.
356      */
getAnimatorControllerFromNotification( ExpandableNotificationRow associatedView)357     ActivityTransitionAnimator.Controller getAnimatorControllerFromNotification(
358             ExpandableNotificationRow associatedView);
359 }
360