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

Commit 1172ffa7 authored by Hunter Knepshield's avatar Hunter Knepshield
Browse files

Add new "addedInSdk" attribute to carrier-associated apps.

Previously, the sysconfig wasn't capable of understanding
carrier-associated apps that were added after a device's initial launch
(i.e. via OTA) because the logic in CarrierAppUtils explicitly avoids
disabling such apps a second time.

Most of this change is just plumbing everything through. For now, it's
all @hide due to R API deadlines. It will be made public in S.

Bug: 154872019
Test: manual, QA, atest FrameworksTelephonyTests:CarrierAppUtilsTest
Change-Id: I530a4f73146b09879547ca2e0c26428957fef37a
parent 8202b399
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;

parcelable CarrierAssociatedAppEntry;
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.os;

/**
 * Represents a carrier app entry for use with {@link SystemConfigService}.
 *
 * @hide
 */
public final class CarrierAssociatedAppEntry implements Parcelable {

    /**
     * For carrier-associated app entries that don't specify the addedInSdk XML
     * attribute.
     */
    public static final int SDK_UNSPECIFIED = -1;

    public final String packageName;
    /** May be {@link #SDK_UNSPECIFIED}. */
    public final int addedInSdk;

    public CarrierAssociatedAppEntry(String packageName, int addedInSdk) {
        this.packageName = packageName;
        this.addedInSdk = addedInSdk;
    }

    public CarrierAssociatedAppEntry(Parcel in) {
        packageName = in.readString();
        addedInSdk = in.readInt();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(packageName);
        dest.writeInt(addedInSdk);
    }

    public static final Parcelable.Creator<CarrierAssociatedAppEntry> CREATOR =
            new Parcelable.Creator<CarrierAssociatedAppEntry>() {
        @Override
        public CarrierAssociatedAppEntry createFromParcel(Parcel source) {
            return new CarrierAssociatedAppEntry(source);
        }

        @Override
        public CarrierAssociatedAppEntry[] newArray(int size) {
            return new CarrierAssociatedAppEntry[size];
        }
    };
}
+5 −0
Original line number Diff line number Diff line
@@ -30,4 +30,9 @@ interface ISystemConfig {
     * @see SystemConfigManager#getDisabledUntilUsedPreinstalledCarrierAssociatedApps
     */
    Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps();

    /**
     * @see SystemConfigManager#getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries
     */
    Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries();
}
+25 −0
Original line number Diff line number Diff line
@@ -88,4 +88,29 @@ public class SystemConfigManager {
            return Collections.emptyMap();
        }
    }

    /**
     * Returns a map that describes helper apps associated with carrier apps that, like the apps
     * returned by {@link #getDisabledUntilUsedPreinstalledCarrierApps()}, should be disabled until
     * the correct SIM is inserted into the device.
     *
     * <p>TODO(b/159069037) expose this and get rid of the other method that omits SDK version.
     *
     * @return A map with keys corresponding to package names returned by
     *         {@link #getDisabledUntilUsedPreinstalledCarrierApps()} and values as lists of package
     *         names of helper apps and the SDK versions when they were first added.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.READ_CARRIER_APP_INFO)
    public @NonNull Map<String, List<CarrierAssociatedAppEntry>>
            getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() {
        try {
            return (Map<String, List<CarrierAssociatedAppEntry>>)
                    mInterface.getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries();
        } catch (RemoteException e) {
            Log.e(TAG, "Caught remote exception", e);
            return Collections.emptyMap();
        }
    }
}
+24 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.ComponentName;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.CarrierAssociatedAppEntry;
import android.os.Environment;
import android.os.FileUtils;
import android.os.Process;
@@ -198,8 +199,8 @@ public class SystemConfig {

    // These are the packages of carrier-associated apps which should be disabled until used until
    // a SIM is inserted which grants carrier privileges to that carrier app.
    final ArrayMap<String, List<String>> mDisabledUntilUsedPreinstalledCarrierAssociatedApps =
            new ArrayMap<>();
    final ArrayMap<String, List<CarrierAssociatedAppEntry>>
            mDisabledUntilUsedPreinstalledCarrierAssociatedApps = new ArrayMap<>();

    final ArrayMap<String, ArraySet<String>> mPrivAppPermissions = new ArrayMap<>();
    final ArrayMap<String, ArraySet<String>> mPrivAppDenyPermissions = new ArrayMap<>();
@@ -331,7 +332,8 @@ public class SystemConfig {
        return mDisabledUntilUsedPreinstalledCarrierApps;
    }

    public ArrayMap<String, List<String>> getDisabledUntilUsedPreinstalledCarrierAssociatedApps() {
    public ArrayMap<String, List<CarrierAssociatedAppEntry>>
            getDisabledUntilUsedPreinstalledCarrierAssociatedApps() {
        return mDisabledUntilUsedPreinstalledCarrierAssociatedApps;
    }

@@ -954,7 +956,23 @@ public class SystemConfig {
                                        + "> without package or carrierAppPackage in " + permFile
                                        + " at " + parser.getPositionDescription());
                            } else {
                                List<String> associatedPkgs =
                                // APKs added to system images via OTA should specify the addedInSdk
                                // attribute, otherwise they may be enabled-by-default in too many
                                // cases. See CarrierAppUtils for more info.
                                int addedInSdk = CarrierAssociatedAppEntry.SDK_UNSPECIFIED;
                                String addedInSdkStr = parser.getAttributeValue(null, "addedInSdk");
                                if (!TextUtils.isEmpty(addedInSdkStr)) {
                                    try {
                                        addedInSdk = Integer.parseInt(addedInSdkStr);
                                    } catch (NumberFormatException e) {
                                        Slog.w(TAG, "<" + name + "> addedInSdk not an integer in "
                                                + permFile + " at "
                                                + parser.getPositionDescription());
                                        XmlUtils.skipCurrentTag(parser);
                                        break;
                                    }
                                }
                                List<CarrierAssociatedAppEntry> associatedPkgs =
                                        mDisabledUntilUsedPreinstalledCarrierAssociatedApps.get(
                                                carrierPkgname);
                                if (associatedPkgs == null) {
@@ -962,7 +980,8 @@ public class SystemConfig {
                                    mDisabledUntilUsedPreinstalledCarrierAssociatedApps.put(
                                            carrierPkgname, associatedPkgs);
                                }
                                associatedPkgs.add(pkgname);
                                associatedPkgs.add(
                                        new CarrierAssociatedAppEntry(pkgname, addedInSdk));
                            }
                        } else {
                            logNotAllowedInPartition(name, permFile, parser);
Loading