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

Commit f1476845 authored by William Escande's avatar William Escande Committed by Cherrypicker Worker
Browse files

Adapter test fix: Recreate config after factory reset

Obfuscate test expect a config to be present, but gd will delete the
config if there is no 'Adapter' section.
Enabling bt at the end of the test is the easier way to create this
config

Fix: 267528843
Test: atest BluetoothInstrumentationTests:com.android.bluetooth.btservice
Change-Id: I34f570fa1e18b8674e090c7809e68dab6eafa312
(cherry picked from commit 3ee70109)
Merged-In: I34f570fa1e18b8674e090c7809e68dab6eafa312
parent 03077e74
Loading
Loading
Loading
Loading
+9 −6
Original line number Original line Diff line number Diff line
@@ -145,7 +145,7 @@ public class AdapterServiceFactoryResetTest {
    private int mForegroundUserId;
    private int mForegroundUserId;


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


    @BeforeClass
    @BeforeClass
    public static void setupClass() {
    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
        // Bring native layer up and down to make sure config files are properly loaded
        if (Looper.myLooper() == null) {
        if (Looper.myLooper() == null) {
            Looper.prepare();
            Looper.prepare();
@@ -194,7 +194,7 @@ public class AdapterServiceFactoryResetTest {


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


    @After
    @After
    public void tearDown() {
    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
        // Restores the foregroundUserId to the ID prior to the test setup
        Utils.setForegroundUserId(mForegroundUserId);
        Utils.setForegroundUserId(mForegroundUserId);
@@ -351,7 +354,7 @@ public class AdapterServiceFactoryResetTest {
    }
    }


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


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


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


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


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


    @BeforeClass
    @BeforeClass
    public static void setupClass() {
    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
        // Bring native layer up and down to make sure config files are properly loaded
        if (Looper.myLooper() == null) {
        if (Looper.myLooper() == null) {
            Looper.prepare();
            Looper.prepare();
@@ -180,7 +180,7 @@ public class AdapterServiceRestartTest {


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


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


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

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

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