Java Code Examples for android.content.pm.PackageInfo#isStaticOverlayPackage()

The following examples show how to use android.content.pm.PackageInfo#isStaticOverlayPackage() . 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: OverlayManagerServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to merge the overlay manager's (as read from overlays.xml)
 * and package manager's (as parsed from AndroidManifest.xml files) views
 * on overlays.
 *
 * Both managers are usually in agreement, but especially after an OTA things
 * may differ. The package manager is always providing the truth; the overlay
 * manager has to adapt. Depending on what has changed about an overlay, we
 * should either scrap the overlay manager's previous settings or merge the old
 * settings with the new.
 */
private static boolean mustReinitializeOverlay(@NonNull final PackageInfo theTruth,
        @Nullable final OverlayInfo oldSettings) {
    if (oldSettings == null) {
        return true;
    }
    if (!Objects.equals(theTruth.overlayTarget, oldSettings.targetPackageName)) {
        return true;
    }
    if (theTruth.isStaticOverlayPackage() != oldSettings.isStatic) {
        return true;
    }
    // a change in priority is only relevant for static RROs: specifically,
    // a regular RRO should not have its state reset only because a change
    // in priority
    if (theTruth.isStaticOverlayPackage() &&
            theTruth.overlayPriority != oldSettings.priority) {
        return true;
    }
    return false;
}
 
Example 2
Source File: OverlayManagerServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
boolean setEnabled(@NonNull final String packageName, final boolean enable,
        final int userId) {
    if (DEBUG) {
        Slog.d(TAG, String.format("setEnabled packageName=%s enable=%s userId=%d",
                    packageName, enable, userId));
    }

    final PackageInfo overlayPackage = mPackageManager.getPackageInfo(packageName, userId);
    if (overlayPackage == null) {
        return false;
    }

    // Ignore static overlays.
    if (overlayPackage.isStaticOverlayPackage()) {
        return false;
    }

    try {
        final OverlayInfo oi = mSettings.getOverlayInfo(packageName, userId);
        boolean modified = mSettings.setEnabled(packageName, userId, enable);
        modified |= updateState(oi.targetPackageName, oi.packageName, userId, 0);

        if (modified) {
            mListener.onOverlaysChanged(oi.targetPackageName, userId);
        }
        return true;
    } catch (OverlayManagerSettings.BadKeyException e) {
        return false;
    }
}
 
Example 3
Source File: OverlayManagerServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean isPackageUpdatableOverlay(@NonNull final String packageName, final int userId) {
    final PackageInfo overlayPackage = mPackageManager.getPackageInfo(packageName, userId);
    if (overlayPackage == null || overlayPackage.isStaticOverlayPackage()) {
        return false;
    }
    return true;
}
 
Example 4
Source File: OverlayManagerServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the settings/state was modified, false otherwise.
 */
private boolean updateState(@NonNull final String targetPackageName,
        @NonNull final String overlayPackageName, final int userId, final int flags)
        throws OverlayManagerSettings.BadKeyException {

    final PackageInfo targetPackage = mPackageManager.getPackageInfo(targetPackageName, userId);
    final PackageInfo overlayPackage = mPackageManager.getPackageInfo(overlayPackageName,
            userId);

    // Static RROs targeting to "android", ie framework-res.apk, are handled by native layers.
    if (targetPackage != null && overlayPackage != null &&
            !("android".equals(targetPackageName)
                    && overlayPackage.isStaticOverlayPackage())) {
        mIdmapManager.createIdmap(targetPackage, overlayPackage, userId);
    }

    boolean modified = false;
    if (overlayPackage != null) {
        modified |= mSettings.setBaseCodePath(overlayPackageName, userId,
                overlayPackage.applicationInfo.getBaseCodePath());
        modified |= mSettings.setCategory(overlayPackageName, userId,
                overlayPackage.overlayCategory);
    }

    final @OverlayInfo.State int currentState = mSettings.getState(overlayPackageName, userId);
    final @OverlayInfo.State int newState = calculateNewState(targetPackage, overlayPackage,
            userId, flags);
    if (currentState != newState) {
        if (DEBUG) {
            Slog.d(TAG, String.format("%s:%d: %s -> %s",
                        overlayPackageName, userId,
                        OverlayInfo.stateToString(currentState),
                        OverlayInfo.stateToString(newState)));
        }
        modified |= mSettings.setState(overlayPackageName, userId, newState);
    }
    return modified;
}
 
