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

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

Merge changes from topic "nov14"

* changes:
  Hand-migration to TypedXml interface.
  Mechanically apply TypedXml refaster template.
  Refaster templates for new TypedXml classes.
  Mechanical refactoring to new XML resolvers.
  Refine TypedXmlPullParser API interface.
parents 6e53c223 5058d5e9
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ java_defaults {
            "-Xep:AndroidFrameworkBinderIdentity:ERROR",
            "-Xep:AndroidFrameworkCompatChange:ERROR",
            "-Xep:AndroidFrameworkUid:ERROR",
            // NOTE: only enable to generate local patchfiles
            // "-XepPatchChecks:refaster:frameworks/base/errorprone/refaster/EfficientXml.java.refaster",
            // "-XepPatchLocation:/tmp/refaster/",
        ],
    },
}
@@ -915,8 +918,9 @@ java_library_host {
        include_dirs: ["external/protobuf/src"],
        type: "full",
    },
    // Protos have lots of MissingOverride and similar.
    errorprone: {
        javacflags: ["-Xep:MissingOverride:OFF"], // b/72714520
        javacflags: ["-XepDisableAllChecks"],
    },
}

+15 −2
Original line number Diff line number Diff line
@@ -5626,10 +5626,23 @@ public class PackageParser {
            return null;
        }

        try {
            return parsePublicKey(Base64.decode(encodedPublicKey, Base64.DEFAULT));
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Could not parse verifier public key; invalid Base64");
            return null;
        }
    }

    public static final PublicKey parsePublicKey(final byte[] publicKey) {
        if (publicKey == null) {
            Slog.w(TAG, "Could not parse null public key");
            return null;
        }

        EncodedKeySpec keySpec;
        try {
            final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
            keySpec = new X509EncodedKeySpec(encoded);
            keySpec = new X509EncodedKeySpec(publicKey);
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Could not parse verifier public key; invalid Base64");
            return null;
+9 −0
Original line number Diff line number Diff line
@@ -16,14 +16,17 @@

package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.TypedXmlSerializer;

import com.android.internal.util.ArrayUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.security.PublicKey;
@@ -289,6 +292,12 @@ public class Signature implements Parcelable {
        }
    };

    /** {@hide} */
    public void writeToXmlAttributeBytesHex(@NonNull TypedXmlSerializer out,
            @Nullable String namespace, @NonNull String name) throws IOException {
        out.attributeBytesHex(namespace, name, mSignature);
    }

    private Signature(Parcel source) {
        mSignature = source.createByteArray();
    }
+18 −6
Original line number Diff line number Diff line
@@ -21,14 +21,15 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.ArrayMap;
import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import android.util.Xml;
import android.util.proto.ProtoOutputStream;

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

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

import java.io.IOException;
@@ -234,7 +235,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa

    /** @hide */
    @Override
    public void writeUnknownObject(Object v, String name, XmlSerializer out)
    public void writeUnknownObject(Object v, String name, TypedXmlSerializer out)
            throws XmlPullParserException, IOException {
        if (v instanceof PersistableBundle) {
            out.startTag(null, TAG_PERSISTABLEMAP);
@@ -248,6 +249,11 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa

    /** @hide */
    public void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
        saveToXml(XmlUtils.makeTyped(out));
    }

    /** @hide */
    public void saveToXml(TypedXmlSerializer out) throws IOException, XmlPullParserException {
        unparcel();
        XmlUtils.writeMapXml(mMap, out, this);
    }
@@ -255,7 +261,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
    /** @hide */
    static class MyReadMapCallback implements  XmlUtils.ReadMapCallback {
        @Override
        public Object readThisUnknownObjectXml(XmlPullParser in, String tag)
        public Object readThisUnknownObjectXml(TypedXmlPullParser in, String tag)
                throws XmlPullParserException, IOException {
            if (TAG_PERSISTABLEMAP.equals(tag)) {
                return restoreFromXml(in);
@@ -290,6 +296,12 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
    /** @hide */
    public static PersistableBundle restoreFromXml(XmlPullParser in) throws IOException,
            XmlPullParserException {
        return restoreFromXml(XmlUtils.makeTyped(in));
    }

    /** @hide */
    public static PersistableBundle restoreFromXml(TypedXmlPullParser in) throws IOException,
            XmlPullParserException {
        final int outerDepth = in.getDepth();
        final String startTag = in.getName();
        final String[] tagName = new String[1];
@@ -355,7 +367,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
     * @see #readFromStream
     */
    public void writeToStream(@NonNull OutputStream outputStream) throws IOException {
        FastXmlSerializer serializer = new FastXmlSerializer();
        TypedXmlSerializer serializer = Xml.newFastSerializer();
        serializer.setOutput(outputStream, UTF_8.name());
        serializer.startTag(null, "bundle");
        try {
@@ -378,7 +390,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
    public static PersistableBundle readFromStream(@NonNull InputStream inputStream)
            throws IOException {
        try {
            XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
            TypedXmlPullParser parser = Xml.newFastPullParser();
            parser.setInput(inputStream, UTF_8.name());
            parser.next();
            return PersistableBundle.restoreFromXml(parser);
+49 −24
Original line number Diff line number Diff line
@@ -20,8 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;

import org.xmlpull.v1.XmlPullParser;

import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;

/**
 * Specialization of {@link XmlPullParser} which adds explicit methods to
@@ -31,67 +30,93 @@ import java.io.IOException;
 */
public interface TypedXmlPullParser extends XmlPullParser {
    /**
     * @return decoded strongly-typed {@link #getAttributeValue}, or
     *         {@code null} if malformed or undefined
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    @Nullable byte[] getAttributeBytesHex(@Nullable String namespace, @NonNull String name)
            throws IOException;
    @NonNull byte[] getAttributeBytesHex(@Nullable String namespace, @NonNull String name)
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}, or
     *         {@code null} if malformed or undefined
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    @Nullable byte[] getAttributeBytesBase64(@Nullable String namespace, @NonNull String name)
            throws IOException;
    @NonNull byte[] getAttributeBytesBase64(@Nullable String namespace, @NonNull String name)
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    int getAttributeInt(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    int getAttributeIntHex(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    long getAttributeLong(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    long getAttributeLongHex(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    float getAttributeFloat(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    double getAttributeDouble(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws IOException if the value is malformed or undefined
     * @throws XmlPullParserException if the value is malformed or undefined
     */
    boolean getAttributeBoolean(@Nullable String namespace, @NonNull String name)
            throws IOException;
            throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}, otherwise
     *         default value if the value is malformed or undefined
     */
    default @Nullable byte[] getAttributeBytesHex(@Nullable String namespace,
            @NonNull String name, @Nullable byte[] defaultValue) {
        try {
            return getAttributeBytesHex(namespace, name);
        } catch (Exception ignored) {
            return defaultValue;
        }
    }

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}, otherwise
     *         default value if the value is malformed or undefined
     */
    default @Nullable byte[] getAttributeBytesBase64(@Nullable String namespace,
            @NonNull String name, @Nullable byte[] defaultValue) {
        try {
            return getAttributeBytesBase64(namespace, name);
        } catch (Exception ignored) {
            return defaultValue;
        }
    }

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}, otherwise
Loading