Merge "Replace targetSDK check with platform compat framework gating."
This commit is contained in:
committed by
Android (Google) Code Review
commit
91ede359fa
@@ -426,7 +426,7 @@ java_library {
|
||||
|
||||
java_library {
|
||||
name: "framework-annotation-proc",
|
||||
defaults: ["framework-defaults"],
|
||||
defaults: ["framework-aidl-export-defaults"],
|
||||
srcs: [":framework-all-sources"],
|
||||
installable: false,
|
||||
plugins: [
|
||||
|
||||
@@ -18,10 +18,17 @@ package android.content.pm;
|
||||
import static android.content.pm.SharedLibraryNames.ANDROID_TEST_BASE;
|
||||
import static android.content.pm.SharedLibraryNames.ANDROID_TEST_RUNNER;
|
||||
|
||||
import android.compat.annotation.ChangeId;
|
||||
import android.compat.annotation.EnabledAfter;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageParser.Package;
|
||||
import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.compat.IPlatformCompat;
|
||||
|
||||
/**
|
||||
* Updates a package to ensure that if it targets <= Q that the android.test.base library is
|
||||
@@ -37,10 +44,26 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater {
|
||||
private static final String TAG = "AndroidTestBaseUpdater";
|
||||
|
||||
private static boolean apkTargetsApiLevelLessThanOrEqualToQ(Package pkg) {
|
||||
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
|
||||
return targetSdkVersion <= Build.VERSION_CODES.Q;
|
||||
/**
|
||||
* Remove android.test.base library for apps that target SDK R or more and do not depend on
|
||||
* android.test.runner (as it depends on classes from the android.test.base library).
|
||||
*/
|
||||
@ChangeId
|
||||
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
|
||||
private static final long REMOVE_ANDROID_TEST_BASE = 133396946L;
|
||||
|
||||
private static boolean isChangeEnabled(Package pkg) {
|
||||
IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface(
|
||||
ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
|
||||
try {
|
||||
return platformCompat.isChangeEnabled(REMOVE_ANDROID_TEST_BASE, pkg.applicationInfo);
|
||||
} catch (RemoteException | NullPointerException e) {
|
||||
Log.e(TAG, "Failed to get a response from PLATFORM_COMPAT_SERVICE", e);
|
||||
}
|
||||
// Fall back to previous behaviour.
|
||||
return pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.Q;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +71,7 @@ public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater {
|
||||
// Packages targeted at <= Q expect the classes in the android.test.base library
|
||||
// to be accessible so this maintains backward compatibility by adding the
|
||||
// android.test.base library to those packages.
|
||||
if (apkTargetsApiLevelLessThanOrEqualToQ(pkg)) {
|
||||
if (!isChangeEnabled(pkg)) {
|
||||
prefixRequiredLibrary(pkg, ANDROID_TEST_BASE);
|
||||
} else {
|
||||
// If a package already depends on android.test.runner then add a dependency on
|
||||
|
||||
Reference in New Issue
Block a user