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

Commit db4ae71b authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge changes from topic "nov30"

* changes:
  Hand-migration to TypedXml interface.
  Mechanically apply TypedXml refaster template.
  Mechanical refactoring to new typed XML classes.
  Additional hand-migration to TypedXml interface.
  "Resolve" both human-readable and binary XML.
parents e1af0f92 a2c132d9
Loading
Loading
Loading
Loading
+19 −20
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ import android.util.ArrayMap;
import android.util.DisplayMetrics;
import android.util.Singleton;
import android.util.Size;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.view.Surface;
import android.view.WindowInsetsController.Appearance;

@@ -1502,57 +1504,54 @@ public class ActivityManager {
        }

        /** @hide */
        public void saveToXml(XmlSerializer out) throws IOException {
        public void saveToXml(TypedXmlSerializer out) throws IOException {
            if (mLabel != null) {
                out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
            }
            if (mColorPrimary != 0) {
                out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
                        Integer.toHexString(mColorPrimary));
                out.attributeIntHex(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY, mColorPrimary);
            }
            if (mColorBackground != 0) {
                out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
                        Integer.toHexString(mColorBackground));
                out.attributeIntHex(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND, mColorBackground);
            }
            if (mIconFilename != null) {
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_FILENAME, mIconFilename);
            }
            if (mIcon != null && mIcon.getType() == Icon.TYPE_RESOURCE) {
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE,
                        Integer.toString(mIcon.getResId()));
                out.attributeInt(null, ATTR_TASKDESCRIPTIONICON_RESOURCE, mIcon.getResId());
                out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE,
                        mIcon.getResPackage());
            }
        }

        /** @hide */
        public void restoreFromXml(XmlPullParser in) {
        public void restoreFromXml(TypedXmlPullParser in) {
            final String label = in.getAttributeValue(null, ATTR_TASKDESCRIPTIONLABEL);
            if (label != null) {
                setLabel(label);
            }
            final String colorPrimary = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONCOLOR_PRIMARY);
            if (colorPrimary != null) {
                setPrimaryColor((int) Long.parseLong(colorPrimary, 16));
            final int colorPrimary = in.getAttributeIntHex(null,
                    ATTR_TASKDESCRIPTIONCOLOR_PRIMARY, 0);
            if (colorPrimary != 0) {
                setPrimaryColor(colorPrimary);
            }
            final String colorBackground = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND);
            if (colorBackground != null) {
                setBackgroundColor((int) Long.parseLong(colorBackground, 16));
            final int colorBackground = in.getAttributeIntHex(null,
                    ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND, 0);
            if (colorBackground != 0) {
                setBackgroundColor(colorBackground);
            }
            final String iconFilename = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_FILENAME);
            if (iconFilename != null) {
                setIconFilename(iconFilename);
            }
            final String iconResourceId = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE);
            final int iconResourceId = in.getAttributeInt(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE, Resources.ID_NULL);
            final String iconResourcePackage = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE);
            if (iconResourceId != null && iconResourcePackage != null) {
            if (iconResourceId != Resources.ID_NULL && iconResourcePackage != null) {
                setIcon(Icon.createWithResource(iconResourcePackage,
                        Integer.parseInt(iconResourceId, 10)));
                        iconResourceId));
            }
        }

+34 −47
Original line number Diff line number Diff line
@@ -32,9 +32,12 @@ import android.os.Parcelable;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.util.proto.ProtoOutputStream;

import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;

