| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.Manifest; |
| 20 |
import android.annotation.IntDef; |
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.annotation.RequiresPermission; |
| 24 |
import android.annotation.SystemApi; |
| 25 |
import android.annotation.SystemService; |
| 26 |
import android.annotation.TestApi; |
| 27 |
import android.app.compat.CompatChanges; |
| 28 |
import android.compat.annotation.ChangeId; |
| 29 |
import android.compat.annotation.EnabledSince; |
| 30 |
import android.compat.annotation.UnsupportedAppUsage; |
| 31 |
import android.content.ComponentName; |
| 32 |
import android.content.Context; |
| 33 |
import android.graphics.drawable.Icon; |
| 34 |
import android.media.INearbyMediaDevicesProvider; |
| 35 |
import android.media.INearbyMediaDevicesUpdateCallback; |
| 36 |
import android.media.MediaRoute2Info; |
| 37 |
import android.media.NearbyDevice; |
| 38 |
import android.media.NearbyMediaDevicesProvider; |
| 39 |
import android.os.Binder; |
| 40 |
import android.os.Build; |
| 41 |
import android.os.Bundle; |
| 42 |
import android.os.IBinder; |
| 43 |
import android.os.RemoteException; |
| 44 |
import android.os.ServiceManager; |
| 45 |
import android.os.UserHandle; |
| 46 |
import android.util.Pair; |
| 47 |
import android.util.Slog; |
| 48 |
import android.view.View; |
| 49 |
|
| 50 |
import com.android.internal.statusbar.IAddTileResultCallback; |
| 51 |
import com.android.internal.statusbar.IStatusBarService; |
| 52 |
import com.android.internal.statusbar.IUndoMediaTransferCallback; |
| 53 |
import com.android.internal.statusbar.NotificationVisibility; |
| 54 |
|
| 55 |
import java.lang.annotation.Retention; |
| 56 |
import java.lang.annotation.RetentionPolicy; |
| 57 |
import java.util.HashMap; |
| 58 |
import java.util.List; |
| 59 |
import java.util.Map; |
| 60 |
import java.util.Objects; |
| 61 |
import java.util.Set; |
| 62 |
import java.util.concurrent.Executor; |
| 63 |
import java.util.function.Consumer; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
@SystemService(Context.STATUS_BAR_SERVICE) |
| 69 |
public class StatusBarManager { |
| 70 |
|
| 71 |
|
| 72 |
public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND; |
| 73 |
|
| 74 |
public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS; |
| 75 |
|
| 76 |
public static final int DISABLE_NOTIFICATION_ALERTS |
| 77 |
= View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS; |
| 78 |
|
| 79 |
|
| 80 |
@Deprecated |
| 81 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 82 |
public static final int DISABLE_NOTIFICATION_TICKER |
| 83 |
= View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER; |
| 84 |
|
| 85 |
public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO; |
| 86 |
|
| 87 |
public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; |
| 88 |
|
| 89 |
public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; |
| 90 |
|
| 91 |
public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; |
| 92 |
|
| 93 |
public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; |
| 94 |
|
| 95 |
public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH; |
| 96 |
|
| 97 |
|
| 98 |
public static final int DISABLE_ONGOING_CALL_CHIP = View.STATUS_BAR_DISABLE_ONGOING_CALL_CHIP; |
| 99 |
|
| 100 |
|
| 101 |
@Deprecated |
| 102 |
public static final int DISABLE_NAVIGATION = |
| 103 |
View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; |
| 104 |
|
| 105 |
|
| 106 |
public static final int DISABLE_NONE = 0x00000000; |
| 107 |
|
| 108 |
|
| 109 |
public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS |
| 110 |
| DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER |
| 111 |
| DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK |
| 112 |
| DISABLE_SEARCH | DISABLE_ONGOING_CALL_CHIP; |
| 113 |
|
| 114 |
|
| 115 |
@IntDef(flag = true, prefix = {"DISABLE_"}, value = { |
| 116 |
DISABLE_NONE, |
| 117 |
DISABLE_EXPAND, |
| 118 |
DISABLE_NOTIFICATION_ICONS, |
| 119 |
DISABLE_NOTIFICATION_ALERTS, |
| 120 |
DISABLE_NOTIFICATION_TICKER, |
| 121 |
DISABLE_SYSTEM_INFO, |
| 122 |
DISABLE_HOME, |
| 123 |
DISABLE_RECENT, |
| 124 |
DISABLE_BACK, |
| 125 |
DISABLE_CLOCK, |
| 126 |
DISABLE_SEARCH, |
| 127 |
DISABLE_ONGOING_CALL_CHIP |
| 128 |
}) |
| 129 |
@Retention(RetentionPolicy.SOURCE) |
| 130 |
public @interface DisableFlags {} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public static final int DISABLE2_QUICK_SETTINGS = 1; |
| 140 |
|
| 141 |
public static final int DISABLE2_SYSTEM_ICONS = 1 << 1; |
| 142 |
|
| 143 |
public static final int DISABLE2_NOTIFICATION_SHADE = 1 << 2; |
| 144 |
|
| 145 |
public static final int DISABLE2_GLOBAL_ACTIONS = 1 << 3; |
| 146 |
|
| 147 |
public static final int DISABLE2_ROTATE_SUGGESTIONS = 1 << 4; |
| 148 |
|
| 149 |
|
| 150 |
public static final int DISABLE2_NONE = 0x00000000; |
| 151 |
|
| 152 |
|
| 153 |
public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS | DISABLE2_SYSTEM_ICONS |
| 154 |
| DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS | DISABLE2_ROTATE_SUGGESTIONS; |
| 155 |
|
| 156 |
|
| 157 |
@IntDef(flag = true, prefix = { "DISABLE2_" }, value = { |
| 158 |
DISABLE2_NONE, |
| 159 |
DISABLE2_MASK, |
| 160 |
DISABLE2_QUICK_SETTINGS, |
| 161 |
DISABLE2_SYSTEM_ICONS, |
| 162 |
DISABLE2_NOTIFICATION_SHADE, |
| 163 |
DISABLE2_GLOBAL_ACTIONS, |
| 164 |
DISABLE2_ROTATE_SUGGESTIONS |
| 165 |
}) |
| 166 |
@Retention(RetentionPolicy.SOURCE) |
| 167 |
public @interface Disable2Flags {} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public static final int DEFAULT_SETUP_DISABLE_FLAGS = DISABLE_NOTIFICATION_ALERTS |
| 176 |
| DISABLE_HOME | DISABLE_EXPAND | DISABLE_RECENT | DISABLE_CLOCK | DISABLE_SEARCH; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static final int DEFAULT_SETUP_DISABLE2_FLAGS = DISABLE2_NONE; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
private static final int DEFAULT_SIM_LOCKED_DISABLED_FLAGS = DISABLE_EXPAND; |
| 189 |
|
| 190 |
|
| 191 |
public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0; |
| 192 |
|
| 193 |
public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1; |
| 194 |
|
| 195 |
public static final int NAVIGATION_HINT_IME_SWITCHER_SHOWN = 1 << 2; |
| 196 |
|
| 197 |
|
| 198 |
public static final int WINDOW_STATUS_BAR = 1; |
| 199 |
|
| 200 |
public static final int WINDOW_NAVIGATION_BAR = 2; |
| 201 |
|
| 202 |
|
| 203 |
@IntDef(flag = true, prefix = { "WINDOW_" }, value = { |
| 204 |
WINDOW_STATUS_BAR, |
| 205 |
WINDOW_NAVIGATION_BAR |
| 206 |
}) |
| 207 |
@Retention(RetentionPolicy.SOURCE) |
| 208 |
public @interface WindowType {} |
| 209 |
|
| 210 |
|
| 211 |
public static final int WINDOW_STATE_SHOWING = 0; |
| 212 |
|
| 213 |
public static final int WINDOW_STATE_HIDING = 1; |
| 214 |
|
| 215 |
public static final int WINDOW_STATE_HIDDEN = 2; |
| 216 |
|
| 217 |
|
| 218 |
@IntDef(flag = true, prefix = { "WINDOW_STATE_" }, value = { |
| 219 |
WINDOW_STATE_SHOWING, |
| 220 |
WINDOW_STATE_HIDING, |
| 221 |
WINDOW_STATE_HIDDEN |
| 222 |
}) |
| 223 |
@Retention(RetentionPolicy.SOURCE) |
| 224 |
public @interface WindowVisibleState {} |
| 225 |
|
| 226 |
|
| 227 |
public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0; |
| 228 |
|
| 229 |
public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1; |
| 230 |
|
| 231 |
public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2; |
| 232 |
|
| 233 |
public static final int CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE = 3; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
public static final int SESSION_KEYGUARD = 1 << 0; |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public static final int SESSION_BIOMETRIC_PROMPT = 1 << 1; |
| 251 |
|
| 252 |
|
| 253 |
public static final Set<Integer> ALL_SESSIONS = Set.of( |
| 254 |
SESSION_KEYGUARD, |
| 255 |
SESSION_BIOMETRIC_PROMPT |
| 256 |
); |
| 257 |
|
| 258 |
|
| 259 |
@Retention(RetentionPolicy.SOURCE) |
| 260 |
@IntDef(flag = true, prefix = { "SESSION_KEYGUARD" }, value = { |
| 261 |
SESSION_KEYGUARD, |
| 262 |
SESSION_BIOMETRIC_PROMPT, |
| 263 |
}) |
| 264 |
public @interface SessionFlags {} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public static final int TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED = 0; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
public static final int TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED = 1; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public static final int TILE_ADD_REQUEST_RESULT_TILE_ADDED = 2; |
| 278 |
|
| 279 |
public static final int TILE_ADD_REQUEST_RESULT_DIALOG_DISMISSED = 3; |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
private static final int TILE_ADD_REQUEST_FIRST_ERROR_CODE = 1000; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public static final int TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE = |
| 291 |
TILE_ADD_REQUEST_FIRST_ERROR_CODE; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
public static final int TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS = |
| 296 |
TILE_ADD_REQUEST_FIRST_ERROR_CODE + 1; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
public static final int TILE_ADD_REQUEST_ERROR_BAD_COMPONENT = |
| 302 |
TILE_ADD_REQUEST_FIRST_ERROR_CODE + 2; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
public static final int TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER = |
| 307 |
TILE_ADD_REQUEST_FIRST_ERROR_CODE + 3; |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
public static final int TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND = |
| 312 |
TILE_ADD_REQUEST_FIRST_ERROR_CODE + 4; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
public static final int TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE = |
| 318 |
TILE_ADD_REQUEST_FIRST_ERROR_CODE + 5; |
| 319 |
|
| 320 |
|
| 321 |
@IntDef(prefix = {"TILE_ADD_REQUEST"}, value = { |
| 322 |
TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED, |
| 323 |
TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED, |
| 324 |
TILE_ADD_REQUEST_RESULT_TILE_ADDED, |
| 325 |
TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE, |
| 326 |
TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS, |
| 327 |
TILE_ADD_REQUEST_ERROR_BAD_COMPONENT, |
| 328 |
TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER, |
| 329 |
TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND, |
| 330 |
TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE |
| 331 |
}) |
| 332 |
@Retention(RetentionPolicy.SOURCE) |
| 333 |
public @interface RequestResult {} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
@SystemApi |
| 341 |
public static final int NAV_BAR_MODE_DEFAULT = 0; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
@SystemApi |
| 352 |
public static final int NAV_BAR_MODE_KIDS = 1; |
| 353 |
|
| 354 |
|
| 355 |
@IntDef(prefix = {"NAV_BAR_MODE_"}, value = { |
| 356 |
NAV_BAR_MODE_DEFAULT, |
| 357 |
NAV_BAR_MODE_KIDS |
| 358 |
}) |
| 359 |
@Retention(RetentionPolicy.SOURCE) |
| 360 |
public @interface NavBarMode {} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
@SystemApi |
| 380 |
public static final int MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_START_CAST = 0; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
@SystemApi |
| 399 |
public static final int MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_END_CAST = 1; |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
@SystemApi |
| 412 |
public static final int MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_TRIGGERED = 2; |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
@SystemApi |
| 425 |
public static final int MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_TRIGGERED = 3; |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
@SystemApi |
| 438 |
public static final int MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED = 4; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
@SystemApi |
| 451 |
public static final int MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED = 5; |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
@SystemApi |
| 459 |
public static final int MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_FAILED = 6; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
@SystemApi |
| 467 |
public static final int MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_FAILED = 7; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
@SystemApi |
| 475 |
public static final int MEDIA_TRANSFER_SENDER_STATE_FAR_FROM_RECEIVER = 8; |
| 476 |
|
| 477 |
|
| 478 |
@IntDef(prefix = {"MEDIA_TRANSFER_SENDER_STATE_"}, value = { |
| 479 |
MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_START_CAST, |
| 480 |
MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_END_CAST, |
| 481 |
MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_TRIGGERED, |
| 482 |
MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_TRIGGERED, |
| 483 |
MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED, |
| 484 |
MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED, |
| 485 |
MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_FAILED, |
| 486 |
MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_FAILED, |
| 487 |
MEDIA_TRANSFER_SENDER_STATE_FAR_FROM_RECEIVER, |
| 488 |
}) |
| 489 |
@Retention(RetentionPolicy.SOURCE) |
| 490 |
public @interface MediaTransferSenderState {} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
@SystemApi |
| 504 |
public static final int MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER = 0; |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
@SystemApi |
| 512 |
public static final int MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER = 1; |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public static final int MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED = 2; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
public static final int MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_FAILED = 3; |
| 527 |
|
| 528 |
|
| 529 |
@IntDef(prefix = {"MEDIA_TRANSFER_RECEIVER_STATE_"}, value = { |
| 530 |
MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER, |
| 531 |
MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER, |
| 532 |
MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED, |
| 533 |
MEDIA_TRANSFER_RECEIVER_STATE_TRANSFER_TO_RECEIVER_FAILED, |
| 534 |
}) |
| 535 |
@Retention(RetentionPolicy.SOURCE) |
| 536 |
public @interface MediaTransferReceiverState {} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
private final Map<NearbyMediaDevicesProvider, NearbyMediaDevicesProviderWrapper> |
| 546 |
nearbyMediaDevicesProviderMap = new HashMap<>(); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
@ChangeId |
| 566 |
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 567 |
private static final long MEDIA_CONTROL_SESSION_ACTIONS = 203800354L; |
| 568 |
|
| 569 |
@UnsupportedAppUsage |
| 570 |
private Context mContext; |
| 571 |
private IStatusBarService mService; |
| 572 |
@UnsupportedAppUsage |
| 573 |
private IBinder mToken = new Binder(); |
| 574 |
|
| 575 |
@UnsupportedAppUsage |
| 576 |
StatusBarManager(Context context) { |
| 577 |
mContext = context; |
| 578 |
} |
| 579 |
|
| 580 |
@UnsupportedAppUsage |
| 581 |
private synchronized IStatusBarService getService() { |
| 582 |
if (mService == null) { |
| 583 |
mService = IStatusBarService.Stub.asInterface( |
| 584 |
ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 585 |
if (mService == null) { |
| 586 |
Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 587 |
} |
| 588 |
} |
| 589 |
return mService; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
@UnsupportedAppUsage |
| 599 |
public void disable(int what) { |
| 600 |
try { |
| 601 |
final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 602 |
final IStatusBarService svc = getService(); |
| 603 |
if (svc != null) { |
| 604 |
svc.disableForUser(what, mToken, mContext.getPackageName(), userId); |
| 605 |
} |
| 606 |
} catch (RemoteException ex) { |
| 607 |
throw ex.rethrowFromSystemServer(); |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
public void disable2(@Disable2Flags int what) { |
| 620 |
try { |
| 621 |
final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 622 |
final IStatusBarService svc = getService(); |
| 623 |
if (svc != null) { |
| 624 |
svc.disable2ForUser(what, mToken, mContext.getPackageName(), userId); |
| 625 |
} |
| 626 |
} catch (RemoteException ex) { |
| 627 |
throw ex.rethrowFromSystemServer(); |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
@TestApi |
| 637 |
public void clickNotification(@Nullable String key, int rank, int count, boolean visible) { |
| 638 |
clickNotificationInternal(key, rank, count, visible); |
| 639 |
} |
| 640 |
|
| 641 |
private void clickNotificationInternal(String key, int rank, int count, boolean visible) { |
| 642 |
try { |
| 643 |
final IStatusBarService svc = getService(); |
| 644 |
if (svc != null) { |
| 645 |
svc.onNotificationClick(key, |
| 646 |
NotificationVisibility.obtain(key, rank, count, visible)); |
| 647 |
} |
| 648 |
} catch (RemoteException ex) { |
| 649 |
throw ex.rethrowFromSystemServer(); |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
@TestApi |
| 659 |
public void sendNotificationFeedback(@Nullable String key, @Nullable Bundle feedback) { |
| 660 |
try { |
| 661 |
final IStatusBarService svc = getService(); |
| 662 |
if (svc != null) { |
| 663 |
svc.onNotificationFeedbackReceived(key, feedback); |
| 664 |
} |
| 665 |
} catch (RemoteException ex) { |
| 666 |
throw ex.rethrowFromSystemServer(); |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
@UnsupportedAppUsage |
| 676 |
@TestApi |
| 677 |
public void expandNotificationsPanel() { |
| 678 |
try { |
| 679 |
final IStatusBarService svc = getService(); |
| 680 |
if (svc != null) { |
| 681 |
svc.expandNotificationsPanel(); |
| 682 |
} |
| 683 |
} catch (RemoteException ex) { |
| 684 |
throw ex.rethrowFromSystemServer(); |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 698 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "This operation" |
| 699 |
+ " is not allowed anymore, please see {@link android.content" |
| 700 |
+ ".Intent#ACTION_CLOSE_SYSTEM_DIALOGS} for more details.") |
| 701 |
@TestApi |
| 702 |
public void collapsePanels() { |
| 703 |
|
| 704 |
try { |
| 705 |
final IStatusBarService svc = getService(); |
| 706 |
if (svc != null) { |
| 707 |
svc.collapsePanels(); |
| 708 |
} |
| 709 |
} catch (RemoteException ex) { |
| 710 |
throw ex.rethrowFromSystemServer(); |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 720 |
@TestApi |
| 721 |
public void togglePanel() { |
| 722 |
try { |
| 723 |
final IStatusBarService svc = getService(); |
| 724 |
if (svc != null) { |
| 725 |
svc.togglePanel(); |
| 726 |
} |
| 727 |
} catch (RemoteException ex) { |
| 728 |
throw ex.rethrowFromSystemServer(); |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 738 |
@TestApi |
| 739 |
public void handleSystemKey(int key) { |
| 740 |
try { |
| 741 |
final IStatusBarService svc = getService(); |
| 742 |
if (svc != null) { |
| 743 |
svc.handleSystemKey(key); |
| 744 |
} |
| 745 |
} catch (RemoteException ex) { |
| 746 |
throw ex.rethrowFromSystemServer(); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
@UnsupportedAppUsage |
| 756 |
public void expandSettingsPanel() { |
| 757 |
expandSettingsPanel(null); |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 767 |
public void expandSettingsPanel(@Nullable String subPanel) { |
| 768 |
try { |
| 769 |
final IStatusBarService svc = getService(); |
| 770 |
if (svc != null) { |
| 771 |
svc.expandSettingsPanel(subPanel); |
| 772 |
} |
| 773 |
} catch (RemoteException ex) { |
| 774 |
throw ex.rethrowFromSystemServer(); |
| 775 |
} |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 780 |
public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { |
| 781 |
try { |
| 782 |
final IStatusBarService svc = getService(); |
| 783 |
if (svc != null) { |
| 784 |
svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, |
| 785 |
contentDescription); |
| 786 |
} |
| 787 |
} catch (RemoteException ex) { |
| 788 |
throw ex.rethrowFromSystemServer(); |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 794 |
public void removeIcon(String slot) { |
| 795 |
try { |
| 796 |
final IStatusBarService svc = getService(); |
| 797 |
if (svc != null) { |
| 798 |
svc.removeIcon(slot); |
| 799 |
} |
| 800 |
} catch (RemoteException ex) { |
| 801 |
throw ex.rethrowFromSystemServer(); |
| 802 |
} |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 807 |
public void setIconVisibility(String slot, boolean visible) { |
| 808 |
try { |
| 809 |
final IStatusBarService svc = getService(); |
| 810 |
if (svc != null) { |
| 811 |
svc.setIconVisibility(slot, visible); |
| 812 |
} |
| 813 |
} catch (RemoteException ex) { |
| 814 |
throw ex.rethrowFromSystemServer(); |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
@SystemApi |
| 827 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 828 |
public void setDisabledForSetup(boolean disabled) { |
| 829 |
try { |
| 830 |
final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 831 |
final IStatusBarService svc = getService(); |
| 832 |
if (svc != null) { |
| 833 |
svc.disableForUser(disabled ? DEFAULT_SETUP_DISABLE_FLAGS : DISABLE_NONE, |
| 834 |
mToken, mContext.getPackageName(), userId); |
| 835 |
svc.disable2ForUser(disabled ? DEFAULT_SETUP_DISABLE2_FLAGS : DISABLE2_NONE, |
| 836 |
mToken, mContext.getPackageName(), userId); |
| 837 |
} |
| 838 |
} catch (RemoteException ex) { |
| 839 |
throw ex.rethrowFromSystemServer(); |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
@TestApi |
| 852 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 853 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 854 |
public void setExpansionDisabledForSimNetworkLock(boolean disabled) { |
| 855 |
try { |
| 856 |
final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 857 |
final IStatusBarService svc = getService(); |
| 858 |
if (svc != null) { |
| 859 |
svc.disableForUser(disabled ? DEFAULT_SIM_LOCKED_DISABLED_FLAGS : DISABLE_NONE, |
| 860 |
mToken, mContext.getPackageName(), userId); |
| 861 |
} |
| 862 |
} catch (RemoteException ex) { |
| 863 |
throw ex.rethrowFromSystemServer(); |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
@SystemApi |
| 875 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 876 |
@NonNull |
| 877 |
public DisableInfo getDisableInfo() { |
| 878 |
try { |
| 879 |
final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 880 |
final IStatusBarService svc = getService(); |
| 881 |
int[] flags = new int[] {0, 0}; |
| 882 |
if (svc != null) { |
| 883 |
flags = svc.getDisableFlags(mToken, userId); |
| 884 |
} |
| 885 |
|
| 886 |
return new DisableInfo(flags[0], flags[1]); |
| 887 |
} catch (RemoteException ex) { |
| 888 |
throw ex.rethrowFromSystemServer(); |
| 889 |
} |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
public void requestTileServiceListeningState(@NonNull ComponentName componentName) { |
| 902 |
Objects.requireNonNull(componentName); |
| 903 |
try { |
| 904 |
getService().requestTileServiceListeningState(componentName, mContext.getUserId()); |
| 905 |
} catch (RemoteException ex) { |
| 906 |
throw ex.rethrowFromSystemServer(); |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
public void requestAddTileService( |
| 944 |
@NonNull ComponentName tileServiceComponentName, |
| 945 |
@NonNull CharSequence tileLabel, |
| 946 |
@NonNull Icon icon, |
| 947 |
@NonNull Executor resultExecutor, |
| 948 |
@NonNull Consumer<Integer> resultCallback |
| 949 |
) { |
| 950 |
Objects.requireNonNull(tileServiceComponentName); |
| 951 |
Objects.requireNonNull(tileLabel); |
| 952 |
Objects.requireNonNull(icon); |
| 953 |
Objects.requireNonNull(resultExecutor); |
| 954 |
Objects.requireNonNull(resultCallback); |
| 955 |
if (!tileServiceComponentName.getPackageName().equals(mContext.getPackageName())) { |
| 956 |
resultExecutor.execute( |
| 957 |
() -> resultCallback.accept(TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE)); |
| 958 |
return; |
| 959 |
} |
| 960 |
int userId = mContext.getUserId(); |
| 961 |
RequestResultCallback callbackProxy = new RequestResultCallback(resultExecutor, |
| 962 |
resultCallback); |
| 963 |
IStatusBarService svc = getService(); |
| 964 |
try { |
| 965 |
svc.requestAddTile( |
| 966 |
tileServiceComponentName, |
| 967 |
tileLabel, |
| 968 |
icon, |
| 969 |
userId, |
| 970 |
callbackProxy |
| 971 |
); |
| 972 |
} catch (RemoteException ex) { |
| 973 |
ex.rethrowFromSystemServer(); |
| 974 |
} |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
@TestApi |
| 982 |
public void cancelRequestAddTile(@NonNull String packageName) { |
| 983 |
Objects.requireNonNull(packageName); |
| 984 |
IStatusBarService svc = getService(); |
| 985 |
try { |
| 986 |
svc.cancelRequestAddTile(packageName); |
| 987 |
} catch (RemoteException e) { |
| 988 |
e.rethrowFromSystemServer(); |
| 989 |
} |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
@SystemApi |
| 1000 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 1001 |
public void setNavBarMode(@NavBarMode int navBarMode) { |
| 1002 |
if (navBarMode != NAV_BAR_MODE_DEFAULT && navBarMode != NAV_BAR_MODE_KIDS) { |
| 1003 |
throw new IllegalArgumentException("Supplied navBarMode not supported: " + navBarMode); |
| 1004 |
} |
| 1005 |
|
| 1006 |
try { |
| 1007 |
final IStatusBarService svc = getService(); |
| 1008 |
if (svc != null) { |
| 1009 |
svc.setNavBarMode(navBarMode); |
| 1010 |
} |
| 1011 |
} catch (RemoteException e) { |
| 1012 |
throw e.rethrowFromSystemServer(); |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
@SystemApi |
| 1022 |
@RequiresPermission(android.Manifest.permission.STATUS_BAR) |
| 1023 |
public @NavBarMode int getNavBarMode() { |
| 1024 |
int navBarMode = NAV_BAR_MODE_DEFAULT; |
| 1025 |
try { |
| 1026 |
final IStatusBarService svc = getService(); |
| 1027 |
if (svc != null) { |
| 1028 |
navBarMode = svc.getNavBarMode(); |
| 1029 |
} |
| 1030 |
} catch (RemoteException e) { |
| 1031 |
throw e.rethrowFromSystemServer(); |
| 1032 |
} |
| 1033 |
return navBarMode; |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
@SystemApi |
| 1058 |
@RequiresPermission(Manifest.permission.MEDIA_CONTENT_CONTROL) |
| 1059 |
public void updateMediaTapToTransferSenderDisplay( |
| 1060 |
@MediaTransferSenderState int displayState, |
| 1061 |
@NonNull MediaRoute2Info routeInfo, |
| 1062 |
@Nullable Executor undoExecutor, |
| 1063 |
@Nullable Runnable undoCallback |
| 1064 |
) { |
| 1065 |
Objects.requireNonNull(routeInfo); |
| 1066 |
if (displayState != MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_SUCCEEDED |
| 1067 |
&& displayState != MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_THIS_DEVICE_SUCCEEDED |
| 1068 |
&& undoCallback != null) { |
| 1069 |
throw new IllegalArgumentException( |
| 1070 |
"The undoCallback should only be provided when the state is a " |
| 1071 |
+ "transfer succeeded state"); |
| 1072 |
} |
| 1073 |
if (undoCallback != null && undoExecutor == null) { |
| 1074 |
throw new IllegalArgumentException( |
| 1075 |
"You must pass an executor when you pass an undo callback"); |
| 1076 |
} |
| 1077 |
IStatusBarService svc = getService(); |
| 1078 |
try { |
| 1079 |
UndoCallback callbackProxy = null; |
| 1080 |
if (undoExecutor != null) { |
| 1081 |
callbackProxy = new UndoCallback(undoExecutor, undoCallback); |
| 1082 |
} |
| 1083 |
svc.updateMediaTapToTransferSenderDisplay(displayState, routeInfo, callbackProxy); |
| 1084 |
} catch (RemoteException e) { |
| 1085 |
e.rethrowFromSystemServer(); |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
@SystemApi |
| 1100 |
@RequiresPermission(Manifest.permission.MEDIA_CONTENT_CONTROL) |
| 1101 |
public void updateMediaTapToTransferReceiverDisplay( |
| 1102 |
@MediaTransferReceiverState int displayState, |
| 1103 |
@NonNull MediaRoute2Info routeInfo, |
| 1104 |
@Nullable Icon appIcon, |
| 1105 |
@Nullable CharSequence appName) { |
| 1106 |
Objects.requireNonNull(routeInfo); |
| 1107 |
IStatusBarService svc = getService(); |
| 1108 |
try { |
| 1109 |
svc.updateMediaTapToTransferReceiverDisplay(displayState, routeInfo, appIcon, appName); |
| 1110 |
} catch (RemoteException e) { |
| 1111 |
e.rethrowFromSystemServer(); |
| 1112 |
} |
| 1113 |
} |
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
@SystemApi |
| 1127 |
@RequiresPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL) |
| 1128 |
public void registerNearbyMediaDevicesProvider( |
| 1129 |
@NonNull NearbyMediaDevicesProvider provider |
| 1130 |
) { |
| 1131 |
Objects.requireNonNull(provider); |
| 1132 |
if (nearbyMediaDevicesProviderMap.containsKey(provider)) { |
| 1133 |
return; |
| 1134 |
} |
| 1135 |
try { |
| 1136 |
final IStatusBarService svc = getService(); |
| 1137 |
NearbyMediaDevicesProviderWrapper providerWrapper = |
| 1138 |
new NearbyMediaDevicesProviderWrapper(provider); |
| 1139 |
nearbyMediaDevicesProviderMap.put(provider, providerWrapper); |
| 1140 |
svc.registerNearbyMediaDevicesProvider(providerWrapper); |
| 1141 |
} catch (RemoteException e) { |
| 1142 |
throw e.rethrowFromSystemServer(); |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
@SystemApi |
| 1157 |
@RequiresPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL) |
| 1158 |
public void unregisterNearbyMediaDevicesProvider( |
| 1159 |
@NonNull NearbyMediaDevicesProvider provider |
| 1160 |
) { |
| 1161 |
Objects.requireNonNull(provider); |
| 1162 |
if (!nearbyMediaDevicesProviderMap.containsKey(provider)) { |
| 1163 |
return; |
| 1164 |
} |
| 1165 |
try { |
| 1166 |
final IStatusBarService svc = getService(); |
| 1167 |
NearbyMediaDevicesProviderWrapper providerWrapper = |
| 1168 |
nearbyMediaDevicesProviderMap.get(provider); |
| 1169 |
nearbyMediaDevicesProviderMap.remove(provider); |
| 1170 |
svc.unregisterNearbyMediaDevicesProvider(providerWrapper); |
| 1171 |
} catch (RemoteException e) { |
| 1172 |
throw e.rethrowFromSystemServer(); |
| 1173 |
} |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
@RequiresPermission(allOf = {android.Manifest.permission.READ_COMPAT_CHANGE_CONFIG, |
| 1186 |
android.Manifest.permission.LOG_COMPAT_CHANGE}) |
| 1187 |
public static boolean useMediaSessionActionsForApp(String packageName, UserHandle user) { |
| 1188 |
return CompatChanges.isChangeEnabled(MEDIA_CONTROL_SESSION_ACTIONS, packageName, user); |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
public static String windowStateToString(int state) { |
| 1193 |
if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING"; |
| 1194 |
if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN"; |
| 1195 |
if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING"; |
| 1196 |
return "WINDOW_STATE_UNKNOWN"; |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
@SystemApi |
| 1206 |
public static final class DisableInfo { |
| 1207 |
|
| 1208 |
private boolean mStatusBarExpansion; |
| 1209 |
private boolean mNavigateHome; |
| 1210 |
private boolean mNotificationPeeking; |
| 1211 |
private boolean mRecents; |
| 1212 |
private boolean mSearch; |
| 1213 |
private boolean mSystemIcons; |
| 1214 |
private boolean mClock; |
| 1215 |
private boolean mNotificationIcons; |
| 1216 |
private boolean mRotationSuggestion; |
| 1217 |
|
| 1218 |
|
| 1219 |
public DisableInfo(int flags1, int flags2) { |
| 1220 |
mStatusBarExpansion = (flags1 & DISABLE_EXPAND) != 0; |
| 1221 |
mNavigateHome = (flags1 & DISABLE_HOME) != 0; |
| 1222 |
mNotificationPeeking = (flags1 & DISABLE_NOTIFICATION_ALERTS) != 0; |
| 1223 |
mRecents = (flags1 & DISABLE_RECENT) != 0; |
| 1224 |
mSearch = (flags1 & DISABLE_SEARCH) != 0; |
| 1225 |
mSystemIcons = (flags1 & DISABLE_SYSTEM_INFO) != 0; |
| 1226 |
mClock = (flags1 & DISABLE_CLOCK) != 0; |
| 1227 |
mNotificationIcons = (flags1 & DISABLE_NOTIFICATION_ICONS) != 0; |
| 1228 |
mRotationSuggestion = (flags2 & DISABLE2_ROTATE_SUGGESTIONS) != 0; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
public DisableInfo() {} |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
@SystemApi |
| 1240 |
public boolean isStatusBarExpansionDisabled() { |
| 1241 |
return mStatusBarExpansion; |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
public void setStatusBarExpansionDisabled(boolean disabled) { |
| 1246 |
mStatusBarExpansion = disabled; |
| 1247 |
} |
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
@SystemApi |
| 1255 |
public boolean isNavigateToHomeDisabled() { |
| 1256 |
return mNavigateHome; |
| 1257 |
} |
| 1258 |
|
| 1259 |
|
| 1260 |
public void setNagivationHomeDisabled(boolean disabled) { |
| 1261 |
mNavigateHome = disabled; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
@SystemApi |
| 1270 |
public boolean isNotificationPeekingDisabled() { |
| 1271 |
return mNotificationPeeking; |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
public void setNotificationPeekingDisabled(boolean disabled) { |
| 1276 |
mNotificationPeeking = disabled; |
| 1277 |
} |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
@SystemApi |
| 1285 |
public boolean isRecentsDisabled() { |
| 1286 |
return mRecents; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
public void setRecentsDisabled(boolean disabled) { |
| 1291 |
mRecents = disabled; |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
@SystemApi |
| 1300 |
public boolean isSearchDisabled() { |
| 1301 |
return mSearch; |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
public void setSearchDisabled(boolean disabled) { |
| 1306 |
mSearch = disabled; |
| 1307 |
} |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
public boolean areSystemIconsDisabled() { |
| 1315 |
return mSystemIcons; |
| 1316 |
} |
| 1317 |
|
| 1318 |
|
| 1319 |
public void setSystemIconsDisabled(boolean disabled) { |
| 1320 |
mSystemIcons = disabled; |
| 1321 |
} |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
public boolean isClockDisabled() { |
| 1329 |
return mClock; |
| 1330 |
} |
| 1331 |
|
| 1332 |
|
| 1333 |
public void setClockDisabled(boolean disabled) { |
| 1334 |
mClock = disabled; |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
public boolean areNotificationIconsDisabled() { |
| 1343 |
return mNotificationIcons; |
| 1344 |
} |
| 1345 |
|
| 1346 |
|
| 1347 |
public void setNotificationIconsDisabled(boolean disabled) { |
| 1348 |
mNotificationIcons = disabled; |
| 1349 |
} |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
@TestApi |
| 1357 |
public boolean isRotationSuggestionDisabled() { |
| 1358 |
return mRotationSuggestion; |
| 1359 |
} |
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
@SystemApi |
| 1366 |
public boolean areAllComponentsEnabled() { |
| 1367 |
return !mStatusBarExpansion && !mNavigateHome && !mNotificationPeeking && !mRecents |
| 1368 |
&& !mSearch && !mSystemIcons && !mClock && !mNotificationIcons |
| 1369 |
&& !mRotationSuggestion; |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
public void setEnableAll() { |
| 1374 |
mStatusBarExpansion = false; |
| 1375 |
mNavigateHome = false; |
| 1376 |
mNotificationPeeking = false; |
| 1377 |
mRecents = false; |
| 1378 |
mSearch = false; |
| 1379 |
mSystemIcons = false; |
| 1380 |
mClock = false; |
| 1381 |
mNotificationIcons = false; |
| 1382 |
mRotationSuggestion = false; |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
public boolean areAllComponentsDisabled() { |
| 1391 |
return mStatusBarExpansion && mNavigateHome && mNotificationPeeking |
| 1392 |
&& mRecents && mSearch && mSystemIcons && mClock && mNotificationIcons |
| 1393 |
&& mRotationSuggestion; |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
public void setDisableAll() { |
| 1398 |
mStatusBarExpansion = true; |
| 1399 |
mNavigateHome = true; |
| 1400 |
mNotificationPeeking = true; |
| 1401 |
mRecents = true; |
| 1402 |
mSearch = true; |
| 1403 |
mSystemIcons = true; |
| 1404 |
mClock = true; |
| 1405 |
mNotificationIcons = true; |
| 1406 |
mRotationSuggestion = true; |
| 1407 |
} |
| 1408 |
|
| 1409 |
@NonNull |
| 1410 |
@Override |
| 1411 |
public String toString() { |
| 1412 |
StringBuilder sb = new StringBuilder(); |
| 1413 |
sb.append("DisableInfo: "); |
| 1414 |
sb.append(" mStatusBarExpansion=").append(mStatusBarExpansion ? "disabled" : "enabled"); |
| 1415 |
sb.append(" mNavigateHome=").append(mNavigateHome ? "disabled" : "enabled"); |
| 1416 |
sb.append(" mNotificationPeeking=") |
| 1417 |
.append(mNotificationPeeking ? "disabled" : "enabled"); |
| 1418 |
sb.append(" mRecents=").append(mRecents ? "disabled" : "enabled"); |
| 1419 |
sb.append(" mSearch=").append(mSearch ? "disabled" : "enabled"); |
| 1420 |
sb.append(" mSystemIcons=").append(mSystemIcons ? "disabled" : "enabled"); |
| 1421 |
sb.append(" mClock=").append(mClock ? "disabled" : "enabled"); |
| 1422 |
sb.append(" mNotificationIcons=").append(mNotificationIcons ? "disabled" : "enabled"); |
| 1423 |
sb.append(" mRotationSuggestion=").append(mRotationSuggestion ? "disabled" : "enabled"); |
| 1424 |
|
| 1425 |
return sb.toString(); |
| 1426 |
|
| 1427 |
} |
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
public Pair<Integer, Integer> toFlags() { |
| 1436 |
int disable1 = DISABLE_NONE; |
| 1437 |
int disable2 = DISABLE2_NONE; |
| 1438 |
|
| 1439 |
if (mStatusBarExpansion) disable1 |= DISABLE_EXPAND; |
| 1440 |
if (mNavigateHome) disable1 |= DISABLE_HOME; |
| 1441 |
if (mNotificationPeeking) disable1 |= DISABLE_NOTIFICATION_ALERTS; |
| 1442 |
if (mRecents) disable1 |= DISABLE_RECENT; |
| 1443 |
if (mSearch) disable1 |= DISABLE_SEARCH; |
| 1444 |
if (mSystemIcons) disable1 |= DISABLE_SYSTEM_INFO; |
| 1445 |
if (mClock) disable1 |= DISABLE_CLOCK; |
| 1446 |
if (mNotificationIcons) disable1 |= DISABLE_NOTIFICATION_ICONS; |
| 1447 |
if (mRotationSuggestion) disable2 |= DISABLE2_ROTATE_SUGGESTIONS; |
| 1448 |
|
| 1449 |
return new Pair<Integer, Integer>(disable1, disable2); |
| 1450 |
} |
| 1451 |
} |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
static final class RequestResultCallback extends IAddTileResultCallback.Stub { |
| 1457 |
|
| 1458 |
@NonNull |
| 1459 |
private final Executor mExecutor; |
| 1460 |
@NonNull |
| 1461 |
private final Consumer<Integer> mCallback; |
| 1462 |
|
| 1463 |
RequestResultCallback(@NonNull Executor executor, @NonNull Consumer<Integer> callback) { |
| 1464 |
mExecutor = executor; |
| 1465 |
mCallback = callback; |
| 1466 |
} |
| 1467 |
|
| 1468 |
@Override |
| 1469 |
public void onTileRequest(int userResponse) { |
| 1470 |
mExecutor.execute(() -> mCallback.accept(userResponse)); |
| 1471 |
} |
| 1472 |
} |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
static final class UndoCallback extends IUndoMediaTransferCallback.Stub { |
| 1478 |
@NonNull |
| 1479 |
private final Executor mExecutor; |
| 1480 |
@NonNull |
| 1481 |
private final Runnable mCallback; |
| 1482 |
|
| 1483 |
UndoCallback(@NonNull Executor executor, @NonNull Runnable callback) { |
| 1484 |
mExecutor = executor; |
| 1485 |
mCallback = callback; |
| 1486 |
} |
| 1487 |
|
| 1488 |
@Override |
| 1489 |
public void onUndoTriggered() { |
| 1490 |
final long callingIdentity = Binder.clearCallingIdentity(); |
| 1491 |
try { |
| 1492 |
mExecutor.execute(mCallback); |
| 1493 |
} finally { |
| 1494 |
restoreCallingIdentity(callingIdentity); |
| 1495 |
} |
| 1496 |
} |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
static final class NearbyMediaDevicesProviderWrapper extends INearbyMediaDevicesProvider.Stub { |
| 1503 |
@NonNull |
| 1504 |
private final NearbyMediaDevicesProvider mProvider; |
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
@NonNull |
| 1510 |
private final Map<INearbyMediaDevicesUpdateCallback, Consumer<List<NearbyDevice>>> |
| 1511 |
mRegisteredCallbacks = new HashMap<>(); |
| 1512 |
|
| 1513 |
NearbyMediaDevicesProviderWrapper(@NonNull NearbyMediaDevicesProvider provider) { |
| 1514 |
mProvider = provider; |
| 1515 |
} |
| 1516 |
|
| 1517 |
@Override |
| 1518 |
public void registerNearbyDevicesCallback( |
| 1519 |
@NonNull INearbyMediaDevicesUpdateCallback callback) { |
| 1520 |
Consumer<List<NearbyDevice>> callbackAsConsumer = nearbyDevices -> { |
| 1521 |
try { |
| 1522 |
callback.onDevicesUpdated(nearbyDevices); |
| 1523 |
} catch (RemoteException ex) { |
| 1524 |
throw ex.rethrowFromSystemServer(); |
| 1525 |
} |
| 1526 |
}; |
| 1527 |
|
| 1528 |
mRegisteredCallbacks.put(callback, callbackAsConsumer); |
| 1529 |
mProvider.registerNearbyDevicesCallback(callbackAsConsumer); |
| 1530 |
} |
| 1531 |
|
| 1532 |
@Override |
| 1533 |
public void unregisterNearbyDevicesCallback( |
| 1534 |
@NonNull INearbyMediaDevicesUpdateCallback callback) { |
| 1535 |
if (!mRegisteredCallbacks.containsKey(callback)) { |
| 1536 |
return; |
| 1537 |
} |
| 1538 |
mProvider.unregisterNearbyDevicesCallback(mRegisteredCallbacks.get(callback)); |
| 1539 |
mRegisteredCallbacks.remove(callback); |
| 1540 |
} |
| 1541 |
} |
| 1542 |
} |