Loading android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java +2 −2 Original line number Diff line number Diff line Loading @@ -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), Loading Loading @@ -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); Loading android/app/tests/unit/src/com/android/bluetooth/TestUtils.java +71 −32 Original line number Diff line number Diff line Loading @@ -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 * Loading Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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()); } /** Loading @@ -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(); Loading Loading @@ -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); } /** Loading android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSettingsTest.java +2 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading @@ -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); Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java +3 −4 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); } Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -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 Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java +2 −2 Original line number Diff line number Diff line Loading @@ -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), Loading Loading @@ -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); Loading
android/app/tests/unit/src/com/android/bluetooth/TestUtils.java +71 −32 Original line number Diff line number Diff line Loading @@ -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 * Loading Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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()); } /** Loading @@ -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(); Loading Loading @@ -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); } /** Loading
android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapSettingsTest.java +2 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading @@ -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); Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java +3 −4 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); } Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -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