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.NavigationBarView; 45 import com.android.systemui.plugins.ActivityStarter.OnDismissAction; 46 import com.android.systemui.qs.QSPanelController; 47 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; 48 import com.android.systemui.util.Compile; 49 50 import java.io.PrintWriter; 51 52 /** */ 53 public interface CentralSurfaces extends Dumpable, LifecycleOwner, CoreStartable { 54 boolean MULTIUSER_DEBUG = false; 55 // Should match the values in PhoneWindowManager 56 String SYSTEM_DIALOG_REASON_KEY = "reason"; 57 String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; 58 String SYSTEM_DIALOG_REASON_DREAM = "dream"; 59 String SYSTEM_DIALOG_REASON_SCREENSHOT = "screenshot"; 60 String TAG = "CentralSurfaces"; 61 boolean DEBUG = false; 62 boolean SPEW = false; 63 boolean DEBUG_GESTURES = false; 64 boolean DEBUG_MEDIA_FAKE_ARTWORK = false; 65 boolean DEBUG_CAMERA_LIFT = false; 66 boolean DEBUG_WINDOW_STATE = false; 67 boolean DEBUG_WAKEUP_DELAY = Compile.IS_DEBUG; 68 boolean SHOW_LOCKSCREEN_MEDIA_ARTWORK = true; 69 String ACTION_FAKE_ARTWORK = "fake_artwork"; 70 int FADE_KEYGUARD_START_DELAY = 100; 71 int FADE_KEYGUARD_DURATION = 300; 72 int FADE_KEYGUARD_DURATION_PULSING = 96; 73 long[] CAMERA_LAUNCH_GESTURE_VIBRATION_TIMINGS = 74 new long[]{20, 20, 20, 20, 100, 20}; 75 int[] CAMERA_LAUNCH_GESTURE_VIBRATION_AMPLITUDES = 76 new int[]{39, 82, 139, 213, 0, 127}; 77 78 /** If true, the lockscreen will show a distinct wallpaper */ 79 boolean ENABLE_LOCKSCREEN_WALLPAPER = true; 80 // Time after we abort the launch transition. 81 long LAUNCH_TRANSITION_TIMEOUT_MS = 5000; 82 int MSG_DISMISS_KEYBOARD_SHORTCUTS_MENU = 1027; 83 84 static final boolean CLOSE_PANEL_WHEN_EMPTIED = true; 85 viewInfo(View v)86 static String viewInfo(View v) { 87 return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom() 88 + ") " + v.getWidth() + "x" + v.getHeight() + "]"; 89 } 90 dumpBarTransitions( PrintWriter pw, String var, @Nullable BarTransitions transitions)91 static void dumpBarTransitions( 92 PrintWriter pw, String var, @Nullable BarTransitions transitions) { 93 pw.print(" "); 94 pw.print(var); 95 pw.print(".BarTransitions.mMode="); 96 if (transitions != null) { 97 pw.println(BarTransitions.modeToString(transitions.getMode())); 98 } else { 99 pw.println("Unknown"); 100 } 101 } 102 103 /** 104 * Returns an ActivityOptions bundle created using the given parameters. 105 * 106 * @param displayId The ID of the display to launch the activity in. Typically this would 107 * be the display the status bar is on. 108 * @param animationAdapter The animation adapter used to start this activity, or {@code null} 109 * for the default animation. 110 */ getActivityOptions(int displayId, @Nullable RemoteAnimationAdapter animationAdapter)111 static Bundle getActivityOptions(int displayId, 112 @Nullable RemoteAnimationAdapter animationAdapter) { 113 ActivityOptions options = getDefaultActivityOptions(animationAdapter); 114 options.setLaunchDisplayId(displayId); 115 options.setCallerDisplayId(displayId); 116 options.setPendingIntentBackgroundActivityLaunchAllowed(true); 117 return options.toBundle(); 118 } 119 120 /** 121 * Returns an ActivityOptions bundle created using the given parameters. 122 * 123 * @param displayId The ID of the display to launch the activity in. Typically this 124 * would be the 125 * display the status bar is on. 126 * @param animationAdapter The animation adapter used to start this activity, or {@code null} 127 * for the default animation. 128 * @param isKeyguardShowing Whether keyguard is currently showing. 129 * @param eventTime The event time in milliseconds since boot, not including sleep. See 130 * {@link ActivityOptions#setSourceInfo}. 131 */ getActivityOptions(int displayId, @Nullable RemoteAnimationAdapter animationAdapter, boolean isKeyguardShowing, long eventTime)132 static Bundle getActivityOptions(int displayId, 133 @Nullable RemoteAnimationAdapter animationAdapter, boolean isKeyguardShowing, 134 long eventTime) { 135 ActivityOptions options = getDefaultActivityOptions(animationAdapter); 136 options.setSourceInfo(isKeyguardShowing ? ActivityOptions.SourceInfo.TYPE_LOCKSCREEN 137 : ActivityOptions.SourceInfo.TYPE_NOTIFICATION, eventTime); 138 options.setLaunchDisplayId(displayId); 139 options.setCallerDisplayId(displayId); 140 options.setPendingIntentBackgroundActivityLaunchAllowed(true); 141 return options.toBundle(); 142 } 143 getDefaultActivityOptions( @ullable RemoteAnimationAdapter animationAdapter)144 static ActivityOptions getDefaultActivityOptions( 145 @Nullable RemoteAnimationAdapter animationAdapter) { 146 ActivityOptions options; 147 if (animationAdapter != null) { 148 if (ENABLE_SHELL_TRANSITIONS) { 149 options = ActivityOptions.makeRemoteTransition( 150 new RemoteTransition( 151 RemoteAnimationRunnerCompat.wrap(animationAdapter.getRunner()), 152 animationAdapter.getCallingApplication(), "SysUILaunch")); 153 } else { 154 options = ActivityOptions.makeRemoteAnimation(animationAdapter); 155 } 156 } else { 157 options = ActivityOptions.makeBasic(); 158 } 159 options.setSplashScreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_SOLID_COLOR); 160 return options; 161 } 162 163 /** 164 * @return a PackageManager for userId or if userId is < 0 (USER_ALL etc) then 165 * return PackageManager for mContext 166 */ getPackageManagerForUser(Context context, int userId)167 static PackageManager getPackageManagerForUser(Context context, int userId) { 168 Context contextForUser = context; 169 // UserHandle defines special userId as negative values, e.g. USER_ALL 170 if (userId >= 0) { 171 try { 172 // Create a context for the correct user so if a package isn't installed 173 // for user 0 we can still load information about the package. 174 contextForUser = 175 context.createPackageContextAsUser(context.getPackageName(), 176 Context.CONTEXT_RESTRICTED, 177 new UserHandle(userId)); 178 } catch (PackageManager.NameNotFoundException e) { 179 // Shouldn't fail to find the package name for system ui. 180 } 181 } 182 return contextForUser.getPackageManager(); 183 } 184 185 /** Default impl for CoreStartable. */ start()186 default 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 isLaunchingActivityOverLockscreen()199 boolean isLaunchingActivityOverLockscreen(); 200 201 /** 202 * Whether an activity launch over lockscreen is causing the shade to be dismissed. 203 */ isDismissingShadeForActivityLaunch()204 boolean isDismissingShadeForActivityLaunch(); 205 onKeyguardViewManagerStatesUpdated()206 void onKeyguardViewManagerStatesUpdated(); 207 208 /** */ getCommandQueuePanelsEnabled()209 boolean getCommandQueuePanelsEnabled(); 210 showWirelessChargingAnimation(int batteryLevel)211 void showWirelessChargingAnimation(int batteryLevel); 212 checkBarModes()213 void checkBarModes(); 214 updateBubblesVisibility()215 void updateBubblesVisibility(); 216 setInteracting(int barWindow, boolean interacting)217 void setInteracting(int barWindow, boolean interacting); 218 219 /** @deprecated Use {@link DisplayMetricsRepository} instead. */ 220 @Deprecated getDisplayWidth()221 float getDisplayWidth(); 222 223 /** @deprecated Use {@link DisplayMetricsRepository} instead. */ 224 @Deprecated getDisplayHeight()225 float getDisplayHeight(); 226 showKeyguard()227 void showKeyguard(); 228 hideKeyguard()229 boolean hideKeyguard(); 230 showKeyguardImpl()231 void showKeyguardImpl(); 232 fadeKeyguardAfterLaunchTransition(Runnable beforeFading, Runnable endRunnable, Runnable cancelRunnable)233 void fadeKeyguardAfterLaunchTransition(Runnable beforeFading, 234 Runnable endRunnable, Runnable cancelRunnable); 235 startLaunchTransitionTimeout()236 void startLaunchTransitionTimeout(); 237 hideKeyguardImpl(boolean forceStateChange)238 boolean hideKeyguardImpl(boolean forceStateChange); 239 keyguardGoingAway()240 void keyguardGoingAway(); 241 setKeyguardFadingAway(long startTime, long delay, long fadeoutDuration)242 void setKeyguardFadingAway(long startTime, long delay, long fadeoutDuration); 243 finishKeyguardFadingAway()244 void finishKeyguardFadingAway(); 245 userActivity()246 void userActivity(); 247 endAffordanceLaunch()248 void endAffordanceLaunch(); 249 250 /** Should the keyguard be hidden immediately in response to a back press/gesture. */ shouldKeyguardHideImmediately()251 boolean shouldKeyguardHideImmediately(); 252 showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction, Runnable cancelAction)253 void showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction, 254 Runnable cancelAction); 255 256 // TODO: Figure out way to remove these. getNavigationBarView()257 NavigationBarView getNavigationBarView(); 258 setBouncerShowing(boolean bouncerShowing)259 void setBouncerShowing(boolean bouncerShowing); 260 isScreenFullyOff()261 boolean isScreenFullyOff(); 262 isCameraAllowedByAdmin()263 boolean isCameraAllowedByAdmin(); 264 isGoingToSleep()265 boolean isGoingToSleep(); 266 notifyBiometricAuthModeChanged()267 void notifyBiometricAuthModeChanged(); 268 setTransitionToFullShadeProgress(float transitionToFullShadeProgress)269 void setTransitionToFullShadeProgress(float transitionToFullShadeProgress); 270 271 /** 272 * Sets the amount of progress to the bouncer being fully hidden/visible. 1 means the bouncer 273 * is fully hidden, while 0 means the bouncer is visible. 274 */ setPrimaryBouncerHiddenFraction(float expansion)275 void setPrimaryBouncerHiddenFraction(float expansion); 276 277 @VisibleForTesting updateScrimController()278 void updateScrimController(); 279 shouldIgnoreTouch()280 boolean shouldIgnoreTouch(); 281 isDeviceInteractive()282 boolean isDeviceInteractive(); 283 awakenDreams()284 void awakenDreams(); 285 286 /** 287 * Handle a touch event while dreaming or on the glanceable hub when the touch was initiated 288 * within a prescribed swipeable area. This method is provided for cases where swiping in 289 * certain areas should be handled by CentralSurfaces instead (e.g. swiping hub open, opening 290 * the notification shade over dream or hub). 291 */ handleExternalShadeWindowTouch(MotionEvent event)292 void handleExternalShadeWindowTouch(MotionEvent event); 293 isBouncerShowing()294 boolean isBouncerShowing(); 295 isBouncerShowingScrimmed()296 boolean isBouncerShowingScrimmed(); 297 updateNotificationPanelTouchState()298 void updateNotificationPanelTouchState(); 299 getRotation()300 int getRotation(); 301 302 @VisibleForTesting setBarStateForTest(int state)303 void setBarStateForTest(int state); 304 acquireGestureWakeLock(long time)305 void acquireGestureWakeLock(long time); 306 resendMessage(int msg)307 void resendMessage(int msg); 308 resendMessage(Object msg)309 void resendMessage(Object msg); 310 setLastCameraLaunchSource(int source)311 void setLastCameraLaunchSource(int source); 312 setLaunchCameraOnFinishedGoingToSleep(boolean launch)313 void setLaunchCameraOnFinishedGoingToSleep(boolean launch); 314 setLaunchCameraOnFinishedWaking(boolean launch)315 void setLaunchCameraOnFinishedWaking(boolean launch); 316 setLaunchEmergencyActionOnFinishedGoingToSleep(boolean launch)317 void setLaunchEmergencyActionOnFinishedGoingToSleep(boolean launch); 318 setLaunchEmergencyActionOnFinishedWaking(boolean launch)319 void setLaunchEmergencyActionOnFinishedWaking(boolean launch); 320 getQSPanelController()321 QSPanelController getQSPanelController(); 322 323 /** @deprecated Use {@link DisplayMetricsRepository} instead. */ 324 @Deprecated getDisplayDensity()325 float getDisplayDensity(); 326 327 /** 328 * Forwards touch events to communal hub 329 */ handleCommunalHubTouch(MotionEvent event)330 void handleCommunalHubTouch(MotionEvent event); 331 332 public static class KeyboardShortcutsMessage { 333 final int mDeviceId; 334 KeyboardShortcutsMessage(int deviceId)335 KeyboardShortcutsMessage(int deviceId) { 336 mDeviceId = deviceId; 337 } 338 } 339 340 /** 341 * Sets launching activity over LS state in central surfaces. 342 */ setIsLaunchingActivityOverLockscreen( boolean isLaunchingActivityOverLockscreen, boolean dismissShade)343 void setIsLaunchingActivityOverLockscreen( 344 boolean isLaunchingActivityOverLockscreen, boolean dismissShade); 345 346 /** 347 * Gets an animation controller from a notification row. 348 */ getAnimatorControllerFromNotification( ExpandableNotificationRow associatedView)349 ActivityTransitionAnimator.Controller getAnimatorControllerFromNotification( 350 ExpandableNotificationRow associatedView); 351 } 352