Merge "Add apis for listing all compat changes"
am: 2c3b1a1010
Change-Id: I5b756833ba7637ac80f4219783ff24c190412641
This commit is contained in:
@@ -49,6 +49,18 @@ public final class CompatibilityChangeConfig implements Parcelable {
|
||||
return mChangeConfig.forceDisabledSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a change is enabled or disabled in this config.
|
||||
*/
|
||||
public boolean isChangeEnabled(long changeId) {
|
||||
if (mChangeConfig.isForceEnabled(changeId)) {
|
||||
return true;
|
||||
} else if (mChangeConfig.isForceDisabled(changeId)) {
|
||||
return false;
|
||||
}
|
||||
throw new IllegalStateException("Change " + changeId + " is not defined.");
|
||||
}
|
||||
|
||||
private CompatibilityChangeConfig(Parcel in) {
|
||||
long[] enabledArray = in.createLongArray();
|
||||
long[] disabledArray = in.createLongArray();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 com.android.internal.compat;
|
||||
|
||||
parcelable CompatibilityChangeInfo;
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 com.android.internal.compat;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* This class is a parcelable version of {@link com.android.server.compat.Change}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class CompatibilityChangeInfo implements Parcelable {
|
||||
private final long mChangeId;
|
||||
private final @Nullable String mName;
|
||||
private final int mEnableAfterTargetSdk;
|
||||
private final boolean mDisabled;
|
||||
|
||||
public long getId() {
|
||||
return mChangeId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public int getEnableAfterTargetSdk() {
|
||||
return mEnableAfterTargetSdk;
|
||||
}
|
||||
|
||||
public boolean getDisabled() {
|
||||
return mDisabled;
|
||||
}
|
||||
|
||||
public CompatibilityChangeInfo(
|
||||
Long changeId, String name, int enableAfterTargetSdk, boolean disabled) {
|
||||
this.mChangeId = changeId;
|
||||
this.mName = name;
|
||||
this.mEnableAfterTargetSdk = enableAfterTargetSdk;
|
||||
this.mDisabled = disabled;
|
||||
}
|
||||
|
||||
private CompatibilityChangeInfo(Parcel in) {
|
||||
mChangeId = in.readLong();
|
||||
mName = in.readString();
|
||||
mEnableAfterTargetSdk = in.readInt();
|
||||
mDisabled = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(mChangeId);
|
||||
dest.writeString(mName);
|
||||
dest.writeInt(mEnableAfterTargetSdk);
|
||||
dest.writeBoolean(mDisabled);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<CompatibilityChangeInfo> CREATOR =
|
||||
new Parcelable.Creator<CompatibilityChangeInfo>() {
|
||||
|
||||
@Override
|
||||
public CompatibilityChangeInfo createFromParcel(Parcel in) {
|
||||
return new CompatibilityChangeInfo(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompatibilityChangeInfo[] newArray(int size) {
|
||||
return new CompatibilityChangeInfo[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -17,8 +17,10 @@
|
||||
package com.android.internal.compat;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import java.util.Map;
|
||||
|
||||
parcelable CompatibilityChangeConfig;
|
||||
parcelable CompatibilityChangeInfo;
|
||||
|
||||
/**
|
||||
* Platform private API for talking with the PlatformCompat service.
|
||||
@@ -146,4 +148,21 @@ interface IPlatformCompat
|
||||
*
|
||||
*/
|
||||
void clearOverrides(in String packageName);
|
||||
|
||||
/**
|
||||
* Get configs for an application.
|
||||
*
|
||||
* @param appInfo The application whose config will be returned.
|
||||
*
|
||||
* @return A {@link CompatibilityChangeConfig}, representing whether a change is enabled for
|
||||
* the given app or not.
|
||||
*/
|
||||
CompatibilityChangeConfig getAppConfig(in ApplicationInfo appInfo);
|
||||
|
||||
/**
|
||||
* List all compatibility changes.
|
||||
*
|
||||
* @return An array of {@link CompatChangeInfo} known to the service.
|
||||
*/
|
||||
CompatibilityChangeInfo[] listAllChanges();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
|
||||
import android.compat.annotation.EnabledAfter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
|
||||
import com.android.internal.compat.CompatibilityChangeInfo;
|
||||
import com.android.server.compat.config.Change;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -35,12 +36,8 @@ import java.util.Map;
|
||||
*
|
||||
* <p>Note, this class is not thread safe so callers must ensure thread safety.
|
||||
*/
|
||||
public final class CompatChange {
|
||||
public final class CompatChange extends CompatibilityChangeInfo {
|
||||
|
||||
private final long mChangeId;
|
||||
@Nullable private final String mName;
|
||||
private final int mEnableAfterTargetSdk;
|
||||
private final boolean mDisabled;
|
||||
private Map<String, Boolean> mPackageOverrides;
|
||||
|
||||
public CompatChange(long changeId) {
|
||||
@@ -56,29 +53,15 @@ public final class CompatChange {
|
||||
*/
|
||||
public CompatChange(long changeId, @Nullable String name, int enableAfterTargetSdk,
|
||||
boolean disabled) {
|
||||
mChangeId = changeId;
|
||||
mName = name;
|
||||
mEnableAfterTargetSdk = enableAfterTargetSdk;
|
||||
mDisabled = disabled;
|
||||
super(changeId, name, enableAfterTargetSdk, disabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param change an object generated by services/core/xsd/platform-compat-config.xsd
|
||||
*/
|
||||
public CompatChange(Change change) {
|
||||
mChangeId = change.getId();
|
||||
mName = change.getName();
|
||||
mEnableAfterTargetSdk = change.getEnableAfterTargetSdk();
|
||||
mDisabled = change.getDisabled();
|
||||
}
|
||||
|
||||
long getId() {
|
||||
return mChangeId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getName() {
|
||||
return mName;
|
||||
super(change.getId(), change.getName(), change.getEnableAfterTargetSdk(),
|
||||
change.getDisabled());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,11 +104,11 @@ public final class CompatChange {
|
||||
if (mPackageOverrides != null && mPackageOverrides.containsKey(app.packageName)) {
|
||||
return mPackageOverrides.get(app.packageName);
|
||||
}
|
||||
if (mDisabled) {
|
||||
if (getDisabled()) {
|
||||
return false;
|
||||
}
|
||||
if (mEnableAfterTargetSdk != -1) {
|
||||
return app.targetSdkVersion > mEnableAfterTargetSdk;
|
||||
if (getEnableAfterTargetSdk() != -1) {
|
||||
return app.targetSdkVersion > getEnableAfterTargetSdk();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -133,14 +116,14 @@ public final class CompatChange {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("ChangeId(")
|
||||
.append(mChangeId);
|
||||
if (mName != null) {
|
||||
sb.append("; name=").append(mName);
|
||||
.append(getId());
|
||||
if (getName() != null) {
|
||||
sb.append("; name=").append(getName());
|
||||
}
|
||||
if (mEnableAfterTargetSdk != -1) {
|
||||
sb.append("; enableAfterTargetSdk=").append(mEnableAfterTargetSdk);
|
||||
if (getEnableAfterTargetSdk() != -1) {
|
||||
sb.append("; enableAfterTargetSdk=").append(getEnableAfterTargetSdk());
|
||||
}
|
||||
if (mDisabled) {
|
||||
if (getDisabled()) {
|
||||
sb.append("; disabled");
|
||||
}
|
||||
if (mPackageOverrides != null && mPackageOverrides.size() > 0) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.compat;
|
||||
|
||||
import android.compat.Compatibility.ChangeConfig;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
@@ -26,6 +27,7 @@ import android.util.Slog;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.compat.CompatibilityChangeConfig;
|
||||
import com.android.internal.compat.CompatibilityChangeInfo;
|
||||
import com.android.server.compat.config.Change;
|
||||
import com.android.server.compat.config.XmlParser;
|
||||
|
||||
@@ -37,6 +39,8 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
/**
|
||||
@@ -243,6 +247,49 @@ public final class CompatConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config for a given app.
|
||||
*
|
||||
* @param applicationInfo the {@link ApplicationInfo} for which the info should be dumped.
|
||||
* @return A {@link CompatibilityChangeConfig} which contains the compat config info for the
|
||||
* given app.
|
||||
*/
|
||||
|
||||
public CompatibilityChangeConfig getAppConfig(ApplicationInfo applicationInfo) {
|
||||
Set<Long> enabled = new HashSet<>();
|
||||
Set<Long> disabled = new HashSet<>();
|
||||
synchronized (mChanges) {
|
||||
for (int i = 0; i < mChanges.size(); ++i) {
|
||||
CompatChange c = mChanges.valueAt(i);
|
||||
if (c.isEnabled(applicationInfo)) {
|
||||
enabled.add(c.getId());
|
||||
} else {
|
||||
disabled.add(c.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return new CompatibilityChangeConfig(new ChangeConfig(enabled, disabled));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps all the compatibility change information.
|
||||
*
|
||||
* @return An array of {@link CompatibilityChangeInfo} with the current changes.
|
||||
*/
|
||||
public CompatibilityChangeInfo[] dumpChanges() {
|
||||
synchronized (mChanges) {
|
||||
CompatibilityChangeInfo[] changeInfos = new CompatibilityChangeInfo[mChanges.size()];
|
||||
for (int i = 0; i < mChanges.size(); ++i) {
|
||||
CompatChange change = mChanges.valueAt(i);
|
||||
changeInfos[i] = new CompatibilityChangeInfo(change.getId(),
|
||||
change.getName(),
|
||||
change.getEnableAfterTargetSdk(),
|
||||
change.getDisabled());
|
||||
}
|
||||
return changeInfos;
|
||||
}
|
||||
}
|
||||
|
||||
CompatConfig initConfigFromLib(File libraryDir) {
|
||||
if (!libraryDir.exists() || !libraryDir.isDirectory()) {
|
||||
Slog.e(TAG, "No directory " + libraryDir + ", skipping");
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.util.StatsLog;
|
||||
|
||||
import com.android.internal.compat.ChangeReporter;
|
||||
import com.android.internal.compat.CompatibilityChangeConfig;
|
||||
import com.android.internal.compat.CompatibilityChangeInfo;
|
||||
import com.android.internal.compat.IPlatformCompat;
|
||||
import com.android.internal.util.DumpUtils;
|
||||
|
||||
@@ -113,6 +114,16 @@ public class PlatformCompat extends IPlatformCompat.Stub {
|
||||
config.removePackageOverrides(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompatibilityChangeConfig getAppConfig(ApplicationInfo appInfo) {
|
||||
return CompatConfig.get().getAppConfig(appInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompatibilityChangeInfo[] listAllChanges() {
|
||||
return CompatConfig.get().dumpChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, "platform_compat", pw)) return;
|
||||
|
||||
Reference in New Issue
Block a user