android.content.pm.IPackageManager Java Examples

The following examples show how to use android.content.pm.IPackageManager. 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 Project: AndroidComponentPlugin   Author: androidmalin   File: BroadcastQueue.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source Project: android_9.0.0_r45   Author: lulululbj   File: JobSchedulerService.java    License: Apache License 2.0 6 votes vote down vote up
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
    }
}
 
Example #3
Source Project: android_9.0.0_r45   Author: lulululbj   File: SenderPackageFilter.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source Project: android_9.0.0_r45   Author: lulululbj   File: SenderFilter.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source Project: android_9.0.0_r45   Author: lulululbj   File: BroadcastQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #7
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #8
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ApplicationPackageManager.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #9
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #11
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ApplicationPackageManager.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #12
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #13
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ApplicationPackageManager.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #14
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #15
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ActivityThread.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #16
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ActivityThread.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #18
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #19
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #20
Source Project: AndroidComponentPlugin   Author: androidmalin   File: LoadedApk.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #21
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ApplicationPackageManager.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #22
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #23
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ApplicationPackageManager.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #24
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #25
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #26
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #27
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #28
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #29
Source Project: android_9.0.0_r45   Author: lulululbj   File: BluetoothManagerService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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.
    }
}
 
Example #30
Source Project: android_9.0.0_r45   Author: lulululbj   File: JobSchedulerService.java    License: Apache License 2.0 5 votes vote down vote up
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;
}