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

Commit 9f3a6f32 authored by William Escande's avatar William Escande
Browse files

ErrorProne: Enforce & fix NonApiType

See https://errorprone.info/bugpattern/NonApiType

Bug: 344658662
Test: m BluetoothInstrumentationTests
Flag: Exempt Build and test only
Change-Id: Ic16352008f41b5ae2a30545e78ee2ea778837be8
parent 1694d818
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@ java_defaults {
            "-Xep:AlmostJavadoc:ERROR",
            "-Xep:AlmostJavadoc:ERROR",
            "-Xep:EmptyCatch:ERROR",
            "-Xep:EmptyCatch:ERROR",
            "-Xep:InvalidInlineTag:ERROR",
            "-Xep:InvalidInlineTag:ERROR",
            "-Xep:NonApiType:ERROR",
            "-Xep:UnnecessaryAssignment:ERROR",
            "-Xep:UnnecessaryAssignment:ERROR",
            "-Xep:UnnecessaryAsync:ERROR",
            "-Xep:UnnecessaryAsync:ERROR",
            "-Xep:UnusedMethod:ERROR",
            "-Xep:UnusedMethod:ERROR",
+3 −2
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import java.util.stream.IntStream;
@@ -304,8 +305,8 @@ public class TestUtils {
     * @return A {@link HashMap} of Bluetooth configs in the format: section -> key1 -> value1 ->
     * @return A {@link HashMap} of Bluetooth configs in the format: section -> key1 -> value1 ->
     *     key2 -> value2 Assume no empty section name, no duplicate keys in the same section
     *     key2 -> value2 Assume no empty section name, no duplicate keys in the same section
     */
     */
    public static HashMap<String, HashMap<String, String>> readAdapterConfig() {
    public static Map<String, Map<String, String>> readAdapterConfig() {
        HashMap<String, HashMap<String, String>> adapterConfig = new HashMap<>();
        Map<String, Map<String, String>> adapterConfig = new HashMap<>();
        try (BufferedReader reader =
        try (BufferedReader reader =
                new BufferedReader(new FileReader("/data/misc/bluedroid/bt_config.conf"))) {
                new BufferedReader(new FileReader("/data/misc/bluedroid/bt_config.conf"))) {
            String section = "";
            String section = "";
+2 −2
Original line number Original line Diff line number Diff line
@@ -73,7 +73,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.junit.MockitoRule;


import java.util.HashMap;
import java.util.Map;


@MediumTest
@MediumTest
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
@@ -116,7 +116,7 @@ public class AdapterServiceRestartTest {


    private PackageManager mMockPackageManager;
    private PackageManager mMockPackageManager;
    private MockContentResolver mMockContentResolver;
    private MockContentResolver mMockContentResolver;
    private HashMap<String, HashMap<String, String>> mAdapterConfig;
    private Map<String, Map<String, String>> mAdapterConfig;
    private int mForegroundUserId;
    private int mForegroundUserId;
    private TestLooper mLooper;
    private TestLooper mLooper;


+6 −6
Original line number Original line Diff line number Diff line
@@ -104,8 +104,8 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.security.InvalidKeyException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Map;


import javax.crypto.Mac;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.SecretKeySpec;
@@ -966,7 +966,7 @@ public class AdapterServiceTest {
    @Test
    @Test
    @Ignore("b/296127545: This is a native test")
    @Ignore("b/296127545: This is a native test")
    public void testObfuscateBluetoothAddress_BluetoothDisabled() {
    public void testObfuscateBluetoothAddress_BluetoothDisabled() {
        HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        Map<String, Map<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        assertThat(adapterConfig).isNotNull();
        assertThat(adapterConfig).isNotNull();


        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
@@ -986,7 +986,7 @@ public class AdapterServiceTest {
    @Test
    @Test
    @Ignore("b/296127545: This is a native test")
    @Ignore("b/296127545: This is a native test")
    public void testObfuscateBluetoothAddress_BluetoothEnabled() {
    public void testObfuscateBluetoothAddress_BluetoothEnabled() {
        HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        Map<String, Map<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        assertThat(adapterConfig).isNotNull();
        assertThat(adapterConfig).isNotNull();


        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
@@ -1005,7 +1005,7 @@ public class AdapterServiceTest {
    @Test
    @Test
    @Ignore("b/296127545: This is a native test")
    @Ignore("b/296127545: This is a native test")
    public void testObfuscateBluetoothAddress_PersistentBetweenToggle() {
    public void testObfuscateBluetoothAddress_PersistentBetweenToggle() {
        HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        Map<String, Map<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        assertThat(adapterConfig).isNotNull();
        assertThat(adapterConfig).isNotNull();


        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
@@ -1061,8 +1061,8 @@ public class AdapterServiceTest {
        assertThat(mAdapterService.getIdentityAddress(device.getAddress())).isNull();
        assertThat(mAdapterService.getIdentityAddress(device.getAddress())).isNull();
    }
    }


    public static byte[] getMetricsSalt(HashMap<String, HashMap<String, String>> adapterConfig) {
    public static byte[] getMetricsSalt(Map<String, Map<String, String>> adapterConfig) {
        HashMap<String, String> metricsSection = adapterConfig.get("Metrics");
        Map<String, String> metricsSection = adapterConfig.get("Metrics");
        if (metricsSection == null) {
        if (metricsSection == null) {
            Log.e(TAG, "Metrics section is null: " + adapterConfig.toString());
            Log.e(TAG, "Metrics section is null: " + adapterConfig.toString());
            return null;
            return null;
+2 −2
Original line number Original line Diff line number Diff line
@@ -157,7 +157,7 @@ public class MetricsLoggerTest {
        MetricsLogger.dumpProto(metricsBuilder);
        MetricsLogger.dumpProto(metricsBuilder);
        BluetoothLog metricsProto = metricsBuilder.build();
        BluetoothLog metricsProto = metricsBuilder.build();
        Assert.assertEquals(2, metricsProto.getProfileConnectionStatsCount());
        Assert.assertEquals(2, metricsProto.getProfileConnectionStatsCount());
        HashMap<ProfileId, ProfileConnectionStats> profileConnectionCountMap =
        Map<ProfileId, ProfileConnectionStats> profileConnectionCountMap =
                getProfileUsageStatsMap(metricsProto.getProfileConnectionStatsList());
                getProfileUsageStatsMap(metricsProto.getProfileConnectionStatsList());
        Assert.assertTrue(profileConnectionCountMap.containsKey(ProfileId.AVRCP));
        Assert.assertTrue(profileConnectionCountMap.containsKey(ProfileId.AVRCP));
        Assert.assertEquals(
        Assert.assertEquals(
@@ -172,7 +172,7 @@ public class MetricsLoggerTest {
        Assert.assertEquals(0, metricsProtoAfterDump.getProfileConnectionStatsCount());
        Assert.assertEquals(0, metricsProtoAfterDump.getProfileConnectionStatsCount());
    }
    }


    private static HashMap<ProfileId, ProfileConnectionStats> getProfileUsageStatsMap(
    private static Map<ProfileId, ProfileConnectionStats> getProfileUsageStatsMap(
            List<ProfileConnectionStats> profileUsageStats) {
            List<ProfileConnectionStats> profileUsageStats) {
        HashMap<ProfileId, ProfileConnectionStats> profileUsageStatsMap = new HashMap<>();
        HashMap<ProfileId, ProfileConnectionStats> profileUsageStatsMap = new HashMap<>();
        profileUsageStats.forEach(item -> profileUsageStatsMap.put(item.getProfileId(), item));
        profileUsageStats.forEach(item -> profileUsageStatsMap.put(item.getProfileId(), item));
Loading