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

Commit 57a4a21f authored by William Escande's avatar William Escande
Browse files

Fix Map test with wrong dependency to hidden api

Context:
The BluetoothInstrumentationTests is not setup with correct rules.
It should not use reference to jarjar name and instead should jarjar the
code directly. To do so we need to change the following:
* Link against a non jarjared bluetooth app
* use fwk-bluetooth-pre-jarjar instead of the .impl

This CL:
FastXmlSerializer is no longer used in Bluetooth since aosp/1799788 (see
it for justification on why). We now need to remove the dependency from
test as this will not build once we start using jarjaring (or we will
need to add another static dependency to the test)

Test: atest BluetoothInstrumentationTests
Bug: 223837004
Change-Id: I71ead70dff14a5916c5fe64c67c7ad99697b50ef
parent 52e7d78e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -226,8 +226,7 @@ public class BluetoothMapConvoListingElement
    private String getSummary() {
        if (mSummary != null) {
            try {
                return new String(BluetoothMapUtils.truncateUtf8StringToBytearray(mSummary, 256),
                        "UTF-8");
                return BluetoothMapUtils.truncateUtf8StringToString(mSummary, 256);
            } catch (UnsupportedEncodingException e) {
                // This cannot happen on an Android platform - UTF-8 is mandatory
                Log.e(TAG, "Missing UTF-8 support on platform", e);
+31 −0
Original line number Diff line number Diff line
@@ -22,8 +22,13 @@ import com.android.bluetooth.mapapi.BluetoothMapContract;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.BitSet;
@@ -447,6 +452,32 @@ public class BluetoothMapUtils {
        return utf8Bytes;
    }

    /**
     * Truncate UTF-8 string encoded to desired length
     * @param utf8InString String to truncate
     * @param maxBytesLength Max length in bytes of the returned string
     * @return A valid truncated utf-8 string
     * @throws UnsupportedEncodingException
     */
    public static String truncateUtf8StringToString(String utf8InString, int maxBytesLength)
            throws UnsupportedEncodingException {
        Charset charset = StandardCharsets.UTF_8;
        final byte[] utf8InBytes = utf8InString.getBytes(charset);
        if (utf8InBytes.length <= maxBytesLength) {
            return utf8InString;
        }
        // Create a buffer that wildly truncate at desired lengtht.
        // It may contain invalid utf-8 char.
        ByteBuffer truncatedString = ByteBuffer.wrap(utf8InBytes, 0, maxBytesLength);
        CharBuffer validUtf8Buffer = CharBuffer.allocate(maxBytesLength);
        // Decode From the truncatedString into a valid Utf8 CharBuffer while ignoring(discarding)
        // any invalid utf-8
        CharsetDecoder decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.IGNORE);
        decoder.decode(truncatedString, validUtf8Buffer, true);
        decoder.flush(validUtf8Buffer);
        return new String(validUtf8Buffer.array(), 0, validUtf8Buffer.position());
    }

    private static final Pattern PATTERN = Pattern.compile("=\\?(.+?)\\?(.)\\?(.+?(?=\\?=))\\?=");

    /**
+3 −2
Original line number Diff line number Diff line
@@ -20,10 +20,11 @@ import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.util.Xml;

import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.SignedLongLong;
import com.android.internal.util.FastXmlSerializer;

import org.junit.Before;
import org.junit.Test;
@@ -124,7 +125,7 @@ public class BluetoothMapConvoContactElementTest {
                TEST_PRESENCE_STATUS, TEST_PRESENCE_AVAILABILITY, TEST_LAST_ACTIVITY,
                TEST_CHAT_STATE, TEST_PRIORITY, TEST_BT_UID);

        final XmlSerializer serializer = new FastXmlSerializer();
        final XmlSerializer serializer = Xml.newSerializer();
        final StringWriter writer = new StringWriter();

        serializer.setOutput(writer);
+3 −2
Original line number Diff line number Diff line
@@ -18,11 +18,12 @@ package com.android.bluetooth.map;

import static com.google.common.truth.Truth.assertThat;

import android.util.Xml;

import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.SignedLongLong;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.internal.util.FastXmlSerializer;

import org.junit.Before;
import org.junit.Test;
@@ -120,7 +121,7 @@ public class BluetoothMapConvoListingElementTest {

    @Test
    public void encodeToXml_thenDecodeToInstance_returnsCorrectly() throws Exception {
        final XmlSerializer serializer = new FastXmlSerializer();
        final XmlSerializer serializer = Xml.newSerializer();
        final StringWriter writer = new StringWriter();

        serializer.setOutput(writer);
+3 −2
Original line number Diff line number Diff line
@@ -18,10 +18,11 @@ package com.android.bluetooth.map;

import static com.google.common.truth.Truth.assertThat;

import android.util.Xml;

import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.internal.util.FastXmlSerializer;

import org.junit.Before;
import org.junit.Test;
@@ -131,7 +132,7 @@ public class BluetoothMapMessageListingElementTest {
    public void encode() throws Exception {
        mMessageListingElement.setSubject(null);

        final XmlSerializer serializer = new FastXmlSerializer();
        final XmlSerializer serializer = Xml.newSerializer();
        final StringWriter writer = new StringWriter();

        serializer.setOutput(writer);