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

Commit a926dbf5 authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge "Allow max aspect ratio to be specified by meta-data tag." into oc-dr1-dev

parents 717dd58c 22571db5
Loading
Loading
Loading
Loading
+66 −17
Original line number Original line Diff line number Diff line
@@ -200,6 +200,8 @@ public class PackageParser {
    // Temporary workaround; allow meta-data to expose components to instant apps
    // Temporary workaround; allow meta-data to expose components to instant apps
    private static final String META_DATA_INSTANT_APPS = "instantapps.clients.allowed";
    private static final String META_DATA_INSTANT_APPS = "instantapps.clients.allowed";


    private static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect";

    /**
    /**
     * Bit mask of all the valid bits that can be set in recreateOnConfigChanges.
     * Bit mask of all the valid bits that can be set in recreateOnConfigChanges.
     * @hide
     * @hide
@@ -3639,6 +3641,7 @@ public class PackageParser {


        final int innerDepth = parser.getDepth();
        final int innerDepth = parser.getDepth();
        int type;
        int type;

        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
@@ -3815,6 +3818,10 @@ public class PackageParser {
            }
            }
        }
        }


        // Must be ran after the entire {@link ApplicationInfo} has been fully processed and after
        // every activity info has had a chance to set it from its attributes.
        setMaxAspectRatio(owner);

        modifySharedLibrariesForBackwardCompatibility(owner);
        modifySharedLibrariesForBackwardCompatibility(owner);


        if (hasDomainURLs(owner)) {
        if (hasDomainURLs(owner)) {
@@ -4258,7 +4265,12 @@ public class PackageParser {
                a.info.flags |= FLAG_ALWAYS_FOCUSABLE;
                a.info.flags |= FLAG_ALWAYS_FOCUSABLE;
            }
            }


            setActivityMaxAspectRatio(a.info, sa, owner);
            if (sa.hasValue(R.styleable.AndroidManifestActivity_maxAspectRatio)
                    && sa.getType(R.styleable.AndroidManifestActivity_maxAspectRatio)
                    == TypedValue.TYPE_FLOAT) {
                a.setMaxAspectRatio(sa.getFloat(R.styleable.AndroidManifestActivity_maxAspectRatio,
                        0 /*default*/));
            }


            a.info.lockTaskLaunchMode =
            a.info.lockTaskLaunchMode =
                    sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0);
                    sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0);
@@ -4496,28 +4508,40 @@ public class PackageParser {
        }
        }
    }
    }


    private void setActivityMaxAspectRatio(ActivityInfo aInfo, TypedArray sa, Package owner) {
    /**
        if (aInfo.resizeMode == RESIZE_MODE_RESIZEABLE
     * Sets every the max aspect ratio of every child activity that doesn't already have an aspect
                || aInfo.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
     * ratio set.
            // Resizeable activities can be put in any aspect ratio.
     */
            aInfo.maxAspectRatio = 0;
    private void setMaxAspectRatio(Package owner) {
            return;
        }

        // Default to (1.86) 16.7:9 aspect ratio for pre-O apps and unset for O and greater.
        // Default to (1.86) 16.7:9 aspect ratio for pre-O apps and unset for O and greater.
        // NOTE: 16.7:9 was the max aspect ratio Android devices can support pre-O per the CDD.
        // NOTE: 16.7:9 was the max aspect ratio Android devices can support pre-O per the CDD.
        float defaultMaxAspectRatio = owner.applicationInfo.targetSdkVersion < O
        float maxAspectRatio = owner.applicationInfo.targetSdkVersion < O
                ? DEFAULT_PRE_O_MAX_ASPECT_RATIO : 0;
                ? DEFAULT_PRE_O_MAX_ASPECT_RATIO : 0;

        if (owner.applicationInfo.maxAspectRatio != 0) {
        if (owner.applicationInfo.maxAspectRatio != 0) {
            // Use the application max aspect ration as default if set.
            // Use the application max aspect ration as default if set.
            defaultMaxAspectRatio = owner.applicationInfo.maxAspectRatio;
            maxAspectRatio = owner.applicationInfo.maxAspectRatio;
        } else if (owner.mAppMetaData != null
                && owner.mAppMetaData.containsKey(METADATA_MAX_ASPECT_RATIO)) {
            maxAspectRatio = owner.mAppMetaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio);
        }
        }


        aInfo.maxAspectRatio = sa.getFloat(
        for (Activity activity : owner.activities) {
                R.styleable.AndroidManifestActivity_maxAspectRatio, defaultMaxAspectRatio);
            // If the max aspect ratio for the activity has already been set, skip.
        if (aInfo.maxAspectRatio < 1.0f && aInfo.maxAspectRatio != 0) {
            if (activity.hasMaxAspectRatio()) {
            // Ignore any value lesser than 1.0.
                continue;
            aInfo.maxAspectRatio = 0;
            }

            // By default we prefer to use a values defined on the activity directly than values
            // defined on the application. We do not check the styled attributes on the activity
            // as it would have already been set when we processed the activity. We wait to process
            // the meta data here since this method is called at the end of processing the
            // application and all meta data is guaranteed.
            final float activityAspectRatio = activity.metaData != null
                    ? activity.metaData.getFloat(METADATA_MAX_ASPECT_RATIO, maxAspectRatio)
                    : maxAspectRatio;

            activity.setMaxAspectRatio(activityAspectRatio);
        }
        }
    }
    }


