android.content.pm.PackageManagerInternal#getActivityInfo()源码实例Demo

下面列出了android.content.pm.PackageManagerInternal#getActivityInfo() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: LauncherAppsService.java
@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);
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: LauncherAppsService.java
@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);
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: LauncherAppsService.java
@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());
}