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

Commit 3f97875b authored by Hieu Dang's avatar Hieu Dang Committed by Gerrit Code Review
Browse files

Merge "Show actions for incoming file notification"

parents 220dbdd5 bfdc7652
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -582,8 +582,6 @@ class BluetoothOppNotification {
                            true)
                            .setOngoing(true)
                            .setWhen(info.mTimeStamp)
                            .addAction(actionDecline)
                            .addAction(actionAccept)
                            .setContentIntent(PendingIntent.getBroadcast(mContext, 0,
                                    new Intent(baseIntent).setAction(
                                            Constants.ACTION_INCOMING_FILE_CONFIRM),
@@ -633,6 +631,8 @@ class BluetoothOppNotification {
                            .setSmallIcon(R.drawable.bt_incomming_file_notification)
                            .setLocalOnly(true)
                            .setVisibility(Notification.VISIBILITY_PRIVATE)
                            .addAction(actionDecline)
                            .addAction(actionAccept)
                            .setPublicVersion(public_n)
                            .build();
            mNotificationMgr.notify(NOTIFICATION_ID_PROGRESS, n);
+71 −32
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ import java.util.concurrent.TimeoutException;
public class TestUtils {
    private static final int SERVICE_TOGGLE_TIMEOUT_MS = 1000;    // 1s

    private static String sSystemScreenOffTimeout = "10000";

    /**
     * Utility method to replace obj.fieldName with newValue where obj is of type c
     *
@@ -91,7 +93,8 @@ public class TestUtils {
     * @throws NoSuchMethodException     when setAdapterService method is not found
     * @throws IllegalAccessException    when setAdapterService method cannot be accessed
     * @throws InvocationTargetException when setAdapterService method cannot be invoked, which
     * should never happen since setAdapterService is a static method
     *                                   should never happen since setAdapterService is a static
     *                                   method
     */
    public static void setAdapterService(AdapterService adapterService)
            throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
@@ -115,7 +118,8 @@ public class TestUtils {
     * @throws NoSuchMethodException     when clearAdapterService method is not found
     * @throws IllegalAccessException    when clearAdapterService method cannot be accessed
     * @throws InvocationTargetException when clearAdappterService method cannot be invoked,
     * which should never happen since clearAdapterService is a static method
     *                                   which should never happen since clearAdapterService is a
     *                                   static method
     */
    public static void clearAdapterService(AdapterService adapterService)
            throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
@@ -136,11 +140,14 @@ public class TestUtils {
     * {@link #setAdapterService(AdapterService)} must be called with a mocked
     * {@link AdapterService} before calling this method
     *
     * @param serviceTestRule the {@link ServiceTestRule} used to execute the service start request
     * @param serviceTestRule     the {@link ServiceTestRule} used to execute the service start
     *                            request
     * @param profileServiceClass a class from one of {@link ProfileService}'s child classes
     * @throws TimeoutException when service failed to start within either default timeout of
     * {@link ServiceTestRule#DEFAULT_TIMEOUT} (normally 5s) or user specified time when creating
     * {@link ServiceTestRule} through {@link ServiceTestRule#withTimeout(long, TimeUnit)} method
     *                          {@link ServiceTestRule#DEFAULT_TIMEOUT} (normally 5s) or user
     *                          specified time when creating
     *                          {@link ServiceTestRule} through
     *                          {@link ServiceTestRule#withTimeout(long, TimeUnit)} method
     */
    public static <T extends ProfileService> void startService(ServiceTestRule serviceTestRule,
            Class<T> profileServiceClass) throws TimeoutException {
@@ -167,11 +174,14 @@ public class TestUtils {
     * {@link #setAdapterService(AdapterService)} must be called with a mocked
     * {@link AdapterService} before calling this method
     *
     * @param serviceTestRule the {@link ServiceTestRule} used to execute the service start request
     * @param serviceTestRule     the {@link ServiceTestRule} used to execute the service start
     *                            request
     * @param profileServiceClass a class from one of {@link ProfileService}'s child classes
     * @throws TimeoutException when service failed to start within either default timeout of
     * {@link ServiceTestRule#DEFAULT_TIMEOUT} (normally 5s) or user specified time when creating
     * {@link ServiceTestRule} through {@link ServiceTestRule#withTimeout(long, TimeUnit)} method
     *                          {@link ServiceTestRule#DEFAULT_TIMEOUT} (normally 5s) or user
     *                          specified time when creating
     *                          {@link ServiceTestRule} through
     *                          {@link ServiceTestRule#withTimeout(long, TimeUnit)} method
     */
    public static <T extends ProfileService> void stopService(ServiceTestRule serviceTestRule,
            Class<T> profileServiceClass) throws TimeoutException {
@@ -190,8 +200,10 @@ public class TestUtils {
                profile.capture(), eq(BluetoothAdapter.STATE_OFF));
        Assert.assertEquals(profileServiceClass.getName(), profile.getValue().getClass().getName());
        ArgumentCaptor<ProfileService> profile2 = ArgumentCaptor.forClass(profileServiceClass);
        verify(adapterService, timeout(SERVICE_TOGGLE_TIMEOUT_MS)).removeProfile(profile2.capture());
        Assert.assertEquals(profileServiceClass.getName(), profile2.getValue().getClass().getName());
        verify(adapterService, timeout(SERVICE_TOGGLE_TIMEOUT_MS)).removeProfile(
                profile2.capture());
        Assert.assertEquals(profileServiceClass.getName(),
                profile2.getValue().getClass().getName());
    }

    /**
@@ -212,7 +224,8 @@ public class TestUtils {

    public static Resources getTestApplicationResources(Context context) {
        try {
            return context.getPackageManager().getResourcesForApplication("com.android.bluetooth.tests");
            return context.getPackageManager().getResourcesForApplication(
                    "com.android.bluetooth.tests");
        } catch (PackageManager.NameNotFoundException e) {
            assertWithMessage("Setup Failure: Unable to get test application resources"
                    + e.toString()).fail();
@@ -381,11 +394,37 @@ public class TestUtils {
        return intent;
    }

    public static void wakeUpAndDismissKeyGuard() throws Exception {
    public static void setUpUiTest() throws Exception {
        final UiDevice device = UiDevice.getInstance(
                androidx.test.platform.app.InstrumentationRegistry.getInstrumentation());
        // Turn on screen and unlock
        device.wakeUp();
        device.executeShellCommand("wm dismiss-keyguard");

        // Disable animation
        device.executeShellCommand("settings put global window_animation_scale 0.0");
        device.executeShellCommand("settings put global transition_animation_scale 0.0");
        device.executeShellCommand("settings put global animator_duration_scale 0.0");

        // change device screen_off_timeout
        sSystemScreenOffTimeout =
                device.executeShellCommand("settings get system screen_off_timeout");
        device.executeShellCommand("settings put system screen_off_timeout 30000");
    }

    public static void tearDownUiTest() throws Exception {
        final UiDevice device = UiDevice.getInstance(
                androidx.test.platform.app.InstrumentationRegistry.getInstrumentation());
        device.executeShellCommand("wm dismiss-keyguard");

        // Re-enable animation
        device.executeShellCommand("settings put global window_animation_scale 1.0");
        device.executeShellCommand("settings put global transition_animation_scale 1.0");
        device.executeShellCommand("settings put global animator_duration_scale 1.0");

        // restore screen_off_timeout
        device.executeShellCommand("settings put system screen_off_timeout "
                + sSystemScreenOffTimeout);
    }

    /**
+2 −3
Original line number Diff line number Diff line
@@ -38,9 +38,7 @@ import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -56,7 +54,7 @@ public class BluetoothMapSettingsTest {
    @Before
    public void setUp() throws Exception {
        enableActivity(true);
        TestUtils.wakeUpAndDismissKeyGuard();
        TestUtils.setUpUiTest();
        mIntent = new Intent();
        mIntent.setClass(mTargetContext, BluetoothMapSettings.class);
        mActivityScenario = ActivityScenario.launch(mIntent);
@@ -64,6 +62,7 @@ public class BluetoothMapSettingsTest {

    @After
    public void tearDown() throws Exception {
        TestUtils.tearDownUiTest();
        if (mActivityScenario != null) {
            // Workaround for b/159805732. Without this, test hangs for 45 seconds.
            Thread.sleep(1_000);
+3 −4
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

import java.io.IOException;

public class BluetoothOppBtEnableActivityTest {

    Intent mIntent;
@@ -57,11 +55,12 @@ public class BluetoothOppBtEnableActivityTest {
        mIntent.setClass(mTargetContext, BluetoothOppBtEnableActivity.class);
        Intents.init();
        BluetoothOppTestUtils.enableOppActivities(true, mTargetContext);
        TestUtils.wakeUpAndDismissKeyGuard();
        TestUtils.setUpUiTest();
    }

    @After
    public void tearDown() {
    public void tearDown() throws Exception {
        TestUtils.tearDownUiTest();
        Intents.release();
        BluetoothOppTestUtils.enableOppActivities(false, mTargetContext);
    }
+3 −2
Original line number Diff line number Diff line
@@ -75,11 +75,12 @@ public class BluetoothOppBtEnablingActivityTest {

        mRealTimeoutValue = BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs;
        BluetoothOppTestUtils.enableOppActivities(true, mTargetContext);
        TestUtils.wakeUpAndDismissKeyGuard();
        TestUtils.setUpUiTest();
    }

    @After
    public void tearDown() {
    public void tearDown() throws Exception {
        TestUtils.tearDownUiTest();
        BluetoothMethodProxy.setInstanceForTesting(null);
        BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs = mRealTimeoutValue;
        BluetoothOppTestUtils.enableOppActivities(false, mTargetContext);
Loading