Merge "[ToA] New string for title and summary" into main
diff --git a/src/com/android/settings/RegulatoryInfoDisplayActivity.kt b/src/com/android/settings/RegulatoryInfoDisplayActivity.kt
index fdf66c3..6b5ccc7 100644
--- a/src/com/android/settings/RegulatoryInfoDisplayActivity.kt
+++ b/src/com/android/settings/RegulatoryInfoDisplayActivity.kt
@@ -23,6 +23,7 @@
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.getRegulatoryInfo
+import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
/**
* [Activity] that displays regulatory information for the "Regulatory information"
@@ -53,8 +54,8 @@
return
}
- val regulatoryText = resources.getText(R.string.regulatory_info_text)
- if (regulatoryText.isNotEmpty()) {
+ val regulatoryText = getRegulatoryText()
+ if (!regulatoryText.isNullOrEmpty()) {
builder.setMessage(regulatoryText)
val dialog = builder.show()
// we have to show the dialog first, or the setGravity() call will throw a NPE
@@ -64,4 +65,10 @@
finish()
}
}
+
+ private fun getRegulatoryText(): CharSequence? {
+ val regulatoryInfoText = resources.getText(R.string.regulatory_info_text)
+ if (regulatoryInfoText.isNotBlank()) return regulatoryInfoText
+ return featureFactory.hardwareInfoFeatureProvider?.countryIfOriginLabel
+ }
}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt
index 400ece9..e9866d7 100644
--- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProvider.kt
@@ -23,4 +23,9 @@
* Returns the manufactured year
*/
val manufacturedYear: String?
-}
\ No newline at end of file
+
+ /**
+ * The country of origin label.
+ */
+ val countryIfOriginLabel: String
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt
deleted file mode 100644
index 54a112b..0000000
--- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFeatureProviderImpl.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2023 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.deviceinfo.hardwareinfo
-
-/**
- * Feature provider for hardware info
- */
-object HardwareInfoFeatureProviderImpl : HardwareInfoFeatureProvider {
- override val manufacturedYear: String?
- get() = null
-}
\ No newline at end of file
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt b/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt
index 92d7733..9d1a826 100644
--- a/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/ManufacturedYearPreferenceController.kt
@@ -22,7 +22,8 @@
/** Preference controller for Manufactured Year. */
class ManufacturedYearPreferenceController(context: Context, preferenceKey: String) :
BasePreferenceController(context, preferenceKey) {
- private val year: String? = featureFactory.hardwareInfoFeatureProvider.manufacturedYear
+
+ private val year: String? = featureFactory.hardwareInfoFeatureProvider?.manufacturedYear
override fun getAvailabilityStatus(): Int =
if (!year.isNullOrEmpty()) AVAILABLE else UNSUPPORTED_ON_DEVICE
diff --git a/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt b/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt
index e26e061..2982e47 100644
--- a/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt
+++ b/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfo.kt
@@ -23,8 +23,7 @@
import androidx.annotation.DrawableRes
import androidx.annotation.VisibleForTesting
import com.android.settings.R
-
-
+import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
/** To load Regulatory Info from device. */
object RegulatoryInfo {
@@ -38,10 +37,10 @@
/** Gets the regulatory drawable. */
fun Context.getRegulatoryInfo(): Drawable? {
- val sku = getSku()
+ val sku = getSku().lowercase()
if (sku.isNotBlank()) {
// When hardware coo property exists, use regulatory_info_<sku>_<coo> resource if valid.
- val coo = getCoo()
+ val coo = getCoo().lowercase()
if (coo.isNotBlank()) {
getRegulatoryInfo("${REGULATORY_INFO_RESOURCE}_${sku}_$coo")?.let { return it }
}
@@ -51,9 +50,9 @@
return getRegulatoryInfo(REGULATORY_INFO_RESOURCE)
}
- private fun getCoo(): String = SystemProperties.get(KEY_COO).lowercase()
+ fun getCoo(): String = SystemProperties.get(KEY_COO)
- private fun getSku(): String = SystemProperties.get(KEY_SKU).lowercase()
+ fun getSku(): String = SystemProperties.get(KEY_SKU)
private fun Context.getRegulatoryInfo(fileName: String): Drawable? {
val overlayPackageName =
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
index 51dce26..5e6d7d5 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
@@ -556,9 +556,11 @@
String.format(
"getBatterySinceLastFullChargeUsageData() size=%d time=%d/ms",
batteryHistoryMap.size(), (System.currentTimeMillis() - start)));
-
final Map<Integer, Map<Integer, BatteryDiffData>> batteryUsageData =
- DataProcessor.getBatteryUsageData(context, batteryHistoryMap);
+ DataProcessor.getBatteryUsageData(
+ context,
+ new UserIdsSeries(context, /* mainUserOnly= */ false),
+ batteryHistoryMap);
if (batteryUsageData == null) {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
index fb5b9a1..d1bf0d2 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
@@ -84,12 +84,12 @@
}
@VisibleForTesting
- static void loadAppUsageData(final Context context) {
+ static void loadAppUsageData(final Context context, final UserIdsSeries userIdsSeries) {
final long start = System.currentTimeMillis();
final Map<Long, UsageEvents> appUsageEvents =
sFakeAppUsageEventsSupplier != null
? sFakeAppUsageEventsSupplier.get()
- : DataProcessor.getAppUsageEvents(context);
+ : DataProcessor.getAppUsageEvents(context, userIdsSeries);
if (appUsageEvents == null) {
Log.w(TAG, "loadAppUsageData() returns null");
return;
@@ -113,13 +113,15 @@
DatabaseUtils.sendAppUsageEventData(context, appUsageEventList);
}
- private static void preprocessBatteryUsageSlots(final Context context) {
+ private static void preprocessBatteryUsageSlots(
+ final Context context, final UserIdsSeries userIdsSeries) {
final long start = System.currentTimeMillis();
final Handler handler = new Handler(Looper.getMainLooper());
final BatteryLevelData batteryLevelData =
DataProcessManager.getBatteryLevelData(
context,
handler,
+ userIdsSeries,
/* isFromPeriodJob= */ true,
batteryDiffDataMap -> {
DatabaseUtils.sendBatteryUsageSlotData(
@@ -162,8 +164,12 @@
loadBatteryStatsData(context, isFullChargeStart);
if (!isFullChargeStart) {
// No app usage data or battery diff data at this time.
- loadAppUsageData(context);
- preprocessBatteryUsageSlots(context);
+ final UserIdsSeries userIdsSeries =
+ new UserIdsSeries(context, /* mainUserOnly= */ true);
+ if (!userIdsSeries.isCurrentUserLocked()) {
+ loadAppUsageData(context, userIdsSeries);
+ preprocessBatteryUsageSlots(context, userIdsSeries);
+ }
}
Log.d(
TAG,
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java b/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java
index b3bcb47..3e8df61 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DataProcessManager.java
@@ -21,8 +21,6 @@
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
-import android.os.UserHandle;
-import android.os.UserManager;
import android.util.ArrayMap;
import android.util.Log;
@@ -30,7 +28,6 @@
import androidx.annotation.Nullable;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.settings.Utils;
import java.util.ArrayList;
import java.util.Calendar;
@@ -82,7 +79,7 @@
private final long mLastFullChargeTimestamp;
private final Context mContext;
private final Handler mHandler;
- private final UserManager mUserManager;
+ private final UserIdsSeries mUserIdsSeries;
private final OnBatteryDiffDataMapLoadedListener mCallbackFunction;
private final List<AppUsageEvent> mAppUsageEventList = new ArrayList<>();
private final List<BatteryEvent> mBatteryEventList = new ArrayList<>();
@@ -123,6 +120,7 @@
DataProcessManager(
Context context,
Handler handler,
+ final UserIdsSeries userIdsSeries,
final long rawStartTimestamp,
final long lastFullChargeTimestamp,
@NonNull final OnBatteryDiffDataMapLoadedListener callbackFunction,
@@ -130,7 +128,7 @@
@NonNull final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
mContext = context.getApplicationContext();
mHandler = handler;
- mUserManager = mContext.getSystemService(UserManager.class);
+ mUserIdsSeries = userIdsSeries;
mRawStartTimestamp = rawStartTimestamp;
mLastFullChargeTimestamp = lastFullChargeTimestamp;
mCallbackFunction = callbackFunction;
@@ -142,10 +140,11 @@
DataProcessManager(
Context context,
Handler handler,
+ final UserIdsSeries userIdsSeries,
@NonNull final OnBatteryDiffDataMapLoadedListener callbackFunction) {
mContext = context.getApplicationContext();
mHandler = handler;
- mUserManager = mContext.getSystemService(UserManager.class);
+ mUserIdsSeries = userIdsSeries;
mCallbackFunction = callbackFunction;
mRawStartTimestamp = 0L;
mLastFullChargeTimestamp = 0L;
@@ -175,10 +174,18 @@
// Loads the latest app usage list from the service.
loadCurrentAppUsageList();
// Loads existing battery usage slots from database.
- loadBatteryUsageSlotList();
+ if (mUserIdsSeries.isMainUserProfileOnly()) {
+ loadBatteryUsageSlotList();
+ } else {
+ mIsBatteryUsageSlotLoaded = true;
+ }
}
// Loads app usage list from database.
- loadDatabaseAppUsageList();
+ if (mUserIdsSeries.isMainUserProfileOnly()) {
+ loadDatabaseAppUsageList();
+ } else {
+ mIsDatabaseAppUsageLoaded = true;
+ }
// Loads the battery event list from database.
loadPowerConnectionBatteryEventList();
} else {
@@ -264,6 +271,7 @@
private void loadCurrentAppUsageList() {
new AsyncTask<Void, Void, List<AppUsageEvent>>() {
@Override
+ @Nullable
protected List<AppUsageEvent> doInBackground(Void... voids) {
if (!shouldLoadAppUsageData()) {
Log.d(TAG, "not loadCurrentAppUsageList");
@@ -271,33 +279,21 @@
}
final long startTime = System.currentTimeMillis();
// Loads the current battery usage data from the battery stats service.
- final int currentUserId = getCurrentUserId();
- final int workProfileUserId = getWorkProfileUserId();
- final UsageEvents usageEventsForCurrentUser =
- DataProcessor.getAppUsageEventsForUser(
- mContext, currentUserId, mRawStartTimestamp);
- // If fail to load usage events for current user, return null directly and screen-on
- // time will not be shown in the UI.
- if (usageEventsForCurrentUser == null) {
- Log.w(TAG, "usageEventsForCurrentUser is null");
- return null;
- }
- UsageEvents usageEventsForWorkProfile = null;
- if (workProfileUserId != Integer.MIN_VALUE) {
- usageEventsForWorkProfile =
- DataProcessor.getAppUsageEventsForUser(
- mContext, workProfileUserId, mRawStartTimestamp);
- } else {
- Log.d(TAG, "there is no work profile");
- }
-
final Map<Long, UsageEvents> usageEventsMap = new ArrayMap<>();
- usageEventsMap.put(Long.valueOf(currentUserId), usageEventsForCurrentUser);
- if (usageEventsForWorkProfile != null) {
- Log.d(TAG, "usageEventsForWorkProfile is null");
- usageEventsMap.put(Long.valueOf(workProfileUserId), usageEventsForWorkProfile);
+ for (int userId : mUserIdsSeries.getVisibleUserIds()) {
+ final UsageEvents usageEventsForCurrentUser =
+ DataProcessor.getCurrentAppUsageEventsForUser(
+ mContext, mUserIdsSeries, userId, mRawStartTimestamp);
+ if (usageEventsForCurrentUser == null) {
+ // If fail to load usage events for any user, return null directly and
+ // screen-on time will not be shown in the UI.
+ if (userId == mUserIdsSeries.getCurrentUserId()) {
+ return null;
+ }
+ } else {
+ usageEventsMap.put(Long.valueOf(userId), usageEventsForCurrentUser);
+ }
}
-
final List<AppUsageEvent> appUsageEventList =
DataProcessor.generateAppUsageEventListFromUsageEvents(
mContext, usageEventsMap);
@@ -337,7 +333,7 @@
DatabaseUtils.getAppUsageEventForUsers(
mContext,
Calendar.getInstance(),
- getCurrentUserIds(),
+ mUserIdsSeries.getVisibleUserIds(),
mRawStartTimestamp);
Log.d(
TAG,
@@ -435,6 +431,7 @@
final Map<Long, BatteryDiffData> batteryDiffDataMap =
DataProcessor.getBatteryDiffDataMapFromStatsService(
mContext,
+ mUserIdsSeries,
mRawStartTimestamp,
getSystemAppsPackageNames(),
getSystemAppsUids());
@@ -514,6 +511,7 @@
batteryDiffDataMap.putAll(
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
mHourlyBatteryLevelsPerDay,
mBatteryHistoryMap,
mAppUsagePeriodMap,
@@ -546,9 +544,8 @@
if (!mShowScreenOnTime) {
return false;
}
- final int currentUserId = getCurrentUserId();
// If current user is locked, no need to load app usage data from service or database.
- if (mUserManager == null || !mUserManager.isUserUnlocked(currentUserId)) {
+ if (mUserIdsSeries.isCurrentUserLocked()) {
Log.d(TAG, "shouldLoadAppUsageData: false, current user is locked");
mShowScreenOnTime = false;
return false;
@@ -556,26 +553,6 @@
return true;
}
- // Returns the list of current user id and work profile id if exists.
- private List<Integer> getCurrentUserIds() {
- final List<Integer> userIds = new ArrayList<>();
- userIds.add(getCurrentUserId());
- final int workProfileUserId = getWorkProfileUserId();
- if (workProfileUserId != Integer.MIN_VALUE) {
- userIds.add(workProfileUserId);
- }
- return userIds;
- }
-
- private int getCurrentUserId() {
- return mContext.getUserId();
- }
-
- private int getWorkProfileUserId() {
- final UserHandle userHandle = Utils.getManagedProfile(mUserManager);
- return userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
- }
-
private synchronized Set<String> getSystemAppsPackageNames() {
if (mSystemAppsPackageNames == null) {
mSystemAppsPackageNames = DataProcessor.getSystemAppsPackageNames(mContext);
@@ -599,6 +576,7 @@
public static BatteryLevelData getBatteryLevelData(
Context context,
@Nullable Handler handler,
+ final UserIdsSeries userIdsSeries,
final boolean isFromPeriodJob,
final OnBatteryDiffDataMapLoadedListener onBatteryUsageMapLoadedListener) {
final long start = System.currentTimeMillis();
@@ -610,13 +588,14 @@
lastFullChargeTime,
DatabaseUtils.BATTERY_LEVEL_RECORD_EVENTS);
final long startTimestamp =
- batteryLevelRecordEvents.isEmpty()
+ (batteryLevelRecordEvents.isEmpty() || !userIdsSeries.isMainUserProfileOnly())
? lastFullChargeTime
: batteryLevelRecordEvents.get(0).getTimestamp();
final BatteryLevelData batteryLevelData =
getPeriodBatteryLevelData(
context,
handler,
+ userIdsSeries,
startTimestamp,
lastFullChargeTime,
isFromPeriodJob,
@@ -636,6 +615,7 @@
private static BatteryLevelData getPeriodBatteryLevelData(
Context context,
@Nullable Handler handler,
+ final UserIdsSeries userIdsSeries,
final long startTimestamp,
final long lastFullChargeTime,
final boolean isFromPeriodJob,
@@ -663,7 +643,9 @@
lastFullChargeTime);
if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) {
Log.d(TAG, "batteryHistoryMap is null in getPeriodBatteryLevelData()");
- new DataProcessManager(context, handler, onBatteryDiffDataMapLoadedListener).start();
+ new DataProcessManager(
+ context, handler, userIdsSeries, onBatteryDiffDataMapLoadedListener)
+ .start();
return null;
}
@@ -675,7 +657,9 @@
DataProcessor.getLevelDataThroughProcessedHistoryMap(
context, processedBatteryHistoryMap);
if (batteryLevelData == null) {
- new DataProcessManager(context, handler, onBatteryDiffDataMapLoadedListener).start();
+ new DataProcessManager(
+ context, handler, userIdsSeries, onBatteryDiffDataMapLoadedListener)
+ .start();
Log.d(TAG, "getBatteryLevelData() returns null");
return null;
}
@@ -684,6 +668,7 @@
new DataProcessManager(
context,
handler,
+ userIdsSeries,
startTimestamp,
lastFullChargeTime,
onBatteryDiffDataMapLoadedListener,
diff --git a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
index 2ef12f1..da8481d 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/DataProcessor.java
@@ -28,7 +28,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.content.pm.UserInfo;
import android.os.BatteryConsumer;
import android.os.BatteryStatsManager;
import android.os.BatteryUsageStats;
@@ -52,7 +51,6 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.PowerProfile;
-import com.android.settings.Utils;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.fuelgauge.BatteryStatus;
@@ -134,6 +132,7 @@
@Nullable
public static Map<Integer, Map<Integer, BatteryDiffData>> getBatteryUsageData(
Context context,
+ UserIdsSeries userIdsSeries,
@Nullable final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) {
Log.d(TAG, "getBatteryLevelData() returns null");
@@ -161,6 +160,7 @@
context,
getBatteryDiffDataMap(
context,
+ userIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
processedBatteryHistoryMap,
/* appUsagePeriodMap= */ null,
@@ -183,24 +183,21 @@
/** Gets the {@link UsageEvents} from system service for all unlocked users. */
@Nullable
- public static Map<Long, UsageEvents> getAppUsageEvents(Context context) {
+ public static Map<Long, UsageEvents> getAppUsageEvents(
+ Context context, UserIdsSeries userIdsSeries) {
final long start = System.currentTimeMillis();
context = DatabaseUtils.getParentContext(context);
if (context == null) {
return null;
}
final Map<Long, UsageEvents> resultMap = new ArrayMap();
- final UserManager userManager = context.getSystemService(UserManager.class);
- if (userManager == null) {
- return null;
- }
final long sixDaysAgoTimestamp =
DatabaseUtils.getTimestampSixDaysAgo(Calendar.getInstance());
- for (final UserInfo user : userManager.getAliveUsers()) {
+ for (final int userId : userIdsSeries.getVisibleUserIds()) {
final UsageEvents events =
- getAppUsageEventsForUser(context, userManager, user.id, sixDaysAgoTimestamp);
+ getAppUsageEventsForUser(context, userIdsSeries, userId, sixDaysAgoTimestamp);
if (events != null) {
- resultMap.put(Long.valueOf(user.id), events);
+ resultMap.put(Long.valueOf(userId), events);
}
}
final long elapsedTime = System.currentTimeMillis() - start;
@@ -212,22 +209,21 @@
/** Gets the {@link UsageEvents} from system service for the specific user. */
@Nullable
- public static UsageEvents getAppUsageEventsForUser(
- Context context, final int userID, final long startTimestampOfLevelData) {
+ public static UsageEvents getCurrentAppUsageEventsForUser(
+ Context context,
+ final UserIdsSeries userIdsSeries,
+ final int userID,
+ final long startTimestampOfLevelData) {
final long start = System.currentTimeMillis();
context = DatabaseUtils.getParentContext(context);
if (context == null) {
return null;
}
- final UserManager userManager = context.getSystemService(UserManager.class);
- if (userManager == null) {
- return null;
- }
final long sixDaysAgoTimestamp =
DatabaseUtils.getTimestampSixDaysAgo(Calendar.getInstance());
final long earliestTimestamp = Math.max(sixDaysAgoTimestamp, startTimestampOfLevelData);
final UsageEvents events =
- getAppUsageEventsForUser(context, userManager, userID, earliestTimestamp);
+ getAppUsageEventsForUser(context, userIdsSeries, userID, earliestTimestamp);
final long elapsedTime = System.currentTimeMillis() - start;
Log.d(
TAG,
@@ -521,6 +517,7 @@
static Map<Long, BatteryDiffData> getBatteryDiffDataMap(
Context context,
+ final UserIdsSeries userIdsSeries,
final List<BatteryLevelData.PeriodBatteryLevelData> hourlyBatteryLevelsPerDay,
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap,
final Map<Integer, Map<Integer, Map<Long, Map<String, List<AppUsagePeriod>>>>>
@@ -528,11 +525,6 @@
final @NonNull Set<String> systemAppsPackageNames,
final @NonNull Set<Integer> systemAppsUids) {
final Map<Long, BatteryDiffData> batteryDiffDataMap = new ArrayMap<>();
- final int currentUserId = context.getUserId();
- final UserHandle userHandle =
- Utils.getManagedProfile(context.getSystemService(UserManager.class));
- final int workProfileUserId =
- userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
// Each time slot usage diff data =
// sum(Math.abs(timestamp[i+1] data - timestamp[i] data));
// since we want to aggregate every hour usage diff data into a single time slot.
@@ -569,8 +561,7 @@
endTimestamp,
startBatteryLevel,
endBatteryLevel,
- currentUserId,
- workProfileUserId,
+ userIdsSeries,
slotDuration,
systemAppsPackageNames,
systemAppsUids,
@@ -629,6 +620,7 @@
@Nullable
static BatteryDiffData generateBatteryDiffData(
final Context context,
+ final UserIdsSeries userIdsSeries,
final long startTimestamp,
final List<BatteryHistEntry> batteryHistEntryList,
final @NonNull Set<String> systemAppsPackageNames,
@@ -650,15 +642,9 @@
systemAppsUids,
/* isAccumulated= */ false);
}
- final int currentUserId = context.getUserId();
- final UserHandle userHandle =
- Utils.getManagedProfile(context.getSystemService(UserManager.class));
- final int workProfileUserId =
- userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
-
for (BatteryHistEntry entry : batteryHistEntryList) {
final boolean isFromOtherUsers =
- isConsumedFromOtherUsers(currentUserId, workProfileUserId, entry);
+ isConsumedFromOtherUsers(userIdsSeries, entry);
// Not show other users' battery usage data.
if (isFromOtherUsers) {
continue;
@@ -905,6 +891,7 @@
static Map<Long, BatteryDiffData> getBatteryDiffDataMapFromStatsService(
final Context context,
+ final UserIdsSeries userIdsSeries,
final long startTimestamp,
@NonNull final Set<String> systemAppsPackageNames,
@NonNull final Set<Integer> systemAppsUids) {
@@ -913,6 +900,7 @@
startTimestamp,
generateBatteryDiffData(
context,
+ userIdsSeries,
startTimestamp,
getBatteryHistListFromFromStatsService(context),
systemAppsPackageNames,
@@ -1034,14 +1022,14 @@
@Nullable
private static UsageEvents getAppUsageEventsForUser(
Context context,
- final UserManager userManager,
+ final UserIdsSeries userIdsSeries,
final int userID,
final long earliestTimestamp) {
final String callingPackage = context.getPackageName();
final long now = System.currentTimeMillis();
// When the user is not unlocked, UsageStatsManager will return null, so bypass the
// following data loading logics directly.
- if (!userManager.isUserUnlocked(userID)) {
+ if (userIdsSeries.isUserLocked(userID)) {
Log.w(TAG, "fail to load app usage event for user :" + userID + " because locked");
return null;
}
@@ -1331,8 +1319,7 @@
final long endTimestamp,
final int startBatteryLevel,
final int endBatteryLevel,
- final int currentUserId,
- final int workProfileUserId,
+ final UserIdsSeries userIdsSeries,
final long slotDuration,
final Set<String> systemAppsPackageNames,
final Set<Integer> systemAppsUids,
@@ -1342,8 +1329,7 @@
if (appUsageMap != null) {
final List<AppUsagePeriod> flatAppUsagePeriodList = new ArrayList<>();
for (final long userId : appUsageMap.keySet()) {
- if ((userId != currentUserId && userId != workProfileUserId)
- || appUsageMap.get(userId) == null) {
+ if (userIdsSeries.isFromOtherUsers(userId) || appUsageMap.get(userId) == null) {
continue;
}
for (final String packageName : appUsageMap.get(userId).keySet()) {
@@ -1405,8 +1391,7 @@
// Not show other users' battery usage data.
final boolean isFromOtherUsers =
- isConsumedFromOtherUsers(
- currentUserId, workProfileUserId, selectedBatteryEntry);
+ isConsumedFromOtherUsers(userIdsSeries, selectedBatteryEntry);
if (isFromOtherUsers) {
continue;
}
@@ -1593,12 +1578,10 @@
}
private static boolean isConsumedFromOtherUsers(
- final int currentUserId,
- final int workProfileUserId,
+ final UserIdsSeries userIdsSeries,
final BatteryHistEntry batteryHistEntry) {
return isUidConsumer(batteryHistEntry.mConsumerType)
- && batteryHistEntry.mUserId != currentUserId
- && batteryHistEntry.mUserId != workProfileUserId;
+ && userIdsSeries.isFromOtherUsers(batteryHistEntry.mUserId);
}
@Nullable
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
index 29839e9..f5ed06d 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
@@ -492,6 +492,7 @@
return DataProcessManager.getBatteryLevelData(
getContext(),
mHandler,
+ new UserIdsSeries(getContext(), /* mainUserOnly= */ false),
/* isFromPeriodJob= */ false,
PowerUsageAdvanced.this::onBatteryDiffDataMapUpdate);
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/UserIdsSeries.java b/src/com/android/settings/fuelgauge/batteryusage/UserIdsSeries.java
new file mode 100644
index 0000000..3dc311e
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batteryusage/UserIdsSeries.java
@@ -0,0 +1,91 @@
+/*
+ * 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.fuelgauge.batteryusage;
+
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserManager;
+
+import androidx.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class UserIdsSeries {
+ private final UserManager mUserManager;
+ private final int mCurrentUserId;
+ private final List<Integer> mVisibleUserIds = new ArrayList<>();
+
+ @Nullable private UserInfo mPrivateUser = null;
+ @Nullable private UserInfo mManagedProfileUser = null;
+
+ UserIdsSeries(final Context context, final boolean mainUserOnly) {
+ mUserManager = context.getSystemService(UserManager.class);
+ mCurrentUserId = context.getUserId();
+ List<UserInfo> aliveUsers =
+ mUserManager != null ? mUserManager.getAliveUsers() : new ArrayList<>();
+
+ if (mainUserOnly) {
+ aliveUsers.stream()
+ .filter(UserInfo::isMain)
+ .forEach(userInfo -> mVisibleUserIds.add(userInfo.id));
+ return;
+ }
+
+ for (UserInfo userInfo : aliveUsers) {
+ if (!mUserManager.isSameProfileGroup(mCurrentUserId, userInfo.id)) {
+ continue;
+ }
+ if (!userInfo.isQuietModeEnabled() || userInfo.isManagedProfile()) {
+ mVisibleUserIds.add(userInfo.id);
+ }
+ if (userInfo.isPrivateProfile()) {
+ mPrivateUser = userInfo;
+ }
+ if (userInfo.isManagedProfile()) {
+ mManagedProfileUser = userInfo;
+ }
+ }
+ }
+
+ int getCurrentUserId() {
+ return mCurrentUserId;
+ }
+
+ List<Integer> getVisibleUserIds() {
+ return mVisibleUserIds;
+ }
+
+ boolean isCurrentUserLocked() {
+ return isUserLocked(mCurrentUserId);
+ }
+
+ boolean isUserLocked(int userId) {
+ return mUserManager == null || !mUserManager.isUserUnlocked(userId);
+ }
+
+ boolean isFromOtherUsers(long userId) {
+ return !mVisibleUserIds.contains((int) userId);
+ }
+
+ boolean isMainUserProfileOnly() {
+ return mUserManager != null
+ && mUserManager.isMainUser()
+ && mPrivateUser == null
+ && mManagedProfileUser == null;
+ }
+}
diff --git a/src/com/android/settings/localepicker/TermsOfAddressBaseController.java b/src/com/android/settings/localepicker/TermsOfAddressBaseController.java
index 34c502f..d9962de 100644
--- a/src/com/android/settings/localepicker/TermsOfAddressBaseController.java
+++ b/src/com/android/settings/localepicker/TermsOfAddressBaseController.java
@@ -26,8 +26,12 @@
import com.android.settings.widget.TickButtonPreference;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
public abstract class TermsOfAddressBaseController extends BasePreferenceController {
+ private static final Executor sExecutor = Executors.newSingleThreadExecutor();
private PreferenceScreen mPreferenceScreen;
private MetricsFeatureProvider mMetricsFeatureProvider;
private TickButtonPreference mPreference;
@@ -46,8 +50,11 @@
mPreferenceScreen = screen;
mPreference = screen.findPreference(getPreferenceKey());
mPreference.setOnPreferenceClickListener(clickedPref -> {
- mGrammaticalInflectionManager.setSystemWideGrammaticalGender(
- getGrammaticalGenderType());
+ sExecutor.execute(
+ () -> {
+ mGrammaticalInflectionManager.setSystemWideGrammaticalGender(
+ getGrammaticalGenderType());
+ });
setSelected(mPreference);
mMetricsFeatureProvider.action(mContext, getMetricsActionKey());
return true;
diff --git a/src/com/android/settings/overlay/FeatureFactory.kt b/src/com/android/settings/overlay/FeatureFactory.kt
index 2c4a295..53ad8ba 100644
--- a/src/com/android/settings/overlay/FeatureFactory.kt
+++ b/src/com/android/settings/overlay/FeatureFactory.kt
@@ -68,7 +68,7 @@
/**
* Retrieves implementation for Hardware Info feature.
*/
- abstract val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider
+ open val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider? = null
/** Implementation for [SupportFeatureProvider]. */
open val supportFeatureProvider: SupportFeatureProvider? = null
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.kt b/src/com/android/settings/overlay/FeatureFactoryImpl.kt
index e1519b3..1770209 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.kt
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.kt
@@ -45,8 +45,6 @@
import com.android.settings.dashboard.DashboardFeatureProviderImpl
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProvider
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProviderImpl
import com.android.settings.display.DisplayFeatureProvider
import com.android.settings.display.DisplayFeatureProviderImpl
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl
@@ -81,9 +79,6 @@
ContextualCardFeatureProviderImpl(appContext)
}
- override val hardwareInfoFeatureProvider: HardwareInfoFeatureProvider =
- HardwareInfoFeatureProviderImpl
-
override val metricsFeatureProvider by lazy { SettingsMetricsFeatureProvider() }
override val powerUsageFeatureProvider by lazy { PowerUsageFeatureProviderImpl(appContext) }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoaderTest.java
index 723a138..41379b3 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoaderTest.java
@@ -52,6 +52,7 @@
public final class BatteryUsageDataLoaderTest {
private Context mContext;
+ @Mock private UserIdsSeries mUserIdsSeries;
@Mock private ContentResolver mMockContentResolver;
@Mock private BatteryStatsManager mBatteryStatsManager;
@Mock private PackageManager mPackageManager;
@@ -120,7 +121,7 @@
BatteryUsageDataLoader.sFakeAppUsageEventsSupplier = () -> new HashMap<>();
BatteryUsageDataLoader.sFakeUsageEventsListSupplier = () -> AppUsageEventList;
- BatteryUsageDataLoader.loadAppUsageData(mContext);
+ BatteryUsageDataLoader.loadAppUsageData(mContext, mUserIdsSeries);
verify(mMockContentResolver).bulkInsert(any(), any());
verify(mMockContentResolver).notifyChange(any(), any());
@@ -130,7 +131,7 @@
public void loadAppUsageData_nullAppUsageEvents_notInsertDataIntoProvider() {
BatteryUsageDataLoader.sFakeAppUsageEventsSupplier = () -> null;
- BatteryUsageDataLoader.loadAppUsageData(mContext);
+ BatteryUsageDataLoader.loadAppUsageData(mContext, mUserIdsSeries);
verifyNoMoreInteractions(mMockContentResolver);
}
@@ -140,7 +141,7 @@
BatteryUsageDataLoader.sFakeAppUsageEventsSupplier = () -> new HashMap<>();
BatteryUsageDataLoader.sFakeUsageEventsListSupplier = () -> null;
- BatteryUsageDataLoader.loadAppUsageData(mContext);
+ BatteryUsageDataLoader.loadAppUsageData(mContext, mUserIdsSeries);
verifyNoMoreInteractions(mMockContentResolver);
}
@@ -150,7 +151,7 @@
BatteryUsageDataLoader.sFakeAppUsageEventsSupplier = () -> new HashMap<>();
BatteryUsageDataLoader.sFakeUsageEventsListSupplier = () -> new ArrayList<>();
- BatteryUsageDataLoader.loadAppUsageData(mContext);
+ BatteryUsageDataLoader.loadAppUsageData(mContext, mUserIdsSeries);
verifyNoMoreInteractions(mMockContentResolver);
}
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 6227790..b025db8 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessManagerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessManagerTest.java
@@ -70,6 +70,7 @@
private Context mContext;
private DataProcessManager mDataProcessManager;
+ @Mock private UserIdsSeries mUserIdsSeries;
@Mock private IUsageStatsManager mUsageStatsManager;
@Mock private UserManager mUserManager;
@Mock private BatteryStatsManager mBatteryStatsManager;
@@ -95,11 +96,13 @@
doReturn(mIntent).when(mContext).registerReceiver(any(), any());
doReturn(100).when(mIntent).getIntExtra(eq(BatteryManager.EXTRA_SCALE), anyInt());
doReturn(66).when(mIntent).getIntExtra(eq(BatteryManager.EXTRA_LEVEL), anyInt());
+ doReturn(true).when(mUserIdsSeries).isMainUserProfileOnly();
mDataProcessManager =
new DataProcessManager(
mContext,
/* handler= */ null,
+ mUserIdsSeries,
/* rawStartTimestamp= */ 0L,
/* lastFullChargeTimestamp= */ 0L,
/* callbackFunction= */ null,
@@ -117,7 +120,11 @@
@LooperMode(LooperMode.Mode.LEGACY)
public void constructor_noLevelData() {
final DataProcessManager dataProcessManager =
- new DataProcessManager(mContext, /* handler= */ null, /* callbackFunction= */ null);
+ new DataProcessManager(
+ mContext,
+ /* handler= */ null,
+ mUserIdsSeries,
+ /* callbackFunction= */ null);
assertThat(dataProcessManager.getShowScreenOnTime()).isFalse();
}
@@ -180,6 +187,7 @@
doReturn(1).when(mContext).getUserId();
// No work profile.
doReturn(new ArrayList<>()).when(mUserManager).getUserProfiles();
+ doReturn(new ArrayList<>(List.of(1))).when(mUserIdsSeries).getVisibleUserIds();
// Fake database usage data.
final MatrixCursor cursor =
@@ -239,6 +247,7 @@
new DataProcessManager(
mContext,
/* handler= */ null,
+ mUserIdsSeries,
/* rawStartTimestamp= */ 2L,
/* lastFullChargeTimestamp= */ 1L,
/* callbackFunction= */ null,
@@ -301,7 +310,7 @@
doReturn(getUsageEvents(events))
.when(mUsageStatsManager)
.queryEventsForUser(anyLong(), anyLong(), anyInt(), any());
- doReturn(false).when(mUserManager).isUserUnlocked(anyInt());
+ doReturn(true).when(mUserIdsSeries).isCurrentUserLocked();
final MatrixCursor cursor =
new MatrixCursor(
new String[] {
@@ -327,6 +336,7 @@
DataProcessManager.getBatteryLevelData(
mContext,
/* handler= */ null,
+ mUserIdsSeries,
/* isFromPeriodJob= */ false,
/* asyncResponseDelegate= */ null))
.isNull();
@@ -334,6 +344,7 @@
DataProcessManager.getBatteryLevelData(
mContext,
/* handler= */ null,
+ mUserIdsSeries,
/* isFromPeriodJob= */ true,
/* asyncResponseDelegate= */ null))
.isNull();
@@ -355,6 +366,7 @@
DataProcessManager.getBatteryLevelData(
mContext,
/* handler= */ null,
+ mUserIdsSeries,
/* isFromPeriodJob= */ false,
/* asyncResponseDelegate= */ null);
@@ -383,6 +395,7 @@
DataProcessManager.getBatteryLevelData(
mContext,
/* handler= */ null,
+ mUserIdsSeries,
/* isFromPeriodJob= */ false,
/* asyncResponseDelegate= */ null);
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 7a67240..2897343 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/DataProcessorTest.java
@@ -80,6 +80,7 @@
@Mock private Intent mIntent;
@Mock private BatteryUsageStats mBatteryUsageStats;
@Mock private UserManager mUserManager;
+ @Mock private UserIdsSeries mUserIdsSeries;
@Mock private IUsageStatsManager mUsageStatsManager;
@Mock private BatteryEntry mMockBatteryEntry1;
@Mock private BatteryEntry mMockBatteryEntry2;
@@ -95,6 +96,7 @@
mContext = spy(RuntimeEnvironment.application);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mPowerUsageFeatureProvider = mFeatureFactory.powerUsageFeatureProvider;
+ doReturn(true).when(mUserIdsSeries).isMainUserProfileOnly();
DataProcessor.sTestSystemAppsPackageNames = Set.of();
DataProcessor.sUsageStatsManager = mUsageStatsManager;
@@ -118,8 +120,10 @@
doReturn(mUsageEvents1)
.when(mUsageStatsManager)
.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString());
+ doReturn(new ArrayList<>(List.of(0))).when(mUserIdsSeries).getVisibleUserIds();
- final Map<Long, UsageEvents> resultMap = DataProcessor.getAppUsageEvents(mContext);
+ final Map<Long, UsageEvents> resultMap =
+ DataProcessor.getAppUsageEvents(mContext, mUserIdsSeries);
assertThat(resultMap).hasSize(1);
assertThat(resultMap.get(Long.valueOf(userInfo.id))).isEqualTo(mUsageEvents1);
@@ -134,7 +138,8 @@
// Test locked user.
doReturn(false).when(mUserManager).isUserUnlocked(userInfo.id);
- final Map<Long, UsageEvents> resultMap = DataProcessor.getAppUsageEvents(mContext);
+ final Map<Long, UsageEvents> resultMap =
+ DataProcessor.getAppUsageEvents(mContext, mUserIdsSeries);
assertThat(resultMap).isNull();
}
@@ -150,7 +155,8 @@
.when(mUsageStatsManager)
.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString());
- final Map<Long, UsageEvents> resultMap = DataProcessor.getAppUsageEvents(mContext);
+ final Map<Long, UsageEvents> resultMap =
+ DataProcessor.getAppUsageEvents(mContext, mUserIdsSeries);
assertThat(resultMap).isNull();
}
@@ -163,7 +169,8 @@
.when(mUsageStatsManager)
.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString());
- assertThat(DataProcessor.getAppUsageEventsForUser(mContext, userId, 0))
+ assertThat(DataProcessor.getCurrentAppUsageEventsForUser(
+ mContext, mUserIdsSeries, userId, 0))
.isEqualTo(mUsageEvents1);
}
@@ -173,7 +180,9 @@
// Test locked user.
doReturn(false).when(mUserManager).isUserUnlocked(userId);
- assertThat(DataProcessor.getAppUsageEventsForUser(mContext, userId, 0)).isNull();
+ assertThat(DataProcessor.getCurrentAppUsageEventsForUser(
+ mContext, mUserIdsSeries, userId, 0))
+ .isNull();
}
@Test
@@ -184,7 +193,9 @@
.when(mUsageStatsManager)
.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString());
- assertThat(DataProcessor.getAppUsageEventsForUser(mContext, userId, 0)).isNull();
+ assertThat(DataProcessor.getCurrentAppUsageEventsForUser(
+ mContext, mUserIdsSeries, userId, 0))
+ .isNull();
}
@Test
@@ -852,6 +863,7 @@
assertThat(
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
hourlyBatteryLevelsPerDay,
new HashMap<>(),
/* appUsagePeriodMap= */ null,
@@ -938,6 +950,7 @@
Map<Long, BatteryDiffData> batteryDiffDataMap =
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
batteryHistoryMap,
appUsagePeriodMap,
@@ -1154,6 +1167,7 @@
mContext,
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
batteryHistoryMap,
appUsagePeriodMap,
@@ -1271,6 +1285,10 @@
};
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
final int currentUserId = mContext.getUserId();
+ doReturn(false).when(mUserIdsSeries).isFromOtherUsers(currentUserId);
+ doReturn(true).when(mUserIdsSeries).isFromOtherUsers(currentUserId + 1);
+ doReturn(true).when(mUserIdsSeries).isFromOtherUsers(currentUserId + 2);
+
// Adds the index = 0 data.
Map<String, BatteryHistEntry> entryMap = new HashMap<>();
BatteryHistEntry entry =
@@ -1431,6 +1449,7 @@
mContext,
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
batteryHistoryMap,
/* appUsagePeriodMap= */ null,
@@ -1546,6 +1565,7 @@
mContext,
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
batteryHistoryMap,
appUsagePeriodMap,
@@ -1701,6 +1721,7 @@
mContext,
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
batteryHistoryMap,
/* appUsagePeriodMap= */ null,
@@ -1851,6 +1872,7 @@
mContext,
DataProcessor.getBatteryDiffDataMap(
mContext,
+ mUserIdsSeries,
batteryLevelData.getHourlyBatteryLevelsPerDay(),
batteryHistoryMap,
/* appUsagePeriodMap= */ null,
@@ -1873,6 +1895,7 @@
final BatteryDiffData batteryDiffData =
DataProcessor.generateBatteryDiffData(
mContext,
+ mUserIdsSeries,
System.currentTimeMillis(),
DataProcessor.convertToBatteryHistEntry(null, mBatteryUsageStats),
/* systemAppsPackageNames= */ Set.of(),
@@ -1933,6 +1956,7 @@
final BatteryDiffData batteryDiffData =
DataProcessor.generateBatteryDiffData(
mContext,
+ mUserIdsSeries,
System.currentTimeMillis(),
DataProcessor.convertToBatteryHistEntry(
batteryEntryList, mBatteryUsageStats),
diff --git a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
index f49cc68..38683d0 100644
--- a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java
@@ -32,8 +32,6 @@
import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProviderImpl;
import com.android.settings.display.DisplayFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
@@ -299,11 +297,6 @@
}
@Override
- public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() {
- return HardwareInfoFeatureProviderImpl.INSTANCE;
- }
-
- @Override
public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
return mAdvancedVpnFeatureProvider;
}
diff --git a/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt b/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt
index f1e18fc..7486e78 100644
--- a/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt
+++ b/tests/spa_unit/src/com/android/settings/deviceinfo/regulatory/RegulatoryInfoTest.kt
@@ -35,14 +35,12 @@
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.MockitoSession
-import org.mockito.Spy
import org.mockito.quality.Strictness
@RunWith(AndroidJUnit4::class)
class RegulatoryInfoTest {
private lateinit var mockSession: MockitoSession
- @Spy
private val context: Context = ApplicationProvider.getApplicationContext()
@Before
@@ -98,8 +96,31 @@
assertDrawableSameAs(regulatoryInfo, R.drawable.regulatory_info_sku)
}
+ @Test
+ fun getCoo() {
+ doReturn(COO).`when` { SystemProperties.get(KEY_COO) }
+
+ val coo = RegulatoryInfo.getCoo()
+
+ assertThat(coo).isEqualTo(COO)
+ }
+
+ @Test
+ fun getSku() {
+ doReturn(SKU).`when` { SystemProperties.get(KEY_SKU) }
+
+ val coo = RegulatoryInfo.getSku()
+
+ assertThat(coo).isEqualTo(SKU)
+ }
+
private fun assertDrawableSameAs(drawable: Drawable?, @DrawableRes resId: Int) {
val expected = context.getDrawable(resId)!!.toBitmap()
assertThat(drawable!!.toBitmap().sameAs(expected)).isTrue()
}
+
+ private companion object {
+ const val SKU = "ABC"
+ const val COO = "CN"
+ }
}
diff --git a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
index 4f17a3a..29758de 100644
--- a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -32,8 +32,6 @@
import com.android.settings.connecteddevice.stylus.StylusFeatureProvider;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProvider;
-import com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFeatureProviderImpl;
import com.android.settings.display.DisplayFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
@@ -300,11 +298,6 @@
}
@Override
- public HardwareInfoFeatureProvider getHardwareInfoFeatureProvider() {
- return HardwareInfoFeatureProviderImpl.INSTANCE;
- }
-
- @Override
public AdvancedVpnFeatureProvider getAdvancedVpnFeatureProvider() {
return mAdvancedVpnFeatureProvider;
}