Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6a25737 authored by Alan Viverette's avatar Alan Viverette
Browse files

Show warning when app was compiled against incompatible preview SDK

Adds publicly-visible API for compile SDK version and codename. AAPT2 does
not support these yet, but that will be included in a follow-up CL.

Also refactors the Unsupported Display Size dialog out to a generic app
warnings manager class and fixes a bug there where the "always show"
preference was not persisted.

Improves documentation around threading and concurrency guarantees.

Bug: 64107584
Fixes: 68995409
Test: CtsActivityManagerDeviceTestCases
Change-Id: Ic86efa554b8b1caf80e5e004fda897d3483a68e8
parent 58180b02
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.content.pm;
import static android.os.Build.VERSION_CODES.DONUT;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.Context;
@@ -889,6 +890,29 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public int versionCode;

    /**
     * The user-visible SDK version (ex. 26) of the framework against which the application claims
     * to have been compiled, or {@code 0} if not specified.
     * <p>
     * This property is the compile-time equivalent of
     * {@link android.os.Build.VERSION#CODENAME Build.VERSION.SDK_INT}.
     *
     * @hide For platform use only; we don't expect developers to need to read this value.
     */
    public int compileSdkVersion;

    /**
     * The development codename (ex. "O", "REL") of the framework against which the application
     * claims to have been compiled, or {@code null} if not specified.
     * <p>
     * This property is the compile-time equivalent of
     * {@link android.os.Build.VERSION#CODENAME Build.VERSION.CODENAME}.
     *
     * @hide For platform use only; we don't expect developers to need to read this value.
     */
    @Nullable
    public String compileSdkVersionCodename;

    /**
     * When false, indicates that all components within this application are
     * considered disabled, regardless of their individually set enabled status.
@@ -1305,6 +1329,8 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        dest.writeInt(targetSandboxVersion);
        dest.writeString(classLoaderName);
        dest.writeStringArray(splitClassLoaderNames);
        dest.writeInt(compileSdkVersion);
        dest.writeString(compileSdkVersionCodename);
    }

    public static final Parcelable.Creator<ApplicationInfo> CREATOR
@@ -1372,6 +1398,8 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        targetSandboxVersion = source.readInt();
        classLoaderName = source.readString();
        splitClassLoaderNames = source.readStringArray();
        compileSdkVersion = source.readInt();
        compileSdkVersionCodename = source.readString();
    }

    /**
+28 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.pm;

import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

@@ -289,6 +290,29 @@ public class PackageInfo implements Parcelable {
    /** @hide */
    public boolean isStaticOverlay;

    /**
     * The user-visible SDK version (ex. 26) of the framework against which the application claims
     * to have been compiled, or {@code 0} if not specified.
     * <p>
     * This property is the compile-time equivalent of
     * {@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT}.
     *
     * @hide For platform use only; we don't expect developers to need to read this value.
     */
    public int compileSdkVersion;

    /**
     * The development codename (ex. "O", "REL") of the framework against which the application
     * claims to have been compiled, or {@code null} if not specified.
     * <p>
     * This property is the compile-time equivalent of
     * {@link android.os.Build.VERSION#CODENAME Build.VERSION.CODENAME}.
     *
     * @hide For platform use only; we don't expect developers to need to read this value.
     */
    @Nullable
    public String compileSdkVersionCodename;

    public PackageInfo() {
    }

@@ -344,6 +368,8 @@ public class PackageInfo implements Parcelable {
        dest.writeString(overlayTarget);
        dest.writeInt(isStaticOverlay ? 1 : 0);
        dest.writeInt(overlayPriority);
        dest.writeInt(compileSdkVersion);
        dest.writeString(compileSdkVersionCodename);
    }

    public static final Parcelable.Creator<PackageInfo> CREATOR
