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

Commit 851a5414 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Implement targetSdkVersion and maxSdkVersion, plus version code names.

This adds new attributes for specifying a targetSdkVersion and maxSdkVersion.
There is a new ApplicationInfo flag that is set if the application has set
its targetSdkVersion to the current platform or later.  Also you can now
use a string for minSdkVersion and targetSdkVerion, to indicate you are
building against a development tree instead of an official platform.
parent ed3b804f
Loading
Loading
Loading
Loading
+125 −0
Original line number Diff line number Diff line
@@ -5113,6 +5113,17 @@
 visibility="public"
>
</field>
<field name="maxSdkVersion"
 type="int"
 transient="false"
 volatile="false"
 value="16843377"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="maxWidth"
 type="int"
 transient="false"
@@ -7192,6 +7203,17 @@
 visibility="public"
>
</field>
<field name="targetSdkVersion"
 type="int"
 transient="false"
 volatile="false"
 value="16843376"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="taskAffinity"
 type="int"
 transient="false"
@@ -31852,6 +31874,28 @@
 visibility="public"
>
</field>
<field name="FLAG_TARGETS_SDK"
 type="int"
 transient="false"
 volatile="false"
 value="256"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="FLAG_UPDATED_SYSTEM_APP"
 type="int"
 transient="false"
 volatile="false"
 value="128"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="className"
 type="java.lang.String"
 transient="false"
@@ -34085,6 +34129,17 @@
 visibility="public"
>
</field>
<field name="INSTALL_FAILED_NEWER_SDK"
 type="int"
 transient="false"
 volatile="false"
 value="-14"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="INSTALL_FAILED_NO_SHARED_USER"
 type="int"
 transient="false"
@@ -85947,6 +86002,66 @@
 volatile="false"
 static="true"
 final="true"
 deprecated="deprecated"
 visibility="public"
>
</field>
<field name="SDK_INT"
 type="int"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="Build.VERSION_CODES"
 extends="java.lang.Object"
 abstract="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="Build.VERSION_CODES"
 type="android.os.Build.VERSION_CODES"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<field name="BASE"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="BASE_1_1"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="CUPCAKE"
 type="int"
 transient="false"
 volatile="false"
 value="3"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
@@ -86088,6 +86203,16 @@
 visibility="public"
>
</constructor>
<field name="CODENAME"
 type="java.lang.String"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="INCREMENTAL"
 type="java.lang.String"
 transient="false"
