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

Commit 94412aa8 authored by Danesh M's avatar Danesh M
Browse files

PackageManager : Extend prebundled logic

Instead of specifying which packages to explicitly install,
Only install packages if :

a) Its in the current mcc's config_region_locked_packages
b) Its not region locked by checking config_restrict_to_region_locked_devices

issue-id: CYNGNOS-912

Change-Id: I9ddba06d059a6c08478cee11e25a4cd2d2a1524b
parent d31b89c1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -352,6 +352,9 @@
    <!-- Wifi AP Disabled from Subscription change -->
    <java-symbol type="string" name="subscription_change_disabled_wifi_ap" />

    <!-- Region locked prebundled packages -->
    <!-- Region locked prebundled packages (per mcc) -->
    <java-symbol type="array" name="config_region_locked_packages" />

    <!-- Packages in this list should be a union of all packages defined in values-mccxxx (mcc) -->
    <java-symbol type="array" name="config_restrict_to_region_locked_devices" />
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -2363,4 +2363,7 @@
    <string-array name="config_region_locked_packages" translatable="false">
    </string-array>

    <!-- Packages in this list should be a union of all packages defined in values-mccxxx (mcc) -->
    <string-array name="config_restrict_to_region_locked_devices" translatable="false">
    </string-array>
</resources>
+12 −1
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    //Maximum number of phones
    private static final int MAX_PHONE_COUNT = 3;

    private String mPublicSrcDir;

    static {
        mValidTables.add(TABLE_SYSTEM);
        mValidTables.add(TABLE_SECURE);
@@ -125,6 +127,13 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        super(context, dbNameForUser(userHandle), null, DATABASE_VERSION);
        mContext = context;
        mUserHandle = userHandle;
        try {
            String packageName = mContext.getPackageName();
            mPublicSrcDir = mContext.getPackageManager().getApplicationInfo(packageName, 0)
                    .publicSourceDir;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static boolean isValidTable(String name) {
@@ -2949,7 +2958,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        Resources customResources = null;
        if (!TextUtils.isEmpty(mcc)) {
            tempConfiguration.mcc = Integer.parseInt(mcc);
            customResources = new Resources(new AssetManager(), new DisplayMetrics(),
            AssetManager assetManager = new AssetManager();
            assetManager.addAssetPath(mPublicSrcDir);
            customResources = new Resources(assetManager, new DisplayMetrics(),
                    tempConfiguration);
        }
        loadSetting(stmt, key, customResources == null ? mContext.getResources().getString(resid)
+3 −3
Original line number Diff line number Diff line
@@ -4541,9 +4541,9 @@ public class PackageManagerService extends IPackageManager.Stub {
                    // gone.  Assume that the user uninstalled it intentionally: do not reinstall.
                    throw new PackageManagerException(INSTALL_FAILED_UNINSTALLED_PREBUNDLE,
                            "skip reinstall for " + pkg.packageName);
                } else if (existingSettings == null && mCustomResources != null &&
                        !mSettings.isPrebundledPackagedNeededForRegion(pkg.packageName,
                        SystemProperties.get("ro.prebundled.mcc"), mCustomResources)) {
                } else if (existingSettings == null &&
                        !mSettings.shouldPrebundledPackageBeInstalled(mContext.getResources(),
                                pkg.packageName, mCustomResources)) {
                    // The prebundled app is not needed for the default mobile country code,
                    // skip installing it
                    throw new PackageManagerException(INSTALL_FAILED_REGION_LOCKED_PREBUNDLE,
+27 −12
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.os.UserManager;
import android.util.LogPrinter;

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

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

        // Configured resources can be null if the device
        // is not region locked. In such cases, fall back to
        // the default resources object
        Resources resources = configuredResources;
        if (configuredResources == null) {
            resources = res;
        }

        // If the package is compatible with the current region, install it
        // Note : If a package needs to be installed only if the device is
        // not provisioned, overlay values/config_region_locked_packages
        // TODO change config_region_locked_packages to something that is
        // not confusing inside a non region resource bucket
        String[] prebundledArray
                = configuredResources.getStringArray(R.array.config_region_locked_packages);
        if (prebundledArray != null) {
            for (String pkg : prebundledArray) {
                if (TextUtils.equals(packageName, pkg)) {
                = resources.getStringArray(R.array.config_region_locked_packages);
        if (ArrayUtils.contains(prebundledArray, packageName)) {
            return true;
        }
            }
        }
        return false;

        // If the package is not compatible with the current region, check if its locked
        // to any other region before installing it.
        prebundledArray = resources
                .getStringArray(R.array.config_restrict_to_region_locked_devices);
        return !ArrayUtils.contains(prebundledArray, packageName);
    }

    void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
Loading