Example 5
Source File: OverlayManagerServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private @OverlayInfo.State int calculateNewState(@Nullable final PackageInfo targetPackage,
        @Nullable final PackageInfo overlayPackage, final int userId, final int flags)
    throws OverlayManagerSettings.BadKeyException {

    if ((flags & FLAG_TARGET_IS_UPGRADING) != 0) {
        return STATE_TARGET_UPGRADING;
    }

    if ((flags & FLAG_OVERLAY_IS_UPGRADING) != 0) {
        return STATE_OVERLAY_UPGRADING;
    }

    // assert expectation on overlay package: can only be null if the flags are used
    if (DEBUG && overlayPackage == null) {
        throw new IllegalArgumentException("null overlay package not compatible with no flags");
    }

    if (targetPackage == null) {
        return STATE_MISSING_TARGET;
    }

    if (!mIdmapManager.idmapExists(overlayPackage, userId)) {
        return STATE_NO_IDMAP;
    }

    if (overlayPackage.isStaticOverlayPackage()) {
        return STATE_ENABLED_STATIC;
    }

    final boolean enabled = mSettings.getEnabled(overlayPackage.packageName, userId);
    return enabled ? STATE_ENABLED : STATE_DISABLED;
}
 
Example 6
Source File: OverlayManagerServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
boolean setEnabledExclusive(@NonNull final String packageName, boolean withinCategory,
        final int userId) {
    if (DEBUG) {
        Slog.d(TAG, String.format("setEnabledExclusive packageName=%s"
                + " withinCategory=%s userId=%d", packageName, withinCategory, userId));
    }

    final PackageInfo overlayPackage = mPackageManager.getPackageInfo(packageName, userId);
    if (overlayPackage == null) {
        return false;
    }

    try {
        final OverlayInfo oi = mSettings.getOverlayInfo(packageName, userId);
        final String targetPackageName = oi.targetPackageName;

        List<OverlayInfo> allOverlays = getOverlayInfosForTarget(targetPackageName, userId);

        boolean modified = false;

        // Disable all other overlays.
        allOverlays.remove(oi);
        for (int i = 0; i < allOverlays.size(); i++) {
            final String disabledOverlayPackageName = allOverlays.get(i).packageName;
            final PackageInfo disabledOverlayPackageInfo = mPackageManager.getPackageInfo(
                    disabledOverlayPackageName, userId);
            if (disabledOverlayPackageInfo == null) {
                modified |= mSettings.remove(disabledOverlayPackageName, userId);
                continue;
            }

            if (disabledOverlayPackageInfo.isStaticOverlayPackage()) {
                // Don't touch static overlays.
                continue;
            }
            if (withinCategory && !Objects.equals(disabledOverlayPackageInfo.overlayCategory,
                    oi.category)) {
                // Don't touch overlays from other categories.
                continue;
            }

            // Disable the overlay.
            modified |= mSettings.setEnabled(disabledOverlayPackageName, userId, false);
            modified |= updateState(targetPackageName, disabledOverlayPackageName, userId, 0);
        }

        // Enable the selected overlay.
        modified |= mSettings.setEnabled(packageName, userId, true);
        modified |= updateState(targetPackageName, packageName, userId, 0);

        if (modified) {
            mListener.onOverlaysChanged(targetPackageName, userId);
        }
        return true;
    } catch (OverlayManagerSettings.BadKeyException e) {
        return false;
    }
}