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

Commit d25f1cfe 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
(cherry picked from commit 8ce512be)
Merged-In: I973315eebc347049d8cfe6b62582a1bcb8805b4d
parent 46e00181
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@ public class AdapterServiceTest {
        AsyncTask.setDefaultExecutor((r) -> {
            InstrumentationRegistry.getInstrumentation().runOnMainSync(r);
        });
        InstrumentationRegistry.getInstrumentation().getUiAutomation()
                .adoptShellPermissionIdentity();

        InstrumentationRegistry.getInstrumentation().runOnMainSync(
                () -> mAdapterService = new AdapterService());
@@ -238,6 +240,8 @@ public class AdapterServiceTest {
        mPermissionManager = InstrumentationRegistry.getTargetContext()
                .getSystemService(PermissionManager.class);

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

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

        MockitoAnnotations.initMocks(this);

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

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

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

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

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

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

import androidx.test.InstrumentationRegistry;

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

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

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

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

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