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

Commit 1e47e532 authored by Rahul Sabnis's avatar Rahul Sabnis Committed by Automerger Merge Worker
Browse files

Merge changes from topic "re-enable-bt-instrumentation-tests" into tm-dev am: 27c96eb1

parents f9686eaf 27c96eb1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -322,6 +322,11 @@ public final class Utils {
    }

    static int sForegroundUserId = USER_HANDLE_NULL.getIdentifier();

    public static int getForegroundUserId() {
        return Utils.sForegroundUserId;
    }

    public static void setForegroundUserId(int userId) {
        Utils.sForegroundUserId = userId;
    }
+1 −3
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ import android.bluetooth.UidTraffic;
import android.companion.CompanionDeviceManager;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -3715,8 +3714,7 @@ public class AdapterService extends Service {
        @Override
        public void setForegroundUserId(int userId, AttributionSource attributionSource) {
            AdapterService service = getService();
            if (service == null || !callerIsSystemOrActiveUser(TAG, "setForegroundUserId")
                    || !Utils.checkConnectPermissionForDataDelivery(
            if (service == null || !Utils.checkConnectPermissionForDataDelivery(
                    service, Utils.getCallingAttributionSource(mService),
                    "AdapterService setForegroundUserId")) {
                return;
+21 −0
Original line number Diff line number Diff line
@@ -15,15 +15,21 @@
 */
package com.android.bluetooth;

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

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.Process;

import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;
@@ -198,6 +204,21 @@ public class TestUtils {
        return testDevice;
    }

    public static Resources getTestApplicationResources(Context context) {
        for (String name: context.getPackageManager().getPackagesForUid(Process.BLUETOOTH_UID)) {
            if (name.contains(".android.bluetooth.tests")) {
                try {
                    return context.getPackageManager().getResourcesForApplication(name);
                } catch (PackageManager.NameNotFoundException e) {
                    assertWithMessage("Setup Failure: Unable to get test application resources"
                            + e.toString()).fail();
                }
            }
        }
        assertWithMessage("Could not find tests package").fail();
        return null;
    }

    /**
     * Wait and verify that an intent has been received.
     *
+2 −6
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;

import org.junit.After;
import org.junit.Assert;
@@ -94,12 +95,7 @@ public class BrowserPlayerWrapperTest {
        MockitoAnnotations.initMocks(this);

        mTargetContext = InstrumentationRegistry.getTargetContext();
        try {
            mTestResources = mTargetContext.getPackageManager()
                    .getResourcesForApplication("com.android.bluetooth.tests");
        } catch (PackageManager.NameNotFoundException e) {
            Assert.fail("Setup Failure Unable to get resources" + e.toString());
        }
        mTestResources = TestUtils.getTestApplicationResources(mTargetContext);

        mTestBitmap = loadImage(com.android.bluetooth.tests.R.raw.image_200_200);

+2 −6
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;

import org.junit.After;
import org.junit.Before;
@@ -82,12 +83,7 @@ public class ImageTest {
        MockitoAnnotations.initMocks(this);

        mTargetContext = InstrumentationRegistry.getTargetContext();
        try {
            mTestResources = mTargetContext.getPackageManager()
                    .getResourcesForApplication("com.android.bluetooth.tests");
        } catch (PackageManager.NameNotFoundException e) {
            assertWithMessage("Setup Failure Unable to get resources" + e.toString()).fail();
        }
        mTestResources = TestUtils.getTestApplicationResources(mTargetContext);

        mTestBitmap = loadImage(com.android.bluetooth.tests.R.raw.image_200_200);

Loading