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

Commit 8ce512be authored by William Escande's avatar William Escande
Browse files

Fix BluetoothInstrumentationTests

Sqlite update is now crashing whent getCacheDir is returning null (issue
on mocked context)
Use uiautomation permission for passing tests involving MANAGE_USER
(despite the fact we shouldn't need it)

Test: atest BluetoothInstrumentationTests
Fix: 254325296
Change-Id: I973315eebc347049d8cfe6b62582a1bcb8805b4d
parent bd08758a
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -216,6 +216,8 @@ public class AdapterServiceTest {
        AsyncTask.setDefaultExecutor((r) -> {
        AsyncTask.setDefaultExecutor((r) -> {
            InstrumentationRegistry.getInstrumentation().runOnMainSync(r);
            InstrumentationRegistry.getInstrumentation().runOnMainSync(r);
        });
        });
        InstrumentationRegistry.getInstrumentation().getUiAutomation()
                .adoptShellPermissionIdentity();


        InstrumentationRegistry.getInstrumentation().runOnMainSync(
        InstrumentationRegistry.getInstrumentation().runOnMainSync(
                () -> mAdapterService = new AdapterService());
                () -> mAdapterService = new AdapterService());
@@ -243,6 +245,8 @@ public class AdapterServiceTest {
        mBluetoothManager = InstrumentationRegistry.getTargetContext()
        mBluetoothManager = InstrumentationRegistry.getTargetContext()
                .getSystemService(BluetoothManager.class);
                .getSystemService(BluetoothManager.class);


        when(mMockContext.getCacheDir()).thenReturn(InstrumentationRegistry.getTargetContext()
                .getCacheDir());
        when(mMockContext.getApplicationInfo()).thenReturn(mMockApplicationInfo);
        when(mMockContext.getApplicationInfo()).thenReturn(mMockApplicationInfo);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
+2 −0
Original line number Original line Diff line number Diff line
@@ -108,6 +108,8 @@ public class TbsGattTest {
            Looper.prepare();
            Looper.prepare();
        }
        }


        getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();

        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);


        TestUtils.setAdapterService(mAdapterService);
        TestUtils.setAdapterService(mAdapterService);
+2 −0
Original line number Original line Diff line number Diff line
@@ -82,6 +82,8 @@ public class TbsGenericTest {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mContext = getInstrumentation().getTargetContext();
        mContext = getInstrumentation().getTargetContext();


        getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();

        // Default TbsGatt mock behavior
        // Default TbsGatt mock behavior
        doReturn(true).when(mTbsGatt).init(mGtbsCcidCaptor.capture(), mGtbsUciCaptor.capture(),
        doReturn(true).when(mTbsGatt).init(mGtbsCcidCaptor.capture(), mGtbsUciCaptor.capture(),
                mDefaultGtbsUriSchemesCaptor.capture(), anyBoolean(), anyBoolean(),
                mDefaultGtbsUriSchemesCaptor.capture(), anyBoolean(), anyBoolean(),
+2 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.Log;


import androidx.test.core.app.ApplicationProvider;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.filters.MediumTest;
import androidx.test.rule.ServiceTestRule;
import androidx.test.rule.ServiceTestRule;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;
@@ -120,6 +121,7 @@ public class BluetoothInCallServiceTest {
    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);
        InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();


        // Create the service Intent.
        // Create the service Intent.
        Intent serviceIntent =
        Intent serviceIntent =
+8 −0
Original line number Original line Diff line number Diff line
@@ -18,8 +18,11 @@ package com.android.bluetooth.util;


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


import androidx.test.InstrumentationRegistry;

import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.uicc.IccUtils;


import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.JUnit4;
@@ -29,6 +32,11 @@ public final class GsmAlphabetTest {


  private static final String GSM_EXTENDED_CHARS = "{|}\\[~]\f\u20ac";
  private static final String GSM_EXTENDED_CHARS = "{|}\\[~]\f\u20ac";


  @Before
  public void setUp() throws Exception {
    InstrumentationRegistry.getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();
  }

  @Test
  @Test
  public void gsm7BitPackedToString() throws Exception {
  public void gsm7BitPackedToString() throws Exception {
    byte[] packed;
    byte[] packed;
Loading