+3 −0
Original line number Diff line number Diff line
@@ -537,6 +537,9 @@ public final class Pm {
        case PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER:
            s = "INSTALL_FAILED_CONFLICTING_PROVIDER";
            break;
        case PackageManager.INSTALL_FAILED_NEWER_SDK:
            s = "INSTALL_FAILED_NEWER_SDK";
            break;
        case PackageManager.INSTALL_PARSE_FAILED_NOT_APK:
            s = "INSTALL_PARSE_FAILED_NOT_APK";
            break;
+10 −4
Original line number Diff line number Diff line
@@ -113,19 +113,25 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
    
    
    /**
     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
     *  {@hide}
     * Value for {@link #flags}: this is set if this application has been
     * install as an update to a built-in system application.
     */
    public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
    
    /**
     * Value for {@link #flags}: this is set of the application has set
     * its android:targetSdkVersion to something >= the current SDK version.
     */
    public static final int FLAG_TARGETS_SDK = 1<<8;

    /**
     * Flags associated with the application.  Any combination of
     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
     * {@link #FLAG_ALLOW_TASK_REPARENTING}
     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}.
     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
     * {@link #FLAG_TARGETS_SDK}.
     */
    public int flags = 0;
    
+8 −0
Original line number Diff line number Diff line
@@ -354,6 +354,14 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;

    /**
     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
     * the new package failed because the current SDK version is newer than
     * that required by the package.
     */
    public static final int INSTALL_FAILED_NEWER_SDK = -14;

    /**
     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
+70 −12
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class PackageParser {
    private String mArchiveSourcePath;
    private String[] mSeparateProcesses;
    private int mSdkVersion;
    private String mSdkCodename;

    private int mParseError = PackageManager.INSTALL_SUCCEEDED;

@@ -123,8 +124,9 @@ public class PackageParser {
        mSeparateProcesses = procs;
    }

    public void setSdkVersion(int sdkVersion) {
    public void setSdkVersion(int sdkVersion, String codename) {
        mSdkVersion = sdkVersion;
        mSdkCodename = codename;
    }

    private static final boolean isPackageFilename(String name) {
@@ -613,8 +615,8 @@ public class PackageParser {
        int type;

        final Package pkg = new Package(pkgName);
        pkg.mSystem = (flags&PARSE_IS_SYSTEM) != 0;
        boolean foundApp = false;
        boolean targetsSdk = false;
        
        TypedArray sa = res.obtainAttributes(attrs,
                com.android.internal.R.styleable.AndroidManifest);
@@ -726,13 +728,68 @@ public class PackageParser {
                    sa = res.obtainAttributes(attrs,
                            com.android.internal.R.styleable.AndroidManifestUsesSdk);

                    int vers = sa.getInt(
                            com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion, 0);
                    int minVers = 0;
                    String minCode = null;
                    int targetVers = 0;
                    String targetCode = null;
                    
                    TypedValue val = sa.peekValue(
                            com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
                    if (val != null) {
                        if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                            targetCode = minCode = val.string.toString();
                        } else {
                            // If it's not a string, it's an integer.
                            minVers = val.data;
                        }
                    }
                    
                    val = sa.peekValue(
                            com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
                    if (val != null) {
                        if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                            targetCode = minCode = val.string.toString();
                        } else {
                            // If it's not a string, it's an integer.
                            targetVers = val.data;
                        }
                    }
                    
                    int maxVers = sa.getInt(
                            com.android.internal.R.styleable.AndroidManifestUsesSdk_maxSdkVersion,
                            mSdkVersion);

                    sa.recycle();

                    if (vers > mSdkVersion) {
                        outError[0] = "Requires newer sdk version #" + vers
                    if (targetCode != null) {
                        if (!targetCode.equals(mSdkCodename)) {
                            if (mSdkCodename != null) {
                                outError[0] = "Requires development platform " + targetCode
                                        + " (current platform is " + mSdkCodename + ")";
                            } else {
                                outError[0] = "Requires development platform " + targetCode
                                        + " but this is a release platform.";
                            }
                            mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                            return null;
                        }
                        // If the code matches, it definitely targets this SDK.
                        targetsSdk = true;
                    } else if (targetVers >= mSdkVersion) {
                        // If they have explicitly targeted our current version
                        // or something after it, then note this.
                        targetsSdk = true;
                    }
                    
                    if (minVers > mSdkVersion) {
                        outError[0] = "Requires newer sdk version #" + minVers
                                + " (current version is #" + mSdkVersion + ")";
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                    
                    if (maxVers < mSdkVersion) {
                        outError[0] = "Requires older sdk version #" + maxVers
                                + " (current version is #" + mSdkVersion + ")";
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
@@ -767,6 +824,10 @@ public class PackageParser {
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
        }

        if (targetsSdk) {
            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_TARGETS_SDK;
        }
        
        if (pkg.usesLibraries.size() > 0) {
            pkg.usesLibraryFiles = new String[pkg.usesLibraries.size()];
            pkg.usesLibraries.toArray(pkg.usesLibraryFiles);
@@ -2133,9 +2194,6 @@ public class PackageParser {
        // If this is a 3rd party app, this is the path of the zip file.
        public String mPath;

        // True if this package is part of the system image.
        public boolean mSystem;

        // The version code declared for this package.
        public int mVersionCode;
        
Loading