android.content.pm.IPackageManager源码实例Demo

类android.content.pm.IPackageManager源码实例Demo

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

源代码1 项目: AndroidComponentPlugin   文件: BroadcastQueue.java
/**
 * Return true if all given permissions are signature-only perms.
 */
final boolean isSignaturePerm(String[] perms) {
    if (perms == null) {
        return false;
    }
    IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = perms.length-1; i >= 0; i--) {
        try {
            PermissionInfo pi = pm.getPermissionInfo(perms[i], "android", 0);
            if ((pi.protectionLevel & (PermissionInfo.PROTECTION_MASK_BASE
                    | PermissionInfo.PROTECTION_FLAG_PRIVILEGED))
                    != PermissionInfo.PROTECTION_SIGNATURE) {
                // If this a signature permission and NOT allowed for privileged apps, it
                // is okay...  otherwise, nope!
                return false;
            }
        } catch (RemoteException e) {
            return false;
        }
    }
    return true;
}
 
源代码2 项目: android_9.0.0_r45   文件: JobSchedulerService.java
private void enforceValidJobRequest(int uid, JobInfo job) {
    final IPackageManager pm = AppGlobals.getPackageManager();
    final ComponentName service = job.getService();
    try {
        ServiceInfo si = pm.getServiceInfo(service,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                UserHandle.getUserId(uid));
        if (si == null) {
            throw new IllegalArgumentException("No such service " + service);
        }
        if (si.applicationInfo.uid != uid) {
            throw new IllegalArgumentException("uid " + uid +
                    " cannot schedule job in " + service.getPackageName());
        }
        if (!JobService.PERMISSION_BIND.equals(si.permission)) {
            throw new IllegalArgumentException("Scheduled service " + service
                    + " does not require android.permission.BIND_JOB_SERVICE permission");
        }
    } catch (RemoteException e) {
        // Can't happen; the Package Manager is in this same process
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: SenderPackageFilter.java
@Override
public boolean matches(IntentFirewall ifw, ComponentName resolvedComponent, Intent intent,
        int callerUid, int callerPid, String resolvedType, int receivingUid) {
    IPackageManager pm = AppGlobals.getPackageManager();

    int packageUid = -1;
    try {
        // USER_SYSTEM here is not important. Only app id is used and getPackageUid() will
        // return a uid whether the app is installed for a user or not.
        packageUid = pm.getPackageUid(mPackageName, PackageManager.MATCH_ANY_USER,
                UserHandle.USER_SYSTEM);
    } catch (RemoteException ex) {
        // handled below
    }

    if (packageUid == -1)  {
        return false;
    }

    return UserHandle.isSameApp(packageUid, callerUid);
}
 
源代码4 项目: android_9.0.0_r45   文件: SenderFilter.java
static boolean isPrivilegedApp(int callerUid, int callerPid) {
    if (callerUid == Process.SYSTEM_UID || callerUid == 0 ||
            callerPid == Process.myPid() || callerPid == 0) {
        return true;
    }

    IPackageManager pm = AppGlobals.getPackageManager();
    try {
        return (pm.getPrivateFlagsForUid(callerUid) & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED)
                != 0;
    } catch (RemoteException ex) {
        Slog.e(IntentFirewall.TAG, "Remote exception while retrieving uid flags",
                ex);
    }

    return false;
}
 
源代码5 项目: android_9.0.0_r45   文件: BroadcastQueue.java
/**
 * Return true if all given permissions are signature-only perms.
 */
final boolean isSignaturePerm(String[] perms) {
    if (perms == null) {
        return false;
    }
    IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = perms.length-1; i >= 0; i--) {
        try {
            PermissionInfo pi = pm.getPermissionInfo(perms[i], "android", 0);
            if ((pi.protectionLevel & (PermissionInfo.PROTECTION_MASK_BASE
                    | PermissionInfo.PROTECTION_FLAG_PRIVILEGED))
                    != PermissionInfo.PROTECTION_SIGNATURE) {
                // If this a signature permission and NOT allowed for privileged apps, it
                // is okay...  otherwise, nope!
                return false;
            }
        } catch (RemoteException e) {
            return false;
        }
    }
    return true;
}
 
源代码6 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码7 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
@VisibleForTesting
protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
        StorageManager storageManager, IPackageManager pm) {
    final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
    final List<VolumeInfo> vols = storageManager.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol)
                || isPackageCandidateVolume(mContext, app, vol, pm)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
 
