Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21b4c4df authored by Adnan Begovic's avatar Adnan Begovic
Browse files

pm: Create per-mcc prebundled install filter.

  If packages are region locked, avoid installing them
  for the SKU, otherwise if a package is specified for
  a mobile country code, allow it to be installed.

TICKET: CYNGNOS-912
Change-Id: I69c5be62dff771fc7d3117e9edf65d8ea4150f28
parent 39107f48
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -825,6 +825,14 @@ public abstract class PackageManager {
     */
     */
    public static final int INSTALL_FAILED_UNINSTALLED_PREBUNDLE = -403;
    public static final int INSTALL_FAILED_UNINSTALLED_PREBUNDLE = -403;


    /**
     * Used for prebundles
     * Installation failed for a prebundled app because it wasn't needed in the default
     * mobile country exported by the hardware
     * @hide
     */
    public static final int INSTALL_FAILED_REGION_LOCKED_PREBUNDLE = -404; //bloat not found

    /**
    /**
     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
     * package's data directory.
     * package's data directory.
+3 −0
Original line number Original line Diff line number Diff line
@@ -351,4 +351,7 @@


    <!-- Wifi AP Disabled from Subscription change -->
    <!-- Wifi AP Disabled from Subscription change -->
    <java-symbol type="string" name="subscription_change_disabled_wifi_ap" />
    <java-symbol type="string" name="subscription_change_disabled_wifi_ap" />

    <!-- Region locked prebundled packages -->
    <java-symbol type="array" name="config_region_locked_packages" />
</resources>
</resources>
+4 −0
Original line number Original line Diff line number Diff line
@@ -2359,4 +2359,8 @@
    <!-- Config to disable showing ringtones from removable storage -->
    <!-- Config to disable showing ringtones from removable storage -->
    <bool name="config_excludeRingtonesFromRemovableStorage">false</bool>
    <bool name="config_excludeRingtonesFromRemovableStorage">false</bool>


    <!-- Config to enable installation of region locked packages -->
    <string-array name="config_region_locked_packages" translatable="false">
    </string-array>

</resources>
</resources>
+26 −0
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY;
import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY;
import static android.content.pm.PackageManager.INSTALL_FAILED_PACKAGE_CHANGED;
import static android.content.pm.PackageManager.INSTALL_FAILED_PACKAGE_CHANGED;
import static android.content.pm.PackageManager.INSTALL_FAILED_REGION_LOCKED_PREBUNDLE;
import static android.content.pm.PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
import static android.content.pm.PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
import static android.content.pm.PackageManager.INSTALL_FAILED_TEST_ONLY;
import static android.content.pm.PackageManager.INSTALL_FAILED_TEST_ONLY;
@@ -63,6 +64,7 @@ import static com.android.internal.util.ArrayUtils.appendInt;
import static com.android.internal.util.ArrayUtils.removeInt;
import static com.android.internal.util.ArrayUtils.removeInt;
import android.app.PackageInstallObserver;
import android.app.PackageInstallObserver;
import android.content.res.Configuration;
import android.util.ArrayMap;
import android.util.ArrayMap;
import com.android.internal.R;
import com.android.internal.R;
@@ -454,6 +456,8 @@ public class PackageManagerService extends IPackageManager.Stub {
    final Settings mSettings;
    final Settings mSettings;
    boolean mRestoredSettings;
    boolean mRestoredSettings;
    private Resources mCustomResources;
    // System configuration read by SystemConfig.
    // System configuration read by SystemConfig.
    final int[] mGlobalGids;
    final int[] mGlobalGids;
    final SparseArray<ArraySet<String>> mSystemPermissions;
    final SparseArray<ArraySet<String>> mSystemPermissions;
@@ -1695,8 +1699,11 @@ public class PackageManagerService extends IPackageManager.Stub {
                    | PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags, 0, null);
                    | PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags, 0, null);
            // Collect all prebundled packages.
            // Collect all prebundled packages.
            createAndSetCustomResources();
            scanDirLI(Environment.getPrebundledDirectory(),
            scanDirLI(Environment.getPrebundledDirectory(),
                    PackageParser.PARSE_IS_PREBUNDLED_DIR, scanFlags, 0, UserHandle.OWNER);
                    PackageParser.PARSE_IS_PREBUNDLED_DIR, scanFlags, 0, UserHandle.OWNER);
            // Clean up
            mCustomResources = null;
            if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands");
            if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands");
            mInstaller.moveFiles();
            mInstaller.moveFiles();
@@ -4534,6 +4541,13 @@ public class PackageManagerService extends IPackageManager.Stub {
                    // gone.  Assume that the user uninstalled it intentionally: do not reinstall.
                    // gone.  Assume that the user uninstalled it intentionally: do not reinstall.
                    throw new PackageManagerException(INSTALL_FAILED_UNINSTALLED_PREBUNDLE,
                    throw new PackageManagerException(INSTALL_FAILED_UNINSTALLED_PREBUNDLE,
                            "skip reinstall for " + pkg.packageName);
                            "skip reinstall for " + pkg.packageName);
                } else if (existingSettings == null && mCustomResources != null &&
                        !mSettings.isPrebundledPackagedNeededForRegion(pkg.packageName,
                        SystemProperties.get("ro.prebundled.mcc"), mCustomResources)) {
                    // The prebundled app is not needed for the default mobile country code,
                    // skip installing it
                    throw new PackageManagerException(INSTALL_FAILED_REGION_LOCKED_PREBUNDLE,
                            "skip install for " + pkg.packageName);
                } else if (existingSettings != null
                } else if (existingSettings != null
                        && existingSettings.versionCode >= pkg.mVersionCode
                        && existingSettings.versionCode >= pkg.mVersionCode
                        && !existingSettings.codePathString.contains(
                        && !existingSettings.codePathString.contains(
@@ -14281,9 +14295,11 @@ public class PackageManagerService extends IPackageManager.Stub {
            // Set flag to monitor and not change apk file paths when
            // Set flag to monitor and not change apk file paths when
            // scanning install directories.
            // scanning install directories.
            final int scanFlags = SCAN_NO_PATHS | SCAN_DEFER_DEX | SCAN_BOOTING;
            final int scanFlags = SCAN_NO_PATHS | SCAN_DEFER_DEX | SCAN_BOOTING;
            createAndSetCustomResources();
            scanDirLI(Environment.getPrebundledDirectory(),
            scanDirLI(Environment.getPrebundledDirectory(),
                    PackageParser.PARSE_IS_PREBUNDLED_DIR, scanFlags, 0,
                    PackageParser.PARSE_IS_PREBUNDLED_DIR, scanFlags, 0,
                    new UserHandle(userHandle));
                    new UserHandle(userHandle));
            mCustomResources = null;
        }
        }
    }
    }
@@ -14736,6 +14752,16 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        }
    }
    }
    private void createAndSetCustomResources() {
        Configuration tempConfiguration = new Configuration();
        String mcc = SystemProperties.get("ro.prebundled.mcc");
        if (!TextUtils.isEmpty(mcc)) {
            tempConfiguration.mcc = Integer.parseInt(mcc);
            mCustomResources = new Resources(new AssetManager(), new DisplayMetrics(),
                    tempConfiguration);
        }
    }
    /**
    /**
     * The new resource cache structure does not flatten the paths for idmaps, so this method
     * The new resource cache structure does not flatten the paths for idmaps, so this method
     * checks for files that end with @idmap and assumes this indicates the older format and
     * checks for files that end with @idmap and assumes this indicates the older format and
+22 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,8 @@ import static android.os.Process.PACKAGE_INFO_GID;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.net.Uri;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
@@ -40,6 +42,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.util.LogPrinter;
import android.util.LogPrinter;


import com.android.internal.R;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.JournaledFile;
import com.android.internal.util.JournaledFile;
import com.android.internal.util.XmlUtils;
import com.android.internal.util.XmlUtils;
@@ -1927,6 +1930,25 @@ final class Settings {
        return mPrebundledPackages.get(userId).contains(packageName);
        return mPrebundledPackages.get(userId).contains(packageName);
    }
    }


    boolean isPrebundledPackagedNeededForRegion(String packageName, String mcc,
            Resources configuredResources) {
        // Default fallback on lack of mcc or bad package
        if (TextUtils.isEmpty(mcc) || TextUtils.isEmpty(packageName)) {
            return false;
        }

        String[] prebundledArray
                = configuredResources.getStringArray(R.array.config_region_locked_packages);
        if (prebundledArray != null) {
            for (String pkg : prebundledArray) {
                if (TextUtils.equals(packageName, pkg)) {
                    return true;
                }
            }
        }
        return false;
    }

    void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
    void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
            throws java.io.IOException {
            throws java.io.IOException {
        serializer.startTag(null, "updated-package");
        serializer.startTag(null, "updated-package");
Loading