1 /* 2 * Copyright (C) 2007 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 android.app; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.RequiresPermission; 23 import android.annotation.SystemApi; 24 import android.annotation.SystemService; 25 import android.annotation.TestApi; 26 import android.compat.annotation.UnsupportedAppUsage; 27 import android.content.Context; 28 import android.os.Binder; 29 import android.os.Build; 30 import android.os.Bundle; 31 import android.os.IBinder; 32 import android.os.RemoteException; 33 import android.os.ServiceManager; 34 import android.util.Pair; 35 import android.util.Slog; 36 import android.view.View; 37 38 import com.android.internal.statusbar.IStatusBarService; 39 import com.android.internal.statusbar.NotificationVisibility; 40 41 import java.lang.annotation.Retention; 42 import java.lang.annotation.RetentionPolicy; 43 44 /** 45 * Allows an app to control the status bar. 46 */ 47 @SystemService(Context.STATUS_BAR_SERVICE) 48 public class StatusBarManager { 49 50 /** @hide */ 51 public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND; 52 /** @hide */ 53 public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS; 54 /** @hide */ 55 public static final int DISABLE_NOTIFICATION_ALERTS 56 = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS; 57 58 /** @hide */ 59 @Deprecated 60 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 61 public static final int DISABLE_NOTIFICATION_TICKER 62 = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER; 63 /** @hide */ 64 public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO; 65 /** @hide */ 66 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; 67 /** @hide */ 68 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; 69 /** @hide */ 70 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; 71 /** @hide */ 72 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; 73 /** @hide */ 74 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH; 75 76 /** @hide */ 77 public static final int DISABLE_ONGOING_CALL_CHIP = View.STATUS_BAR_DISABLE_ONGOING_CALL_CHIP; 78 79 /** @hide */ 80 @Deprecated 81 public static final int DISABLE_NAVIGATION = 82 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; 83 84 /** @hide */ 85 public static final int DISABLE_NONE = 0x00000000; 86 87 /** @hide */ 88 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS 89 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER 90 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK 91 | DISABLE_SEARCH | DISABLE_ONGOING_CALL_CHIP; 92 93 /** @hide */ 94 @IntDef(flag = true, prefix = {"DISABLE_"}, value = { 95 DISABLE_NONE, 96 DISABLE_EXPAND, 97 DISABLE_NOTIFICATION_ICONS, 98 DISABLE_NOTIFICATION_ALERTS, 99 DISABLE_NOTIFICATION_TICKER, 100 DISABLE_SYSTEM_INFO, 101 DISABLE_HOME, 102 DISABLE_RECENT, 103 DISABLE_BACK, 104 DISABLE_CLOCK, 105 DISABLE_SEARCH, 106 DISABLE_ONGOING_CALL_CHIP 107 }) 108 @Retention(RetentionPolicy.SOURCE) 109 public @interface DisableFlags {} 110 111 /** 112 * Flag to disable quick settings. 113 * 114 * Setting this flag disables quick settings completely, but does not disable expanding the 115 * notification shade. 116 */ 117 /** @hide */ 118 public static final int DISABLE2_QUICK_SETTINGS = 1; 119 /** @hide */ 120 public static final int DISABLE2_SYSTEM_ICONS = 1 << 1; 121 /** @hide */ 122 public static final int DISABLE2_NOTIFICATION_SHADE = 1 << 2; 123 /** @hide */ 124 public static final int DISABLE2_GLOBAL_ACTIONS = 1 << 3; 125 /** @hide */ 126 public static final int DISABLE2_ROTATE_SUGGESTIONS = 1 << 4; 127 128 /** @hide */ 129 public static final int DISABLE2_NONE = 0x00000000; 130 131 /** @hide */ 132 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS | DISABLE2_SYSTEM_ICONS 133 | DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS | DISABLE2_ROTATE_SUGGESTIONS; 134 135 /** @hide */ 136 @IntDef(flag = true, prefix = { "DISABLE2_" }, value = { 137 DISABLE2_NONE, 138 DISABLE2_MASK, 139 DISABLE2_QUICK_SETTINGS, 140 DISABLE2_SYSTEM_ICONS, 141 DISABLE2_NOTIFICATION_SHADE, 142 DISABLE2_GLOBAL_ACTIONS, 143 DISABLE2_ROTATE_SUGGESTIONS 144 }) 145 @Retention(RetentionPolicy.SOURCE) 146 public @interface Disable2Flags {} 147 148 /** 149 * Default disable flags for setup 150 * 151 * @hide 152 */ 153 public static final int DEFAULT_SETUP_DISABLE_FLAGS = DISABLE_NOTIFICATION_ALERTS 154 | DISABLE_HOME | DISABLE_EXPAND | DISABLE_RECENT | DISABLE_CLOCK | DISABLE_SEARCH; 155 156 /** 157 * Default disable2 flags for setup 158 * 159 * @hide 160 */ 161 public static final int DEFAULT_SETUP_DISABLE2_FLAGS = DISABLE2_ROTATE_SUGGESTIONS; 162 163 /** 164 * disable flags to be applied when the device is sim-locked. 165 */ 166 private static final int DEFAULT_SIM_LOCKED_DISABLED_FLAGS = DISABLE_EXPAND; 167 168 /** @hide */ 169 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0; 170 /** @hide */ 171 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1; 172 173 /** @hide */ 174 public static final int WINDOW_STATUS_BAR = 1; 175 /** @hide */ 176 public static final int WINDOW_NAVIGATION_BAR = 2; 177 178 /** @hide */ 179 @IntDef(flag = true, prefix = { "WINDOW_" }, value = { 180 WINDOW_STATUS_BAR, 181 WINDOW_NAVIGATION_BAR 182 }) 183 @Retention(RetentionPolicy.SOURCE) 184 public @interface WindowType {} 185 186 /** @hide */ 187 public static final int WINDOW_STATE_SHOWING = 0; 188 /** @hide */ 189 public static final int WINDOW_STATE_HIDING = 1; 190 /** @hide */ 191 public static final int WINDOW_STATE_HIDDEN = 2; 192 193 /** @hide */ 194 @IntDef(flag = true, prefix = { "WINDOW_STATE_" }, value = { 195 WINDOW_STATE_SHOWING, 196 WINDOW_STATE_HIDING, 197 WINDOW_STATE_HIDDEN 198 }) 199 @Retention(RetentionPolicy.SOURCE) 200 public @interface WindowVisibleState {} 201 202 /** @hide */ 203 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0; 204 /** @hide */ 205 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1; 206 /** @hide */ 207 public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2; 208 209 @UnsupportedAppUsage 210 private Context mContext; 211 private IStatusBarService mService; 212 @UnsupportedAppUsage 213 private IBinder mToken = new Binder(); 214 215 @UnsupportedAppUsage StatusBarManager(Context context)216 StatusBarManager(Context context) { 217 mContext = context; 218 } 219 220 @UnsupportedAppUsage getService()221 private synchronized IStatusBarService getService() { 222 if (mService == null) { 223 mService = IStatusBarService.Stub.asInterface( 224 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 225 if (mService == null) { 226 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); 227 } 228 } 229 return mService; 230 } 231 232 /** 233 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. 234 * To re-enable everything, pass {@link #DISABLE_NONE}. 235 * 236 * @hide 237 */ 238 @UnsupportedAppUsage disable(int what)239 public void disable(int what) { 240 try { 241 final int userId = Binder.getCallingUserHandle().getIdentifier(); 242 final IStatusBarService svc = getService(); 243 if (svc != null) { 244 svc.disableForUser(what, mToken, mContext.getPackageName(), userId); 245 } 246 } catch (RemoteException ex) { 247 throw ex.rethrowFromSystemServer(); 248 } 249 } 250 251 /** 252 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags. 253 * To re-enable everything, pass {@link #DISABLE_NONE}. 254 * 255 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags. 256 * 257 * @hide 258 */ disable2(@isable2Flags int what)259 public void disable2(@Disable2Flags int what) { 260 try { 261 final int userId = Binder.getCallingUserHandle().getIdentifier(); 262 final IStatusBarService svc = getService(); 263 if (svc != null) { 264 svc.disable2ForUser(what, mToken, mContext.getPackageName(), userId); 265 } 266 } catch (RemoteException ex) { 267 throw ex.rethrowFromSystemServer(); 268 } 269 } 270 271 /** 272 * Simulate notification click for testing 273 * 274 * @hide 275 */ 276 @TestApi clickNotification(@ullable String key, int rank, int count, boolean visible)277 public void clickNotification(@Nullable String key, int rank, int count, boolean visible) { 278 clickNotificationInternal(key, rank, count, visible); 279 } 280 clickNotificationInternal(String key, int rank, int count, boolean visible)281 private void clickNotificationInternal(String key, int rank, int count, boolean visible) { 282 try { 283 final IStatusBarService svc = getService(); 284 if (svc != null) { 285 svc.onNotificationClick(key, 286 NotificationVisibility.obtain(key, rank, count, visible)); 287 } 288 } catch (RemoteException ex) { 289 throw ex.rethrowFromSystemServer(); 290 } 291 } 292 293 /** 294 * Simulate notification feedback for testing 295 * 296 * @hide 297 */ 298 @TestApi sendNotificationFeedback(@ullable String key, @Nullable Bundle feedback)299 public void sendNotificationFeedback(@Nullable String key, @Nullable Bundle feedback) { 300 try { 301 final IStatusBarService svc = getService(); 302 if (svc != null) { 303 svc.onNotificationFeedbackReceived(key, feedback); 304 } 305 } catch (RemoteException ex) { 306 throw ex.rethrowFromSystemServer(); 307 } 308 } 309 310 /** 311 * Expand the notifications panel. 312 * 313 * @hide 314 */ 315 @UnsupportedAppUsage 316 @TestApi expandNotificationsPanel()317 public void expandNotificationsPanel() { 318 try { 319 final IStatusBarService svc = getService(); 320 if (svc != null) { 321 svc.expandNotificationsPanel(); 322 } 323 } catch (RemoteException ex) { 324 throw ex.rethrowFromSystemServer(); 325 } 326 } 327 328 /** 329 * Collapse the notifications and settings panels. 330 * 331 * Starting in Android {@link Build.VERSION_CODES.S}, apps targeting SDK level {@link 332 * Build.VERSION_CODES.S} or higher will need {@link android.Manifest.permission.STATUS_BAR} 333 * permission to call this API. 334 * 335 * @hide 336 */ 337 @RequiresPermission(android.Manifest.permission.STATUS_BAR) 338 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "This operation" 339 + " is not allowed anymore, please see {@link android.content" 340 + ".Intent#ACTION_CLOSE_SYSTEM_DIALOGS} for more details.") 341 @TestApi collapsePanels()342 public void collapsePanels() { 343 344 try { 345 final IStatusBarService svc = getService(); 346 if (svc != null) { 347 svc.collapsePanels(); 348 } 349 } catch (RemoteException ex) { 350 throw ex.rethrowFromSystemServer(); 351 } 352 } 353 354 /** 355 * Toggles the notification panel. 356 * 357 * @hide 358 */ 359 @RequiresPermission(android.Manifest.permission.STATUS_BAR) 360 @TestApi togglePanel()361 public void togglePanel() { 362 try { 363 final IStatusBarService svc = getService(); 364 if (svc != null) { 365 svc.togglePanel(); 366 } 367 } catch (RemoteException ex) { 368 throw ex.rethrowFromSystemServer(); 369 } 370 } 371 372 /** 373 * Sends system keys to the status bar. 374 * 375 * @hide 376 */ 377 @RequiresPermission(android.Manifest.permission.STATUS_BAR) 378 @TestApi handleSystemKey(int key)379 public void handleSystemKey(int key) { 380 try { 381 final IStatusBarService svc = getService(); 382 if (svc != null) { 383 svc.handleSystemKey(key); 384 } 385 } catch (RemoteException ex) { 386 throw ex.rethrowFromSystemServer(); 387 } 388 } 389 390 /** 391 * Expand the settings panel. 392 * 393 * @hide 394 */ 395 @UnsupportedAppUsage expandSettingsPanel()396 public void expandSettingsPanel() { 397 expandSettingsPanel(null); 398 } 399 400 /** 401 * Expand the settings panel and open a subPanel. If the subpanel is null or does not have a 402 * corresponding tile, the QS panel is simply expanded 403 * 404 * @hide 405 */ 406 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) expandSettingsPanel(@ullable String subPanel)407 public void expandSettingsPanel(@Nullable String subPanel) { 408 try { 409 final IStatusBarService svc = getService(); 410 if (svc != null) { 411 svc.expandSettingsPanel(subPanel); 412 } 413 } catch (RemoteException ex) { 414 throw ex.rethrowFromSystemServer(); 415 } 416 } 417 418 /** @hide */ 419 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setIcon(String slot, int iconId, int iconLevel, String contentDescription)420 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { 421 try { 422 final IStatusBarService svc = getService(); 423 if (svc != null) { 424 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, 425 contentDescription); 426 } 427 } catch (RemoteException ex) { 428 throw ex.rethrowFromSystemServer(); 429 } 430 } 431 432 /** @hide */ 433 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) removeIcon(String slot)434 public void removeIcon(String slot) { 435 try { 436 final IStatusBarService svc = getService(); 437 if (svc != null) { 438 svc.removeIcon(slot); 439 } 440 } catch (RemoteException ex) { 441 throw ex.rethrowFromSystemServer(); 442 } 443 } 444 445 /** @hide */ 446 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setIconVisibility(String slot, boolean visible)447 public void setIconVisibility(String slot, boolean visible) { 448 try { 449 final IStatusBarService svc = getService(); 450 if (svc != null) { 451 svc.setIconVisibility(slot, visible); 452 } 453 } catch (RemoteException ex) { 454 throw ex.rethrowFromSystemServer(); 455 } 456 } 457 458 /** 459 * Enable or disable status bar elements (notifications, clock) which are inappropriate during 460 * device setup. 461 * 462 * @param disabled whether to apply or remove the disabled flags 463 * 464 * @hide 465 */ 466 @SystemApi 467 @RequiresPermission(android.Manifest.permission.STATUS_BAR) setDisabledForSetup(boolean disabled)468 public void setDisabledForSetup(boolean disabled) { 469 try { 470 final int userId = Binder.getCallingUserHandle().getIdentifier(); 471 final IStatusBarService svc = getService(); 472 if (svc != null) { 473 svc.disableForUser(disabled ? DEFAULT_SETUP_DISABLE_FLAGS : DISABLE_NONE, 474 mToken, mContext.getPackageName(), userId); 475 svc.disable2ForUser(disabled ? DEFAULT_SETUP_DISABLE2_FLAGS : DISABLE2_NONE, 476 mToken, mContext.getPackageName(), userId); 477 } 478 } catch (RemoteException ex) { 479 throw ex.rethrowFromSystemServer(); 480 } 481 } 482 483 /** 484 * Enable or disable expansion of the status bar. When the device is SIM-locked, the status 485 * bar should not be expandable. 486 * 487 * @param disabled If {@code true}, the status bar will be set to non-expandable. If 488 * {@code false}, re-enables expansion of the status bar. 489 * @hide 490 */ 491 @TestApi 492 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 493 @RequiresPermission(android.Manifest.permission.STATUS_BAR) setExpansionDisabledForSimNetworkLock(boolean disabled)494 public void setExpansionDisabledForSimNetworkLock(boolean disabled) { 495 try { 496 final int userId = Binder.getCallingUserHandle().getIdentifier(); 497 final IStatusBarService svc = getService(); 498 if (svc != null) { 499 svc.disableForUser(disabled ? DEFAULT_SIM_LOCKED_DISABLED_FLAGS : DISABLE_NONE, 500 mToken, mContext.getPackageName(), userId); 501 } 502 } catch (RemoteException ex) { 503 throw ex.rethrowFromSystemServer(); 504 } 505 } 506 507 /** 508 * Get this app's currently requested disabled components 509 * 510 * @return a new DisableInfo 511 * 512 * @hide 513 */ 514 @SystemApi 515 @RequiresPermission(android.Manifest.permission.STATUS_BAR) 516 @NonNull getDisableInfo()517 public DisableInfo getDisableInfo() { 518 try { 519 final int userId = Binder.getCallingUserHandle().getIdentifier(); 520 final IStatusBarService svc = getService(); 521 int[] flags = new int[] {0, 0}; 522 if (svc != null) { 523 flags = svc.getDisableFlags(mToken, userId); 524 } 525 526 return new DisableInfo(flags[0], flags[1]); 527 } catch (RemoteException ex) { 528 throw ex.rethrowFromSystemServer(); 529 } 530 } 531 532 /** @hide */ windowStateToString(int state)533 public static String windowStateToString(int state) { 534 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING"; 535 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN"; 536 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING"; 537 return "WINDOW_STATE_UNKNOWN"; 538 } 539 540 /** 541 * DisableInfo describes this app's requested state of the StatusBar with regards to which 542 * components are enabled/disabled 543 * 544 * @hide 545 */ 546 @SystemApi 547 public static final class DisableInfo { 548 549 private boolean mStatusBarExpansion; 550 private boolean mNavigateHome; 551 private boolean mNotificationPeeking; 552 private boolean mRecents; 553 private boolean mSearch; 554 private boolean mSystemIcons; 555 private boolean mClock; 556 private boolean mNotificationIcons; 557 558 /** @hide */ DisableInfo(int flags1, int flags2)559 public DisableInfo(int flags1, int flags2) { 560 mStatusBarExpansion = (flags1 & DISABLE_EXPAND) != 0; 561 mNavigateHome = (flags1 & DISABLE_HOME) != 0; 562 mNotificationPeeking = (flags1 & DISABLE_NOTIFICATION_ALERTS) != 0; 563 mRecents = (flags1 & DISABLE_RECENT) != 0; 564 mSearch = (flags1 & DISABLE_SEARCH) != 0; 565 mSystemIcons = (flags1 & DISABLE_SYSTEM_INFO) != 0; 566 mClock = (flags1 & DISABLE_CLOCK) != 0; 567 mNotificationIcons = (flags1 & DISABLE_NOTIFICATION_ICONS) != 0; 568 } 569 570 /** @hide */ DisableInfo()571 public DisableInfo() {} 572 573 /** 574 * @return {@code true} if expanding the notification shade is disabled 575 * 576 * @hide 577 */ 578 @SystemApi isStatusBarExpansionDisabled()579 public boolean isStatusBarExpansionDisabled() { 580 return mStatusBarExpansion; 581 } 582 583 /** * @hide */ setStatusBarExpansionDisabled(boolean disabled)584 public void setStatusBarExpansionDisabled(boolean disabled) { 585 mStatusBarExpansion = disabled; 586 } 587 588 /** 589 * @return {@code true} if navigation home is disabled 590 * 591 * @hide 592 */ 593 @SystemApi isNavigateToHomeDisabled()594 public boolean isNavigateToHomeDisabled() { 595 return mNavigateHome; 596 } 597 598 /** * @hide */ setNagivationHomeDisabled(boolean disabled)599 public void setNagivationHomeDisabled(boolean disabled) { 600 mNavigateHome = disabled; 601 } 602 603 /** 604 * @return {@code true} if notification peeking (heads-up notification) is disabled 605 * 606 * @hide 607 */ 608 @SystemApi isNotificationPeekingDisabled()609 public boolean isNotificationPeekingDisabled() { 610 return mNotificationPeeking; 611 } 612 613 /** @hide */ setNotificationPeekingDisabled(boolean disabled)614 public void setNotificationPeekingDisabled(boolean disabled) { 615 mNotificationPeeking = disabled; 616 } 617 618 /** 619 * @return {@code true} if mRecents/overview is disabled 620 * 621 * @hide 622 */ 623 @SystemApi isRecentsDisabled()624 public boolean isRecentsDisabled() { 625 return mRecents; 626 } 627 628 /** @hide */ setRecentsDisabled(boolean disabled)629 public void setRecentsDisabled(boolean disabled) { 630 mRecents = disabled; 631 } 632 633 /** 634 * @return {@code true} if mSearch is disabled 635 * 636 * @hide 637 */ 638 @SystemApi isSearchDisabled()639 public boolean isSearchDisabled() { 640 return mSearch; 641 } 642 643 /** @hide */ setSearchDisabled(boolean disabled)644 public void setSearchDisabled(boolean disabled) { 645 mSearch = disabled; 646 } 647 648 /** 649 * @return {@code true} if system icons are disabled 650 * 651 * @hide 652 */ areSystemIconsDisabled()653 public boolean areSystemIconsDisabled() { 654 return mSystemIcons; 655 } 656 657 /** * @hide */ setSystemIconsDisabled(boolean disabled)658 public void setSystemIconsDisabled(boolean disabled) { 659 mSystemIcons = disabled; 660 } 661 662 /** 663 * @return {@code true} if the clock icon is disabled 664 * 665 * @hide 666 */ isClockDisabled()667 public boolean isClockDisabled() { 668 return mClock; 669 } 670 671 /** * @hide */ setClockDisabled(boolean disabled)672 public void setClockDisabled(boolean disabled) { 673 mClock = disabled; 674 } 675 676 /** 677 * @return {@code true} if notification icons are disabled 678 * 679 * @hide 680 */ areNotificationIconsDisabled()681 public boolean areNotificationIconsDisabled() { 682 return mNotificationIcons; 683 } 684 685 /** * @hide */ setNotificationIconsDisabled(boolean disabled)686 public void setNotificationIconsDisabled(boolean disabled) { 687 mNotificationIcons = disabled; 688 } 689 690 /** 691 * @return {@code true} if no components are disabled (default state) 692 * 693 * @hide 694 */ 695 @SystemApi areAllComponentsEnabled()696 public boolean areAllComponentsEnabled() { 697 return !mStatusBarExpansion && !mNavigateHome && !mNotificationPeeking && !mRecents 698 && !mSearch && !mSystemIcons && !mClock && !mNotificationIcons; 699 } 700 701 /** @hide */ setEnableAll()702 public void setEnableAll() { 703 mStatusBarExpansion = false; 704 mNavigateHome = false; 705 mNotificationPeeking = false; 706 mRecents = false; 707 mSearch = false; 708 mSystemIcons = false; 709 mClock = false; 710 mNotificationIcons = false; 711 } 712 713 /** 714 * @return {@code true} if all status bar components are disabled 715 * 716 * @hide 717 */ areAllComponentsDisabled()718 public boolean areAllComponentsDisabled() { 719 return mStatusBarExpansion && mNavigateHome && mNotificationPeeking 720 && mRecents && mSearch && mSystemIcons && mClock && mNotificationIcons; 721 } 722 723 /** @hide */ setDisableAll()724 public void setDisableAll() { 725 mStatusBarExpansion = true; 726 mNavigateHome = true; 727 mNotificationPeeking = true; 728 mRecents = true; 729 mSearch = true; 730 mSystemIcons = true; 731 mClock = true; 732 mNotificationIcons = true; 733 } 734 735 @NonNull 736 @Override toString()737 public String toString() { 738 StringBuilder sb = new StringBuilder(); 739 sb.append("DisableInfo: "); 740 sb.append(" mStatusBarExpansion=").append(mStatusBarExpansion ? "disabled" : "enabled"); 741 sb.append(" mNavigateHome=").append(mNavigateHome ? "disabled" : "enabled"); 742 sb.append(" mNotificationPeeking=") 743 .append(mNotificationPeeking ? "disabled" : "enabled"); 744 sb.append(" mRecents=").append(mRecents ? "disabled" : "enabled"); 745 sb.append(" mSearch=").append(mSearch ? "disabled" : "enabled"); 746 sb.append(" mSystemIcons=").append(mSystemIcons ? "disabled" : "enabled"); 747 sb.append(" mClock=").append(mClock ? "disabled" : "enabled"); 748 sb.append(" mNotificationIcons=").append(mNotificationIcons ? "disabled" : "enabled"); 749 750 return sb.toString(); 751 752 } 753 754 /** 755 * Convert a DisableInfo to equivalent flags 756 * @return a pair of equivalent disable flags 757 * 758 * @hide 759 */ toFlags()760 public Pair<Integer, Integer> toFlags() { 761 int disable1 = DISABLE_NONE; 762 int disable2 = DISABLE2_NONE; 763 764 if (mStatusBarExpansion) disable1 |= DISABLE_EXPAND; 765 if (mNavigateHome) disable1 |= DISABLE_HOME; 766 if (mNotificationPeeking) disable1 |= DISABLE_NOTIFICATION_ALERTS; 767 if (mRecents) disable1 |= DISABLE_RECENT; 768 if (mSearch) disable1 |= DISABLE_SEARCH; 769 if (mSystemIcons) disable1 |= DISABLE_SYSTEM_INFO; 770 if (mClock) disable1 |= DISABLE_CLOCK; 771 if (mNotificationIcons) disable1 |= DISABLE_NOTIFICATION_ICONS; 772 773 return new Pair<Integer, Integer>(disable1, disable2); 774 } 775 } 776 } 777