Skip to content

Commit

Permalink
Add new "addedInSdk" attribute to carrier-associated apps.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hunterknepshield committed Jun 16, 2020
1 parent 8202b39 commit 1172ffa
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 5 deletions.
19 changes: 19 additions & 0 deletions core/java/android/os/CarrierAssociatedAppEntry.aidl
Original file line number Diff line number Diff line change
@@ -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;
68 changes: 68 additions & 0 deletions core/java/android/os/CarrierAssociatedAppEntry.java
Original file line number Diff line number Diff line change
@@ -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<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 changes: 5 additions & 0 deletions core/java/android/os/ISystemConfig.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ interface ISystemConfig {
* @see SystemConfigManager#getDisabledUntilUsedPreinstalledCarrierAssociatedApps
*/
Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps();

/**
* @see SystemConfigManager#getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries
*/
Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries();
}
25 changes: 25 additions & 0 deletions core/java/android/os/SystemConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,29 @@ public 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();
}
}
}
29 changes: 24 additions & 5 deletions core/java/com/android/server/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -198,8 +199,8 @@ public static final class PermissionEntry {

// 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<>();
Expand Down Expand Up @@ -331,7 +332,8 @@ public ArraySet<String> getDisabledUntilUsedPreinstalledCarrierApps() {
return mDisabledUntilUsedPreinstalledCarrierApps;
}

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

Expand Down Expand Up @@ -954,15 +956,32 @@ private void readPermissionsFromXml(File permFile, int permissionFlag) {
+ "> 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) {
associatedPkgs = new ArrayList<>();
mDisabledUntilUsedPreinstalledCarrierAssociatedApps.put(
carrierPkgname, associatedPkgs);
}
associatedPkgs.add(pkgname);
associatedPkgs.add(
new CarrierAssociatedAppEntry(pkgname, addedInSdk));
}
} else {
logNotAllowedInPartition(name, permFile, parser);
Expand Down
16 changes: 16 additions & 0 deletions services/java/com/android/server/SystemConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +48,19 @@ public Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps() {
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();
}
Expand Down

0 comments on commit 1172ffa

Please sign in to comment.