updates = new ArrayList<>();
- for (ShortcutInfo info : sm.getPinnedShortcuts()) {
- if (!info.getId().startsWith(SHORTCUT_ID_PREFIX)) {
- continue;
- }
- ComponentName cn = ComponentName.unflattenFromString(
- info.getId().substring(SHORTCUT_ID_PREFIX.length()));
- ResolveInfo ri = pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
- if (ri == null) {
- continue;
- }
- updates.add(new ShortcutInfo.Builder(mContext, info.getId())
- .setShortLabel(ri.loadLabel(pm)).build());
- }
- if (!updates.isEmpty()) {
- sm.updateShortcuts(updates);
- }
- return null;
- }
-}
diff --git a/src/com/android/settings/shortcut/ShortcutsUpdater.java b/src/com/android/settings/shortcut/ShortcutsUpdater.java
new file mode 100644
index 00000000000..90a60fda379
--- /dev/null
+++ b/src/com/android/settings/shortcut/ShortcutsUpdater.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.shortcut;
+
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_ID_PREFIX;
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_PROBE;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import android.app.Flags;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutManager;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.settings.Settings;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ShortcutsUpdater {
+
+ /**
+ * Update label, icon, and intent of pinned shortcuts to Settings subpages.
+ *
+ * Should be called whenever any of those could have changed, such as after changing locale,
+ * restoring a backup from a different device, or when flags controlling available features
+ * may have flipped.
+ */
+ public static void updatePinnedShortcuts(Context context) {
+ ShortcutManager sm = checkNotNull(context.getSystemService(ShortcutManager.class));
+
+ List updates = new ArrayList<>();
+ for (ShortcutInfo info : sm.getPinnedShortcuts()) {
+ ResolveInfo resolvedActivity = resolveActivity(context, info);
+ if (resolvedActivity != null) {
+ // Id is preserved to update an existing shortcut, but the activity it opens might
+ // be different, according to maybeGetReplacingComponent.
+ updates.add(Shortcuts.createShortcutInfo(context, info.getId(), resolvedActivity));
+ }
+ }
+ if (!updates.isEmpty()) {
+ sm.updateShortcuts(updates);
+ }
+ }
+
+ @Nullable
+ private static ResolveInfo resolveActivity(Context context, ShortcutInfo shortcut) {
+ if (!shortcut.getId().startsWith(SHORTCUT_ID_PREFIX)) {
+ return null;
+ }
+
+ ComponentName cn = ComponentName.unflattenFromString(
+ shortcut.getId().substring(SHORTCUT_ID_PREFIX.length()));
+ if (cn == null) {
+ return null;
+ }
+
+ // Check if the componentName is obsolete and has been replaced by a different one.
+ cn = maybeGetReplacingComponent(context, cn);
+ PackageManager pm = context.getPackageManager();
+ return pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
+ }
+
+ @NonNull
+ private static ComponentName maybeGetReplacingComponent(Context context, ComponentName cn) {
+ // ZenModeSettingsActivity is replaced by ModesSettingsActivity and will be deleted
+ // soon (so we shouldn't use ZenModeSettingsActivity.class).
+ if (Flags.modesApi() && Flags.modesUi()
+ && cn.getClassName().endsWith("Settings$ZenModeSettingsActivity")) {
+ return new ComponentName(context, Settings.ModesSettingsActivity.class);
+ }
+
+ return cn;
+ }
+}
diff --git a/src/com/android/settings/spa/network/SimsSection.kt b/src/com/android/settings/spa/network/SimsSection.kt
index 276d121c24f..bd55b32a5e8 100644
--- a/src/com/android/settings/spa/network/SimsSection.kt
+++ b/src/com/android/settings/spa/network/SimsSection.kt
@@ -137,7 +137,7 @@ private fun AddSim() {
}
}
-private fun startAddSimFlow(context: Context) {
+fun startAddSimFlow(context: Context) {
val intent = Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION)
intent.setPackage(Utils.PHONE_PACKAGE_NAME)
intent.putExtra(EuiccManager.EXTRA_FORCE_PROVISION, true)
diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
index 14ef4833588..00bd0f23cdc 100644
--- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
+++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
@@ -41,19 +41,20 @@ public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase imp
private static final String WALLPAPER_FOCUS = "focus_wallpaper";
private static final String WALLPAPER_ONLY = "wallpaper_only";
private static final String LAUNCHED_SUW = "app_launched_suw";
-
- private String mWallpaperLaunchExtra;
+ private static final String LAUNCH_SOURCE_SETTINGS_SEARCH = "app_launched_settings_search";
@Override
protected void addExtras(Intent intent) {
+ String wallpaperLaunchExtra =
+ getResources().getString(R.string.config_wallpaper_picker_launch_extra);;
if (WizardManagerHelper.isAnySetupWizard(intent)) {
intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_ONLY);
-
- mWallpaperLaunchExtra =
- getResources().getString(R.string.config_wallpaper_picker_launch_extra);
- intent.putExtra(mWallpaperLaunchExtra, LAUNCHED_SUW);
+ intent.putExtra(wallpaperLaunchExtra, LAUNCHED_SUW);
} else {
+ // This is the case when user enter the wallpaper picker from the search result entry
+ // on the Settings app
intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
+ intent.putExtra(wallpaperLaunchExtra, LAUNCH_SOURCE_SETTINGS_SEARCH);
}
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBaseTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBaseTest.java
index 40f7895d8dc..e326c1e2630 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBaseTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBaseTest.java
@@ -16,52 +16,80 @@
package com.android.settings.bluetooth;
+import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE;
+import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_PAIR_AND_JOIN_SHARING;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
+import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
+import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Looper;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.util.Pair;
+import android.widget.TextView;
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
import androidx.test.core.app.ApplicationProvider;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.flags.Flags;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
+import java.util.concurrent.Executor;
+
/** Tests for {@link BluetoothDevicePairingDetailBase}. */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowBluetoothAdapter.class,
+ ShadowAlertDialogCompat.class,
com.android.settings.testutils.shadow.ShadowFragment.class,
})
public class BluetoothDevicePairingDetailBaseTest {
@Rule
- public final MockitoRule mockito = MockitoJUnit.rule();
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
public static final String KEY_DEVICE_LIST_GROUP = "test_key";
@@ -86,8 +114,12 @@ public class BluetoothDevicePairingDetailBaseTest {
@Before
public void setUp() {
mAvailableDevicesCategory = spy(new BluetoothProgressCategory(mContext));
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mBluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
+ mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
+ BluetoothStatusCodes.FEATURE_SUPPORTED);
+ mShadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
+ BluetoothStatusCodes.FEATURE_SUPPORTED);
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
final Pair pairs = new Pair<>(mDrawable, "fake_device");
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
@@ -155,8 +187,88 @@ public class BluetoothDevicePairingDetailBaseTest {
verify(mFragment).showBluetoothTurnedOnToast();
}
+ @Test
+ public void onDeviceBondStateChanged_bonded_pairAndJoinSharingDisabled_finish() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ setUpFragmentWithPairAndJoinSharingIntent(false);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDED);
+
+ verify(mFragment).finish();
+ }
+
+ @Test
+ public void onDeviceBondStateChanged_bonded_pairAndJoinSharingEnabled_handle() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ setUpFragmentWithPairAndJoinSharingIntent(true);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDED);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
+ assertThat(dialog).isNotNull();
+ TextView message = dialog.findViewById(R.id.message);
+ assertThat(message).isNotNull();
+ // TODO: use stringr res once finalized
+ assertThat(message.getText().toString()).isEqualTo(
+ "Connecting to " + TEST_DEVICE_ADDRESS + "...");
+ verify(mFragment, never()).finish();
+ }
+
+ @Test
+ public void onDeviceBondStateChanged_bonding_pairAndJoinSharingDisabled_doNothing() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ setUpFragmentWithPairAndJoinSharingIntent(false);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDING);
+
+ verify(mBluetoothAdapter, never()).addOnMetadataChangedListener(any(BluetoothDevice.class),
+ any(Executor.class), any(BluetoothAdapter.OnMetadataChangedListener.class));
+ }
+
+ @Test
+ public void onDeviceBondStateChanged_bonding_pairAndJoinSharingEnabled_addListener() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ setUpFragmentWithPairAndJoinSharingIntent(true);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDING);
+
+ verify(mBluetoothAdapter).addOnMetadataChangedListener(eq(mBluetoothDevice),
+ any(Executor.class),
+ any(BluetoothAdapter.OnMetadataChangedListener.class));
+ }
+
+ @Test
+ public void onDeviceBondStateChanged_unbonded_pairAndJoinSharingDisabled_doNothing() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_NONE);
+
+ verify(mBluetoothAdapter, never()).removeOnMetadataChangedListener(
+ any(BluetoothDevice.class), any(BluetoothAdapter.OnMetadataChangedListener.class));
+ }
+
+ @Test
+ public void onDeviceBondStateChanged_unbonded_pairAndJoinSharingEnabled_removeListener() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ setUpFragmentWithPairAndJoinSharingIntent(true);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDING);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_NONE);
+
+ verify(mBluetoothAdapter).removeOnMetadataChangedListener(eq(mBluetoothDevice),
+ any(BluetoothAdapter.OnMetadataChangedListener.class));
+ }
+
@Test
public void onProfileConnectionStateChanged_deviceInSelectedListAndConnected_finish() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
mFragment.mSelectedList.add(mBluetoothDevice);
mFragment.mSelectedList.add(device);
@@ -165,13 +277,43 @@ public class BluetoothDevicePairingDetailBaseTest {
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
+ BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mFragment).finish();
}
+ @Test
+ public void
+ onProfileConnectionStateChanged_deviceInSelectedListAndConnected_pairAndJoinSharing() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ mFragment.mSelectedList.add(mBluetoothDevice);
+ setUpFragmentWithPairAndJoinSharingIntent(true);
+ mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDED);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
+
+ mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ ArgumentCaptor captor = ArgumentCaptor.forClass(Intent.class);
+ verify(mFragment.getActivity()).setResult(eq(Activity.RESULT_OK), captor.capture());
+ Intent intent = captor.getValue();
+ BluetoothDevice btDevice =
+ intent != null
+ ? intent.getParcelableExtra(EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE,
+ BluetoothDevice.class)
+ : null;
+ assertThat(btDevice).isNotNull();
+ assertThat(btDevice).isEqualTo(mBluetoothDevice);
+ verify(mFragment).finish();
+ }
+
@Test
public void onProfileConnectionStateChanged_deviceNotInSelectedList_doNothing() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
mFragment.mSelectedList.add(device);
@@ -179,13 +321,14 @@ public class BluetoothDevicePairingDetailBaseTest {
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
+ BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.A2DP);
// not crash
}
@Test
public void onProfileConnectionStateChanged_deviceDisconnected_doNothing() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
mFragment.mSelectedList.add(mBluetoothDevice);
mFragment.mSelectedList.add(device);
@@ -194,13 +337,14 @@ public class BluetoothDevicePairingDetailBaseTest {
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothProfile.A2DP, BluetoothAdapter.STATE_DISCONNECTED);
+ BluetoothAdapter.STATE_DISCONNECTED, BluetoothProfile.A2DP);
// not crash
}
@Test
public void onProfileConnectionStateChanged_deviceInPreferenceMapAndConnected_removed() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
final BluetoothDevicePreference preference =
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
@@ -211,13 +355,14 @@ public class BluetoothDevicePairingDetailBaseTest {
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
+ BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.A2DP);
assertThat(mFragment.getDevicePreferenceMap().size()).isEqualTo(0);
}
@Test
public void onProfileConnectionStateChanged_deviceNotInPreferenceMap_doNothing() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
final BluetoothDevicePreference preference =
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
@@ -233,12 +378,26 @@ public class BluetoothDevicePairingDetailBaseTest {
when(cachedDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
when(cachedDevice.getIdentityAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
- mFragment.onProfileConnectionStateChanged(cachedDevice, BluetoothProfile.A2DP,
- BluetoothAdapter.STATE_CONNECTED);
+ mFragment.onProfileConnectionStateChanged(cachedDevice, BluetoothAdapter.STATE_CONNECTED,
+ BluetoothProfile.A2DP);
// not crash
}
+ private void setUpFragmentWithPairAndJoinSharingIntent(boolean enablePairAndJoinSharing) {
+ Bundle args = new Bundle();
+ args.putBoolean(EXTRA_PAIR_AND_JOIN_SHARING, enablePairAndJoinSharing);
+ Intent intent = new Intent();
+ intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
+ FragmentActivity activity = spy(Robolectric.setupActivity(FragmentActivity.class));
+ doReturn(intent).when(activity).getIntent();
+ doReturn(activity).when(mFragment).getActivity();
+ FragmentManager fragmentManager = mock(FragmentManager.class);
+ doReturn(fragmentManager).when(mFragment).getFragmentManager();
+ mFragment.mShouldTriggerAudioSharingShareThenPairFlow =
+ mFragment.shouldTriggerAudioSharingShareThenPairFlow();
+ }
+
private static class TestBluetoothDevicePairingDetailBase extends
BluetoothDevicePairingDetailBase {
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragmentTest.java
index 7d8846d0506..1ce3316811b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragmentTest.java
@@ -16,16 +16,29 @@
package com.android.settings.connecteddevice.audiosharing;
+import static com.android.settings.connecteddevice.audiosharing.AudioSharingDashboardFragment.SHARE_THEN_PAIR_REQUEST_CODE;
+import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
+import android.app.Activity;
import android.app.settings.SettingsEnums;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
+import android.os.Looper;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.view.View;
import androidx.test.core.app.ApplicationProvider;
@@ -33,24 +46,29 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsCategoryController;
+import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settingslib.flags.Flags;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
+import org.robolectric.shadow.api.Shadow;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowFragment.class})
+@Config(shadows = {ShadowFragment.class, ShadowBluetoothAdapter.class})
public class AudioSharingDashboardFragmentTest {
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock private SettingsActivity mActivity;
@Mock private SettingsMainSwitchBar mSwitchBar;
@@ -59,11 +77,19 @@ public class AudioSharingDashboardFragmentTest {
@Mock private AudioSharingCallAudioPreferenceController mCallAudioController;
@Mock private AudioSharingPlaySoundPreferenceController mPlaySoundController;
@Mock private AudioStreamsCategoryController mStreamsCategoryController;
+ @Mock private AudioSharingSwitchBarController mSwitchBarController;
private final Context mContext = ApplicationProvider.getApplicationContext();
private AudioSharingDashboardFragment mFragment;
+ private ShadowBluetoothAdapter mShadowBluetoothAdapter;
@Before
public void setUp() {
+ mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
+ mShadowBluetoothAdapter.setEnabled(true);
+ mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
+ BluetoothStatusCodes.FEATURE_SUPPORTED);
+ mShadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
+ BluetoothStatusCodes.FEATURE_SUPPORTED);
when(mSwitchBar.getRootView()).thenReturn(mView);
mFragment = new AudioSharingDashboardFragment();
}
@@ -100,13 +126,73 @@ public class AudioSharingDashboardFragmentTest {
verify(mSwitchBar).show();
}
+ @Test
+ public void onActivityResult_shareThenPairWithBadCode_doNothing() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ mFragment.setControllers(
+ mVolumeGroupController,
+ mCallAudioController,
+ mPlaySoundController,
+ mStreamsCategoryController,
+ mSwitchBarController);
+ Intent data = new Intent();
+ Bundle extras = new Bundle();
+ BluetoothDevice device = Mockito.mock(BluetoothDevice.class);
+ extras.putParcelable(EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, device);
+ data.putExtras(extras);
+ mFragment.onActivityResult(SHARE_THEN_PAIR_REQUEST_CODE, Activity.RESULT_CANCELED, data);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ verify(mSwitchBarController, never()).handleAutoAddSourceAfterPair(device);
+ }
+
+ @Test
+ public void onActivityResult_shareThenPairWithNoDevice_doNothing() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ mFragment.setControllers(
+ mVolumeGroupController,
+ mCallAudioController,
+ mPlaySoundController,
+ mStreamsCategoryController,
+ mSwitchBarController);
+ Intent data = new Intent();
+ Bundle extras = new Bundle();
+ extras.putParcelable(EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, null);
+ data.putExtras(extras);
+ mFragment.onActivityResult(SHARE_THEN_PAIR_REQUEST_CODE, Activity.RESULT_CANCELED, data);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ verify(mSwitchBarController, never()).handleAutoAddSourceAfterPair(any());
+ }
+
+ @Test
+ public void onActivityResult_shareThenPairWithDevice_handleAutoAddSource() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ mFragment.setControllers(
+ mVolumeGroupController,
+ mCallAudioController,
+ mPlaySoundController,
+ mStreamsCategoryController,
+ mSwitchBarController);
+ Intent data = new Intent();
+ Bundle extras = new Bundle();
+ BluetoothDevice device = Mockito.mock(BluetoothDevice.class);
+ extras.putParcelable(EXTRA_BT_DEVICE_TO_AUTO_ADD_SOURCE, device);
+ data.putExtras(extras);
+ mFragment.onActivityResult(SHARE_THEN_PAIR_REQUEST_CODE, Activity.RESULT_OK, data);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ verify(mSwitchBarController).handleAutoAddSourceAfterPair(device);
+ }
+
@Test
public void onAudioSharingStateChanged_updateVisibilityForControllers() {
mFragment.setControllers(
mVolumeGroupController,
mCallAudioController,
mPlaySoundController,
- mStreamsCategoryController);
+ mStreamsCategoryController,
+ mSwitchBarController);
mFragment.onAudioSharingStateChanged();
verify(mVolumeGroupController).updateVisibility();
verify(mCallAudioController).updateVisibility();
@@ -120,7 +206,8 @@ public class AudioSharingDashboardFragmentTest {
mVolumeGroupController,
mCallAudioController,
mPlaySoundController,
- mStreamsCategoryController);
+ mStreamsCategoryController,
+ mSwitchBarController);
mFragment.onAudioSharingProfilesConnected();
verify(mVolumeGroupController).onAudioSharingProfilesConnected();
}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
index 7227f37998b..dec85e47b80 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
@@ -34,6 +34,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -82,11 +83,6 @@ public class AudioSharingDialogFragmentTest {
new AudioSharingDeviceItem(TEST_DEVICE_NAME3, /* groupId= */ 3, /* isActive= */ false);
private static final AudioSharingDialogFragment.DialogEventListener EMPTY_EVENT_LISTENER =
new AudioSharingDialogFragment.DialogEventListener() {
- @Override
- public void onItemClick(AudioSharingDeviceItem item) {}
-
- @Override
- public void onCancelClick() {}
};
private static final Pair TEST_EVENT_DATA = Pair.create(1, 1);
private static final Pair[] TEST_EVENT_DATA_LIST =
@@ -176,8 +172,17 @@ public class AudioSharingDialogFragmentTest {
@Test
public void onCreateDialog_noExtraConnectedDevice_pairNewDevice() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ AtomicBoolean isPairBtnClicked = new AtomicBoolean(false);
AudioSharingDialogFragment.show(
- mParent, new ArrayList<>(), EMPTY_EVENT_LISTENER, TEST_EVENT_DATA_LIST);
+ mParent,
+ new ArrayList<>(),
+ new AudioSharingDialogFragment.DialogEventListener() {
+ @Override
+ public void onPositiveClick() {
+ isPairBtnClicked.set(true);
+ }
+ },
+ TEST_EVENT_DATA_LIST);
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNotNull();
@@ -191,14 +196,24 @@ public class AudioSharingDialogFragmentTest {
any(Context.class),
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_POSITIVE_BTN_CLICKED),
eq(TEST_EVENT_DATA));
+ assertThat(isPairBtnClicked.get()).isTrue();
assertThat(dialog.isShowing()).isFalse();
}
@Test
public void onCreateDialog_noExtraConnectedDevice_showQRCode() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ AtomicBoolean isQrCodeBtnClicked = new AtomicBoolean(false);
AudioSharingDialogFragment.show(
- mParent, new ArrayList<>(), EMPTY_EVENT_LISTENER, TEST_EVENT_DATA_LIST);
+ mParent,
+ new ArrayList<>(),
+ new AudioSharingDialogFragment.DialogEventListener() {
+ @Override
+ public void onCancelClick() {
+ isQrCodeBtnClicked.set(true);
+ }
+ },
+ TEST_EVENT_DATA_LIST);
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
assertThat(dialog).isNotNull();
@@ -212,6 +227,7 @@ public class AudioSharingDialogFragmentTest {
any(Context.class),
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_NEGATIVE_BTN_CLICKED),
eq(TEST_EVENT_DATA));
+ assertThat(isQrCodeBtnClicked.get()).isTrue();
assertThat(dialog.isShowing()).isFalse();
}
@@ -286,12 +302,9 @@ public class AudioSharingDialogFragmentTest {
list,
new AudioSharingDialogFragment.DialogEventListener() {
@Override
- public void onItemClick(AudioSharingDeviceItem item) {
+ public void onItemClick(@NonNull AudioSharingDeviceItem item) {
isShareBtnClicked.set(true);
}
-
- @Override
- public void onCancelClick() {}
},
TEST_EVENT_DATA_LIST);
shadowMainLooper().idle();
@@ -359,9 +372,6 @@ public class AudioSharingDialogFragmentTest {
mParent,
list,
new AudioSharingDialogFragment.DialogEventListener() {
- @Override
- public void onItemClick(AudioSharingDeviceItem item) {}
-
@Override
public void onCancelClick() {
isCancelBtnClicked.set(true);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingIncompatibleDialogFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingIncompatibleDialogFragmentTest.java
index 7f172918d36..67cb2aa915b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingIncompatibleDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingIncompatibleDialogFragmentTest.java
@@ -18,7 +18,6 @@ package com.android.settings.connecteddevice.audiosharing;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
import android.bluetooth.BluetoothAdapter;
@@ -34,7 +33,6 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.flags.Flags;
import org.junit.After;
@@ -42,7 +40,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
@@ -62,7 +59,6 @@ public class AudioSharingIncompatibleDialogFragmentTest {
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
- @Mock private CachedBluetoothDevice mCachedBluetoothDevice;
private Fragment mParent;
private AudioSharingIncompatibleDialogFragment mFragment;
@@ -76,7 +72,6 @@ public class AudioSharingIncompatibleDialogFragmentTest {
BluetoothStatusCodes.FEATURE_SUPPORTED);
shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
BluetoothStatusCodes.FEATURE_SUPPORTED);
- when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);
mFragment = new AudioSharingIncompatibleDialogFragment();
mParent = new Fragment();
FragmentController.setupFragment(mParent, FragmentActivity.class, /* containerViewId= */
@@ -97,7 +92,7 @@ public class AudioSharingIncompatibleDialogFragmentTest {
@Test
public void onCreateDialog_flagOff_dialogNotExist() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
- AudioSharingIncompatibleDialogFragment.show(mParent, mCachedBluetoothDevice,
+ AudioSharingIncompatibleDialogFragment.show(mParent, TEST_DEVICE_NAME,
EMPTY_EVENT_LISTENER);
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -107,7 +102,7 @@ public class AudioSharingIncompatibleDialogFragmentTest {
@Test
public void onCreateDialog_unattachedFragment_dialogNotExist() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
- AudioSharingIncompatibleDialogFragment.show(new Fragment(), mCachedBluetoothDevice,
+ AudioSharingIncompatibleDialogFragment.show(new Fragment(), TEST_DEVICE_NAME,
EMPTY_EVENT_LISTENER);
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -117,7 +112,7 @@ public class AudioSharingIncompatibleDialogFragmentTest {
@Test
public void onCreateDialog_flagOn_showDialog() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
- AudioSharingIncompatibleDialogFragment.show(mParent, mCachedBluetoothDevice,
+ AudioSharingIncompatibleDialogFragment.show(mParent, TEST_DEVICE_NAME,
EMPTY_EVENT_LISTENER);
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
@@ -134,7 +129,7 @@ public class AudioSharingIncompatibleDialogFragmentTest {
public void onCreateDialog_clickBtn_callbackTriggered() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
AtomicBoolean isBtnClicked = new AtomicBoolean(false);
- AudioSharingIncompatibleDialogFragment.show(mParent, mCachedBluetoothDevice,
+ AudioSharingIncompatibleDialogFragment.show(mParent, TEST_DEVICE_NAME,
() -> isBtnClicked.set(true));
shadowMainLooper().idle();
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
index 0d21f18b821..eb2083ebe7b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
@@ -934,6 +934,19 @@ public class AudioSharingSwitchBarControllerTest {
childFragments.forEach(fragment -> ((DialogFragment) fragment).dismiss());
}
+ @Test
+ public void handleAutoAddSourceAfterPair() {
+ when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1));
+ when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata);
+ mController.handleAutoAddSourceAfterPair(mDevice1);
+ shadowOf(Looper.getMainLooper()).idle();
+
+ verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
+ List childFragments = mParentFragment.getChildFragmentManager().getFragments();
+ assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
+ AudioSharingLoadingStateDialogFragment.class.getName());
+ }
+
private Fragment setUpFragmentWithStartSharingIntent() {
Bundle args = new Bundle();
args.putBoolean(EXTRA_START_LE_AUDIO_SHARING, true);
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
deleted file mode 100644
index 1823d6d6bed..00000000000
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.notNull;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.content.Intent;
-import android.provider.Settings;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.telephony.euicc.EuiccManager;
-import android.text.TextUtils;
-
-import androidx.lifecycle.LifecycleOwner;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.Settings.MobileNetworkActivity;
-import com.android.settings.widget.AddPreference;
-import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-import java.util.Arrays;
-
-@RunWith(RobolectricTestRunner.class)
-public class MobileNetworkSummaryControllerTest {
-
- @Mock
- private TelephonyManager mTelephonyManager;
- @Mock
- private SubscriptionManager mSubscriptionManager;
- @Mock
- private EuiccManager mEuiccManager;
- @Mock
- private PreferenceScreen mPreferenceScreen;
- @Mock
- private MobileNetworkRepository mMobileNetworkRepository;
- @Mock
- private MobileNetworkRepository.MobileNetworkCallback mMobileNetworkCallback;
-
- private AddPreference mPreference;
- private Context mContext;
- private MobileNetworkSummaryController mController;
- private LifecycleOwner mLifecycleOwner;
- private Lifecycle mLifecycle;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
- doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
- doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
- doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
- mMobileNetworkRepository = MobileNetworkRepository.getInstance(mContext);
- mLifecycleOwner = () -> mLifecycle;
- mLifecycle = new Lifecycle(mLifecycleOwner);
- mMobileNetworkRepository.addRegister(mLifecycleOwner, mMobileNetworkCallback,
- SubscriptionManager.INVALID_SUBSCRIPTION_ID);
-
- when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
- when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
- when(mEuiccManager.isEnabled()).thenReturn(true);
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
-
- mController = new MobileNetworkSummaryController(mContext, mLifecycle, mLifecycleOwner);
- mPreference = spy(new AddPreference(mContext, null));
- mPreference.setKey(mController.getPreferenceKey());
- when(mPreferenceScreen.findPreference(eq(mController.getPreferenceKey()))).thenReturn(
- mPreference);
- }
-
- @After
- public void tearDown() {
- mMobileNetworkRepository.removeRegister(mMobileNetworkCallback);
- SubscriptionUtil.setActiveSubscriptionsForTesting(null);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(null);
- }
-
- @Test
- public void getSummary_noSubscriptions_returnSummaryCorrectly() {
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- assertThat(mController.getSummary()).isEqualTo("Add a network");
- }
-
- @Test
- public void getSummary_noSubscriptionsNoEuiccMgr_correctSummaryAndClickHandler() {
- when(mEuiccManager.isEnabled()).thenReturn(false);
- assertThat(TextUtils.isEmpty(mController.getSummary())).isTrue();
- assertThat(mPreference.getOnPreferenceClickListener()).isNull();
- assertThat(mPreference.getFragment()).isNull();
- }
-
- @Test
- @Ignore
- public void getSummary_oneSubscription_correctSummaryAndClickHandler() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(1);
- when(sub1.getDisplayName()).thenReturn("sub1");
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- assertThat(mController.getSummary()).isEqualTo("sub1");
- assertThat(mPreference.getFragment()).isNull();
- final ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class);
- doNothing().when(mContext).startActivity(intentCaptor.capture());
- mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
- Intent intent = intentCaptor.getValue();
- assertThat(intent.getComponent().getClassName()).isEqualTo(
- MobileNetworkActivity.class.getName());
- assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,
- SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(sub1.getSubscriptionId());
- }
-
- @Test
- @Ignore
- public void getSummary_oneInactivePSim_cannotDisablePsim_correctSummaryAndClickHandler() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(1);
- when(sub1.getDisplayName()).thenReturn("sub1");
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- when(mSubscriptionManager.isActiveSubscriptionId(eq(1))).thenReturn(false);
-
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- assertThat(mController.getSummary()).isEqualTo("Tap to activate sub1");
-
- assertThat(mPreference.getFragment()).isNull();
- mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
- verify(mSubscriptionManager).setSubscriptionEnabled(eq(sub1.getSubscriptionId()), eq(true));
- }
-
- @Test
- @Ignore
- public void getSummary_oneInactivePSim_canDisablePsim_correctSummaryAndClickHandler() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(1);
- when(sub1.getDisplayName()).thenReturn("sub1");
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
- when(mSubscriptionManager.isActiveSubscriptionId(eq(1))).thenReturn(false);
- when(mSubscriptionManager.canDisablePhysicalSubscription()).thenReturn(true);
-
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- assertThat(mController.getSummary()).isEqualTo("sub1");
-
- final ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class);
- doNothing().when(mContext).startActivity(intentCaptor.capture());
- mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
- Intent intent = intentCaptor.getValue();
- assertThat(intent.getComponent().getClassName()).isEqualTo(
- MobileNetworkActivity.class.getName());
- assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,
- SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(sub1.getSubscriptionId());
- }
-
- @Test
- public void addButton_noSubscriptionsNoEuiccMgr_noAddClickListener() {
- when(mEuiccManager.isEnabled()).thenReturn(false);
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- verify(mPreference, never()).setOnAddClickListener(notNull());
- }
-
- @Test
- public void addButton_oneSubscriptionNoEuiccMgr_noAddClickListener() {
- when(mEuiccManager.isEnabled()).thenReturn(false);
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- verify(mPreference, never()).setOnAddClickListener(notNull());
- }
-
- @Test
- public void addButton_noSubscriptions_noAddClickListener() {
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- verify(mPreference, never()).setOnAddClickListener(notNull());
- }
-
- @Test
- @Ignore
- public void addButton_oneSubscription_hasAddClickListener() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- verify(mPreference).setOnAddClickListener(notNull());
- }
-
- @Test
- @Ignore
- public void addButton_twoSubscriptions_hasAddClickListener() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- verify(mPreference).setOnAddClickListener(notNull());
- }
-
- @Test
- @Ignore
- public void addButton_oneSubscriptionAirplaneModeTurnedOn_addButtonGetsDisabled() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
- mController.onAirplaneModeChanged(true);
-
- final ArgumentCaptor captor = ArgumentCaptor.forClass(Boolean.class);
- verify(mPreference, atLeastOnce()).setAddWidgetEnabled(captor.capture());
- assertThat(captor.getValue()).isFalse();
- }
-
- @Test
- @Ignore
- public void onResume_oneSubscriptionAirplaneMode_isDisabled() {
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- assertThat(mPreference.isEnabled()).isFalse();
-
- final ArgumentCaptor captor = ArgumentCaptor.forClass(Boolean.class);
- verify(mPreference, atLeastOnce()).setAddWidgetEnabled(captor.capture());
- assertThat(captor.getValue()).isFalse();
- }
-
- @Test
- public void onAvailableSubInfoChanged_noSubscriptionEsimDisabled_isDisabled() {
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
- when(mEuiccManager.isEnabled()).thenReturn(false);
- mController.displayPreference(mPreferenceScreen);
-
- mController.onAvailableSubInfoChanged(null);
-
- assertThat(mPreference.isEnabled()).isFalse();
- }
-
- @Test
- public void onAirplaneModeChanged_oneSubscriptionAirplaneModeGetsTurnedOn_isDisabled() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- assertThat(mPreference.isEnabled()).isTrue();
-
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
- mController.onAirplaneModeChanged(true);
-
- assertThat(mPreference.isEnabled()).isFalse();
- }
-
- @Test
- @Ignore
- public void onAirplaneModeChanged_oneSubscriptionAirplaneModeGetsTurnedOff_isEnabled() {
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
-
- assertThat(mPreference.isEnabled()).isFalse();
-
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
- mController.onAirplaneModeChanged(false);
-
- assertThat(mPreference.isEnabled()).isTrue();
-
- final ArgumentCaptor captor = ArgumentCaptor.forClass(Boolean.class);
- verify(mPreference, atLeastOnce()).setAddWidgetEnabled(eq(false));
- verify(mPreference, atLeastOnce()).setAddWidgetEnabled(captor.capture());
- assertThat(captor.getValue()).isTrue();
- }
-
- @Test
- public void onResume_disabledByAdmin_prefStaysDisabled() {
- mPreference.setDisabledByAdmin(new RestrictedLockUtils.EnforcedAdmin());
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- verify(mPreference, never()).setEnabled(eq(true));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
index 1aecad51242..a04a14de57b 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
@@ -18,35 +18,77 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
import android.media.RingtoneManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
+import com.android.server.notification.Flags;
+import com.android.settings.R;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
public class NotificationRingtonePreferenceControllerTest {
private NotificationRingtonePreferenceController mController;
+ @Mock private Context mMockContext;
+ @Mock private Resources mMockResources;
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mController = new NotificationRingtonePreferenceController(RuntimeEnvironment.application);
+ when(mMockContext.getResources()).thenReturn(mMockResources);
+ mController = new NotificationRingtonePreferenceController(mMockContext);
}
@Test
+ @DisableFlags(Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI)
public void isAvailable_byDefault_isTrue() {
+ when(mMockResources
+ .getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
+ .thenReturn(false);
+ when(mMockResources.getBoolean(R.bool.config_show_notification_ringtone))
+ .thenReturn(true);
+
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
+ @DisableFlags(Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI)
public void isAvailable_whenNotVisible_isFalse() {
+ when(mMockResources
+ .getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
+ .thenReturn(false);
+ when(mMockResources.getBoolean(R.bool.config_show_notification_ringtone))
+ .thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI)
+ public void isAvailable_whenFlagsNotificationVibrationInSoundUri_isFalse() {
+ when(mMockResources
+ .getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
+ .thenReturn(true);
+ when(mMockResources.getBoolean(R.bool.config_show_notification_ringtone))
+ .thenReturn(true);
+
assertThat(mController.isAvailable()).isFalse();
}
diff --git a/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
index 9727dd13848..8442a37873b 100644
--- a/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/shortcut/CreateShortcutPreferenceControllerTest.java
@@ -16,7 +16,7 @@
package com.android.settings.shortcut;
-import static com.android.settings.shortcut.CreateShortcutPreferenceController.SHORTCUT_ID_PREFIX;
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_ID_PREFIX;
import static com.google.common.truth.Truth.assertThat;
@@ -101,10 +101,10 @@ public class CreateShortcutPreferenceControllerTest {
when(mShortcutManager.createShortcutResultIntent(any(ShortcutInfo.class)))
.thenReturn(new Intent().putExtra("d1", "d2"));
- final Intent intent = new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE)
+ final Intent intent = new Intent(Shortcuts.SHORTCUT_PROBE)
.setClass(mContext, Settings.ManageApplicationsActivity.class);
final ResolveInfo ri = mContext.getPackageManager().resolveActivity(intent, 0);
- final Intent result = mController.createResultIntent(intent, ri, "mock");
+ final Intent result = mController.createResultIntent(ri);
assertThat(result.getStringExtra("d1")).isEqualTo("d2");
assertThat((Object) result.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT)).isNotNull();
@@ -131,7 +131,7 @@ public class CreateShortcutPreferenceControllerTest {
ri2.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.setResolveInfosForIntent(
- new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
+ new Intent(Shortcuts.SHORTCUT_PROBE),
Arrays.asList(ri1, ri2));
doReturn(false).when(mController).canShowWifiHotspot();
@@ -158,7 +158,7 @@ public class CreateShortcutPreferenceControllerTest {
ri2.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.setResolveInfosForIntent(
- new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
+ new Intent(Shortcuts.SHORTCUT_PROBE),
Arrays.asList(ri1, ri2));
doReturn(false).when(mController).canShowWifiHotspot();
@@ -276,7 +276,7 @@ public class CreateShortcutPreferenceControllerTest {
ri.activityInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
mPackageManager.setResolveInfosForIntent(
- new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE),
+ new Intent(Shortcuts.SHORTCUT_PROBE),
Arrays.asList(ri));
}
}
diff --git a/tests/robotests/src/com/android/settings/shortcut/ShortcutsTest.java b/tests/robotests/src/com/android/settings/shortcut/ShortcutsTest.java
new file mode 100644
index 00000000000..a347ff9e0db
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/shortcut/ShortcutsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.shortcut;
+
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_PROBE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ShortcutInfo;
+
+import com.android.settings.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class ShortcutsTest {
+
+ private Context mContext;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.getApplication();
+ }
+
+ @Test
+ public void shortcutsUpdateTask() {
+ final Intent intent = new Intent(SHORTCUT_PROBE)
+ .setClass(mContext, Settings.ManageApplicationsActivity.class);
+ final ResolveInfo ri = mContext.getPackageManager().resolveActivity(intent, 0);
+ assertThat(ri).isNotNull();
+
+ ShortcutInfo shortcut = Shortcuts.createShortcutInfo(mContext, ri);
+
+ assertThat(shortcut.getLabel()).isNotNull();
+ assertThat(shortcut.getLabel().toString()).isEqualTo("App info");
+
+ assertThat(shortcut.getIntent()).isNotNull();
+ assertThat(shortcut.getIntent().getAction()).isEqualTo(Intent.ACTION_MAIN);
+ assertThat(shortcut.getIntent().getCategories()).contains("com.android.settings.SHORTCUT");
+ assertThat(shortcut.getIntent().getComponent()).isEqualTo(
+ new ComponentName(mContext, Settings.ManageApplicationsActivity.class));
+ assertThat(shortcut.getIcon()).isNotNull();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdateTaskTest.java b/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdaterTest.java
similarity index 52%
rename from tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdateTaskTest.java
rename to tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdaterTest.java
index 8352e7a9634..5324ff50f43 100644
--- a/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdateTaskTest.java
+++ b/tests/robotests/src/com/android/settings/shortcut/ShortcutsUpdaterTest.java
@@ -16,30 +16,30 @@
package com.android.settings.shortcut;
-import static com.android.settings.shortcut.CreateShortcutPreferenceController.SHORTCUT_ID_PREFIX;
+import static com.android.settings.shortcut.Shortcuts.SHORTCUT_ID_PREFIX;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Flags;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import com.android.settings.Settings;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -48,17 +48,17 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.shadow.api.Shadow;
-import org.robolectric.shadows.ShadowPackageManager;
import java.util.Arrays;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-public class ShortcutsUpdateTaskTest {
+public class ShortcutsUpdaterTest {
private Context mContext;
- private ShadowPackageManager mPackageManager;
+
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock
private ShortcutManager mShortcutManager;
@@ -68,29 +68,12 @@ public class ShortcutsUpdateTaskTest {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mPackageManager = Shadow.extract(mContext.getPackageManager());
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE));
}
@Test
- public void shortcutsUpdateTask() {
- mContext = spy(RuntimeEnvironment.application);
- doReturn(mShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE));
- final Intent shortcut1 = new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE)
- .setComponent(new ComponentName(
- mContext, Settings.ManageApplicationsActivity.class));
- final ResolveInfo ri1 = mock(ResolveInfo.class);
- ri1.nonLocalizedLabel = "label1";
-
- final Intent shortcut2 = new Intent(CreateShortcutPreferenceController.SHORTCUT_PROBE)
- .setComponent(new ComponentName(
- mContext, Settings.SoundSettingsActivity.class));
- final ResolveInfo ri2 = mock(ResolveInfo.class);
- ri2.nonLocalizedLabel = "label2";
-
- mPackageManager.addResolveInfoForIntent(shortcut1, ri1);
- mPackageManager.addResolveInfoForIntent(shortcut2, ri2);
-
+ public void updatePinnedShortcuts_updatesAllShortcuts() {
final List pinnedShortcuts = Arrays.asList(
makeShortcut("d1"),
makeShortcut("d2"),
@@ -99,7 +82,7 @@ public class ShortcutsUpdateTaskTest {
makeShortcut(Settings.SoundSettingsActivity.class));
when(mShortcutManager.getPinnedShortcuts()).thenReturn(pinnedShortcuts);
- new ShortcutsUpdateTask(mContext).doInBackground();
+ ShortcutsUpdater.updatePinnedShortcuts(mContext);
verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
@@ -108,6 +91,52 @@ public class ShortcutsUpdateTaskTest {
assertThat(updates).hasSize(2);
assertThat(pinnedShortcuts.get(2).getId()).isEqualTo(updates.get(0).getId());
assertThat(pinnedShortcuts.get(4).getId()).isEqualTo(updates.get(1).getId());
+ assertThat(updates.get(0).getShortLabel().toString()).isEqualTo("App info");
+ assertThat(updates.get(1).getShortLabel().toString()).isEqualTo("Sound & vibration");
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI)
+ public void updatePinnedShortcuts_withModesFlag_replacesDndByModes() {
+ List shortcuts = List.of(
+ makeShortcut(Settings.ZenModeSettingsActivity.class));
+ when(mShortcutManager.getPinnedShortcuts()).thenReturn(shortcuts);
+
+ ShortcutsUpdater.updatePinnedShortcuts(mContext);
+
+ verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
+ final List updates = mListCaptor.getValue();
+ assertThat(updates).hasSize(1);
+
+ // Id hasn't changed, but intent and label has.
+ ComponentName zenCn = new ComponentName(mContext, Settings.ZenModeSettingsActivity.class);
+ ComponentName modesCn = new ComponentName(mContext, Settings.ModesSettingsActivity.class);
+ assertThat(updates.get(0).getId()).isEqualTo(
+ SHORTCUT_ID_PREFIX + zenCn.flattenToShortString());
+ assertThat(updates.get(0).getIntent().getComponent()).isEqualTo(modesCn);
+ assertThat(updates.get(0).getShortLabel().toString()).isEqualTo("Modes");
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_MODES_UI)
+ public void updatePinnedShortcuts_withoutModesFlag_leavesDndAlone() {
+ List shortcuts = List.of(
+ makeShortcut(Settings.ZenModeSettingsActivity.class));
+ when(mShortcutManager.getPinnedShortcuts()).thenReturn(shortcuts);
+
+ ShortcutsUpdater.updatePinnedShortcuts(mContext);
+
+ verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
+ final List updates = mListCaptor.getValue();
+ assertThat(updates).hasSize(1);
+
+ // Nothing has changed.
+ ComponentName zenCn = new ComponentName(mContext, Settings.ZenModeSettingsActivity.class);
+ assertThat(updates.get(0).getId()).isEqualTo(
+ SHORTCUT_ID_PREFIX + zenCn.flattenToShortString());
+ assertThat(updates.get(0).getIntent().getComponent()).isEqualTo(zenCn);
+ assertThat(updates.get(0).getShortLabel().toString()).isEqualTo("Do Not Disturb");
+
}
private ShortcutInfo makeShortcut(Class> className) {
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
index 3f6d785463d..230b443f296 100644
--- a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
@@ -118,7 +118,7 @@ public class WallpaperSuggestionActivityTest {
}
@Test
- public void addExtras_intentNotFromSetupWizard_extrasHasFocusWallpaper() {
+ public void addExtras_intentNotFromSetupWizard_extrasHasFocusWallpaperAndLaunchedSettingsSearch() {
WallpaperSuggestionActivity activity = Robolectric.buildActivity(
WallpaperSuggestionActivity.class, new Intent(Intent.ACTION_MAIN).setComponent(
new ComponentName(RuntimeEnvironment.application,
@@ -127,6 +127,8 @@ public class WallpaperSuggestionActivityTest {
assertThat(intent).isNotNull();
assertThat(intent.getStringExtra(WALLPAPER_FLAVOR)).isEqualTo("focus_wallpaper");
+ assertThat(intent.getStringExtra(WALLPAPER_LAUNCH_SOURCE))
+ .isEqualTo("app_launched_settings_search");
}
diff --git a/tests/spa_unit/src/com/android/settings/network/MobileNetworkSummaryControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/MobileNetworkSummaryControllerTest.kt
new file mode 100644
index 00000000000..69fa9c42e6c
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/MobileNetworkSummaryControllerTest.kt
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network
+
+import android.content.Context
+import androidx.lifecycle.testing.TestLifecycleOwner
+import androidx.preference.PreferenceManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settingslib.RestrictedPreference
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.runBlocking
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.stub
+
+@RunWith(AndroidJUnit4::class)
+class MobileNetworkSummaryControllerTest {
+
+ private val context: Context = ApplicationProvider.getApplicationContext()
+
+ private val preference = RestrictedPreference(context).apply { key = KEY }
+ private val preferenceScreen = PreferenceManager(context).createPreferenceScreen(context)
+
+ private val mockMobileNetworkSummaryRepository = mock()
+ private val airplaneModeOnFlow = MutableStateFlow(false)
+
+ private val controller =
+ MobileNetworkSummaryController(
+ context = context,
+ preferenceKey = KEY,
+ repository = mockMobileNetworkSummaryRepository,
+ airplaneModeOnFlow = airplaneModeOnFlow,
+ )
+
+ @Before
+ fun setUp() {
+ preferenceScreen.addPreference(preference)
+ controller.displayPreference(preferenceScreen)
+ }
+
+ @Test
+ fun onViewCreated_noSubscriptions(): Unit = runBlocking {
+ mockMobileNetworkSummaryRepository.stub {
+ on { subscriptionsStateFlow() } doReturn
+ flowOf(MobileNetworkSummaryRepository.NoSubscriptions)
+ }
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.summary).isNull()
+ assertThat(preference.isEnabled).isFalse()
+ assertThat(preference.onPreferenceClickListener).isNull()
+ }
+
+ @Test
+ fun onViewCreated_addNetwork(): Unit = runBlocking {
+ mockMobileNetworkSummaryRepository.stub {
+ on { subscriptionsStateFlow() } doReturn
+ flowOf(MobileNetworkSummaryRepository.AddNetwork)
+ }
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.summary)
+ .isEqualTo(context.getString(R.string.mobile_network_summary_add_a_network))
+ assertThat(preference.isEnabled).isTrue()
+ assertThat(preference.onPreferenceClickListener).isNotNull()
+ }
+
+ @Test
+ fun onViewCreated_hasSubscriptions(): Unit = runBlocking {
+ mockMobileNetworkSummaryRepository.stub {
+ on { subscriptionsStateFlow() } doReturn
+ flowOf(
+ MobileNetworkSummaryRepository.HasSubscriptions(
+ displayNames = listOf(DISPLAY_NAME_1, DISPLAY_NAME_2)
+ )
+ )
+ }
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.summary).isEqualTo("$DISPLAY_NAME_1, $DISPLAY_NAME_2")
+ assertThat(preference.isEnabled).isTrue()
+ assertThat(preference.fragment).isNotNull()
+ }
+
+ @Test
+ fun onViewCreated_addNetworkAndAirplaneModeOn(): Unit = runBlocking {
+ mockMobileNetworkSummaryRepository.stub {
+ on { subscriptionsStateFlow() } doReturn
+ flowOf(MobileNetworkSummaryRepository.AddNetwork)
+ }
+ airplaneModeOnFlow.value = true
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.isEnabled).isFalse()
+ }
+
+ @Test
+ fun onViewCreated_hasSubscriptionsAndAirplaneModeOn(): Unit = runBlocking {
+ mockMobileNetworkSummaryRepository.stub {
+ on { subscriptionsStateFlow() } doReturn
+ flowOf(
+ MobileNetworkSummaryRepository.HasSubscriptions(
+ displayNames = listOf(DISPLAY_NAME_1, DISPLAY_NAME_2)
+ )
+ )
+ }
+ airplaneModeOnFlow.value = true
+
+ controller.onViewCreated(TestLifecycleOwner())
+ delay(100)
+
+ assertThat(preference.isEnabled).isFalse()
+ }
+
+
+ private companion object {
+ const val KEY = "test_key"
+ const val DISPLAY_NAME_1 = "Display Name 1"
+ const val DISPLAY_NAME_2 = "Display Name 2"
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/MobileNetworkSummaryRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/MobileNetworkSummaryRepositoryTest.kt
new file mode 100644
index 00000000000..463af96268f
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/MobileNetworkSummaryRepositoryTest.kt
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network
+
+import android.content.Context
+import android.telephony.SubscriptionInfo
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.network.telephony.SubscriptionRepository
+import com.android.settings.network.telephony.euicc.EuiccRepository
+import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.stub
+
+@RunWith(AndroidJUnit4::class)
+class MobileNetworkSummaryRepositoryTest {
+
+ private val context: Context = ApplicationProvider.getApplicationContext()
+
+ private val mockSubscriptionRepository = mock()
+ private val mockEuiccRepository = mock()
+
+ private val repository =
+ MobileNetworkSummaryRepository(
+ context = context,
+ subscriptionRepository = mockSubscriptionRepository,
+ euiccRepository = mockEuiccRepository,
+ getDisplayName = { it.displayName.toString() },
+ )
+
+ @Test
+ fun subscriptionsStateFlow_noSubscriptionsAndShowEuicc_returnsAddNetwork() = runBlocking {
+ mockSubscriptionRepository.stub {
+ on { selectableSubscriptionInfoListFlow() } doReturn flowOf(emptyList())
+ }
+ mockEuiccRepository.stub { on { showEuiccSettings() } doReturn true }
+
+ val state = repository.subscriptionsStateFlow().firstWithTimeoutOrNull()
+
+ assertThat(state).isEqualTo(MobileNetworkSummaryRepository.AddNetwork)
+ }
+
+ @Test
+ fun subscriptionsStateFlow_noSubscriptionsAndHideEuicc_returnsNoSubscriptions() = runBlocking {
+ mockSubscriptionRepository.stub {
+ on { selectableSubscriptionInfoListFlow() } doReturn flowOf(emptyList())
+ }
+ mockEuiccRepository.stub { on { showEuiccSettings() } doReturn false }
+
+ val state = repository.subscriptionsStateFlow().firstWithTimeoutOrNull()
+
+ assertThat(state).isEqualTo(MobileNetworkSummaryRepository.NoSubscriptions)
+ }
+
+ @Test
+ fun subscriptionsStateFlow_hasSubscriptions_returnsHasSubscriptions() = runBlocking {
+ mockSubscriptionRepository.stub {
+ on { selectableSubscriptionInfoListFlow() } doReturn
+ flowOf(
+ listOf(
+ SubscriptionInfo.Builder().setDisplayName(DISPLAY_NAME_1).build(),
+ SubscriptionInfo.Builder().setDisplayName(DISPLAY_NAME_2).build(),
+ )
+ )
+ }
+
+ val state = repository.subscriptionsStateFlow().firstWithTimeoutOrNull()
+
+ assertThat(state)
+ .isEqualTo(
+ MobileNetworkSummaryRepository.HasSubscriptions(
+ listOf(DISPLAY_NAME_1, DISPLAY_NAME_2)
+ )
+ )
+ }
+
+ private companion object {
+ const val DISPLAY_NAME_1 = "Sub 1"
+ const val DISPLAY_NAME_2 = "Sub 2"
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/VoNrRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/VoNrRepositoryTest.kt
index 90d0aa56d77..265cd33f3bf 100644
--- a/tests/spa_unit/src/com/android/settings/network/telephony/VoNrRepositoryTest.kt
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/VoNrRepositoryTest.kt
@@ -27,7 +27,9 @@ import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.doThrow
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.stub
@@ -134,6 +136,15 @@ class VoNrRepositoryTest {
assertThat(isVoNrEnabled).isTrue()
}
+ @Test
+ fun isVoNrEnabledFlow_noPhoneProcess_noCrash() = runBlocking {
+ mockTelephonyManager.stub { on { isVoNrEnabled } doThrow IllegalStateException("no Phone") }
+
+ val isVoNrEnabled = repository.isVoNrEnabledFlow(SUB_ID).firstWithTimeoutOrNull()
+
+ assertThat(isVoNrEnabled).isFalse()
+ }
+
@Test
fun setVoNrEnabled(): Unit = runBlocking {
repository.setVoNrEnabled(SUB_ID, true)
@@ -141,7 +152,20 @@ class VoNrRepositoryTest {
verify(mockTelephonyManager).setVoNrEnabled(true)
}
+ @Test
+ fun setVoNrEnabled_noPhoneProcess_noCrash(): Unit = runBlocking {
+ mockTelephonyManager.stub {
+ on {
+ setVoNrEnabled(any())
+ } doThrow IllegalStateException("no Phone")
+ }
+
+ repository.setVoNrEnabled(SUB_ID, true)
+
+ verify(mockTelephonyManager).setVoNrEnabled(true)
+ }
+
private companion object {
const val SUB_ID = 1
}
-}
+}
\ No newline at end of file