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