源代码9 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码10 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
@VisibleForTesting
protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
        StorageManager storageManager, IPackageManager pm) {
    final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
    final List<VolumeInfo> vols = storageManager.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol)
                || isPackageCandidateVolume(mContext, app, vol, pm)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
 
源代码12 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
@VisibleForTesting
protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
        StorageManager storageManager, IPackageManager pm) {
    final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
    final List<VolumeInfo> vols = storageManager.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol)
                || isPackageCandidateVolume(mContext, app, vol, pm)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
 
源代码14 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码15 项目: AndroidComponentPlugin   文件: ActivityThread.java
public static IPackageManager getPackageManager() {
    if (sPackageManager != null) {
        //Slog.v("PackageManager", "returning cur default = " + sPackageManager);
        return sPackageManager;
    }
    IBinder b = ServiceManager.getService("package");
    //Slog.v("PackageManager", "default service binder = " + b);
    sPackageManager = IPackageManager.Stub.asInterface(b);
    //Slog.v("PackageManager", "default service = " + sPackageManager);
    return sPackageManager;
}
 
源代码16 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码17 项目: AndroidComponentPlugin   文件: ActivityThread.java
public static IPackageManager getPackageManager() {
    if (sPackageManager != null) {
        //Slog.v("PackageManager", "returning cur default = " + sPackageManager);
        return sPackageManager;
    }
    IBinder b = ServiceManager.getService("package");
    //Slog.v("PackageManager", "default service binder = " + b);
    sPackageManager = IPackageManager.Stub.asInterface(b);
    //Slog.v("PackageManager", "default service = " + sPackageManager);
    return sPackageManager;
}
 
源代码18 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码19 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码20 项目: AndroidComponentPlugin   文件: LoadedApk.java
/**
 * Setup value for Thread.getContextClassLoader(). If the
 * package will not run in in a VM with other packages, we set
 * the Java context ClassLoader to the
 * PackageInfo.getClassLoader value. However, if this VM can
 * contain multiple packages, we intead set the Java context
 * ClassLoader to a proxy that will warn about the use of Java
 * context ClassLoaders and then fall through to use the
 * system ClassLoader.
 *
 * <p> Note that this is similar to but not the same as the
 * android.content.Context.getClassLoader(). While both
 * context class loaders are typically set to the
 * PathClassLoader used to load the package archive in the
 * single application per VM case, a single Android process
 * may contain several Contexts executing on one thread with
 * their own logical ClassLoaders while the Java context
 * ClassLoader is a thread local. This is why in the case when
 * we have multiple packages per VM we do not set the Java
 * context ClassLoader to an arbitrary but instead warn the
 * user to set their own if we detect that they are using a
 * Java library that expects it to be set.
 */
