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

Commit a2c132d9 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Hand-migration to TypedXml interface.

Previous changes have applied mechanical refactorings, but this change
hand-migrates the remaining logic which was too complex to identify.

This change should have no behavior change; famous last words.

Bug: 171832118
Test: manual
Exempt-From-Owner-Approval: trivial refactoring
Change-Id: I85cd830eb6bfde18fca6e73ee7adfdc385a890de
parent 8f431517
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -1530,28 +1530,28 @@ public class ActivityManager {
            if (label != null) {
            if (label != null) {
                setLabel(label);
                setLabel(label);
            }
            }
            final String colorPrimary = in.getAttributeValue(null,
            final int colorPrimary = in.getAttributeIntHex(null,
                    ATTR_TASKDESCRIPTIONCOLOR_PRIMARY);
                    ATTR_TASKDESCRIPTIONCOLOR_PRIMARY, 0);
            if (colorPrimary != null) {
            if (colorPrimary != 0) {
                setPrimaryColor((int) Long.parseLong(colorPrimary, 16));
                setPrimaryColor(colorPrimary);
            }
            }
            final String colorBackground = in.getAttributeValue(null,
            final int colorBackground = in.getAttributeIntHex(null,
                    ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND);
                    ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND, 0);
            if (colorBackground != null) {
            if (colorBackground != 0) {
                setBackgroundColor((int) Long.parseLong(colorBackground, 16));
                setBackgroundColor(colorBackground);
            }
            }
            final String iconFilename = in.getAttributeValue(null,
            final String iconFilename = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_FILENAME);
                    ATTR_TASKDESCRIPTIONICON_FILENAME);
            if (iconFilename != null) {
            if (iconFilename != null) {
                setIconFilename(iconFilename);
                setIconFilename(iconFilename);
            }
            }
            final String iconResourceId = in.getAttributeValue(null,
            final int iconResourceId = in.getAttributeInt(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE);
                    ATTR_TASKDESCRIPTIONICON_RESOURCE, Resources.ID_NULL);
            final String iconResourcePackage = in.getAttributeValue(null,
            final String iconResourcePackage = in.getAttributeValue(null,
                    ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE);
                    ATTR_TASKDESCRIPTIONICON_RESOURCE_PACKAGE);
            if (iconResourceId != null && iconResourcePackage != null) {
            if (iconResourceId != Resources.ID_NULL && iconResourcePackage != null) {
                setIcon(Icon.createWithResource(iconResourcePackage,
                setIcon(Icon.createWithResource(iconResourcePackage,
                        Integer.parseInt(iconResourceId, 10)));
                        iconResourceId));
            }
            }
        }
        }


