Merge "Move battery usage files to a separate folder." into tm-qpr-dev am: 3b7953eac2
am: 6470ada117
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18797446 Change-Id: I3d6a155e80a5d54c309061c41d0b6436e61cc4cb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -42,6 +42,9 @@ import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
|
@@ -190,7 +190,7 @@ public class BatteryUtils {
|
||||
* Returns true if the specified battery consumer should be excluded from
|
||||
* battery consumption lists, either short or full.
|
||||
*/
|
||||
boolean shouldHideUidBatteryConsumerUnconditionally(UidBatteryConsumer consumer,
|
||||
public boolean shouldHideUidBatteryConsumerUnconditionally(UidBatteryConsumer consumer,
|
||||
String[] packages) {
|
||||
final int uid = consumer.getUid();
|
||||
return uid == UID_TETHERING
|
||||
|
@@ -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.
|
||||
@@ -21,6 +21,7 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -73,6 +74,7 @@ public interface PowerUsageFeatureProvider {
|
||||
|
||||
/**
|
||||
* Returns an improved projection curve for future battery level.
|
||||
*
|
||||
* @param zeroTime timestamps (array keys) are shifted by this amount
|
||||
*/
|
||||
SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime);
|
||||
@@ -84,21 +86,20 @@ public interface PowerUsageFeatureProvider {
|
||||
|
||||
/**
|
||||
* Checks whether debugging should be enabled for battery estimates.
|
||||
* @return
|
||||
*/
|
||||
boolean isEstimateDebugEnabled();
|
||||
|
||||
/**
|
||||
* Converts the provided string containing the remaining time into a debug string for enhanced
|
||||
* estimates.
|
||||
* @param timeRemaining
|
||||
*
|
||||
* @return A string containing the estimate and a label indicating it is an enhanced estimate
|
||||
*/
|
||||
String getEnhancedEstimateDebugString(String timeRemaining);
|
||||
|
||||
/**
|
||||
* Converts the provided string containing the remaining time into a debug string.
|
||||
* @param timeRemaining
|
||||
*
|
||||
* @return A string containing the estimate and a label indicating it is a normal estimate
|
||||
*/
|
||||
String getOldEstimateDebugString(String timeRemaining);
|
||||
@@ -114,7 +115,7 @@ public interface PowerUsageFeatureProvider {
|
||||
* to their next charging time.
|
||||
*
|
||||
* @param id Optional string used to identify the caller for metrics. Usually the class name of
|
||||
* the caller
|
||||
* the caller
|
||||
*/
|
||||
boolean getEarlyWarningSignal(Context context, String id);
|
||||
|
||||
|
@@ -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.
|
||||
@@ -26,11 +26,13 @@ import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Implementation of {@code PowerUsageFeatureProvider} */
|
||||
public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
|
||||
|
||||
private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar";
|
||||
|
@@ -21,12 +21,13 @@ import android.os.Parcel;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
|
||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Tip to suggest user to remove app restriction. This is the empty tip and it is only used in
|
||||
* {@link com.android.settings.fuelgauge.AdvancedPowerUsageDetail} to create dialog.
|
||||
* {@link AdvancedPowerUsageDetail} to create dialog.
|
||||
*/
|
||||
public class UnrestrictAppTip extends BatteryTip {
|
||||
private AppInfo mAppInfo;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -11,11 +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.Activity;
|
||||
import android.content.Context;
|
||||
@@ -35,8 +34,8 @@ import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.SparseArray;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -48,6 +47,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.lifecycle.Lifecycle;
|
||||
@@ -72,6 +73,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
|
||||
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 20;
|
||||
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
|
||||
private static final String MEDIASERVER_PACKAGE_NAME = "mediaserver";
|
||||
private static final String NOT_AVAILABLE = "not_available";
|
||||
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mAppListGroup;
|
||||
@@ -230,7 +232,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
|
||||
if (sConfig.shouldShowBatteryAttributionList(mContext)) {
|
||||
final int dischargePercentage = getDischargePercentage(batteryUsageStats);
|
||||
final List<BatteryEntry> 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<BatteryEntry> 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);
|
@@ -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<Integer, List<BatteryDiffEntry>> 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<String, BatteryHistEntry> 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<BatteryDiffEntry> 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<BatteryDiffEntry> getBatteryLast24HrUsageData(Context context) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final Map<Long, Map<String, BatteryHistEntry>> 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<Integer, List<BatteryDiffEntry>> 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<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
|
||||
final List<Long> 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<Integer, List<BatteryDiffEntry>> 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<BatteryDiffEntry> 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;
|
||||
}
|
||||
|
@@ -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<String> 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<AccessibilityServiceInfo> 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();
|
@@ -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) {
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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) {
|
@@ -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<Long, Map<String, BatteryHistEntry>> loadInBackground() {
|
||||
final PowerUsageFeatureProvider powerUsageFeatureProvider =
|
||||
FeatureFactory.getFactory(mContext).getPowerUsageFeatureProvider(mContext);
|
||||
FeatureFactory.getFactory(mContext).getPowerUsageFeatureProvider(mContext);
|
||||
return powerUsageFeatureProvider.getBatteryHistory(mContext);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
@@ -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;
|
@@ -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<String, BatteryHistEntry> 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<String, BatteryHistEntry> currentBatteryHistMap =
|
||||
batteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
|
||||
batteryHistoryMap.getOrDefault(currentTimestamp, EMPTY_BATTERY_MAP);
|
||||
final Map<String, BatteryHistEntry> nextBatteryHistMap =
|
||||
batteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
|
||||
batteryHistoryMap.getOrDefault(nextTimestamp, EMPTY_BATTERY_MAP);
|
||||
final Map<String, BatteryHistEntry> 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();
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
@@ -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);
|
||||
}
|
@@ -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) {
|
@@ -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);
|
Reference in New Issue
Block a user