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

Commit ec7bf15a authored by William Escande's avatar William Escande Committed by Android (Google) Code Review
Browse files

Merge "Adapter test fix: Recreate config after factory reset" into tm-qpr-dev

parents bc4e4763 f1476845
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ public class AdapterServiceFactoryResetTest {
    private int mForegroundUserId;

    private void configureEnabledProfiles() {
        Log.e("AdapterServiceTest", "configureEnabledProfiles");
        Log.e(TAG, "configureEnabledProfiles");
        Config.setProfileEnabled(PanService.class, true);
        Config.setProfileEnabled(BluetoothPbapService.class, true);
        Config.setProfileEnabled(GattService.class, true);
@@ -176,7 +176,7 @@ public class AdapterServiceFactoryResetTest {

    @BeforeClass
    public static void setupClass() {
        Log.e("AdapterServiceTest", "setupClass");
        Log.e(TAG, "setupClass");
        // Bring native layer up and down to make sure config files are properly loaded
        if (Looper.myLooper() == null) {
            Looper.prepare();
@@ -194,7 +194,7 @@ public class AdapterServiceFactoryResetTest {

    @Before
    public void setUp() throws PackageManager.NameNotFoundException {
        Log.e("AdapterServiceTest", "setUp()");
        Log.e(TAG, "setUp()");
        MockitoAnnotations.initMocks(this);
        if (Looper.myLooper() == null) {
            Looper.prepare();
@@ -327,7 +327,10 @@ public class AdapterServiceFactoryResetTest {

    @After
    public void tearDown() {
        Log.e("AdapterServiceTest", "tearDown()");
        Log.e(TAG, "tearDown()");

        // Enable the stack to re-create the config. Next tests rely on it.
        doEnable(0, false);

        // Restores the foregroundUserId to the ID prior to the test setup
        Utils.setForegroundUserId(mForegroundUserId);
@@ -351,7 +354,7 @@ public class AdapterServiceFactoryResetTest {
    }

    private void doEnable(int invocationNumber, boolean onlyGatt) {
        Log.e("AdapterServiceTest", "doEnable() start");
        Log.e(TAG, "doEnable() start");
        Assert.assertFalse(mAdapterService.getState() == BluetoothAdapter.STATE_ON);

        int startServiceCalls;
@@ -398,7 +401,7 @@ public class AdapterServiceFactoryResetTest {
                || scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
        Assert.assertTrue(mAdapterService.getState() == BluetoothAdapter.STATE_ON);

        Log.e("AdapterServiceTest", "doEnable() complete success");
        Log.e(TAG, "doEnable() complete success");
    }

    /**
+9 −4
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class AdapterServiceRestartTest {
    private int mForegroundUserId;

    private void configureEnabledProfiles() {
        Log.e("AdapterServiceTest", "configureEnabledProfiles");
        Log.e(TAG, "configureEnabledProfiles");
        Config.setProfileEnabled(PanService.class, true);
        Config.setProfileEnabled(BluetoothPbapService.class, true);
        Config.setProfileEnabled(GattService.class, true);
@@ -162,7 +162,7 @@ public class AdapterServiceRestartTest {

    @BeforeClass
    public static void setupClass() {
        Log.e("AdapterServiceTest", "setupClass");
        Log.e(TAG, "setupClass");
        // Bring native layer up and down to make sure config files are properly loaded
        if (Looper.myLooper() == null) {
            Looper.prepare();
@@ -180,7 +180,7 @@ public class AdapterServiceRestartTest {

    @Before
    public void setUp() throws PackageManager.NameNotFoundException {
        Log.e("AdapterServiceTest", "setUp()");
        Log.e(TAG, "setUp()");
        MockitoAnnotations.initMocks(this);
        if (Looper.myLooper() == null) {
            Looper.prepare();
@@ -309,7 +309,7 @@ public class AdapterServiceRestartTest {

    @After
    public void tearDown() {
        Log.e("AdapterServiceTest", "tearDown()");
        Log.e(TAG, "tearDown()");

        // Restores the foregroundUserId to the ID prior to the test setup
        Utils.setForegroundUserId(mForegroundUserId);
@@ -341,6 +341,11 @@ public class AdapterServiceRestartTest {
                obfuscatedAddress1);
        tearDown();
        setUp();

        byte[] metricsSalt2 = AdapterServiceTest.getMetricsSalt(mAdapterConfig);
        Assert.assertNotNull(metricsSalt2);
        Assert.assertArrayEquals(metricsSalt, metricsSalt2);

        Assert.assertFalse(mAdapterService.getState() == BluetoothAdapter.STATE_ON);
        byte[] obfuscatedAddress2 = mAdapterService.obfuscateAddress(device);
        Assert.assertTrue(obfuscatedAddress2.length > 0);
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ static void read_or_set_metrics_salt() {
    metrics_salt.fill(0);
  }
  if (!AddressObfuscator::IsSaltValid(metrics_salt)) {
    LOG(INFO) << __func__ << ": Metrics salt is not invalid, creating new one";
    LOG(INFO) << __func__ << ": Metrics salt is invalid, creating new one";
    if (RAND_bytes(metrics_salt.data(), metrics_salt.size()) != 1) {
      LOG(FATAL) << __func__ << "Failed to generate salt for metrics";
    }