+2 −14
Original line number Original line Diff line number Diff line
@@ -1116,23 +1116,11 @@ public final class NotificationChannel implements Parcelable {
    }
    }


    private static int safeInt(TypedXmlPullParser parser, String att, int defValue) {
    private static int safeInt(TypedXmlPullParser parser, String att, int defValue) {
        final String val = parser.getAttributeValue(null, att);
        return parser.getAttributeInt(null, att, defValue);
        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 boolean safeBool(TypedXmlPullParser parser, String att, boolean defValue) {
    private static boolean safeBool(TypedXmlPullParser parser, String att, boolean defValue) {
        final String value = parser.getAttributeValue(null, att);
        return parser.getAttributeBoolean(null, att, defValue);
        if (TextUtils.isEmpty(value)) return defValue;
        return Boolean.parseBoolean(value);
    }
    }


    private static long[] safeLongArray(TypedXmlPullParser parser, String att, long[] defValue) {
    private static long[] safeLongArray(TypedXmlPullParser parser, String att, long[] defValue) {
+1 −7
Original line number Original line Diff line number Diff line
@@ -231,13 +231,7 @@ public final class NotificationChannelGroup implements Parcelable {
    public void populateFromXml(TypedXmlPullParser parser) {
    public void populateFromXml(TypedXmlPullParser parser) {
        // Name, id, and importance are set in the constructor.
        // Name, id, and importance are set in the constructor.
        setDescription(parser.getAttributeValue(null, ATT_DESC));
        setDescription(parser.getAttributeValue(null, ATT_DESC));
        setBlocked(safeBool(parser, ATT_BLOCKED, false));
        setBlocked(parser.getAttributeBoolean(null, ATT_BLOCKED, false));
    }

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


    /**
    /**
+14 −5
Original line number Original line Diff line number Diff line
@@ -21,9 +21,12 @@ import android.annotation.Nullable;
import android.os.Build;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.util.Log;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.util.TypedXmlSerializer;


import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
@@ -33,6 +36,7 @@ import java.util.Objects;
 * A class containing information about a pending system update.
 * A class containing information about a pending system update.
 */
 */
public final class SystemUpdateInfo implements Parcelable {
public final class SystemUpdateInfo implements Parcelable {
    private static final String TAG = "SystemUpdateInfo";


    /**
    /**
     * Represents it is unknown whether the system update is a security patch.
     * Represents it is unknown whether the system update is a security patch.
@@ -140,11 +144,16 @@ public final class SystemUpdateInfo implements Parcelable {
        if (!Build.FINGERPRINT.equals(buildFingerprint)) {
        if (!Build.FINGERPRINT.equals(buildFingerprint)) {
            return null;
            return null;
        }
        }
        try {
            final long receivedTime =
            final long receivedTime =
                    parser.getAttributeLong(null, ATTR_RECEIVED_TIME);
                    parser.getAttributeLong(null, ATTR_RECEIVED_TIME);
            final int securityPatchState =
            final int securityPatchState =
                    parser.getAttributeInt(null, ATTR_SECURITY_PATCH_STATE);
                    parser.getAttributeInt(null, ATTR_SECURITY_PATCH_STATE);
            return new SystemUpdateInfo(receivedTime, securityPatchState);
            return new SystemUpdateInfo(receivedTime, securityPatchState);
        } catch (XmlPullParserException e) {
            Log.w(TAG, "Load xml failed", e);
            return null;
        }
    }
    }


    @Override
    @Override
+19 −26
Original line number Original line Diff line number Diff line
@@ -744,18 +744,12 @@ public final class SystemUpdatePolicy implements Parcelable {
    public static SystemUpdatePolicy restoreFromXml(TypedXmlPullParser parser) {
    public static SystemUpdatePolicy restoreFromXml(TypedXmlPullParser parser) {
        try {
        try {
            SystemUpdatePolicy policy = new SystemUpdatePolicy();
            SystemUpdatePolicy policy = new SystemUpdatePolicy();
            String value = parser.getAttributeValue(null, KEY_POLICY_TYPE);
            policy.mPolicyType =
            if (value != null) {
                    parser.getAttributeInt(null, KEY_POLICY_TYPE, TYPE_UNKNOWN);
                policy.mPolicyType = Integer.parseInt(value);
            policy.mMaintenanceWindowStart =

                    parser.getAttributeInt(null, KEY_INSTALL_WINDOW_START, 0);
                value = parser.getAttributeValue(null, KEY_INSTALL_WINDOW_START);
            policy.mMaintenanceWindowEnd =
                if (value != null) {
                    parser.getAttributeInt(null, KEY_INSTALL_WINDOW_END, 0);
                    policy.mMaintenanceWindowStart = Integer.parseInt(value);
                }
                value = parser.getAttributeValue(null, KEY_INSTALL_WINDOW_END);
                if (value != null) {
                    policy.mMaintenanceWindowEnd = Integer.parseInt(value);
                }


            int outerDepth = parser.getDepth();
            int outerDepth = parser.getDepth();
            int type;
            int type;
@@ -772,7 +766,6 @@ public final class SystemUpdatePolicy implements Parcelable {
                        MonthDay.parse(parser.getAttributeValue(null, KEY_FREEZE_END))));
                        MonthDay.parse(parser.getAttributeValue(null, KEY_FREEZE_END))));
            }
            }
            return policy;
            return policy;
            }
        } catch (NumberFormatException | XmlPullParserException | IOException e) {
        } catch (NumberFormatException | XmlPullParserException | IOException e) {
            // Fail through
            // Fail through
            Log.w(TAG, "Load xml failed", e);
            Log.w(TAG, "Load xml failed", e);
Loading