@@ -4658,6 +4682,7 @@ public class PackageParser {
        info.windowLayout = target.info.windowLayout;
        info.windowLayout = target.info.windowLayout;
        info.resizeMode = target.info.resizeMode;
        info.resizeMode = target.info.resizeMode;
        info.maxAspectRatio = target.info.maxAspectRatio;
        info.maxAspectRatio = target.info.maxAspectRatio;

        info.encryptionAware = info.directBootAware = target.info.directBootAware;
        info.encryptionAware = info.directBootAware = target.info.directBootAware;


        Activity a = new Activity(mParseActivityAliasArgs, info);
        Activity a = new Activity(mParseActivityAliasArgs, info);
@@ -6940,6 +6965,11 @@ public class PackageParser {


    public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable {
    public final static class Activity extends Component<ActivityIntentInfo> implements Parcelable {
        public final ActivityInfo info;
        public final ActivityInfo info;
        private boolean mHasMaxAspectRatio;

        private boolean hasMaxAspectRatio() {
            return mHasMaxAspectRatio;
        }


        public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
        public Activity(final ParseComponentArgs args, final ActivityInfo _info) {
            super(args, _info);
            super(args, _info);
@@ -6952,6 +6982,23 @@ public class PackageParser {
            info.packageName = packageName;
            info.packageName = packageName;
        }
        }



        private void setMaxAspectRatio(float maxAspectRatio) {
            if (info.resizeMode == RESIZE_MODE_RESIZEABLE
                    || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
                // Resizeable activities can be put in any aspect ratio.
                return;
            }

            if (maxAspectRatio < 1.0f && maxAspectRatio != 0) {
                // Ignore any value lesser than 1.0.
                return;
            }

            info.maxAspectRatio = maxAspectRatio;
            mHasMaxAspectRatio = true;
        }

        public String toString() {
        public String toString() {
            StringBuilder sb = new StringBuilder(128);
            StringBuilder sb = new StringBuilder(128);
            sb.append("Activity{");
            sb.append("Activity{");
@@ -6971,11 +7018,13 @@ public class PackageParser {
        public void writeToParcel(Parcel dest, int flags) {
        public void writeToParcel(Parcel dest, int flags) {
            super.writeToParcel(dest, flags);
            super.writeToParcel(dest, flags);
            dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES);
            dest.writeParcelable(info, flags | Parcelable.PARCELABLE_ELIDE_DUPLICATES);
            dest.writeBoolean(mHasMaxAspectRatio);
        }
        }


        private Activity(Parcel in) {
        private Activity(Parcel in) {
            super(in);
            super(in);
            info = in.readParcelable(Object.class.getClassLoader());
            info = in.readParcelable(Object.class.getClassLoader());
            mHasMaxAspectRatio = in.readBoolean();


            for (ActivityIntentInfo aii : intents) {
            for (ActivityIntentInfo aii : intents) {
                aii.activity = this;
                aii.activity = this;