1 /* 2 * Copyright (C) 2016 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.wm; 18 19 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; 20 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 21 22 import static org.mockito.Mockito.mock; 23 24 import android.annotation.Nullable; 25 import android.content.Context; 26 import android.content.res.CompatibilityInfo; 27 import android.content.res.Configuration; 28 import android.graphics.Rect; 29 import android.os.Bundle; 30 import android.os.IBinder; 31 import android.os.RemoteException; 32 import android.util.proto.ProtoOutputStream; 33 import android.view.Display; 34 import android.view.DisplayCutout; 35 import android.view.IWindow; 36 import android.view.IWindowManager; 37 import android.view.KeyEvent; 38 import android.view.WindowManager; 39 import android.view.animation.Animation; 40 41 import com.android.internal.policy.IKeyguardDismissCallback; 42 import com.android.internal.policy.IShortcutService; 43 import com.android.server.policy.WindowManagerPolicy; 44 45 import java.io.PrintWriter; 46 import java.util.function.Supplier; 47 48 class TestWindowManagerPolicy implements WindowManagerPolicy { 49 private static final String TAG = "TestWindowManagerPolicy"; 50 51 private final Supplier<WindowManagerService> mWmSupplier; 52 53 int rotationToReport = 0; 54 boolean keyguardShowingAndNotOccluded = false; 55 56 private Runnable mRunnableWhenAddingSplashScreen; 57 58 public TestWindowManagerPolicy(Supplier<WindowManagerService> wmSupplier) { 59 60 mWmSupplier = wmSupplier; 61 } 62 63 @Override 64 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver) 65 throws RemoteException { 66 67 } 68 69 @Override 70 public void init(Context context, IWindowManager windowManager, 71 WindowManagerFuncs windowManagerFuncs) { 72 73 } 74 75 @Override 76 public boolean isDefaultOrientationForced() { 77 return false; 78 } 79 80 @Override 81 public void setInitialDisplaySize(Display display, int width, int height, int density) { 82 83 } 84 85 @Override 86 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { 87 return 0; 88 } 89 90 @Override 91 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { 92 return false; 93 } 94 95 @Override 96 public void adjustWindowParamsLw(WindowState win, WindowManager.LayoutParams attrs, 97 boolean hasStatusBarServicePermission) { 98 } 99 100 @Override 101 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 102 int navigationPresence) { 103 104 } 105 106 @Override 107 public int getMaxWallpaperLayer() { 108 return 0; 109 } 110 111 @Override 112 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, 113 int displayId, DisplayCutout displayCutout) { 114 return 0; 115 } 116 117 @Override 118 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, 119 int displayId, DisplayCutout displayCutout) { 120 return 0; 121 } 122 123 @Override 124 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, 125 int displayId, DisplayCutout displayCutout) { 126 return 0; 127 } 128 129 @Override 130 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, 131 int displayId, DisplayCutout displayCutout) { 132 return 0; 133 } 134 135 @Override 136 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { 137 return attrs.type == TYPE_STATUS_BAR; 138 } 139 140 @Override 141 public boolean canBeHiddenByKeyguardLw(WindowState win) { 142 return false; 143 } 144 145 /** 146 * Sets a runnable to run when adding a splash screen which gets executed after the window has 147 * been added but before returning the surface. 148 */ 149 void setRunnableWhenAddingSplashScreen(Runnable r) { 150 mRunnableWhenAddingSplashScreen = r; 151 } 152 153 @Override 154 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, 155 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, 156 int logo, int windowFlags, Configuration overrideConfig, int displayId) { 157 final com.android.server.wm.WindowState window; 158 final AppWindowToken atoken; 159 final WindowManagerService wm = mWmSupplier.get(); 160 synchronized (wm.mWindowMap) { 161 atoken = wm.mRoot.getAppWindowToken(appToken); 162 window = WindowTestsBase.createWindow(null, TYPE_APPLICATION_STARTING, atoken, 163 "Starting window", 0 /* ownerId */, false /* internalWindows */, wm, 164 mock(Session.class), mock(IWindow.class)); 165 atoken.startingWindow = window; 166 } 167 if (mRunnableWhenAddingSplashScreen != null) { 168 mRunnableWhenAddingSplashScreen.run(); 169 mRunnableWhenAddingSplashScreen = null; 170 } 171 return () -> { 172 synchronized (wm.mWindowMap) { 173 atoken.removeChild(window); 174 atoken.startingWindow = null; 175 } 176 }; 177 } 178 179 @Override 180 public int prepareAddWindowLw(WindowState win, 181 WindowManager.LayoutParams attrs) { 182 return 0; 183 } 184 185 @Override 186 public void removeWindowLw(WindowState win) { 187 188 } 189 190 @Override 191 public int selectAnimationLw(WindowState win, int transit) { 192 return 0; 193 } 194 195 @Override 196 public void selectRotationAnimationLw(int[] anim) { 197 198 } 199 200 @Override 201 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, 202 boolean forceDefault) { 203 return false; 204 } 205 206 @Override 207 public Animation createHiddenByKeyguardExit(boolean onWallpaper, 208 boolean goingToNotificationShade) { 209 return null; 210 } 211 212 @Override 213 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) { 214 return null; 215 } 216 217 @Override 218 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { 219 return 0; 220 } 221 222 @Override 223 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { 224 return 0; 225 } 226 227 @Override 228 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, 229 int policyFlags) { 230 return 0; 231 } 232 233 @Override 234 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, 235 int policyFlags) { 236 return null; 237 } 238 239 @Override 240 public int getSystemDecorLayerLw() { 241 return 0; 242 } 243 244 @Override 245 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { 246 247 } 248 249 @Override 250 public void applyPostLayoutPolicyLw(WindowState win, 251 WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) { 252 } 253 254 @Override 255 public int finishPostLayoutPolicyLw() { 256 return 0; 257 } 258 259 @Override 260 public boolean allowAppAnimationsLw() { 261 return false; 262 } 263 264 @Override 265 public int focusChangedLw(WindowState lastFocus, 266 WindowState newFocus) { 267 return 0; 268 } 269 270 @Override 271 public void startedWakingUp() { 272 273 } 274 275 @Override 276 public void finishedWakingUp() { 277 278 } 279 280 @Override 281 public void startedGoingToSleep(int why) { 282 283 } 284 285 @Override 286 public void finishedGoingToSleep(int why) { 287 288 } 289 290 @Override 291 public void screenTurningOn(ScreenOnListener screenOnListener) { 292 293 } 294 295 @Override 296 public void screenTurnedOn() { 297 298 } 299 300 @Override 301 public void screenTurningOff(ScreenOffListener screenOffListener) { 302 303 } 304 305 @Override 306 public void screenTurnedOff() { 307 308 } 309 310 @Override 311 public boolean isScreenOn() { 312 return true; 313 } 314 315 @Override 316 public boolean okToAnimate() { 317 return true; 318 } 319 320 @Override 321 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { 322 323 } 324 325 @Override 326 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { 327 328 } 329 330 @Override 331 public void enableKeyguard(boolean enabled) { 332 333 } 334 335 @Override 336 public void exitKeyguardSecurely(OnKeyguardExitResult callback) { 337 338 } 339 340 @Override 341 public boolean isKeyguardLocked() { 342 return keyguardShowingAndNotOccluded; 343 } 344 345 @Override 346 public boolean isKeyguardSecure(int userId) { 347 return false; 348 } 349 350 @Override 351 public boolean isKeyguardOccluded() { 352 return false; 353 } 354 355 @Override 356 public boolean isKeyguardTrustedLw() { 357 return false; 358 } 359 360 @Override 361 public boolean isKeyguardShowingAndNotOccluded() { 362 return keyguardShowingAndNotOccluded; 363 } 364 365 @Override 366 public boolean inKeyguardRestrictedKeyInputMode() { 367 return false; 368 } 369 370 @Override 371 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback, 372 CharSequence message) { 373 } 374 375 @Override 376 public boolean isKeyguardDrawnLw() { 377 return false; 378 } 379 380 @Override 381 public boolean isShowingDreamLw() { 382 return false; 383 } 384 385 @Override 386 public void onKeyguardOccludedChangedLw(boolean occluded) { 387 } 388 389 @Override 390 public int rotationForOrientationLw(int orientation, int lastRotation, boolean defaultDisplay) { 391 return rotationToReport; 392 } 393 394 @Override 395 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { 396 return true; 397 } 398 399 @Override 400 public void setRotationLw(int rotation) { 401 402 } 403 404 @Override 405 public void setSafeMode(boolean safeMode) { 406 407 } 408 409 @Override 410 public void systemReady() { 411 412 } 413 414 @Override 415 public void systemBooted() { 416 417 } 418 419 @Override 420 public void showBootMessage(CharSequence msg, boolean always) { 421 422 } 423 424 @Override 425 public void hideBootMessages() { 426 427 } 428 429 @Override 430 public void userActivity() { 431 432 } 433 434 @Override 435 public void enableScreenAfterBoot() { 436 437 } 438 439 @Override 440 public void setCurrentOrientationLw(int newOrientation) { 441 442 } 443 444 @Override 445 public boolean performHapticFeedbackLw(WindowState win, int effectId, 446 boolean always) { 447 return false; 448 } 449 450 @Override 451 public void keepScreenOnStartedLw() { 452 453 } 454 455 @Override 456 public void keepScreenOnStoppedLw() { 457 458 } 459 460 @Override 461 public int getUserRotationMode() { 462 return 0; 463 } 464 465 @Override 466 public void setUserRotationMode(int mode, 467 int rotation) { 468 469 } 470 471 @Override 472 public int adjustSystemUiVisibilityLw(int visibility) { 473 return 0; 474 } 475 476 @Override 477 public boolean hasNavigationBar() { 478 return false; 479 } 480 481 @Override 482 public void lockNow(Bundle options) { 483 484 } 485 486 @Override 487 public void setLastInputMethodWindowLw(WindowState ime, 488 WindowState target) { 489 490 } 491 492 @Override 493 public void showRecentApps() { 494 495 } 496 497 @Override 498 public void showGlobalActions() { 499 500 } 501 502 @Override 503 public void setCurrentUserLw(int newUserId) { 504 505 } 506 507 @Override 508 public void setSwitchingUser(boolean switching) { 509 510 } 511 512 @Override 513 public void writeToProto(ProtoOutputStream proto, long fieldId) { 514 515 } 516 517 @Override 518 public void dump(String prefix, PrintWriter writer, String[] args) { 519 520 } 521 522 @Override 523 public boolean isTopLevelWindow(int windowType) { 524 return false; 525 } 526 527 @Override 528 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { 529 530 } 531 532 @Override 533 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, 534 DisplayCutout cutout, Rect outInsets) { 535 536 } 537 538 @Override 539 public boolean isNavBarForcedShownLw(WindowState win) { 540 return false; 541 } 542 543 @NavigationBarPosition 544 @Override 545 public int getNavBarPosition() { 546 return NAV_BAR_BOTTOM; 547 } 548 549 @Override 550 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, 551 DisplayCutout cutout, Rect outInsets) { 552 553 } 554 555 @Override 556 public boolean isDockSideAllowed(int dockSide, int originalDockSide, int displayWidth, 557 int displayHeight, int displayRotation) { 558 return false; 559 } 560 561 @Override 562 public void onConfigurationChanged() { 563 564 } 565 566 @Override 567 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) { 568 return false; 569 } 570 571 @Override 572 public void setPipVisibilityLw(boolean visible) { 573 574 } 575 576 @Override 577 public void setRecentsVisibilityLw(boolean visible) { 578 579 } 580 581 @Override 582 public void setNavBarVirtualKeyHapticFeedbackEnabledLw(boolean enabled) { 583 } 584 585 @Override 586 public void onSystemUiStarted() { 587 } 588 589 @Override 590 public boolean canDismissBootAnimation() { 591 return true; 592 } 593 594 @Override 595 public void requestUserActivityNotification() { 596 } 597 598 @Override 599 public void onLockTaskStateChangedLw(int lockTaskState) { 600 } 601 602 @Override 603 public boolean setAodShowing(boolean aodShowing) { 604 return false; 605 } 606 } 607