private void initializeJavaContextClassLoader() {
    IPackageManager pm = ActivityThread.getPackageManager();
    android.content.pm.PackageInfo pi;
    try {
        pi = pm.getPackageInfo(mPackageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                UserHandle.myUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    if (pi == null) {
        throw new IllegalStateException("Unable to get package info for "
                + mPackageName + "; is package not installed?");
    }
    /*
     * Two possible indications that this package could be
     * sharing its virtual machine with other packages:
     *
     * 1.) the sharedUserId attribute is set in the manifest,
     *     indicating a request to share a VM with other
     *     packages with the same sharedUserId.
     *
     * 2.) the application element of the manifest has an
     *     attribute specifying a non-default process name,
     *     indicating the desire to run in another packages VM.
     */
    boolean sharedUserIdSet = (pi.sharedUserId != null);
    boolean processNameNotDefault =
        (pi.applicationInfo != null &&
         !mPackageName.equals(pi.applicationInfo.processName));
    boolean sharable = (sharedUserIdSet || processNameNotDefault);
    ClassLoader contextClassLoader =
        (sharable)
        ? new WarningContextClassLoader()
        : mClassLoader;
    Thread.currentThread().setContextClassLoader(contextClassLoader);
}
 
@VisibleForTesting
protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
        StorageManager storageManager, IPackageManager pm) {
    final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
    final List<VolumeInfo> vols = storageManager.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol)
                || isPackageCandidateVolume(mContext, app, vol, pm)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
 
源代码22 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
@VisibleForTesting
protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
        StorageManager storageManager, IPackageManager pm) {
    final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
    final List<VolumeInfo> vols = storageManager.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    for (VolumeInfo vol : vols) {
        if (Objects.equals(vol, currentVol)
                || isPackageCandidateVolume(mContext, app, vol, pm)) {
            candidates.add(vol);
        }
    }
    return candidates;
}
 
源代码24 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码25 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码26 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码27 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
源代码28 项目: AndroidComponentPlugin   文件: ContextImpl.java
@Override
public PackageManager getPackageManager() {
    if (mPackageManager != null) {
        return mPackageManager;
    }

    IPackageManager pm = ActivityThread.getPackageManager();
    if (pm != null) {
        // Doesn't matter if we make more than one instance.
        return (mPackageManager = new ApplicationPackageManager(this, pm));
    }

    return null;
}
 
/**
 * Disables BluetoothOppLauncherActivity component, so the Bluetooth sharing option is not
 * offered to the user if Bluetooth or sharing is disallowed. Puts the component to its default
 * state if Bluetooth is not disallowed.
 *
 * @param userId user to disable bluetooth sharing for.
 * @param bluetoothSharingDisallowed whether bluetooth sharing is disallowed.
 */
private void updateOppLauncherComponentState(int userId, boolean bluetoothSharingDisallowed) {
    final ComponentName oppLauncherComponent = new ComponentName("com.android.bluetooth",
            "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
    final int newState =
            bluetoothSharingDisallowed ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
    try {
        final IPackageManager imp = AppGlobals.getPackageManager();
        imp.setComponentEnabledSetting(oppLauncherComponent, newState,
                PackageManager.DONT_KILL_APP, userId);
    } catch (Exception e) {
        // The component was not found, do nothing.
    }
}
 
源代码30 项目: android_9.0.0_r45   文件: JobSchedulerService.java
int executeCancelCommand(PrintWriter pw, String pkgName, int userId,
        boolean hasJobId, int jobId) {
    if (DEBUG) {
        Slog.v(TAG, "executeCancelCommand(): " + pkgName + "/" + userId + " " + jobId);
    }

    int pkgUid = -1;
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        pkgUid = pm.getPackageUid(pkgName, 0, userId);
    } catch (RemoteException e) { /* can't happen */ }

    if (pkgUid < 0) {
        pw.println("Package " + pkgName + " not found.");
        return JobSchedulerShellCommand.CMD_ERR_NO_PACKAGE;
    }

    if (!hasJobId) {
        pw.println("Canceling all jobs for " + pkgName + " in user " + userId);
        if (!cancelJobsForUid(pkgUid, "cancel shell command for package")) {
            pw.println("No matching jobs found.");
        }
    } else {
        pw.println("Canceling job " + pkgName + "/#" + jobId + " in user " + userId);
        if (!cancelJob(pkgUid, jobId, Process.SHELL_UID)) {
            pw.println("No matching job found.");
        }
    }

    return 0;
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法