diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 92f99d8de80..ec52bbf1657 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2855,7 +2855,7 @@
+ android:value="com.android.settings.fuelgauge.batteryusage.PowerUsageSummary" />
diff --git a/res/layout/battery_chart_graph.xml b/res/layout/battery_chart_graph.xml
index e89c9120c74..df481443e83 100644
--- a/res/layout/battery_chart_graph.xml
+++ b/res/layout/battery_chart_graph.xml
@@ -31,7 +31,7 @@
android:textColor="?android:attr/textColorSecondary"
android:text="@string/battery_usage_chart_graph_hint" />
-
-
diff --git a/res/xml/top_level_settings.xml b/res/xml/top_level_settings.xml
index c9e60170eb9..5fbc7350b89 100644
--- a/res/xml/top_level_settings.xml
+++ b/res/xml/top_level_settings.xml
@@ -59,7 +59,7 @@
settings:highlightableMenuKey="@string/menu_key_notifications"/>
usageList =
- getCoalescedUsageList(showAllApps, /*loadDataInBackground=*/ true);
+ getCoalescedUsageList(showAllApps, /*loadDataInBackground=*/ true);
final double totalPower = batteryUsageStats.getConsumedPower();
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
@@ -292,7 +294,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
}
final int dischargePercentage = getDischargePercentage(batteryUsageStats);
final List usageList =
- getCoalescedUsageList(showAllApps, /*loadDataInBackground=*/ false);
+ getCoalescedUsageList(showAllApps, /*loadDataInBackground=*/ false);
final double totalPower = batteryUsageStats.getConsumedPower();
for (int i = 0; i < usageList.size(); i++) {
final BatteryEntry entry = usageList.get(i);
@@ -458,8 +460,8 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
private void cacheRemoveAllPrefs(PreferenceGroup group) {
mPreferenceCache = new ArrayMap<>();
- final int N = group.getPreferenceCount();
- for (int i = 0; i < N; i++) {
+ final int n = group.getPreferenceCount();
+ for (int i = 0; i < n; i++) {
Preference p = group.getPreference(i);
if (TextUtils.isEmpty(p.getKey())) {
continue;
@@ -563,7 +565,6 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
}
private void addNotAvailableMessage() {
- final String NOT_AVAILABLE = "not_available";
Preference notAvailable = getCachedPreference(NOT_AVAILABLE);
if (notAvailable == null) {
notAvailable = new Preference(mPrefContext);
diff --git a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
similarity index 81%
rename from src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
index 02248c9af51..d363308740a 100644
--- a/src/com/android/settings/fuelgauge/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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
@@ -11,10 +12,9 @@
* 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;
+package com.android.settings.fuelgauge.batteryusage;
import android.app.settings.SettingsEnums;
import android.content.Context;
@@ -38,6 +38,8 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -60,8 +62,8 @@ import java.util.Map;
/** Controls the update for chart graph and the list items. */
public class BatteryChartPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnCreate, OnDestroy,
- OnSaveInstanceState, BatteryChartView.OnSelectListener, OnResume,
- ExpandDividerPreference.OnExpandListener {
+ OnSaveInstanceState, BatteryChartView.OnSelectListener, OnResume,
+ ExpandDividerPreference.OnExpandListener {
private static final String TAG = "BatteryChartPreferenceController";
private static final String KEY_FOOTER_PREF = "battery_graph_footer";
private static final String PACKAGE_NAME_NONE = "none";
@@ -82,16 +84,25 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
@VisibleForTesting
Map> mBatteryIndexedMap;
- @VisibleForTesting Context mPrefContext;
- @VisibleForTesting BatteryUtils mBatteryUtils;
- @VisibleForTesting PreferenceGroup mAppListPrefGroup;
- @VisibleForTesting BatteryChartView mBatteryChartView;
- @VisibleForTesting ExpandDividerPreference mExpandDividerPreference;
+ @VisibleForTesting
+ Context mPrefContext;
+ @VisibleForTesting
+ BatteryUtils mBatteryUtils;
+ @VisibleForTesting
+ PreferenceGroup mAppListPrefGroup;
+ @VisibleForTesting
+ BatteryChartView mBatteryChartView;
+ @VisibleForTesting
+ ExpandDividerPreference mExpandDividerPreference;
- @VisibleForTesting boolean mIsExpanded = false;
- @VisibleForTesting int[] mBatteryHistoryLevels;
- @VisibleForTesting long[] mBatteryHistoryKeys;
- @VisibleForTesting int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID;
+ @VisibleForTesting
+ boolean mIsExpanded = false;
+ @VisibleForTesting
+ int[] mBatteryHistoryLevels;
+ @VisibleForTesting
+ long[] mBatteryHistoryKeys;
+ @VisibleForTesting
+ int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID;
private boolean mIs24HourFormat = false;
private boolean mIsFooterPrefAdded = false;
@@ -122,15 +133,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mPreferenceKey = preferenceKey;
mIs24HourFormat = DateFormat.is24HourFormat(context);
mMetricsFeatureProvider =
- FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
+ FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
mNotAllowShowEntryPackages =
- FeatureFactory.getFactory(context)
- .getPowerUsageFeatureProvider(context)
- .getHideApplicationEntries(context);
+ FeatureFactory.getFactory(context)
+ .getPowerUsageFeatureProvider(context)
+ .getHideApplicationEntries(context);
mNotAllowShowSummaryPackages =
- FeatureFactory.getFactory(context)
- .getPowerUsageFeatureProvider(context)
- .getHideApplicationSummary(context);
+ FeatureFactory.getFactory(context)
+ .getPowerUsageFeatureProvider(context)
+ .getHideApplicationSummary(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -142,18 +153,18 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return;
}
mTrapezoidIndex =
- savedInstanceState.getInt(KEY_CURRENT_TIME_SLOT, mTrapezoidIndex);
+ savedInstanceState.getInt(KEY_CURRENT_TIME_SLOT, mTrapezoidIndex);
mIsExpanded =
- savedInstanceState.getBoolean(KEY_EXPAND_SYSTEM_INFO, mIsExpanded);
+ savedInstanceState.getBoolean(KEY_EXPAND_SYSTEM_INFO, mIsExpanded);
Log.d(TAG, String.format("onCreate() slotIndex=%d isExpanded=%b",
- mTrapezoidIndex, mIsExpanded));
+ mTrapezoidIndex, mIsExpanded));
}
@Override
public void onResume() {
final int currentUiMode =
- mContext.getResources().getConfiguration().uiMode
- & Configuration.UI_MODE_NIGHT_MASK;
+ mContext.getResources().getConfiguration().uiMode
+ & Configuration.UI_MODE_NIGHT_MASK;
if (sUiMode != currentUiMode) {
sUiMode = currentUiMode;
BatteryDiffEntry.clearCache();
@@ -171,7 +182,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
savedInstance.putInt(KEY_CURRENT_TIME_SLOT, mTrapezoidIndex);
savedInstance.putBoolean(KEY_EXPAND_SYSTEM_INFO, mIsExpanded);
Log.d(TAG, String.format("onSaveInstanceState() slotIndex=%d isExpanded=%b",
- mTrapezoidIndex, mIsExpanded));
+ mTrapezoidIndex, mIsExpanded));
}
@Override
@@ -194,7 +205,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mAppListPrefGroup = screen.findPreference(mPreferenceKey);
mAppListPrefGroup.setOrderingAsAdded(false);
mAppListPrefGroup.setTitle(
- mPrefContext.getString(R.string.battery_app_usage_for_past_24));
+ mPrefContext.getString(R.string.battery_app_usage_for_past_24));
mFooterPreference = screen.findPreference(KEY_FOOTER_PREF);
// Removes footer first until usage data is loaded to avoid flashing.
if (mFooterPreference != null) {
@@ -243,19 +254,19 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
Log.d(TAG, "onChartSelect:" + trapezoidIndex);
refreshUi(trapezoidIndex, /*isForce=*/ false);
mMetricsFeatureProvider.action(
- mPrefContext,
- trapezoidIndex == BatteryChartView.SELECTED_INDEX_ALL
- ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
- : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
+ mPrefContext,
+ trapezoidIndex == BatteryChartView.SELECTED_INDEX_ALL
+ ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
+ : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
}
@Override
public void onExpand(boolean isExpanded) {
mIsExpanded = isExpanded;
mMetricsFeatureProvider.action(
- mPrefContext,
- SettingsEnums.ACTION_BATTERY_USAGE_EXPAND_ITEM,
- isExpanded);
+ mPrefContext,
+ SettingsEnums.ACTION_BATTERY_USAGE_EXPAND_ITEM,
+ isExpanded);
refreshExpandUi();
}
@@ -276,7 +287,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
final Map entryMap = batteryHistoryMap.get(timestamp);
if (entryMap == null || entryMap.isEmpty()) {
Log.e(TAG, "abnormal entry list in the timestamp:"
- + ConvertUtils.utcToLocalTime(mPrefContext, timestamp));
+ + ConvertUtils.utcToLocalTime(mPrefContext, timestamp));
continue;
}
// Averages the battery level in each time slot to avoid corner conditions.
@@ -285,15 +296,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
batteryLevelCounter += entry.mBatteryLevel;
}
mBatteryHistoryLevels[index] =
- Math.round(batteryLevelCounter / entryMap.size());
+ Math.round(batteryLevelCounter / entryMap.size());
}
forceRefreshUi();
Log.d(TAG, String.format(
- "setBatteryHistoryMap() size=%d key=%s\nlevels=%s",
- batteryHistoryMap.size(),
- ConvertUtils.utcToLocalTime(mPrefContext,
- mBatteryHistoryKeys[mBatteryHistoryKeys.length - 1]),
- Arrays.toString(mBatteryHistoryLevels)));
+ "setBatteryHistoryMap() size=%d key=%s\nlevels=%s",
+ batteryHistoryMap.size(),
+ ConvertUtils.utcToLocalTime(mPrefContext,
+ mBatteryHistoryKeys[mBatteryHistoryKeys.length - 1]),
+ Arrays.toString(mBatteryHistoryLevels)));
// Loads item icon and label in the background.
new LoadAllItemsInfoTask(batteryHistoryMap).execute();
@@ -313,9 +324,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private void forceRefreshUi() {
final int refreshIndex =
- mTrapezoidIndex == BatteryChartView.SELECTED_INDEX_INVALID
- ? BatteryChartView.SELECTED_INDEX_ALL
- : mTrapezoidIndex;
+ mTrapezoidIndex == BatteryChartView.SELECTED_INDEX_INVALID
+ ? BatteryChartView.SELECTED_INDEX_ALL
+ : mTrapezoidIndex;
if (mBatteryChartView != null) {
mBatteryChartView.setLevels(mBatteryHistoryLevels);
mBatteryChartView.setSelectedIndex(refreshIndex);
@@ -333,7 +344,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return false;
}
Log.d(TAG, String.format("refreshUi: index=%d size=%d isForce:%b",
- trapezoidIndex, mBatteryIndexedMap.size(), isForce));
+ trapezoidIndex, mBatteryIndexedMap.size(), isForce));
mTrapezoidIndex = trapezoidIndex;
mHandler.post(() -> {
@@ -349,7 +360,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private void addAllPreferences() {
final List entries =
- mBatteryIndexedMap.get(Integer.valueOf(mTrapezoidIndex));
+ mBatteryIndexedMap.get(Integer.valueOf(mTrapezoidIndex));
addFooterPreferenceIfNeeded(entries != null && !entries.isEmpty());
if (entries == null) {
Log.w(TAG, "cannot find BatteryDiffEntry for:" + mTrapezoidIndex);
@@ -377,7 +388,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
Collections.sort(appEntries, BatteryDiffEntry.COMPARATOR);
Collections.sort(mSystemEntries, BatteryDiffEntry.COMPARATOR);
Log.d(TAG, String.format("addAllPreferences() app=%d system=%d",
- appEntries.size(), mSystemEntries.size()));
+ appEntries.size(), mSystemEntries.size()));
// Adds app entries to the list if it is not empty.
if (!appEntries.isEmpty()) {
@@ -391,7 +402,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mExpandDividerPreference.setIsExpanded(mIsExpanded);
}
mExpandDividerPreference.setOrder(
- mAppListPrefGroup.getPreferenceCount());
+ mAppListPrefGroup.getPreferenceCount());
mAppListPrefGroup.addPreference(mExpandDividerPreference);
}
refreshExpandUi();
@@ -479,11 +490,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
Log.d(TAG, String.format("refreshCategoryTitle:%s", slotInformation));
if (mAppListPrefGroup != null) {
mAppListPrefGroup.setTitle(
- getSlotInformation(/*isApp=*/ true, slotInformation));
+ getSlotInformation(/*isApp=*/ true, slotInformation));
}
if (mExpandDividerPreference != null) {
mExpandDividerPreference.setTitle(
- getSlotInformation(/*isApp=*/ false, slotInformation));
+ getSlotInformation(/*isApp=*/ false, slotInformation));
}
}
@@ -491,12 +502,12 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
// Null means we show all information without a specific time slot.
if (slotInformation == null) {
return isApp
- ? mPrefContext.getString(R.string.battery_app_usage_for_past_24)
- : mPrefContext.getString(R.string.battery_system_usage_for_past_24);
+ ? mPrefContext.getString(R.string.battery_app_usage_for_past_24)
+ : mPrefContext.getString(R.string.battery_system_usage_for_past_24);
} else {
return isApp
- ? mPrefContext.getString(R.string.battery_app_usage_for, slotInformation)
- : mPrefContext.getString(R.string.battery_system_usage_for ,slotInformation);
+ ? mPrefContext.getString(R.string.battery_app_usage_for, slotInformation)
+ : mPrefContext.getString(R.string.battery_system_usage_for, slotInformation);
}
}
@@ -505,12 +516,12 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return null;
}
final String fromHour = ConvertUtils.utcToLocalTimeHour(mPrefContext,
- mBatteryHistoryKeys[mTrapezoidIndex * 2], mIs24HourFormat);
+ mBatteryHistoryKeys[mTrapezoidIndex * 2], mIs24HourFormat);
final String toHour = ConvertUtils.utcToLocalTimeHour(mPrefContext,
- mBatteryHistoryKeys[(mTrapezoidIndex + 1) * 2], mIs24HourFormat);
+ mBatteryHistoryKeys[(mTrapezoidIndex + 1) * 2], mIs24HourFormat);
return mIs24HourFormat
- ? String.format("%sā%s", fromHour, toHour)
- : String.format("%s ā %s", fromHour, toHour);
+ ? String.format("%sā%s", fromHour, toHour)
+ : String.format("%s ā %s", fromHour, toHour);
}
@VisibleForTesting
@@ -528,10 +539,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
// Not shows summary for some system components without usage time.
if (totalUsageTimeInMs == 0) {
preference.setSummary(null);
- // Shows background summary only if we don't have foreground usage time.
+ // Shows background summary only if we don't have foreground usage time.
} else if (foregroundUsageTimeInMs == 0 && backgroundUsageTimeInMs != 0) {
usageTimeSummary = buildUsageTimeInfo(backgroundUsageTimeInMs, true);
- // Shows total usage summary only if total usage time is small.
+ // Shows total usage summary only if total usage time is small.
} else if (totalUsageTimeInMs < DateUtils.MINUTE_IN_MILLIS) {
usageTimeSummary = buildUsageTimeInfo(totalUsageTimeInMs, false);
} else {
@@ -539,7 +550,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
// Shows background usage time if it is larger than a minute.
if (backgroundUsageTimeInMs > 0) {
usageTimeSummary +=
- "\n" + buildUsageTimeInfo(backgroundUsageTimeInMs, true);
+ "\n" + buildUsageTimeInfo(backgroundUsageTimeInMs, true);
}
}
preference.setSummary(usageTimeSummary);
@@ -548,17 +559,17 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private String buildUsageTimeInfo(long usageTimeInMs, boolean isBackground) {
if (usageTimeInMs < DateUtils.MINUTE_IN_MILLIS) {
return mPrefContext.getString(
- isBackground
- ? R.string.battery_usage_background_less_than_one_minute
- : R.string.battery_usage_total_less_than_one_minute);
+ isBackground
+ ? R.string.battery_usage_background_less_than_one_minute
+ : R.string.battery_usage_total_less_than_one_minute);
}
final CharSequence timeSequence =
- StringUtil.formatElapsedTime(mPrefContext, usageTimeInMs,
- /*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
+ StringUtil.formatElapsedTime(mPrefContext, usageTimeInMs,
+ /*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
final int resourceId =
- isBackground
- ? R.string.battery_usage_for_background_time
- : R.string.battery_usage_for_total_time;
+ isBackground
+ ? R.string.battery_usage_for_background_time
+ : R.string.battery_usage_for_total_time;
return mPrefContext.getString(resourceId, timeSequence);
}
@@ -578,7 +589,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return;
}
final long latestTimestamp =
- mBatteryHistoryKeys[mBatteryHistoryKeys.length - 1];
+ mBatteryHistoryKeys[mBatteryHistoryKeys.length - 1];
mBatteryChartView.setLatestTimestamp(latestTimestamp);
}
@@ -588,9 +599,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
mIsFooterPrefAdded = true;
mFooterPreference.setTitle(mPrefContext.getString(
- containAppItems
- ? R.string.battery_usage_screen_footer
- : R.string.battery_usage_screen_footer_empty));
+ containAppItems
+ ? R.string.battery_usage_screen_footer
+ : R.string.battery_usage_screen_footer_empty));
mHandler.post(() -> mPreferenceScreen.addPreference(mFooterPreference));
}
@@ -623,21 +634,21 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
public static List getBatteryLast24HrUsageData(Context context) {
final long start = System.currentTimeMillis();
final Map> batteryHistoryMap =
- FeatureFactory.getFactory(context)
- .getPowerUsageFeatureProvider(context)
- .getBatteryHistory(context);
+ FeatureFactory.getFactory(context)
+ .getPowerUsageFeatureProvider(context)
+ .getBatteryHistory(context);
if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) {
return null;
}
Log.d(TAG, String.format("getBatteryLast24HrData() size=%d time=&d/ms",
- batteryHistoryMap.size(), (System.currentTimeMillis() - start)));
+ batteryHistoryMap.size(), (System.currentTimeMillis() - start)));
final Map> batteryIndexedMap =
- ConvertUtils.getIndexedUsageMap(
- context,
- /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1,
- getBatteryHistoryKeys(batteryHistoryMap),
- batteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ true);
+ ConvertUtils.getIndexedUsageMap(
+ context,
+ /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1,
+ getBatteryHistoryKeys(batteryHistoryMap),
+ batteryHistoryMap,
+ /*purgeLowPercentageAndFakeData=*/ true);
return batteryIndexedMap.get(BatteryChartView.SELECTED_INDEX_ALL);
}
@@ -666,7 +677,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private static long[] getBatteryHistoryKeys(
final Map> batteryHistoryMap) {
final List batteryHistoryKeyList =
- new ArrayList<>(batteryHistoryMap.keySet());
+ new ArrayList<>(batteryHistoryMap.keySet());
Collections.sort(batteryHistoryKeyList);
final long[] batteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
@@ -695,16 +706,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
final long startTime = System.currentTimeMillis();
final Map> indexedUsageMap =
- ConvertUtils.getIndexedUsageMap(
- mPrefContext, /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1,
- mBatteryHistoryKeysCache, mBatteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ true);
+ ConvertUtils.getIndexedUsageMap(
+ mPrefContext, /*timeSlotSize=*/ CHART_LEVEL_ARRAY_SIZE - 1,
+ mBatteryHistoryKeysCache, mBatteryHistoryMap,
+ /*purgeLowPercentageAndFakeData=*/ true);
// Pre-loads each BatteryDiffEntry relative icon and label for all slots.
for (List entries : indexedUsageMap.values()) {
entries.forEach(entry -> entry.loadLabelAndIcon());
}
Log.d(TAG, String.format("execute LoadAllItemsInfoTask in %d/ms",
- (System.currentTimeMillis() - startTime)));
+ (System.currentTimeMillis() - startTime)));
return indexedUsageMap;
}
diff --git a/src/com/android/settings/fuelgauge/BatteryChartView.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java
similarity index 83%
rename from src/com/android/settings/fuelgauge/BatteryChartView.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java
index ff61fcead5a..427388befcd 100644
--- a/src/com/android/settings/fuelgauge/BatteryChartView.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java
@@ -1,22 +1,24 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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
+ * 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.
+ * 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;
-
-import static java.lang.Math.round;
+package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.Utils.formatPercentage;
+import static java.lang.Math.round;
+
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.content.res.Resources;
@@ -37,8 +39,8 @@ import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.TextView;
-import androidx.appcompat.widget.AppCompatImageView;
import androidx.annotation.VisibleForTesting;
+import androidx.appcompat.widget.AppCompatImageView;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
@@ -54,7 +56,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
AccessibilityManager.AccessibilityStateChangeListener {
private static final String TAG = "BatteryChartView";
private static final List ACCESSIBILITY_SERVICE_NAMES =
- Arrays.asList("SwitchAccessService", "TalkBackService", "JustSpeakService");
+ Arrays.asList("SwitchAccessService", "TalkBackService", "JustSpeakService");
private static final int DEFAULT_TRAPEZOID_COUNT = 12;
private static final int DEFAULT_TIMESTAMP_COUNT = 4;
@@ -68,6 +70,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
/** A callback listener for selected group index is updated. */
public interface OnSelectListener {
+ /** The callback function for selected group index is updated. */
void onSelect(int trapezoidIndex);
}
@@ -79,9 +82,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private boolean mIsSlotsClickabled;
private String[] mPercentages = getPercentages();
- @VisibleForTesting int mHoveredIndex = SELECTED_INDEX_INVALID;
- @VisibleForTesting int mSelectedIndex = SELECTED_INDEX_INVALID;
- @VisibleForTesting String[] mTimestamps;
+ @VisibleForTesting
+ int mHoveredIndex = SELECTED_INDEX_INVALID;
+ @VisibleForTesting
+ int mSelectedIndex = SELECTED_INDEX_INVALID;
+ @VisibleForTesting
+ String[] mTimestamps;
// Colors for drawing the trapezoid shape and dividers.
private int mTrapezoidColor;
@@ -91,10 +97,10 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private int mTextPadding;
private final Rect mIndent = new Rect();
private final Rect[] mPercentageBounds =
- new Rect[] {new Rect(), new Rect(), new Rect()};
+ new Rect[]{new Rect(), new Rect(), new Rect()};
// For drawing the timestamp information.
private final Rect[] mTimestampsBounds =
- new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()};
+ new Rect[]{new Rect(), new Rect(), new Rect(), new Rect()};
@VisibleForTesting
Handler mHandler = new Handler();
@@ -202,14 +208,15 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTimestamps = new String[DEFAULT_TIMESTAMP_COUNT];
}
final long timeSlotOffset =
- DateUtils.HOUR_IN_MILLIS * (/*total 24 hours*/ 24 / TIMESTAMP_GAPS_COUNT);
+ DateUtils.HOUR_IN_MILLIS * (/*total 24 hours*/ 24 / TIMESTAMP_GAPS_COUNT);
final boolean is24HourFormat = DateFormat.is24HourFormat(getContext());
for (int index = 0; index < DEFAULT_TIMESTAMP_COUNT; index++) {
mTimestamps[index] =
- ConvertUtils.utcToLocalTimeHour(
- getContext(),
- latestTimestamp - (TIMESTAMP_GAPS_COUNT - index) * timeSlotOffset,
- is24HourFormat);
+ ConvertUtils.utcToLocalTimeHour(
+ getContext(),
+ latestTimestamp - (TIMESTAMP_GAPS_COUNT - index)
+ * timeSlotOffset,
+ is24HourFormat);
}
requestLayout();
}
@@ -221,8 +228,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
if (mTextPaint != null) {
for (int index = 0; index < mPercentages.length; index++) {
mTextPaint.getTextBounds(
- mPercentages[index], 0, mPercentages[index].length(),
- mPercentageBounds[index]);
+ mPercentages[index], 0, mPercentages[index].length(),
+ mPercentageBounds[index]);
}
// Updates the indent configurations.
mIndent.top = mPercentageBounds[0].height();
@@ -232,8 +239,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
int maxHeight = 0;
for (int index = 0; index < DEFAULT_TIMESTAMP_COUNT; index++) {
mTextPaint.getTextBounds(
- mTimestamps[index], 0, mTimestamps[index].length(),
- mTimestampsBounds[index]);
+ mTimestamps[index], 0, mTimestamps[index].length(),
+ mTimestampsBounds[index]);
maxHeight = Math.max(maxHeight, mTimestampsBounds[index].height());
}
mIndent.bottom = maxHeight + round(mTextPadding * 1.5f);
@@ -318,14 +325,14 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
super.onAttachedToWindow();
updateClickableState();
mContext.getSystemService(AccessibilityManager.class)
- .addAccessibilityStateChangeListener(/*listener=*/ this);
+ .addAccessibilityStateChangeListener(/*listener=*/ this);
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
mContext.getSystemService(AccessibilityManager.class)
- .removeAccessibilityStateChangeListener(/*listener=*/ this);
+ .removeAccessibilityStateChangeListener(/*listener=*/ this);
mHandler.removeCallbacks(mUpdateClickableStateRun);
}
@@ -336,16 +343,16 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// We should delay it a while since accessibility manager will spend
// some times to bind with new enabled accessibility services.
mHandler.postDelayed(
- mUpdateClickableStateRun, UPDATE_STATE_DELAYED_TIME);
+ mUpdateClickableStateRun, UPDATE_STATE_DELAYED_TIME);
}
private void updateClickableState() {
final Context context = mContext;
mIsSlotsClickabled =
- FeatureFactory.getFactory(context)
- .getPowerUsageFeatureProvider(context)
- .isChartGraphSlotsEnabled(context)
- && !isAccessibilityEnabled(context);
+ FeatureFactory.getFactory(context)
+ .getPowerUsageFeatureProvider(context)
+ .isChartGraphSlotsEnabled(context)
+ && !isAccessibilityEnabled(context);
Log.d(TAG, "isChartGraphSlotsEnabled:" + mIsSlotsClickabled);
setClickable(isClickable());
// Initializes the trapezoid curve paint for non-clickable case.
@@ -378,7 +385,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);
mTrapezoidColor = Utils.getDisabled(context, mTrapezoidSolidColor);
mTrapezoidHoverColor = Utils.getColorAttrDefaultColor(context,
- com.android.internal.R.attr.colorAccentSecondaryVariant);
+ com.android.internal.R.attr.colorAccentSecondaryVariant);
// Initializes the divider line paint.
final Resources resources = getContext().getResources();
mDividerWidth = resources.getDimensionPixelSize(R.dimen.chartview_divider_width);
@@ -398,8 +405,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTrapezoidPaint.setColor(mTrapezoidSolidColor);
mTrapezoidPaint.setStyle(Paint.Style.FILL);
mTrapezoidPaint.setPathEffect(
- new CornerPathEffect(
- resources.getDimensionPixelSize(R.dimen.chartview_trapezoid_radius)));
+ new CornerPathEffect(
+ resources.getDimensionPixelSize(R.dimen.chartview_trapezoid_radius)));
// Initializes for drawing text information.
mTextPadding = resources.getDimensionPixelSize(R.dimen.chartview_text_padding);
}
@@ -414,7 +421,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Draws the center divider line for 50% curve.
final float availableSpace =
- height - mDividerWidth * 2 - mTrapezoidVOffset - mDividerHeight;
+ height - mDividerWidth * 2 - mTrapezoidVOffset - mDividerHeight;
offsetY = mIndent.top + mDividerWidth + availableSpace * .5f;
canvas.drawLine(0, offsetY, width, offsetY, mDividerPaint);
drawPercentage(canvas, /*index=*/ 1, offsetY);
@@ -428,10 +435,11 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private void drawPercentage(Canvas canvas, int index, float offsetY) {
if (mTextPaint != null) {
canvas.drawText(
- mPercentages[index],
- getWidth() - mPercentageBounds[index].width() - mPercentageBounds[index].left,
- offsetY + mPercentageBounds[index].height() *.5f,
- mTextPaint);
+ mPercentages[index],
+ getWidth() - mPercentageBounds[index].width()
+ - mPercentageBounds[index].left,
+ offsetY + mPercentageBounds[index].height() * .5f,
+ mTextPaint);
}
}
@@ -471,31 +479,32 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private void drawTimestamp(Canvas canvas, float[] xOffsets) {
// Draws the 1st timestamp info.
canvas.drawText(
- mTimestamps[0],
- xOffsets[0] - mTimestampsBounds[0].left,
- getTimestampY(0), mTextPaint);
+ mTimestamps[0],
+ xOffsets[0] - mTimestampsBounds[0].left,
+ getTimestampY(0), mTextPaint);
final int latestIndex = DEFAULT_TIMESTAMP_COUNT - 1;
// Draws the last timestamp info.
canvas.drawText(
- mTimestamps[latestIndex],
- xOffsets[latestIndex] - mTimestampsBounds[latestIndex].width()
- - mTimestampsBounds[latestIndex].left,
- getTimestampY(latestIndex), mTextPaint);
+ mTimestamps[latestIndex],
+ xOffsets[latestIndex] - mTimestampsBounds[latestIndex].width()
+ - mTimestampsBounds[latestIndex].left,
+ getTimestampY(latestIndex), mTextPaint);
// Draws the rest of timestamp info since it is located in the center.
for (int index = 1; index <= DEFAULT_TIMESTAMP_COUNT - 2; index++) {
canvas.drawText(
- mTimestamps[index],
- xOffsets[index] -
- (mTimestampsBounds[index].width() - mTimestampsBounds[index].left) * .5f,
- getTimestampY(index), mTextPaint);
+ mTimestamps[index],
+ xOffsets[index]
+ - (mTimestampsBounds[index].width() - mTimestampsBounds[index].left)
+ * .5f,
+ getTimestampY(index), mTextPaint);
}
}
private int getTimestampY(int index) {
return getHeight() - mTimestampsBounds[index].height()
- + (mTimestampsBounds[index].height() + mTimestampsBounds[index].top)
- + round(mTextPadding * 1.5f);
+ + (mTimestampsBounds[index].height() + mTimestampsBounds[index].top)
+ + round(mTextPadding * 1.5f);
}
private void drawTrapezoids(Canvas canvas) {
@@ -504,8 +513,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
return;
}
final float trapezoidBottom =
- getHeight() - mIndent.bottom - mDividerHeight - mDividerWidth
- - mTrapezoidVOffset;
+ getHeight() - mIndent.bottom - mDividerHeight - mDividerWidth
+ - mTrapezoidVOffset;
final float availableSpace = trapezoidBottom - mDividerWidth * .5f - mIndent.top;
final float unitHeight = availableSpace / 100f;
// Draws all trapezoid shapes into the canvas.
@@ -522,12 +531,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
// Configures the trapezoid paint color.
final int trapezoidColor =
- !mIsSlotsClickabled
- ? mTrapezoidColor
- : mSelectedIndex == index || mSelectedIndex == SELECTED_INDEX_ALL
- ? mTrapezoidSolidColor : mTrapezoidColor;
+ !mIsSlotsClickabled
+ ? mTrapezoidColor
+ : mSelectedIndex == index || mSelectedIndex == SELECTED_INDEX_ALL
+ ? mTrapezoidSolidColor : mTrapezoidColor;
final boolean isHoverState =
- mIsSlotsClickabled && mHoveredIndex == index && isValidToDraw(mHoveredIndex);
+ mIsSlotsClickabled && mHoveredIndex == index && isValidToDraw(mHoveredIndex);
mTrapezoidPaint.setColor(isHoverState ? mTrapezoidHoverColor : trapezoidColor);
final float leftTop = round(trapezoidBottom - mLevels[index] * unitHeight);
@@ -546,7 +555,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Generates path for non-clickable trapezoid curve.
if (mTrapezoidCurvePaint != null) {
if (trapezoidCurvePath == null) {
- trapezoidCurvePath= new Path();
+ trapezoidCurvePath = new Path();
trapezoidCurvePath.moveTo(mTrapezoidSlots[index].mLeft, leftTop);
} else {
trapezoidCurvePath.lineTo(mTrapezoidSlots[index].mLeft, leftTop);
@@ -582,23 +591,23 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
private static String[] getPercentages() {
- return new String[] {
- formatPercentage(/*percentage=*/ 100, /*round=*/ true),
- formatPercentage(/*percentage=*/ 50, /*round=*/ true),
- formatPercentage(/*percentage=*/ 0, /*round=*/ true)};
+ return new String[]{
+ formatPercentage(/*percentage=*/ 100, /*round=*/ true),
+ formatPercentage(/*percentage=*/ 50, /*round=*/ true),
+ formatPercentage(/*percentage=*/ 0, /*round=*/ true)};
}
@VisibleForTesting
static boolean isAccessibilityEnabled(Context context) {
final AccessibilityManager accessibilityManager =
- context.getSystemService(AccessibilityManager.class);
+ context.getSystemService(AccessibilityManager.class);
if (!accessibilityManager.isEnabled()) {
return false;
}
final List serviceInfoList =
- accessibilityManager.getEnabledAccessibilityServiceList(
- AccessibilityServiceInfo.FEEDBACK_SPOKEN
- | AccessibilityServiceInfo.FEEDBACK_GENERIC);
+ accessibilityManager.getEnabledAccessibilityServiceList(
+ AccessibilityServiceInfo.FEEDBACK_SPOKEN
+ | AccessibilityServiceInfo.FEEDBACK_GENERIC);
for (AccessibilityServiceInfo info : serviceInfoList) {
for (String serviceName : ACCESSIBILITY_SERVICE_NAMES) {
final String serviceId = info.getId();
diff --git a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
similarity index 73%
rename from src/com/android/settings/fuelgauge/BatteryDiffEntry.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
index 403f79cffa4..8b995c859f9 100644
--- a/src/com/android/settings/fuelgauge/BatteryDiffEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
@@ -1,17 +1,19 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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
+ * 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.
+ * 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;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -26,6 +28,7 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settingslib.utils.StringUtil;
import java.util.Comparator;
@@ -61,11 +64,16 @@ public class BatteryDiffEntry {
private UserManager mUserManager;
private String mDefaultPackageName = null;
- @VisibleForTesting int mAppIconId;
- @VisibleForTesting String mAppLabel = null;
- @VisibleForTesting Drawable mAppIcon = null;
- @VisibleForTesting boolean mIsLoaded = false;
- @VisibleForTesting boolean mValidForRestriction = true;
+ @VisibleForTesting
+ int mAppIconId;
+ @VisibleForTesting
+ String mAppLabel = null;
+ @VisibleForTesting
+ Drawable mAppIcon = null;
+ @VisibleForTesting
+ boolean mIsLoaded = false;
+ @VisibleForTesting
+ boolean mValidForRestriction = true;
public BatteryDiffEntry(
Context context,
@@ -85,7 +93,7 @@ public class BatteryDiffEntry {
public void setTotalConsumePower(double totalConsumePower) {
mTotalConsumePower = totalConsumePower;
mPercentOfTotal = totalConsumePower == 0
- ? 0 : (mConsumePower / mTotalConsumePower) * 100.0;
+ ? 0 : (mConsumePower / mTotalConsumePower) * 100.0;
}
/** Gets the percentage of total consumed power. */
@@ -96,11 +104,11 @@ public class BatteryDiffEntry {
/** Clones a new instance. */
public BatteryDiffEntry clone() {
return new BatteryDiffEntry(
- this.mContext,
- this.mForegroundUsageTimeInMs,
- this.mBackgroundUsageTimeInMs,
- this.mConsumePower,
- this.mBatteryHistEntry /*same instance*/);
+ this.mContext,
+ this.mForegroundUsageTimeInMs,
+ this.mBackgroundUsageTimeInMs,
+ this.mConsumePower,
+ this.mBatteryHistEntry /*same instance*/);
}
/** Gets the app label name for this entry. */
@@ -108,8 +116,8 @@ public class BatteryDiffEntry {
loadLabelAndIcon();
// Returns default applicationn label if we cannot find it.
return mAppLabel == null || mAppLabel.length() == 0
- ? mBatteryHistEntry.mAppLabel
- : mAppLabel;
+ ? mBatteryHistEntry.mAppLabel
+ : mAppLabel;
}
/** Gets the app icon {@link Drawable} for this entry. */
@@ -129,15 +137,15 @@ public class BatteryDiffEntry {
/** Gets the searching package name for UID battery type. */
public String getPackageName() {
final String packageName = mDefaultPackageName != null
- ? mDefaultPackageName : mBatteryHistEntry.mPackageName;
+ ? mDefaultPackageName : mBatteryHistEntry.mPackageName;
if (packageName == null) {
return packageName;
}
// Removes potential appended process name in the PackageName.
// From "com.opera.browser:privileged_process0" to "com.opera.browser"
- final String[] splittedPackageNames = packageName.split(":");
- return splittedPackageNames != null && splittedPackageNames.length > 0
- ? splittedPackageNames[0] : packageName;
+ final String[] splitPackageNames = packageName.split(":");
+ return splitPackageNames != null && splitPackageNames.length > 0
+ ? splitPackageNames[0] : packageName;
}
/** Whether this item is valid for users to launch restriction page? */
@@ -196,20 +204,20 @@ public class BatteryDiffEntry {
switch (mBatteryHistEntry.mConsumerType) {
case ConvertUtils.CONSUMER_TYPE_USER_BATTERY:
final BatteryEntry.NameAndIcon nameAndIconForUser =
- BatteryEntry.getNameAndIconFromUserId(
- mContext, (int) mBatteryHistEntry.mUserId);
+ BatteryEntry.getNameAndIconFromUserId(
+ mContext, (int) mBatteryHistEntry.mUserId);
if (nameAndIconForUser != null) {
mAppIcon = nameAndIconForUser.mIcon;
mAppLabel = nameAndIconForUser.mName;
sResourceCache.put(
- getKey(),
- new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, /*iconId=*/ 0));
+ getKey(),
+ new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, /*iconId=*/ 0));
}
break;
case ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY:
final BatteryEntry.NameAndIcon nameAndIconForSystem =
- BatteryEntry.getNameAndIconFromPowerComponent(
- mContext, mBatteryHistEntry.mDrainType);
+ BatteryEntry.getNameAndIconFromPowerComponent(
+ mContext, mBatteryHistEntry.mDrainType);
if (nameAndIconForSystem != null) {
mAppLabel = nameAndIconForSystem.mName;
if (nameAndIconForSystem.mIconId != 0) {
@@ -217,8 +225,8 @@ public class BatteryDiffEntry {
mAppIcon = mContext.getDrawable(nameAndIconForSystem.mIconId);
}
sResourceCache.put(
- getKey(),
- new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, mAppIconId));
+ getKey(),
+ new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, mAppIconId));
}
break;
case ConvertUtils.CONSUMER_TYPE_UID_BATTERY:
@@ -231,8 +239,8 @@ public class BatteryDiffEntry {
mAppIcon = getBadgeIconForUser(mAppIcon);
if (mAppLabel != null || mAppIcon != null) {
sResourceCache.put(
- getKey(),
- new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, /*iconId=*/ 0));
+ getKey(),
+ new BatteryEntry.NameAndIcon(mAppLabel, mAppIcon, /*iconId=*/ 0));
}
break;
}
@@ -251,23 +259,23 @@ public class BatteryDiffEntry {
}
final boolean isValidPackage =
BatteryUtils.getInstance(mContext).getPackageUid(getPackageName())
- != BatteryUtils.UID_NULL;
+ != BatteryUtils.UID_NULL;
if (!isValidPackage) {
mValidForRestriction = false;
return;
}
try {
mValidForRestriction =
- mContext.getPackageManager().getPackageInfo(
- getPackageName(),
- PackageManager.MATCH_DISABLED_COMPONENTS
- | PackageManager.MATCH_ANY_USER
- | PackageManager.GET_SIGNATURES
- | PackageManager.GET_PERMISSIONS)
- != null;
+ mContext.getPackageManager().getPackageInfo(
+ getPackageName(),
+ PackageManager.MATCH_DISABLED_COMPONENTS
+ | PackageManager.MATCH_ANY_USER
+ | PackageManager.GET_SIGNATURES
+ | PackageManager.GET_PERMISSIONS)
+ != null;
} catch (Exception e) {
Log.e(TAG, String.format("getPackageInfo() error %s for package=%s",
- e.getCause(), getPackageName()));
+ e.getCause(), getPackageName()));
mValidForRestriction = false;
}
}
@@ -276,7 +284,7 @@ public class BatteryDiffEntry {
final Locale locale = Locale.getDefault();
if (sCurrentLocale != locale) {
Log.d(TAG, String.format("clearCache() locale is changed from %s to %s",
- sCurrentLocale, locale));
+ sCurrentLocale, locale));
sCurrentLocale = locale;
clearCache();
}
@@ -290,7 +298,7 @@ public class BatteryDiffEntry {
if (packageName != null && packageName.length() != 0) {
try {
final ApplicationInfo appInfo =
- packageManager.getApplicationInfo(packageName, /*no flags*/ 0);
+ packageManager.getApplicationInfo(packageName, /*no flags*/ 0);
if (appInfo != null) {
mAppLabel = packageManager.getApplicationLabel(appInfo).toString();
mAppIcon = packageManager.getApplicationIcon(appInfo);
@@ -310,15 +318,15 @@ public class BatteryDiffEntry {
// Loads special defined application label and icon if available.
if (packages == null || packages.length == 0) {
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryEntry.getNameAndIconFromUid(mContext, mAppLabel, uid);
+ BatteryEntry.getNameAndIconFromUid(mContext, mAppLabel, uid);
mAppLabel = nameAndIcon.mName;
mAppIcon = nameAndIcon.mIcon;
}
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryEntry.loadNameAndIcon(
- mContext, uid, /*handler=*/ null, /*batteryEntry=*/ null,
- packageName, mAppLabel, mAppIcon);
+ BatteryEntry.loadNameAndIcon(
+ mContext, uid, /*handler=*/ null, /*batteryEntry=*/ null,
+ packageName, mAppLabel, mAppIcon);
// Clears BatteryEntry internal cache since we will have another one.
BatteryEntry.clearUidCache();
if (nameAndIcon != null) {
@@ -328,7 +336,7 @@ public class BatteryDiffEntry {
if (mDefaultPackageName != null
&& !mDefaultPackageName.equals(nameAndIcon.mPackageName)) {
Log.w(TAG, String.format("found different package: %s | %s",
- mDefaultPackageName, nameAndIcon.mPackageName));
+ mDefaultPackageName, nameAndIcon.mPackageName));
}
}
}
@@ -336,19 +344,19 @@ public class BatteryDiffEntry {
@Override
public String toString() {
final StringBuilder builder = new StringBuilder()
- .append("BatteryDiffEntry{")
- .append(String.format("\n\tname=%s restrictable=%b",
- mAppLabel, mValidForRestriction))
- .append(String.format("\n\tconsume=%.2f%% %f/%f",
- mPercentOfTotal, mConsumePower, mTotalConsumePower))
- .append(String.format("\n\tforeground:%s background:%s",
- StringUtil.formatElapsedTime(mContext, mForegroundUsageTimeInMs,
- /*withSeconds=*/ true, /*collapseTimeUnit=*/ false),
- StringUtil.formatElapsedTime(mContext, mBackgroundUsageTimeInMs,
- /*withSeconds=*/ true, /*collapseTimeUnit=*/ false)))
- .append(String.format("\n\tpackage:%s|%s uid:%d userId:%d",
- mBatteryHistEntry.mPackageName, getPackageName(),
- mBatteryHistEntry.mUid, mBatteryHistEntry.mUserId));
+ .append("BatteryDiffEntry{")
+ .append(String.format("\n\tname=%s restrictable=%b",
+ mAppLabel, mValidForRestriction))
+ .append(String.format("\n\tconsume=%.2f%% %f/%f",
+ mPercentOfTotal, mConsumePower, mTotalConsumePower))
+ .append(String.format("\n\tforeground:%s background:%s",
+ StringUtil.formatElapsedTime(mContext, mForegroundUsageTimeInMs,
+ /*withSeconds=*/ true, /*collapseTimeUnit=*/ false),
+ StringUtil.formatElapsedTime(mContext, mBackgroundUsageTimeInMs,
+ /*withSeconds=*/ true, /*collapseTimeUnit=*/ false)))
+ .append(String.format("\n\tpackage:%s|%s uid:%d userId:%d",
+ mBatteryHistEntry.mPackageName, getPackageName(),
+ mBatteryHistEntry.mUid, mBatteryHistEntry.mUserId));
return builder.toString();
}
@@ -361,7 +369,7 @@ public class BatteryDiffEntry {
private Drawable getBadgeIconForUser(Drawable icon) {
final int userId = UserHandle.getUserId((int) mBatteryHistEntry.mUid);
return userId == UserHandle.USER_OWNER ? icon :
- mUserManager.getBadgedIconForUser(icon, new UserHandle(userId));
+ mUserManager.getBadgedIconForUser(icon, new UserHandle(userId));
}
private static boolean isSystemUid(int uid) {
diff --git a/src/com/android/settings/fuelgauge/BatteryEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
similarity index 93%
rename from src/com/android/settings/fuelgauge/BatteryEntry.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
index 9dcbd05564e..24d6dad8f88 100644
--- a/src/com/android/settings/fuelgauge/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import android.app.AppGlobals;
import android.content.Context;
@@ -36,9 +36,8 @@ import android.os.UserManager;
import android.util.DebugUtils;
import android.util.Log;
-import androidx.annotation.NonNull;
-
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settingslib.Utils;
import java.util.ArrayList;
@@ -52,6 +51,7 @@ import java.util.Locale;
*/
public class BatteryEntry {
+ /** The app name and icon in app list. */
public static final class NameAndIcon {
public final String mName;
public final String mPackageName;
@@ -84,10 +84,10 @@ public class BatteryEntry {
static Locale sCurrentLocale = null;
- static private class NameAndIconLoader extends Thread {
+ private static class NameAndIconLoader extends Thread {
private boolean mAbort = false;
- public NameAndIconLoader() {
+ NameAndIconLoader() {
super("BatteryUsage Icon Loader");
}
@@ -109,9 +109,9 @@ public class BatteryEntry {
be = sRequestQueue.remove(0);
}
final NameAndIcon nameAndIcon =
- BatteryEntry.loadNameAndIcon(
- be.mContext, be.getUid(), sHandler, be,
- be.mDefaultPackageName, be.mName, be.mIcon);
+ BatteryEntry.loadNameAndIcon(
+ be.mContext, be.getUid(), sHandler, be,
+ be.mDefaultPackageName, be.mName, be.mIcon);
if (nameAndIcon != null) {
be.mIcon = nameAndIcon.mIcon;
be.mName = nameAndIcon.mName;
@@ -121,35 +121,38 @@ public class BatteryEntry {
}
}
- private static NameAndIconLoader mRequestThread;
+ private static NameAndIconLoader sRequestThread;
+ /** Starts the request queue. */
public static void startRequestQueue() {
if (sHandler != null) {
synchronized (sRequestQueue) {
if (!sRequestQueue.isEmpty()) {
- if (mRequestThread != null) {
- mRequestThread.abort();
+ if (sRequestThread != null) {
+ sRequestThread.abort();
}
- mRequestThread = new NameAndIconLoader();
- mRequestThread.setPriority(Thread.MIN_PRIORITY);
- mRequestThread.start();
+ sRequestThread = new NameAndIconLoader();
+ sRequestThread.setPriority(Thread.MIN_PRIORITY);
+ sRequestThread.start();
sRequestQueue.notify();
}
}
}
}
+ /** Stops the request queue. */
public static void stopRequestQueue() {
synchronized (sRequestQueue) {
- if (mRequestThread != null) {
- mRequestThread.abort();
- mRequestThread = null;
+ if (sRequestThread != null) {
+ sRequestThread.abort();
+ sRequestThread = null;
sRequestQueue.clear();
sHandler = null;
}
}
}
+ /** Clears the UID cache. */
public static void clearUidCache() {
sUidCache.clear();
}
@@ -252,14 +255,14 @@ public class BatteryEntry {
mIsHidden = false;
mPowerComponentId = powerComponentId;
mConsumedPower =
- powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
- ? devicePowerMah
- : devicePowerMah - appsPowerMah;
+ powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
+ ? devicePowerMah
+ : devicePowerMah - appsPowerMah;
mUsageDurationMs = usageDurationMs;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
final NameAndIcon nameAndIcon =
- getNameAndIconFromPowerComponent(context, powerComponentId);
+ getNameAndIconFromPowerComponent(context, powerComponentId);
mIconId = nameAndIcon.mIconId;
mName = nameAndIcon.mName;
if (mIconId != 0) {
@@ -280,9 +283,9 @@ public class BatteryEntry {
mIcon = context.getDrawable(mIconId);
mName = powerComponentName;
mConsumedPower =
- powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
- ? devicePowerMah
- : devicePowerMah - appsPowerMah;
+ powerComponentId == BatteryConsumer.POWER_COMPONENT_SCREEN
+ ? devicePowerMah
+ : devicePowerMah - appsPowerMah;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
}
@@ -354,7 +357,7 @@ public class BatteryEntry {
final PackageManager pm = context.getPackageManager();
final String[] packages = isSystemUid(uid)
- ? new String[] {PACKAGE_SYSTEM} : pm.getPackagesForUid(uid);
+ ? new String[]{PACKAGE_SYSTEM} : pm.getPackagesForUid(uid);
if (packages != null) {
final String[] packageLabels = new String[packages.length];
System.arraycopy(packages, 0, packageLabels, 0, packages.length);
@@ -552,8 +555,8 @@ public class BatteryEntry {
name = context.getResources().getString(R.string.process_network_tethering);
} else if ("mediaserver".equals(name)) {
name = context.getResources().getString(R.string.process_mediaserver_label);
- } else if ("dex2oat".equals(name) || "dex2oat32".equals(name) ||
- "dex2oat64".equals(name)) {
+ } else if ("dex2oat".equals(name) || "dex2oat32".equals(name)
+ || "dex2oat64".equals(name)) {
name = context.getResources().getString(R.string.process_dex2oat_label);
}
return new NameAndIcon(name, icon, 0 /* iconId */);
@@ -612,7 +615,8 @@ public class BatteryEntry {
return new NameAndIcon(name, null /* icon */, iconId);
}
- static boolean isSystemUid(int uid) {
+ /** Whether the uid is system uid. */
+ public static boolean isSystemUid(int uid) {
return uid == Process.SYSTEM_UID;
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryHistEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
similarity index 78%
rename from src/com/android/settings/fuelgauge/BatteryHistEntry.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
index 45f9e9f018c..b88b2f6ec25 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
@@ -1,17 +1,19 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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
+ * 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.
+ * 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;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.ContentValues;
import android.database.Cursor;
@@ -117,14 +119,14 @@ public class BatteryHistEntry {
}
private BatteryHistEntry(
- BatteryHistEntry fromEntry,
- long bootTimestamp,
- long timestamp,
- double totalPower,
- double consumePower,
- long foregroundUsageTimeInMs,
- long backgroundUsageTimeInMs,
- int batteryLevel) {
+ BatteryHistEntry fromEntry,
+ long bootTimestamp,
+ long timestamp,
+ double totalPower,
+ double consumePower,
+ long foregroundUsageTimeInMs,
+ long backgroundUsageTimeInMs,
+ int batteryLevel) {
mUid = fromEntry.mUid;
mUserId = fromEntry.mUserId;
mAppLabel = fromEntry.mAppLabel;
@@ -186,28 +188,28 @@ public class BatteryHistEntry {
@Override
public String toString() {
final String recordAtDateTime =
- ConvertUtils.utcToLocalTime(/*context=*/ null, mTimestamp);
+ ConvertUtils.utcToLocalTime(/*context=*/ null, mTimestamp);
final StringBuilder builder = new StringBuilder()
- .append("\nBatteryHistEntry{")
- .append(String.format("\n\tpackage=%s|label=%s|uid=%d|userId=%d|isHidden=%b",
- mPackageName, mAppLabel, mUid, mUserId, mIsHidden))
- .append(String.format("\n\ttimestamp=%s|zoneId=%s|bootTimestamp=%d",
- recordAtDateTime, mZoneId, Duration.ofMillis(mBootTimestamp).getSeconds()))
- .append(String.format("\n\tusage=%f|total=%f|consume=%f|elapsedTime=%d|%d",
- mPercentOfTotal, mTotalPower, mConsumePower,
- Duration.ofMillis(mForegroundUsageTimeInMs).getSeconds(),
- Duration.ofMillis(mBackgroundUsageTimeInMs).getSeconds()))
- .append(String.format("\n\tdrainType=%d|consumerType=%d",
- mDrainType, mConsumerType))
- .append(String.format("\n\tbattery=%d|status=%d|health=%d\n}",
- mBatteryLevel, mBatteryStatus, mBatteryHealth));
+ .append("\nBatteryHistEntry{")
+ .append(String.format("\n\tpackage=%s|label=%s|uid=%d|userId=%d|isHidden=%b",
+ mPackageName, mAppLabel, mUid, mUserId, mIsHidden))
+ .append(String.format("\n\ttimestamp=%s|zoneId=%s|bootTimestamp=%d",
+ recordAtDateTime, mZoneId, Duration.ofMillis(mBootTimestamp).getSeconds()))
+ .append(String.format("\n\tusage=%f|total=%f|consume=%f|elapsedTime=%d|%d",
+ mPercentOfTotal, mTotalPower, mConsumePower,
+ Duration.ofMillis(mForegroundUsageTimeInMs).getSeconds(),
+ Duration.ofMillis(mBackgroundUsageTimeInMs).getSeconds()))
+ .append(String.format("\n\tdrainType=%d|consumerType=%d",
+ mDrainType, mConsumerType))
+ .append(String.format("\n\tbattery=%d|status=%d|health=%d\n}",
+ mBatteryLevel, mBatteryStatus, mBatteryHealth));
return builder.toString();
}
private int getInteger(ContentValues values, String key) {
if (values != null && values.containsKey(key)) {
return values.getAsInteger(key);
- };
+ }
mIsValidEntry = false;
return 0;
}
@@ -298,21 +300,21 @@ public class BatteryHistEntry {
BatteryHistEntry lowerHistEntry,
BatteryHistEntry upperHistEntry) {
final double totalPower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mTotalPower,
- upperHistEntry.mTotalPower,
- ratio);
+ lowerHistEntry == null ? 0 : lowerHistEntry.mTotalPower,
+ upperHistEntry.mTotalPower,
+ ratio);
final double consumePower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mConsumePower,
- upperHistEntry.mConsumePower,
- ratio);
+ lowerHistEntry == null ? 0 : lowerHistEntry.mConsumePower,
+ upperHistEntry.mConsumePower,
+ ratio);
final double foregroundUsageTimeInMs = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundUsageTimeInMs,
- upperHistEntry.mForegroundUsageTimeInMs,
- ratio);
+ lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundUsageTimeInMs,
+ upperHistEntry.mForegroundUsageTimeInMs,
+ ratio);
final double backgroundUsageTimeInMs = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageTimeInMs,
- upperHistEntry.mBackgroundUsageTimeInMs,
- ratio);
+ lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageTimeInMs,
+ upperHistEntry.mBackgroundUsageTimeInMs,
+ ratio);
// Checks whether there is any abnoaml cases!
if (upperHistEntry.mConsumePower < consumePower
|| upperHistEntry.mForegroundUsageTimeInMs < foregroundUsageTimeInMs
@@ -324,22 +326,22 @@ public class BatteryHistEntry {
}
}
final double batteryLevel =
- lowerHistEntry == null
- ? upperHistEntry.mBatteryLevel
- : interpolate(
- lowerHistEntry.mBatteryLevel,
- upperHistEntry.mBatteryLevel,
- ratio);
+ lowerHistEntry == null
+ ? upperHistEntry.mBatteryLevel
+ : interpolate(
+ lowerHistEntry.mBatteryLevel,
+ upperHistEntry.mBatteryLevel,
+ ratio);
return new BatteryHistEntry(
- upperHistEntry,
- /*bootTimestamp=*/ upperHistEntry.mBootTimestamp
+ upperHistEntry,
+ /*bootTimestamp=*/ upperHistEntry.mBootTimestamp
- (upperTimestamp - slotTimestamp),
- /*timestamp=*/ slotTimestamp,
- totalPower,
- consumePower,
- Math.round(foregroundUsageTimeInMs),
- Math.round(backgroundUsageTimeInMs),
- (int) Math.round(batteryLevel));
+ /*timestamp=*/ slotTimestamp,
+ totalPower,
+ consumePower,
+ Math.round(foregroundUsageTimeInMs),
+ Math.round(backgroundUsageTimeInMs),
+ (int) Math.round(batteryLevel));
}
private static double interpolate(double v1, double v2, double ratio) {
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryLoader.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryLoader.java
similarity index 84%
rename from src/com/android/settings/fuelgauge/BatteryHistoryLoader.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryLoader.java
index ddf3bf47d43..34606a5a583 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryLoader.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.utils.AsyncLoaderCompat;
@@ -41,7 +42,7 @@ public class BatteryHistoryLoader
@Override
public Map> loadInBackground() {
final PowerUsageFeatureProvider powerUsageFeatureProvider =
- FeatureFactory.getFactory(mContext).getPowerUsageFeatureProvider(mContext);
+ FeatureFactory.getFactory(mContext).getPowerUsageFeatureProvider(mContext);
return powerUsageFeatureProvider.getBatteryHistory(mContext);
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java
similarity index 84%
rename from src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java
index b2818bf601d..e125d17d6a3 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.os.BatteryUsageStats;
@@ -29,6 +29,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryInfo;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.UsageView;
@@ -38,8 +40,10 @@ import com.android.settings.widget.UsageView;
public class BatteryHistoryPreference extends Preference {
private static final String TAG = "BatteryHistoryPreference";
- @VisibleForTesting boolean mHideSummary;
- @VisibleForTesting BatteryInfo mBatteryInfo;
+ @VisibleForTesting
+ boolean mHideSummary;
+ @VisibleForTesting
+ BatteryInfo mBatteryInfo;
private boolean mIsChartGraphEnabled;
@@ -51,16 +55,17 @@ public class BatteryHistoryPreference extends Preference {
public BatteryHistoryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mIsChartGraphEnabled =
- FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context)
- .isChartGraphEnabled(context);
+ FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context)
+ .isChartGraphEnabled(context);
Log.i(TAG, "isChartGraphEnabled: " + mIsChartGraphEnabled);
setLayoutResource(
- mIsChartGraphEnabled
- ? R.layout.battery_chart_graph
- : R.layout.battery_usage_graph);
+ mIsChartGraphEnabled
+ ? R.layout.battery_chart_graph
+ : R.layout.battery_usage_graph);
setSelectable(false);
}
+ /** Sets the text of bottom summary. */
public void setBottomSummary(CharSequence text) {
mSummaryContent = text;
if (mSummaryView != null) {
@@ -70,6 +75,7 @@ public class BatteryHistoryPreference extends Preference {
mHideSummary = false;
}
+ /** Hides the bottom summary. */
public void hideBottomSummary() {
if (mSummaryView != null) {
mSummaryView.setVisibility(View.GONE);
@@ -101,7 +107,7 @@ public class BatteryHistoryPreference extends Preference {
if (mIsChartGraphEnabled) {
mBatteryChartView = (BatteryChartView) view.findViewById(R.id.battery_chart);
mBatteryChartView.setCompanionTextView(
- (TextView) view.findViewById(R.id.companion_text));
+ (TextView) view.findViewById(R.id.companion_text));
if (mChartPreferenceController != null) {
mChartPreferenceController.setBatteryChartView(mBatteryChartView);
}
diff --git a/src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java
similarity index 95%
rename from src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java
rename to src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java
index 65f2ddbb5be..d61b2764633 100644
--- a/src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.os.BatteryStatsManager;
diff --git a/src/com/android/settings/fuelgauge/ConvertUtils.java b/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
similarity index 78%
rename from src/com/android/settings/fuelgauge/ConvertUtils.java
rename to src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
index 696147b44d4..76f9419ac41 100644
--- a/src/com/android/settings/fuelgauge/ConvertUtils.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/ConvertUtils.java
@@ -1,17 +1,19 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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
+ * 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.
+ * 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;
+package com.android.settings.fuelgauge.batteryusage;
import android.annotation.IntDef;
import android.content.ContentValues;
@@ -46,7 +48,7 @@ public final class ConvertUtils {
private static final String TAG = "ConvertUtils";
private static final Map EMPTY_BATTERY_MAP = new HashMap<>();
private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
- new BatteryHistEntry(new ContentValues());
+ new BatteryHistEntry(new ContentValues());
// Maximum total time value for each slot cumulative data at most 2 hours.
private static final float TOTAL_TIME_THRESHOLD = DateUtils.HOUR_IN_MILLIS * 2;
@@ -64,21 +66,24 @@ public final class ConvertUtils {
public static final String FAKE_PACKAGE_NAME = "fake_package";
@IntDef(prefix = {"CONSUMER_TYPE"}, value = {
- CONSUMER_TYPE_UNKNOWN,
- CONSUMER_TYPE_UID_BATTERY,
- CONSUMER_TYPE_USER_BATTERY,
- CONSUMER_TYPE_SYSTEM_BATTERY,
+ CONSUMER_TYPE_UNKNOWN,
+ CONSUMER_TYPE_UID_BATTERY,
+ CONSUMER_TYPE_USER_BATTERY,
+ CONSUMER_TYPE_SYSTEM_BATTERY,
})
@Retention(RetentionPolicy.SOURCE)
- public static @interface ConsumerType {}
+ public static @interface ConsumerType {
+ }
public static final int CONSUMER_TYPE_UNKNOWN = 0;
public static final int CONSUMER_TYPE_UID_BATTERY = 1;
public static final int CONSUMER_TYPE_USER_BATTERY = 2;
public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3;
- private ConvertUtils() {}
+ private ConvertUtils() {
+ }
+ /** Converts to content values */
public static ContentValues convert(
BatteryEntry entry,
BatteryUsageStats batteryUsageStats,
@@ -91,25 +96,25 @@ public final class ConvertUtils {
if (entry != null && batteryUsageStats != null) {
values.put(BatteryHistEntry.KEY_UID, Long.valueOf(entry.getUid()));
values.put(BatteryHistEntry.KEY_USER_ID,
- Long.valueOf(UserHandle.getUserId(entry.getUid())));
+ Long.valueOf(UserHandle.getUserId(entry.getUid())));
values.put(BatteryHistEntry.KEY_APP_LABEL, entry.getLabel());
values.put(BatteryHistEntry.KEY_PACKAGE_NAME,
- entry.getDefaultPackageName());
+ entry.getDefaultPackageName());
values.put(BatteryHistEntry.KEY_IS_HIDDEN, Boolean.valueOf(entry.isHidden()));
values.put(BatteryHistEntry.KEY_TOTAL_POWER,
- Double.valueOf(batteryUsageStats.getConsumedPower()));
+ Double.valueOf(batteryUsageStats.getConsumedPower()));
values.put(BatteryHistEntry.KEY_CONSUME_POWER,
- Double.valueOf(entry.getConsumedPower()));
+ Double.valueOf(entry.getConsumedPower()));
values.put(BatteryHistEntry.KEY_PERCENT_OF_TOTAL,
- Double.valueOf(entry.mPercent));
+ Double.valueOf(entry.mPercent));
values.put(BatteryHistEntry.KEY_FOREGROUND_USAGE_TIME,
- Long.valueOf(entry.getTimeInForegroundMs()));
+ Long.valueOf(entry.getTimeInForegroundMs()));
values.put(BatteryHistEntry.KEY_BACKGROUND_USAGE_TIME,
- Long.valueOf(entry.getTimeInBackgroundMs()));
+ Long.valueOf(entry.getTimeInBackgroundMs()));
values.put(BatteryHistEntry.KEY_DRAIN_TYPE,
- Integer.valueOf(entry.getPowerComponentId()));
+ Integer.valueOf(entry.getPowerComponentId()));
values.put(BatteryHistEntry.KEY_CONSUMER_TYPE,
- Integer.valueOf(entry.getConsumerType()));
+ Integer.valueOf(entry.getConsumerType()));
} else {
values.put(BatteryHistEntry.KEY_PACKAGE_NAME, FAKE_PACKAGE_NAME);
}
@@ -126,7 +131,7 @@ public final class ConvertUtils {
public static String utcToLocalTime(Context context, long timestamp) {
final Locale locale = getLocale(context);
final String pattern =
- DateFormat.getBestDateTimePattern(locale, "MMM dd,yyyy HH:mm:ss");
+ DateFormat.getBestDateTimePattern(locale, "MMM dd,yyyy HH:mm:ss");
return DateFormat.format(pattern, timestamp).toString();
}
@@ -159,18 +164,18 @@ public final class ConvertUtils {
final int timestampStride = 2;
for (int index = 0; index < timeSlotSize; index++) {
final Long currentTimestamp =
- Long.valueOf(batteryHistoryKeys[index * timestampStride]);
+ Long.valueOf(batteryHistoryKeys[index * timestampStride]);
final Long nextTimestamp =
- Long.valueOf(batteryHistoryKeys[index * timestampStride + 1]);
+ Long.valueOf(batteryHistoryKeys[index * timestampStride + 1]);
final Long nextTwoTimestamp =
- Long.valueOf(batteryHistoryKeys[index * timestampStride + 2]);
+ Long.valueOf(batteryHistoryKeys[index * timestampStride + 2]);
// Fetches BatteryHistEntry data from corresponding time slot.
final Map currentBatteryHistMap =
- batteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
+ batteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
final Map nextBatteryHistMap =
- batteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
+ batteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
final Map nextTwoBatteryHistMap =
- batteryHistoryMap.getOrDefault(nextTwoTimestamp, EMPTY_BATTERY_MAP);
+ batteryHistoryMap.getOrDefault(nextTwoTimestamp, EMPTY_BATTERY_MAP);
// We should not get the empty list since we have at least one fake data to record
// the battery level and status in each time slot, the empty list is used to
// represent there is no enough data to apply interpolation arithmetic.
@@ -195,27 +200,27 @@ public final class ConvertUtils {
// Calculates all packages diff usage data in a specific time slot.
for (String key : allBatteryHistEntryKeys) {
final BatteryHistEntry currentEntry =
- currentBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
+ currentBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
final BatteryHistEntry nextEntry =
- nextBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
+ nextBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
final BatteryHistEntry nextTwoEntry =
- nextTwoBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
+ nextTwoBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
// Cumulative values is a specific time slot for a specific app.
long foregroundUsageTimeInMs =
- getDiffValue(
- currentEntry.mForegroundUsageTimeInMs,
- nextEntry.mForegroundUsageTimeInMs,
- nextTwoEntry.mForegroundUsageTimeInMs);
+ getDiffValue(
+ currentEntry.mForegroundUsageTimeInMs,
+ nextEntry.mForegroundUsageTimeInMs,
+ nextTwoEntry.mForegroundUsageTimeInMs);
long backgroundUsageTimeInMs =
- getDiffValue(
- currentEntry.mBackgroundUsageTimeInMs,
- nextEntry.mBackgroundUsageTimeInMs,
- nextTwoEntry.mBackgroundUsageTimeInMs);
+ getDiffValue(
+ currentEntry.mBackgroundUsageTimeInMs,
+ nextEntry.mBackgroundUsageTimeInMs,
+ nextTwoEntry.mBackgroundUsageTimeInMs);
double consumePower =
- getDiffValue(
- currentEntry.mConsumePower,
- nextEntry.mConsumePower,
- nextTwoEntry.mConsumePower);
+ getDiffValue(
+ currentEntry.mConsumePower,
+ nextEntry.mConsumePower,
+ nextTwoEntry.mConsumePower);
// Excludes entry since we don't have enough data to calculate.
if (foregroundUsageTimeInMs == 0
&& backgroundUsageTimeInMs == 0
@@ -223,14 +228,14 @@ public final class ConvertUtils {
continue;
}
final BatteryHistEntry selectedBatteryEntry =
- selectBatteryHistEntry(currentEntry, nextEntry, nextTwoEntry);
+ selectBatteryHistEntry(currentEntry, nextEntry, nextTwoEntry);
if (selectedBatteryEntry == null) {
continue;
}
// Forces refine the cumulative value since it may introduce deviation
// error since we will apply the interpolation arithmetic.
final float totalUsageTimeInMs =
- foregroundUsageTimeInMs + backgroundUsageTimeInMs;
+ foregroundUsageTimeInMs + backgroundUsageTimeInMs;
if (totalUsageTimeInMs > TOTAL_TIME_THRESHOLD) {
final float ratio = TOTAL_TIME_THRESHOLD / totalUsageTimeInMs;
if (DEBUG) {
@@ -240,19 +245,19 @@ public final class ConvertUtils {
currentEntry));
}
foregroundUsageTimeInMs =
- Math.round(foregroundUsageTimeInMs * ratio);
+ Math.round(foregroundUsageTimeInMs * ratio);
backgroundUsageTimeInMs =
- Math.round(backgroundUsageTimeInMs * ratio);
+ Math.round(backgroundUsageTimeInMs * ratio);
consumePower = consumePower * ratio;
}
totalConsumePower += consumePower;
batteryDiffEntryList.add(
- new BatteryDiffEntry(
- context,
- foregroundUsageTimeInMs,
- backgroundUsageTimeInMs,
- consumePower,
- selectedBatteryEntry));
+ new BatteryDiffEntry(
+ context,
+ foregroundUsageTimeInMs,
+ backgroundUsageTimeInMs,
+ consumePower,
+ selectedBatteryEntry));
}
// Sets total consume power data into all BatteryDiffEntry in the same slot.
for (BatteryDiffEntry diffEntry : batteryDiffEntryList) {
@@ -282,9 +287,9 @@ public final class ConvertUtils {
} else {
// Sums up some fields data into the existing one.
oldBatteryDiffEntry.mForegroundUsageTimeInMs +=
- entry.mForegroundUsageTimeInMs;
+ entry.mForegroundUsageTimeInMs;
oldBatteryDiffEntry.mBackgroundUsageTimeInMs +=
- entry.mBackgroundUsageTimeInMs;
+ entry.mBackgroundUsageTimeInMs;
oldBatteryDiffEntry.mConsumePower += entry.mConsumePower;
}
totalConsumePower += entry.mConsumePower;
@@ -318,7 +323,7 @@ public final class ConvertUtils {
if (packageName != null
&& !backgroundUsageTimeHideList.isEmpty()
&& backgroundUsageTimeHideList.contains(packageName)) {
- entry.mBackgroundUsageTimeInMs = 0;
+ entry.mBackgroundUsageTimeInMs = 0;
}
}
}
@@ -342,7 +347,7 @@ public final class ConvertUtils {
return entry2;
} else {
return entry3 != null && entry3 != EMPTY_BATTERY_HIST_ENTRY
- ? entry3 : null;
+ ? entry3 : null;
}
}
@@ -352,8 +357,8 @@ public final class ConvertUtils {
return Locale.getDefault();
}
final LocaleList locales =
- context.getResources().getConfiguration().getLocales();
+ context.getResources().getConfiguration().getLocales();
return locales != null && !locales.isEmpty() ? locales.get(0)
- : Locale.getDefault();
+ : Locale.getDefault();
}
}
diff --git a/src/com/android/settings/fuelgauge/ExpandDividerPreference.java b/src/com/android/settings/fuelgauge/batteryusage/ExpandDividerPreference.java
similarity index 91%
rename from src/com/android/settings/fuelgauge/ExpandDividerPreference.java
rename to src/com/android/settings/fuelgauge/batteryusage/ExpandDividerPreference.java
index 45171770e6a..8af842bc9c2 100644
--- a/src/com/android/settings/fuelgauge/ExpandDividerPreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/ExpandDividerPreference.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.util.AttributeSet;
-import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@@ -33,8 +32,10 @@ public class ExpandDividerPreference extends Preference {
@VisibleForTesting
static final String PREFERENCE_KEY = "expandable_divider";
- @VisibleForTesting TextView mTextView;
- @VisibleForTesting ImageView mImageView;
+ @VisibleForTesting
+ TextView mTextView;
+ @VisibleForTesting
+ ImageView mImageView;
private OnExpandListener mOnExpandListener;
private boolean mIsExpanded = false;
@@ -42,6 +43,7 @@ public class ExpandDividerPreference extends Preference {
/** A callback listener for expand state is changed by users. */
public interface OnExpandListener {
+ /** Callback function for expand state is changed by users. */
void onExpand(boolean isExpanded);
}
diff --git a/src/com/android/settings/fuelgauge/PowerGaugePreference.java b/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java
similarity index 91%
rename from src/com/android/settings/fuelgauge/PowerGaugePreference.java
rename to src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java
index ea79d111cc3..5a4f672f086 100644
--- a/src/com/android/settings/fuelgauge/PowerGaugePreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.graphics.drawable.Drawable;
@@ -67,34 +67,41 @@ public class PowerGaugePreference extends AppPreference {
mShowAnomalyIcon = false;
}
+ /** Sets the content description. */
public void setContentDescription(String name) {
mContentDescription = name;
notifyChanged();
}
+ /** Sets the percent of total. */
public void setPercent(double percentOfTotal) {
mProgress = Utils.formatPercentage(percentOfTotal, true);
notifyChanged();
}
+ /** Gets the percent of total. */
public String getPercent() {
return mProgress.toString();
}
+ /** Sets the subtitle. */
public void setSubtitle(CharSequence subtitle) {
mProgress = subtitle;
notifyChanged();
}
+ /** Gets the subtitle. */
public CharSequence getSubtitle() {
return mProgress;
}
+ /** Sets whether to show anomaly icon */
public void shouldShowAnomalyIcon(boolean showAnomalyIcon) {
mShowAnomalyIcon = showAnomalyIcon;
notifyChanged();
}
+ /** Gets whether to show anomaly icon */
public boolean showAnomalyIcon() {
return mShowAnomalyIcon;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
similarity index 88%
rename from src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
rename to src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
index afbb71f9ed0..b88d85ddd1f 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageAdvanced.java
@@ -1,17 +1,19 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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
+ * 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.
+ * 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;
+package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
@@ -35,6 +37,7 @@ import androidx.loader.content.Loader;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -45,6 +48,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
+/** Advanced power usage. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class PowerUsageAdvanced extends PowerUsageBase {
private static final String TAG = "AdvancedBatteryUsage";
@@ -69,14 +73,14 @@ public class PowerUsageAdvanced extends PowerUsageBase {
private final ContentObserver mBatteryObserver =
new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange) {
- Log.d(TAG, "onBatteryContentChange: " + selfChange);
- mIsChartDataLoaded = false;
- restartBatteryStatsLoader(
- BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
- }
- };
+ @Override
+ public void onChange(boolean selfChange) {
+ Log.d(TAG, "onBatteryContentChange: " + selfChange);
+ mIsChartDataLoaded = false;
+ restartBatteryStatsLoader(
+ BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
+ }
+ };
@Override
public void onCreate(Bundle icicle) {
@@ -87,7 +91,7 @@ public class PowerUsageAdvanced extends PowerUsageBase {
if (mIsChartGraphEnabled) {
setBatteryChartPreferenceController();
} else {
- updateHistPrefSummary(context);
+ updateHistPrefSummary(context);
}
}
@@ -143,13 +147,13 @@ public class PowerUsageAdvanced extends PowerUsageBase {
if (mIsChartGraphEnabled) {
mBatteryChartPreferenceController =
new BatteryChartPreferenceController(context, KEY_APP_LIST,
- getSettingsLifecycle(), (SettingsActivity) getActivity(), this);
+ getSettingsLifecycle(), (SettingsActivity) getActivity(), this);
controllers.add(mBatteryChartPreferenceController);
setBatteryChartPreferenceController();
} else {
mBatteryAppListPreferenceController =
new BatteryAppListPreferenceController(context, KEY_APP_LIST,
- getSettingsLifecycle(), (SettingsActivity) getActivity(), this);
+ getSettingsLifecycle(), (SettingsActivity) getActivity(), this);
controllers.add(mBatteryAppListPreferenceController);
}
return controllers;
@@ -185,7 +189,7 @@ public class PowerUsageAdvanced extends PowerUsageBase {
if (mIsChartGraphEnabled && !mIsChartDataLoaded) {
mIsChartDataLoaded = true;
getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
- mBatteryHistoryLoaderCallbacks);
+ mBatteryHistoryLoaderCallbacks);
} else if (!mIsChartGraphEnabled) {
super.restartBatteryStatsLoader(refreshType);
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java
similarity index 95%
rename from src/com/android/settings/fuelgauge/PowerUsageBase.java
rename to src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java
index 6563155fb75..ccefdf2c4db 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
@@ -23,7 +23,6 @@ import android.os.BatteryUsageStats;
import android.os.Bundle;
import android.os.UserManager;
import android.util.Log;
-import android.view.Menu;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -31,6 +30,8 @@ import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
+import com.android.settings.fuelgauge.BatteryUtils;
/**
* Common base class for things that need to show the battery usage graph.
@@ -99,6 +100,7 @@ public abstract class PowerUsageBase extends DashboardFragment {
}
protected abstract void refreshUi(@BatteryUpdateType int refreshType);
+
protected abstract boolean isBatteryHistoryNeeded();
protected void updatePreference(BatteryHistoryPreference historyPref) {
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java
similarity index 94%
rename from src/com/android/settings/fuelgauge/PowerUsageSummary.java
rename to src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java
index 19a801110c0..405d855d3d8 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummary.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
@@ -34,6 +34,11 @@ import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
+import com.android.settings.fuelgauge.BatteryHeaderPreferenceController;
+import com.android.settings.fuelgauge.BatteryInfo;
+import com.android.settings.fuelgauge.BatteryInfoLoader;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
@@ -255,9 +260,9 @@ public class PowerUsageSummary extends PowerUsageBase implements
void initPreference() {
mBatteryUsagePreference = findPreference(KEY_BATTERY_USAGE);
mBatteryUsagePreference.setSummary(
- mPowerFeatureProvider.isChartGraphEnabled(getContext()) ?
- getString(R.string.advanced_battery_preference_summary_with_hours) :
- getString(R.string.advanced_battery_preference_summary));
+ mPowerFeatureProvider.isChartGraphEnabled(getContext())
+ ? getString(R.string.advanced_battery_preference_summary_with_hours)
+ : getString(R.string.advanced_battery_preference_summary));
mHelpPreference = findPreference(KEY_BATTERY_ERROR);
mHelpPreference.setVisible(false);
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
index f10a2d74c9d..33dcd4e7972 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
@@ -44,11 +44,11 @@ import androidx.slice.builders.SliceAction;
import com.android.settings.R;
import com.android.settings.SubSettings;
import com.android.settings.Utils;
-import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
-import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
+import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBuilderUtils;
diff --git a/src/com/android/settings/search/CustomSiteMapRegistry.java b/src/com/android/settings/search/CustomSiteMapRegistry.java
index ab33fa256d1..1777cb83b62 100644
--- a/src/com/android/settings/search/CustomSiteMapRegistry.java
+++ b/src/com/android/settings/search/CustomSiteMapRegistry.java
@@ -21,8 +21,8 @@ import android.util.ArrayMap;
import com.android.settings.backup.UserBackupSettingsActivity;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
-import com.android.settings.fuelgauge.PowerUsageAdvanced;
-import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.fuelgauge.batteryusage.PowerUsageAdvanced;
+import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.GestureNavigationSettingsFragment;
import com.android.settings.gestures.SystemNavigationGestureSettings;
import com.android.settings.location.LocationSettings;
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java
index 03b3a479895..a75663b2f64 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppBatteryPreferenceControllerTest.java
@@ -40,8 +40,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.SettingsActivity;
-import com.android.settings.fuelgauge.BatteryDiffEntry;
import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 9dc94ac61bd..079e8f9c0ab 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -52,6 +52,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
+import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowActivityManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index d4c4406bd1f..66a5e7f8bd0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryAppListPreferenceControllerTest.java
similarity index 95%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryAppListPreferenceControllerTest.java
index 46773c96622..da397fd791e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryAppListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryAppListPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +35,7 @@ import androidx.preference.PreferenceGroup;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -81,9 +82,9 @@ public class BatteryAppListPreferenceControllerTest {
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
- when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
+ when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
when(mFeatureFactory.powerUsageFeatureProvider.getHideApplicationSummary(mContext))
- .thenReturn(new String[] {"com.android.googlequicksearchbox"});
+ .thenReturn(new String[]{"com.android.googlequicksearchbox"});
mPreference = new PowerGaugePreference(mContext);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
similarity index 75%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
index 1d74491a0e1..75b7fe143e9 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,22 +14,20 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
-import android.content.Context;
import android.content.ContentValues;
+import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -37,15 +35,14 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.LocaleList;
import android.text.format.DateUtils;
-import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
-import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -58,11 +55,10 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
-import java.util.List;
import java.util.Map;
@RunWith(RobolectricTestRunner.class)
@@ -70,20 +66,24 @@ public final class BatteryChartPreferenceControllerTest {
private static final String PREF_KEY = "pref_key";
private static final String PREF_SUMMARY = "fake preference summary";
private static final int DESIRED_HISTORY_SIZE =
- BatteryChartPreferenceController.DESIRED_HISTORY_SIZE;
+ BatteryChartPreferenceController.DESIRED_HISTORY_SIZE;
- @Mock private InstrumentedPreferenceFragment mFragment;
- @Mock private SettingsActivity mSettingsActivity;
- @Mock private PreferenceGroup mAppListGroup;
- @Mock private PackageManager mPackageManager;
- @Mock private Drawable mDrawable;
- @Mock private BatteryHistEntry mBatteryHistEntry;
- @Mock private BatteryChartView mBatteryChartView;
- @Mock private PowerGaugePreference mPowerGaugePreference;
- @Mock private ExpandDividerPreference mExpandDividerPreference;
- @Mock private BatteryUtils mBatteryUtils;
- @Mock private Configuration mConfiguration;
- @Mock private Resources mResources;
+ @Mock
+ private InstrumentedPreferenceFragment mFragment;
+ @Mock
+ private SettingsActivity mSettingsActivity;
+ @Mock
+ private PreferenceGroup mAppListGroup;
+ @Mock
+ private Drawable mDrawable;
+ @Mock
+ private BatteryHistEntry mBatteryHistEntry;
+ @Mock
+ private BatteryChartView mBatteryChartView;
+ @Mock
+ private PowerGaugePreference mPowerGaugePreference;
+ @Mock
+ private BatteryUtils mBatteryUtils;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@@ -102,29 +102,29 @@ public final class BatteryChartPreferenceControllerTest {
final Resources resources = spy(mContext.getResources());
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
doReturn(resources).when(mContext).getResources();
- doReturn(new String[] {"com.android.googlequicksearchbox"})
- .when(mFeatureFactory.powerUsageFeatureProvider)
- .getHideApplicationSummary(mContext);
- doReturn(new String[] {"com.android.gms.persistent"})
- .when(mFeatureFactory.powerUsageFeatureProvider)
- .getHideApplicationEntries(mContext);
+ doReturn(new String[]{"com.android.googlequicksearchbox"})
+ .when(mFeatureFactory.powerUsageFeatureProvider)
+ .getHideApplicationSummary(mContext);
+ doReturn(new String[]{"com.android.gms.persistent"})
+ .when(mFeatureFactory.powerUsageFeatureProvider)
+ .getHideApplicationEntries(mContext);
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mPrefContext = mContext;
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
mBatteryChartPreferenceController.mBatteryChartView = mBatteryChartView;
mBatteryDiffEntry = new BatteryDiffEntry(
- mContext,
- /*foregroundUsageTimeInMs=*/ 1,
- /*backgroundUsageTimeInMs=*/ 2,
- /*consumePower=*/ 3,
- mBatteryHistEntry);
+ mContext,
+ /*foregroundUsageTimeInMs=*/ 1,
+ /*backgroundUsageTimeInMs=*/ 2,
+ /*consumePower=*/ 3,
+ mBatteryHistEntry);
mBatteryDiffEntry = spy(mBatteryDiffEntry);
// Adds fake testing data.
BatteryDiffEntry.sResourceCache.put(
- "fakeBatteryDiffEntryKey",
- new BatteryEntry.NameAndIcon("fakeName", /*icon=*/ null, /*iconId=*/ 1));
+ "fakeBatteryDiffEntryKey",
+ new BatteryEntry.NameAndIcon("fakeName", /*icon=*/ null, /*iconId=*/ 1));
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ createBatteryHistoryMap());
}
@Test
@@ -151,7 +151,7 @@ public final class BatteryChartPreferenceControllerTest {
public void testOnDestroy_clearPreferenceCache() {
// Ensures the testing environment is correct.
mBatteryChartPreferenceController.mPreferenceCache.put(
- PREF_KEY, mPowerGaugePreference);
+ PREF_KEY, mPowerGaugePreference);
assertThat(mBatteryChartPreferenceController.mPreferenceCache).hasSize(1);
mBatteryChartPreferenceController.onDestroy();
@@ -168,19 +168,19 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void testSetBatteryHistoryMap_createExpectedKeysAndLevels() {
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ createBatteryHistoryMap());
// Verifies the created battery keys array.
for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(index + 1);
+ // These values is are calculated by hand from createBatteryHistoryMap().
+ .isEqualTo(index + 1);
}
// Verifies the created battery levels array.
for (int index = 0; index < 13; index++) {
assertThat(mBatteryChartPreferenceController.mBatteryHistoryLevels[index])
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(100 - index * 2);
+ // These values is are calculated by hand from createBatteryHistoryMap().
+ .isEqualTo(100 - index * 2);
}
assertThat(mBatteryChartPreferenceController.mBatteryIndexedMap).hasSize(13);
}
@@ -188,19 +188,19 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void testSetBatteryHistoryMap_largeSize_createExpectedKeysAndLevels() {
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ createBatteryHistoryMap());
// Verifies the created battery keys array.
for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
- assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(index + 1);
+ assertThat(mBatteryChartPreferenceController.mBatteryHistoryKeys[index])
+ // These values is are calculated by hand from createBatteryHistoryMap().
+ .isEqualTo(index + 1);
}
// Verifies the created battery levels array.
for (int index = 0; index < 13; index++) {
- assertThat(mBatteryChartPreferenceController.mBatteryHistoryLevels[index])
- // These values is are calculated by hand from createBatteryHistoryMap().
- .isEqualTo(100 - index * 2);
+ assertThat(mBatteryChartPreferenceController.mBatteryHistoryLevels[index])
+ // These values is are calculated by hand from createBatteryHistoryMap().
+ .isEqualTo(100 - index * 2);
}
assertThat(mBatteryChartPreferenceController.mBatteryIndexedMap).hasSize(13);
}
@@ -209,14 +209,14 @@ public final class BatteryChartPreferenceControllerTest {
public void testRefreshUi_batteryIndexedMapIsNull_ignoreRefresh() {
mBatteryChartPreferenceController.setBatteryHistoryMap(null);
assertThat(mBatteryChartPreferenceController.refreshUi(
- /*trapezoidIndex=*/ 1, /*isForce=*/ false)).isFalse();
+ /*trapezoidIndex=*/ 1, /*isForce=*/ false)).isFalse();
}
@Test
public void testRefreshUi_batteryChartViewIsNull_ignoreRefresh() {
mBatteryChartPreferenceController.mBatteryChartView = null;
assertThat(mBatteryChartPreferenceController.refreshUi(
- /*trapezoidIndex=*/ 1, /*isForce=*/ false)).isFalse();
+ /*trapezoidIndex=*/ 1, /*isForce=*/ false)).isFalse();
}
@Test
@@ -224,7 +224,7 @@ public final class BatteryChartPreferenceControllerTest {
final int trapezoidIndex = 1;
mBatteryChartPreferenceController.mTrapezoidIndex = trapezoidIndex;
assertThat(mBatteryChartPreferenceController.refreshUi(
- trapezoidIndex, /*isForce=*/ false)).isFalse();
+ trapezoidIndex, /*isForce=*/ false)).isFalse();
}
@Test
@@ -232,18 +232,18 @@ public final class BatteryChartPreferenceControllerTest {
final int trapezoidIndex = 1;
mBatteryChartPreferenceController.mTrapezoidIndex = trapezoidIndex;
assertThat(mBatteryChartPreferenceController.refreshUi(
- trapezoidIndex, /*isForce=*/ true)).isTrue();
+ trapezoidIndex, /*isForce=*/ true)).isTrue();
}
@Test
public void testForceRefreshUi_updateTrapezoidIndexIntoSelectAll() {
mBatteryChartPreferenceController.mTrapezoidIndex =
- BatteryChartView.SELECTED_INDEX_INVALID;
+ BatteryChartView.SELECTED_INDEX_INVALID;
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ createBatteryHistoryMap());
assertThat(mBatteryChartPreferenceController.mTrapezoidIndex)
- .isEqualTo(BatteryChartView.SELECTED_INDEX_ALL);
+ .isEqualTo(BatteryChartView.SELECTED_INDEX_ALL);
}
@Test
@@ -252,7 +252,7 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(0).when(mAppListGroup).getPreferenceCount();
mBatteryChartPreferenceController.refreshUi(
- trapezoidIndex, /*isForce=*/ true);
+ trapezoidIndex, /*isForce=*/ true);
verify(mAppListGroup, never()).removeAll();
}
@@ -266,17 +266,17 @@ public final class BatteryChartPreferenceControllerTest {
assertThat(mBatteryChartPreferenceController.mPreferenceCache).isEmpty();
mBatteryChartPreferenceController.refreshUi(
- trapezoidIndex, /*isForce=*/ true);
+ trapezoidIndex, /*isForce=*/ true);
assertThat(mBatteryChartPreferenceController.mPreferenceCache.get(PREF_KEY))
- .isEqualTo(mPowerGaugePreference);
+ .isEqualTo(mPowerGaugePreference);
verify(mAppListGroup).removeAll();
}
@Test
public void testAddPreferenceToScreen_emptyContent_ignoreAddPreference() {
mBatteryChartPreferenceController.addPreferenceToScreen(
- new ArrayList());
+ new ArrayList());
verify(mAppListGroup, never()).addPreference(any());
}
@@ -291,12 +291,12 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(false).when(mBatteryDiffEntry).validForRestriction();
mBatteryChartPreferenceController.addPreferenceToScreen(
- Arrays.asList(mBatteryDiffEntry));
+ Arrays.asList(mBatteryDiffEntry));
// Verifies the preference cache.
final PowerGaugePreference pref =
- (PowerGaugePreference) mBatteryChartPreferenceController.mPreferenceCache
- .get(PREF_KEY);
+ (PowerGaugePreference) mBatteryChartPreferenceController.mPreferenceCache
+ .get(PREF_KEY);
assertThat(pref).isNotNull();
// Verifies the added preference configuration.
verify(mAppListGroup).addPreference(pref);
@@ -319,7 +319,7 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(mPowerGaugePreference).when(mAppListGroup).findPreference(PREF_KEY);
mBatteryChartPreferenceController.addPreferenceToScreen(
- Arrays.asList(mBatteryDiffEntry));
+ Arrays.asList(mBatteryDiffEntry));
verify(mAppListGroup, never()).addPreference(any());
}
@@ -327,12 +327,12 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void testHandlePreferenceTreeiClick_notPowerGaugePreference_returnFalse() {
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(mAppListGroup))
- .isFalse();
+ .isFalse();
verify(mMetricsFeatureProvider, never())
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM);
+ .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM);
verify(mMetricsFeatureProvider, never())
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM);
+ .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM);
}
@Test
@@ -341,7 +341,7 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(
- mPowerGaugePreference)).isTrue();
+ mPowerGaugePreference)).isTrue();
verify(mMetricsFeatureProvider)
.action(
SettingsEnums.OPEN_BATTERY_USAGE,
@@ -358,7 +358,7 @@ public final class BatteryChartPreferenceControllerTest {
doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(
- mPowerGaugePreference)).isTrue();
+ mPowerGaugePreference)).isTrue();
verify(mMetricsFeatureProvider)
.action(
SettingsEnums.OPEN_BATTERY_USAGE,
@@ -374,9 +374,9 @@ public final class BatteryChartPreferenceControllerTest {
pref.setSummary(PREF_SUMMARY);
mBatteryChartPreferenceController.setPreferenceSummary(
- pref, createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ 0,
- /*backgroundUsageTimeInMs=*/ 0));
+ pref, createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ 0,
+ /*backgroundUsageTimeInMs=*/ 0));
assertThat(pref.getSummary()).isNull();
}
@@ -386,9 +386,9 @@ public final class BatteryChartPreferenceControllerTest {
pref.setSummary(PREF_SUMMARY);
mBatteryChartPreferenceController.setPreferenceSummary(
- pref, createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ 0,
- /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
+ pref, createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ 0,
+ /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
assertThat(pref.getSummary()).isEqualTo("Background: 1 min");
}
@@ -398,9 +398,9 @@ public final class BatteryChartPreferenceControllerTest {
pref.setSummary(PREF_SUMMARY);
mBatteryChartPreferenceController.setPreferenceSummary(
- pref, createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ 100,
- /*backgroundUsageTimeInMs=*/ 200));
+ pref, createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ 100,
+ /*backgroundUsageTimeInMs=*/ 200));
assertThat(pref.getSummary()).isEqualTo("Total: less than a min");
}
@@ -410,11 +410,11 @@ public final class BatteryChartPreferenceControllerTest {
pref.setSummary(PREF_SUMMARY);
mBatteryChartPreferenceController.setPreferenceSummary(
- pref, createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
- /*backgroundUsageTimeInMs=*/ 200));
+ pref, createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
+ /*backgroundUsageTimeInMs=*/ 200));
assertThat(pref.getSummary())
- .isEqualTo("Total: 1 min\nBackground: less than a min");
+ .isEqualTo("Total: 1 min\nBackground: less than a min");
}
@Test
@@ -423,9 +423,9 @@ public final class BatteryChartPreferenceControllerTest {
pref.setSummary(PREF_SUMMARY);
mBatteryChartPreferenceController.setPreferenceSummary(
- pref, createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
- /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
+ pref, createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
+ /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
assertThat(pref.getSummary()).isEqualTo("Total: 2 min\nBackground: 1 min");
}
@@ -434,11 +434,11 @@ public final class BatteryChartPreferenceControllerTest {
final PowerGaugePreference pref = new PowerGaugePreference(mContext);
pref.setSummary(PREF_SUMMARY);
final BatteryDiffEntry batteryDiffEntry =
- spy(createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
- /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
+ spy(createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
+ /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS));
doReturn("com.android.googlequicksearchbox").when(batteryDiffEntry)
- .getPackageName();
+ .getPackageName();
mBatteryChartPreferenceController.setPreferenceSummary(pref, batteryDiffEntry);
assertThat(pref.getSummary()).isNull();
@@ -447,28 +447,28 @@ public final class BatteryChartPreferenceControllerTest {
@Test
public void testValidateUsageTime_returnTrueIfBatteryDiffEntryIsValid() {
assertThat(BatteryChartPreferenceController.validateUsageTime(
- createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
- /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS)))
- .isTrue();
+ createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS,
+ /*backgroundUsageTimeInMs=*/ DateUtils.MINUTE_IN_MILLIS)))
+ .isTrue();
}
@Test
public void testValidateUsageTime_foregroundTimeExceedThreshold_returnFalse() {
assertThat(BatteryChartPreferenceController.validateUsageTime(
- createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ DateUtils.HOUR_IN_MILLIS * 3,
- /*backgroundUsageTimeInMs=*/ 0)))
- .isFalse();
+ createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ DateUtils.HOUR_IN_MILLIS * 3,
+ /*backgroundUsageTimeInMs=*/ 0)))
+ .isFalse();
}
@Test
public void testValidateUsageTime_backgroundTimeExceedThreshold_returnFalse() {
assertThat(BatteryChartPreferenceController.validateUsageTime(
- createBatteryDiffEntry(
- /*foregroundUsageTimeInMs=*/ 0,
- /*backgroundUsageTimeInMs=*/ DateUtils.HOUR_IN_MILLIS * 3)))
- .isFalse();
+ createBatteryDiffEntry(
+ /*foregroundUsageTimeInMs=*/ 0,
+ /*backgroundUsageTimeInMs=*/ DateUtils.HOUR_IN_MILLIS * 3)))
+ .isFalse();
}
@Test
@@ -486,10 +486,10 @@ public final class BatteryChartPreferenceControllerTest {
// Verifies the added preference.
assertThat(captor.getValue().getKey()).isEqualTo(PREF_KEY);
verify(mMetricsFeatureProvider)
- .action(
- mContext,
- SettingsEnums.ACTION_BATTERY_USAGE_EXPAND_ITEM,
- true /*isExpanded*/);
+ .action(
+ mContext,
+ SettingsEnums.ACTION_BATTERY_USAGE_EXPAND_ITEM,
+ true /*isExpanded*/);
}
@Test
@@ -506,10 +506,10 @@ public final class BatteryChartPreferenceControllerTest {
verify(mAppListGroup).removePreference(mPowerGaugePreference);
assertThat(mBatteryChartPreferenceController.mPreferenceCache).hasSize(1);
verify(mMetricsFeatureProvider)
- .action(
- mContext,
- SettingsEnums.ACTION_BATTERY_USAGE_EXPAND_ITEM,
- false /*isExpanded*/);
+ .action(
+ mContext,
+ SettingsEnums.ACTION_BATTERY_USAGE_EXPAND_ITEM,
+ false /*isExpanded*/);
}
@Test
@@ -517,16 +517,16 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController.onSelect(1 /*slot index*/);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
+ .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT);
}
@Test
public void testOnSelect_selectAll_logMetric() {
mBatteryChartPreferenceController.onSelect(
- BatteryChartView.SELECTED_INDEX_ALL /*slot index*/);
+ BatteryChartView.SELECTED_INDEX_ALL /*slot index*/);
verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL);
+ .action(mContext, SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL);
}
@Test
@@ -534,9 +534,9 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController = createController();
setUpBatteryHistoryKeys();
mBatteryChartPreferenceController.mAppListPrefGroup =
- spy(new PreferenceCategory(mContext));
+ spy(new PreferenceCategory(mContext));
mBatteryChartPreferenceController.mExpandDividerPreference =
- spy(new ExpandDividerPreference(mContext));
+ spy(new ExpandDividerPreference(mContext));
// Simulates select the first slot.
mBatteryChartPreferenceController.mTrapezoidIndex = 0;
@@ -545,12 +545,12 @@ public final class BatteryChartPreferenceControllerTest {
ArgumentCaptor captor = ArgumentCaptor.forClass(String.class);
// Verifies the title in the preference group.
verify(mBatteryChartPreferenceController.mAppListPrefGroup)
- .setTitle(captor.capture());
+ .setTitle(captor.capture());
assertThat(captor.getValue()).isNotEqualTo("App usage for past 24 hr");
// Verifies the title in the expandable divider.
captor = ArgumentCaptor.forClass(String.class);
verify(mBatteryChartPreferenceController.mExpandDividerPreference)
- .setTitle(captor.capture());
+ .setTitle(captor.capture());
assertThat(captor.getValue()).isNotEqualTo("System usage for past 24 hr");
}
@@ -558,27 +558,27 @@ public final class BatteryChartPreferenceControllerTest {
public void testRefreshCategoryTitle_setLast24HrIntoBothTitleTextView() {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mAppListPrefGroup =
- spy(new PreferenceCategory(mContext));
+ spy(new PreferenceCategory(mContext));
mBatteryChartPreferenceController.mExpandDividerPreference =
- spy(new ExpandDividerPreference(mContext));
+ spy(new ExpandDividerPreference(mContext));
// Simulates select all condition.
mBatteryChartPreferenceController.mTrapezoidIndex =
- BatteryChartView.SELECTED_INDEX_ALL;
+ BatteryChartView.SELECTED_INDEX_ALL;
mBatteryChartPreferenceController.refreshCategoryTitle();
ArgumentCaptor captor = ArgumentCaptor.forClass(String.class);
// Verifies the title in the preference group.
verify(mBatteryChartPreferenceController.mAppListPrefGroup)
- .setTitle(captor.capture());
+ .setTitle(captor.capture());
assertThat(captor.getValue())
- .isEqualTo("App usage for past 24 hr");
+ .isEqualTo("App usage for past 24 hr");
// Verifies the title in the expandable divider.
captor = ArgumentCaptor.forClass(String.class);
verify(mBatteryChartPreferenceController.mExpandDividerPreference)
- .setTitle(captor.capture());
+ .setTitle(captor.capture());
assertThat(captor.getValue())
- .isEqualTo("System usage for past 24 hr");
+ .isEqualTo("System usage for past 24 hr");
}
@Test
@@ -586,37 +586,37 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mBatteryHistoryKeys = null;
mBatteryChartPreferenceController.mBatteryChartView =
- spy(new BatteryChartView(mContext));
+ spy(new BatteryChartView(mContext));
mBatteryChartPreferenceController.setTimestampLabel();
verify(mBatteryChartPreferenceController.mBatteryChartView, never())
- .setLatestTimestamp(anyLong());
+ .setLatestTimestamp(anyLong());
}
@Test
public void testSetTimestampLabel_setExpectedTimestampData() {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mBatteryChartView =
- spy(new BatteryChartView(mContext));
+ spy(new BatteryChartView(mContext));
setUpBatteryHistoryKeys();
mBatteryChartPreferenceController.setTimestampLabel();
verify(mBatteryChartPreferenceController.mBatteryChartView)
- .setLatestTimestamp(1619247636826L);
+ .setLatestTimestamp(1619247636826L);
}
@Test
public void testSetTimestampLabel_withoutValidTimestamp_setExpectedTimestampData() {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mBatteryChartView =
- spy(new BatteryChartView(mContext));
- mBatteryChartPreferenceController.mBatteryHistoryKeys = new long[] {0L};
+ spy(new BatteryChartView(mContext));
+ mBatteryChartPreferenceController.mBatteryHistoryKeys = new long[]{0L};
mBatteryChartPreferenceController.setTimestampLabel();
verify(mBatteryChartPreferenceController.mBatteryChartView)
- .setLatestTimestamp(anyLong());
+ .setLatestTimestamp(anyLong());
}
@Test
@@ -633,10 +633,10 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController.onCreate(bundle);
mBatteryChartPreferenceController.setBatteryHistoryMap(
- createBatteryHistoryMap());
+ createBatteryHistoryMap());
assertThat(mBatteryChartPreferenceController.mTrapezoidIndex)
- .isEqualTo(expectedIndex);
+ .isEqualTo(expectedIndex);
assertThat(mBatteryChartPreferenceController.mIsExpanded).isTrue();
}
@@ -644,24 +644,24 @@ public final class BatteryChartPreferenceControllerTest {
public void testIsValidToShowSummary_returnExpectedResult() {
assertThat(mBatteryChartPreferenceController
.isValidToShowSummary("com.google.android.apps.scone"))
- .isTrue();
+ .isTrue();
// Verifies the item which is defined in the array list.
assertThat(mBatteryChartPreferenceController
.isValidToShowSummary("com.android.googlequicksearchbox"))
- .isFalse();
+ .isFalse();
}
@Test
public void testIsValidToShowEntry_returnExpectedResult() {
assertThat(mBatteryChartPreferenceController
.isValidToShowEntry("com.google.android.apps.scone"))
- .isTrue();
+ .isTrue();
// Verifies the items which are defined in the array list.
assertThat(mBatteryChartPreferenceController
.isValidToShowEntry("com.android.gms.persistent"))
- .isFalse();
+ .isFalse();
}
private static Map> createBatteryHistoryMap() {
@@ -680,22 +680,22 @@ public final class BatteryChartPreferenceControllerTest {
private BatteryDiffEntry createBatteryDiffEntry(
long foregroundUsageTimeInMs, long backgroundUsageTimeInMs) {
return new BatteryDiffEntry(
- mContext, foregroundUsageTimeInMs, backgroundUsageTimeInMs,
- /*consumePower=*/ 0, mBatteryHistEntry);
+ mContext, foregroundUsageTimeInMs, backgroundUsageTimeInMs,
+ /*consumePower=*/ 0, mBatteryHistEntry);
}
private void setUpBatteryHistoryKeys() {
mBatteryChartPreferenceController.mBatteryHistoryKeys =
- new long[] {1619196786769L, 0L, 1619247636826L};
+ new long[]{1619196786769L, 0L, 1619247636826L};
ConvertUtils.utcToLocalTimeHour(
- mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
+ mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
}
private BatteryChartPreferenceController createController() {
final BatteryChartPreferenceController controller =
- new BatteryChartPreferenceController(
- mContext, "app_list", /*lifecycle=*/ null,
- mSettingsActivity, mFragment);
+ new BatteryChartPreferenceController(
+ mContext, "app_list", /*lifecycle=*/ null,
+ mSettingsActivity, mFragment);
controller.mPrefContext = mContext;
return controller;
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewTest.java
similarity index 72%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewTest.java
index 0b75e798423..a2d8ca95c07 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewTest.java
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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
@@ -11,14 +12,11 @@
* 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;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -30,6 +28,7 @@ import android.content.Context;
import android.os.LocaleList;
import android.view.accessibility.AccessibilityManager;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -40,8 +39,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Locale;
@RunWith(RobolectricTestRunner.class)
@@ -52,8 +51,10 @@ public final class BatteryChartViewTest {
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
- @Mock private AccessibilityServiceInfo mockAccessibilityServiceInfo;
- @Mock private AccessibilityManager mockAccessibilityManager;
+ @Mock
+ private AccessibilityServiceInfo mMockAccessibilityServiceInfo;
+ @Mock
+ private AccessibilityManager mMockAccessibilityManager;
@Before
public void setUp() {
@@ -62,64 +63,64 @@ public final class BatteryChartViewTest {
mPowerUsageFeatureProvider = mFeatureFactory.powerUsageFeatureProvider;
mContext = spy(RuntimeEnvironment.application);
mContext.getResources().getConfiguration().setLocales(
- new LocaleList(new Locale("en_US")));
+ new LocaleList(new Locale("en_US")));
mBatteryChartView = new BatteryChartView(mContext);
- doReturn(mockAccessibilityManager).when(mContext)
- .getSystemService(AccessibilityManager.class);
- doReturn("TalkBackService").when(mockAccessibilityServiceInfo).getId();
- doReturn(Arrays.asList(mockAccessibilityServiceInfo))
- .when(mockAccessibilityManager)
- .getEnabledAccessibilityServiceList(anyInt());
+ doReturn(mMockAccessibilityManager).when(mContext)
+ .getSystemService(AccessibilityManager.class);
+ doReturn("TalkBackService").when(mMockAccessibilityServiceInfo).getId();
+ doReturn(Arrays.asList(mMockAccessibilityServiceInfo))
+ .when(mMockAccessibilityManager)
+ .getEnabledAccessibilityServiceList(anyInt());
}
@Test
public void testIsAccessibilityEnabled_disable_returnFalse() {
- doReturn(false).when(mockAccessibilityManager).isEnabled();
+ doReturn(false).when(mMockAccessibilityManager).isEnabled();
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse();
}
@Test
public void testIsAccessibilityEnabled_emptyInfo_returnFalse() {
- doReturn(true).when(mockAccessibilityManager).isEnabled();
+ doReturn(true).when(mMockAccessibilityManager).isEnabled();
doReturn(new ArrayList())
- .when(mockAccessibilityManager)
- .getEnabledAccessibilityServiceList(anyInt());
+ .when(mMockAccessibilityManager)
+ .getEnabledAccessibilityServiceList(anyInt());
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse();
}
@Test
public void testIsAccessibilityEnabled_validServiceId_returnTrue() {
- doReturn(true).when(mockAccessibilityManager).isEnabled();
+ doReturn(true).when(mMockAccessibilityManager).isEnabled();
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isTrue();
}
@Test
public void testSetSelectedIndex_invokesCallback() {
- final int selectedIndex[] = new int[1];
+ final int[] selectedIndex = new int[1];
final int expectedIndex = 2;
mBatteryChartView.mSelectedIndex = 1;
mBatteryChartView.setOnSelectListener(
- trapezoidIndex -> {
- selectedIndex[0] = trapezoidIndex;
- });
+ trapezoidIndex -> {
+ selectedIndex[0] = trapezoidIndex;
+ });
mBatteryChartView.setSelectedIndex(expectedIndex);
assertThat(mBatteryChartView.mSelectedIndex)
- .isEqualTo(expectedIndex);
+ .isEqualTo(expectedIndex);
assertThat(selectedIndex[0]).isEqualTo(expectedIndex);
}
@Test
public void testSetSelectedIndex_sameIndex_notInvokesCallback() {
- final int selectedIndex[] = new int[1];
+ final int[] selectedIndex = new int[1];
final int expectedIndex = 1;
mBatteryChartView.mSelectedIndex = expectedIndex;
mBatteryChartView.setOnSelectListener(
- trapezoidIndex -> {
- selectedIndex[0] = trapezoidIndex;
- });
+ trapezoidIndex -> {
+ selectedIndex[0] = trapezoidIndex;
+ });
mBatteryChartView.setSelectedIndex(expectedIndex);
@@ -130,7 +131,7 @@ public final class BatteryChartViewTest {
public void testClickable_isChartGraphSlotsEnabledIsFalse_notClickable() {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
- .thenReturn(false);
+ .thenReturn(false);
mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isFalse();
@@ -141,8 +142,8 @@ public final class BatteryChartViewTest {
public void testClickable_accessibilityIsDisabled_clickable() {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
- .thenReturn(true);
- doReturn(false).when(mockAccessibilityManager).isEnabled();
+ .thenReturn(true);
+ doReturn(false).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isTrue();
@@ -153,11 +154,11 @@ public final class BatteryChartViewTest {
public void testClickable_accessibilityIsEnabledWithoutValidId_clickable() {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
- .thenReturn(true);
- doReturn(true).when(mockAccessibilityManager).isEnabled();
+ .thenReturn(true);
+ doReturn(true).when(mMockAccessibilityManager).isEnabled();
doReturn(new ArrayList())
- .when(mockAccessibilityManager)
- .getEnabledAccessibilityServiceList(anyInt());
+ .when(mMockAccessibilityManager)
+ .getEnabledAccessibilityServiceList(anyInt());
mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isTrue();
@@ -168,8 +169,8 @@ public final class BatteryChartViewTest {
public void testClickable_accessibilityIsEnabledWithValidId_notClickable() {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
- .thenReturn(true);
- doReturn(true).when(mockAccessibilityManager).isEnabled();
+ .thenReturn(true);
+ doReturn(true).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isFalse();
@@ -186,13 +187,13 @@ public final class BatteryChartViewTest {
mBatteryChartView.setLevels(levels);
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
- .thenReturn(true);
- doReturn(true).when(mockAccessibilityManager).isEnabled();
+ .thenReturn(true);
+ doReturn(true).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
// Ensures the testing environment is correct.
assertThat(mBatteryChartView.isClickable()).isFalse();
// Turns off accessibility service.
- doReturn(false).when(mockAccessibilityManager).isEnabled();
+ doReturn(false).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
@@ -202,23 +203,23 @@ public final class BatteryChartViewTest {
@Test
public void testOnAttachedToWindow_addAccessibilityStateChangeListener() {
mBatteryChartView.onAttachedToWindow();
- verify(mockAccessibilityManager)
- .addAccessibilityStateChangeListener(mBatteryChartView);
+ verify(mMockAccessibilityManager)
+ .addAccessibilityStateChangeListener(mBatteryChartView);
}
@Test
public void testOnDetachedFromWindow_removeAccessibilityStateChangeListener() {
mBatteryChartView.onAttachedToWindow();
mBatteryChartView.mHandler.postDelayed(
- mBatteryChartView.mUpdateClickableStateRun, 1000);
+ mBatteryChartView.mUpdateClickableStateRun, 1000);
mBatteryChartView.onDetachedFromWindow();
- verify(mockAccessibilityManager)
- .removeAccessibilityStateChangeListener(mBatteryChartView);
+ verify(mMockAccessibilityManager)
+ .removeAccessibilityStateChangeListener(mBatteryChartView);
assertThat(mBatteryChartView.mHandler.hasCallbacks(
mBatteryChartView.mUpdateClickableStateRun))
- .isFalse();
+ .isFalse();
}
@Test
@@ -227,8 +228,8 @@ public final class BatteryChartViewTest {
mBatteryChartView.onAccessibilityStateChanged(/*enabled=*/ true);
verify(mBatteryChartView.mHandler)
- .removeCallbacks(mBatteryChartView.mUpdateClickableStateRun);
+ .removeCallbacks(mBatteryChartView.mUpdateClickableStateRun);
verify(mBatteryChartView.mHandler)
- .postDelayed(mBatteryChartView.mUpdateClickableStateRun, 500L);
+ .postDelayed(mBatteryChartView.mUpdateClickableStateRun, 500L);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java
similarity index 68%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java
index 6ea13901eef..bb19b5a53dc 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryDiffEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +35,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryUtils;
import org.junit.Before;
import org.junit.Test;
@@ -59,15 +60,24 @@ public final class BatteryDiffEntryTest {
private Context mContext;
- @Mock private ApplicationInfo mockAppInfo;
- @Mock private PackageManager mockPackageManager;
- @Mock private UserManager mockUserManager;
- @Mock private Drawable mockDrawable;
- @Mock private Drawable mockDrawable2;
- @Mock private Drawable mockBadgedDrawable;
- @Mock private BatteryHistEntry mBatteryHistEntry;
- @Mock private PackageInfo mockPackageInfo;
- @Mock private ConstantState mockConstantState;
+ @Mock
+ private ApplicationInfo mMockAppInfo;
+ @Mock
+ private PackageManager mMockPackageManager;
+ @Mock
+ private UserManager mMockUserManager;
+ @Mock
+ private Drawable mMockDrawable;
+ @Mock
+ private Drawable mMockDrawable2;
+ @Mock
+ private Drawable mMockBadgedDrawable;
+ @Mock
+ private BatteryHistEntry mBatteryHistEntry;
+ @Mock
+ private PackageInfo mMockPackageInfo;
+ @Mock
+ private ConstantState mMockConstantState;
@Before
public void setUp() {
@@ -75,20 +85,20 @@ public final class BatteryDiffEntryTest {
ShadowUserHandle.reset();
mContext = spy(RuntimeEnvironment.application);
doReturn(mContext).when(mContext).getApplicationContext();
- doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
- doReturn(mockPackageManager).when(mContext).getPackageManager();
+ doReturn(mMockUserManager).when(mContext).getSystemService(UserManager.class);
+ doReturn(mMockPackageManager).when(mContext).getPackageManager();
BatteryDiffEntry.clearCache();
}
@Test
public void testSetTotalConsumePower_returnExpectedResult() {
final BatteryDiffEntry entry =
- new BatteryDiffEntry(
- mContext,
- /*foregroundUsageTimeInMs=*/ 10001L,
- /*backgroundUsageTimeInMs=*/ 20002L,
- /*consumePower=*/ 22.0,
- /*batteryHistEntry=*/ null);
+ new BatteryDiffEntry(
+ mContext,
+ /*foregroundUsageTimeInMs=*/ 10001L,
+ /*backgroundUsageTimeInMs=*/ 20002L,
+ /*consumePower=*/ 22.0,
+ /*batteryHistEntry=*/ null);
entry.setTotalConsumePower(100.0);
assertThat(entry.getPercentOfTotal()).isEqualTo(22.0);
@@ -97,12 +107,12 @@ public final class BatteryDiffEntryTest {
@Test
public void testSetTotalConsumePower_setZeroValue_returnsZeroValue() {
final BatteryDiffEntry entry =
- new BatteryDiffEntry(
- mContext,
- /*foregroundUsageTimeInMs=*/ 10001L,
- /*backgroundUsageTimeInMs=*/ 20002L,
- /*consumePower=*/ 22.0,
- /*batteryHistEntry=*/ null);
+ new BatteryDiffEntry(
+ mContext,
+ /*foregroundUsageTimeInMs=*/ 10001L,
+ /*backgroundUsageTimeInMs=*/ 20002L,
+ /*consumePower=*/ 22.0,
+ /*batteryHistEntry=*/ null);
entry.setTotalConsumePower(0);
assertThat(entry.getPercentOfTotal()).isEqualTo(0);
@@ -127,9 +137,9 @@ public final class BatteryDiffEntryTest {
final String expectedName = "Ambient display";
// Generates fake testing data.
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
values.put("drainType",
- Integer.valueOf(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY));
+ Integer.valueOf(BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY));
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
@@ -139,7 +149,7 @@ public final class BatteryDiffEntryTest {
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.mName).isEqualTo(expectedName);
assertThat(nameAndIcon.mIconId).isEqualTo(R.drawable.ic_settings_aod);
// Verifies the restrictable flag in the cache.
@@ -150,10 +160,10 @@ public final class BatteryDiffEntryTest {
@Test
public void testLoadLabelAndIcon_forUserBattery_returnExpectedResult() {
final String expectedName = "Removed user";
- doReturn(null).when(mockUserManager).getUserInfo(1001);
+ doReturn(null).when(mMockUserManager).getUserInfo(1001);
// Generates fake testing data.
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_USER_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_USER_BATTERY);
values.put("userId", Integer.valueOf(1001));
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
@@ -165,7 +175,7 @@ public final class BatteryDiffEntryTest {
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.mName).isEqualTo(expectedName);
assertThat(nameAndIcon.mIconId).isEqualTo(0);
// Verifies the restrictable flag in the cache.
@@ -178,13 +188,13 @@ public final class BatteryDiffEntryTest {
final String expectedAppLabel = "fake app label";
final String fakePackageName = "com.fake.google.com";
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("uid", /*invalid uid*/ 10001);
values.put("packageName", fakePackageName);
- doReturn(mockAppInfo).when(mockPackageManager)
- .getApplicationInfo(fakePackageName, 0);
- doReturn(expectedAppLabel).when(mockPackageManager)
- .getApplicationLabel(mockAppInfo);
+ doReturn(mMockAppInfo).when(mMockPackageManager)
+ .getApplicationInfo(fakePackageName, 0);
+ doReturn(expectedAppLabel).when(mMockPackageManager)
+ .getApplicationLabel(mMockAppInfo);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
@@ -194,7 +204,7 @@ public final class BatteryDiffEntryTest {
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.mName).isEqualTo(expectedAppLabel);
// Verifies the restrictable flag in the cache.
assertThat(entry.mValidForRestriction).isFalse();
@@ -205,7 +215,7 @@ public final class BatteryDiffEntryTest {
public void testGetAppLabel_loadDataFromPreDefinedNameAndUid() {
final String expectedAppLabel = "Android OS";
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
@@ -214,7 +224,7 @@ public final class BatteryDiffEntryTest {
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.mName).isEqualTo(expectedAppLabel);
}
@@ -222,7 +232,7 @@ public final class BatteryDiffEntryTest {
public void testGetAppLabel_nullAppLabel_returnAppLabelInBatteryHistEntry() {
final String expectedAppLabel = "fake app label";
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("appLabel", expectedAppLabel);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
@@ -236,15 +246,15 @@ public final class BatteryDiffEntryTest {
@Test
public void testGetAppIcon_nonUidConsumer_returnAppIconInBatteryDiffEntry() {
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
- mockConstantState(mockDrawable);
+ mockConstantState(mMockDrawable);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
entry.mIsLoaded = true;
- entry.mAppIcon = mockDrawable;
- assertThat(entry.getAppIcon()).isEqualTo(mockDrawable);
+ entry.mAppIcon = mMockDrawable;
+ assertThat(entry.getAppIcon()).isEqualTo(mMockDrawable);
assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
}
@@ -252,38 +262,38 @@ public final class BatteryDiffEntryTest {
public void testGetAppIcon_uidConsumerForNonOwner_returnDefaultActivityIconWithBadge()
throws Exception {
ShadowUserHandle.setUid(10);
- final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable);
- mockConstantState(mockDrawable);
- mockConstantState(mockBadgedDrawable);
- doReturn(mockBadgedDrawable).when(mockUserManager)
- .getBadgedIconForUser(eq(mockDrawable), any());
+ final BatteryDiffEntry entry = createBatteryDiffEntry(mMockDrawable);
+ mockConstantState(mMockDrawable);
+ mockConstantState(mMockBadgedDrawable);
+ doReturn(mMockBadgedDrawable).when(mMockUserManager)
+ .getBadgedIconForUser(eq(mMockDrawable), any());
entry.mAppIcon = null;
- assertThat(entry.getAppIcon()).isEqualTo(mockBadgedDrawable);
+ assertThat(entry.getAppIcon()).isEqualTo(mMockBadgedDrawable);
}
@Test
public void testGetAppIcon_uidConsumerWithNullIcon_returnDefaultActivityIcon()
throws Exception {
- final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable);
- mockConstantState(mockDrawable);
+ final BatteryDiffEntry entry = createBatteryDiffEntry(mMockDrawable);
+ mockConstantState(mMockDrawable);
entry.mAppIcon = null;
- assertThat(entry.getAppIcon()).isEqualTo(mockDrawable);
+ assertThat(entry.getAppIcon()).isEqualTo(mMockDrawable);
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry.getKey());
- assertThat(nameAndIcon.mIcon).isEqualTo(mockDrawable);
+ BatteryDiffEntry.sResourceCache.get(entry.getKey());
+ assertThat(nameAndIcon.mIcon).isEqualTo(mMockDrawable);
}
@Test
public void testClearCache_clearDataForResourcesAndFlags() {
BatteryDiffEntry.sResourceCache.put(
- "fake application key",
- new BatteryEntry.NameAndIcon("app label", null, /*iconId=*/ 0));
+ "fake application key",
+ new BatteryEntry.NameAndIcon("app label", null, /*iconId=*/ 0));
BatteryDiffEntry.sValidForRestriction.put(
- "fake application key", Boolean.valueOf(false));
+ "fake application key", Boolean.valueOf(false));
BatteryDiffEntry.clearCache();
@@ -295,83 +305,83 @@ public final class BatteryDiffEntryTest {
public void testClearCache_switchLocale_clearCacheIconAndLabel() throws Exception {
final int userId = UserHandle.getUserId(1001);
Locale.setDefault(new Locale("en_US"));
- final BatteryDiffEntry entry1 = createBatteryDiffEntry(mockDrawable);
- mockConstantState(mockDrawable);
- assertThat(entry1.getAppIcon()).isEqualTo(mockDrawable);
+ final BatteryDiffEntry entry1 = createBatteryDiffEntry(mMockDrawable);
+ mockConstantState(mMockDrawable);
+ assertThat(entry1.getAppIcon()).isEqualTo(mMockDrawable);
// Switch the locale into another one.
Locale.setDefault(new Locale("zh_TW"));
- final BatteryDiffEntry entry2 = createBatteryDiffEntry(mockDrawable2);
+ final BatteryDiffEntry entry2 = createBatteryDiffEntry(mMockDrawable2);
// We should get new drawable without caching.
- mockConstantState(mockDrawable2);
- assertThat(entry2.getAppIcon()).isEqualTo(mockDrawable2);
+ mockConstantState(mMockDrawable2);
+ assertThat(entry2.getAppIcon()).isEqualTo(mMockDrawable2);
// Verifies the cache is updated into the new drawable.
final BatteryEntry.NameAndIcon nameAndIcon =
- BatteryDiffEntry.sResourceCache.get(entry2.getKey());
- assertThat(nameAndIcon.mIcon).isEqualTo(mockDrawable2);
+ BatteryDiffEntry.sResourceCache.get(entry2.getKey());
+ assertThat(nameAndIcon.mIcon).isEqualTo(mMockDrawable2);
}
@Test
public void testIsSystemEntry_userBattery_returnTrue() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_USER_BATTERY,
- /*uid=*/ 0, /*isHidden=*/ false);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_USER_BATTERY,
+ /*uid=*/ 0, /*isHidden=*/ false);
assertThat(entry.isSystemEntry()).isTrue();
}
@Test
public void testIsSystemEntry_systemBattery_returnTrue() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY,
- /*uid=*/ 0, /*isHidden=*/ false);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY,
+ /*uid=*/ 0, /*isHidden=*/ false);
assertThat(entry.isSystemEntry()).isTrue();
}
@Test
public void testIsSystemEntry_uidBattery_returnFalse() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
- /*uid=*/ 123, /*isHidden=*/ false);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
+ /*uid=*/ 123, /*isHidden=*/ false);
assertThat(entry.isSystemEntry()).isFalse();
}
@Test
public void testIsSystemEntry_uidBatteryWithHiddenState_returnTrue() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
- /*uid=*/ 123, /*isHidden=*/ true);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
+ /*uid=*/ 123, /*isHidden=*/ true);
assertThat(entry.isSystemEntry()).isTrue();
}
@Test
public void testIsSystemEntry_uidBatteryWithSystemProcess_returnFalse() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
- /*uid=*/ 1230, /*isHidden=*/ false);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
+ /*uid=*/ 1230, /*isHidden=*/ false);
assertThat(entry.isSystemEntry()).isFalse();
}
@Test
public void testIsSystemEntry_uidBatteryWithTetheringProcess_returnTrue() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
- /*uid=*/ BatteryUtils.UID_TETHERING, /*isHidden=*/ false);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
+ /*uid=*/ BatteryUtils.UID_TETHERING, /*isHidden=*/ false);
assertThat(entry.isSystemEntry()).isTrue();
}
@Test
public void testIsSystemEntry_uidBatteryWithRemovedAppsProcess_returnTrue() {
final BatteryDiffEntry entry =
- createBatteryDiffEntry(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
- /*uid=*/ BatteryUtils.UID_REMOVED_APPS, /*isHidden=*/ false);
+ createBatteryDiffEntry(
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY,
+ /*uid=*/ BatteryUtils.UID_REMOVED_APPS, /*isHidden=*/ false);
assertThat(entry.isSystemEntry()).isTrue();
}
@@ -380,30 +390,30 @@ public final class BatteryDiffEntryTest {
final String expectedAppLabel = "fake app label";
final String fakePackageName = "com.fake.google.com";
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("uid", /*invalid uid*/ 10001);
values.put("packageName", fakePackageName);
final BatteryDiffEntry entry =
- createBatteryDiffEntry(10, new BatteryHistEntry(values));
+ createBatteryDiffEntry(10, new BatteryHistEntry(values));
entry.updateRestrictionFlagState();
// Sets false if the app entry cannot be found.
assertThat(entry.mValidForRestriction).isFalse();
- doReturn(BatteryUtils.UID_NULL).when(mockPackageManager).getPackageUid(
- entry.getPackageName(), PackageManager.GET_META_DATA);
+ doReturn(BatteryUtils.UID_NULL).when(mMockPackageManager).getPackageUid(
+ entry.getPackageName(), PackageManager.GET_META_DATA);
entry.updateRestrictionFlagState();
// Sets false if the app is invalid package name.
assertThat(entry.mValidForRestriction).isFalse();
- doReturn(1000).when(mockPackageManager).getPackageUid(
- entry.getPackageName(), PackageManager.GET_META_DATA);
+ doReturn(1000).when(mMockPackageManager).getPackageUid(
+ entry.getPackageName(), PackageManager.GET_META_DATA);
entry.updateRestrictionFlagState();
// Sets false if the app PackageInfo cannot be found.
assertThat(entry.mValidForRestriction).isFalse();
- doReturn(mockPackageInfo).when(mockPackageManager).getPackageInfo(
- eq(entry.getPackageName()), anyInt());
+ doReturn(mMockPackageInfo).when(mMockPackageManager).getPackageInfo(
+ eq(entry.getPackageName()), anyInt());
entry.updateRestrictionFlagState();
// Sets true if package is valid and PackageInfo can be found.
assertThat(entry.mValidForRestriction).isTrue();
@@ -413,10 +423,10 @@ public final class BatteryDiffEntryTest {
public void testGetPackageName_returnExpectedResult() {
final String expectedPackageName = "com.fake.google.com";
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("packageName", expectedPackageName);
final BatteryDiffEntry entry =
- createBatteryDiffEntry(10, new BatteryHistEntry(values));
+ createBatteryDiffEntry(10, new BatteryHistEntry(values));
assertThat(entry.getPackageName()).isEqualTo(expectedPackageName);
}
@@ -425,12 +435,12 @@ public final class BatteryDiffEntryTest {
public void testGetPackageName_withProcessName_returnExpectedResult() {
final String expectedPackageName = "com.fake.google.com";
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put(
- "packageName",
- expectedPackageName + ":privileged_process0");
+ "packageName",
+ expectedPackageName + ":privileged_process0");
final BatteryDiffEntry entry =
- createBatteryDiffEntry(10, new BatteryHistEntry(values));
+ createBatteryDiffEntry(10, new BatteryHistEntry(values));
assertThat(entry.getPackageName()).isEqualTo(expectedPackageName);
}
@@ -441,21 +451,21 @@ public final class BatteryDiffEntryTest {
values.put("isHidden", isHidden);
values.put("uid", uid);
return new BatteryDiffEntry(
- mContext,
- /*foregroundUsageTimeInMs=*/ 0,
- /*backgroundUsageTimeInMs=*/ 0,
- /*consumePower=*/ 0,
- new BatteryHistEntry(values));
+ mContext,
+ /*foregroundUsageTimeInMs=*/ 0,
+ /*backgroundUsageTimeInMs=*/ 0,
+ /*consumePower=*/ 0,
+ new BatteryHistEntry(values));
}
private BatteryDiffEntry createBatteryDiffEntry(
- double consumePower, BatteryHistEntry batteryHistEntry) {
+ double consumePower, BatteryHistEntry batteryHistEntry) {
final BatteryDiffEntry entry = new BatteryDiffEntry(
- mContext,
- /*foregroundUsageTimeInMs=*/ 0,
- /*backgroundUsageTimeInMs=*/ 0,
- consumePower,
- batteryHistEntry);
+ mContext,
+ /*foregroundUsageTimeInMs=*/ 0,
+ /*backgroundUsageTimeInMs=*/ 0,
+ consumePower,
+ batteryHistEntry);
entry.setTotalConsumePower(100.0);
return entry;
}
@@ -468,20 +478,20 @@ public final class BatteryDiffEntryTest {
private BatteryDiffEntry createBatteryDiffEntry(Drawable drawable) throws Exception {
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("uid", 1001);
values.put("packageName", "com.a.b.c");
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
- doReturn(drawable).when(mockPackageManager).getDefaultActivityIcon();
- doReturn(null).when(mockPackageManager).getApplicationInfo("com.a.b.c", 0);
- doReturn(new String[] {"com.a.b.c"}).when(mockPackageManager)
- .getPackagesForUid(1001);
+ doReturn(drawable).when(mMockPackageManager).getDefaultActivityIcon();
+ doReturn(null).when(mMockPackageManager).getApplicationInfo("com.a.b.c", 0);
+ doReturn(new String[]{"com.a.b.c"}).when(mMockPackageManager)
+ .getPackagesForUid(1001);
return createBatteryDiffEntry(10, batteryHistEntry);
}
private void mockConstantState(Drawable drawable) {
- doReturn(mockConstantState).when(drawable).getConstantState();
- doReturn(drawable).when(mockConstantState).newDrawable();
+ doReturn(mMockConstantState).when(drawable).getConstantState();
+ doReturn(drawable).when(mMockConstantState).newDrawable();
}
@Implements(UserHandle.class)
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java
similarity index 88%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java
index 707a658c569..5ca3aca189f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryEntryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -37,7 +37,8 @@ import android.os.UserBatteryConsumer;
import android.os.UserManager;
import com.android.settings.R;
-import com.android.settings.fuelgauge.BatteryEntry.NameAndIcon;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batteryusage.BatteryEntry.NameAndIcon;
import org.junit.Before;
import org.junit.Rule;
@@ -62,31 +63,36 @@ public class BatteryEntryTest {
private static final String HIGH_DRAIN_PACKAGE = "com.android.test.screen";
private static final String ANDROID_PACKAGE = "android";
- @Rule public MockitoRule mocks = MockitoJUnit.rule();
+ @Rule
+ public MockitoRule mocks = MockitoJUnit.rule();
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mMockContext;
private Context mContext;
- @Mock private Handler mockHandler;
- @Mock private PackageManager mockPackageManager;
- @Mock private UserManager mockUserManager;
- @Mock private UidBatteryConsumer mUidBatteryConsumer;
+ @Mock
+ private Handler mMockHandler;
+ @Mock
+ private PackageManager mMockPackageManager;
+ @Mock
+ private UserManager mMockUserManager;
+ @Mock
+ private UidBatteryConsumer mUidBatteryConsumer;
@Before
public void stubContextToReturnMockPackageManager() {
mContext = spy(RuntimeEnvironment.application);
- when(mMockContext.getPackageManager()).thenReturn(mockPackageManager);
+ when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
}
@Before
public void stubPackageManagerToReturnAppPackageAndName() throws NameNotFoundException {
- when(mockPackageManager.getApplicationInfo(anyString(), eq(0) /* no flags */))
+ when(mMockPackageManager.getApplicationInfo(anyString(), eq(0) /* no flags */))
.thenAnswer(invocation -> {
ApplicationInfo info = new ApplicationInfo();
info.packageName = invocation.getArgument(0);
return info;
});
- when(mockPackageManager.getApplicationLabel(any(ApplicationInfo.class)))
+ when(mMockPackageManager.getApplicationLabel(any(ApplicationInfo.class)))
.thenAnswer(invocation -> LABEL_PREFIX
+ ((ApplicationInfo) invocation.getArgument(0)).packageName);
}
@@ -96,7 +102,7 @@ public class BatteryEntryTest {
UidBatteryConsumer consumer = mock(UidBatteryConsumer.class);
when(consumer.getUid()).thenReturn(APP_UID);
when(consumer.getPackageWithHighestDrain()).thenReturn(highDrainPackage);
- return new BatteryEntry(mMockContext, mockHandler, mockUserManager,
+ return new BatteryEntry(mMockContext, mMockHandler, mMockUserManager,
consumer, false, APP_UID, packages, packageName);
}
@@ -111,7 +117,7 @@ public class BatteryEntryTest {
private BatteryEntry createUserBatteryConsumer(int userId) {
UserBatteryConsumer consumer = mock(UserBatteryConsumer.class);
when(consumer.getUserId()).thenReturn(userId);
- return new BatteryEntry(mMockContext, mockHandler, mockUserManager,
+ return new BatteryEntry(mMockContext, mMockHandler, mMockUserManager,
consumer, false, 0, null, null);
}
@@ -127,7 +133,7 @@ public class BatteryEntryTest {
@Test
public void batteryEntryForApp_shouldSetLabelAsPackageName_whenPackageCannotBeFound()
throws Exception {
- when(mockPackageManager.getApplicationInfo(APP_DEFAULT_PACKAGE_NAME, 0 /* no flags */))
+ when(mMockPackageManager.getApplicationInfo(APP_DEFAULT_PACKAGE_NAME, 0 /* no flags */))
.thenThrow(new NameNotFoundException());
BatteryEntry entry = createBatteryEntryForApp(null, APP_DEFAULT_PACKAGE_NAME, null);
@@ -137,7 +143,7 @@ public class BatteryEntryTest {
@Test
public void batteryEntryForApp_shouldSetHighestDrainPackage_whenPackagesCannotBeFoundForUid() {
- when(mockPackageManager.getPackagesForUid(APP_UID)).thenReturn(null);
+ when(mMockPackageManager.getPackagesForUid(APP_UID)).thenReturn(null);
BatteryEntry entry = createBatteryEntryForApp(null, null, HIGH_DRAIN_PACKAGE);
@@ -147,7 +153,7 @@ public class BatteryEntryTest {
@Test
public void batteryEntryForApp_shouldSetHighestDrainPackage_whenMultiplePackagesFoundForUid() {
BatteryEntry entry = createBatteryEntryForApp(
- new String[] {APP_DEFAULT_PACKAGE_NAME, "package2", "package3"}, null,
+ new String[]{APP_DEFAULT_PACKAGE_NAME, "package2", "package3"}, null,
HIGH_DRAIN_PACKAGE);
assertThat(entry.getLabel()).isEqualTo(LABEL_PREFIX + HIGH_DRAIN_PACKAGE);
@@ -176,8 +182,8 @@ public class BatteryEntryTest {
when(mUidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND))
.thenReturn(100L);
- final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mockHandler,
- mockUserManager, mUidBatteryConsumer, false, 0, null, null);
+ final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mMockHandler,
+ mMockUserManager, mUidBatteryConsumer, false, 0, null, null);
assertThat(entry.getTimeInForegroundMs()).isEqualTo(100L);
}
@@ -195,8 +201,8 @@ public class BatteryEntryTest {
when(mUidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND))
.thenReturn(100L);
- final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mockHandler,
- mockUserManager, mUidBatteryConsumer, false, 0, null, null);
+ final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mMockHandler,
+ mMockUserManager, mUidBatteryConsumer, false, 0, null, null);
assertThat(entry.getTimeInBackgroundMs()).isEqualTo(100L);
}
@@ -247,7 +253,7 @@ public class BatteryEntryTest {
@Test
public void getKey_UserBatteryConsumer_returnUserId() {
- doReturn(mockUserManager).when(mMockContext).getSystemService(UserManager.class);
+ doReturn(mMockUserManager).when(mMockContext).getSystemService(UserManager.class);
final BatteryEntry entry = createUserBatteryConsumer(2);
final String key = entry.getKey();
assertThat(key).isEqualTo("U|2");
@@ -256,8 +262,8 @@ public class BatteryEntryTest {
@Test
public void getNameAndIconFromUserId_nullUserInfo_returnDefaultNameAndIcon() {
final int userId = 1001;
- doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
- doReturn(null).when(mockUserManager).getUserInfo(userId);
+ doReturn(mMockUserManager).when(mContext).getSystemService(UserManager.class);
+ doReturn(null).when(mMockUserManager).getUserInfo(userId);
final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUserId(
mContext, userId);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistEntryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntryTest.java
similarity index 65%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryHistEntryTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntryTest.java
index 3acb8f3558b..553c0895c0d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistEntryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -38,7 +38,7 @@ import java.util.TimeZone;
public final class BatteryHistEntryTest {
@Mock
- private BatteryEntry mockBatteryEntry;
+ private BatteryEntry mMockBatteryEntry;
@Mock
private BatteryUsageStats mBatteryUsageStats;
@@ -50,33 +50,33 @@ public final class BatteryHistEntryTest {
@Test
public void testConstructor_contentValues_returnsExpectedResult() {
final int expectedType = 3;
- when(mockBatteryEntry.getUid()).thenReturn(1001);
- when(mockBatteryEntry.getLabel()).thenReturn("Settings");
- when(mockBatteryEntry.getDefaultPackageName())
- .thenReturn("com.google.android.settings.battery");
- when(mockBatteryEntry.isHidden()).thenReturn(true);
+ when(mMockBatteryEntry.getUid()).thenReturn(1001);
+ when(mMockBatteryEntry.getLabel()).thenReturn("Settings");
+ when(mMockBatteryEntry.getDefaultPackageName())
+ .thenReturn("com.google.android.settings.battery");
+ when(mMockBatteryEntry.isHidden()).thenReturn(true);
when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1);
- when(mockBatteryEntry.getConsumedPower()).thenReturn(1.1);
- mockBatteryEntry.mPercent = 0.3;
- when(mockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
- when(mockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
- when(mockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
- when(mockBatteryEntry.getConsumerType())
- .thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ when(mMockBatteryEntry.getConsumedPower()).thenReturn(1.1);
+ mMockBatteryEntry.mPercent = 0.3;
+ when(mMockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
+ when(mMockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
+ when(mMockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
+ when(mMockBatteryEntry.getConsumerType())
+ .thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final ContentValues values =
- ConvertUtils.convert(
- mockBatteryEntry,
- mBatteryUsageStats,
- /*batteryLevel=*/ 12,
- /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
- /*batteryHealth=*/ BatteryManager.BATTERY_HEALTH_COLD,
- /*bootTimestamp=*/ 101L,
- /*timestamp=*/ 10001L);
+ ConvertUtils.convert(
+ mMockBatteryEntry,
+ mBatteryUsageStats,
+ /*batteryLevel=*/ 12,
+ /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
+ /*batteryHealth=*/ BatteryManager.BATTERY_HEALTH_COLD,
+ /*bootTimestamp=*/ 101L,
+ /*timestamp=*/ 10001L);
assertBatteryHistEntry(
- new BatteryHistEntry(values),
- /*drainType=*/ expectedType,
- /*percentOfTotal=*/ mockBatteryEntry.mPercent);
+ new BatteryHistEntry(values),
+ /*drainType=*/ expectedType,
+ /*percentOfTotal=*/ mMockBatteryEntry.mPercent);
}
@Test
@@ -88,22 +88,22 @@ public final class BatteryHistEntryTest {
@Test
public void testConstructor_cursor_returnsExpectedResult() {
assertBatteryHistEntry(
- createBatteryHistEntry(
- /*bootTimestamp=*/ 101L,
- /*timestamp=*/ 10001L,
- /*totalPower=*/ 5.1,
- /*consumePower=*/ 1.1,
- /*foregroundUsageTimeInMs=*/ 1234L,
- /*backgroundUsageTimeInMs=*/ 5689L,
- /*batteryLevel=*/ 12),
- /*drainType=*/ 3,
- /*percentOfTotal=*/ 0.3);
+ createBatteryHistEntry(
+ /*bootTimestamp=*/ 101L,
+ /*timestamp=*/ 10001L,
+ /*totalPower=*/ 5.1,
+ /*consumePower=*/ 1.1,
+ /*foregroundUsageTimeInMs=*/ 1234L,
+ /*backgroundUsageTimeInMs=*/ 5689L,
+ /*batteryLevel=*/ 12),
+ /*drainType=*/ 3,
+ /*percentOfTotal=*/ 0.3);
}
@Test
public void testGetKey_consumerUidType_returnExpectedString() {
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put(BatteryHistEntry.KEY_UID, 3);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
@@ -113,7 +113,7 @@ public final class BatteryHistEntryTest {
@Test
public void testGetKey_consumerUserType_returnExpectedString() {
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_USER_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_USER_BATTERY);
values.put(BatteryHistEntry.KEY_USER_ID, 2);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
@@ -123,7 +123,7 @@ public final class BatteryHistEntryTest {
@Test
public void testGetKey_consumerSystemType_returnExpectedString() {
final ContentValues values = getContentValuesWithType(
- ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
values.put(BatteryHistEntry.KEY_DRAIN_TYPE, 1);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
@@ -133,31 +133,31 @@ public final class BatteryHistEntryTest {
@Test
public void testIsAppEntry_returnExpectedResult() {
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY).isAppEntry())
- .isFalse();
+ .isFalse();
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_USER_BATTERY).isAppEntry())
- .isFalse();
+ .isFalse();
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_UID_BATTERY).isAppEntry())
- .isTrue();
+ .isTrue();
}
@Test
public void testIsUserEntry_returnExpectedResult() {
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY).isUserEntry())
- .isFalse();
+ .isFalse();
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_USER_BATTERY).isUserEntry())
- .isTrue();
+ .isTrue();
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_UID_BATTERY).isUserEntry())
- .isFalse();
+ .isFalse();
}
@Test
public void testIsSystemEntry_returnExpectedResult() {
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY).isSystemEntry())
- .isTrue();
+ .isTrue();
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_USER_BATTERY).isSystemEntry())
- .isFalse();
+ .isFalse();
assertThat(createEntry(ConvertUtils.CONSUMER_TYPE_UID_BATTERY).isSystemEntry())
- .isFalse();
+ .isFalse();
}
@Test
@@ -167,39 +167,39 @@ public final class BatteryHistEntryTest {
final long lowerTimestamp = 100L;
final double ratio = 0.5;
final BatteryHistEntry lowerHistEntry = createBatteryHistEntry(
- /*bootTimestamp=*/ 1000L,
- lowerTimestamp,
- /*totalPower=*/ 50,
- /*consumePower=*/ 10,
- /*foregroundUsageTimeInMs=*/ 100,
- /*backgroundUsageTimeInMs=*/ 200,
- /*batteryLevel=*/ 90);
+ /*bootTimestamp=*/ 1000L,
+ lowerTimestamp,
+ /*totalPower=*/ 50,
+ /*consumePower=*/ 10,
+ /*foregroundUsageTimeInMs=*/ 100,
+ /*backgroundUsageTimeInMs=*/ 200,
+ /*batteryLevel=*/ 90);
final BatteryHistEntry upperHistEntry = createBatteryHistEntry(
- /*bootTimestamp=*/ 1200L,
- upperTimestamp,
- /*totalPower=*/ 80,
- /*consumePower=*/ 20,
- /*foregroundUsageTimeInMs=*/ 200,
- /*backgroundUsageTimeInMs=*/ 300,
- /*batteryLevel=*/ 80);
+ /*bootTimestamp=*/ 1200L,
+ upperTimestamp,
+ /*totalPower=*/ 80,
+ /*consumePower=*/ 20,
+ /*foregroundUsageTimeInMs=*/ 200,
+ /*backgroundUsageTimeInMs=*/ 300,
+ /*batteryLevel=*/ 80);
final BatteryHistEntry newEntry =
- BatteryHistEntry.interpolate(
- slotTimestamp,
- upperTimestamp,
- ratio,
- lowerHistEntry,
- upperHistEntry);
+ BatteryHistEntry.interpolate(
+ slotTimestamp,
+ upperTimestamp,
+ ratio,
+ lowerHistEntry,
+ upperHistEntry);
assertBatteryHistEntry(
- newEntry, 3, upperHistEntry.mPercentOfTotal,
- /*bootTimestamp=*/ 1200 - 100,
- /*timestamp=*/ slotTimestamp,
- /*totalPower=*/ 50 + 0.5 * (80 - 50),
- /*consumePower=*/ 10 + 0.5 * (20 - 10),
- /*foregroundUsageTimeInMs=*/ Math.round(100 + 0.5 * (200 - 100)),
- /*backgroundUsageTimeInMs=*/ Math.round(200 + 0.5 * (300 - 200)),
- /*batteryLevel=*/ (int) Math.round(90 + 0.5 * (80 - 90)));
+ newEntry, 3, upperHistEntry.mPercentOfTotal,
+ /*bootTimestamp=*/ 1200 - 100,
+ /*timestamp=*/ slotTimestamp,
+ /*totalPower=*/ 50 + 0.5 * (80 - 50),
+ /*consumePower=*/ 10 + 0.5 * (20 - 10),
+ /*foregroundUsageTimeInMs=*/ Math.round(100 + 0.5 * (200 - 100)),
+ /*backgroundUsageTimeInMs=*/ Math.round(200 + 0.5 * (300 - 200)),
+ /*batteryLevel=*/ (int) Math.round(90 + 0.5 * (80 - 90)));
}
@Test
@@ -209,31 +209,31 @@ public final class BatteryHistEntryTest {
final long lowerTimestamp = 100L;
final double ratio = 0.5;
final BatteryHistEntry upperHistEntry = createBatteryHistEntry(
- /*bootTimestamp=*/ 1200L,
- upperTimestamp,
- /*totalPower=*/ 80,
- /*consumePower=*/ 20,
- /*foregroundUsageTimeInMs=*/ 200,
- /*backgroundUsageTimeInMs=*/ 300,
- /*batteryLevel=*/ 80);
+ /*bootTimestamp=*/ 1200L,
+ upperTimestamp,
+ /*totalPower=*/ 80,
+ /*consumePower=*/ 20,
+ /*foregroundUsageTimeInMs=*/ 200,
+ /*backgroundUsageTimeInMs=*/ 300,
+ /*batteryLevel=*/ 80);
final BatteryHistEntry newEntry =
- BatteryHistEntry.interpolate(
- slotTimestamp,
- upperTimestamp,
- ratio,
- /*lowerHistEntry=*/ null,
- upperHistEntry);
+ BatteryHistEntry.interpolate(
+ slotTimestamp,
+ upperTimestamp,
+ ratio,
+ /*lowerHistEntry=*/ null,
+ upperHistEntry);
assertBatteryHistEntry(
- newEntry, 3, upperHistEntry.mPercentOfTotal,
- /*bootTimestamp=*/ 1200 - 100,
- /*timestamp=*/ slotTimestamp,
- /*totalPower=*/ 0.5 * 80,
- /*consumePower=*/ 0.5 * 20,
- /*foregroundUsageTimeInMs=*/ Math.round(0.5 * 200),
- /*backgroundUsageTimeInMs=*/ Math.round(0.5 * 300),
- /*batteryLevel=*/ upperHistEntry.mBatteryLevel);
+ newEntry, 3, upperHistEntry.mPercentOfTotal,
+ /*bootTimestamp=*/ 1200 - 100,
+ /*timestamp=*/ slotTimestamp,
+ /*totalPower=*/ 0.5 * 80,
+ /*consumePower=*/ 0.5 * 20,
+ /*foregroundUsageTimeInMs=*/ Math.round(0.5 * 200),
+ /*backgroundUsageTimeInMs=*/ Math.round(0.5 * 300),
+ /*batteryLevel=*/ upperHistEntry.mBatteryLevel);
}
private static BatteryHistEntry createEntry(int consumerType) {
@@ -243,21 +243,21 @@ public final class BatteryHistEntryTest {
private static ContentValues getContentValuesWithType(int consumerType) {
final ContentValues values = new ContentValues();
values.put(BatteryHistEntry.KEY_CONSUMER_TYPE,
- Integer.valueOf(consumerType));
+ Integer.valueOf(consumerType));
return values;
}
private void assertBatteryHistEntry(
BatteryHistEntry entry, int drainType, double percentOfTotal) {
assertBatteryHistEntry(
- entry, drainType, percentOfTotal,
- /*bootTimestamp=*/ 101L,
- /*timestamp=*/ 10001L,
- /*totalPower=*/ 5.1,
- /*consumePower=*/ 1.1,
- /*foregroundUsageTimeInMs=*/ 1234L,
- /*backgroundUsageTimeInMs=*/ 5689L,
- /*batteryLevel=*/ 12);
+ entry, drainType, percentOfTotal,
+ /*bootTimestamp=*/ 101L,
+ /*timestamp=*/ 10001L,
+ /*totalPower=*/ 5.1,
+ /*consumePower=*/ 1.1,
+ /*foregroundUsageTimeInMs=*/ 1234L,
+ /*backgroundUsageTimeInMs=*/ 5689L,
+ /*batteryLevel=*/ 12);
}
private void assertBatteryHistEntry(
@@ -276,7 +276,7 @@ public final class BatteryHistEntryTest {
assertThat(entry.mUserId).isEqualTo(UserHandle.getUserId(1001));
assertThat(entry.mAppLabel).isEqualTo("Settings");
assertThat(entry.mPackageName)
- .isEqualTo("com.google.android.settings.battery");
+ .isEqualTo("com.google.android.settings.battery");
assertThat(entry.mIsHidden).isTrue();
assertThat(entry.mBootTimestamp).isEqualTo(bootTimestamp);
assertThat(entry.mTimestamp).isEqualTo(timestamp);
@@ -288,12 +288,12 @@ public final class BatteryHistEntryTest {
assertThat(entry.mBackgroundUsageTimeInMs).isEqualTo(backgroundUsageTimeInMs);
assertThat(entry.mDrainType).isEqualTo(drainType);
assertThat(entry.mConsumerType)
- .isEqualTo(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ .isEqualTo(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
assertThat(entry.mBatteryLevel).isEqualTo(batteryLevel);
assertThat(entry.mBatteryStatus)
- .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
+ .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
assertThat(entry.mBatteryHealth)
- .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
+ .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
}
private BatteryHistEntry createBatteryHistEntry(
@@ -305,7 +305,7 @@ public final class BatteryHistEntryTest {
long backgroundUsageTimeInMs,
int batteryLevel) {
final MatrixCursor cursor = new MatrixCursor(
- new String[] {
+ new String[]{
BatteryHistEntry.KEY_UID,
BatteryHistEntry.KEY_USER_ID,
BatteryHistEntry.KEY_APP_LABEL,
@@ -325,7 +325,7 @@ public final class BatteryHistEntryTest {
BatteryHistEntry.KEY_BATTERY_STATUS,
BatteryHistEntry.KEY_BATTERY_HEALTH});
cursor.addRow(
- new Object[] {
+ new Object[]{
Long.valueOf(1001),
Long.valueOf(UserHandle.getUserId(1001)),
"Settings",
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryLoaderTest.java
similarity index 94%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryLoaderTest.java
index a0fd5fd5f52..98a44de81b8 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryLoaderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,18 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.doReturn;
import android.content.Context;
import com.android.settings.testutils.FakeFeatureFactory;
-import java.util.HashMap;
-import java.util.Map;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,6 +30,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import java.util.HashMap;
+import java.util.Map;
+
@RunWith(RobolectricTestRunner.class)
public final class BatteryHistoryLoaderTest {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreferenceTest.java
similarity index 96%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreferenceTest.java
index 83fcbae69d8..7017c43b20c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreferenceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -31,6 +31,7 @@ import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.widget.UsageView;
import org.junit.Before;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUsageStatsLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoaderTest.java
similarity index 96%
rename from tests/robotests/src/com/android/settings/fuelgauge/BatteryUsageStatsLoaderTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoaderTest.java
index 8c47ff680bd..1d0bca4d8c5 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUsageStatsLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageStatsLoaderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/ConvertUtilsTest.java
similarity index 71%
rename from tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/ConvertUtilsTest.java
index 42483d0e89e..0b8a98a742d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/ConvertUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -27,6 +27,7 @@ import android.os.BatteryUsageStats;
import android.os.LocaleList;
import android.os.UserHandle;
+import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -37,7 +38,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -54,7 +54,7 @@ public final class ConvertUtilsTest {
@Mock
private BatteryUsageStats mBatteryUsageStats;
@Mock
- private BatteryEntry mockBatteryEntry;
+ private BatteryEntry mMockBatteryEntry;
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -70,115 +70,116 @@ public final class ConvertUtilsTest {
@Test
public void convert_returnsExpectedContentValues() {
final int expectedType = 3;
- when(mockBatteryEntry.getUid()).thenReturn(1001);
- when(mockBatteryEntry.getLabel()).thenReturn("Settings");
- when(mockBatteryEntry.getDefaultPackageName())
- .thenReturn("com.google.android.settings.battery");
- when(mockBatteryEntry.isHidden()).thenReturn(true);
+ when(mMockBatteryEntry.getUid()).thenReturn(1001);
+ when(mMockBatteryEntry.getLabel()).thenReturn("Settings");
+ when(mMockBatteryEntry.getDefaultPackageName())
+ .thenReturn("com.google.android.settings.battery");
+ when(mMockBatteryEntry.isHidden()).thenReturn(true);
when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1);
- when(mockBatteryEntry.getConsumedPower()).thenReturn(1.1);
- mockBatteryEntry.mPercent = 0.3;
- when(mockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
- when(mockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
- when(mockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
- when(mockBatteryEntry.getConsumerType())
- .thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ when(mMockBatteryEntry.getConsumedPower()).thenReturn(1.1);
+ mMockBatteryEntry.mPercent = 0.3;
+ when(mMockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
+ when(mMockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
+ when(mMockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
+ when(mMockBatteryEntry.getConsumerType())
+ .thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final ContentValues values =
- ConvertUtils.convert(
- mockBatteryEntry,
- mBatteryUsageStats,
- /*batteryLevel=*/ 12,
- /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
- /*batteryHealth=*/ BatteryManager.BATTERY_HEALTH_COLD,
- /*bootTimestamp=*/ 101L,
- /*timestamp=*/ 10001L);
+ ConvertUtils.convert(
+ mMockBatteryEntry,
+ mBatteryUsageStats,
+ /*batteryLevel=*/ 12,
+ /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
+ /*batteryHealth=*/ BatteryManager.BATTERY_HEALTH_COLD,
+ /*bootTimestamp=*/ 101L,
+ /*timestamp=*/ 10001L);
assertThat(values.getAsLong(BatteryHistEntry.KEY_UID)).isEqualTo(1001L);
assertThat(values.getAsLong(BatteryHistEntry.KEY_USER_ID))
- .isEqualTo(UserHandle.getUserId(1001));
+ .isEqualTo(UserHandle.getUserId(1001));
assertThat(values.getAsString(BatteryHistEntry.KEY_APP_LABEL))
- .isEqualTo("Settings");
+ .isEqualTo("Settings");
assertThat(values.getAsString(BatteryHistEntry.KEY_PACKAGE_NAME))
- .isEqualTo("com.google.android.settings.battery");
+ .isEqualTo("com.google.android.settings.battery");
assertThat(values.getAsBoolean(BatteryHistEntry.KEY_IS_HIDDEN)).isTrue();
assertThat(values.getAsLong(BatteryHistEntry.KEY_BOOT_TIMESTAMP))
- .isEqualTo(101L);
+ .isEqualTo(101L);
assertThat(values.getAsLong(BatteryHistEntry.KEY_TIMESTAMP)).isEqualTo(10001L);
assertThat(values.getAsString(BatteryHistEntry.KEY_ZONE_ID))
- .isEqualTo(TimeZone.getDefault().getID());
+ .isEqualTo(TimeZone.getDefault().getID());
assertThat(values.getAsDouble(BatteryHistEntry.KEY_TOTAL_POWER)).isEqualTo(5.1);
assertThat(values.getAsDouble(BatteryHistEntry.KEY_CONSUME_POWER)).isEqualTo(1.1);
assertThat(values.getAsDouble(BatteryHistEntry.KEY_PERCENT_OF_TOTAL)).isEqualTo(0.3);
assertThat(values.getAsLong(BatteryHistEntry.KEY_FOREGROUND_USAGE_TIME))
- .isEqualTo(1234L);
+ .isEqualTo(1234L);
assertThat(values.getAsLong(BatteryHistEntry.KEY_BACKGROUND_USAGE_TIME))
- .isEqualTo(5689L);
+ .isEqualTo(5689L);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_DRAIN_TYPE)).isEqualTo(expectedType);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_CONSUMER_TYPE))
- .isEqualTo(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
+ .isEqualTo(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_BATTERY_LEVEL)).isEqualTo(12);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_BATTERY_STATUS))
- .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
+ .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_BATTERY_HEALTH))
- .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
+ .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
}
@Test
public void convert_nullBatteryEntry_returnsExpectedContentValues() {
final ContentValues values =
- ConvertUtils.convert(
- /*entry=*/ null,
- /*batteryUsageStats=*/ null,
- /*batteryLevel=*/ 12,
- /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
- /*batteryHealth=*/ BatteryManager.BATTERY_HEALTH_COLD,
- /*bootTimestamp=*/ 101L,
- /*timestamp=*/ 10001L);
+ ConvertUtils.convert(
+ /*entry=*/ null,
+ /*batteryUsageStats=*/ null,
+ /*batteryLevel=*/ 12,
+ /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
+ /*batteryHealth=*/ BatteryManager.BATTERY_HEALTH_COLD,
+ /*bootTimestamp=*/ 101L,
+ /*timestamp=*/ 10001L);
assertThat(values.getAsLong(BatteryHistEntry.KEY_BOOT_TIMESTAMP))
- .isEqualTo(101L);
+ .isEqualTo(101L);
assertThat(values.getAsLong(BatteryHistEntry.KEY_TIMESTAMP))
- .isEqualTo(10001L);
+ .isEqualTo(10001L);
assertThat(values.getAsString(BatteryHistEntry.KEY_ZONE_ID))
- .isEqualTo(TimeZone.getDefault().getID());
+ .isEqualTo(TimeZone.getDefault().getID());
assertThat(values.getAsInteger(BatteryHistEntry.KEY_BATTERY_LEVEL)).isEqualTo(12);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_BATTERY_STATUS))
- .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
+ .isEqualTo(BatteryManager.BATTERY_STATUS_FULL);
assertThat(values.getAsInteger(BatteryHistEntry.KEY_BATTERY_HEALTH))
- .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
+ .isEqualTo(BatteryManager.BATTERY_HEALTH_COLD);
assertThat(values.getAsString(BatteryHistEntry.KEY_PACKAGE_NAME))
- .isEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
+ .isEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
}
@Test
public void getIndexedUsageMap_nullOrEmptyHistoryMap_returnEmptyCollection() {
final int timeSlotSize = 2;
- final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
+ final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L, 104L, 105L};
assertThat(ConvertUtils.getIndexedUsageMap(
mContext, timeSlotSize, batteryHistoryKeys,
/*batteryHistoryMap=*/ null, /*purgeLowPercentageAndFakeData=*/ true))
- .isEmpty();
+ .isEmpty();
assertThat(ConvertUtils.getIndexedUsageMap(
mContext, timeSlotSize, batteryHistoryKeys,
new HashMap>(),
/*purgeLowPercentageAndFakeData=*/ true))
- .isEmpty();
+ .isEmpty();
}
+
@Test
public void getIndexedUsageMap_returnsExpectedResult() {
// Creates the fake testing data.
final int timeSlotSize = 2;
- final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
+ final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L, 104L, 105L};
final Map> batteryHistoryMap =
- new HashMap<>();
+ new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry(
- ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);
+ ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);
// Adds the index = 0 data.
Map entryMap = new HashMap<>();
BatteryHistEntry entry = createBatteryHistEntry(
- "package1", "label1", 5.0, 1L, 10L, 20L);
+ "package1", "label1", 5.0, 1L, 10L, 20L);
entryMap.put(entry.getKey(), entry);
entryMap.put(fakeEntry.getKey(), fakeEntry);
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[0]), entryMap);
@@ -189,38 +190,38 @@ public final class ConvertUtilsTest {
// Adds the index = 2 data.
entryMap = new HashMap<>();
entry = createBatteryHistEntry(
- "package2", "label2", 10.0, 2L, 15L, 25L);
+ "package2", "label2", 10.0, 2L, 15L, 25L);
entryMap.put(entry.getKey(), entry);
entryMap.put(fakeEntry.getKey(), fakeEntry);
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[2]), entryMap);
// Adds the index = 3 data.
entryMap = new HashMap<>();
entry = createBatteryHistEntry(
- "package2", "label2", 15.0, 2L, 25L, 35L);
+ "package2", "label2", 15.0, 2L, 25L, 35L);
entryMap.put(entry.getKey(), entry);
entry = createBatteryHistEntry(
- "package3", "label3", 5.0, 3L, 5L, 5L);
+ "package3", "label3", 5.0, 3L, 5L, 5L);
entryMap.put(entry.getKey(), entry);
entryMap.put(fakeEntry.getKey(), fakeEntry);
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[3]), entryMap);
// Adds the index = 4 data.
entryMap = new HashMap<>();
entry = createBatteryHistEntry(
- "package2", "label2", 30.0, 2L, 30L, 40L);
+ "package2", "label2", 30.0, 2L, 30L, 40L);
entryMap.put(entry.getKey(), entry);
entry = createBatteryHistEntry(
- "package2", "label2", 75.0, 4L, 40L, 50L);
+ "package2", "label2", 75.0, 4L, 40L, 50L);
entryMap.put(entry.getKey(), entry);
entry = createBatteryHistEntry(
- "package3", "label3", 5.0, 3L, 5L, 5L);
+ "package3", "label3", 5.0, 3L, 5L, 5L);
entryMap.put(entry.getKey(), entry);
entryMap.put(fakeEntry.getKey(), fakeEntry);
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[4]), entryMap);
final Map> resultMap =
- ConvertUtils.getIndexedUsageMap(
- mContext, timeSlotSize, batteryHistoryKeys, batteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ false);
+ ConvertUtils.getIndexedUsageMap(
+ mContext, timeSlotSize, batteryHistoryKeys, batteryHistoryMap,
+ /*purgeLowPercentageAndFakeData=*/ false);
assertThat(resultMap).hasSize(3);
// Verifies the first timestamp result.
@@ -243,9 +244,9 @@ public final class ConvertUtilsTest {
// Test getIndexedUsageMap() with purged data.
ConvertUtils.PERCENTAGE_OF_TOTAL_THRESHOLD = 50;
final Map> purgedResultMap =
- ConvertUtils.getIndexedUsageMap(
- mContext, timeSlotSize, batteryHistoryKeys, batteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ true);
+ ConvertUtils.getIndexedUsageMap(
+ mContext, timeSlotSize, batteryHistoryKeys, batteryHistoryMap,
+ /*purgeLowPercentageAndFakeData=*/ true);
assertThat(purgedResultMap).hasSize(3);
// Verifies the first timestamp result.
@@ -260,7 +261,7 @@ public final class ConvertUtilsTest {
assertThat(entryList).hasSize(1);
// Verifies the fake data is cleared out.
assertThat(entryList.get(0).getPackageName())
- .isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
+ .isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
// Adds lacked data into the battery history map.
final int remainingSize = 25 - batteryHistoryKeys.length;
@@ -268,10 +269,10 @@ public final class ConvertUtilsTest {
batteryHistoryMap.put(105L + index + 1, new HashMap<>());
}
when(mPowerUsageFeatureProvider.getBatteryHistory(mContext))
- .thenReturn(batteryHistoryMap);
+ .thenReturn(batteryHistoryMap);
final List batteryDiffEntryList =
- BatteryChartPreferenceController.getBatteryLast24HrUsageData(mContext);
+ BatteryChartPreferenceController.getBatteryLast24HrUsageData(mContext);
assertThat(batteryDiffEntryList).isNotEmpty();
final BatteryDiffEntry resultEntry = batteryDiffEntryList.get(0);
@@ -281,11 +282,11 @@ public final class ConvertUtilsTest {
@Test
public void getIndexedUsageMap_usageTimeExceed_returnsExpectedResult() {
final int timeSlotSize = 1;
- final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
+ final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L};
final Map> batteryHistoryMap =
- new HashMap<>();
+ new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry(
- ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);
+ ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);
// Adds the index = 0 data.
Map entryMap = new HashMap<>();
entryMap.put(fakeEntry.getKey(), fakeEntry);
@@ -297,14 +298,14 @@ public final class ConvertUtilsTest {
// Adds the index = 2 data.
entryMap = new HashMap<>();
final BatteryHistEntry entry = createBatteryHistEntry(
- "package3", "label3", 500, 5L, 3600000L, 7200000L);
+ "package3", "label3", 500, 5L, 3600000L, 7200000L);
entryMap.put(entry.getKey(), entry);
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[2]), entryMap);
final Map> purgedResultMap =
- ConvertUtils.getIndexedUsageMap(
- mContext, timeSlotSize, batteryHistoryKeys, batteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ true);
+ ConvertUtils.getIndexedUsageMap(
+ mContext, timeSlotSize, batteryHistoryKeys, batteryHistoryMap,
+ /*purgeLowPercentageAndFakeData=*/ true);
assertThat(purgedResultMap).hasSize(2);
final List entryList = purgedResultMap.get(0);
@@ -313,19 +314,19 @@ public final class ConvertUtilsTest {
final float ratio = (float) (7200) / (float) (3600 + 7200);
final BatteryDiffEntry resultEntry = entryList.get(0);
assertThat(resultEntry.mForegroundUsageTimeInMs)
- .isEqualTo(Math.round(entry.mForegroundUsageTimeInMs * ratio));
+ .isEqualTo(Math.round(entry.mForegroundUsageTimeInMs * ratio));
assertThat(resultEntry.mBackgroundUsageTimeInMs)
- .isEqualTo(Math.round(entry.mBackgroundUsageTimeInMs * ratio));
+ .isEqualTo(Math.round(entry.mBackgroundUsageTimeInMs * ratio));
assertThat(resultEntry.mConsumePower)
- .isEqualTo(entry.mConsumePower * ratio);
+ .isEqualTo(entry.mConsumePower * ratio);
}
@Test
public void getIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() {
- final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
+ final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L};
final Map> batteryHistoryMap = new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry(
- ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);
+ ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);
// Adds the index = 0 data.
Map entryMap = new HashMap<>();
entryMap.put(fakeEntry.getKey(), fakeEntry);
@@ -337,16 +338,16 @@ public final class ConvertUtilsTest {
// Adds the index = 2 data.
entryMap = new HashMap<>();
final BatteryHistEntry entry = createBatteryHistEntry(
- "package3", "label3", 500, 5L, 3600000L, 7200000L);
+ "package3", "label3", 500, 5L, 3600000L, 7200000L);
entryMap.put(entry.getKey(), entry);
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[2]), entryMap);
when(mPowerUsageFeatureProvider.getHideBackgroundUsageTimeSet(mContext))
- .thenReturn(new HashSet(Arrays.asList((CharSequence) "package3")));
+ .thenReturn(new HashSet(Arrays.asList((CharSequence) "package3")));
final Map> purgedResultMap =
- ConvertUtils.getIndexedUsageMap(
- mContext, /*timeSlotSize=*/ 1, batteryHistoryKeys, batteryHistoryMap,
- /*purgeLowPercentageAndFakeData=*/ true);
+ ConvertUtils.getIndexedUsageMap(
+ mContext, /*timeSlotSize=*/ 1, batteryHistoryKeys, batteryHistoryMap,
+ /*purgeLowPercentageAndFakeData=*/ true);
final BatteryDiffEntry resultEntry = purgedResultMap.get(0).get(0);
assertThat(resultEntry.mBackgroundUsageTimeInMs).isEqualTo(0);
@@ -355,7 +356,7 @@ public final class ConvertUtilsTest {
@Test
public void getLocale_nullContext_returnDefaultLocale() {
assertThat(ConvertUtils.getLocale(/*context=*/ null))
- .isEqualTo(Locale.getDefault());
+ .isEqualTo(Locale.getDefault());
}
@Test
@@ -379,12 +380,12 @@ public final class ConvertUtilsTest {
values.put(BatteryHistEntry.KEY_APP_LABEL, appLabel);
values.put(BatteryHistEntry.KEY_UID, Long.valueOf(uid));
values.put(BatteryHistEntry.KEY_CONSUMER_TYPE,
- Integer.valueOf(ConvertUtils.CONSUMER_TYPE_UID_BATTERY));
+ Integer.valueOf(ConvertUtils.CONSUMER_TYPE_UID_BATTERY));
values.put(BatteryHistEntry.KEY_CONSUME_POWER, consumePower);
values.put(BatteryHistEntry.KEY_FOREGROUND_USAGE_TIME,
- Long.valueOf(foregroundUsageTimeInMs));
+ Long.valueOf(foregroundUsageTimeInMs));
values.put(BatteryHistEntry.KEY_BACKGROUND_USAGE_TIME,
- Long.valueOf(backgroundUsageTimeInMs));
+ Long.valueOf(backgroundUsageTimeInMs));
return new BatteryHistEntry(values);
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/ExpandDividerPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/ExpandDividerPreferenceTest.java
similarity index 93%
rename from tests/robotests/src/com/android/settings/fuelgauge/ExpandDividerPreferenceTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/ExpandDividerPreferenceTest.java
index 9e32da4bea0..e36f94854e7 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/ExpandDividerPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/ExpandDividerPreferenceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import android.content.Context;
import android.widget.ImageView;
@@ -74,7 +73,7 @@ public final class ExpandDividerPreferenceTest {
@Test
public void testOnClick_switchExpandStateAndInvokeCallback() {
- final boolean[] isExpandedArray = new boolean[] {false};
+ final boolean[] isExpandedArray = new boolean[]{false};
mExpandDividerPreference.mImageView = mImageView;
mExpandDividerPreference.setOnExpandListener(
isExpanded -> isExpandedArray[0] = isExpanded);
@@ -94,7 +93,7 @@ public final class ExpandDividerPreferenceTest {
@Test
public void testSetIsExpanded_updateStateButNotInvokeCallback() {
- final boolean[] isExpandedArray = new boolean[] {false};
+ final boolean[] isExpandedArray = new boolean[]{false};
mExpandDividerPreference.mImageView = mImageView;
mExpandDividerPreference.setOnExpandListener(
isExpanded -> isExpandedArray[0] = isExpanded);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
similarity index 95%
rename from tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
index 10b89a62290..5d599fe603a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerGaugePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -55,7 +55,7 @@ public class PowerGaugePreferenceTest {
mContext = RuntimeEnvironment.application;
mRootView = LayoutInflater.from(mContext).inflate(R.layout.preference_app, null);
mWidgetView =
- LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary, null);
+ LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary, null);
final LinearLayout widgetFrame = mRootView.findViewById(android.R.id.widget_frame);
assertThat(widgetFrame).isNotNull();
widgetFrame.addView(mWidgetView);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java
similarity index 96%
rename from tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java
index 451e605985b..27009301da9 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageBaseTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java
similarity index 93%
rename from tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
rename to tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java
index 843cc99143b..81b574aa7d6 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerUsageSummaryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.fuelgauge;
+package com.android.settings.fuelgauge.batteryusage;
-import static com.android.settings.fuelgauge.PowerUsageSummary.BATTERY_INFO_LOADER;
-import static com.android.settings.fuelgauge.PowerUsageSummary.KEY_BATTERY_ERROR;
-import static com.android.settings.fuelgauge.PowerUsageSummary.KEY_BATTERY_USAGE;
+import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.BATTERY_INFO_LOADER;
+import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.KEY_BATTERY_ERROR;
+import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.KEY_BATTERY_USAGE;
import static com.google.common.truth.Truth.assertThat;
@@ -44,6 +44,8 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
+import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.XmlTestUtils;
@@ -55,6 +57,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -74,6 +77,7 @@ public class PowerUsageSummaryTest {
public static void beforeClass() {
sAdditionalBatteryInfoIntent = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO");
}
+
@Mock
private SettingsActivity mSettingsActivity;
@Mock
@@ -111,7 +115,7 @@ public class PowerUsageSummaryTest {
.thenReturn(sAdditionalBatteryInfoIntent);
when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mRealContext))
.thenReturn(true);
- mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext));
+ mFragment.mBatteryUtils = Mockito.spy(new BatteryUtils(mRealContext));
ReflectionHelpers.setField(mFragment, "mVisibilityLoggerMixin", mVisibilityLoggerMixin);
ReflectionHelpers.setField(mFragment, "mBatteryBroadcastReceiver",
mBatteryBroadcastReceiver);
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
index e4fc9fa6f7c..78541db4947 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java
@@ -31,13 +31,13 @@ import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
-import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
+import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
import com.android.settings.slices.SliceBackgroundWorker;
import org.junit.After;
diff --git a/tests/unit/src/com/android/settings/search/CustomSiteMapRegistryTest.java b/tests/unit/src/com/android/settings/search/CustomSiteMapRegistryTest.java
index 5eb3b336ede..a3090c6c5f5 100644
--- a/tests/unit/src/com/android/settings/search/CustomSiteMapRegistryTest.java
+++ b/tests/unit/src/com/android/settings/search/CustomSiteMapRegistryTest.java
@@ -23,8 +23,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.backup.UserBackupSettingsActivity;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
-import com.android.settings.fuelgauge.PowerUsageAdvanced;
-import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.fuelgauge.batteryusage.PowerUsageAdvanced;
+import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.GestureNavigationSettingsFragment;
import com.android.settings.gestures.SystemNavigationGestureSettings;
import com.android.settings.location.LocationSettings;