TestWindowManagerPolicy.java revision fb1bf69d5d7fc8c45e3ddbb8916e21ae57432ff1
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 17package com.android.server.wm; 18 19import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; 20import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; 21import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; 22import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; 23import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; 24import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; 25import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; 26import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 27import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; 28import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; 29import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY; 30import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; 31import static android.view.WindowManager.LayoutParams.TYPE_DRAG; 32import static android.view.WindowManager.LayoutParams.TYPE_DREAM; 33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; 34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 36import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; 37import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; 38import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; 39import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; 40import static android.view.WindowManager.LayoutParams.TYPE_PHONE; 41import static android.view.WindowManager.LayoutParams.TYPE_POINTER; 42import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; 43import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; 44import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; 45import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; 46import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; 47import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; 48import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; 49import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 50import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; 51import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; 52import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; 53import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; 54import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 55import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; 56import static android.view.WindowManager.LayoutParams.TYPE_TOAST; 57import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; 58import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING; 59import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; 60import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 61import static org.mockito.Mockito.mock; 62 63import android.annotation.Nullable; 64import android.content.Context; 65import android.content.res.CompatibilityInfo; 66import android.content.res.Configuration; 67import android.graphics.Rect; 68import android.hardware.display.DisplayManagerInternal; 69import android.os.Bundle; 70import android.os.IBinder; 71import android.os.RemoteException; 72import android.util.Log; 73import android.view.Display; 74import android.view.IWindowManager; 75import android.view.KeyEvent; 76import android.view.WindowManager; 77import android.view.WindowManagerPolicy; 78import android.view.animation.Animation; 79import android.os.PowerManagerInternal; 80 81import com.android.internal.policy.IKeyguardDismissCallback; 82import com.android.internal.policy.IShortcutService; 83import com.android.server.input.InputManagerService; 84import com.android.server.LocalServices; 85 86import java.io.PrintWriter; 87 88class TestWindowManagerPolicy implements WindowManagerPolicy { 89 private static final String TAG = "TestWindowManagerPolicy"; 90 91 private static WindowManagerService sWm = null; 92 93 int rotationToReport = 0; 94 95 static synchronized WindowManagerService getWindowManagerService(Context context) { 96 if (sWm == null) { 97 // We only want to do this once for the test process as we don't want WM to try to 98 // register a bunch of local services again. 99 if (LocalServices.getService(DisplayManagerInternal.class) == null) { 100 LocalServices.addService(DisplayManagerInternal.class, 101 mock(DisplayManagerInternal.class)); 102 } 103 if (LocalServices.getService(PowerManagerInternal.class) == null) { 104 LocalServices.addService(PowerManagerInternal.class, 105 mock(PowerManagerInternal.class)); 106 } 107 sWm = WindowManagerService.main(context, mock(InputManagerService.class), true, false, 108 false, new TestWindowManagerPolicy()); 109 } 110 return sWm; 111 } 112 113 @Override 114 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutKeyReceiver) 115 throws RemoteException { 116 117 } 118 119 @Override 120 public void init(Context context, IWindowManager windowManager, 121 WindowManagerFuncs windowManagerFuncs) { 122 123 } 124 125 @Override 126 public boolean isDefaultOrientationForced() { 127 return false; 128 } 129 130 @Override 131 public void setInitialDisplaySize(Display display, int width, int height, int density) { 132 133 } 134 135 @Override 136 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { 137 138 } 139 140 @Override 141 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { 142 return 0; 143 } 144 145 @Override 146 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { 147 return false; 148 } 149 150 @Override 151 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { 152 153 } 154 155 @Override 156 public void adjustConfigurationLw(Configuration config, int keyboardPresence, 157 int navigationPresence) { 158 159 } 160 161 @Override 162 public int windowTypeToLayerLw(int type) { 163 // TODO: figure-out a good way to keep this in-sync with PhoneWindowManager...sigh! 164 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { 165 return 2; 166 } 167 switch (type) { 168 case TYPE_PRESENTATION: 169 case TYPE_PRIVATE_PRESENTATION: 170 return 2; 171 case TYPE_WALLPAPER: 172 // wallpaper is at the bottom, though the window manager may move it. 173 return 2; 174 case TYPE_DOCK_DIVIDER: 175 return 2; 176 case TYPE_QS_DIALOG: 177 return 2; 178 case TYPE_PHONE: 179 return 3; 180 case TYPE_SEARCH_BAR: 181 case TYPE_VOICE_INTERACTION_STARTING: 182 return 4; 183 case TYPE_VOICE_INTERACTION: 184 // voice interaction layer is almost immediately above apps. 185 return 5; 186 case TYPE_INPUT_CONSUMER: 187 return 6; 188 case TYPE_SYSTEM_DIALOG: 189 return 7; 190 case TYPE_TOAST: 191 // toasts and the plugged-in battery thing 192 return 8; 193 case TYPE_PRIORITY_PHONE: 194 // SIM errors and unlock. Not sure if this really should be in a high layer. 195 return 9; 196 case TYPE_DREAM: 197 // used for Dreams (screensavers with TYPE_DREAM windows) 198 return 10; 199 case TYPE_SYSTEM_ALERT: 200 // like the ANR / app crashed dialogs 201 return 11; 202 case TYPE_INPUT_METHOD: 203 // on-screen keyboards and other such input method user interfaces go here. 204 return 12; 205 case TYPE_INPUT_METHOD_DIALOG: 206 // on-screen keyboards and other such input method user interfaces go here. 207 return 13; 208 case TYPE_STATUS_BAR_SUB_PANEL: 209 return 15; 210 case TYPE_STATUS_BAR: 211 return 16; 212 case TYPE_STATUS_BAR_PANEL: 213 return 17; 214 case TYPE_KEYGUARD_DIALOG: 215 return 18; 216 case TYPE_VOLUME_OVERLAY: 217 // the on-screen volume indicator and controller shown when the user 218 // changes the device volume 219 return 19; 220 case TYPE_SYSTEM_OVERLAY: 221 // the on-screen volume indicator and controller shown when the user 222 // changes the device volume 223 return 20; 224 case TYPE_NAVIGATION_BAR: 225 // the navigation bar, if available, shows atop most things 226 return 21; 227 case TYPE_NAVIGATION_BAR_PANEL: 228 // some panels (e.g. search) need to show on top of the navigation bar 229 return 22; 230 case TYPE_SCREENSHOT: 231 // screenshot selection layer shouldn't go above system error, but it should cover 232 // navigation bars at the very least. 233 return 23; 234 case TYPE_SYSTEM_ERROR: 235 // system-level error dialogs 236 return 24; 237 case TYPE_MAGNIFICATION_OVERLAY: 238 // used to highlight the magnified portion of a display 239 return 25; 240 case TYPE_DISPLAY_OVERLAY: 241 // used to simulate secondary display devices 242 return 26; 243 case TYPE_DRAG: 244 // the drag layer: input for drag-and-drop is associated with this window, 245 // which sits above all other focusable windows 246 return 27; 247 case TYPE_ACCESSIBILITY_OVERLAY: 248 // overlay put by accessibility services to intercept user interaction 249 return 28; 250 case TYPE_SECURE_SYSTEM_OVERLAY: 251 return 29; 252 case TYPE_BOOT_PROGRESS: 253 return 30; 254 case TYPE_POINTER: 255 // the (mouse) pointer layer 256 return 31; 257 } 258 Log.e(TAG, "Unknown window type: " + type); 259 return 2; 260 } 261 262 @Override 263 public int subWindowTypeToLayerLw(int type) { 264 // TODO: figure-out a good way to keep this in-sync with PhoneWindowManager... 265 switch (type) { 266 case TYPE_APPLICATION_PANEL: 267 case TYPE_APPLICATION_ATTACHED_DIALOG: 268 return 1; 269 case TYPE_APPLICATION_MEDIA: 270 return -2; 271 case TYPE_APPLICATION_MEDIA_OVERLAY: 272 return -1; 273 case TYPE_APPLICATION_SUB_PANEL: 274 return 2; 275 case TYPE_APPLICATION_ABOVE_SUB_PANEL: 276 return 3; 277 } 278 Log.e(TAG, "Unknown sub-window type: " + type); 279 return 0; 280 } 281 282 @Override 283 public int getMaxWallpaperLayer() { 284 return 0; 285 } 286 287 @Override 288 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, 289 int displayId) { 290 return 0; 291 } 292 293 @Override 294 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, 295 int displayId) { 296 return 0; 297 } 298 299 @Override 300 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, 301 int displayId) { 302 return 0; 303 } 304 305 @Override 306 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, 307 int displayId) { 308 return 0; 309 } 310 311 @Override 312 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { 313 return false; 314 } 315 316 @Override 317 public boolean canBeHiddenByKeyguardLw(WindowState win) { 318 return false; 319 } 320 321 @Override 322 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme, 323 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, 324 int logo, int windowFlags, Configuration overrideConfig, int displayId) { 325 return null; 326 } 327 328 @Override 329 public int prepareAddWindowLw(WindowState win, 330 WindowManager.LayoutParams attrs) { 331 return 0; 332 } 333 334 @Override 335 public void removeWindowLw(WindowState win) { 336 337 } 338 339 @Override 340 public int selectAnimationLw(WindowState win, int transit) { 341 return 0; 342 } 343 344 @Override 345 public void selectRotationAnimationLw(int[] anim) { 346 347 } 348 349 @Override 350 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, 351 boolean forceDefault) { 352 return false; 353 } 354 355 @Override 356 public Animation createHiddenByKeyguardExit(boolean onWallpaper, 357 boolean goingToNotificationShade) { 358 return null; 359 } 360 361 @Override 362 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) { 363 return null; 364 } 365 366 @Override 367 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { 368 return 0; 369 } 370 371 @Override 372 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { 373 return 0; 374 } 375 376 @Override 377 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, 378 int policyFlags) { 379 return 0; 380 } 381 382 @Override 383 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, 384 int policyFlags) { 385 return null; 386 } 387 388 @Override 389 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, 390 int displayRotation, int uiMode) { 391 392 } 393 394 @Override 395 public int getSystemDecorLayerLw() { 396 return 0; 397 } 398 399 @Override 400 public void getContentRectLw(Rect r) { 401 402 } 403 404 @Override 405 public void layoutWindowLw(WindowState win, 406 WindowState attached) { 407 408 } 409 410 @Override 411 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds, 412 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets, 413 Rect outStableInsets, Rect outOutsets) { 414 return false; 415 } 416 417 @Override 418 public void finishLayoutLw() { 419 420 } 421 422 @Override 423 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { 424 425 } 426 427 @Override 428 public void applyPostLayoutPolicyLw(WindowState win, 429 WindowManager.LayoutParams attrs, WindowState attached, WindowState imeTarget) { 430 } 431 432 @Override 433 public int finishPostLayoutPolicyLw() { 434 return 0; 435 } 436 437 @Override 438 public boolean allowAppAnimationsLw() { 439 return false; 440 } 441 442 @Override 443 public int focusChangedLw(WindowState lastFocus, 444 WindowState newFocus) { 445 return 0; 446 } 447 448 @Override 449 public void startedWakingUp() { 450 451 } 452 453 @Override 454 public void finishedWakingUp() { 455 456 } 457 458 @Override 459 public void startedGoingToSleep(int why) { 460 461 } 462 463 @Override 464 public void finishedGoingToSleep(int why) { 465 466 } 467 468 @Override 469 public void screenTurningOn(ScreenOnListener screenOnListener) { 470 471 } 472 473 @Override 474 public void screenTurnedOn() { 475 476 } 477 478 @Override 479 public void screenTurnedOff() { 480 481 } 482 483 @Override 484 public boolean isScreenOn() { 485 return false; 486 } 487 488 @Override 489 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { 490 491 } 492 493 @Override 494 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { 495 496 } 497 498 @Override 499 public void enableKeyguard(boolean enabled) { 500 501 } 502 503 @Override 504 public void exitKeyguardSecurely(OnKeyguardExitResult callback) { 505 506 } 507 508 @Override 509 public boolean isKeyguardLocked() { 510 return false; 511 } 512 513 @Override 514 public boolean isKeyguardSecure(int userId) { 515 return false; 516 } 517 518 @Override 519 public boolean isKeyguardOccluded() { 520 return false; 521 } 522 523 @Override 524 public boolean isKeyguardTrustedLw() { 525 return false; 526 } 527 528 @Override 529 public boolean isKeyguardShowingAndNotOccluded() { 530 return false; 531 } 532 533 @Override 534 public boolean inKeyguardRestrictedKeyInputMode() { 535 return false; 536 } 537 538 @Override 539 public void dismissKeyguardLw(@Nullable IKeyguardDismissCallback callback) { 540 } 541 542 @Override 543 public boolean isKeyguardDrawnLw() { 544 return false; 545 } 546 547 @Override 548 public boolean isShowingDreamLw() { 549 return false; 550 } 551 552 @Override 553 public void onKeyguardOccludedChangedLw(boolean occluded) { 554 } 555 556 @Override 557 public int rotationForOrientationLw(int orientation, 558 int lastRotation) { 559 return rotationToReport; 560 } 561 562 @Override 563 public boolean rotationHasCompatibleMetricsLw(int orientation, 564 int rotation) { 565 return false; 566 } 567 568 @Override 569 public void setRotationLw(int rotation) { 570 571 } 572 573 @Override 574 public void setSafeMode(boolean safeMode) { 575 576 } 577 578 @Override 579 public void systemReady() { 580 581 } 582 583 @Override 584 public void systemBooted() { 585 586 } 587 588 @Override 589 public void showBootMessage(CharSequence msg, boolean always) { 590 591 } 592 593 @Override 594 public void hideBootMessages() { 595 596 } 597 598 @Override 599 public void userActivity() { 600 601 } 602 603 @Override 604 public void enableScreenAfterBoot() { 605 606 } 607 608 @Override 609 public void setCurrentOrientationLw(int newOrientation) { 610 611 } 612 613 @Override 614 public boolean performHapticFeedbackLw(WindowState win, int effectId, 615 boolean always) { 616 return false; 617 } 618 619 @Override 620 public void keepScreenOnStartedLw() { 621 622 } 623 624 @Override 625 public void keepScreenOnStoppedLw() { 626 627 } 628 629 @Override 630 public int getUserRotationMode() { 631 return 0; 632 } 633 634 @Override 635 public void setUserRotationMode(int mode, 636 int rotation) { 637 638 } 639 640 @Override 641 public int adjustSystemUiVisibilityLw(int visibility) { 642 return 0; 643 } 644 645 @Override 646 public boolean hasNavigationBar() { 647 return false; 648 } 649 650 @Override 651 public void lockNow(Bundle options) { 652 653 } 654 655 @Override 656 public void setLastInputMethodWindowLw(WindowState ime, 657 WindowState target) { 658 659 } 660 661 @Override 662 public void showRecentApps(boolean fromHome) { 663 664 } 665 666 @Override 667 public void showGlobalActions() { 668 669 } 670 671 @Override 672 public int getInputMethodWindowVisibleHeightLw() { 673 return 0; 674 } 675 676 @Override 677 public void setCurrentUserLw(int newUserId) { 678 679 } 680 681 @Override 682 public void setSwitchingUser(boolean switching) { 683 684 } 685 686 @Override 687 public void dump(String prefix, PrintWriter writer, String[] args) { 688 689 } 690 691 @Override 692 public boolean canMagnifyWindow(int windowType) { 693 return false; 694 } 695 696 @Override 697 public boolean isTopLevelWindow(int windowType) { 698 return false; 699 } 700 701 @Override 702 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { 703 704 } 705 706 @Override 707 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, 708 Rect outInsets) { 709 710 } 711 712 @Override 713 public boolean isNavBarForcedShownLw(WindowState win) { 714 return false; 715 } 716 717 @Override 718 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, 719 Rect outInsets) { 720 721 } 722 723 @Override 724 public boolean isDockSideAllowed(int dockSide) { 725 return false; 726 } 727 728 @Override 729 public void onConfigurationChanged() { 730 731 } 732 733 @Override 734 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) { 735 return false; 736 } 737 738 @Override 739 public void setTvPipVisibilityLw(boolean visible) { 740 741 } 742 743 @Override 744 public void setRecentsVisibilityLw(boolean visible) { 745 746 } 747} 748