@@ -396,6 +422,8 @@ public class PackageInfo implements Parcelable {
        overlayTarget = source.readString();
        isStaticOverlay = source.readInt() != 0;
        overlayPriority = source.readInt();
        compileSdkVersion = source.readInt();
        compileSdkVersionCodename = source.readString();

        // The component lists were flattened with the redundant ApplicationInfo
        // instances omitted.  Distribute the canonical one here as appropriate.
+19 −0
Original line number Diff line number Diff line
@@ -678,6 +678,8 @@ public class PackageParser {
        pi.overlayTarget = p.mOverlayTarget;
        pi.overlayPriority = p.mOverlayPriority;
        pi.isStaticOverlay = p.mIsStaticOverlay;
        pi.compileSdkVersion = p.mCompileSdkVersion;
        pi.compileSdkVersionCodename = p.mCompileSdkVersionCodename;
        pi.firstInstallTime = firstInstallTime;
        pi.lastUpdateTime = lastUpdateTime;
        if ((flags&PackageManager.GET_GIDS) != 0) {
@@ -2076,6 +2078,16 @@ public class PackageParser {

        pkg.coreApp = parser.getAttributeBooleanValue(null, "coreApp", false);

        pkg.mCompileSdkVersion = sa.getInteger(
                com.android.internal.R.styleable.AndroidManifest_compileSdkVersion, 0);
        pkg.applicationInfo.compileSdkVersion = pkg.mCompileSdkVersion;
        pkg.mCompileSdkVersionCodename = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifest_compileSdkVersionCodename, 0);
        if (pkg.mCompileSdkVersionCodename != null) {
            pkg.mCompileSdkVersionCodename = pkg.mCompileSdkVersionCodename.intern();
        }
        pkg.applicationInfo.compileSdkVersionCodename = pkg.mCompileSdkVersionCodename;

        sa.recycle();

        return parseBaseApkCommon(pkg, null, res, parser, flags, outError);
@@ -5967,6 +5979,9 @@ public class PackageParser {
        public boolean mIsStaticOverlay;
        public boolean mTrustedOverlay;

        public int mCompileSdkVersion;
        public String mCompileSdkVersionCodename;

        /**
         * Data used to feed the KeySetManagerService
         */
@@ -6458,6 +6473,8 @@ public class PackageParser {
            mOverlayPriority = dest.readInt();
            mIsStaticOverlay = (dest.readInt() == 1);
            mTrustedOverlay = (dest.readInt() == 1);
            mCompileSdkVersion = dest.readInt();
            mCompileSdkVersionCodename = dest.readString();
            mSigningKeys = (ArraySet<PublicKey>) dest.readArraySet(boot);
            mUpgradeKeySets = (ArraySet<String>) dest.readArraySet(boot);

@@ -6581,6 +6598,8 @@ public class PackageParser {
            dest.writeInt(mOverlayPriority);
            dest.writeInt(mIsStaticOverlay ? 1 : 0);
            dest.writeInt(mTrustedOverlay ? 1 : 0);
            dest.writeInt(mCompileSdkVersion);
            dest.writeString(mCompileSdkVersionCodename);
            dest.writeArraySet(mSigningKeys);
            dest.writeArraySet(mUpgradeKeySets);
            writeKeySetMapping(dest, mKeySetMapping);
+31 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * Copyright (C) 2017 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.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:paddingTop="?attr/dialogPreferredPadding"
              android:paddingLeft="?attr/dialogPreferredPadding"
              android:paddingRight="?attr/dialogPreferredPadding">

    <CheckBox
        android:id="@+id/ask_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:text="@string/unsupported_compile_sdk_show" />
</FrameLayout>
+19 −0
Original line number Diff line number Diff line
@@ -1340,6 +1340,23 @@
         <p>The default value of this attribute is <code>1</code>. -->
    <attr name="targetSandboxVersion" format="integer" />

    <!-- The user-visible SDK version (ex. 26) of the framework against which the application was
         compiled. This attribute is automatically specified by the Android build tools and should
         NOT be manually specified.
         <p>
         This attribute is the compile-time equivalent of
         {@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT}. -->
    <attr name="compileSdkVersion" format="integer" />

    <!-- The development codename (ex. "O") of the framework against which the application was
         compiled, or "REL" if the application was compiled against a release build. This attribute
         is automatically specified by the Android build tools and should NOT be manually
         specified.
         <p>
         This attribute is the compile-time equivalent of
         {@link android.os.Build.VERSION#CODENAME Build.VERSION.CODENAME}. -->
    <attr name="compileSdkVersionCodename" format="string" />

    <!-- The <code>manifest</code> tag is the root of an
         <code>AndroidManifest.xml</code> file,
         describing the contents of an Android package (.apk) file.  One
@@ -1369,6 +1386,8 @@
        <attr name="isolatedSplits" />
        <attr name="isFeatureSplit" />
        <attr name="targetSandboxVersion" />
        <attr name="compileSdkVersion" />
        <attr name="compileSdkVersionCodename" />
    </declare-styleable>

    <!-- The <code>application</code> tag describes application-level components
Loading