import org.json.JSONException;
import org.json.JSONObject;
@@ -869,7 +872,7 @@ public final class NotificationChannel implements Parcelable {
     * @hide
     */
    public void populateFromXmlForRestore(XmlPullParser parser, Context context) {
        populateFromXml(parser, true, context);
        populateFromXml(XmlUtils.makeTyped(parser), true, context);
    }

    /**
@@ -877,13 +880,13 @@ public final class NotificationChannel implements Parcelable {
     */
    @SystemApi
    public void populateFromXml(XmlPullParser parser) {
        populateFromXml(parser, false, null);
        populateFromXml(XmlUtils.makeTyped(parser), false, null);
    }

    /**
     * If {@param forRestore} is true, {@param Context} MUST be non-null.
     */
    private void populateFromXml(XmlPullParser parser, boolean forRestore,
    private void populateFromXml(TypedXmlPullParser parser, boolean forRestore,
            @Nullable Context context) {
        Preconditions.checkArgument(!forRestore || context != null,
                "forRestore is true but got null context");
@@ -941,14 +944,14 @@ public final class NotificationChannel implements Parcelable {
     */
    @SystemApi
    public void writeXml(XmlSerializer out) throws IOException {
        writeXml(out, false, null);
        writeXml(XmlUtils.makeTyped(out), false, null);
    }

    /**
     * @hide
     */
    public void writeXmlForBackup(XmlSerializer out, Context context) throws IOException {
        writeXml(out, true, context);
        writeXml(XmlUtils.makeTyped(out), true, context);
    }

    private Uri getSoundForBackup(Context context) {
@@ -967,7 +970,7 @@ public final class NotificationChannel implements Parcelable {
    /**
     * If {@param forBackup} is true, {@param Context} MUST be non-null.
     */
    private void writeXml(XmlSerializer out, boolean forBackup, @Nullable Context context)
    private void writeXml(TypedXmlSerializer out, boolean forBackup, @Nullable Context context)
            throws IOException {
        Preconditions.checkArgument(!forBackup || context != null,
                "forBackup is true but got null context");
@@ -980,62 +983,58 @@ public final class NotificationChannel implements Parcelable {
            out.attribute(null, ATT_DESC, getDescription());
        }
        if (getImportance() != DEFAULT_IMPORTANCE) {
            out.attribute(
                    null, ATT_IMPORTANCE, Integer.toString(getImportance()));
            out.attributeInt(null, ATT_IMPORTANCE, getImportance());
        }
        if (canBypassDnd()) {
            out.attribute(
                    null, ATT_PRIORITY, Integer.toString(Notification.PRIORITY_MAX));
            out.attributeInt(null, ATT_PRIORITY, Notification.PRIORITY_MAX);
        }
        if (getLockscreenVisibility() != DEFAULT_VISIBILITY) {
            out.attribute(null, ATT_VISIBILITY,
                    Integer.toString(getLockscreenVisibility()));
            out.attributeInt(null, ATT_VISIBILITY, getLockscreenVisibility());
        }
        Uri sound = forBackup ? getSoundForBackup(context) : getSound();
        if (sound != null) {
            out.attribute(null, ATT_SOUND, sound.toString());
        }
        if (getAudioAttributes() != null) {
            out.attribute(null, ATT_USAGE, Integer.toString(getAudioAttributes().getUsage()));
            out.attribute(null, ATT_CONTENT_TYPE,
                    Integer.toString(getAudioAttributes().getContentType()));
            out.attribute(null, ATT_FLAGS, Integer.toString(getAudioAttributes().getFlags()));
            out.attributeInt(null, ATT_USAGE, getAudioAttributes().getUsage());
            out.attributeInt(null, ATT_CONTENT_TYPE, getAudioAttributes().getContentType());
            out.attributeInt(null, ATT_FLAGS, getAudioAttributes().getFlags());
        }
        if (shouldShowLights()) {
            out.attribute(null, ATT_LIGHTS, Boolean.toString(shouldShowLights()));
            out.attributeBoolean(null, ATT_LIGHTS, shouldShowLights());
        }
        if (getLightColor() != DEFAULT_LIGHT_COLOR) {
            out.attribute(null, ATT_LIGHT_COLOR, Integer.toString(getLightColor()));
            out.attributeInt(null, ATT_LIGHT_COLOR, getLightColor());
        }
        if (shouldVibrate()) {
            out.attribute(null, ATT_VIBRATION_ENABLED, Boolean.toString(shouldVibrate()));
            out.attributeBoolean(null, ATT_VIBRATION_ENABLED, shouldVibrate());
        }
        if (getVibrationPattern() != null) {
            out.attribute(null, ATT_VIBRATION, longArrayToString(getVibrationPattern()));
        }
        if (getUserLockedFields() != 0) {
            out.attribute(null, ATT_USER_LOCKED, Integer.toString(getUserLockedFields()));
            out.attributeInt(null, ATT_USER_LOCKED, getUserLockedFields());
        }
        if (isFgServiceShown()) {
            out.attribute(null, ATT_FG_SERVICE_SHOWN, Boolean.toString(isFgServiceShown()));
            out.attributeBoolean(null, ATT_FG_SERVICE_SHOWN, isFgServiceShown());
        }
        if (canShowBadge()) {
            out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(canShowBadge()));
            out.attributeBoolean(null, ATT_SHOW_BADGE, canShowBadge());
        }
        if (isDeleted()) {
            out.attribute(null, ATT_DELETED, Boolean.toString(isDeleted()));
            out.attributeBoolean(null, ATT_DELETED, isDeleted());
        }
        if (getGroup() != null) {
            out.attribute(null, ATT_GROUP, getGroup());
        }
        if (isBlockable()) {
            out.attribute(null, ATT_BLOCKABLE_SYSTEM, Boolean.toString(isBlockable()));
            out.attributeBoolean(null, ATT_BLOCKABLE_SYSTEM, isBlockable());
        }
        if (getAllowBubbles() != DEFAULT_ALLOW_BUBBLE) {
            out.attribute(null, ATT_ALLOW_BUBBLE, Integer.toString(getAllowBubbles()));
            out.attributeInt(null, ATT_ALLOW_BUBBLE, getAllowBubbles());
        }
        if (getOriginalImportance() != DEFAULT_IMPORTANCE) {
            out.attribute(null, ATT_ORIG_IMP, Integer.toString(getOriginalImportance()));
            out.attributeInt(null, ATT_ORIG_IMP, getOriginalImportance());
        }
        if (getParentChannelId() != null) {
            out.attribute(null, ATT_PARENT_CHANNEL, getParentChannelId());
@@ -1044,10 +1043,10 @@ public final class NotificationChannel implements Parcelable {
            out.attribute(null, ATT_CONVERSATION_ID, getConversationId());
        }
        if (isDemoted()) {
            out.attribute(null, ATT_DEMOTE, Boolean.toString(isDemoted()));
            out.attributeBoolean(null, ATT_DEMOTE, isDemoted());
        }
        if (isImportantConversation()) {
            out.attribute(null, ATT_IMP_CONVERSATION, Boolean.toString(isImportantConversation()));
            out.attributeBoolean(null, ATT_IMP_CONVERSATION, isImportantConversation());
        }

        // mImportanceLockedDefaultApp and mImportanceLockedByOEM have a different source of
@@ -1099,7 +1098,7 @@ public final class NotificationChannel implements Parcelable {
        return record;
    }

    private static AudioAttributes safeAudioAttributes(XmlPullParser parser) {
    private static AudioAttributes safeAudioAttributes(TypedXmlPullParser parser) {
        int usage = safeInt(parser, ATT_USAGE, AudioAttributes.USAGE_NOTIFICATION);
        int contentType = safeInt(parser, ATT_CONTENT_TYPE,
                AudioAttributes.CONTENT_TYPE_SONIFICATION);
@@ -1111,32 +1110,20 @@ public final class NotificationChannel implements Parcelable {
                .build();
    }

    private static Uri safeUri(XmlPullParser parser, String att) {
    private static Uri safeUri(TypedXmlPullParser parser, String att) {
        final String val = parser.getAttributeValue(null, att);
        return val == null ? null : Uri.parse(val);
    }

    private static int safeInt(XmlPullParser parser, String att, int defValue) {
        final String val = parser.getAttributeValue(null, att);
        return tryParseInt(val, defValue);
    }

    private static int tryParseInt(String value, int defValue) {
        if (TextUtils.isEmpty(value)) return defValue;
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            return defValue;
        }
    private static int safeInt(TypedXmlPullParser parser, String att, int defValue) {
        return parser.getAttributeInt(null, att, defValue);
    }

    private static boolean safeBool(XmlPullParser parser, String att, boolean defValue) {
        final String value = parser.getAttributeValue(null, att);
        if (TextUtils.isEmpty(value)) return defValue;
        return Boolean.parseBoolean(value);
    private static boolean safeBool(TypedXmlPullParser parser, String att, boolean defValue) {
        return parser.getAttributeBoolean(null, att, defValue);
    }

    private static long[] safeLongArray(XmlPullParser parser, String att, long[] defValue) {
    private static long[] safeLongArray(TypedXmlPullParser parser, String att, long[] defValue) {
        final String attributeValue = parser.getAttributeValue(null, att);
        if (TextUtils.isEmpty(attributeValue)) return defValue;
        String[] values = attributeValue.split(DELIMITER);
+7 −13
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@ import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.util.proto.ProtoOutputStream;

import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.util.ArrayList;
@@ -228,22 +228,16 @@ public final class NotificationChannelGroup implements Parcelable {
    /**
     * @hide
     */
    public void populateFromXml(XmlPullParser parser) {
    public void populateFromXml(TypedXmlPullParser parser) {
        // Name, id, and importance are set in the constructor.
        setDescription(parser.getAttributeValue(null, ATT_DESC));
        setBlocked(safeBool(parser, ATT_BLOCKED, false));
    }

    private static boolean safeBool(XmlPullParser parser, String att, boolean defValue) {
        final String value = parser.getAttributeValue(null, att);
        if (TextUtils.isEmpty(value)) return defValue;
        return Boolean.parseBoolean(value);
        setBlocked(parser.getAttributeBoolean(null, ATT_BLOCKED, false));
    }

    /**
     * @hide
     */
    public void writeXml(XmlSerializer out) throws IOException {
    public void writeXml(TypedXmlSerializer out) throws IOException {
        out.startTag(null, TAG_GROUP);

        out.attribute(null, ATT_ID, getId());
@@ -253,8 +247,8 @@ public final class NotificationChannelGroup implements Parcelable {
        if (getDescription() != null) {
            out.attribute(null, ATT_DESC, getDescription().toString());
        }
        out.attribute(null, ATT_BLOCKED, Boolean.toString(isBlocked()));
        out.attribute(null, ATT_USER_LOCKED, Integer.toString(mUserLockedFields));
        out.attributeBoolean(null, ATT_BLOCKED, isBlocked());
        out.attributeInt(null, ATT_USER_LOCKED, mUserLockedFields);

        out.endTag(null, TAG_GROUP);
    }
+6 −6
Original line number Diff line number Diff line
@@ -37,11 +37,12 @@ import android.util.AttributeSet;
import android.util.Log;
import android.util.Printer;
import android.util.SparseArray;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.util.ArrayList;
@@ -472,16 +473,15 @@ public final class DeviceAdminInfo implements Parcelable {
    }

    /** @hide */
    public void writePoliciesToXml(XmlSerializer out)
    public void writePoliciesToXml(TypedXmlSerializer out)
            throws IllegalArgumentException, IllegalStateException, IOException {
        out.attribute(null, "flags", Integer.toString(mUsesPolicies));
        out.attributeInt(null, "flags", mUsesPolicies);
    }

    /** @hide */
    public void readPoliciesFromXml(XmlPullParser parser)
    public void readPoliciesFromXml(TypedXmlPullParser parser)
            throws XmlPullParserException, IOException {
        mUsesPolicies = Integer.parseInt(
                parser.getAttributeValue(null, "flags"));
        mUsesPolicies = parser.getAttributeInt(null, "flags");
    }

    public void dump(Printer pw, String prefix) {
+8 −8
Original line number Diff line number Diff line
@@ -26,10 +26,10 @@ import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.util.ArrayList;
@@ -201,10 +201,10 @@ public final class FactoryResetProtectionPolicy implements Parcelable {
     * @hide
     */
    @Nullable
    public static FactoryResetProtectionPolicy readFromXml(@NonNull XmlPullParser parser) {
    public static FactoryResetProtectionPolicy readFromXml(@NonNull TypedXmlPullParser parser) {
        try {
            boolean factoryResetProtectionEnabled = Boolean.parseBoolean(
                    parser.getAttributeValue(null, KEY_FACTORY_RESET_PROTECTION_ENABLED));
            boolean factoryResetProtectionEnabled = parser.getAttributeBoolean(null,
                    KEY_FACTORY_RESET_PROTECTION_ENABLED, false);

            List<String> factoryResetProtectionAccounts = new ArrayList<>();
            int outerDepth = parser.getDepth();
@@ -232,9 +232,9 @@ public final class FactoryResetProtectionPolicy implements Parcelable {
    /**
     * @hide
     */
    public void writeToXml(@NonNull XmlSerializer out) throws IOException {
        out.attribute(null, KEY_FACTORY_RESET_PROTECTION_ENABLED,
                Boolean.toString(mFactoryResetProtectionEnabled));
    public void writeToXml(@NonNull TypedXmlSerializer out) throws IOException {
        out.attributeBoolean(null, KEY_FACTORY_RESET_PROTECTION_ENABLED,
                mFactoryResetProtectionEnabled);
        for (String account : mFactoryResetProtectionAccounts) {
            out.startTag(null, KEY_FACTORY_RESET_PROTECTION_ACCOUNT);
            out.attribute(null, ATTR_VALUE, account);
Loading