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

Commit b90e6818 authored by Hai Zhang's avatar Hai Zhang
Browse files

Extract four byte sequence modified UTF-8 into separate classes.

The four byte sequence modified UTF-8 is now handled by classes
prefixed with ART, whereas the base classes implements the standard
modified UTF-8 and should be used by new clients in modules.

Bug: 243194720
Test: atest -rerun-until-failure 10 FastDataTest BinaryXmlTest \
      FrameworksCoreTests:XmlTest FastDataPerfTest
Change-Id: I08cea54c2a27249e00b7e155af0cf11949486375
parent 384e8af6
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class FastDataPerfTest {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        while (state.keepRunning()) {
            os.reset();
            final FastDataOutput out = FastDataOutput.obtainUsing4ByteSequences(os);
            final FastDataOutput out = ArtFastDataOutput.obtain(os);
            try {
                doWrite(out);
                out.flush();
@@ -84,7 +84,7 @@ public class FastDataPerfTest {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        while (state.keepRunning()) {
            os.reset();
            final FastDataOutput out = FastDataOutput.obtainUsing3ByteSequences(os);
            final FastDataOutput out = FastDataOutput.obtain(os);
            try {
                doWrite(out);
                out.flush();
@@ -116,7 +116,7 @@ public class FastDataPerfTest {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        while (state.keepRunning()) {
            is.reset();
            final FastDataInput in = FastDataInput.obtainUsing4ByteSequences(is);
            final FastDataInput in = ArtFastDataInput.obtain(is);
            try {
                doRead(in);
            } finally {
@@ -131,7 +131,7 @@ public class FastDataPerfTest {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        while (state.keepRunning()) {
            is.reset();
            final FastDataInput in = FastDataInput.obtainUsing3ByteSequences(is);
            final FastDataInput in = FastDataInput.obtain(is);
            try {
                doRead(in);
            } finally {
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import android.os.Environment;
import android.util.AtomicFile;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.FastDataInput;
import com.android.internal.util.ArtFastDataInput;

import libcore.io.IoUtils;

@@ -254,7 +254,7 @@ public class NetworkStatsDataMigrationUtils {
    private static void readPlatformCollection(@NonNull NetworkStatsCollection.Builder builder,
            @NonNull File file) throws IOException {
        final FileInputStream is = new FileInputStream(file);
        final FastDataInput dataIn = new FastDataInput(is, BUFFER_SIZE);
        final ArtFastDataInput dataIn = new ArtFastDataInput(is, BUFFER_SIZE);
        try {
            readPlatformCollection(builder, dataIn);
        } finally {
+4 −3
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ import android.os.SystemProperties;
import android.system.ErrnoException;
import android.system.Os;

import com.android.internal.util.BinaryXmlPullParser;
import com.android.internal.util.ArtBinaryXmlPullParser;
import com.android.internal.util.ArtBinaryXmlSerializer;
import com.android.internal.util.BinaryXmlSerializer;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.XmlUtils;
@@ -146,7 +147,7 @@ public class Xml {
     * @hide
     */
    public static @NonNull TypedXmlPullParser newBinaryPullParser() {
        return new BinaryXmlPullParser();
        return new ArtBinaryXmlPullParser();
    }

    /**
@@ -225,7 +226,7 @@ public class Xml {
     * @hide
     */
    public static @NonNull TypedXmlSerializer newBinarySerializer() {
        return new BinaryXmlSerializer();
        return new ArtBinaryXmlSerializer();
    }

    /**
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util;

import android.annotation.NonNull;

import java.io.DataInput;
import java.io.InputStream;

/**
 * {@inheritDoc}
 * <p>
 * This decodes large code-points using 4-byte sequences, and <em>is not</em> compatible with the
 * {@link DataInput} API contract, which specifies that large code-points must be encoded with
 * 3-byte sequences.
 */
public class ArtBinaryXmlPullParser extends BinaryXmlPullParser {
    @NonNull
    protected FastDataInput obtainFastDataInput(@NonNull InputStream is) {
        return ArtFastDataInput.obtain(is);
    }
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util;

import android.annotation.NonNull;

import java.io.DataOutput;
import java.io.OutputStream;

/**
 * {@inheritDoc}
 * <p>
 * This encodes large code-points using 4-byte sequences and <em>is not</em> compatible with the
 * {@link DataOutput} API contract, which specifies that large code-points must be encoded with
 * 3-byte sequences.
 */
public class ArtBinaryXmlSerializer extends BinaryXmlSerializer {
    @NonNull
    @Override
    protected FastDataOutput obtainFastDataOutput(@NonNull OutputStream os) {
        return ArtFastDataOutput.obtain(os);
    }
}
Loading