diff --git a/core/java/android/os/CarrierAssociatedAppEntry.aidl b/core/java/android/os/CarrierAssociatedAppEntry.aidl new file mode 100644 index 0000000000000..a9b1055ee1744 --- /dev/null +++ b/core/java/android/os/CarrierAssociatedAppEntry.aidl @@ -0,0 +1,19 @@ +/* + * 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; diff --git a/core/java/android/os/CarrierAssociatedAppEntry.java b/core/java/android/os/CarrierAssociatedAppEntry.java new file mode 100644 index 0000000000000..13f6eb63e29c8 --- /dev/null +++ b/core/java/android/os/CarrierAssociatedAppEntry.java @@ -0,0 +1,68 @@ +/* + * 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 CREATOR = + new Parcelable.Creator() { + @Override + public CarrierAssociatedAppEntry createFromParcel(Parcel source) { + return new CarrierAssociatedAppEntry(source); + } + + @Override + public CarrierAssociatedAppEntry[] newArray(int size) { + return new CarrierAssociatedAppEntry[size]; + } + }; +} diff --git a/core/java/android/os/ISystemConfig.aidl b/core/java/android/os/ISystemConfig.aidl index d3b029854112f..52f0ce1f054f3 100644 --- a/core/java/android/os/ISystemConfig.aidl +++ b/core/java/android/os/ISystemConfig.aidl @@ -30,4 +30,9 @@ interface ISystemConfig { * @see SystemConfigManager#getDisabledUntilUsedPreinstalledCarrierAssociatedApps */ Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps(); + + /** + * @see SystemConfigManager#getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries + */ + Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries(); } diff --git a/core/java/android/os/SystemConfigManager.java b/core/java/android/os/SystemConfigManager.java index 3a9ce2fa85f13..12a1ffaf69c15 100644 --- a/core/java/android/os/SystemConfigManager.java +++ b/core/java/android/os/SystemConfigManager.java @@ -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. + * + *

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> + getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() { + try { + return (Map>) + mInterface.getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries(); + } catch (RemoteException e) { + Log.e(TAG, "Caught remote exception", e); + return Collections.emptyMap(); + } + } } diff --git a/core/java/com/android/server/SystemConfig.java b/core/java/com/android/server/SystemConfig.java index d9ca9c2f87f55..ea390cd71e318 100644 --- a/core/java/com/android/server/SystemConfig.java +++ b/core/java/com/android/server/SystemConfig.java @@ -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> mDisabledUntilUsedPreinstalledCarrierAssociatedApps = - new ArrayMap<>(); + final ArrayMap> + mDisabledUntilUsedPreinstalledCarrierAssociatedApps = new ArrayMap<>(); final ArrayMap> mPrivAppPermissions = new ArrayMap<>(); final ArrayMap> mPrivAppDenyPermissions = new ArrayMap<>(); @@ -331,7 +332,8 @@ public class SystemConfig { return mDisabledUntilUsedPreinstalledCarrierApps; } - public ArrayMap> getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { + public ArrayMap> + getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { return mDisabledUntilUsedPreinstalledCarrierAssociatedApps; } @@ -954,7 +956,23 @@ public class SystemConfig { + "> without package or carrierAppPackage in " + permFile + " at " + parser.getPositionDescription()); } else { - List 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 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); diff --git a/services/java/com/android/server/SystemConfigService.java b/services/java/com/android/server/SystemConfigService.java index e8ab10124ef8b..1801f3bca30ea 100644 --- a/services/java/com/android/server/SystemConfigService.java +++ b/services/java/com/android/server/SystemConfigService.java @@ -15,6 +15,9 @@ */ package com.android.server; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; + import android.Manifest; import android.content.Context; import android.os.ISystemConfig; @@ -45,6 +48,19 @@ public class SystemConfigService extends SystemService { mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, "getDisabledUntilUsedPreInstalledCarrierAssociatedApps requires" + " READ_CARRIER_APP_INFO"); + return SystemConfig.getInstance() + .getDisabledUntilUsedPreinstalledCarrierAssociatedApps().entrySet().stream() + .collect(toMap( + Map.Entry::getKey, + e -> e.getValue().stream().map(app -> app.packageName) + .collect(toList()))); + } + + @Override + public Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, + "getDisabledUntilUsedPreInstalledCarrierAssociatedAppEntries requires" + + " READ_CARRIER_APP_INFO"); return SystemConfig.getInstance() .getDisabledUntilUsedPreinstalledCarrierAssociatedApps(); }