) {
- val cellInfos = results.distinctBy { CellInfoScanKey(it) }
- trySend(NetworkScanCellInfos(cellInfos))
- Log.d(TAG, "CellInfoList: ${CellInfoUtil.cellInfoListToString(cellInfos)}")
+ cellInfos = results.distinctBy { CellInfoScanKey(it) }
+ sendResult()
}
override fun onComplete() {
- trySend(NetworkScanComplete)
- close()
- Log.d(TAG, "onComplete")
+ state = NetworkScanState.COMPLETE
+ sendResult()
+ // Don't call close() here since onComplete() could happens before onResults()
}
override fun onError(error: Int) {
- trySend(NetworkScanError(error))
+ state = NetworkScanState.ERROR
+ sendResult()
close()
- Log.d(TAG, "onError: $error")
+ }
+
+ private fun sendResult() {
+ trySend(NetworkScanResult(state, cellInfos))
}
}
@@ -92,7 +102,7 @@ class NetworkScanRepository(private val context: Context, subId: Int) {
)
awaitClose { networkScan.stopScan() }
- }.flowOn(Dispatchers.Default)
+ }.conflate().onEach { Log.d(TAG, "networkScanFlow: $it") }.flowOn(Dispatchers.Default)
/** Create network scan for allowed network types. */
private fun createNetworkScan(): NetworkScanRequest {
diff --git a/src/com/android/settings/panel/PanelContent.java b/src/com/android/settings/panel/PanelContent.java
index 6b582288457..1bbe2dba83a 100644
--- a/src/com/android/settings/panel/PanelContent.java
+++ b/src/com/android/settings/panel/PanelContent.java
@@ -28,7 +28,10 @@ import java.util.List;
/**
* Represents the data class needed to create a Settings Panel. See {@link PanelFragment}.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public interface PanelContent extends Instrumentable {
int VIEW_TYPE_SLIDER = 1;
diff --git a/src/com/android/settings/panel/PanelContentCallback.java b/src/com/android/settings/panel/PanelContentCallback.java
index e59d69913db..cceecd1e4ed 100644
--- a/src/com/android/settings/panel/PanelContentCallback.java
+++ b/src/com/android/settings/panel/PanelContentCallback.java
@@ -18,7 +18,10 @@ package com.android.settings.panel;
/**
* PanelContentCallback provides a callback interface for {@link PanelFragment} to receive
* events from {@link PanelContent}.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public interface PanelContentCallback {
/**
diff --git a/src/com/android/settings/panel/PanelFeatureProvider.java b/src/com/android/settings/panel/PanelFeatureProvider.java
index 402a562d53d..943c37def46 100644
--- a/src/com/android/settings/panel/PanelFeatureProvider.java
+++ b/src/com/android/settings/panel/PanelFeatureProvider.java
@@ -19,6 +19,7 @@ package com.android.settings.panel;
import android.content.Context;
import android.os.Bundle;
+@Deprecated(forRemoval = true)
public interface PanelFeatureProvider {
/**
diff --git a/src/com/android/settings/panel/PanelFeatureProviderImpl.java b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
index ddfce652c4b..a0aeec60856 100644
--- a/src/com/android/settings/panel/PanelFeatureProviderImpl.java
+++ b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
@@ -27,6 +27,7 @@ import androidx.annotation.Nullable;
import com.android.settings.Utils;
import com.android.settings.flags.Flags;
+@Deprecated(forRemoval = true)
public class PanelFeatureProviderImpl implements PanelFeatureProvider {
@Override
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
index 159028369aa..b3a28844be5 100644
--- a/src/com/android/settings/panel/PanelFragment.java
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -66,6 +66,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+@Deprecated(forRemoval = true)
public class PanelFragment extends Fragment {
private static final String TAG = "PanelFragment";
@@ -519,6 +520,7 @@ public class PanelFragment extends Fragment {
return mPanel.getViewType();
}
+ @Deprecated(forRemoval = true)
class LocalPanelCallback implements PanelContentCallback {
@Override
diff --git a/src/com/android/settings/panel/PanelLoggingContract.java b/src/com/android/settings/panel/PanelLoggingContract.java
index e6e3012abef..fd145f865fb 100644
--- a/src/com/android/settings/panel/PanelLoggingContract.java
+++ b/src/com/android/settings/panel/PanelLoggingContract.java
@@ -21,7 +21,10 @@ package com.android.settings.panel;
*
* Constants should only be removed if underlying panel, or use case is removed.
*
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public class PanelLoggingContract {
/**
diff --git a/src/com/android/settings/panel/PanelSlicesAdapter.java b/src/com/android/settings/panel/PanelSlicesAdapter.java
index a2360d8367b..2223cbb61ab 100644
--- a/src/com/android/settings/panel/PanelSlicesAdapter.java
+++ b/src/com/android/settings/panel/PanelSlicesAdapter.java
@@ -48,7 +48,10 @@ import java.util.Map;
/**
* RecyclerView adapter for Slices in Settings Panels.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public class PanelSlicesAdapter
extends RecyclerView.Adapter {
@@ -112,7 +115,10 @@ public class PanelSlicesAdapter
/**
* ViewHolder for binding Slices to SliceViews.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+ @Deprecated(forRemoval = true)
public class SliceRowViewHolder extends RecyclerView.ViewHolder
implements DividerItemDecoration.DividedViewHolder {
diff --git a/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatch.java b/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatch.java
index 6137d6c564e..49fd8619941 100644
--- a/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatch.java
+++ b/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatch.java
@@ -36,7 +36,10 @@ import java.util.concurrent.CountDownLatch;
* {@link Uri}. Then check if all of the Slices have loaded with
* {@link #isPanelReadyToLoad()}, which will return {@code true} the first time after all
* Slices have loaded.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public class PanelSlicesLoaderCountdownLatch {
private final Set mLoadedSlices;
private final CountDownLatch mCountDownLatch;
diff --git a/src/com/android/settings/panel/SettingsPanelActivity.java b/src/com/android/settings/panel/SettingsPanelActivity.java
index 60b8f887936..d539c433c58 100644
--- a/src/com/android/settings/panel/SettingsPanelActivity.java
+++ b/src/com/android/settings/panel/SettingsPanelActivity.java
@@ -42,7 +42,10 @@ import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
/**
* Dialog Activity to host Settings Slices.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public class SettingsPanelActivity extends FragmentActivity {
private static final String TAG = "SettingsPanelActivity";
diff --git a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
index 623816a01b4..0b35bd3fbc2 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
@@ -19,6 +19,7 @@ package com.android.settings.privatespace;
import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
import static com.android.internal.app.SetScreenLockDialogActivity.LAUNCH_REASON_PRIVATE_SPACE_SETTINGS_ACCESS;
+import static com.android.settings.activityembedding.EmbeddedDeepLinkUtils.tryStartMultiPaneDeepLink;
import android.app.ActivityOptions;
import android.app.AlertDialog;
@@ -36,11 +37,12 @@ import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
+import androidx.fragment.app.FragmentActivity;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.SetScreenLockDialogActivity;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
+import com.android.settings.activityembedding.ActivityEmbeddingUtils;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.transition.SettingsTransitionHelper;
@@ -52,7 +54,7 @@ import com.google.android.setupdesign.util.ThemeHelper;
* user to set a device lock if not set with an alert dialog. This can be launched using the intent
* com.android.settings.action.OPEN_PRIVATE_SPACE_SETTINGS.
*/
-public class PrivateSpaceAuthenticationActivity extends SettingsActivity {
+public class PrivateSpaceAuthenticationActivity extends FragmentActivity {
private static final String TAG = "PrivateSpaceAuthCheck";
public static final String EXTRA_SHOW_PRIVATE_SPACE_UNLOCKED =
"extra_show_private_space_unlocked";
@@ -76,31 +78,55 @@ public class PrivateSpaceAuthenticationActivity extends SettingsActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (isFinishing()) {
+ if (!(Flags.allowPrivateProfile()
+ && android.multiuser.Flags.enablePrivateSpaceFeatures())) {
+ finish();
return;
}
- if (Flags.allowPrivateProfile()
- && android.multiuser.Flags.enablePrivateSpaceFeatures()) {
- ThemeHelper.trySetDynamicColor(this);
- mPrivateSpaceMaintainer =
- new Injector().injectPrivateSpaceMaintainer(getApplicationContext());
- if (getKeyguardManager().isDeviceSecure()) {
- if (savedInstanceState == null) {
- if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
- unlockAndLaunchPrivateSpaceSettings(this);
- } else {
- authenticatePrivateSpaceEntry();
- }
+ Intent intent = getIntent();
+ String highlightMenuKey = getString(R.string.menu_key_security);
+ if (shouldShowMultiPaneDeepLink(intent)
+ && tryStartMultiPaneDeepLink(this, intent, highlightMenuKey)) {
+ finish();
+ return;
+ }
+
+ ThemeHelper.trySetDynamicColor(this);
+ mPrivateSpaceMaintainer =
+ new Injector().injectPrivateSpaceMaintainer(getApplicationContext());
+ if (getKeyguardManager().isDeviceSecure()) {
+ if (savedInstanceState == null) {
+ if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
+ unlockAndLaunchPrivateSpaceSettings(this);
+ } else {
+ authenticatePrivateSpaceEntry();
}
- } else {
- promptToSetDeviceLock();
}
} else {
- finish();
+ promptToSetDeviceLock();
}
}
+ private boolean shouldShowMultiPaneDeepLink(Intent intent) {
+ if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this)) {
+ return false;
+ }
+
+ // If the activity is task root, starting trampoline is needed in order to show two-pane UI.
+ // If FLAG_ACTIVITY_NEW_TASK is set, the activity will become the start of a new task on
+ // this history stack, so starting trampoline is needed in order to notify the homepage that
+ // the highlight key is changed.
+ if (!isTaskRoot() && (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
+ return false;
+ }
+
+ // Only starts trampoline for deep links. Should return false for all the cases that
+ // Settings app starts SettingsActivity or SubSetting by itself.
+ // Other apps should send deep link intent which matches intent filter of the Activity.
+ return intent.getAction() != null;
+ }
+
/** Starts private space setup flow or the PS settings page on device lock authentication */
@VisibleForTesting
public void onLockAuthentication(Context context) {
diff --git a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
index 28b7a9e1cab..98d83402339 100644
--- a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
+++ b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
@@ -36,11 +36,11 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
-import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
+import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.android.settings.R
@@ -62,7 +62,6 @@ import com.android.settingslib.spaprivileged.settingsprovider.settingsGlobalBool
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.flowOf
@@ -207,7 +206,7 @@ fun MobileDataSectionImpl(
}.collectAsStateWithLifecycle(initialValue = null)
val mobileDataStateChanged by remember(mobileDataSelectedId.intValue) {
- TelephonyRepository(context).isDataEnabled(mobileDataSelectedId.intValue)
+ TelephonyRepository(context).isDataEnabledFlow(mobileDataSelectedId.intValue)
}.collectAsStateWithLifecycle(initialValue = false)
val coroutineScope = rememberCoroutineScope()
diff --git a/src/com/android/settings/webview/WebViewAppPicker.java b/src/com/android/settings/webview/WebViewAppPicker.java
index 0060fa0c7b7..b1dfd1454f9 100644
--- a/src/com/android/settings/webview/WebViewAppPicker.java
+++ b/src/com/android/settings/webview/WebViewAppPicker.java
@@ -33,14 +33,12 @@ import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAppPickerFragment;
-import com.android.settings.development.DeveloperOptionAwareMixin;
import com.android.settingslib.applications.DefaultAppInfo;
import java.util.ArrayList;
import java.util.List;
-public class WebViewAppPicker extends DefaultAppPickerFragment implements
- DeveloperOptionAwareMixin {
+public class WebViewAppPicker extends DefaultAppPickerFragment {
private WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
private WebViewUpdateServiceWrapper getWebViewUpdateServiceWrapper() {
diff --git a/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java b/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java
index 8084a4811d6..4ba12056630 100644
--- a/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java
+++ b/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java
@@ -34,6 +34,7 @@ import androidx.window.embedding.ActivityEmbeddingController;
import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.settings.flags.Flags;
import com.android.settings.homepage.SettingsHomepageActivity;
/**
@@ -46,9 +47,13 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 100L;
private static final int RES_NORMAL_BACKGROUND =
- R.drawable.homepage_selectable_item_background;
+ Flags.homepageRevamp()
+ ? R.drawable.homepage_selectable_item_background_v2
+ : R.drawable.homepage_selectable_item_background;
private static final int RES_HIGHLIGHTED_BACKGROUND =
- R.drawable.homepage_highlighted_item_background;
+ Flags.homepageRevamp()
+ ? R.drawable.homepage_highlighted_item_background_v2
+ : R.drawable.homepage_highlighted_item_background;
private final int mTitleColorNormal;
private final int mTitleColorHighlight;
diff --git a/src/com/android/settings/widget/HomepagePreferenceLayoutHelper.java b/src/com/android/settings/widget/HomepagePreferenceLayoutHelper.java
index 6242e23000c..2251180e5f6 100644
--- a/src/com/android/settings/widget/HomepagePreferenceLayoutHelper.java
+++ b/src/com/android/settings/widget/HomepagePreferenceLayoutHelper.java
@@ -22,6 +22,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
+import com.android.settings.flags.Flags;
/** Helper for homepage preference to manage layout. */
public class HomepagePreferenceLayoutHelper {
@@ -39,7 +40,10 @@ public class HomepagePreferenceLayoutHelper {
}
public HomepagePreferenceLayoutHelper(Preference preference) {
- preference.setLayoutResource(R.layout.homepage_preference);
+ preference.setLayoutResource(
+ Flags.homepageRevamp()
+ ? R.layout.homepage_preference_v2
+ : R.layout.homepage_preference);
}
/** Sets whether the icon should be visible */
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
index ee000686b2a..b2449dab39e 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
@@ -30,7 +30,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
-import android.content.pm.PackageInfo;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
@@ -44,7 +44,6 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.shadow.ShadowAudioManager;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowCachedBluetoothDeviceManager;
-import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.flags.Flags;
@@ -68,7 +67,7 @@ import java.util.Collection;
public class ConnectedBluetoothDeviceUpdaterTest {
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
- private static final String FAKE_EXCLUSIVE_MANAGER_NAME = "com.fake.name";
+ private static final String TEST_EXCLUSIVE_MANAGER = "com.test.manager";
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@@ -355,13 +354,16 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_notAllowedExclusiveManagedDevice_addDevice() {
+ public void update_exclusivelyManagedDevice_packageNotInstalled_addDevice()
+ throws Exception {
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- FAKE_EXCLUSIVE_MANAGER_NAME.getBytes());
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doThrow(new PackageManager.NameNotFoundException()).when(mPackageManager)
+ .getApplicationInfo(TEST_EXCLUSIVE_MANAGER, 0);
mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
@@ -370,64 +372,39 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_existingExclusivelyManagedDeviceWithPackageInstalled_removePreference()
+ public void update_exclusivelyManagedDevice_packageNotEnabled_addDevice()
throws Exception {
- final String exclusiveManagerName =
- BluetoothUtils.getExclusiveManagers().stream().findAny().orElse(
- FAKE_EXCLUSIVE_MANAGER_NAME);
+ ApplicationInfo appInfo = new ApplicationInfo();
+ appInfo.enabled = false;
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater
- .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
+ .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- exclusiveManagerName.getBytes());
- doReturn(new PackageInfo()).when(mPackageManager).getPackageInfo(exclusiveManagerName, 0);
-
- mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
-
- verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
- verify(mBluetoothDeviceUpdater, never()).addPreference(mCachedBluetoothDevice);
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_newExclusivelyManagedDeviceWithPackageInstalled_doNotAddPreference()
- throws Exception {
- final String exclusiveManagerName =
- BluetoothUtils.getExclusiveManagers().stream().findAny().orElse(
- FAKE_EXCLUSIVE_MANAGER_NAME);
- mAudioManager.setMode(AudioManager.MODE_NORMAL);
- when(mBluetoothDeviceUpdater
- .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
- when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
- when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- exclusiveManagerName.getBytes());
- doReturn(new PackageInfo()).when(mPackageManager).getPackageInfo(exclusiveManagerName, 0);
-
- mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
-
- verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
- verify(mBluetoothDeviceUpdater, never()).addPreference(mCachedBluetoothDevice);
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_exclusivelyManagedDeviceWithoutPackageInstalled_addDevice()
- throws Exception {
- final String exclusiveManagerName =
- BluetoothUtils.getExclusiveManagers().stream().findAny().orElse(
- FAKE_EXCLUSIVE_MANAGER_NAME);
- mAudioManager.setMode(AudioManager.MODE_NORMAL);
- when(mBluetoothDeviceUpdater
- .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
- when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
- when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- exclusiveManagerName.getBytes());
- doThrow(new PackageManager.NameNotFoundException()).when(mPackageManager).getPackageInfo(
- exclusiveManagerName, 0);
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doReturn(appInfo).when(mPackageManager).getApplicationInfo(TEST_EXCLUSIVE_MANAGER, 0);
mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
+ public void update_exclusivelyManagedDevice_packageInstalledAndEnabled_removePreference()
+ throws Exception {
+ mAudioManager.setMode(AudioManager.MODE_NORMAL);
+ when(mBluetoothDeviceUpdater
+ .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
+ when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
+ when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doReturn(new ApplicationInfo()).when(mPackageManager).getApplicationInfo(
+ TEST_EXCLUSIVE_MANAGER, 0);
+
+ mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+ verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
+ verify(mBluetoothDeviceUpdater, never()).addPreference(mCachedBluetoothDevice);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
index 796120d43f5..e2cf14810c4 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
@@ -29,7 +29,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
-import android.content.pm.PackageInfo;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.platform.test.annotations.RequiresFlagsDisabled;
@@ -41,7 +41,6 @@ import android.util.Pair;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
-import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -66,7 +65,7 @@ import java.util.List;
public class SavedBluetoothDeviceUpdaterTest {
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
- private static final String FAKE_EXCLUSIVE_MANAGER_NAME = "com.fake.name";
+ private static final String TEST_EXCLUSIVE_MANAGER = "com.test.manager";
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@@ -339,42 +338,18 @@ public class SavedBluetoothDeviceUpdaterTest {
@Test
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_notAllowedExclusivelyManagedDevice_addDevice() {
- final Collection cachedDevices = new ArrayList<>();
- cachedDevices.add(mCachedBluetoothDevice);
-
- when(mBluetoothAdapter.isEnabled()).thenReturn(true);
- when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
- when(mDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
- when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
- when(mBluetoothDevice.isConnected()).thenReturn(false);
- when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- FAKE_EXCLUSIVE_MANAGER_NAME.getBytes());
-
- mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
-
- verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice,
- BluetoothDevicePreference.SortType.TYPE_NO_SORT);
- }
-
- @Test
- @RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_existingExclusivelyManagedDeviceWithPackageInstalled_removePreference()
+ public void update_existingExclusivelyManagedDevice_packageEnabled_removePreference()
throws Exception {
final Collection cachedDevices = new ArrayList<>();
- final String exclusiveManagerName =
- BluetoothUtils.getExclusiveManagers().stream().findAny().orElse(
- FAKE_EXCLUSIVE_MANAGER_NAME);
-
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
when(mDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mBluetoothDevice.isConnected()).thenReturn(false);
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- exclusiveManagerName.getBytes());
-
- doReturn(new PackageInfo()).when(mPackageManager).getPackageInfo(exclusiveManagerName, 0);
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doReturn(new ApplicationInfo()).when(mPackageManager).getApplicationInfo(
+ TEST_EXCLUSIVE_MANAGER, 0);
mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, mPreference);
mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
@@ -386,23 +361,19 @@ public class SavedBluetoothDeviceUpdaterTest {
@Test
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_newExclusivelyManagedDeviceWithPackageInstalled_doNotAddPreference()
+ public void update_newExclusivelyManagedDevice_packageEnabled_doNotAddPreference()
throws Exception {
final Collection cachedDevices = new ArrayList<>();
- final String exclusiveManagerName =
- BluetoothUtils.getExclusiveManagers().stream().findAny().orElse(
- FAKE_EXCLUSIVE_MANAGER_NAME);
cachedDevices.add(mCachedBluetoothDevice);
-
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
when(mDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mBluetoothDevice.isConnected()).thenReturn(false);
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- exclusiveManagerName.getBytes());
-
- doReturn(new PackageInfo()).when(mPackageManager).getPackageInfo(exclusiveManagerName, 0);
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doReturn(new ApplicationInfo()).when(mPackageManager).getApplicationInfo(
+ TEST_EXCLUSIVE_MANAGER, 0);
mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
@@ -413,24 +384,42 @@ public class SavedBluetoothDeviceUpdaterTest {
@Test
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
- public void update_exclusivelyManagedDeviceWithoutPackageInstalled_addDevice()
+ public void update_exclusivelyManagedDevice_packageNotInstalled_addDevice()
throws Exception {
final Collection cachedDevices = new ArrayList<>();
- final String exclusiveManagerName =
- BluetoothUtils.getExclusiveManagers().stream().findAny().orElse(
- FAKE_EXCLUSIVE_MANAGER_NAME);
cachedDevices.add(mCachedBluetoothDevice);
-
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
when(mDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mBluetoothDevice.isConnected()).thenReturn(false);
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
- exclusiveManagerName.getBytes());
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doThrow(new PackageManager.NameNotFoundException()).when(mPackageManager)
+ .getApplicationInfo(TEST_EXCLUSIVE_MANAGER, 0);
- doThrow(new PackageManager.NameNotFoundException()).when(mPackageManager).getPackageInfo(
- exclusiveManagerName, 0);
+ mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
+
+ verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice,
+ BluetoothDevicePreference.SortType.TYPE_NO_SORT);
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
+ public void update_exclusivelyManagedDevice_packageNotEnabled_addDevice()
+ throws Exception {
+ final Collection cachedDevices = new ArrayList<>();
+ cachedDevices.add(mCachedBluetoothDevice);
+ ApplicationInfo appInfo = new ApplicationInfo();
+ appInfo.enabled = false;
+ when(mBluetoothAdapter.isEnabled()).thenReturn(true);
+ when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
+ when(mDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
+ when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
+ when(mBluetoothDevice.isConnected()).thenReturn(false);
+ when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
+ TEST_EXCLUSIVE_MANAGER.getBytes());
+ doReturn(appInfo).when(mPackageManager).getApplicationInfo(TEST_EXCLUSIVE_MANAGER, 0);
mBluetoothDeviceUpdater.update(mCachedBluetoothDevice);
diff --git a/tests/robotests/src/com/android/settings/accessibility/ColorContrastFragmentTest.java b/tests/robotests/src/com/android/settings/display/ColorContrastFragmentTest.java
similarity index 96%
rename from tests/robotests/src/com/android/settings/accessibility/ColorContrastFragmentTest.java
rename to tests/robotests/src/com/android/settings/display/ColorContrastFragmentTest.java
index 3077637a8e4..47a7363b531 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ColorContrastFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/ColorContrastFragmentTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.accessibility;
+package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
@@ -28,6 +28,7 @@ import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
+import com.android.settings.accessibility.ShortcutsSettingsFragment;
import com.android.settings.testutils.XmlTestUtils;
import org.junit.Before;
diff --git a/tests/robotests/src/com/android/settings/accessibility/ContrastPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ContrastPreferenceControllerTest.java
similarity index 55%
rename from tests/robotests/src/com/android/settings/accessibility/ContrastPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/display/ContrastPreferenceControllerTest.java
index 07c3b54f946..1ddc81960b6 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ContrastPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ContrastPreferenceControllerTest.java
@@ -14,15 +14,22 @@
* limitations under the License.
*/
-package com.android.settings.accessibility;
+package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
+import android.content.Context;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
+
import androidx.test.core.app.ApplicationProvider;
+import com.android.settings.accessibility.Flags;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -31,19 +38,30 @@ import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class ContrastPreferenceControllerTest {
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
private static final String PREFERENCE_KEY = "preference_key";
+ private Context mContext;
private ContrastPreferenceController mController;
@Before
public void setUp() {
- mController = new ContrastPreferenceController(ApplicationProvider.getApplicationContext(),
- PREFERENCE_KEY);
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new ContrastPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
- public void getAvailabilityStatus_shouldReturnUnavailable() {
+ @EnableFlags(Flags.FLAG_ENABLE_COLOR_CONTRAST_CONTROL)
+ public void getAvailabilityStatus_flagsEnabled_shouldReturnAvailable() {
assertThat(mController.getAvailabilityStatus())
- .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ .isEqualTo(BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ENABLE_COLOR_CONTRAST_CONTROL)
+ public void getAvailabilityStatus_flagsDisabled_shouldReturnUnsupported() {
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ContrastSelectorPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ContrastSelectorPreferenceControllerTest.java
similarity index 98%
rename from tests/robotests/src/com/android/settings/accessibility/ContrastSelectorPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/display/ContrastSelectorPreferenceControllerTest.java
index 83d9cb957b4..0d490a88347 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ContrastSelectorPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/ContrastSelectorPreferenceControllerTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.accessibility;
+package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
index f62fdb8ce6f..44a16f19cca 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
@@ -50,6 +50,7 @@ import android.widget.TextView;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.FakeFeatureFactory;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +59,7 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -84,10 +86,13 @@ public final class BatteryChartPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
Locale.setDefault(new Locale("en_US"));
org.robolectric.shadows.ShadowSettings.set24HourTimeFormat(false);
- TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ final TimeZone timeZone = TimeZone.getTimeZone("UTC");
+ TimeZone.setDefault(timeZone);
DataProcessor.sTestSystemAppsPackageNames = Set.of();
mFeatureFactory = FakeFeatureFactory.setupForTest();
mContext = spy(RuntimeEnvironment.application);
+ BatteryLevelData.sTestCalendar = Calendar.getInstance();
+ BatteryLevelData.sTestCalendar.setTimeZone(timeZone);
doReturn(mContext).when(mContext).getApplicationContext();
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(true).when(mUserManager).isUserUnlocked(anyInt());
@@ -115,6 +120,11 @@ public final class BatteryChartPreferenceControllerTest {
new BatteryEntry.NameAndIcon("fakeName", /* icon= */ null, /* iconId= */ 1));
}
+ @After
+ public void tearDown() {
+ BatteryLevelData.sTestCalendar = null;
+ }
+
@Test
public void onDestroy_activityIsChanging_clearBatteryEntryCache() {
doReturn(true).when(mSettingsActivity).isChangingConfigurations();
@@ -141,7 +151,8 @@ public final class BatteryChartPreferenceControllerTest {
reset(mHourlyChartView);
setupHourlyChartViewAnimationMock();
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(6));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 0));
verify(mDailyChartView, atLeastOnce()).setVisibility(View.GONE);
// Ignore fast refresh ui from the data processor callback.
@@ -178,7 +189,8 @@ public final class BatteryChartPreferenceControllerTest {
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS,
mBatteryChartPreferenceController.mDailyChartLabelTextGenerator);
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(60));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0));
verify(mDailyChartView, atLeastOnce()).setVisibility(View.VISIBLE);
verify(mViewPropertyAnimator, atLeastOnce()).alpha(0f);
@@ -283,7 +295,8 @@ public final class BatteryChartPreferenceControllerTest {
public void onBatteryLevelDataUpdate_oneDay_showHourlyChartOnly() {
doReturn(View.GONE).when(mHourlyChartView).getVisibility();
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(6));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 0));
verify(mChartSummaryTextView).setVisibility(View.VISIBLE);
verify(mDailyChartView).setVisibility(View.GONE);
@@ -295,7 +308,8 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(View.GONE).when(mHourlyChartView).getVisibility();
mBatteryChartPreferenceController.mDailyChartIndex = SELECTED_INDEX_ALL;
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(60));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0));
verify(mChartSummaryTextView).setVisibility(View.VISIBLE);
verify(mDailyChartView).setVisibility(View.VISIBLE);
@@ -307,7 +321,8 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(View.GONE).when(mHourlyChartView).getVisibility();
mBatteryChartPreferenceController.mDailyChartIndex = 0;
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(60));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0));
verify(mChartSummaryTextView).setVisibility(View.VISIBLE);
verify(mDailyChartView).setVisibility(View.VISIBLE);
@@ -379,7 +394,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void selectedSlotText_selectAllDaysAllHours_returnNull() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(60));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = SELECTED_INDEX_ALL;
mBatteryChartPreferenceController.mHourlyChartIndex = SELECTED_INDEX_ALL;
@@ -390,7 +406,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void selectedSlotText_onlyOneDayDataSelectAllHours_returnNull() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(6));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 0;
mBatteryChartPreferenceController.mHourlyChartIndex = SELECTED_INDEX_ALL;
@@ -401,7 +418,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void selectedSlotText_selectADayAllHours_onlyDayText() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(60));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 1;
mBatteryChartPreferenceController.mHourlyChartIndex = SELECTED_INDEX_ALL;
@@ -412,7 +430,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void selectedSlotText_onlyOneDayDataSelectAnHour_onlyHourText() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(6));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 0;
mBatteryChartPreferenceController.mHourlyChartIndex = 2;
@@ -426,7 +445,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void selectedSlotText_SelectADayAnHour_dayAndHourText() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(60));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 1;
mBatteryChartPreferenceController.mHourlyChartIndex = 8;
@@ -439,8 +459,9 @@ public final class BatteryChartPreferenceControllerTest {
}
@Test
- public void selectedSlotText_selectFirstSlot_withMinuteText() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(6));
+ public void selectedSlotText_selectFirstSlotAfterFullCharged_withMinuteText() {
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 0;
mBatteryChartPreferenceController.mHourlyChartIndex = 0;
@@ -452,9 +473,29 @@ public final class BatteryChartPreferenceControllerTest {
.isEqualTo("Battery level percentage from 100% to 99%");
}
+ @Test
+ public void selectedSlotText_selectFirstSlotAfterTimeUpdated_withMinuteText() {
+ BatteryLevelData batteryLevelData =
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 10);
+ assertThat(batteryLevelData.getHourlyBatteryLevelsPerDay().get(0).isStartTimestamp())
+ .isTrue();
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 10));
+ mBatteryChartPreferenceController.mDailyChartIndex = 0;
+ mBatteryChartPreferenceController.mHourlyChartIndex = 0;
+
+ assertThat(mBatteryChartPreferenceController.getSlotInformation(false))
+ .isEqualTo("7:01 AM - 8 AM");
+ assertThat(mBatteryChartPreferenceController.getSlotInformation(true))
+ .isEqualTo("7:01 AM to 8 AM");
+ assertThat(mBatteryChartPreferenceController.getBatteryLevelPercentageInfo())
+ .isEqualTo("Battery level percentage from 90% to 89%");
+ }
+
@Test
public void selectedSlotText_selectLastSlot_withNowText() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(6));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 6, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 0;
mBatteryChartPreferenceController.mHourlyChartIndex = 3;
@@ -468,7 +509,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void selectedSlotText_selectOnlySlot_withMinuteAndNowText() {
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(1));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 1, /* levelOffset= */ 0));
mBatteryChartPreferenceController.mDailyChartIndex = 0;
mBatteryChartPreferenceController.mHourlyChartIndex = 0;
@@ -493,7 +535,8 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController.mHourlyChartIndex = -1;
mBatteryChartPreferenceController.onCreate(bundle);
- mBatteryChartPreferenceController.onBatteryLevelDataUpdate(createBatteryLevelData(25));
+ mBatteryChartPreferenceController.onBatteryLevelDataUpdate(
+ createBatteryLevelData(/* numOfHours= */ 25, /* levelOffset= */ 0));
assertThat(mBatteryChartPreferenceController.mDailyChartIndex)
.isEqualTo(expectedDailyIndex);
@@ -503,7 +546,8 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void getTotalHours_getExpectedResult() {
- BatteryLevelData batteryLevelData = createBatteryLevelData(60);
+ BatteryLevelData batteryLevelData =
+ createBatteryLevelData(/* numOfHours= */ 60, /* levelOffset= */ 0);
final int totalHour = BatteryChartPreferenceController.getTotalHours(batteryLevelData);
@@ -516,10 +560,10 @@ public final class BatteryChartPreferenceControllerTest {
return 1619247600000L + index * DateUtils.HOUR_IN_MILLIS;
}
- private static BatteryLevelData createBatteryLevelData(int numOfHours) {
+ private static BatteryLevelData createBatteryLevelData(int numOfHours, int levelOffset) {
Map batteryLevelMap = new ArrayMap<>();
for (int index = 0; index < numOfHours; index += 2) {
- final Integer level = 100 - index;
+ final Integer level = 100 - index - levelOffset;
Long timestamp = generateTimestamp(index);
if (index == 0) {
timestamp += DateUtils.MINUTE_IN_MILLIS;
@@ -529,6 +573,8 @@ public final class BatteryChartPreferenceControllerTest {
}
long current = generateTimestamp(numOfHours - 1) + DateUtils.MINUTE_IN_MILLIS * 2;
batteryLevelMap.put(current, 66);
+
+ BatteryLevelData.sTestCalendar.setTimeInMillis(current);
DataProcessor.sTestCurrentTimeMillis = current;
return new BatteryLevelData(batteryLevelMap);
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java
index df330a36ac5..545f7733f41 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BootBroadcastReceiverTest.java
@@ -35,7 +35,6 @@ import com.android.settings.testutils.BatteryTestUtils;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -64,9 +63,8 @@ public final class BootBroadcastReceiverTest {
// Inserts fake data into database for testing.
final BatteryStateDatabase database = BatteryTestUtils.setUpBatteryStateDatabase(mContext);
- BatteryTestUtils.insertDataToBatteryStateTable(
- mContext, Clock.systemUTC().millis(), "com.android.systemui");
mDao = database.batteryStateDao();
+ mDao.clearAll();
clearSharedPreferences();
}
@@ -129,10 +127,13 @@ public final class BootBroadcastReceiverTest {
assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNull();
}
- @Ignore("b/314921894")
@Test
- public void onReceive_withTimeChangedIntent_clearsAllDataAndRefreshesJob()
+ public void onReceive_withTimeChangedIntentSetEarlierTime_refreshesJob()
throws InterruptedException {
+ BatteryTestUtils.insertDataToBatteryStateTable(
+ mContext, Clock.systemUTC().millis() + 60000, "com.android.systemui");
+ assertThat(mDao.getAllAfter(0).size()).isEqualTo(1);
+
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_TIME_CHANGED));
TimeUnit.MILLISECONDS.sleep(100);
@@ -140,6 +141,52 @@ public final class BootBroadcastReceiverTest {
assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
}
+ @Test
+ public void onReceive_withTimeChangedIntentSetLaterTime_clearNoDataAndRefreshesJob()
+ throws InterruptedException {
+ BatteryTestUtils.insertDataToBatteryStateTable(
+ mContext, Clock.systemUTC().millis() - 60000, "com.android.systemui");
+ assertThat(mDao.getAllAfter(0).size()).isEqualTo(1);
+
+ mReceiver.onReceive(mContext, new Intent(Intent.ACTION_TIME_CHANGED));
+
+ TimeUnit.MILLISECONDS.sleep(100);
+ assertThat(mDao.getAllAfter(0).size()).isEqualTo(1);
+ assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
+ }
+
+ @Test
+ public void onReceive_withTimeFormatChangedIntent_skipRefreshJob() throws InterruptedException {
+ BatteryTestUtils.insertDataToBatteryStateTable(
+ mContext, Clock.systemUTC().millis() + 60000, "com.android.systemui");
+ assertThat(mDao.getAllAfter(0).size()).isEqualTo(1);
+
+ mReceiver.onReceive(
+ mContext,
+ new Intent(Intent.EXTRA_INTENT)
+ .putExtra(
+ Intent.EXTRA_TIME_PREF_24_HOUR_FORMAT,
+ Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR));
+
+ TimeUnit.MILLISECONDS.sleep(100);
+ assertThat(mDao.getAllAfter(0).size()).isEqualTo(1);
+ assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNull();
+ }
+
+ @Test
+ public void onReceive_withTimeZoneChangedIntent_clearAllDataAndRefreshesJob()
+ throws InterruptedException {
+ BatteryTestUtils.insertDataToBatteryStateTable(
+ mContext, Clock.systemUTC().millis(), "com.android.systemui");
+ assertThat(mDao.getAllAfter(0).size()).isEqualTo(1);
+
+ mReceiver.onReceive(mContext, new Intent(Intent.ACTION_TIMEZONE_CHANGED));
+
+ TimeUnit.MILLISECONDS.sleep(100);
+ assertThat(mDao.getAllAfter(0)).isEmpty();
+ assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNotNull();
+ }
+
@Test
public void invokeJobRecheck_broadcastsIntent() {
BootBroadcastReceiver.invokeJobRecheck(mContext);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessManagerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessManagerTest.java
index 7faca0d0960..60428014048 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessManagerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessManagerTest.java
@@ -170,7 +170,8 @@ public final class DataProcessManagerTest {
final Map batteryLevelMap1 =
Map.of(timestamps1.get(0), 100, timestamps1.get(1), 100, timestamps1.get(2), 100);
hourlyBatteryLevelsPerDay.add(
- new BatteryLevelData.PeriodBatteryLevelData(batteryLevelMap1, timestamps1));
+ new BatteryLevelData.PeriodBatteryLevelData(
+ batteryLevelMap1, timestamps1, /* isStartTimestamp= */ false));
// Adds the day 2 data.
hourlyBatteryLevelsPerDay.add(null);
// Adds the day 3 data.
@@ -178,7 +179,8 @@ public final class DataProcessManagerTest {
final Map batteryLevelMap2 =
Map.of(timestamps2.get(0), 100, timestamps2.get(1), 100);
hourlyBatteryLevelsPerDay.add(
- new BatteryLevelData.PeriodBatteryLevelData(batteryLevelMap2, timestamps2));
+ new BatteryLevelData.PeriodBatteryLevelData(
+ batteryLevelMap2, timestamps2, /* isStartTimestamp= */ false));
// Fake current usage data.
final UsageEvents.Event event1 =
getUsageEvent(UsageEvents.Event.ACTIVITY_RESUMED, /* timestamp= */ 1, packageName);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
index 28973430ce9..ae4c56d035a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
@@ -209,7 +209,8 @@ public final class DataProcessorTest {
final Map batteryLevelMap1 =
Map.of(timestamps1.get(0), 100, timestamps1.get(1), 100, timestamps1.get(2), 100);
hourlyBatteryLevelsPerDay.add(
- new BatteryLevelData.PeriodBatteryLevelData(batteryLevelMap1, timestamps1));
+ new BatteryLevelData.PeriodBatteryLevelData(
+ batteryLevelMap1, timestamps1, /* isStartTimestamp= */ false));
// Adds the day 2 data.
hourlyBatteryLevelsPerDay.add(null);
// Adds the day 3 data.
@@ -217,7 +218,8 @@ public final class DataProcessorTest {
final Map batteryLevelMap2 =
Map.of(timestamps2.get(0), 100, timestamps2.get(1), 100);
hourlyBatteryLevelsPerDay.add(
- new BatteryLevelData.PeriodBatteryLevelData(batteryLevelMap2, timestamps2));
+ new BatteryLevelData.PeriodBatteryLevelData(
+ batteryLevelMap2, timestamps2, /* isStartTimestamp= */ false));
final List appUsageEventList = new ArrayList<>();
// Adds some events before the start timestamp.
appUsageEventList.add(
@@ -365,7 +367,8 @@ public final class DataProcessorTest {
final List hourlyBatteryLevelsPerDay =
new ArrayList<>();
hourlyBatteryLevelsPerDay.add(
- new BatteryLevelData.PeriodBatteryLevelData(new ArrayMap<>(), new ArrayList<>()));
+ new BatteryLevelData.PeriodBatteryLevelData(
+ new ArrayMap<>(), new ArrayList<>(), /* isStartTimestamp= */ false));
assertThat(
DataProcessor.generateAppUsagePeriodMap(
mContext,
@@ -858,7 +861,8 @@ public final class DataProcessorTest {
new ArrayList<>();
hourlyBatteryLevelsPerDay.add(
- new BatteryLevelData.PeriodBatteryLevelData(new ArrayMap<>(), new ArrayList<>()));
+ new BatteryLevelData.PeriodBatteryLevelData(
+ new ArrayMap<>(), new ArrayList<>(), /* isStartTimestamp= */ false));
assertThat(
DataProcessor.getBatteryDiffDataMap(
diff --git a/tests/robotests/src/com/android/settings/homepage/TopLevelSettingsTest.java b/tests/robotests/src/com/android/settings/homepage/TopLevelSettingsTest.java
index 44f44aa8589..36c48e3cdd7 100644
--- a/tests/robotests/src/com/android/settings/homepage/TopLevelSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/TopLevelSettingsTest.java
@@ -16,8 +16,6 @@
package com.android.settings.homepage;
-import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
@@ -59,11 +57,6 @@ public class TopLevelSettingsTest {
mSettings.onAttach(mContext);
}
- @Test
- public void shouldForceRoundedIcon_true() {
- assertThat(mSettings.shouldForceRoundedIcon()).isTrue();
- }
-
@Test
public void onCreatePreferences_shouldTintPreferenceIcon() {
final Preference preference = new Preference(mContext);
diff --git a/tests/robotests/src/com/android/settings/panel/FakePanelContent.java b/tests/robotests/src/com/android/settings/panel/FakePanelContent.java
index 06beb3ecf51..17787cd01ae 100644
--- a/tests/robotests/src/com/android/settings/panel/FakePanelContent.java
+++ b/tests/robotests/src/com/android/settings/panel/FakePanelContent.java
@@ -29,7 +29,10 @@ import java.util.List;
/**
* Fake PanelContent for testing.
+ *
+ * @deprecated this is no longer used after V and will be removed.
*/
+@Deprecated(forRemoval = true)
public class FakePanelContent implements PanelContent {
public static final String FAKE_ACTION = "fake_action";
diff --git a/tests/robotests/src/com/android/settings/panel/FakeSettingsPanelActivity.java b/tests/robotests/src/com/android/settings/panel/FakeSettingsPanelActivity.java
index ba763ce3a06..fe19f287794 100644
--- a/tests/robotests/src/com/android/settings/panel/FakeSettingsPanelActivity.java
+++ b/tests/robotests/src/com/android/settings/panel/FakeSettingsPanelActivity.java
@@ -19,6 +19,7 @@ package com.android.settings.panel;
import android.content.ComponentName;
import android.content.Intent;
+@Deprecated(forRemoval = true)
public class FakeSettingsPanelActivity extends SettingsPanelActivity {
@Override
public ComponentName getCallingActivity() {
diff --git a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
index 42f3977a227..e77eeab569b 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
@@ -54,6 +54,7 @@ import org.robolectric.annotation.Config;
import java.util.Objects;
+@Deprecated(forRemoval = true)
@Ignore("b/313576125")
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
diff --git a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
index 87a798a2197..e778cb8cec8 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
@@ -67,6 +67,7 @@ import org.robolectric.annotation.Implements;
import java.util.LinkedHashMap;
import java.util.Map;
+@Deprecated(forRemoval = true)
@RunWith(RobolectricTestRunner.class)
@Config(shadows = PanelSlicesAdapterTest.ShadowLayoutInflater.class)
public class PanelSlicesAdapterTest {
diff --git a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
index e550284b028..4f03abb664b 100644
--- a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
+++ b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
@@ -59,6 +59,7 @@ import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
+@Deprecated(forRemoval = true)
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowFragment.class,
diff --git a/tests/spa_unit/src/com/android/settings/datausage/BillingCyclePreferenceTest.kt b/tests/spa_unit/src/com/android/settings/datausage/BillingCyclePreferenceTest.kt
index 4bf385169d3..1db0d48f211 100644
--- a/tests/spa_unit/src/com/android/settings/datausage/BillingCyclePreferenceTest.kt
+++ b/tests/spa_unit/src/com/android/settings/datausage/BillingCyclePreferenceTest.kt
@@ -27,6 +27,8 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.R
import com.android.settings.datausage.lib.BillingCycleRepository
+import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.flow.flowOf
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -39,7 +41,9 @@ class BillingCyclePreferenceTest {
@get:Rule
val composeTestRule = createComposeRule()
- private val mockBillingCycleRepository = mock()
+ private val mockBillingCycleRepository = mock {
+ on { isModifiableFlow(SUB_ID) } doReturn emptyFlow()
+ }
private val context: Context = ApplicationProvider.getApplicationContext()
@@ -56,7 +60,7 @@ class BillingCyclePreferenceTest {
@Test
fun setTemplate_modifiable_enabled() {
mockBillingCycleRepository.stub {
- on { isModifiable(SUB_ID) } doReturn true
+ on { isModifiableFlow(SUB_ID) } doReturn flowOf(true)
}
setTemplate()
@@ -67,7 +71,7 @@ class BillingCyclePreferenceTest {
@Test
fun setTemplate_notModifiable_notEnabled() {
mockBillingCycleRepository.stub {
- on { isModifiable(SUB_ID) } doReturn false
+ on { isModifiableFlow(SUB_ID) } doReturn flowOf(false)
}
setTemplate()
diff --git a/tests/spa_unit/src/com/android/settings/datausage/lib/BillingCycleRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/datausage/lib/BillingCycleRepositoryTest.kt
index deaaf2dd1f0..22e5dfe14b4 100644
--- a/tests/spa_unit/src/com/android/settings/datausage/lib/BillingCycleRepositoryTest.kt
+++ b/tests/spa_unit/src/com/android/settings/datausage/lib/BillingCycleRepositoryTest.kt
@@ -22,8 +22,10 @@ import android.os.UserManager
import android.telephony.TelephonyManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
import com.android.settingslib.spaprivileged.framework.common.userManager
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
@@ -55,43 +57,43 @@ class BillingCycleRepositoryTest {
private val repository = BillingCycleRepository(context, mockNetworkManagementService)
@Test
- fun isModifiable_bandwidthControlDisabled_returnFalse() {
+ fun isModifiable_bandwidthControlDisabled_returnFalse() = runBlocking {
whenever(mockNetworkManagementService.isBandwidthControlEnabled).thenReturn(false)
- val modifiable = repository.isModifiable(SUB_ID)
+ val modifiable = repository.isModifiableFlow(SUB_ID).firstWithTimeoutOrNull()
assertThat(modifiable).isFalse()
}
@Test
- fun isModifiable_notAdminUser_returnFalse() {
+ fun isModifiable_notAdminUser_returnFalse() = runBlocking {
whenever(mockUserManager.isAdminUser).thenReturn(false)
- val modifiable = repository.isModifiable(SUB_ID)
+ val modifiable = repository.isModifiableFlow(SUB_ID).firstWithTimeoutOrNull()
assertThat(modifiable).isFalse()
}
@Test
- fun isModifiable_dataDisabled_returnFalse() {
+ fun isModifiable_dataDisabled_returnFalse() = runBlocking {
whenever(
mockTelephonyManager.isDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER)
).thenReturn(false)
- val modifiable = repository.isModifiable(SUB_ID)
+ val modifiable = repository.isModifiableFlow(SUB_ID).firstWithTimeoutOrNull()
assertThat(modifiable).isFalse()
}
@Test
- fun isModifiable_meetAllRequirements_returnTrue() {
+ fun isModifiable_meetAllRequirements_returnTrue() = runBlocking {
whenever(mockNetworkManagementService.isBandwidthControlEnabled).thenReturn(true)
whenever(mockUserManager.isAdminUser).thenReturn(true)
whenever(
mockTelephonyManager.isDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER)
).thenReturn(true)
- val modifiable = repository.isModifiable(SUB_ID)
+ val modifiable = repository.isModifiableFlow(SUB_ID).firstWithTimeoutOrNull()
assertThat(modifiable).isTrue()
}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.kt
new file mode 100644
index 00000000000..0ddaa520baf
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.kt
@@ -0,0 +1,102 @@
+/*
+ * 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.telephony
+
+import android.content.Context
+import android.telephony.SubscriptionInfo
+import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.core.BasePreferenceController.AVAILABLE
+import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
+import com.google.common.truth.Truth.assertThat
+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 DisableSimFooterPreferenceControllerTest {
+
+ private val subscriptionInfo = mock {
+ on { subscriptionId } doReturn SUB_ID
+ }
+
+ private var context: Context = ApplicationProvider.getApplicationContext()
+
+ private val mockSubscriptionRepository = mock {
+ on { getSelectableSubscriptionInfoList() } doReturn listOf(subscriptionInfo)
+ }
+
+ private var controller = DisableSimFooterPreferenceController(
+ context = context,
+ preferenceKey = PREFERENCE_KEY,
+ subscriptionRepository = mockSubscriptionRepository,
+ ).apply { init(SUB_ID) }
+
+ @Test
+ fun getAvailabilityStatus_invalidId_notAvailable() {
+ val availabilityStatus = controller.getAvailabilityStatus(INVALID_SUBSCRIPTION_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_eSim_notAvailable() {
+ subscriptionInfo.stub {
+ on { isEmbedded } doReturn true
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_pSimAndCannotDisable_available() {
+ mockSubscriptionRepository.stub {
+ on { canDisablePhysicalSubscription() } doReturn false
+ }
+ subscriptionInfo.stub {
+ on { isEmbedded } doReturn false
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+
+ assertThat(availabilityStatus).isEqualTo(AVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_pSimAndCanDisable_notAvailable() {
+ mockSubscriptionRepository.stub {
+ on { canDisablePhysicalSubscription() } doReturn true
+ }
+ subscriptionInfo.stub {
+ on { isEmbedded } doReturn false
+ }
+
+ val availabilityStatus = controller.getAvailabilityStatus(SUB_ID)
+
+ assertThat(availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ private companion object {
+ const val PREFERENCE_KEY = "preference_key"
+ const val SUB_ID = 111
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt
index 60589358e3a..65e8c47023d 100644
--- a/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/TelephonyRepositoryTest.kt
@@ -93,7 +93,7 @@ class TelephonyRepositoryTest {
@Test
fun isDataEnabled_invalidSub_returnFalse() = runBlocking {
- val state = repository.isDataEnabled(
+ val state = repository.isDataEnabledFlow(
subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
)
@@ -108,9 +108,7 @@ class TelephonyRepositoryTest {
} doReturn true
}
- val state = repository.isDataEnabled(
- subId = SUB_ID,
- )
+ val state = repository.isDataEnabledFlow(subId = SUB_ID)
assertThat(state.firstWithTimeoutOrNull()).isTrue()
}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/scan/NetworkScanRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/scan/NetworkScanRepositoryTest.kt
index 070c779b5ea..c0b918fcf5d 100644
--- a/tests/spa_unit/src/com/android/settings/network/telephony/scan/NetworkScanRepositoryTest.kt
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/scan/NetworkScanRepositoryTest.kt
@@ -32,9 +32,6 @@ import android.telephony.TelephonyManager.NETWORK_CLASS_BITMASK_5G
import android.telephony.TelephonyScanManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanCellInfos
-import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanComplete
-import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanError
import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
import com.android.settingslib.spa.testutils.toListWithTimeout
import com.google.common.truth.Truth.assertThat
@@ -88,7 +85,12 @@ class NetworkScanRepositoryTest {
callback?.onResults(cellInfos)
- assertThat(listDeferred.await()).containsExactly(NetworkScanCellInfos(cellInfos))
+ assertThat(listDeferred.await()).containsExactly(
+ NetworkScanRepository.NetworkScanResult(
+ state = NetworkScanRepository.NetworkScanState.ACTIVE,
+ cellInfos = cellInfos,
+ )
+ )
}
@Test
@@ -100,7 +102,12 @@ class NetworkScanRepositoryTest {
callback?.onComplete()
- assertThat(listDeferred.await()).containsExactly(NetworkScanComplete)
+ assertThat(listDeferred.await()).containsExactly(
+ NetworkScanRepository.NetworkScanResult(
+ state = NetworkScanRepository.NetworkScanState.COMPLETE,
+ cellInfos = emptyList(),
+ )
+ )
}
@Test
@@ -112,7 +119,12 @@ class NetworkScanRepositoryTest {
callback?.onError(1)
- assertThat(listDeferred.await()).containsExactly(NetworkScanError(1))
+ assertThat(listDeferred.await()).containsExactly(
+ NetworkScanRepository.NetworkScanResult(
+ state = NetworkScanRepository.NetworkScanState.ERROR,
+ cellInfos = emptyList(),
+ )
+ )
}
@Test
@@ -133,12 +145,13 @@ class NetworkScanRepositoryTest {
callback?.onResults(cellInfos)
assertThat(listDeferred.await()).containsExactly(
- NetworkScanCellInfos(
- listOf(
+ NetworkScanRepository.NetworkScanResult(
+ state = NetworkScanRepository.NetworkScanState.ACTIVE,
+ cellInfos = listOf(
createCellInfoLte("123", false),
createCellInfoLte("124", true),
createCellInfoGsm("123", false),
- )
+ ),
)
)
}
@@ -162,8 +175,9 @@ class NetworkScanRepositoryTest {
callback?.onResults(cellInfos)
assertThat(listDeferred.await()).containsExactly(
- NetworkScanCellInfos(
- listOf(
+ NetworkScanRepository.NetworkScanResult(
+ state = NetworkScanRepository.NetworkScanState.ACTIVE,
+ cellInfos = listOf(
createCellInfoLte("123", false),
createCellInfoLte("123", true),
createCellInfoLte("124", false),
diff --git a/tests/unit/src/com/android/settings/conecteddevice/threadnetwork/ThreadNetworkPreferenceControllerTest.kt b/tests/unit/src/com/android/settings/conecteddevice/threadnetwork/ThreadNetworkPreferenceControllerTest.kt
deleted file mode 100644
index 976096c7cc4..00000000000
--- a/tests/unit/src/com/android/settings/conecteddevice/threadnetwork/ThreadNetworkPreferenceControllerTest.kt
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * 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.connecteddevice.threadnetwork
-
-import android.content.BroadcastReceiver
-import android.content.Context
-import android.content.Intent
-import android.net.thread.ThreadNetworkController.STATE_DISABLED
-import android.net.thread.ThreadNetworkController.STATE_DISABLING
-import android.net.thread.ThreadNetworkController.STATE_ENABLED
-import android.net.thread.ThreadNetworkController.StateCallback
-import android.net.thread.ThreadNetworkException
-import android.os.OutcomeReceiver
-import android.platform.test.flag.junit.SetFlagsRule
-import android.provider.Settings
-import androidx.core.content.ContextCompat
-import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.LifecycleOwner
-import androidx.preference.PreferenceManager
-import androidx.preference.SwitchPreference
-import androidx.test.core.app.ApplicationProvider
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settings.R
-import com.android.settings.core.BasePreferenceController.AVAILABLE
-import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
-import com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING
-import com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE
-import com.android.settings.connecteddevice.threadnetwork.ThreadNetworkPreferenceController.BaseThreadNetworkController
-import com.android.settings.flags.Flags
-import com.google.common.truth.Truth.assertThat
-import org.junit.Before
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.mockito.ArgumentCaptor
-import org.mockito.ArgumentMatchers.any
-import org.mockito.Mockito.mock
-import org.mockito.Mockito.spy
-import org.mockito.Mockito.verify
-import java.util.concurrent.Executor
-
-/** Unit tests for [ThreadNetworkPreferenceController]. */
-@RunWith(AndroidJUnit4::class)
-class ThreadNetworkPreferenceControllerTest {
- @get:Rule
- val mSetFlagsRule = SetFlagsRule()
- private lateinit var context: Context
- private lateinit var executor: Executor
- private lateinit var controller: ThreadNetworkPreferenceController
- private lateinit var fakeThreadNetworkController: FakeThreadNetworkController
- private lateinit var preference: SwitchPreference
- private val broadcastReceiverArgumentCaptor = ArgumentCaptor.forClass(
- BroadcastReceiver::class.java
- )
-
- @Before
- fun setUp() {
- mSetFlagsRule.enableFlags(Flags.FLAG_THREAD_SETTINGS_ENABLED)
- context = spy(ApplicationProvider.getApplicationContext())
- executor = ContextCompat.getMainExecutor(context)
- fakeThreadNetworkController = FakeThreadNetworkController(executor)
- controller = newControllerWithThreadFeatureSupported(true)
- val preferenceManager = PreferenceManager(context)
- val preferenceScreen = preferenceManager.createPreferenceScreen(context)
- preference = SwitchPreference(context)
- preference.key = "thread_network_settings"
- preferenceScreen.addPreference(preference)
- controller.displayPreference(preferenceScreen)
-
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0)
- }
-
- private fun newControllerWithThreadFeatureSupported(
- present: Boolean
- ): ThreadNetworkPreferenceController {
- return ThreadNetworkPreferenceController(
- context,
- "thread_network_settings" /* key */,
- executor,
- if (present) fakeThreadNetworkController else null
- )
- }
-
- @Test
- fun availabilityStatus_flagDisabled_returnsConditionallyUnavailable() {
- mSetFlagsRule.disableFlags(Flags.FLAG_THREAD_SETTINGS_ENABLED)
- assertThat(controller.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE)
- }
-
- @Test
- fun availabilityStatus_airPlaneModeOn_returnsDisabledDependentSetting() {
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 1)
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(controller.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING)
- }
-
- @Test
- fun availabilityStatus_airPlaneModeOff_returnsAvailable() {
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0)
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE)
- }
-
- @Test
- fun availabilityStatus_threadFeatureNotSupported_returnsUnsupported() {
- controller = newControllerWithThreadFeatureSupported(false)
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(fakeThreadNetworkController.registeredStateCallback).isNull()
- assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE)
- }
-
- @Test
- fun isChecked_threadSetEnabled_returnsTrue() {
- fakeThreadNetworkController.setEnabled(true, executor) { }
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(controller.isChecked).isTrue()
- }
-
- @Test
- fun isChecked_threadSetDisabled_returnsFalse() {
- fakeThreadNetworkController.setEnabled(false, executor) { }
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(controller.isChecked).isFalse()
- }
-
- @Test
- fun setChecked_setChecked_threadIsEnabled() {
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- controller.setChecked(true)
-
- assertThat(fakeThreadNetworkController.isEnabled).isTrue()
- }
-
- @Test
- fun setChecked_setUnchecked_threadIsDisabled() {
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- controller.setChecked(false)
-
- assertThat(fakeThreadNetworkController.isEnabled).isFalse()
- }
-
- @Test
- fun updatePreference_airPlaneModeOff_preferenceEnabled() {
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0)
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(preference.isEnabled).isTrue()
- assertThat(preference.summary).isEqualTo(
- context.resources.getString(R.string.thread_network_settings_summary)
- )
- }
-
- @Test
- fun updatePreference_airPlaneModeOn_preferenceDisabled() {
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 1)
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
-
- assertThat(preference.isEnabled).isFalse()
- assertThat(preference.summary).isEqualTo(
- context.resources.getString(R.string.thread_network_settings_summary_airplane_mode)
- )
- }
-
- @Test
- fun updatePreference_airPlaneModeTurnedOn_preferenceDisabled() {
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0)
- startControllerAndCaptureCallbacks()
-
- Settings.Global.putInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 1)
- broadcastReceiverArgumentCaptor.value.onReceive(context, Intent())
-
- assertThat(preference.isEnabled).isFalse()
- assertThat(preference.summary).isEqualTo(
- context.resources.getString(R.string.thread_network_settings_summary_airplane_mode)
- )
- }
-
- private fun startControllerAndCaptureCallbacks() {
- controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
- verify(context)!!.registerReceiver(broadcastReceiverArgumentCaptor.capture(), any())
- }
-
- private class FakeThreadNetworkController(private val executor: Executor) :
- BaseThreadNetworkController {
- var isEnabled = true
- private set
- var registeredStateCallback: StateCallback? = null
- private set
-
- override fun setEnabled(
- enabled: Boolean,
- executor: Executor,
- receiver: OutcomeReceiver
- ) {
- isEnabled = enabled
- if (registeredStateCallback != null) {
- if (!isEnabled) {
- executor.execute {
- registeredStateCallback!!.onThreadEnableStateChanged(
- STATE_DISABLING
- )
- }
- executor.execute {
- registeredStateCallback!!.onThreadEnableStateChanged(
- STATE_DISABLED
- )
- }
- } else {
- executor.execute {
- registeredStateCallback!!.onThreadEnableStateChanged(
- STATE_ENABLED
- )
- }
- }
- }
- executor.execute { receiver.onResult(null) }
- }
-
- override fun registerStateCallback(
- executor: Executor,
- callback: StateCallback
- ) {
- require(callback !== registeredStateCallback) { "callback is already registered" }
- registeredStateCallback = callback
- val enabledState =
- if (isEnabled) STATE_ENABLED else STATE_DISABLED
- executor.execute { registeredStateCallback!!.onThreadEnableStateChanged(enabledState) }
- }
-
- override fun unregisterStateCallback(callback: StateCallback) {
- requireNotNull(registeredStateCallback) { "callback is already unregistered" }
- registeredStateCallback = null
- }
- }
-}
diff --git a/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/FakeThreadNetworkController.kt b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/FakeThreadNetworkController.kt
new file mode 100644
index 00000000000..e30226e25fb
--- /dev/null
+++ b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/FakeThreadNetworkController.kt
@@ -0,0 +1,74 @@
+/*
+ * 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.connecteddevice.threadnetwork
+
+import android.net.thread.ThreadNetworkController
+import android.net.thread.ThreadNetworkException
+import android.os.OutcomeReceiver
+import java.util.concurrent.Executor
+
+/** A fake implementation of [BaseThreadNetworkController] for unit tests. */
+class FakeThreadNetworkController : BaseThreadNetworkController {
+ var isEnabled = false
+ private set
+ var registeredStateCallback: ThreadNetworkController.StateCallback? = null
+ private set
+
+ override fun setEnabled(
+ enabled: Boolean,
+ executor: Executor,
+ receiver: OutcomeReceiver
+ ) {
+ isEnabled = enabled
+ if (registeredStateCallback != null) {
+ if (!isEnabled) {
+ executor.execute {
+ registeredStateCallback!!.onThreadEnableStateChanged(
+ ThreadNetworkController.STATE_DISABLING
+ )
+ }
+ executor.execute {
+ registeredStateCallback!!.onThreadEnableStateChanged(
+ ThreadNetworkController.STATE_DISABLED
+ )
+ }
+ } else {
+ executor.execute {
+ registeredStateCallback!!.onThreadEnableStateChanged(
+ ThreadNetworkController.STATE_ENABLED
+ )
+ }
+ }
+ }
+ executor.execute { receiver.onResult(null) }
+ }
+
+ override fun registerStateCallback(
+ executor: Executor,
+ callback: ThreadNetworkController.StateCallback
+ ) {
+ require(callback !== registeredStateCallback) { "callback is already registered" }
+ registeredStateCallback = callback
+ val enabledState =
+ if (isEnabled) ThreadNetworkController.STATE_ENABLED else ThreadNetworkController.STATE_DISABLED
+ executor.execute { registeredStateCallback!!.onThreadEnableStateChanged(enabledState) }
+ }
+
+ override fun unregisterStateCallback(callback: ThreadNetworkController.StateCallback) {
+ requireNotNull(registeredStateCallback) { "callback is already unregistered" }
+ registeredStateCallback = null
+ }
+}
diff --git a/tests/unit/src/com/android/settings/conecteddevice/threadnetwork/OWNERS b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/OWNERS
similarity index 100%
rename from tests/unit/src/com/android/settings/conecteddevice/threadnetwork/OWNERS
rename to tests/unit/src/com/android/settings/connecteddevice/threadnetwork/OWNERS
diff --git a/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkFragmentControllerTest.kt b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkFragmentControllerTest.kt
new file mode 100644
index 00000000000..0d57dafc144
--- /dev/null
+++ b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkFragmentControllerTest.kt
@@ -0,0 +1,112 @@
+/*
+ * 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.connecteddevice.threadnetwork
+
+import android.content.Context
+import android.platform.test.flag.junit.SetFlagsRule
+import androidx.core.content.ContextCompat
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleOwner
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.core.BasePreferenceController.AVAILABLE
+import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
+import com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE
+import com.android.settings.flags.Flags
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mockito.mock
+import org.mockito.Mockito.spy
+import java.util.concurrent.Executor
+
+/** Unit tests for [ThreadNetworkFragmentController]. */
+@RunWith(AndroidJUnit4::class)
+class ThreadNetworkFragmentControllerTest {
+ @get:Rule
+ val mSetFlagsRule = SetFlagsRule()
+ private lateinit var context: Context
+ private lateinit var executor: Executor
+ private lateinit var controller: ThreadNetworkFragmentController
+ private lateinit var fakeThreadNetworkController: FakeThreadNetworkController
+
+ @Before
+ fun setUp() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_THREAD_SETTINGS_ENABLED)
+ context = spy(ApplicationProvider.getApplicationContext())
+ executor = ContextCompat.getMainExecutor(context)
+ fakeThreadNetworkController = FakeThreadNetworkController()
+ controller = newControllerWithThreadFeatureSupported(true)
+ }
+
+ private fun newControllerWithThreadFeatureSupported(
+ present: Boolean
+ ): ThreadNetworkFragmentController {
+ return ThreadNetworkFragmentController(
+ context,
+ "thread_network_settings" /* key */,
+ executor,
+ if (present) fakeThreadNetworkController else null
+ )
+ }
+
+ @Test
+ fun availabilityStatus_flagDisabled_returnsConditionallyUnavailable() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_THREAD_SETTINGS_ENABLED)
+ startController(controller)
+
+ assertThat(controller.availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun availabilityStatus_threadFeatureNotSupported_returnsUnsupported() {
+ controller = newControllerWithThreadFeatureSupported(false)
+ startController(controller)
+
+ assertThat(fakeThreadNetworkController.registeredStateCallback).isNull()
+ assertThat(controller.availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE)
+ }
+
+ @Test
+ fun availabilityStatus_threadFeatureSupported_returnsAvailable() {
+ controller = newControllerWithThreadFeatureSupported(true)
+ startController(controller)
+
+ assertThat(controller.availabilityStatus).isEqualTo(AVAILABLE)
+ }
+
+ @Test
+ fun getSummary_ThreadIsEnabled_returnsOn() {
+ startController(controller)
+ fakeThreadNetworkController.setEnabled(true, executor) {}
+
+ assertThat(controller.summary).isEqualTo("On")
+ }
+
+ @Test
+ fun getSummary_ThreadIsDisabled_returnsOff() {
+ startController(controller)
+ fakeThreadNetworkController.setEnabled(false, executor) {}
+
+ assertThat(controller.summary).isEqualTo("Off")
+ }
+
+ private fun startController(controller: ThreadNetworkFragmentController) {
+ controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
+ }
+}
diff --git a/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkToggleControllerTest.kt b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkToggleControllerTest.kt
new file mode 100644
index 00000000000..04ebc9252ef
--- /dev/null
+++ b/tests/unit/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkToggleControllerTest.kt
@@ -0,0 +1,127 @@
+/*
+ * 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.connecteddevice.threadnetwork
+
+import android.content.Context
+import android.platform.test.flag.junit.SetFlagsRule
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleOwner
+import androidx.preference.PreferenceManager
+import androidx.preference.SwitchPreference
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE
+import com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE
+import com.android.settings.flags.Flags
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mockito.mock
+import org.mockito.Mockito.spy
+import java.util.concurrent.Executor
+
+/** Unit tests for [ThreadNetworkToggleController]. */
+@RunWith(AndroidJUnit4::class)
+class ThreadNetworkToggleControllerTest {
+ @get:Rule
+ val mSetFlagsRule = SetFlagsRule()
+ private lateinit var context: Context
+ private lateinit var executor: Executor
+ private lateinit var controller: ThreadNetworkToggleController
+ private lateinit var fakeThreadNetworkController: FakeThreadNetworkController
+ private lateinit var preference: SwitchPreference
+
+ @Before
+ fun setUp() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_THREAD_SETTINGS_ENABLED)
+ context = spy(ApplicationProvider.getApplicationContext())
+ executor = Executor { runnable: Runnable -> runnable.run() }
+ fakeThreadNetworkController = FakeThreadNetworkController()
+ controller = newControllerWithThreadFeatureSupported(true)
+ val preferenceManager = PreferenceManager(context)
+ val preferenceScreen = preferenceManager.createPreferenceScreen(context)
+ preference = SwitchPreference(context)
+ preference.key = "toggle_thread_network"
+ preferenceScreen.addPreference(preference)
+ controller.displayPreference(preferenceScreen)
+ }
+
+ private fun newControllerWithThreadFeatureSupported(
+ present: Boolean
+ ): ThreadNetworkToggleController {
+ return ThreadNetworkToggleController(
+ context,
+ "toggle_thread_network" /* key */,
+ executor,
+ if (present) fakeThreadNetworkController else null
+ )
+ }
+
+ @Test
+ fun availabilityStatus_flagDisabled_returnsConditionallyUnavailable() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_THREAD_SETTINGS_ENABLED)
+ assertThat(controller.availabilityStatus).isEqualTo(CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun availabilityStatus_threadFeatureNotSupported_returnsUnsupported() {
+ controller = newControllerWithThreadFeatureSupported(false)
+ startController(controller)
+
+ assertThat(fakeThreadNetworkController.registeredStateCallback).isNull()
+ assertThat(controller.availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE)
+ }
+
+ @Test
+ fun isChecked_threadSetEnabled_returnsTrue() {
+ fakeThreadNetworkController.setEnabled(true, executor) { }
+ startController(controller)
+
+ assertThat(controller.isChecked).isTrue()
+ }
+
+ @Test
+ fun isChecked_threadSetDisabled_returnsFalse() {
+ fakeThreadNetworkController.setEnabled(false, executor) { }
+ startController(controller)
+
+ assertThat(controller.isChecked).isFalse()
+ }
+
+ @Test
+ fun setChecked_setChecked_threadIsEnabled() {
+ startController(controller)
+
+ controller.setChecked(true)
+
+ assertThat(fakeThreadNetworkController.isEnabled).isTrue()
+ }
+
+ @Test
+ fun setChecked_setUnchecked_threadIsDisabled() {
+ startController(controller)
+
+ controller.setChecked(false)
+
+ assertThat(fakeThreadNetworkController.isEnabled).isFalse()
+ }
+
+ private fun startController(controller: ThreadNetworkToggleController) {
+ controller.onStateChanged(mock(LifecycleOwner::class.java), Lifecycle.Event.ON_START)
+ }
+}
diff --git a/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java
deleted file mode 100644
index bbbee216994..00000000000
--- a/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2020 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.telephony;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.network.SubscriptionUtil;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.util.Arrays;
-
-@RunWith(AndroidJUnit4.class)
-public class DisableSimFooterPreferenceControllerTest {
- private static final String PREF_KEY = "pref_key";
- private static final int SUB_ID = 111;
-
- @Mock
- private SubscriptionInfo mInfo;
-
- private Context mContext;
- @Mock
- private SubscriptionManager mSubscriptionManager;
- private DisableSimFooterPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
- when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager);
-
- when(mInfo.getSubscriptionId()).thenReturn(SUB_ID);
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mInfo));
- mController = new DisableSimFooterPreferenceController(mContext, PREF_KEY);
- }
-
- @Test
- public void isAvailable_noInit_notAvailable() {
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void isAvailable_eSIM_notAvailable() {
- when(mInfo.isEmbedded()).thenReturn(true);
- mController.init(SUB_ID);
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void isAvailable_pSIM_available_cannot_disable_pSIM() {
- when(mInfo.isEmbedded()).thenReturn(false);
- mController.init(SUB_ID);
- doReturn(false).when(mSubscriptionManager).canDisablePhysicalSubscription();
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- public void isAvailable_pSIM_available_can_disable_pSIM() {
- when(mInfo.isEmbedded()).thenReturn(false);
- mController.init(SUB_ID);
- doReturn(true).when(mSubscriptionManager).canDisablePhysicalSubscription();
- assertThat(mController.isAvailable()).isFalse();
- }
-}
diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
index a4657cee8a0..d71af84dcf8 100644
--- a/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
@@ -44,8 +44,12 @@ import androidx.preference.PreferenceManager;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
+import com.android.settings.network.telephony.scan.NetworkScanRepository;
+import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanResult;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -163,8 +167,7 @@ public class NetworkSelectSettingsTest {
}
@Override
- protected NetworkOperatorPreference
- createNetworkOperatorPreference(CellInfo cellInfo) {
+ protected NetworkOperatorPreference createNetworkOperatorPreference(CellInfo cellInfo) {
NetworkOperatorPreference pref = super.createNetworkOperatorPreference(cellInfo);
if (cellInfo == mTestEnv.mCellInfo1) {
pref.updateCell(cellInfo, mTestEnv.mCellId1);
@@ -183,9 +186,14 @@ public class NetworkSelectSettingsTest {
@Test
@UiThreadTest
public void updateAllPreferenceCategory_correctOrderingPreference() {
+ NetworkScanResult result = new NetworkScanResult(
+ NetworkScanRepository.NetworkScanState.COMPLETE,
+ ImmutableList.of(mCellInfo1, mCellInfo2));
mNetworkSelectSettings.onCreateInitialization();
mNetworkSelectSettings.enablePreferenceScreen(true);
- mNetworkSelectSettings.scanResultHandler(Arrays.asList(mCellInfo1, mCellInfo2));
+
+ mNetworkSelectSettings.scanResultHandler(result);
+
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
final NetworkOperatorPreference preference =
(NetworkOperatorPreference) mPreferenceCategory.getPreference(1);
diff --git a/tests/unit/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatchTest.java b/tests/unit/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatchTest.java
index 3794e00ea10..e201f42e4b3 100644
--- a/tests/unit/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatchTest.java
+++ b/tests/unit/src/com/android/settings/panel/PanelSlicesLoaderCountdownLatchTest.java
@@ -29,6 +29,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+@Deprecated(forRemoval = true)
@RunWith(AndroidJUnit4.class)
public class PanelSlicesLoaderCountdownLatchTest {
diff --git a/tests/unit/src/com/android/settings/privatespace/delete/PrivateSpaceDeletionProgressFragmentTest.java b/tests/unit/src/com/android/settings/privatespace/delete/PrivateSpaceDeletionProgressFragmentTest.java
index 9806540d540..62505400c8d 100644
--- a/tests/unit/src/com/android/settings/privatespace/delete/PrivateSpaceDeletionProgressFragmentTest.java
+++ b/tests/unit/src/com/android/settings/privatespace/delete/PrivateSpaceDeletionProgressFragmentTest.java
@@ -64,6 +64,11 @@ public class PrivateSpaceDeletionProgressFragmentTest {
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = ApplicationProvider.getApplicationContext();
+ final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
+ when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+ doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
+
mFragment = new PrivateSpaceDeletionProgressFragment();
PrivateSpaceDeletionProgressFragment.Injector injector =
new PrivateSpaceDeletionProgressFragment.Injector() {
@@ -74,10 +79,6 @@ public class PrivateSpaceDeletionProgressFragmentTest {
};
mPrivateSpaceMaintainer = PrivateSpaceMaintainer.getInstance(mContext);
mFragment.setPrivateSpaceMaintainer(injector);
- final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
- when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
- .thenReturn(mLockPatternUtils);
- doReturn(true).when(mLockPatternUtils).isSecure(anyInt());
}
@After