Merge "Link to app-provided configuration intent for app-owned rules." into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8cfd9b5..b28da4f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1427,6 +1427,19 @@
android:value="true" />
</activity>
+ <activity
+ android:name=".Settings$ManageAdaptiveNotificationsActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.settings.MANAGE_ADAPTIVE_NOTIFICATIONS"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.notification.PoliteNotificationsPreferenceFragment" />
+ <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
+ android:value="@string/menu_key_notifications"/>
+ </activity>
+
<activity android:name="Settings$WallpaperSettingsActivity"
android:label="@string/wallpaper_settings_fragment_title"
android:icon="@drawable/ic_wallpaper"
diff --git a/proguard.flags b/proguard.flags
index 492404c..d1c97f3 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -65,3 +65,6 @@
-keep class androidx.window.extensions.** { *; }
-dontwarn androidx.window.extensions.**
-keep class androidx.window.** { *; }
+
+# Keep the com.android.settings.media_drm.FakeFeatureFlagsImpl
+-keep class com.android.settings.media_drm.FakeFeatureFlagsImpl { *; }
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d60e357..af7473b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12386,7 +12386,7 @@
<!-- Toast on failure to reformat data to ext4 -->
<string name="format_ext4_failure_toast">Failed to reformat and wipe the data partition to ext4.</string>
<!-- Dialog to OEM unlock the device before using 16K developer option -->
- <string name="confirm_oem_unlock_for_16k_title">Bootloader Unlock Required for 16KB Mode</string>
+ <string name="confirm_oem_unlock_for_16k_title">Bootloader Unlock Required</string>
<string name="confirm_oem_unlock_for_16k_text">This device needs to have the bootloader unlocked before using the 16KB developer option.
Software integrity cannot be guaranteed in this mode, and any data stored on the phone while the bootloader is unlocked may be at risk.
All user data and settings will be wiped when activating 16KB mode. Once the bootloader is unlocked, activating the 16KB option will require two reboots.
@@ -12415,10 +12415,10 @@
<!-- persistent notification 16k page agnostic mode text -->
<string name="page_agnostic_16k_pages_text_short">You are in the 16KB mode of the page-agnostic mode. Software integrity cannot be guaranteed in this mode,
and any data stored on the phone while the bootloader is unlocked may be at risk. Some features will be disabled in these modes, so some applications may not work.
- In order to re-enter the production mode, you must, switch back to 4K mode and then lock the bootloader of the device. Tap to read more.</string>
+ In order to re-enter the production mode, you must, switch back to 4KB mode and then lock the bootloader of the device. Tap to read more.</string>
<string name="page_agnostic_16k_pages_text">You are in the 16KB mode of the page-agnostic mode. Software integrity cannot be guaranteed in this mode,
and any data stored on the phone while the bootloader is unlocked may be at risk. Some features will be disabled in these modes, so some applications may not work.
- In order to re-enter the production mode, you must, switch back to 4K mode and then lock the bootloader of the device. This would factory reset the device again and
+ In order to re-enter the production mode, you must, switch back to 4KB mode and then lock the bootloader of the device. This would factory reset the device again and
restore it to production settings. After the device successfully boots into Android, disable OEM unlocking in Developer options.
If the device fails to boot into Android or is unstable, re-flash the device with the latest factory images from
<a href=\"https://developers.google.com/android/images\">https://developers.google.com/android/images</a>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index e3bb1a1..24d9525 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -303,6 +303,7 @@
public static class UserSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationAccessSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationAccessDetailsActivity extends SettingsActivity { /* empty */ }
+ public static class ManageAdaptiveNotificationsActivity extends SettingsActivity { /* empty */ }
public static class VrListenersSettingsActivity extends SettingsActivity { /* empty */ }
public static class PremiumSmsAccessActivity extends SettingsActivity { /* empty */ }
public static class PictureInPictureSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 11c05f3..734bddc 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -156,6 +156,7 @@
import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.NotificationAccessSettings;
import com.android.settings.notification.NotificationAssistantPicker;
+import com.android.settings.notification.PoliteNotificationsPreferenceFragment;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.app.AppBubbleNotificationSettings;
import com.android.settings.notification.app.AppNotificationSettings;
@@ -314,6 +315,7 @@
AppInfoDashboardFragment.class.getName(),
BatterySaverSettings.class.getName(),
AppNotificationSettings.class.getName(),
+ PoliteNotificationsPreferenceFragment.class.getName(),
NotificationAssistantPicker.class.getName(),
ChannelNotificationSettings.class.getName(),
SatelliteSetting.class.getName(),
diff --git a/src/com/android/settings/datausage/DataUsageList.kt b/src/com/android/settings/datausage/DataUsageList.kt
index af115d9..a293277 100644
--- a/src/com/android/settings/datausage/DataUsageList.kt
+++ b/src/com/android/settings/datausage/DataUsageList.kt
@@ -33,13 +33,10 @@
import com.android.settings.dashboard.DashboardFragment
import com.android.settings.datausage.lib.BillingCycleRepository
import com.android.settings.datausage.lib.NetworkUsageData
-import com.android.settings.network.MobileNetworkRepository
import com.android.settings.network.SubscriptionUtil
-import com.android.settings.network.telephony.requireSubscriptionManager
-import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity
+import com.android.settings.network.telephony.SubscriptionRepository
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
import com.android.settingslib.spaprivileged.framework.common.userManager
-import com.android.settingslib.utils.ThreadUtils
import kotlin.jvm.optionals.getOrNull
/**
@@ -59,7 +56,6 @@
private lateinit var billingCycleRepository: BillingCycleRepository
private var usageAmount: Preference? = null
- private var subscriptionInfoEntity: SubscriptionInfoEntity? = null
private var dataUsageListAppsController: DataUsageListAppsController? = null
private var chartDataUsagePreferenceController: ChartDataUsagePreferenceController? = null
private var dataUsageListHeaderController: DataUsageListHeaderController? = null
@@ -90,7 +86,6 @@
finish()
return
}
- updateSubscriptionInfoEntity()
dataUsageListAppsController = use(DataUsageListAppsController::class.java).apply {
init(template)
}
@@ -132,6 +127,16 @@
viewModel.chartDataFlow.collectLatestWithLifecycle(viewLifecycleOwner) { chartData ->
chartDataUsagePreferenceController?.update(chartData)
}
+ finishIfSubscriptionDisabled()
+ }
+
+ private fun finishIfSubscriptionDisabled() {
+ if (SubscriptionManager.isUsableSubscriptionId(subId)) {
+ SubscriptionRepository(requireContext()).isSubscriptionEnabledFlow(subId)
+ .collectLatestWithLifecycle(viewLifecycleOwner) { isSubscriptionEnabled ->
+ if (!isSubscriptionEnabled) finish()
+ }
+ }
}
override fun getPreferenceScreenResId() = R.xml.data_usage_list
@@ -155,23 +160,12 @@
}
}
- private fun updateSubscriptionInfoEntity() {
- ThreadUtils.postOnBackgroundThread {
- subscriptionInfoEntity =
- MobileNetworkRepository.getInstance(context).getSubInfoById(subId.toString())
- }
- }
-
/** Update chart sweeps and cycle list to reflect [NetworkPolicy] for current [template]. */
private fun updatePolicy(isModifiable: Boolean) {
- val isBillingCycleModifiable = isModifiable && isActiveSubscription()
- dataUsageListHeaderController?.setConfigButtonVisible(isBillingCycleModifiable)
- chartDataUsagePreferenceController?.setBillingCycleModifiable(isBillingCycleModifiable)
+ dataUsageListHeaderController?.setConfigButtonVisible(isModifiable)
+ chartDataUsagePreferenceController?.setBillingCycleModifiable(isModifiable)
}
- private fun isActiveSubscription(): Boolean =
- requireContext().requireSubscriptionManager().getActiveSubscriptionInfo(subId) != null
-
/**
* Updates the chart and detail data when initial loaded or selected cycle changed.
*/
@@ -187,7 +181,7 @@
/** Updates applications data usage. */
private fun updateApps(usageData: NetworkUsageData) {
dataUsageListAppsController?.update(
- carrierId = subscriptionInfoEntity?.carrierId,
+ subId = subId,
startTime = usageData.startTime,
endTime = usageData.endTime,
)
diff --git a/src/com/android/settings/datausage/DataUsageListAppsController.kt b/src/com/android/settings/datausage/DataUsageListAppsController.kt
index 93623f4..d8bddde 100644
--- a/src/com/android/settings/datausage/DataUsageListAppsController.kt
+++ b/src/com/android/settings/datausage/DataUsageListAppsController.kt
@@ -20,6 +20,7 @@
import android.content.Context
import android.net.NetworkTemplate
import android.os.Bundle
+import android.telephony.SubscriptionManager
import androidx.annotation.OpenForTesting
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LifecycleCoroutineScope
@@ -32,6 +33,7 @@
import com.android.settings.core.SubSettingLauncher
import com.android.settings.datausage.lib.AppDataUsageRepository
import com.android.settings.datausage.lib.NetworkUsageData
+import com.android.settings.network.telephony.requireSubscriptionManager
import com.android.settingslib.AppItem
import com.android.settingslib.net.UidDetailProvider
import kotlinx.coroutines.Dispatchers
@@ -74,8 +76,11 @@
this.cycleData = cycleData
}
- fun update(carrierId: Int?, startTime: Long, endTime: Long) = lifecycleScope.launch {
+ fun update(subId: Int, startTime: Long, endTime: Long) = lifecycleScope.launch {
val apps = withContext(Dispatchers.Default) {
+ val carrierId = if (SubscriptionManager.isValidSubscriptionId(subId)) {
+ mContext.requireSubscriptionManager().getActiveSubscriptionInfo(subId)?.carrierId
+ } else null
repository.getAppPercent(carrierId, startTime, endTime).map { (appItem, percent) ->
AppDataUsagePreference(mContext, appItem, percent, uidDetailProvider).apply {
setOnPreferenceClickListener {
diff --git a/src/com/android/settings/development/PageAgnosticNotificationService.java b/src/com/android/settings/development/PageAgnosticNotificationService.java
index bce1dd9..40dff0c 100644
--- a/src/com/android/settings/development/PageAgnosticNotificationService.java
+++ b/src/com/android/settings/development/PageAgnosticNotificationService.java
@@ -96,13 +96,13 @@
notifyPendingIntent)
.build();
+ // TODO:(b/349860833) Change text style to BigTextStyle once the ellipsis issue is fixed.
Notification.Builder builder =
new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle(title)
.setContentText(text)
.setOngoing(true)
.setSmallIcon(R.drawable.ic_settings_24dp)
- .setStyle(new Notification.BigTextStyle().bigText(text))
.setContentIntent(notifyPendingIntent)
.addAction(action);
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index b54801a..7cf9e44 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -53,7 +53,8 @@
public int batteryStatus;
public int pluggedStatus;
public boolean discharging = true;
- public boolean isBatteryDefender;
+ public boolean isBatteryDefender = false;
+ public boolean isLongLife = false;
public boolean isFastCharging;
public long remainingTimeUs = 0;
public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
@@ -306,7 +307,7 @@
info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
info.mCharging = info.pluggedStatus != 0;
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
- info.isBatteryDefender =
+ info.isLongLife =
batteryBroadcast.getIntExtra(
BatteryManager.EXTRA_CHARGING_STATUS,
BatteryManager.CHARGING_POLICY_DEFAULT)
@@ -319,7 +320,7 @@
info.isFastCharging =
BatteryStatus.getChargingSpeed(context, batteryBroadcast)
== BatteryStatus.CHARGING_FAST;
- if (info.isBatteryDefender) {
+ if (info.isLongLife) {
info.isBatteryDefender =
FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider()
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 9e08664..7cb5733 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -600,12 +600,12 @@
context.getContentResolver(), SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0)
== 1) {
return DockDefenderMode.TEMPORARILY_BYPASSED;
- } else if (batteryInfo.isBatteryDefender
+ } else if (batteryInfo.isLongLife
&& FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider()
.isExtraDefend()) {
return DockDefenderMode.ACTIVE;
- } else if (!batteryInfo.isBatteryDefender) {
+ } else if (!batteryInfo.isLongLife) {
return DockDefenderMode.FUTURE_BYPASS;
}
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 98e1a6e..e12cc9f 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -26,6 +26,7 @@
import androidx.annotation.NonNull;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
+import com.android.settings.fuelgauge.batteryusage.BatteryEvent;
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
import com.android.settingslib.fuelgauge.Estimate;
@@ -43,6 +44,9 @@
/** Check whether the battery tips card is enabled in the battery usage page */
boolean isBatteryTipsEnabled();
+ /** Check whether overwrite the app optimization mode to restricted mode is enabled */
+ boolean isRestrictedModeOverwriteEnabled();
+
/** Check whether force expire the app optimization mode. */
boolean isForceExpireAppOptimizationModeEnabled();
@@ -166,5 +170,6 @@
boolean processBatteryReattributeData(
@NonNull Context context,
@NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
+ @NonNull List<BatteryEvent> batteryEventList,
final boolean isFromPeriodJob);
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index dc5b226..4f163a2 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -18,7 +18,6 @@
import static com.android.settings.Utils.SYSTEMUI_PACKAGE_NAME;
-import android.annotation.Nullable;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -28,9 +27,11 @@
import android.util.SparseIntArray;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import com.android.internal.util.ArrayUtils;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
+import com.android.settings.fuelgauge.batteryusage.BatteryEvent;
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
import com.android.settingslib.fuelgauge.Estimate;
@@ -88,6 +89,11 @@
}
@Override
+ public boolean isRestrictedModeOverwriteEnabled() {
+ return false;
+ }
+
+ @Override
public boolean isForceExpireAppOptimizationModeEnabled() {
return false;
}
@@ -247,13 +253,14 @@
@Override
public boolean isBatteryDefend(BatteryInfo info) {
- return info.isBatteryDefender && !isExtraDefend();
+ return info.isLongLife && !isExtraDefend();
}
@Override
public boolean processBatteryReattributeData(
@NonNull Context context,
@NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
+ @NonNull List<BatteryEvent> batteryEventList,
final boolean isFromPeriodJob) {
return false;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
index 639b3c7..6ff2665 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
@@ -21,7 +21,6 @@
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
-import com.android.settings.overlay.FeatureFactory;
/** Detect whether the battery is overheated */
public class BatteryDefenderDetector implements BatteryTipDetector {
@@ -35,12 +34,10 @@
@Override
public BatteryTip detect() {
- final boolean isBasicBatteryDefend =
- FeatureFactory.getFeatureFactory()
- .getPowerUsageFeatureProvider()
- .isBatteryDefend(mBatteryInfo);
final int state =
- isBasicBatteryDefend ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
+ mBatteryInfo.isBatteryDefender
+ ? BatteryTip.StateType.NEW
+ : BatteryTip.StateType.INVISIBLE;
final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0;
return new BatteryDefenderTip(state, isPluggedIn);
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtils.kt b/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtils.kt
index afff1c9..508c4df 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtils.kt
+++ b/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtils.kt
@@ -76,8 +76,7 @@
fun resetExpiredAppOptModeBeforeTimestamp(context: Context, queryTimestampMs: Long) =
synchronized(appOptimizationModeLock) {
val forceExpireEnabled =
- featureFactory
- .powerUsageFeatureProvider.isForceExpireAppOptimizationModeEnabled
+ featureFactory.powerUsageFeatureProvider.isForceExpireAppOptimizationModeEnabled
val eventsMap = getAppOptModeEventsMap(context)
val expirationUids = ArrayList<Int>(eventsMap.size)
for ((uid, event) in eventsMap) {
@@ -113,12 +112,22 @@
getBatteryOptimizeUtils: (Int, String) -> BatteryOptimizeUtils,
) =
synchronized(appOptimizationModeLock) {
+ val restrictedModeOverwriteEnabled =
+ featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled
val eventsMap = getAppOptModeEventsMap(context)
val expirationEvents: MutableMap<Int, AppOptimizationModeEvent> = ArrayMap()
for (i in uids.indices) {
val uid = uids[i]
val packageName = packageNames[i]
val optimizationMode = optimizationModes[i]
+ if (
+ !restrictedModeOverwriteEnabled &&
+ optimizationMode == BatteryOptimizeUtils.MODE_RESTRICTED
+ ) {
+ // Unable to set restricted mode due to flag protection.
+ Log.w(TAG, "setOptimizationMode($packageName) into restricted ignored")
+ continue
+ }
val originalOptMode: Int =
updateBatteryOptimizationMode(
context,
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java b/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java
index 2b88d34..0a1a547 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java
@@ -522,7 +522,7 @@
FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider();
featureProvider.processBatteryReattributeData(
- mContext, batteryDiffDataMap, mIsFromPeriodJob);
+ mContext, batteryDiffDataMap, mBatteryEventList, mIsFromPeriodJob);
Log.d(
TAG,
diff --git a/src/com/android/settings/network/MobileNetworkRepository.java b/src/com/android/settings/network/MobileNetworkRepository.java
index ebb341e..bd892c8 100644
--- a/src/com/android/settings/network/MobileNetworkRepository.java
+++ b/src/com/android/settings/network/MobileNetworkRepository.java
@@ -41,7 +41,6 @@
import androidx.lifecycle.LifecycleOwner;
import com.android.internal.telephony.flags.Flags;
-import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.mobile.dataservice.MobileNetworkDatabase;
@@ -435,7 +434,7 @@
mMetricsFeatureProvider.action(mContext,
SettingsEnums.ACTION_MOBILE_NETWORK_DB_INSERT_SUB_INFO, subId);
insertUiccInfo(subId, telephonyManager);
- insertMobileNetworkInfo(context, subId, telephonyManager);
+ insertMobileNetworkInfo(subId, telephonyManager);
}
} else if (DEBUG) {
Log.d(TAG, "Can not insert subInfo, the entity is null");
@@ -517,20 +516,13 @@
}
}
- private void insertMobileNetworkInfo(Context context, int subId,
- TelephonyManager telephonyManager) {
- MobileNetworkInfoEntity mobileNetworkInfoEntity = convertToMobileNetworkInfoEntity(context,
- subId, telephonyManager);
-
+ private void insertMobileNetworkInfo(int subId, TelephonyManager telephonyManager) {
+ MobileNetworkInfoEntity mobileNetworkInfoEntity =
+ convertToMobileNetworkInfoEntity(subId, telephonyManager);
Log.d(TAG, "insertMobileNetworkInfo, mobileNetworkInfoEntity = "
+ mobileNetworkInfoEntity);
-
- if (mobileNetworkInfoEntity == null) {
- return;
- }
-
if (!sCacheMobileNetworkInfoEntityMap.containsKey(subId)
|| !sCacheMobileNetworkInfoEntityMap.get(subId).equals(mobileNetworkInfoEntity)) {
sCacheMobileNetworkInfoEntityMap.put(subId, mobileNetworkInfoEntity);
@@ -540,7 +532,7 @@
}
}
- private MobileNetworkInfoEntity convertToMobileNetworkInfoEntity(Context context, int subId,
+ private MobileNetworkInfoEntity convertToMobileNetworkInfoEntity(int subId,
TelephonyManager telephonyManager) {
boolean isDataEnabled = false;
if (telephonyManager != null) {
@@ -549,18 +541,8 @@
Log.d(TAG, "TelephonyManager is null, subId = " + subId);
}
- return new MobileNetworkInfoEntity(String.valueOf(subId),
- MobileNetworkUtils.isContactDiscoveryEnabled(context, subId),
- MobileNetworkUtils.isContactDiscoveryVisible(context, subId),
- isDataEnabled,
- MobileNetworkUtils.isCdmaOptions(context, subId),
- MobileNetworkUtils.isGsmOptions(context, subId),
- MobileNetworkUtils.isWorldMode(context, subId),
- MobileNetworkUtils.shouldDisplayNetworkSelectOptions(context, subId),
- MobileNetworkUtils.isTdscdmaSupported(context, subId),
- MobileNetworkUtils.activeNetworkIsCellular(context),
- SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager),
- /* deprecated isDataRoamingEnabled = */ false
+ return new MobileNetworkInfoEntity(String.valueOf(subId), isDataEnabled,
+ SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager)
);
}
@@ -681,8 +663,7 @@
public void onUserMobileDataStateChanged(boolean enabled) {
Log.d(TAG, "onUserMobileDataStateChanged enabled " + enabled + " on SUB " + mSubId);
sExecutor.execute(() -> {
- insertMobileNetworkInfo(mContext, mSubId,
- getTelephonyManagerBySubId(mContext, mSubId));
+ insertMobileNetworkInfo(mSubId, getTelephonyManagerBySubId(mContext, mSubId));
});
}
}
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index a4193f8..0fcfcb5 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -36,6 +36,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.EventLog;
@@ -370,7 +371,7 @@
mDataUsagePreference = findPreference(PREF_KEY_DATA_USAGE);
mDataUsagePreference.setVisible(DataUsageUtils.hasWifiRadio(getContext()));
mDataUsagePreference.setTemplate(new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI)
- .build(), 0 /*subId*/);
+ .build(), SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mResetInternetPreference = findPreference(PREF_KEY_RESET_INTERNET);
if (mResetInternetPreference != null) {
mResetInternetPreference.setVisible(false);
diff --git a/src/com/android/settings/search/SearchFeatureProviderImpl.java b/src/com/android/settings/search/SearchFeatureProviderImpl.java
deleted file mode 100644
index 3a62ddf..0000000
--- a/src/com/android/settings/search/SearchFeatureProviderImpl.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2017 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.search;
-
-import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.provider.Settings;
-import android.text.TextUtils;
-
-import androidx.annotation.NonNull;
-
-import com.android.settingslib.search.SearchIndexableResources;
-import com.android.settingslib.search.SearchIndexableResourcesMobile;
-
-/**
- * FeatureProvider for the refactored search code.
- */
-public class SearchFeatureProviderImpl implements SearchFeatureProvider {
-
- private SearchIndexableResources mSearchIndexableResources;
-
- @Override
- public void verifyLaunchSearchResultPageCaller(@NonNull Context context,
- @NonNull String callerPackage) {
- if (TextUtils.isEmpty(callerPackage)) {
- throw new IllegalArgumentException("ExternalSettingsTrampoline intents "
- + "must be called with startActivityForResult");
- }
- final boolean isSettingsPackage = TextUtils.equals(callerPackage, context.getPackageName())
- || TextUtils.equals(getSettingsIntelligencePkgName(context), callerPackage);
- final boolean isAllowlistedPackage = isSignatureAllowlisted(context, callerPackage);
- if (isSettingsPackage || isAllowlistedPackage) {
- return;
- }
- throw new SecurityException("Search result intents must be called with from an "
- + "allowlisted package.");
- }
-
- @Override
- public SearchIndexableResources getSearchIndexableResources() {
- if (mSearchIndexableResources == null) {
- mSearchIndexableResources = new SearchIndexableResourcesMobile();
- }
- return mSearchIndexableResources;
- }
-
- @Override
- public Intent buildSearchIntent(Context context, int pageId) {
- return new Intent(Settings.ACTION_APP_SEARCH_SETTINGS)
- .setPackage(getSettingsIntelligencePkgName(context))
- .putExtra(Intent.EXTRA_REFERRER, buildReferrer(context, pageId));
- }
-
- protected boolean isSignatureAllowlisted(Context context, String callerPackage) {
- return false;
- }
-
- private static Uri buildReferrer(Context context, int pageId) {
- return new Uri.Builder()
- .scheme("android-app")
- .authority(context.getPackageName())
- .path(String.valueOf(pageId))
- .build();
- }
-}
diff --git a/src/com/android/settings/search/SearchFeatureProviderImpl.kt b/src/com/android/settings/search/SearchFeatureProviderImpl.kt
new file mode 100644
index 0000000..2ea9910
--- /dev/null
+++ b/src/com/android/settings/search/SearchFeatureProviderImpl.kt
@@ -0,0 +1,64 @@
+/*
+ * 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.search
+
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
+import android.provider.Settings
+import com.android.settings.search.SearchIndexableResourcesFactory.createSearchIndexableResources
+import com.android.settingslib.search.SearchIndexableResources
+
+/** FeatureProvider for the refactored search code. */
+open class SearchFeatureProviderImpl : SearchFeatureProvider {
+ private val lazySearchIndexableResources by lazy { createSearchIndexableResources() }
+
+ override fun verifyLaunchSearchResultPageCaller(context: Context, callerPackage: String) {
+ require(callerPackage.isNotEmpty()) {
+ "ExternalSettingsTrampoline intents must be called with startActivityForResult"
+ }
+ val isSettingsPackage = callerPackage == context.packageName
+ if (isSettingsPackage ||
+ callerPackage == getSettingsIntelligencePkgName(context) ||
+ isSignatureAllowlisted(context, callerPackage)) {
+ return
+ }
+ throw SecurityException(
+ "Search result intents must be called with from an allowlisted package.")
+ }
+
+ override fun getSearchIndexableResources(): SearchIndexableResources =
+ lazySearchIndexableResources
+
+ override fun buildSearchIntent(context: Context, pageId: Int): Intent =
+ Intent(Settings.ACTION_APP_SEARCH_SETTINGS)
+ .setPackage(getSettingsIntelligencePkgName(context))
+ .putExtra(Intent.EXTRA_REFERRER, buildReferrer(context, pageId))
+
+ protected open fun isSignatureAllowlisted(context: Context, callerPackage: String): Boolean =
+ false
+
+ companion object {
+ private fun buildReferrer(context: Context, pageId: Int): Uri =
+ Uri.Builder()
+ .scheme("android-app")
+ .authority(context.packageName)
+ .path(pageId.toString())
+ .build()
+ }
+}
diff --git a/src/com/android/settings/search/SearchIndexableResourcesFactory.java b/src/com/android/settings/search/SearchIndexableResourcesFactory.java
new file mode 100644
index 0000000..25f34ed
--- /dev/null
+++ b/src/com/android/settings/search/SearchIndexableResourcesFactory.java
@@ -0,0 +1,34 @@
+/*
+ * 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.search;
+
+import androidx.annotation.NonNull;
+
+import com.android.settingslib.search.SearchIndexableResources;
+import com.android.settingslib.search.SearchIndexableResourcesMobile;
+
+/**
+ * Creates the {@link SearchIndexableResourcesMobile}.
+ * <p>
+ * Since this class is generated by annotation processor, so it can only be created in Java now.
+ */
+class SearchIndexableResourcesFactory {
+ @NonNull
+ static SearchIndexableResources createSearchIndexableResources() {
+ return new SearchIndexableResourcesMobile();
+ }
+}
diff --git a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
index 05a8f6a..873a2c3 100644
--- a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
+++ b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
@@ -279,14 +279,14 @@
) {
CreatePrimarySimListPreference(
stringResource(id = R.string.primary_sim_calls_title),
- primarySimInfo.callsAndSmsList,
+ primarySimInfo.callsList,
callsSelectedId,
ImageVector.vectorResource(R.drawable.ic_phone),
actionSetCalls
)
CreatePrimarySimListPreference(
stringResource(id = R.string.primary_sim_texts_title),
- primarySimInfo.callsAndSmsList,
+ primarySimInfo.smsList,
textsSelectedId,
Icons.AutoMirrored.Outlined.Message,
actionSetTexts
diff --git a/src/com/android/settings/spa/network/PrimarySimRepository.kt b/src/com/android/settings/spa/network/PrimarySimRepository.kt
index e34a29e..420f870 100644
--- a/src/com/android/settings/spa/network/PrimarySimRepository.kt
+++ b/src/com/android/settings/spa/network/PrimarySimRepository.kt
@@ -22,12 +22,14 @@
import android.util.Log
import com.android.settings.R
import com.android.settings.network.SubscriptionUtil
+import com.android.settings.network.telephony.CarrierConfigRepository
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
class PrimarySimRepository(private val context: Context) {
data class PrimarySimInfo(
- val callsAndSmsList: List<ListPreferenceOption>,
+ val callsList: List<ListPreferenceOption>,
+ val smsList: List<ListPreferenceOption>,
val dataList: List<ListPreferenceOption>,
)
@@ -37,7 +39,8 @@
return null
}
- val callsAndSmsList = mutableListOf<ListPreferenceOption>()
+ val callsList = mutableListOf<ListPreferenceOption>()
+ val smsList = mutableListOf<ListPreferenceOption>()
val dataList = mutableListOf<ListPreferenceOption>()
for (info in selectableSubscriptionInfoList) {
val item = ListPreferenceOption(
@@ -45,15 +48,22 @@
text = "${info.displayName}",
summary = SubscriptionUtil.getBidiFormattedPhoneNumber(context, info) ?: "",
)
- callsAndSmsList += item
+ callsList += item
+ smsList += item
dataList += item
}
- callsAndSmsList += ListPreferenceOption(
+
+ val askEveryTime = ListPreferenceOption(
id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
text = context.getString(R.string.sim_calls_ask_first_prefs_title),
)
+ callsList += askEveryTime
+ if (context.resources
+ .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support)) {
+ smsList += askEveryTime
+ }
- return PrimarySimInfo(callsAndSmsList, dataList)
+ return PrimarySimInfo(callsList, smsList, dataList)
}
private companion object {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index 7bafc6d..b7e6590 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -789,6 +789,40 @@
expectedChargeLabel);
}
+ @Test
+ public void getBatteryInfo_longlife_shouldSetLonglife() {
+ var batteryIntent = createIntentForLongLifeTest(/* hasLongLife= */ true);
+
+ var batteryInfo =
+ BatteryInfo.getBatteryInfo(
+ mContext,
+ batteryIntent,
+ mBatteryUsageStats,
+ /* estimate= */ MOCK_ESTIMATE,
+ /* elapsedRealtimeUs= */ 0L,
+ /* shortString= */ false,
+ /* currentTimeMs= */ 0L);
+
+ assertThat(batteryInfo.isLongLife).isTrue();
+ }
+
+ @Test
+ public void getBatteryInfo_noLonglife_shouldNotLonglife() {
+ var batteryIntent = createIntentForLongLifeTest(/* hasLongLife= */ false);
+
+ var batteryInfo =
+ BatteryInfo.getBatteryInfo(
+ mContext,
+ batteryIntent,
+ mBatteryUsageStats,
+ /* estimate= */ MOCK_ESTIMATE,
+ /* elapsedRealtimeUs= */ 0L,
+ /* shortString= */ false,
+ /* currentTimeMs= */ 0L);
+
+ assertThat(batteryInfo.isLongLife).isFalse();
+ }
+
private enum ChargingSpeed {
FAST,
REGULAR,
@@ -801,6 +835,15 @@
DOCKED
}
+ private Intent createIntentForLongLifeTest(Boolean hasLongLife) {
+ return new Intent(Intent.ACTION_BATTERY_CHANGED)
+ .putExtra(
+ BatteryManager.EXTRA_CHARGING_STATUS,
+ hasLongLife
+ ? BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE
+ : BatteryManager.CHARGING_POLICY_DEFAULT);
+ }
+
private Intent createIntentForGetBatteryInfoTest(
ChargingType chargingType, ChargingSpeed chargingSpeed, int batteryLevel) {
return createBatteryIntent(
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index 6b32ff5..962c40f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -78,6 +78,11 @@
}
@Test
+ public void isRestrictedModeOverwriteEnabled_returnFalse() {
+ assertThat(mPowerFeatureProvider.isRestrictedModeOverwriteEnabled()).isFalse();
+ }
+
+ @Test
public void isForceExpireAppOptimizationModeEnabled_returnFalse() {
assertThat(mPowerFeatureProvider.isForceExpireAppOptimizationModeEnabled()).isFalse();
}
@@ -165,7 +170,7 @@
@Test
public void isBatteryDefend_defenderModeAndExtraDefendAreFalse_returnFalse() {
- mBatteryInfo.isBatteryDefender = false;
+ mBatteryInfo.isLongLife = false;
doReturn(false).when(mPowerFeatureProvider).isExtraDefend();
assertThat(mPowerFeatureProvider.isBatteryDefend(mBatteryInfo)).isFalse();
@@ -173,7 +178,7 @@
@Test
public void isBatteryDefend_defenderModeIsFalse_returnFalse() {
- mBatteryInfo.isBatteryDefender = false;
+ mBatteryInfo.isLongLife = false;
doReturn(true).when(mPowerFeatureProvider).isExtraDefend();
assertThat(mPowerFeatureProvider.isBatteryDefend(mBatteryInfo)).isFalse();
@@ -181,7 +186,7 @@
@Test
public void isBatteryDefend_defenderModeAndExtraDefendAreTrue_returnFalse() {
- mBatteryInfo.isBatteryDefender = true;
+ mBatteryInfo.isLongLife = true;
doReturn(true).when(mPowerFeatureProvider).isExtraDefend();
assertThat(mPowerFeatureProvider.isBatteryDefend(mBatteryInfo)).isFalse();
@@ -189,7 +194,7 @@
@Test
public void isBatteryDefend_extraDefendIsFalse_returnTrue() {
- mBatteryInfo.isBatteryDefender = true;
+ mBatteryInfo.isLongLife = true;
doReturn(false).when(mPowerFeatureProvider).isExtraDefend();
assertThat(mPowerFeatureProvider.isBatteryDefend(mBatteryInfo)).isTrue();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java
index ab1ceb5..7643c41 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetectorTest.java
@@ -18,15 +18,12 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
-
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
-import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
@@ -41,28 +38,23 @@
@Mock private BatteryInfo mBatteryInfo;
private BatteryDefenderDetector mBatteryDefenderDetector;
- private FakeFeatureFactory mFakeFeatureFactory;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final Context context = ApplicationProvider.getApplicationContext();
mBatteryDefenderDetector = new BatteryDefenderDetector(mBatteryInfo, context);
- mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
}
@Test
public void detect_notBatteryDefend_tipInvisible() {
- when(mFakeFeatureFactory.powerUsageFeatureProvider.isBatteryDefend(mBatteryInfo))
- .thenReturn(false);
+ mBatteryInfo.isBatteryDefender = false;
assertThat(mBatteryDefenderDetector.detect().isVisible()).isFalse();
}
@Test
public void detect_isBatteryDefend_tipNew() {
- when(mFakeFeatureFactory.powerUsageFeatureProvider.isBatteryDefend(mBatteryInfo))
- .thenReturn(true);
+ mBatteryInfo.isBatteryDefender = true;
assertThat(mBatteryDefenderDetector.detect().getState())
.isEqualTo(BatteryTip.StateType.NEW);
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index fb29e05..0161178 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -51,6 +51,7 @@
import android.os.PowerManager;
import android.os.UserManager;
import android.provider.Settings;
+import android.telephony.SubscriptionManager;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
@@ -319,7 +320,8 @@
mNetworkProviderSettings.onCreate(Bundle.EMPTY);
verify(mDataUsagePreference).setVisible(true);
- verify(mDataUsagePreference).setTemplate(any(), eq(0) /*subId*/);
+ verify(mDataUsagePreference)
+ .setTemplate(any(), eq(SubscriptionManager.INVALID_SUBSCRIPTION_ID));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
index 8a7419b..599649b 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
@@ -124,8 +124,8 @@
}
@Test(expected = IllegalArgumentException.class)
- public void verifyLaunchSearchResultPageCaller_nullCaller_shouldCrash() {
- mProvider.verifyLaunchSearchResultPageCaller(mActivity, null /* caller */);
+ public void verifyLaunchSearchResultPageCaller_emptyCaller_shouldCrash() {
+ mProvider.verifyLaunchSearchResultPageCaller(mActivity, "");
}
@Test(expected = SecurityException.class)
diff --git a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java
index 8339798..766855c 100644
--- a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java
@@ -21,14 +21,10 @@
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
+import android.content.IntentFilter;
+import android.content.pm.PackageInfo;
import android.service.trust.TrustAgentService;
-import android.text.TextUtils;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -38,34 +34,30 @@
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
-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;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowApplicationPackageManager;
-import java.util.ArrayList;
-import java.util.List;
-
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowLockPatternUtils.class,
ShadowRestrictedLockUtilsInternal.class,
- ShadowDevicePolicyManager.class,
- ShadowApplicationPackageManager.class,
- TrustAgentsPreferenceControllerTest.ShadowTrustAgentManager.class
+ ShadowDevicePolicyManager.class, ShadowApplicationPackageManager.class
})
public class TrustAgentsPreferenceControllerTest {
-
- private static final Intent TEST_INTENT =
- new Intent(TrustAgentService.SERVICE_INTERFACE);
+ private static final ComponentName TRUST_AGENT_A = new ComponentName(
+ "test.data.packageA", "clzAAA");
+ private static final ComponentName TRUST_AGENT_B = new ComponentName(
+ "test.data.packageB", "clzBBB");
+ private static final ComponentName TRUST_AGENT_C = new ComponentName(
+ "test.data.packageC", "clzCCC");
+ private static final ComponentName TRUST_AGENT_D = new ComponentName(
+ "test.data.packageD", "clzDDD");
private Context mContext;
private ShadowApplicationPackageManager mPackageManager;
@@ -84,11 +76,6 @@
mPreferenceScreen.setKey("pref_key");
}
- @After
- public void tearDown() {
- ShadowTrustAgentManager.clearPermissionGrantedList();
- }
-
@Test
public void getAvailabilityStatus_byDefault_shouldBeShown() {
assertThat(mController.getAvailabilityStatus())
@@ -97,8 +84,7 @@
@Test
public void onStart_noTrustAgent_shouldNotAddPreference() {
- final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
+ installFakeAvailableAgents(/* grantPermission= */ false);
mController.displayPreference(mPreferenceScreen);
mController.onStart();
@@ -106,57 +92,34 @@
assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(0);
}
- @Ignore("b/313612480")
@Test
- public void
- onStart_hasAUninstalledTrustAgent_shouldRemoveOnePreferenceAndLeaveTwoPreferences() {
- final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
- final ResolveInfo uninstalledTrustAgent = availableAgents.get(0);
-
- for (ResolveInfo rInfo : availableAgents) {
- ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
- }
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
+ public void onStart_uninstalledTrustAgent_shouldRemoveOnePreferenceAndLeaveTwoPreferences() {
+ installFakeAvailableAgents(/* grantPermission= */ true);
mController.displayPreference(mPreferenceScreen);
mController.onStart();
- availableAgents.remove(uninstalledTrustAgent);
+ uninstallAgent(TRUST_AGENT_A);
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
mController.onStart();
assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(2);
}
- @Ignore("b/313612480")
@Test
public void onStart_hasANewTrustAgent_shouldAddOnePreferenceAndHaveFourPreferences() {
- final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
- final ComponentName newComponentName = new ComponentName("test.data.packageD", "clzDDD");
- final ResolveInfo newTrustAgent = createFakeResolveInfo(newComponentName);
- for (ResolveInfo rInfo : availableAgents) {
- ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
- }
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
+ installFakeAvailableAgents(/* grantPermission= */ true);
mController.displayPreference(mPreferenceScreen);
mController.onStart();
- availableAgents.add(newTrustAgent);
- ShadowTrustAgentManager.grantPermissionToResolveInfo(newTrustAgent);
+ installFakeAvailableAgent(TRUST_AGENT_D, /* grantPermission= */ true);
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
mController.onStart();
assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(4);
}
- @Ignore("b/313612480")
@Test
public void onStart_hasUnrestrictedTrustAgent_shouldAddThreeChangeablePreferences() {
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(0);
- final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
- for (ResolveInfo rInfo : availableAgents) {
- ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
- }
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
+ installFakeAvailableAgents(/* grantPermission= */ true);
mController.displayPreference(mPreferenceScreen);
mController.onStart();
@@ -169,14 +132,9 @@
}
}
- @Ignore("b/313612480")
@Test
- public void onStart_hasRestrictedTructAgent_shouldAddThreeUnchangeablePreferences() {
- final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
- for (ResolveInfo rInfo : availableAgents) {
- ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
- }
- mPackageManager.setResolveInfosForIntent(TEST_INTENT, availableAgents);
+ public void onStart_hasRestrictedTrustAgent_shouldAddThreeUnchangeablePreferences() {
+ installFakeAvailableAgents(/* grantPermission= */ true);
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS);
@@ -191,51 +149,30 @@
}
}
- private List<ResolveInfo> createFakeAvailableAgents() {
- final List<ComponentName> componentNames = new ArrayList<>();
- componentNames.add(new ComponentName("test.data.packageA", "clzAAA"));
- componentNames.add(new ComponentName("test.data.packageB", "clzBBB"));
- componentNames.add(new ComponentName("test.data.packageC", "clzCCC"));
- final List<ResolveInfo> result = new ArrayList<>();
- for (ComponentName cn : componentNames) {
- final ResolveInfo ri = createFakeResolveInfo(cn);
- result.add(ri);
- }
- return result;
+ private void installFakeAvailableAgents(boolean grantPermission) {
+ installFakeAvailableAgent(TRUST_AGENT_A, grantPermission);
+ installFakeAvailableAgent(TRUST_AGENT_B, grantPermission);
+ installFakeAvailableAgent(TRUST_AGENT_C, grantPermission);
}
- private ResolveInfo createFakeResolveInfo(ComponentName cn) {
- final ResolveInfo ri = new ResolveInfo();
- ri.serviceInfo = new ServiceInfo();
- ri.serviceInfo.packageName = cn.getPackageName();
- ri.serviceInfo.name = cn.getClassName();
- ri.serviceInfo.applicationInfo = new ApplicationInfo();
- ri.serviceInfo.applicationInfo.packageName = cn.getPackageName();
- ri.serviceInfo.applicationInfo.name = cn.getClassName();
- return ri;
+ private void installFakeAvailableAgent(ComponentName name,
+ boolean grantPermission) {
+ mPackageManager.addServiceIfNotPresent(name);
+ mPackageManager.addIntentFilterForService(name,
+ new IntentFilter(TrustAgentService.SERVICE_INTERFACE));
+ if (!grantPermission) {
+ return;
+ }
+ PackageInfo pkgInfo = mPackageManager.getInternalMutablePackageInfo(
+ name.getPackageName());
+ pkgInfo.requestedPermissions =
+ new String[]{android.Manifest.permission.PROVIDE_TRUST_AGENT};
+ pkgInfo.requestedPermissionsFlags =
+ new int[]{PackageInfo.REQUESTED_PERMISSION_GRANTED};
}
- @Implements(TrustAgentManager.class)
- public static class ShadowTrustAgentManager {
- private final static List<ResolveInfo> sPermissionGrantedList = new ArrayList<>();
-
- @Implementation
- protected boolean shouldProvideTrust(ResolveInfo resolveInfo, PackageManager pm) {
- for (ResolveInfo info : sPermissionGrantedList) {
- if (info.serviceInfo.equals(resolveInfo.serviceInfo)) {
- return true;
- }
- }
-
- return false;
- }
-
- private static void grantPermissionToResolveInfo(ResolveInfo rInfo) {
- sPermissionGrantedList.add(rInfo);
- }
-
- private static void clearPermissionGrantedList() {
- sPermissionGrantedList.clear();
- }
+ private void uninstallAgent(ComponentName name) {
+ mPackageManager.removeService(name);
+ mPackageManager.removePackage(name.getPackageName());
}
}
diff --git a/tests/spa_unit/src/com/android/settings/spa/network/PrimarySimRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/spa/network/PrimarySimRepositoryTest.kt
new file mode 100644
index 0000000..459afa9
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/spa/network/PrimarySimRepositoryTest.kt
@@ -0,0 +1,206 @@
+/*
+ * 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.spa.network
+
+import android.content.Context
+import android.content.res.Resources
+import android.telephony.SubscriptionInfo
+import android.telephony.SubscriptionManager
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settingslib.spa.widget.preference.ListPreferenceOption
+import com.google.common.truth.Truth.assertThat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.stub
+
+@RunWith(AndroidJUnit4::class)
+class PrimarySimRepositoryTest {
+ @get:Rule
+ val composeTestRule = createComposeRule()
+
+ private val mockSubscriptionManager = mock<SubscriptionManager> {
+ on { addOnSubscriptionsChangedListener(any(), any()) } doAnswer {
+ val listener = it.arguments[1] as SubscriptionManager.OnSubscriptionsChangedListener
+ listener.onSubscriptionsChanged()
+ }
+ on { getPhoneNumber(SUB_ID_1) } doReturn NUMBER_1
+ on { getPhoneNumber(SUB_ID_2) } doReturn NUMBER_2
+ }
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(SubscriptionManager::class.java) } doReturn mockSubscriptionManager
+ }
+ private val spyResources: Resources = spy(context.resources)
+
+ @Test
+ fun getPrimarySimInfo_oneSim_returnNull() {
+ val simList = listOf(
+ SUB_INFO_1,
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNull()
+ }
+
+ @Test
+ fun getPrimarySimInfo_verifyCallsList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ ListPreferenceOption(
+ id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+ text = context.getString(R.string.sim_calls_ask_first_prefs_title),
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.callsList).isEqualTo(expectedList)
+ }
+
+ @Test
+ fun getPrimarySimInfo_verifySmsList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ ListPreferenceOption(
+ id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
+ text = context.getString(R.string.sim_calls_ask_first_prefs_title),
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.smsList).isEqualTo(expectedList)
+ }
+
+ @Test
+ fun getPrimarySimInfo_noAskEveryTime_verifySmsList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ context.stub {
+ on { resources } doReturn spyResources
+ }
+ spyResources.stub {
+ on {
+ getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support)
+ } doReturn false
+ }
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.smsList).isEqualTo(expectedList)
+ }
+
+ @Test
+ fun getPrimarySimInfo_verifyDataList() {
+ val simList = listOf(
+ SUB_INFO_1,
+ SUB_INFO_2
+ )
+ val expectedList = listOf(
+ ListPreferenceOption(
+ id = SUB_INFO_1.subscriptionId,
+ text = "${SUB_INFO_1.displayName}",
+ summary = NUMBER_1
+ ),
+ ListPreferenceOption(
+ id = SUB_INFO_2.subscriptionId,
+ text = "${SUB_INFO_2.displayName}",
+ summary = NUMBER_2
+ ),
+ )
+
+ val primarySimInfo = PrimarySimRepository(context).getPrimarySimInfo(simList)
+
+ assertThat(primarySimInfo).isNotNull()
+ assertThat(primarySimInfo?.dataList).isEqualTo(expectedList)
+ }
+
+ private companion object {
+ const val SUB_ID_1 = 1
+ const val SUB_ID_2 = 2
+ const val DISPLAY_NAME_1 = "Sub 1"
+ const val DISPLAY_NAME_2 = "Sub 2"
+ const val NUMBER_1 = "000000001"
+ const val NUMBER_2 = "000000002"
+ const val MCC = "310"
+
+ val SUB_INFO_1: SubscriptionInfo = SubscriptionInfo.Builder().apply {
+ setId(SUB_ID_1)
+ setDisplayName(DISPLAY_NAME_1)
+ setMcc(MCC)
+ }.build()
+
+ val SUB_INFO_2: SubscriptionInfo = SubscriptionInfo.Builder().apply {
+ setId(SUB_ID_2)
+ setDisplayName(DISPLAY_NAME_2)
+ setMcc(MCC)
+ }.build()
+ }
+}
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index 55df480..be43f8e 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -32,7 +32,6 @@
"truth",
"kotlinx_coroutines_test",
"Settings-testutils2",
- "MediaDrmSettingsFlagsLib",
"servicestests-utils",
// Don't add SettingsLib libraries here - you can use them directly as they are in the
// instrumented Settings app.
diff --git a/tests/unit/src/com/android/settings/development/mediadrm/ForceSwSecureCryptoFallbackPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/mediadrm/ForceSwSecureCryptoFallbackPreferenceControllerTest.java
index 2a0cd05..5eb76f1 100644
--- a/tests/unit/src/com/android/settings/development/mediadrm/ForceSwSecureCryptoFallbackPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/development/mediadrm/ForceSwSecureCryptoFallbackPreferenceControllerTest.java
@@ -29,6 +29,8 @@
import android.content.Context;
import com.android.settings.media_drm.Flags;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import androidx.preference.SwitchPreference;
@@ -65,10 +67,10 @@
}
@Test
+ @EnableFlags(Flags.FLAG_FORCE_L3_ENABLED)
public void updateState_flagEnabled_checkPreference() {
- mSetFlagsRule.enableFlags(Flags.FLAG_FORCE_L3_ENABLED);
mController.updateState(mPreference);
- assumeTrue(mPreference.isEnabled());
+ assertThat(mPreference.isEnabled()).isTrue();
assertThat(mPreference.isChecked()).isFalse();
assertThat(WidevineProperties.forcel3_enabled().orElse(false)).isFalse();
@@ -85,33 +87,22 @@
assertThat(WidevineProperties.forcel3_enabled().orElse(false)).isFalse();
assertThat(mPreference.isEnabled()).isTrue();
assertThat(mPreference.isChecked()).isFalse();
-
- // Test flag rollback
- mController.setChecked(true);
- mController.updateState(mPreference);
- assertThat(mPreference.isChecked()).isTrue();
- assertThat(WidevineProperties.forcel3_enabled().orElse(false)).isTrue();
- mSetFlagsRule.disableFlags(Flags.FLAG_FORCE_L3_ENABLED);
- mController.updateState(mPreference);
- assertThat(mPreference.isEnabled()).isFalse();
- assertThat(mPreference.isChecked()).isFalse();
- assertThat(WidevineProperties.forcel3_enabled().orElse(false)).isFalse();
}
@Test
+ @DisableFlags(Flags.FLAG_FORCE_L3_ENABLED)
public void updateState_flagDisabled_checkPreference() {
- mSetFlagsRule.disableFlags(Flags.FLAG_FORCE_L3_ENABLED);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
+ @EnableFlags(Flags.FLAG_FORCE_L3_ENABLED)
public void updateState_checkWidevine() throws Exception {
try (MediaDrm drm = new MediaDrm(WIDEVINE_UUID)) {
assumeTrue(drm.getPropertyString("securityLevel").equals("L1"));
- mSetFlagsRule.enableFlags(Flags.FLAG_FORCE_L3_ENABLED);
mController.updateState(mPreference);
- assumeTrue(mPreference.isEnabled());
+ assertThat(mPreference.isEnabled()).isTrue();
} catch (UnsupportedSchemeException ex) {
assumeNoException(ex);
}
@@ -139,11 +130,11 @@
}
@Test
+ @EnableFlags(Flags.FLAG_FORCE_L3_ENABLED)
public void updateState_checkWhenWidevineReady() throws Exception {
try (MediaDrm drm = new MediaDrm(WIDEVINE_UUID)) {
if (drm.getPropertyString("securityLevel").equals("L1")) {
String version = drm.getPropertyString(MediaDrm.PROPERTY_VERSION);
- mSetFlagsRule.enableFlags(Flags.FLAG_FORCE_L3_ENABLED);
mController.updateState(mPreference);
if (Integer.parseInt(version.split("\\.", 2)[0]) >= 19) {
assertThat(mPreference.isEnabled()).isTrue();
diff --git a/tests/unit/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtilsTest.kt b/tests/unit/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtilsTest.kt
index 94f082d..95f69da 100644
--- a/tests/unit/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtilsTest.kt
+++ b/tests/unit/src/com/android/settings/fuelgauge/batteryusage/AppOptModeSharedPreferencesUtilsTest.kt
@@ -83,8 +83,17 @@
}
@Test
- fun updateAppOptModeExpirationInternal_withExpirationTime_verifyData() {
- insertAppOptModeEventForTest(expirationTime = 1000L)
+ fun updateAppOptModeExpirationInternal_withoutExpirationTime_verifyEmptyList() {
+ insertAppOptModeEventForTest(expirationTime = UNLIMITED_EXPIRE_TIME)
+
+ assertThat(AppOptModeSharedPreferencesUtils.getAllEvents(context)).isEmpty()
+ }
+
+ @Test
+ fun updateAppOptModeExpirationInternal_setOptimizedModeWithFlagEnabled_verifyData() {
+ whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
+ .thenReturn(true)
+ insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_OPTIMIZED)
val events = AppOptModeSharedPreferencesUtils.getAllEvents(context)
@@ -99,8 +108,46 @@
}
@Test
- fun updateAppOptModeExpirationInternal_withoutExpirationTime_verifyEmptyList() {
- insertAppOptModeEventForTest(expirationTime = UNLIMITED_EXPIRE_TIME)
+ fun updateAppOptModeExpirationInternal_setOptimizedModeWithFlagDisabled_verifyData() {
+ whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
+ .thenReturn(false)
+ insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_OPTIMIZED)
+
+ val events = AppOptModeSharedPreferencesUtils.getAllEvents(context)
+
+ assertThat(events).hasSize(1)
+ assertAppOptimizationModeEventInfo(
+ events[0],
+ UID,
+ PACKAGE_NAME,
+ MODE_OPTIMIZED,
+ expirationTime = 1000L
+ )
+ }
+
+ @Test
+ fun updateAppOptModeExpirationInternal_setRestrictedModeWithFlagEnabled_verifyData() {
+ whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
+ .thenReturn(true)
+ insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_RESTRICTED)
+
+ val events = AppOptModeSharedPreferencesUtils.getAllEvents(context)
+
+ assertThat(events).hasSize(1)
+ assertAppOptimizationModeEventInfo(
+ events[0],
+ UID,
+ PACKAGE_NAME,
+ MODE_RESTRICTED,
+ expirationTime = 1000L
+ )
+ }
+
+ @Test
+ fun updateAppOptModeExpirationInternal_setRestrictedModeWithFlagDisabled_verifyEmptyList() {
+ whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
+ .thenReturn(false)
+ insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_RESTRICTED)
assertThat(AppOptModeSharedPreferencesUtils.getAllEvents(context)).isEmpty()
}
@@ -237,14 +284,14 @@
assertThat(currentOptMode).isEqualTo(MODE_RESTRICTED)
}
- private fun insertAppOptModeEventForTest(expirationTime: Long) {
+ private fun insertAppOptModeEventForTest(expirationTime: Long, mode: Int = MODE_OPTIMIZED) {
whenever(testBatteryOptimizeUtils?.isOptimizeModeMutable).thenReturn(true)
- whenever(testBatteryOptimizeUtils?.getAppOptimizationMode(true)).thenReturn(MODE_OPTIMIZED)
+ whenever(testBatteryOptimizeUtils?.getAppOptimizationMode(true)).thenReturn(mode)
AppOptModeSharedPreferencesUtils.updateAppOptModeExpirationInternal(
context,
mutableListOf(UID),
mutableListOf(PACKAGE_NAME),
- mutableListOf(MODE_OPTIMIZED),
+ mutableListOf(mode),
longArrayOf(expirationTime),
) { _: Int, _: String ->
testBatteryOptimizeUtils
diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
index 152091a..f31e274 100644
--- a/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
@@ -131,8 +131,7 @@
private MobileNetworkInfoEntity setupMobileNetworkInfoEntity(String subId,
boolean isDatEnabled) {
- return new MobileNetworkInfoEntity(subId, false, false, isDatEnabled, false, false, false,
- false, false, false, false, false);
+ return new MobileNetworkInfoEntity(subId, isDatEnabled, false);
}
@Test