Java Code Examples for android.content.pm.PackageManagerInternal#getActivityInfo()
The following examples show how to use
android.content.pm.PackageManagerInternal#getActivityInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LauncherAppsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public ActivityInfo resolveActivity( String callingPackage, ComponentName component, UserHandle user) throws RemoteException { if (!canAccessProfile(user.getIdentifier(), "Cannot resolve activity")) { return null; } final int callingUid = injectBinderCallingUid(); long ident = Binder.clearCallingIdentity(); try { final PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class); return pmInt.getActivityInfo(component, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, callingUid, user.getIdentifier()); } finally { Binder.restoreCallingIdentity(ident); } }
Example 2
Source File: LauncherAppsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean isActivityEnabled( String callingPackage, ComponentName component, UserHandle user) throws RemoteException { if (!canAccessProfile(user.getIdentifier(), "Cannot check component")) { return false; } final int callingUid = injectBinderCallingUid(); long ident = Binder.clearCallingIdentity(); try { final PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class); ActivityInfo info = pmInt.getActivityInfo(component, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, callingUid, user.getIdentifier()); return info != null; } finally { Binder.restoreCallingIdentity(ident); } }
Example 3
Source File: LauncherAppsService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public void startActivityAsUser(IApplicationThread caller, String callingPackage, ComponentName component, Rect sourceBounds, Bundle opts, UserHandle user) throws RemoteException { if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) { return; } Intent launchIntent = new Intent(Intent.ACTION_MAIN); launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); launchIntent.setSourceBounds(sourceBounds); launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); launchIntent.setPackage(component.getPackageName()); boolean canLaunch = false; final int callingUid = injectBinderCallingUid(); long ident = Binder.clearCallingIdentity(); try { final PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class); ActivityInfo info = pmInt.getActivityInfo(component, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, callingUid, user.getIdentifier()); if (!info.exported) { throw new SecurityException("Cannot launch non-exported components " + component); } // Check that the component actually has Intent.CATEGORY_LAUCNCHER // as calling startActivityAsUser ignores the category and just // resolves based on the component if present. List<ResolveInfo> apps = pmInt.queryIntentActivities(launchIntent, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, callingUid, user.getIdentifier()); final int size = apps.size(); for (int i = 0; i < size; ++i) { ActivityInfo activityInfo = apps.get(i).activityInfo; if (activityInfo.packageName.equals(component.getPackageName()) && activityInfo.name.equals(component.getClassName())) { // Found an activity with category launcher that matches // this component so ok to launch. launchIntent.setPackage(null); launchIntent.setComponent(component); canLaunch = true; break; } } if (!canLaunch) { throw new SecurityException("Attempt to launch activity without " + " category Intent.CATEGORY_LAUNCHER " + component); } } finally { Binder.restoreCallingIdentity(ident); } mActivityManagerInternal.startActivityAsUser(caller, callingPackage, launchIntent, opts, user.getIdentifier()); }