| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content.pm; |
| 18 |
|
| 19 |
import static android.Manifest.permission; |
| 20 |
|
| 21 |
import android.annotation.CallbackExecutor; |
| 22 |
import android.annotation.IntDef; |
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.annotation.Nullable; |
| 25 |
import android.annotation.RequiresPermission; |
| 26 |
import android.annotation.SdkConstant; |
| 27 |
import android.annotation.SdkConstant.SdkConstantType; |
| 28 |
import android.annotation.SystemApi; |
| 29 |
import android.annotation.SystemService; |
| 30 |
import android.annotation.TestApi; |
| 31 |
import android.app.PendingIntent; |
| 32 |
import android.appwidget.AppWidgetManager; |
| 33 |
import android.appwidget.AppWidgetProviderInfo; |
| 34 |
import android.compat.annotation.UnsupportedAppUsage; |
| 35 |
import android.content.ActivityNotFoundException; |
| 36 |
import android.content.ComponentName; |
| 37 |
import android.content.Context; |
| 38 |
import android.content.Intent; |
| 39 |
import android.content.IntentSender; |
| 40 |
import android.content.LocusId; |
| 41 |
import android.content.pm.PackageInstaller.SessionCallback; |
| 42 |
import android.content.pm.PackageInstaller.SessionCallbackDelegate; |
| 43 |
import android.content.pm.PackageInstaller.SessionInfo; |
| 44 |
import android.content.pm.PackageManager.ApplicationInfoFlagsBits; |
| 45 |
import android.content.pm.PackageManager.NameNotFoundException; |
| 46 |
import android.content.res.Resources; |
| 47 |
import android.graphics.Bitmap; |
| 48 |
import android.graphics.BitmapFactory; |
| 49 |
import android.graphics.Rect; |
| 50 |
import android.graphics.drawable.AdaptiveIconDrawable; |
| 51 |
import android.graphics.drawable.BitmapDrawable; |
| 52 |
import android.graphics.drawable.Drawable; |
| 53 |
import android.graphics.drawable.Icon; |
| 54 |
import android.net.Uri; |
| 55 |
import android.os.Build; |
| 56 |
import android.os.Bundle; |
| 57 |
import android.os.Handler; |
| 58 |
import android.os.Looper; |
| 59 |
import android.os.Message; |
| 60 |
import android.os.Parcel; |
| 61 |
import android.os.ParcelFileDescriptor; |
| 62 |
import android.os.Parcelable; |
| 63 |
import android.os.RemoteException; |
| 64 |
import android.os.ServiceManager; |
| 65 |
import android.os.UserHandle; |
| 66 |
import android.os.UserManager; |
| 67 |
import android.util.DisplayMetrics; |
| 68 |
import android.util.Log; |
| 69 |
import android.util.Pair; |
| 70 |
|
| 71 |
import com.android.internal.annotations.VisibleForTesting; |
| 72 |
import com.android.internal.infra.AndroidFuture; |
| 73 |
import com.android.internal.util.function.pooled.PooledLambda; |
| 74 |
|
| 75 |
import java.io.FileNotFoundException; |
| 76 |
import java.io.IOException; |
| 77 |
import java.lang.annotation.Retention; |
| 78 |
import java.lang.annotation.RetentionPolicy; |
| 79 |
import java.lang.ref.WeakReference; |
| 80 |
import java.util.ArrayList; |
| 81 |
import java.util.Arrays; |
| 82 |
import java.util.Collections; |
| 83 |
import java.util.HashMap; |
| 84 |
import java.util.Iterator; |
| 85 |
import java.util.List; |
| 86 |
import java.util.Map; |
| 87 |
import java.util.Objects; |
| 88 |
import java.util.concurrent.ExecutionException; |
| 89 |
import java.util.concurrent.Executor; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
@SystemService(Context.LAUNCHER_APPS_SERVICE) |
| 107 |
public class LauncherApps { |
| 108 |
|
| 109 |
static final String TAG = "LauncherApps"; |
| 110 |
static final boolean DEBUG = false; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 126 |
public static final String ACTION_CONFIRM_PIN_SHORTCUT = |
| 127 |
"android.content.pm.action.CONFIRM_PIN_SHORTCUT"; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 144 |
public static final String ACTION_CONFIRM_PIN_APPWIDGET = |
| 145 |
"android.content.pm.action.CONFIRM_PIN_APPWIDGET"; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public static final String EXTRA_PIN_ITEM_REQUEST = |
| 158 |
"android.content.pm.extra.PIN_ITEM_REQUEST"; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public static final int FLAG_CACHE_NOTIFICATION_SHORTCUTS = 0; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public static final int FLAG_CACHE_BUBBLE_SHORTCUTS = 1; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
public static final int FLAG_CACHE_PEOPLE_TILE_SHORTCUTS = 2; |
| 177 |
|
| 178 |
|
| 179 |
@IntDef(flag = false, prefix = { "FLAG_CACHE_" }, value = { |
| 180 |
FLAG_CACHE_NOTIFICATION_SHORTCUTS, |
| 181 |
FLAG_CACHE_BUBBLE_SHORTCUTS, |
| 182 |
FLAG_CACHE_PEOPLE_TILE_SHORTCUTS |
| 183 |
}) |
| 184 |
@Retention(RetentionPolicy.SOURCE) |
| 185 |
public @interface ShortcutCacheFlags {} |
| 186 |
|
| 187 |
private final Context mContext; |
| 188 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 189 |
private final ILauncherApps mService; |
| 190 |
@UnsupportedAppUsage |
| 191 |
private final PackageManager mPm; |
| 192 |
private final UserManager mUserManager; |
| 193 |
|
| 194 |
private final List<CallbackMessageHandler> mCallbacks = new ArrayList<>(); |
| 195 |
private final List<SessionCallbackDelegate> mDelegates = new ArrayList<>(); |
| 196 |
|
| 197 |
private final Map<ShortcutChangeCallback, Pair<Executor, IShortcutChangeCallback>> |
| 198 |
mShortcutChangeCallbacks = new HashMap<>(); |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public static abstract class Callback { |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
abstract public void onPackageRemoved(String packageName, UserHandle user); |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
abstract public void onPackageAdded(String packageName, UserHandle user); |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
abstract public void onPackageChanged(String packageName, UserHandle user); |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
abstract public void onPackagesAvailable(String[] packageNames, UserHandle user, |
| 248 |
boolean replacing); |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
abstract public void onPackagesUnavailable(String[] packageNames, UserHandle user, |
| 262 |
boolean replacing); |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public void onPackagesSuspended(String[] packageNames, UserHandle user) { |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
@Deprecated |
| 300 |
public void onPackagesSuspended(String[] packageNames, UserHandle user, |
| 301 |
@Nullable Bundle launcherExtras) { |
| 302 |
onPackagesSuspended(packageNames, user); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
public void onPackagesUnsuspended(String[] packageNames, UserHandle user) { |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
public void onShortcutsChanged(@NonNull String packageName, |
| 333 |
@NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) { |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
public void onPackageLoadingProgressChanged(@NonNull String packageName, |
| 344 |
@NonNull UserHandle user, float progress) {} |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public static class ShortcutQuery { |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
public static final int FLAG_MATCH_DYNAMIC = 1 << 0; |
| 355 |
|
| 356 |
|
| 357 |
@Deprecated |
| 358 |
public static final int FLAG_GET_DYNAMIC = FLAG_MATCH_DYNAMIC; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
public static final int FLAG_MATCH_PINNED = 1 << 1; |
| 372 |
|
| 373 |
|
| 374 |
@Deprecated |
| 375 |
public static final int FLAG_GET_PINNED = FLAG_MATCH_PINNED; |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public static final int FLAG_MATCH_MANIFEST = 1 << 3; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
public static final int FLAG_MATCH_CACHED = 1 << 4; |
| 386 |
|
| 387 |
|
| 388 |
@Deprecated |
| 389 |
public static final int FLAG_GET_MANIFEST = FLAG_MATCH_MANIFEST; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public static final int FLAG_MATCH_PINNED_BY_ANY_LAUNCHER = 1 << 10; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
public static final int FLAG_MATCH_ALL_KINDS = |
| 412 |
FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_CACHED; |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
public static final int FLAG_MATCH_ALL_KINDS_WITH_ALL_PINNED = |
| 419 |
FLAG_MATCH_ALL_KINDS | FLAG_MATCH_PINNED_BY_ANY_LAUNCHER; |
| 420 |
|
| 421 |
|
| 422 |
@Deprecated |
| 423 |
public static final int FLAG_GET_ALL_KINDS = FLAG_MATCH_ALL_KINDS; |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
public static final int FLAG_GET_KEY_FIELDS_ONLY = 1 << 2; |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
@SystemApi |
| 453 |
public static final int FLAG_GET_PERSISTED_DATA = 1 << 12; |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
@SystemApi |
| 463 |
@RequiresPermission(android.Manifest.permission.ACCESS_SHORTCUTS) |
| 464 |
public static final int FLAG_GET_PERSONS_DATA = 1 << 11; |
| 465 |
|
| 466 |
|
| 467 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 468 |
FLAG_MATCH_DYNAMIC, |
| 469 |
FLAG_MATCH_PINNED, |
| 470 |
FLAG_MATCH_MANIFEST, |
| 471 |
FLAG_MATCH_CACHED, |
| 472 |
FLAG_MATCH_PINNED_BY_ANY_LAUNCHER, |
| 473 |
FLAG_GET_KEY_FIELDS_ONLY, |
| 474 |
FLAG_GET_PERSONS_DATA, |
| 475 |
FLAG_GET_PERSISTED_DATA |
| 476 |
}) |
| 477 |
@Retention(RetentionPolicy.SOURCE) |
| 478 |
public @interface QueryFlags {} |
| 479 |
|
| 480 |
long mChangedSince; |
| 481 |
|
| 482 |
@Nullable |
| 483 |
String mPackage; |
| 484 |
|
| 485 |
@Nullable |
| 486 |
List<String> mShortcutIds; |
| 487 |
|
| 488 |
@Nullable |
| 489 |
List<LocusId> mLocusIds; |
| 490 |
|
| 491 |
@Nullable |
| 492 |
ComponentName mActivity; |
| 493 |
|
| 494 |
@QueryFlags |
| 495 |
int mQueryFlags; |
| 496 |
|
| 497 |
public ShortcutQuery() { |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
public ShortcutQuery setChangedSince(long changedSince) { |
| 506 |
mChangedSince = changedSince; |
| 507 |
return this; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
public ShortcutQuery setPackage(@Nullable String packageName) { |
| 514 |
mPackage = packageName; |
| 515 |
return this; |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
public ShortcutQuery setShortcutIds(@Nullable List<String> shortcutIds) { |
| 523 |
mShortcutIds = shortcutIds; |
| 524 |
return this; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
@NonNull |
| 532 |
public ShortcutQuery setLocusIds(@Nullable List<LocusId> locusIds) { |
| 533 |
mLocusIds = locusIds; |
| 534 |
return this; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
public ShortcutQuery setActivity(@Nullable ComponentName activity) { |
| 543 |
mActivity = activity; |
| 544 |
return this; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
public ShortcutQuery setQueryFlags(@QueryFlags int queryFlags) { |
| 560 |
mQueryFlags = queryFlags; |
| 561 |
return this; |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
public interface ShortcutChangeCallback { |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
default void onShortcutsAddedOrUpdated(@NonNull String packageName, |
| 588 |
@NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) {} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
default void onShortcutsRemoved(@NonNull String packageName, |
| 607 |
@NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) {} |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
private static class ShortcutChangeCallbackProxy extends |
| 616 |
android.content.pm.IShortcutChangeCallback.Stub { |
| 617 |
private final WeakReference<Pair<Executor, ShortcutChangeCallback>> mRemoteReferences; |
| 618 |
|
| 619 |
ShortcutChangeCallbackProxy(Executor executor, ShortcutChangeCallback callback) { |
| 620 |
mRemoteReferences = new WeakReference<>(new Pair<>(executor, callback)); |
| 621 |
} |
| 622 |
|
| 623 |
@Override |
| 624 |
public void onShortcutsAddedOrUpdated(@NonNull String packageName, |
| 625 |
@NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) { |
| 626 |
Pair<Executor, ShortcutChangeCallback> remoteReferences = mRemoteReferences.get(); |
| 627 |
if (remoteReferences == null) { |
| 628 |
|
| 629 |
return; |
| 630 |
} |
| 631 |
|
| 632 |
final Executor executor = remoteReferences.first; |
| 633 |
final ShortcutChangeCallback callback = remoteReferences.second; |
| 634 |
executor.execute( |
| 635 |
PooledLambda.obtainRunnable(ShortcutChangeCallback::onShortcutsAddedOrUpdated, |
| 636 |
callback, packageName, shortcuts, user).recycleOnUse()); |
| 637 |
} |
| 638 |
|
| 639 |
@Override |
| 640 |
public void onShortcutsRemoved(@NonNull String packageName, |
| 641 |
@NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) { |
| 642 |
Pair<Executor, ShortcutChangeCallback> remoteReferences = mRemoteReferences.get(); |
| 643 |
if (remoteReferences == null) { |
| 644 |
|
| 645 |
return; |
| 646 |
} |
| 647 |
|
| 648 |
final Executor executor = remoteReferences.first; |
| 649 |
final ShortcutChangeCallback callback = remoteReferences.second; |
| 650 |
executor.execute( |
| 651 |
PooledLambda.obtainRunnable(ShortcutChangeCallback::onShortcutsRemoved, |
| 652 |
callback, packageName, shortcuts, user).recycleOnUse()); |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
public LauncherApps(Context context, ILauncherApps service) { |
| 658 |
mContext = context; |
| 659 |
mService = service; |
| 660 |
mPm = context.getPackageManager(); |
| 661 |
mUserManager = context.getSystemService(UserManager.class); |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
@TestApi |
| 666 |
public LauncherApps(Context context) { |
| 667 |
this(context, ILauncherApps.Stub.asInterface( |
| 668 |
ServiceManager.getService(Context.LAUNCHER_APPS_SERVICE))); |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
private void logErrorForInvalidProfileAccess(@NonNull UserHandle target) { |
| 678 |
if (UserHandle.myUserId() != target.getIdentifier() && mUserManager.isManagedProfile() |
| 679 |
&& mContext.checkSelfPermission(permission.INTERACT_ACROSS_USERS_FULL) |
| 680 |
!= PackageManager.PERMISSION_GRANTED) { |
| 681 |
Log.w(TAG, "Accessing other profiles/users from managed profile is no longer allowed."); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
public List<UserHandle> getProfiles() { |
| 692 |
if (mUserManager.isManagedProfile()) { |
| 693 |
|
| 694 |
final List result = new ArrayList(1); |
| 695 |
result.add(android.os.Process.myUserHandle()); |
| 696 |
return result; |
| 697 |
} else { |
| 698 |
return mUserManager.getUserProfiles(); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
public List<LauncherActivityInfo> getActivityList(String packageName, UserHandle user) { |
| 742 |
logErrorForInvalidProfileAccess(user); |
| 743 |
try { |
| 744 |
return convertToActivityList(mService.getLauncherActivities(mContext.getPackageName(), |
| 745 |
packageName, user), user); |
| 746 |
} catch (RemoteException re) { |
| 747 |
throw re.rethrowFromSystemServer(); |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
@RequiresPermission(android.Manifest.permission.START_TASKS_FROM_RECENTS) |
| 762 |
@Nullable |
| 763 |
public PendingIntent getMainActivityLaunchIntent(@NonNull ComponentName component, |
| 764 |
@Nullable Bundle startActivityOptions, @NonNull UserHandle user) { |
| 765 |
if (mContext.checkSelfPermission(android.Manifest.permission.START_TASKS_FROM_RECENTS) |
| 766 |
!= PackageManager.PERMISSION_GRANTED) { |
| 767 |
Log.w(TAG, "Only allowed for recents."); |
| 768 |
} |
| 769 |
logErrorForInvalidProfileAccess(user); |
| 770 |
if (DEBUG) { |
| 771 |
Log.i(TAG, "GetMainActivityLaunchIntent " + component + " " + user); |
| 772 |
} |
| 773 |
try { |
| 774 |
return mService.getActivityLaunchIntent(mContext.getPackageName(), component, user); |
| 775 |
} catch (RemoteException re) { |
| 776 |
throw re.rethrowFromSystemServer(); |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
public LauncherActivityInfo resolveActivity(Intent intent, UserHandle user) { |
| 789 |
logErrorForInvalidProfileAccess(user); |
| 790 |
try { |
| 791 |
LauncherActivityInfoInternal ai = mService.resolveLauncherActivityInternal( |
| 792 |
mContext.getPackageName(), intent.getComponent(), user); |
| 793 |
if (ai == null) { |
| 794 |
return null; |
| 795 |
} |
| 796 |
return new LauncherActivityInfo(mContext, user, ai); |
| 797 |
} catch (RemoteException re) { |
| 798 |
throw re.rethrowFromSystemServer(); |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
public void startMainActivity(ComponentName component, UserHandle user, Rect sourceBounds, |
| 811 |
Bundle opts) { |
| 812 |
logErrorForInvalidProfileAccess(user); |
| 813 |
if (DEBUG) { |
| 814 |
Log.i(TAG, "StartMainActivity " + component + " " + user.getIdentifier()); |
| 815 |
} |
| 816 |
try { |
| 817 |
mService.startActivityAsUser(mContext.getIApplicationThread(), |
| 818 |
mContext.getPackageName(), mContext.getAttributionTag(), |
| 819 |
component, sourceBounds, opts, user); |
| 820 |
} catch (RemoteException re) { |
| 821 |
throw re.rethrowFromSystemServer(); |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
public void startPackageInstallerSessionDetailsActivity(@NonNull SessionInfo sessionInfo, |
| 833 |
@Nullable Rect sourceBounds, @Nullable Bundle opts) { |
| 834 |
try { |
| 835 |
mService.startSessionDetailsActivityAsUser(mContext.getIApplicationThread(), |
| 836 |
mContext.getPackageName(), mContext.getAttributionTag(), sessionInfo, |
| 837 |
sourceBounds, opts, sessionInfo.getUser()); |
| 838 |
} catch (RemoteException re) { |
| 839 |
throw re.rethrowFromSystemServer(); |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
public void startAppDetailsActivity(ComponentName component, UserHandle user, |
| 853 |
Rect sourceBounds, Bundle opts) { |
| 854 |
logErrorForInvalidProfileAccess(user); |
| 855 |
try { |
| 856 |
mService.showAppDetailsAsUser(mContext.getIApplicationThread(), |
| 857 |
mContext.getPackageName(), mContext.getAttributionTag(), |
| 858 |
component, sourceBounds, opts, user); |
| 859 |
} catch (RemoteException re) { |
| 860 |
throw re.rethrowFromSystemServer(); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
@Nullable |
| 873 |
public PendingIntent getShortcutIntent(@NonNull final String packageName, |
| 874 |
@NonNull final String shortcutId, @Nullable final Bundle opts, |
| 875 |
@NonNull final UserHandle user) { |
| 876 |
logErrorForInvalidProfileAccess(user); |
| 877 |
if (DEBUG) { |
| 878 |
Log.i(TAG, "GetShortcutIntent " + packageName + "/" + shortcutId + " " + user); |
| 879 |
} |
| 880 |
try { |
| 881 |
|
| 882 |
return mService.getShortcutIntent( |
| 883 |
mContext.getPackageName(), packageName, shortcutId, null , user); |
| 884 |
} catch (RemoteException re) { |
| 885 |
throw re.rethrowFromSystemServer(); |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
public List<LauncherActivityInfo> getShortcutConfigActivityList(@Nullable String packageName, |
| 901 |
@NonNull UserHandle user) { |
| 902 |
logErrorForInvalidProfileAccess(user); |
| 903 |
try { |
| 904 |
return convertToActivityList(mService.getShortcutConfigActivities( |
| 905 |
mContext.getPackageName(), packageName, user), |
| 906 |
user); |
| 907 |
} catch (RemoteException re) { |
| 908 |
throw re.rethrowFromSystemServer(); |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
private List<LauncherActivityInfo> convertToActivityList( |
| 913 |
@Nullable ParceledListSlice<LauncherActivityInfoInternal> internals, UserHandle user) { |
| 914 |
if (internals == null || internals.getList().isEmpty()) { |
| 915 |
return Collections.EMPTY_LIST; |
| 916 |
} |
| 917 |
ArrayList<LauncherActivityInfo> lais = new ArrayList<>(); |
| 918 |
for (LauncherActivityInfoInternal internal : internals.getList()) { |
| 919 |
LauncherActivityInfo lai = new LauncherActivityInfo(mContext, user, internal); |
| 920 |
if (DEBUG) { |
| 921 |
Log.v(TAG, "Returning activity for profile " + user + " : " |
| 922 |
+ lai.getComponentName()); |
| 923 |
} |
| 924 |
lais.add(lai); |
| 925 |
} |
| 926 |
return lais; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
@Nullable |
| 950 |
public IntentSender getShortcutConfigActivityIntent(@NonNull LauncherActivityInfo info) { |
| 951 |
try { |
| 952 |
return mService.getShortcutConfigActivityIntent( |
| 953 |
mContext.getPackageName(), info.getComponentName(), info.getUser()); |
| 954 |
} catch (RemoteException re) { |
| 955 |
throw re.rethrowFromSystemServer(); |
| 956 |
} |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
public boolean isPackageEnabled(String packageName, UserHandle user) { |
| 968 |
logErrorForInvalidProfileAccess(user); |
| 969 |
try { |
| 970 |
return mService.isPackageEnabled(mContext.getPackageName(), packageName, user); |
| 971 |
} catch (RemoteException re) { |
| 972 |
throw re.rethrowFromSystemServer(); |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
public @Nullable Bundle getSuspendedPackageLauncherExtras(String packageName, UserHandle user) { |
| 996 |
logErrorForInvalidProfileAccess(user); |
| 997 |
try { |
| 998 |
return mService.getSuspendedPackageLauncherExtras(packageName, user); |
| 999 |
} catch (RemoteException re) { |
| 1000 |
throw re.rethrowFromSystemServer(); |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
public boolean shouldHideFromSuggestions(@NonNull String packageName, |
| 1014 |
@NonNull UserHandle user) { |
| 1015 |
Objects.requireNonNull(packageName, "packageName"); |
| 1016 |
Objects.requireNonNull(user, "user"); |
| 1017 |
try { |
| 1018 |
return mService.shouldHideFromSuggestions(packageName, user); |
| 1019 |
} catch (RemoteException re) { |
| 1020 |
throw re.rethrowFromSystemServer(); |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
public ApplicationInfo getApplicationInfo(@NonNull String packageName, |
| 1036 |
@ApplicationInfoFlagsBits int flags, @NonNull UserHandle user) |
| 1037 |
throws PackageManager.NameNotFoundException { |
| 1038 |
Objects.requireNonNull(packageName, "packageName"); |
| 1039 |
Objects.requireNonNull(user, "user"); |
| 1040 |
logErrorForInvalidProfileAccess(user); |
| 1041 |
try { |
| 1042 |
final ApplicationInfo ai = mService |
| 1043 |
.getApplicationInfo(mContext.getPackageName(), packageName, flags, user); |
| 1044 |
if (ai == null) { |
| 1045 |
throw new NameNotFoundException("Package " + packageName + " not found for user " |
| 1046 |
+ user.getIdentifier()); |
| 1047 |
} |
| 1048 |
return ai; |
| 1049 |
} catch (RemoteException re) { |
| 1050 |
throw re.rethrowFromSystemServer(); |
| 1051 |
} |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
@Nullable |
| 1068 |
@SystemApi |
| 1069 |
public LauncherApps.AppUsageLimit getAppUsageLimit(@NonNull String packageName, |
| 1070 |
@NonNull UserHandle user) { |
| 1071 |
try { |
| 1072 |
return mService.getAppUsageLimit(mContext.getPackageName(), packageName, user); |
| 1073 |
} catch (RemoteException re) { |
| 1074 |
throw re.rethrowFromSystemServer(); |
| 1075 |
} |
| 1076 |
} |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
public boolean isActivityEnabled(ComponentName component, UserHandle user) { |
| 1090 |
logErrorForInvalidProfileAccess(user); |
| 1091 |
try { |
| 1092 |
return mService.isActivityEnabled(mContext.getPackageName(), component, user); |
| 1093 |
} catch (RemoteException re) { |
| 1094 |
throw re.rethrowFromSystemServer(); |
| 1095 |
} |
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
public boolean hasShortcutHostPermission() { |
| 1119 |
try { |
| 1120 |
return mService.hasShortcutHostPermission(mContext.getPackageName()); |
| 1121 |
} catch (RemoteException re) { |
| 1122 |
throw re.rethrowFromSystemServer(); |
| 1123 |
} |
| 1124 |
} |
| 1125 |
|
| 1126 |
private List<ShortcutInfo> maybeUpdateDisabledMessage(List<ShortcutInfo> shortcuts) { |
| 1127 |
if (shortcuts == null) { |
| 1128 |
return null; |
| 1129 |
} |
| 1130 |
for (int i = shortcuts.size() - 1; i >= 0; i--) { |
| 1131 |
final ShortcutInfo si = shortcuts.get(i); |
| 1132 |
final String message = ShortcutInfo.getDisabledReasonForRestoreIssue(mContext, |
| 1133 |
si.getDisabledReason()); |
| 1134 |
if (message != null) { |
| 1135 |
si.setDisabledMessage(message); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
return shortcuts; |
| 1139 |
} |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
@Nullable |
| 1157 |
public List<ShortcutInfo> getShortcuts(@NonNull ShortcutQuery query, |
| 1158 |
@NonNull UserHandle user) { |
| 1159 |
logErrorForInvalidProfileAccess(user); |
| 1160 |
try { |
| 1161 |
if ((query.mQueryFlags & ShortcutQuery.FLAG_GET_PERSISTED_DATA) != 0) { |
| 1162 |
return getShortcutsBlocked(query, user); |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
return maybeUpdateDisabledMessage(mService.getShortcuts(mContext.getPackageName(), |
| 1171 |
new ShortcutQueryWrapper(query), user) |
| 1172 |
.getList()); |
| 1173 |
} catch (RemoteException e) { |
| 1174 |
throw e.rethrowFromSystemServer(); |
| 1175 |
} |
| 1176 |
} |
| 1177 |
|
| 1178 |
private List<ShortcutInfo> getShortcutsBlocked(@NonNull ShortcutQuery query, |
| 1179 |
@NonNull UserHandle user) { |
| 1180 |
logErrorForInvalidProfileAccess(user); |
| 1181 |
final AndroidFuture<List<ShortcutInfo>> future = new AndroidFuture<>(); |
| 1182 |
future.thenApply(this::maybeUpdateDisabledMessage); |
| 1183 |
try { |
| 1184 |
mService.getShortcutsAsync(mContext.getPackageName(), |
| 1185 |
new ShortcutQueryWrapper(query), user, future); |
| 1186 |
return future.get(); |
| 1187 |
} catch (RemoteException e) { |
| 1188 |
throw e.rethrowFromSystemServer(); |
| 1189 |
} catch (InterruptedException | ExecutionException e) { |
| 1190 |
throw new RuntimeException(e); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
@Nullable |
| 1198 |
@Deprecated |
| 1199 |
public List<ShortcutInfo> getShortcutInfo(@NonNull String packageName, |
| 1200 |
@NonNull List<String> ids, @NonNull UserHandle user) { |
| 1201 |
final ShortcutQuery q = new ShortcutQuery(); |
| 1202 |
q.setPackage(packageName); |
| 1203 |
q.setShortcutIds(ids); |
| 1204 |
q.setQueryFlags(ShortcutQuery.FLAG_GET_ALL_KINDS); |
| 1205 |
return getShortcuts(q, user); |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
public void pinShortcuts(@NonNull String packageName, @NonNull List<String> shortcutIds, |
| 1226 |
@NonNull UserHandle user) { |
| 1227 |
logErrorForInvalidProfileAccess(user); |
| 1228 |
try { |
| 1229 |
mService.pinShortcuts(mContext.getPackageName(), packageName, shortcutIds, user); |
| 1230 |
} catch (RemoteException e) { |
| 1231 |
throw e.rethrowFromSystemServer(); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
@RequiresPermission(android.Manifest.permission.ACCESS_SHORTCUTS) |
| 1262 |
public void cacheShortcuts(@NonNull String packageName, @NonNull List<String> shortcutIds, |
| 1263 |
@NonNull UserHandle user, @ShortcutCacheFlags int cacheFlags) { |
| 1264 |
logErrorForInvalidProfileAccess(user); |
| 1265 |
try { |
| 1266 |
mService.cacheShortcuts( |
| 1267 |
mContext.getPackageName(), packageName, shortcutIds, user, cacheFlags); |
| 1268 |
} catch (RemoteException e) { |
| 1269 |
throw e.rethrowFromSystemServer(); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
@RequiresPermission(android.Manifest.permission.ACCESS_SHORTCUTS) |
| 1293 |
public void uncacheShortcuts(@NonNull String packageName, @NonNull List<String> shortcutIds, |
| 1294 |
@NonNull UserHandle user, @ShortcutCacheFlags int cacheFlags) { |
| 1295 |
logErrorForInvalidProfileAccess(user); |
| 1296 |
try { |
| 1297 |
mService.uncacheShortcuts( |
| 1298 |
mContext.getPackageName(), packageName, shortcutIds, user, cacheFlags); |
| 1299 |
} catch (RemoteException e) { |
| 1300 |
throw e.rethrowFromSystemServer(); |
| 1301 |
} |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
@Deprecated |
| 1308 |
public int getShortcutIconResId(@NonNull ShortcutInfo shortcut) { |
| 1309 |
return shortcut.getIconResourceId(); |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
@Deprecated |
| 1316 |
public int getShortcutIconResId(@NonNull String packageName, @NonNull String shortcutId, |
| 1317 |
@NonNull UserHandle user) { |
| 1318 |
final ShortcutQuery q = new ShortcutQuery(); |
| 1319 |
q.setPackage(packageName); |
| 1320 |
q.setShortcutIds(Arrays.asList(shortcutId)); |
| 1321 |
q.setQueryFlags(ShortcutQuery.FLAG_GET_ALL_KINDS); |
| 1322 |
final List<ShortcutInfo> shortcuts = getShortcuts(q, user); |
| 1323 |
|
| 1324 |
return shortcuts.size() > 0 ? shortcuts.get(0).getIconResourceId() : 0; |
| 1325 |
} |
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
public ParcelFileDescriptor getShortcutIconFd( |
| 1331 |
@NonNull ShortcutInfo shortcut) { |
| 1332 |
return getShortcutIconFd(shortcut.getPackage(), shortcut.getId(), |
| 1333 |
shortcut.getUserId()); |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
public ParcelFileDescriptor getShortcutIconFd( |
| 1340 |
@NonNull String packageName, @NonNull String shortcutId, @NonNull UserHandle user) { |
| 1341 |
return getShortcutIconFd(packageName, shortcutId, user.getIdentifier()); |
| 1342 |
} |
| 1343 |
|
| 1344 |
private ParcelFileDescriptor getShortcutIconFd( |
| 1345 |
@NonNull String packageName, @NonNull String shortcutId, int userId) { |
| 1346 |
try { |
| 1347 |
return mService.getShortcutIconFd(mContext.getPackageName(), |
| 1348 |
packageName, shortcutId, userId); |
| 1349 |
} catch (RemoteException e) { |
| 1350 |
throw e.rethrowFromSystemServer(); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
@VisibleForTesting |
| 1358 |
public ParcelFileDescriptor getUriShortcutIconFd(@NonNull ShortcutInfo shortcut) { |
| 1359 |
return getUriShortcutIconFd(shortcut.getPackage(), shortcut.getId(), shortcut.getUserId()); |
| 1360 |
} |
| 1361 |
|
| 1362 |
private ParcelFileDescriptor getUriShortcutIconFd(@NonNull String packageName, |
| 1363 |
@NonNull String shortcutId, int userId) { |
| 1364 |
String uri = getShortcutIconUri(packageName, shortcutId, userId); |
| 1365 |
if (uri == null) { |
| 1366 |
return null; |
| 1367 |
} |
| 1368 |
try { |
| 1369 |
return mContext.getContentResolver().openFileDescriptor(Uri.parse(uri), "r"); |
| 1370 |
} catch (FileNotFoundException e) { |
| 1371 |
Log.e(TAG, "Icon file not found: " + uri); |
| 1372 |
return null; |
| 1373 |
} |
| 1374 |
} |
| 1375 |
|
| 1376 |
private String getShortcutIconUri(@NonNull String packageName, |
| 1377 |
@NonNull String shortcutId, int userId) { |
| 1378 |
String uri = null; |
| 1379 |
try { |
| 1380 |
uri = mService.getShortcutIconUri(mContext.getPackageName(), packageName, shortcutId, |
| 1381 |
userId); |
| 1382 |
} catch (RemoteException e) { |
| 1383 |
throw e.rethrowFromSystemServer(); |
| 1384 |
} |
| 1385 |
return uri; |
| 1386 |
} |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
public Drawable getShortcutIconDrawable(@NonNull ShortcutInfo shortcut, int density) { |
| 1406 |
if (shortcut.hasIconFile()) { |
| 1407 |
final ParcelFileDescriptor pfd = getShortcutIconFd(shortcut); |
| 1408 |
return loadDrawableFromFileDescriptor(pfd, shortcut.hasAdaptiveBitmap()); |
| 1409 |
} else if (shortcut.hasIconUri()) { |
| 1410 |
final ParcelFileDescriptor pfd = getUriShortcutIconFd(shortcut); |
| 1411 |
return loadDrawableFromFileDescriptor(pfd, shortcut.hasAdaptiveBitmap()); |
| 1412 |
} else if (shortcut.hasIconResource()) { |
| 1413 |
return loadDrawableResourceFromPackage(shortcut.getPackage(), |
| 1414 |
shortcut.getIconResourceId(), shortcut.getUserHandle(), density); |
| 1415 |
} else if (shortcut.getIcon() != null) { |
| 1416 |
|
| 1417 |
final Icon icon = shortcut.getIcon(); |
| 1418 |
switch (icon.getType()) { |
| 1419 |
case Icon.TYPE_RESOURCE: { |
| 1420 |
return loadDrawableResourceFromPackage(shortcut.getPackage(), |
| 1421 |
icon.getResId(), shortcut.getUserHandle(), density); |
| 1422 |
} |
| 1423 |
case Icon.TYPE_BITMAP: |
| 1424 |
case Icon.TYPE_ADAPTIVE_BITMAP: { |
| 1425 |
return icon.loadDrawable(mContext); |
| 1426 |
} |
| 1427 |
default: |
| 1428 |
return null; |
| 1429 |
} |
| 1430 |
} else { |
| 1431 |
return null; |
| 1432 |
} |
| 1433 |
} |
| 1434 |
|
| 1435 |
private Drawable loadDrawableFromFileDescriptor(ParcelFileDescriptor pfd, boolean adaptive) { |
| 1436 |
if (pfd == null) { |
| 1437 |
return null; |
| 1438 |
} |
| 1439 |
try { |
| 1440 |
final Bitmap bmp = BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor()); |
| 1441 |
if (bmp != null) { |
| 1442 |
BitmapDrawable dr = new BitmapDrawable(mContext.getResources(), bmp); |
| 1443 |
if (adaptive) { |
| 1444 |
return new AdaptiveIconDrawable(null, dr); |
| 1445 |
} else { |
| 1446 |
return dr; |
| 1447 |
} |
| 1448 |
} |
| 1449 |
return null; |
| 1450 |
} finally { |
| 1451 |
try { |
| 1452 |
pfd.close(); |
| 1453 |
} catch (IOException ignore) { |
| 1454 |
} |
| 1455 |
} |
| 1456 |
} |
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
public Icon getShortcutIcon(@NonNull ShortcutInfo shortcut) { |
| 1462 |
if (shortcut.hasIconFile()) { |
| 1463 |
final ParcelFileDescriptor pfd = getShortcutIconFd(shortcut); |
| 1464 |
if (pfd == null) { |
| 1465 |
return null; |
| 1466 |
} |
| 1467 |
try { |
| 1468 |
final Bitmap bmp = BitmapFactory.decodeFileDescriptor(pfd.getFileDescriptor()); |
| 1469 |
if (bmp != null) { |
| 1470 |
if (shortcut.hasAdaptiveBitmap()) { |
| 1471 |
return Icon.createWithAdaptiveBitmap(bmp); |
| 1472 |
} else { |
| 1473 |
return Icon.createWithBitmap(bmp); |
| 1474 |
} |
| 1475 |
} |
| 1476 |
return null; |
| 1477 |
} finally { |
| 1478 |
try { |
| 1479 |
pfd.close(); |
| 1480 |
} catch (IOException ignore) { |
| 1481 |
} |
| 1482 |
} |
| 1483 |
} else if (shortcut.hasIconUri()) { |
| 1484 |
String uri = getShortcutIconUri(shortcut.getPackage(), shortcut.getId(), |
| 1485 |
shortcut.getUserId()); |
| 1486 |
if (uri == null) { |
| 1487 |
return null; |
| 1488 |
} |
| 1489 |
if (shortcut.hasAdaptiveBitmap()) { |
| 1490 |
return Icon.createWithAdaptiveBitmapContentUri(uri); |
| 1491 |
} else { |
| 1492 |
return Icon.createWithContentUri(uri); |
| 1493 |
} |
| 1494 |
} else if (shortcut.hasIconResource()) { |
| 1495 |
return Icon.createWithResource(shortcut.getPackage(), shortcut.getIconResourceId()); |
| 1496 |
} else { |
| 1497 |
return shortcut.getIcon(); |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
private Drawable loadDrawableResourceFromPackage(String packageName, int resId, |
| 1502 |
UserHandle user, int density) { |
| 1503 |
try { |
| 1504 |
if (resId == 0) { |
| 1505 |
return null; |
| 1506 |
} |
| 1507 |
final ApplicationInfo ai = getApplicationInfo(packageName, 0, user); |
| 1508 |
final Resources res = mContext.getPackageManager().getResourcesForApplication(ai); |
| 1509 |
return res.getDrawableForDensity(resId, density); |
| 1510 |
} catch (NameNotFoundException | Resources.NotFoundException e) { |
| 1511 |
return null; |
| 1512 |
} |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
public Drawable getShortcutBadgedIconDrawable(ShortcutInfo shortcut, int density) { |
| 1531 |
final Drawable originalIcon = getShortcutIconDrawable(shortcut, density); |
| 1532 |
|
| 1533 |
return (originalIcon == null) ? null : mContext.getPackageManager().getUserBadgedIcon( |
| 1534 |
originalIcon, shortcut.getUserHandle()); |
| 1535 |
} |
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
public void startShortcut(@NonNull String packageName, @NonNull String shortcutId, |
| 1555 |
@Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions, |
| 1556 |
@NonNull UserHandle user) { |
| 1557 |
logErrorForInvalidProfileAccess(user); |
| 1558 |
|
| 1559 |
startShortcut(packageName, shortcutId, sourceBounds, startActivityOptions, |
| 1560 |
user.getIdentifier()); |
| 1561 |
} |
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
public void startShortcut(@NonNull ShortcutInfo shortcut, |
| 1579 |
@Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions) { |
| 1580 |
startShortcut(shortcut.getPackage(), shortcut.getId(), |
| 1581 |
sourceBounds, startActivityOptions, |
| 1582 |
shortcut.getUserId()); |
| 1583 |
} |
| 1584 |
|
| 1585 |
@UnsupportedAppUsage |
| 1586 |
private void startShortcut(@NonNull String packageName, @NonNull String shortcutId, |
| 1587 |
@Nullable Rect sourceBounds, @Nullable Bundle startActivityOptions, |
| 1588 |
int userId) { |
| 1589 |
try { |
| 1590 |
final boolean success = mService.startShortcut(mContext.getPackageName(), packageName, |
| 1591 |
null , shortcutId, sourceBounds, startActivityOptions, |
| 1592 |
userId); |
| 1593 |
if (!success) { |
| 1594 |
throw new ActivityNotFoundException("Shortcut could not be started"); |
| 1595 |
} |
| 1596 |
} catch (RemoteException e) { |
| 1597 |
throw e.rethrowFromSystemServer(); |
| 1598 |
} |
| 1599 |
} |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
public void registerCallback(Callback callback) { |
| 1607 |
registerCallback(callback, null); |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
public void registerCallback(Callback callback, Handler handler) { |
| 1617 |
synchronized (this) { |
| 1618 |
if (callback != null && findCallbackLocked(callback) < 0) { |
| 1619 |
boolean addedFirstCallback = mCallbacks.size() == 0; |
| 1620 |
addCallbackLocked(callback, handler); |
| 1621 |
if (addedFirstCallback) { |
| 1622 |
try { |
| 1623 |
mService.addOnAppsChangedListener(mContext.getPackageName(), |
| 1624 |
mAppsChangedListener); |
| 1625 |
} catch (RemoteException re) { |
| 1626 |
throw re.rethrowFromSystemServer(); |
| 1627 |
} |
| 1628 |
} |
| 1629 |
} |
| 1630 |
} |
| 1631 |
} |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
public void unregisterCallback(Callback callback) { |
| 1640 |
synchronized (this) { |
| 1641 |
removeCallbackLocked(callback); |
| 1642 |
if (mCallbacks.size() == 0) { |
| 1643 |
try { |
| 1644 |
mService.removeOnAppsChangedListener(mAppsChangedListener); |
| 1645 |
} catch (RemoteException re) { |
| 1646 |
throw re.rethrowFromSystemServer(); |
| 1647 |
} |
| 1648 |
} |
| 1649 |
} |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
private int findCallbackLocked(Callback callback) { |
| 1654 |
if (callback == null) { |
| 1655 |
throw new IllegalArgumentException("Callback cannot be null"); |
| 1656 |
} |
| 1657 |
final int size = mCallbacks.size(); |
| 1658 |
for (int i = 0; i < size; ++i) { |
| 1659 |
if (mCallbacks.get(i).mCallback == callback) { |
| 1660 |
return i; |
| 1661 |
} |
| 1662 |
} |
| 1663 |
return -1; |
| 1664 |
} |
| 1665 |
|
| 1666 |
private void removeCallbackLocked(Callback callback) { |
| 1667 |
int pos = findCallbackLocked(callback); |
| 1668 |
if (pos >= 0) { |
| 1669 |
mCallbacks.remove(pos); |
| 1670 |
} |
| 1671 |
} |
| 1672 |
|
| 1673 |
private void addCallbackLocked(Callback callback, Handler handler) { |
| 1674 |
|
| 1675 |
removeCallbackLocked(callback); |
| 1676 |
if (handler == null) { |
| 1677 |
handler = new Handler(); |
| 1678 |
} |
| 1679 |
CallbackMessageHandler toAdd = new CallbackMessageHandler(handler.getLooper(), callback); |
| 1680 |
mCallbacks.add(toAdd); |
| 1681 |
} |
| 1682 |
|
| 1683 |
private IOnAppsChangedListener.Stub mAppsChangedListener = new IOnAppsChangedListener.Stub() { |
| 1684 |
|
| 1685 |
@Override |
| 1686 |
public void onPackageRemoved(UserHandle user, String packageName) |
| 1687 |
throws RemoteException { |
| 1688 |
if (DEBUG) { |
| 1689 |
Log.d(TAG, "onPackageRemoved " + user.getIdentifier() + "," + packageName); |
| 1690 |
} |
| 1691 |
synchronized (LauncherApps.this) { |
| 1692 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1693 |
callback.postOnPackageRemoved(packageName, user); |
| 1694 |
} |
| 1695 |
} |
| 1696 |
} |
| 1697 |
|
| 1698 |
@Override |
| 1699 |
public void onPackageChanged(UserHandle user, String packageName) throws RemoteException { |
| 1700 |
if (DEBUG) { |
| 1701 |
Log.d(TAG, "onPackageChanged " + user.getIdentifier() + "," + packageName); |
| 1702 |
} |
| 1703 |
synchronized (LauncherApps.this) { |
| 1704 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1705 |
callback.postOnPackageChanged(packageName, user); |
| 1706 |
} |
| 1707 |
} |
| 1708 |
} |
| 1709 |
|
| 1710 |
@Override |
| 1711 |
public void onPackageAdded(UserHandle user, String packageName) throws RemoteException { |
| 1712 |
if (DEBUG) { |
| 1713 |
Log.d(TAG, "onPackageAdded " + user.getIdentifier() + "," + packageName); |
| 1714 |
} |
| 1715 |
synchronized (LauncherApps.this) { |
| 1716 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1717 |
callback.postOnPackageAdded(packageName, user); |
| 1718 |
} |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
@Override |
| 1723 |
public void onPackagesAvailable(UserHandle user, String[] packageNames, boolean replacing) |
| 1724 |
throws RemoteException { |
| 1725 |
if (DEBUG) { |
| 1726 |
Log.d(TAG, "onPackagesAvailable " + user.getIdentifier() + "," |
| 1727 |
+ Arrays.toString(packageNames)); |
| 1728 |
} |
| 1729 |
synchronized (LauncherApps.this) { |
| 1730 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1731 |
callback.postOnPackagesAvailable(packageNames, user, replacing); |
| 1732 |
} |
| 1733 |
} |
| 1734 |
} |
| 1735 |
|
| 1736 |
@Override |
| 1737 |
public void onPackagesUnavailable(UserHandle user, String[] packageNames, boolean replacing) |
| 1738 |
throws RemoteException { |
| 1739 |
if (DEBUG) { |
| 1740 |
Log.d(TAG, "onPackagesUnavailable " + user.getIdentifier() + "," |
| 1741 |
+ Arrays.toString(packageNames)); |
| 1742 |
} |
| 1743 |
synchronized (LauncherApps.this) { |
| 1744 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1745 |
callback.postOnPackagesUnavailable(packageNames, user, replacing); |
| 1746 |
} |
| 1747 |
} |
| 1748 |
} |
| 1749 |
|
| 1750 |
@Override |
| 1751 |
public void onPackagesSuspended(UserHandle user, String[] packageNames, |
| 1752 |
Bundle launcherExtras) |
| 1753 |
throws RemoteException { |
| 1754 |
if (DEBUG) { |
| 1755 |
Log.d(TAG, "onPackagesSuspended " + user.getIdentifier() + "," |
| 1756 |
+ Arrays.toString(packageNames)); |
| 1757 |
} |
| 1758 |
synchronized (LauncherApps.this) { |
| 1759 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1760 |
callback.postOnPackagesSuspended(packageNames, launcherExtras, user); |
| 1761 |
} |
| 1762 |
} |
| 1763 |
} |
| 1764 |
|
| 1765 |
@Override |
| 1766 |
public void onPackagesUnsuspended(UserHandle user, String[] packageNames) |
| 1767 |
throws RemoteException { |
| 1768 |
if (DEBUG) { |
| 1769 |
Log.d(TAG, "onPackagesUnsuspended " + user.getIdentifier() + "," |
| 1770 |
+ Arrays.toString(packageNames)); |
| 1771 |
} |
| 1772 |
synchronized (LauncherApps.this) { |
| 1773 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1774 |
callback.postOnPackagesUnsuspended(packageNames, user); |
| 1775 |
} |
| 1776 |
} |
| 1777 |
} |
| 1778 |
|
| 1779 |
@Override |
| 1780 |
public void onShortcutChanged(UserHandle user, String packageName, |
| 1781 |
ParceledListSlice shortcuts) { |
| 1782 |
if (DEBUG) { |
| 1783 |
Log.d(TAG, "onShortcutChanged " + user.getIdentifier() + "," + packageName); |
| 1784 |
} |
| 1785 |
final List<ShortcutInfo> list = shortcuts.getList(); |
| 1786 |
synchronized (LauncherApps.this) { |
| 1787 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1788 |
callback.postOnShortcutChanged(packageName, user, list); |
| 1789 |
} |
| 1790 |
} |
| 1791 |
} |
| 1792 |
|
| 1793 |
public void onPackageLoadingProgressChanged(UserHandle user, String packageName, |
| 1794 |
float progress) { |
| 1795 |
if (DEBUG) { |
| 1796 |
Log.d(TAG, "onPackageLoadingProgressChanged " + user.getIdentifier() + "," |
| 1797 |
+ packageName + "," + progress); |
| 1798 |
} |
| 1799 |
synchronized (LauncherApps.this) { |
| 1800 |
for (CallbackMessageHandler callback : mCallbacks) { |
| 1801 |
callback.postOnPackageLoadingProgressChanged(user, packageName, progress); |
| 1802 |
} |
| 1803 |
} |
| 1804 |
} |
| 1805 |
}; |
| 1806 |
|
| 1807 |
private static class CallbackMessageHandler extends Handler { |
| 1808 |
private static final int MSG_ADDED = 1; |
| 1809 |
private static final int MSG_REMOVED = 2; |
| 1810 |
private static final int MSG_CHANGED = 3; |
| 1811 |
private static final int MSG_AVAILABLE = 4; |
| 1812 |
private static final int MSG_UNAVAILABLE = 5; |
| 1813 |
private static final int MSG_SUSPENDED = 6; |
| 1814 |
private static final int MSG_UNSUSPENDED = 7; |
| 1815 |
private static final int MSG_SHORTCUT_CHANGED = 8; |
| 1816 |
private static final int MSG_LOADING_PROGRESS_CHANGED = 9; |
| 1817 |
|
| 1818 |
private LauncherApps.Callback mCallback; |
| 1819 |
|
| 1820 |
private static class CallbackInfo { |
| 1821 |
String[] packageNames; |
| 1822 |
String packageName; |
| 1823 |
Bundle launcherExtras; |
| 1824 |
boolean replacing; |
| 1825 |
UserHandle user; |
| 1826 |
List<ShortcutInfo> shortcuts; |
| 1827 |
float mLoadingProgress; |
| 1828 |
} |
| 1829 |
|
| 1830 |
public CallbackMessageHandler(Looper looper, LauncherApps.Callback callback) { |
| 1831 |
super(looper, null, true); |
| 1832 |
mCallback = callback; |
| 1833 |
} |
| 1834 |
|
| 1835 |
@Override |
| 1836 |
public void handleMessage(Message msg) { |
| 1837 |
if (mCallback == null || !(msg.obj instanceof CallbackInfo)) { |
| 1838 |
return; |
| 1839 |
} |
| 1840 |
CallbackInfo info = (CallbackInfo) msg.obj; |
| 1841 |
switch (msg.what) { |
| 1842 |
case MSG_ADDED: |
| 1843 |
mCallback.onPackageAdded(info.packageName, info.user); |
| 1844 |
break; |
| 1845 |
case MSG_REMOVED: |
| 1846 |
mCallback.onPackageRemoved(info.packageName, info.user); |
| 1847 |
break; |
| 1848 |
case MSG_CHANGED: |
| 1849 |
mCallback.onPackageChanged(info.packageName, info.user); |
| 1850 |
break; |
| 1851 |
case MSG_AVAILABLE: |
| 1852 |
mCallback.onPackagesAvailable(info.packageNames, info.user, info.replacing); |
| 1853 |
break; |
| 1854 |
case MSG_UNAVAILABLE: |
| 1855 |
mCallback.onPackagesUnavailable(info.packageNames, info.user, info.replacing); |
| 1856 |
break; |
| 1857 |
case MSG_SUSPENDED: |
| 1858 |
mCallback.onPackagesSuspended(info.packageNames, info.user, info.launcherExtras |
| 1859 |
); |
| 1860 |
break; |
| 1861 |
case MSG_UNSUSPENDED: |
| 1862 |
mCallback.onPackagesUnsuspended(info.packageNames, info.user); |
| 1863 |
break; |
| 1864 |
case MSG_SHORTCUT_CHANGED: |
| 1865 |
mCallback.onShortcutsChanged(info.packageName, info.shortcuts, info.user); |
| 1866 |
break; |
| 1867 |
case MSG_LOADING_PROGRESS_CHANGED: |
| 1868 |
mCallback.onPackageLoadingProgressChanged(info.packageName, info.user, |
| 1869 |
info.mLoadingProgress); |
| 1870 |
break; |
| 1871 |
} |
| 1872 |
} |
| 1873 |
|
| 1874 |
public void postOnPackageAdded(String packageName, UserHandle user) { |
| 1875 |
CallbackInfo info = new CallbackInfo(); |
| 1876 |
info.packageName = packageName; |
| 1877 |
info.user = user; |
| 1878 |
obtainMessage(MSG_ADDED, info).sendToTarget(); |
| 1879 |
} |
| 1880 |
|
| 1881 |
public void postOnPackageRemoved(String packageName, UserHandle user) { |
| 1882 |
CallbackInfo info = new CallbackInfo(); |
| 1883 |
info.packageName = packageName; |
| 1884 |
info.user = user; |
| 1885 |
obtainMessage(MSG_REMOVED, info).sendToTarget(); |
| 1886 |
} |
| 1887 |
|
| 1888 |
public void postOnPackageChanged(String packageName, UserHandle user) { |
| 1889 |
CallbackInfo info = new CallbackInfo(); |
| 1890 |
info.packageName = packageName; |
| 1891 |
info.user = user; |
| 1892 |
obtainMessage(MSG_CHANGED, info).sendToTarget(); |
| 1893 |
} |
| 1894 |
|
| 1895 |
public void postOnPackagesAvailable(String[] packageNames, UserHandle user, |
| 1896 |
boolean replacing) { |
| 1897 |
CallbackInfo info = new CallbackInfo(); |
| 1898 |
info.packageNames = packageNames; |
| 1899 |
info.replacing = replacing; |
| 1900 |
info.user = user; |
| 1901 |
obtainMessage(MSG_AVAILABLE, info).sendToTarget(); |
| 1902 |
} |
| 1903 |
|
| 1904 |
public void postOnPackagesUnavailable(String[] packageNames, UserHandle user, |
| 1905 |
boolean replacing) { |
| 1906 |
CallbackInfo info = new CallbackInfo(); |
| 1907 |
info.packageNames = packageNames; |
| 1908 |
info.replacing = replacing; |
| 1909 |
info.user = user; |
| 1910 |
obtainMessage(MSG_UNAVAILABLE, info).sendToTarget(); |
| 1911 |
} |
| 1912 |
|
| 1913 |
public void postOnPackagesSuspended(String[] packageNames, Bundle launcherExtras, |
| 1914 |
UserHandle user) { |
| 1915 |
CallbackInfo info = new CallbackInfo(); |
| 1916 |
info.packageNames = packageNames; |
| 1917 |
info.user = user; |
| 1918 |
info.launcherExtras = launcherExtras; |
| 1919 |
obtainMessage(MSG_SUSPENDED, info).sendToTarget(); |
| 1920 |
} |
| 1921 |
|
| 1922 |
public void postOnPackagesUnsuspended(String[] packageNames, UserHandle user) { |
| 1923 |
CallbackInfo info = new CallbackInfo(); |
| 1924 |
info.packageNames = packageNames; |
| 1925 |
info.user = user; |
| 1926 |
obtainMessage(MSG_UNSUSPENDED, info).sendToTarget(); |
| 1927 |
} |
| 1928 |
|
| 1929 |
public void postOnShortcutChanged(String packageName, UserHandle user, |
| 1930 |
List<ShortcutInfo> shortcuts) { |
| 1931 |
CallbackInfo info = new CallbackInfo(); |
| 1932 |
info.packageName = packageName; |
| 1933 |
info.user = user; |
| 1934 |
info.shortcuts = shortcuts; |
| 1935 |
obtainMessage(MSG_SHORTCUT_CHANGED, info).sendToTarget(); |
| 1936 |
} |
| 1937 |
|
| 1938 |
public void postOnPackageLoadingProgressChanged(UserHandle user, String packageName, |
| 1939 |
float progress) { |
| 1940 |
CallbackInfo info = new CallbackInfo(); |
| 1941 |
info.packageName = packageName; |
| 1942 |
info.user = user; |
| 1943 |
info.mLoadingProgress = progress; |
| 1944 |
obtainMessage(MSG_LOADING_PROGRESS_CHANGED, info).sendToTarget(); |
| 1945 |
} |
| 1946 |
} |
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
public void registerPackageInstallerSessionCallback( |
| 1960 |
@NonNull @CallbackExecutor Executor executor, @NonNull SessionCallback callback) { |
| 1961 |
if (executor == null) { |
| 1962 |
throw new NullPointerException("Executor must not be null"); |
| 1963 |
} |
| 1964 |
|
| 1965 |
synchronized (mDelegates) { |
| 1966 |
final SessionCallbackDelegate delegate = new SessionCallbackDelegate(callback, |
| 1967 |
executor); |
| 1968 |
try { |
| 1969 |
mService.registerPackageInstallerCallback(mContext.getPackageName(), |
| 1970 |
delegate); |
| 1971 |
} catch (RemoteException e) { |
| 1972 |
throw e.rethrowFromSystemServer(); |
| 1973 |
} |
| 1974 |
mDelegates.add(delegate); |
| 1975 |
} |
| 1976 |
} |
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
public void unregisterPackageInstallerSessionCallback(@NonNull SessionCallback callback) { |
| 1985 |
synchronized (mDelegates) { |
| 1986 |
for (Iterator<SessionCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) { |
| 1987 |
final SessionCallbackDelegate delegate = i.next(); |
| 1988 |
if (delegate.mCallback == callback) { |
| 1989 |
mPm.getPackageInstaller().unregisterSessionCallback(delegate.mCallback); |
| 1990 |
i.remove(); |
| 1991 |
} |
| 1992 |
} |
| 1993 |
} |
| 1994 |
} |
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
public @NonNull List<SessionInfo> getAllPackageInstallerSessions() { |
| 2005 |
try { |
| 2006 |
return mService.getAllSessions(mContext.getPackageName()).getList(); |
| 2007 |
} catch (RemoteException e) { |
| 2008 |
throw e.rethrowFromSystemServer(); |
| 2009 |
} |
| 2010 |
} |
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
public void registerShortcutChangeCallback(@NonNull ShortcutChangeCallback callback, |
| 2024 |
@NonNull ShortcutQuery query, @NonNull @CallbackExecutor Executor executor) { |
| 2025 |
Objects.requireNonNull(callback, "Callback cannot be null"); |
| 2026 |
Objects.requireNonNull(query, "Query cannot be null"); |
| 2027 |
Objects.requireNonNull(executor, "Executor cannot be null"); |
| 2028 |
|
| 2029 |
synchronized (mShortcutChangeCallbacks) { |
| 2030 |
IShortcutChangeCallback proxy = new ShortcutChangeCallbackProxy(executor, callback); |
| 2031 |
mShortcutChangeCallbacks.put(callback, new Pair<>(executor, proxy)); |
| 2032 |
try { |
| 2033 |
mService.registerShortcutChangeCallback(mContext.getPackageName(), |
| 2034 |
new ShortcutQueryWrapper(query), proxy); |
| 2035 |
} catch (RemoteException e) { |
| 2036 |
throw e.rethrowFromSystemServer(); |
| 2037 |
} |
| 2038 |
} |
| 2039 |
} |
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
public void unregisterShortcutChangeCallback(@NonNull ShortcutChangeCallback callback) { |
| 2050 |
Objects.requireNonNull(callback, "Callback cannot be null"); |
| 2051 |
|
| 2052 |
synchronized (mShortcutChangeCallbacks) { |
| 2053 |
if (mShortcutChangeCallbacks.containsKey(callback)) { |
| 2054 |
IShortcutChangeCallback proxy = mShortcutChangeCallbacks.remove(callback).second; |
| 2055 |
try { |
| 2056 |
mService.unregisterShortcutChangeCallback(mContext.getPackageName(), proxy); |
| 2057 |
} catch (RemoteException e) { |
| 2058 |
throw e.rethrowFromSystemServer(); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
} |
| 2062 |
} |
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
public PinItemRequest getPinItemRequest(Intent intent) { |
| 2069 |
return intent.getParcelableExtra(EXTRA_PIN_ITEM_REQUEST); |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
public static final class PinItemRequest implements Parcelable { |
| 2110 |
|
| 2111 |
|
| 2112 |
public static final int REQUEST_TYPE_SHORTCUT = 1; |
| 2113 |
|
| 2114 |
|
| 2115 |
public static final int REQUEST_TYPE_APPWIDGET = 2; |
| 2116 |
|
| 2117 |
|
| 2118 |
@IntDef(prefix = { "REQUEST_TYPE_" }, value = { |
| 2119 |
REQUEST_TYPE_SHORTCUT, |
| 2120 |
REQUEST_TYPE_APPWIDGET |
| 2121 |
}) |
| 2122 |
@Retention(RetentionPolicy.SOURCE) |
| 2123 |
public @interface RequestType {} |
| 2124 |
|
| 2125 |
private final int mRequestType; |
| 2126 |
private final IPinItemRequest mInner; |
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
public PinItemRequest(IPinItemRequest inner, int type) { |
| 2132 |
mInner = inner; |
| 2133 |
mRequestType = type; |
| 2134 |
} |
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
@RequestType |
| 2142 |
public int getRequestType() { |
| 2143 |
return mRequestType; |
| 2144 |
} |
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
@Nullable |
| 2155 |
public ShortcutInfo getShortcutInfo() { |
| 2156 |
try { |
| 2157 |
return mInner.getShortcutInfo(); |
| 2158 |
} catch (RemoteException e) { |
| 2159 |
throw e.rethrowAsRuntimeException(); |
| 2160 |
} |
| 2161 |
} |
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
@Nullable |
| 2176 |
public AppWidgetProviderInfo getAppWidgetProviderInfo(Context context) { |
| 2177 |
try { |
| 2178 |
final AppWidgetProviderInfo info = mInner.getAppWidgetProviderInfo(); |
| 2179 |
if (info == null) { |
| 2180 |
return null; |
| 2181 |
} |
| 2182 |
info.updateDimensions(context.getResources().getDisplayMetrics()); |
| 2183 |
return info; |
| 2184 |
} catch (RemoteException e) { |
| 2185 |
throw e.rethrowAsRuntimeException(); |
| 2186 |
} |
| 2187 |
} |
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
@Nullable |
| 2198 |
public Bundle getExtras() { |
| 2199 |
try { |
| 2200 |
return mInner.getExtras(); |
| 2201 |
} catch (RemoteException e) { |
| 2202 |
throw e.rethrowAsRuntimeException(); |
| 2203 |
} |
| 2204 |
} |
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
public boolean isValid() { |
| 2212 |
try { |
| 2213 |
return mInner.isValid(); |
| 2214 |
} catch (RemoteException e) { |
| 2215 |
return false; |
| 2216 |
} |
| 2217 |
} |
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
public boolean accept(@Nullable Bundle options) { |
| 2229 |
try { |
| 2230 |
return mInner.accept(options); |
| 2231 |
} catch (RemoteException e) { |
| 2232 |
throw e.rethrowFromSystemServer(); |
| 2233 |
} |
| 2234 |
} |
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
public boolean accept() { |
| 2244 |
return accept( null); |
| 2245 |
} |
| 2246 |
|
| 2247 |
private PinItemRequest(Parcel source) { |
| 2248 |
final ClassLoader cl = getClass().getClassLoader(); |
| 2249 |
|
| 2250 |
mRequestType = source.readInt(); |
| 2251 |
mInner = IPinItemRequest.Stub.asInterface(source.readStrongBinder()); |
| 2252 |
} |
| 2253 |
|
| 2254 |
@Override |
| 2255 |
public void writeToParcel(Parcel dest, int flags) { |
| 2256 |
dest.writeInt(mRequestType); |
| 2257 |
dest.writeStrongBinder(mInner.asBinder()); |
| 2258 |
} |
| 2259 |
|
| 2260 |
public static final @android.annotation.NonNull Creator<PinItemRequest> CREATOR = |
| 2261 |
new Creator<PinItemRequest>() { |
| 2262 |
public PinItemRequest createFromParcel(Parcel source) { |
| 2263 |
return new PinItemRequest(source); |
| 2264 |
} |
| 2265 |
public PinItemRequest[] newArray(int size) { |
| 2266 |
return new PinItemRequest[size]; |
| 2267 |
} |
| 2268 |
}; |
| 2269 |
|
| 2270 |
@Override |
| 2271 |
public int describeContents() { |
| 2272 |
return 0; |
| 2273 |
} |
| 2274 |
} |
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
@SystemApi |
| 2288 |
public static final class AppUsageLimit implements Parcelable { |
| 2289 |
private final long mTotalUsageLimit; |
| 2290 |
private final long mUsageRemaining; |
| 2291 |
|
| 2292 |
|
| 2293 |
public AppUsageLimit(long totalUsageLimit, long usageRemaining) { |
| 2294 |
this.mTotalUsageLimit = totalUsageLimit; |
| 2295 |
this.mUsageRemaining = usageRemaining; |
| 2296 |
} |
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
public long getTotalUsageLimit() { |
| 2304 |
return mTotalUsageLimit; |
| 2305 |
} |
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
public long getUsageRemaining() { |
| 2314 |
return mUsageRemaining; |
| 2315 |
} |
| 2316 |
|
| 2317 |
private AppUsageLimit(Parcel source) { |
| 2318 |
mTotalUsageLimit = source.readLong(); |
| 2319 |
mUsageRemaining = source.readLong(); |
| 2320 |
} |
| 2321 |
|
| 2322 |
public static final @android.annotation.NonNull Creator<AppUsageLimit> CREATOR = new Creator<AppUsageLimit>() { |
| 2323 |
@Override |
| 2324 |
public AppUsageLimit createFromParcel(Parcel source) { |
| 2325 |
return new AppUsageLimit(source); |
| 2326 |
} |
| 2327 |
|
| 2328 |
@Override |
| 2329 |
public AppUsageLimit[] newArray(int size) { |
| 2330 |
return new AppUsageLimit[size]; |
| 2331 |
} |
| 2332 |
}; |
| 2333 |
|
| 2334 |
@Override |
| 2335 |
public int describeContents() { |
| 2336 |
return 0; |
| 2337 |
} |
| 2338 |
|
| 2339 |
@Override |
| 2340 |
public void writeToParcel(Parcel dest, int flags) { |
| 2341 |
dest.writeLong(mTotalUsageLimit); |
| 2342 |
dest.writeLong(mUsageRemaining); |
| 2343 |
} |
| 2344 |
} |
| 2345 |
} |