Replace ImageDecoder.sApiLevel with a SystemApi helper

Bug: 152322291
Test: CtsGraphicsTestCases

ImageDecoder is moving to a mainline module, so the system can no longer
access the @hidden sApiLevel without making it @SystemApi. Instead of
promoting the existing API, provide a common class to be used by any UI
rendering class that needs to access the targetSdkVersion. Switch AVD to
use the new class, which is a SystemApi.

Change-Id: Ie7172fb93364a1e04ab844b8fa64887bf9d8b005
This commit is contained in:
Leon Scroggins III
2020-03-30 14:03:37 -04:00
parent 03fb4e10aa
commit 143dfeff2d
5 changed files with 60 additions and 21 deletions

View File

@@ -19,6 +19,10 @@ package android.content.rollback {
package android.graphics {
public final class Compatibility {
method public static void setTargetSdkVersion(int);
}
public final class ImageDecoder implements java.lang.AutoCloseable {
method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull android.content.ContentResolver, @NonNull android.net.Uri, @Nullable android.content.res.Resources);
}

View File

@@ -82,7 +82,6 @@ import android.database.sqlite.SQLiteDebug.DbStats;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.HardwareRenderer;
import android.graphics.ImageDecoder;
import android.hardware.display.DisplayManagerGlobal;
import android.inputmethodservice.InputMethodService;
import android.net.ConnectivityManager;
@@ -6280,12 +6279,9 @@ public final class ActivityThread extends ClientTransactionHandler {
Message.updateCheckRecycle(data.appInfo.targetSdkVersion);
// Prior to P, internal calls to decode Bitmaps used BitmapFactory,
// which may scale up to account for density. In P, we switched to
// ImageDecoder, which skips the upscale to save memory. ImageDecoder
// needs to still scale up in older apps, in case they rely on the
// size of the Bitmap without considering its density.
ImageDecoder.sApiLevel = data.appInfo.targetSdkVersion;
// Supply the targetSdkVersion to the UI rendering module, which may
// need it in cases where it does not have access to the appInfo.
android.graphics.Compatibility.setTargetSdkVersion(data.appInfo.targetSdkVersion);
/*
* Before spawning a new process, reset the time zone to be the system time zone.

View File

@@ -0,0 +1,50 @@
/*
* Copyright 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.graphics;
import android.annotation.SystemApi;
/**
* Helper class for graphics classes to retrieve the targetSdkVersion, as
* specified by the app.
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public final class Compatibility {
private Compatibility() {}
private static int sTargetSdkVersion = 0;
/**
* Exposed so that ActivityThread can set it correctly once when binding the
* application. No other code should call this.
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static void setTargetSdkVersion(int targetSdkVersion) {
sTargetSdkVersion = targetSdkVersion;
}
/**
* Public for access by other packages in the module (like android.graphics.drawable),
* but should not be accessed outside the module.
* @hide
*/
public static int getTargetSdkVersion() {
return sTargetSdkVersion;
}
}

View File

@@ -171,9 +171,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
* </pre>
*/
public final class ImageDecoder implements AutoCloseable {
/** @hide **/
public static int sApiLevel;
/**
* Source of encoded image data.
*
@@ -1933,7 +1930,8 @@ public final class ImageDecoder implements AutoCloseable {
// For P and above, only resize if it would be a downscale. Scale up prior
// to P in case the app relies on the Bitmap's size without considering density.
if (srcDensity < dstDensity && sApiLevel >= Build.VERSION_CODES.P) {
if (srcDensity < dstDensity
&& Compatibility.getTargetSdkVersion() >= Build.VERSION_CODES.P) {
return srcDensity;
}

View File

@@ -25,8 +25,6 @@ import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.Application;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.pm.ActivityInfo.Config;
import android.content.res.ColorStateList;
@@ -368,14 +366,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 {
* @return whether invalid animations for vector drawable should be ignored.
*/
private static boolean shouldIgnoreInvalidAnimation() {
Application app = ActivityThread.currentApplication();
if (app == null || app.getApplicationInfo() == null) {
return true;
}
if (app.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
return true;
}
return false;
return android.graphics.Compatibility.getTargetSdkVersion() < Build.VERSION_CODES.N;
}
@Override