Java Code Examples for android.content.pm.ApplicationInfo#isSystemApp()

The following examples show how to use android.content.pm.ApplicationInfo#isSystemApp() . 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: StrictMode.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Determine if the given app is "bundled" as part of the system image. These bundled apps are
 * developed in lock-step with the OS, and they aren't updated outside of an OTA, so we want to
 * chase any {@link StrictMode} regressions by enabling detection when running on {@link
 * Build#IS_USERDEBUG} or {@link Build#IS_ENG} builds.
 *
 * <p>Unbundled apps included in the system image are expected to detect and triage their own
 * {@link StrictMode} issues separate from the OS release process, which is why we don't enable
 * them here.
 *
 * @hide
 */
public static boolean isBundledSystemApp(ApplicationInfo ai) {
    if (ai == null || ai.packageName == null) {
        // Probably system server
        return true;
    } else if (ai.isSystemApp()) {
        // Ignore unbundled apps living in the wrong namespace
        if (ai.packageName.equals("com.android.vending")
                || ai.packageName.equals("com.android.chrome")) {
            return false;
        }

        // Ignore bundled apps that are way too spammy
        // STOPSHIP: burn this list down to zero
        if (ai.packageName.equals("com.android.phone")) {
            return false;
        }

        if (ai.packageName.equals("android")
                || ai.packageName.startsWith("android.")
                || ai.packageName.startsWith("com.android.")) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private static boolean isPackageCandidateVolume(ApplicationInfo app, VolumeInfo vol) {
    // Private internal is always an option
    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return true;
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()
            || app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
            || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 3
Source File: VrManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean isDefaultAllowed(String packageName) {
    PackageManager pm = mContext.getPackageManager();

    ApplicationInfo info = null;
    try {
        info = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
    }

    if (info == null || !(info.isSystemApp() || info.isUpdatedSystemApp())) {
        return false;
    }
    return true;
}
 
Example 4
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol) {
    final boolean forceAllowOnExternal = Settings.Global.getInt(
            context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
    // Private internal is always an option
    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return true;
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (mPM.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 5
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
    final boolean forceAllowOnExternal = isForceAllowOnExternal(context);

    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 6
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
    final boolean forceAllowOnExternal = isForceAllowOnExternal(context);

    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 7
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
    final boolean forceAllowOnExternal = isForceAllowOnExternal(context);

    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 8
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
    final boolean forceAllowOnExternal = isForceAllowOnExternal(context);

    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 9
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
    final boolean forceAllowOnExternal = isForceAllowOnExternal(context);

    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 10
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol) {
    final boolean forceAllowOnExternal = Settings.Global.getInt(
            context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
    // Private internal is always an option
    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return true;
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (mPM.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}
 
Example 11
Source File: GraphicsEnvironment.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Choose whether the current process should use the builtin or an updated driver.
 */
private static void chooseDriver(Context context) {
    String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
    if (driverPackageName == null || driverPackageName.isEmpty()) {
        return;
    }
    // To minimize risk of driver updates crippling the device beyond user repair, never use an
    // updated driver for privileged or non-updated system apps. Presumably pre-installed apps
    // were tested thoroughly with the pre-installed driver.
    ApplicationInfo ai = context.getApplicationInfo();
    if (ai.isPrivilegedApp() || (ai.isSystemApp() && !ai.isUpdatedSystemApp())) {
        if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app");
        return;
    }
    ApplicationInfo driverInfo;
    try {
        driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName,
                PackageManager.MATCH_SYSTEM_ONLY);
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "driver package '" + driverPackageName + "' not installed");
        return;
    }
    String abi = chooseAbi(driverInfo);
    if (abi == null) {
        if (DEBUG) {
            // This is the normal case for the pre-installed empty driver package, don't spam
            if (driverInfo.isUpdatedSystemApp()) {
                Log.w(TAG, "updated driver package has no compatible native libraries");
            }
        }
        return;
    }
    if (driverInfo.targetSdkVersion < Build.VERSION_CODES.O) {
        // O drivers are restricted to the sphal linker namespace, so don't try to use
        // packages unless they declare they're compatible with that restriction.
        Log.w(TAG, "updated driver package is not known to be compatible with O");
        return;
    }

    StringBuilder sb = new StringBuilder();
    sb.append(driverInfo.nativeLibraryDir)
      .append(File.pathSeparator);
    sb.append(driverInfo.sourceDir)
      .append("!/lib/")
      .append(abi);
    String paths = sb.toString();

    if (DEBUG) Log.v(TAG, "gfx driver package libs: " + paths);
    setDriverPath(paths);
}
 
Example 12
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean isPackageCandidateVolume(
        ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
    final boolean forceAllowOnExternal = isForceAllowOnExternal(context);

    if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
        return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
    }

    // System apps and apps demanding internal storage can't be moved
    // anywhere else
    if (app.isSystemApp()) {
        return false;
    }
    if (!forceAllowOnExternal
            && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
                    || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
        return false;
    }

    // Gotta be able to write there
    if (!vol.isMountedWritable()) {
        return false;
    }

    // Moving into an ASEC on public primary is only option internal
    if (vol.isPrimaryPhysical()) {
        return app.isInternal();
    }

    // Some apps can't be moved. (e.g. device admins)
    try {
        if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
            return false;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }

    // Otherwise we can move to any private volume
    return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
}