controllers = new ArrayList<>();
if (settingsActivity != null && fragment != null) {
- controllers.add(
- new RestrictAppPreferenceController(fragment));
+ controllers.add(new RestrictAppPreferenceController(fragment));
} else {
controllers.add(new RestrictAppPreferenceController(context));
}
diff --git a/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java b/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
index b514888baa9..0f54f3e7d03 100644
--- a/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
@@ -34,15 +34,13 @@ import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.utils.ThreadUtils;
-public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
- LifecycleObserver, OnStart, OnStop, BatteryPreferenceController {
+public class TopLevelBatteryPreferenceController extends BasePreferenceController
+ implements LifecycleObserver, OnStart, OnStop, BatteryPreferenceController {
private static final String TAG = "TopLvBatteryPrefControl";
- @VisibleForTesting
- Preference mPreference;
- @VisibleForTesting
- protected boolean mIsBatteryPresent = true;
+ @VisibleForTesting Preference mPreference;
+ @VisibleForTesting protected boolean mIsBatteryPresent = true;
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
@@ -53,28 +51,33 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
public TopLevelBatteryPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
- mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
- Log.d(TAG, "onBatteryChanged: type=" + type);
- if (type == BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_NOT_PRESENT) {
- mIsBatteryPresent = false;
- }
- BatteryInfo.getBatteryInfo(mContext, info -> {
- Log.d(TAG, "getBatteryInfo: " + info);
- mBatteryInfo = info;
- updateState(mPreference);
- // Update the preference summary text to the latest state.
- setSummaryAsync(info);
- }, true /* shortString */);
- });
+ mBatteryBroadcastReceiver.setBatteryChangedListener(
+ type -> {
+ Log.d(TAG, "onBatteryChanged: type=" + type);
+ if (type == BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_NOT_PRESENT) {
+ mIsBatteryPresent = false;
+ }
+ BatteryInfo.getBatteryInfo(
+ mContext,
+ info -> {
+ Log.d(TAG, "getBatteryInfo: " + info);
+ mBatteryInfo = info;
+ updateState(mPreference);
+ // Update the preference summary text to the latest state.
+ setSummaryAsync(info);
+ },
+ true /* shortString */);
+ });
- mBatteryStatusFeatureProvider = FeatureFactory.getFeatureFactory()
- .getBatteryStatusFeatureProvider();
+ mBatteryStatusFeatureProvider =
+ FeatureFactory.getFeatureFactory().getBatteryStatusFeatureProvider();
}
@Override
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(R.bool.config_show_top_level_battery)
- ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -106,13 +109,17 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
return getDashboardLabel(mContext, mBatteryInfo, batteryStatusUpdate);
}
- protected CharSequence getDashboardLabel(Context context, BatteryInfo info,
- boolean batteryStatusUpdate) {
+ protected CharSequence getDashboardLabel(
+ Context context, BatteryInfo info, boolean batteryStatusUpdate) {
if (info == null || context == null) {
return null;
}
- Log.d(TAG, "getDashboardLabel: " + mBatteryStatusLabel + " batteryStatusUpdate="
- + batteryStatusUpdate);
+ Log.d(
+ TAG,
+ "getDashboardLabel: "
+ + mBatteryStatusLabel
+ + " batteryStatusUpdate="
+ + batteryStatusUpdate);
if (batteryStatusUpdate) {
setSummaryAsync(info);
@@ -121,19 +128,24 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
}
private void setSummaryAsync(BatteryInfo info) {
- ThreadUtils.postOnBackgroundThread(() -> {
- // Return false if built-in status should be used, will use updateBatteryStatus()
- // method to inject the customized battery status label.
- final boolean triggerBatteryStatusUpdate =
- mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info);
- ThreadUtils.postOnMainThread(() -> {
- if (!triggerBatteryStatusUpdate) {
- mBatteryStatusLabel = null; // will generateLabel()
- }
- mPreference.setSummary(
- mBatteryStatusLabel == null ? generateLabel(info) : mBatteryStatusLabel);
- });
- });
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ // Return false if built-in status should be used, will use
+ // updateBatteryStatus()
+ // method to inject the customized battery status label.
+ final boolean triggerBatteryStatusUpdate =
+ mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info);
+ ThreadUtils.postOnMainThread(
+ () -> {
+ if (!triggerBatteryStatusUpdate) {
+ mBatteryStatusLabel = null; // will generateLabel()
+ }
+ mPreference.setSummary(
+ mBatteryStatusLabel == null
+ ? generateLabel(info)
+ : mBatteryStatusLabel);
+ });
+ });
}
private CharSequence generateLabel(BatteryInfo info) {
@@ -156,9 +168,7 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
}
}
- /**
- * Callback which receives text for the label.
- */
+ /** Callback which receives text for the label. */
@Override
public void updateBatteryStatus(String label, BatteryInfo info) {
mBatteryStatusLabel = label; // Null if adaptive charging is not active
diff --git a/src/com/android/settings/fuelgauge/UnrestrictedPreferenceController.java b/src/com/android/settings/fuelgauge/UnrestrictedPreferenceController.java
index b06b7e2d08b..652941b2544 100644
--- a/src/com/android/settings/fuelgauge/UnrestrictedPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/UnrestrictedPreferenceController.java
@@ -30,8 +30,7 @@ public class UnrestrictedPreferenceController extends AbstractPreferenceControll
private static final String TAG = "UNRESTRICTED_PREF";
- @VisibleForTesting
- static final String KEY_UNRESTRICTED_PREF = "unrestricted_preference";
+ @VisibleForTesting static final String KEY_UNRESTRICTED_PREF = "unrestricted_preference";
@VisibleForTesting BatteryOptimizeUtils mBatteryOptimizeUtils;
@@ -44,8 +43,9 @@ public class UnrestrictedPreferenceController extends AbstractPreferenceControll
public void updateState(Preference preference) {
preference.setEnabled(mBatteryOptimizeUtils.isSelectorPreferenceEnabled());
- final boolean isUnrestricted = mBatteryOptimizeUtils.getAppOptimizationMode()
- == BatteryOptimizeUtils.MODE_UNRESTRICTED;
+ final boolean isUnrestricted =
+ mBatteryOptimizeUtils.getAppOptimizationMode()
+ == BatteryOptimizeUtils.MODE_UNRESTRICTED;
((SelectorWithWidgetPreference) preference).setChecked(isUnrestricted);
}
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java
index be364eee48e..5c57c0ca96d 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java
@@ -37,12 +37,9 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.fuelgauge.BatterySaverUtils;
import com.android.settingslib.widget.MainSwitchPreference;
-/**
- * Controller to update the battery saver button
- */
-public class BatterySaverButtonPreferenceController extends
- TogglePreferenceController implements LifecycleObserver, OnStart, OnStop,
- BatterySaverReceiver.BatterySaverListener {
+/** Controller to update the battery saver button */
+public class BatterySaverButtonPreferenceController extends TogglePreferenceController
+ implements LifecycleObserver, OnStart, OnStop, BatterySaverReceiver.BatterySaverListener {
private static final long SWITCH_ANIMATION_DURATION = 350L;
private final BatterySaverReceiver mBatterySaverReceiver;
@@ -104,8 +101,8 @@ public class BatterySaverButtonPreferenceController extends
@Override
public boolean setChecked(boolean stateOn) {
- return BatterySaverUtils.setPowerSaveMode(mContext, stateOn,
- false /* needFirstTimeWarning */, SAVER_ENABLED_SETTINGS);
+ return BatterySaverUtils.setPowerSaveMode(
+ mContext, stateOn, false /* needFirstTimeWarning */, SAVER_ENABLED_SETTINGS);
}
@Override
@@ -115,8 +112,7 @@ public class BatterySaverButtonPreferenceController extends
@Override
public void onPowerSaveModeChanged() {
- mHandler.postDelayed(() -> onPowerSaveModeChangedInternal(),
- SWITCH_ANIMATION_DURATION);
+ mHandler.postDelayed(() -> onPowerSaveModeChangedInternal(), SWITCH_ANIMATION_DURATION);
}
private void onPowerSaveModeChangedInternal() {
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSchedulePreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSchedulePreferenceController.java
index dce190393d1..ebec5cf0fc0 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSchedulePreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSchedulePreferenceController.java
@@ -32,17 +32,14 @@ import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.fuelgauge.BatterySaverUtils;
/**
- * Simple controller to navigate users to the scheduling page from
- * "Settings > Battery > Battery Saver". Also updates the summary for preference based on
- * the currently selected settings.
+ * Simple controller to navigate users to the scheduling page from "Settings > Battery > Battery
+ * Saver". Also updates the summary for preference based on the currently selected settings.
*/
public class BatterySaverSchedulePreferenceController extends BasePreferenceController {
- @VisibleForTesting
- Preference mBatterySaverSchedulePreference;
+ @VisibleForTesting Preference mBatterySaverSchedulePreference;
public static final String KEY_BATTERY_SAVER_SCHEDULE = "battery_saver_schedule";
-
public BatterySaverSchedulePreferenceController(Context context) {
super(context, KEY_BATTERY_SAVER_SCHEDULE);
BatterySaverUtils.revertScheduleToNoneIfNeeded(context);
@@ -66,7 +63,8 @@ public class BatterySaverSchedulePreferenceController extends BasePreferenceCont
if (KEY_PERCENTAGE.equals(mode)) {
final int threshold =
Settings.Global.getInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
- return mContext.getString(R.string.battery_saver_auto_percentage_summary,
+ return mContext.getString(
+ R.string.battery_saver_auto_percentage_summary,
Utils.formatPercentage(threshold));
}
return mContext.getText(R.string.battery_saver_auto_no_schedule);
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java
index 4266beaaeb9..45c1be0ad71 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java
@@ -31,12 +31,12 @@ import com.android.settingslib.fuelgauge.BatterySaverUtils;
/**
* Responds to user actions in the Settings > Battery > Set a Schedule Screen
*
- * Note that this is not a preference controller since that screen does not inherit from
+ * Note that this is not a preference controller since that screen does not inherit from
* DashboardFragment.
*
- * Will call the appropriate power manager APIs and modify the correct settings to enable
- * users to control their automatic battery saver toggling preferences.
- * See {@link Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
+ *
Will call the appropriate power manager APIs and modify the correct settings to enable users
+ * to control their automatic battery saver toggling preferences. See {@link
+ * Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
*/
public class BatterySaverScheduleRadioButtonsController {
private static final String TAG = "BatterySaverScheduleRadioButtonsController";
@@ -46,8 +46,8 @@ public class BatterySaverScheduleRadioButtonsController {
private Context mContext;
private BatterySaverScheduleSeekBarController mSeekBarController;
- public BatterySaverScheduleRadioButtonsController(Context context,
- BatterySaverScheduleSeekBarController seekbar) {
+ public BatterySaverScheduleRadioButtonsController(
+ Context context, BatterySaverScheduleSeekBarController seekbar) {
mContext = context;
mSeekBarController = seekbar;
}
@@ -67,10 +67,11 @@ public class BatterySaverScheduleRadioButtonsController {
case KEY_PERCENTAGE:
triggerLevel = TRIGGER_LEVEL_MIN;
confirmationExtras.putBoolean(BatterySaverUtils.EXTRA_CONFIRM_TEXT_ONLY, true);
- confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER,
+ confirmationExtras.putInt(
+ BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER,
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
- confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER_LEVEL,
- triggerLevel);
+ confirmationExtras.putInt(
+ BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER_LEVEL, triggerLevel);
break;
default:
throw new IllegalStateException(
@@ -79,7 +80,7 @@ public class BatterySaverScheduleRadioButtonsController {
if (!TextUtils.equals(key, KEY_NO_SCHEDULE)
&& BatterySaverUtils.maybeShowBatterySaverConfirmation(
- mContext, confirmationExtras)) {
+ mContext, confirmationExtras)) {
// reset this if we need to show the confirmation message
mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE;
triggerLevel = 0;
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSeekBarController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSeekBarController.java
index 687221e3b2a..8580f6ecd1c 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSeekBarController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSeekBarController.java
@@ -35,30 +35,28 @@ import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.fuelgauge.BatterySaverUtils;
/**
- * Responds to user actions in the Settings > Battery > Set a Schedule Screen for the seekbar.
- * Note that this seekbar is only visible when the radio button selected is "Percentage".
+ * Responds to user actions in the Settings > Battery > Set a Schedule Screen for the seekbar. Note
+ * that this seekbar is only visible when the radio button selected is "Percentage".
*
- * Note that this is not a preference controller since that screen does not inherit from
+ *
Note that this is not a preference controller since that screen does not inherit from
* DashboardFragment.
*
- * Will call the appropriate power manager APIs and modify the correct settings to enable
- * users to control their automatic battery saver toggling preferences.
- * See {@link Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
+ *
Will call the appropriate power manager APIs and modify the correct settings to enable users
+ * to control their automatic battery saver toggling preferences. See {@link
+ * Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
*/
-public class BatterySaverScheduleSeekBarController implements
- OnPreferenceChangeListener, OnSeekBarChangeListener {
+public class BatterySaverScheduleSeekBarController
+ implements OnPreferenceChangeListener, OnSeekBarChangeListener {
public static final int MAX_SEEKBAR_VALUE = 15;
public static final int MIN_SEEKBAR_VALUE = 2;
public static final String KEY_BATTERY_SAVER_SEEK_BAR = "battery_saver_seek_bar";
private static final int LEVEL_UNIT_SCALE = 5;
- @VisibleForTesting
- public SeekBarPreference mSeekBarPreference;
+ @VisibleForTesting public SeekBarPreference mSeekBarPreference;
private Context mContext;
- @VisibleForTesting
- int mPercentage;
+ @VisibleForTesting int mPercentage;
public BatterySaverScheduleSeekBarController(Context context) {
mContext = context;
@@ -93,7 +91,8 @@ public class BatterySaverScheduleSeekBarController implements
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (mPercentage > 0) {
- Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.putInt(
+ mContext.getContentResolver(),
Global.LOW_POWER_MODE_TRIGGER_LEVEL,
mPercentage);
}
@@ -108,8 +107,7 @@ public class BatterySaverScheduleSeekBarController implements
final int currentSeekbarValue = Math.max(threshold / 5, MIN_SEEKBAR_VALUE);
mSeekBarPreference.setVisible(true);
mSeekBarPreference.setProgress(currentSeekbarValue);
- final CharSequence stateDescription = formatStateDescription(
- currentSeekbarValue * 5);
+ final CharSequence stateDescription = formatStateDescription(currentSeekbarValue * 5);
mSeekBarPreference.setTitle(stateDescription);
mSeekBarPreference.overrideSeekBarStateDescription(stateDescription);
} else {
@@ -130,7 +128,7 @@ public class BatterySaverScheduleSeekBarController implements
}
private CharSequence formatStateDescription(int percentage) {
- return mContext.getString(R.string.battery_saver_seekbar_title,
- Utils.formatPercentage(percentage));
+ return mContext.getString(
+ R.string.battery_saver_seekbar_title, Utils.formatPercentage(percentage));
}
}
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSettings.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSettings.java
index 2d841bd0964..cded470cfd8 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSettings.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSettings.java
@@ -49,32 +49,32 @@ import com.google.common.collect.Lists;
import java.util.List;
/**
- * Fragment that allows users to customize their automatic battery saver mode settings.
- *
- * Location: Settings > Battery > Battery Saver > Set a Schedule
+ * Fragment that allows users to customize their automatic battery saver mode settings.
+ *
+ * Location: Settings > Battery > Battery Saver > Set a Schedule
* See {@link BatterySaverSchedulePreferenceController} for the controller that manages navigation
- * to this screen from "Settings > Battery > Battery Saver" and the summary.
- * See {@link BatterySaverScheduleRadioButtonsController} &
- * {@link BatterySaverScheduleSeekBarController} for the controller that manages user
- * interactions in this screen.
+ * to this screen from "Settings > Battery > Battery Saver" and the summary.
+ * See {@link BatterySaverScheduleRadioButtonsController} & {@link
+ * BatterySaverScheduleSeekBarController} for the controller that manages user interactions in this
+ * screen.
*/
public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
public BatterySaverScheduleRadioButtonsController mRadioButtonController;
- @VisibleForTesting
- Context mContext;
+ @VisibleForTesting Context mContext;
private int mSaverPercentage;
private String mSaverScheduleKey;
private BatterySaverScheduleSeekBarController mSeekBarController;
@VisibleForTesting
- final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange, Uri uri) {
- getPreferenceScreen().removeAll();
- updateCandidates();
- }
- };
+ final ContentObserver mSettingsObserver =
+ new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ getPreferenceScreen().removeAll();
+ updateCandidates();
+ }
+ };
@Override
protected int getPreferenceScreenResId() {
@@ -85,18 +85,19 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
public void onAttach(Context context) {
super.onAttach(context);
mSeekBarController = new BatterySaverScheduleSeekBarController(context);
- mRadioButtonController = new BatterySaverScheduleRadioButtonsController(
- context, mSeekBarController);
+ mRadioButtonController =
+ new BatterySaverScheduleRadioButtonsController(context, mSeekBarController);
mContext = context;
}
@Override
public void onResume() {
super.onResume();
- mContext.getContentResolver().registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED),
- false,
- mSettingsObserver);
+ mContext.getContentResolver()
+ .registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED),
+ false,
+ mSettingsObserver);
mSaverScheduleKey = BatterySaverUtils.getBatterySaverScheduleKey(mContext);
mSaverPercentage = getSaverPercentage();
}
@@ -124,24 +125,30 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
protected List extends CandidateInfo> getCandidates() {
Context context = getContext();
List candidates = Lists.newArrayList();
- candidates.add(new BatterySaverScheduleCandidateInfo(
- context.getText(R.string.battery_saver_auto_no_schedule),
- /* summary */ null,
- KEY_NO_SCHEDULE,
- /* enabled */ true));
+ candidates.add(
+ new BatterySaverScheduleCandidateInfo(
+ context.getText(R.string.battery_saver_auto_no_schedule),
+ /* summary */ null,
+ KEY_NO_SCHEDULE,
+ /* enabled */ true));
BatterySaverUtils.revertScheduleToNoneIfNeeded(context);
- candidates.add(new BatterySaverScheduleCandidateInfo(
- context.getText(R.string.battery_saver_auto_percentage),
- /* summary */ null,
- KEY_PERCENTAGE,
- /* enabled */ true));
+ candidates.add(
+ new BatterySaverScheduleCandidateInfo(
+ context.getText(R.string.battery_saver_auto_percentage),
+ /* summary */ null,
+ KEY_PERCENTAGE,
+ /* enabled */ true));
return candidates;
}
@Override
- public void bindPreferenceExtra(SelectorWithWidgetPreference pref, String key,
- CandidateInfo info, String defaultKey, String systemDefaultKey) {
+ public void bindPreferenceExtra(
+ SelectorWithWidgetPreference pref,
+ String key,
+ CandidateInfo info,
+ String defaultKey,
+ String systemDefaultKey) {
final BatterySaverScheduleCandidateInfo candidateInfo =
(BatterySaverScheduleCandidateInfo) info;
final CharSequence summary = candidateInfo.getSummary();
@@ -174,14 +181,16 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
private void logPowerSaver() {
final int currentSaverPercentage = getSaverPercentage();
- final String currentSaverScheduleKey = BatterySaverUtils.getBatterySaverScheduleKey(
- mContext);
+ final String currentSaverScheduleKey =
+ BatterySaverUtils.getBatterySaverScheduleKey(mContext);
if (mSaverScheduleKey.equals(currentSaverScheduleKey)
&& mSaverPercentage == currentSaverPercentage) {
return;
}
- FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
- .action(SettingsEnums.FUELGAUGE_BATTERY_SAVER,
+ FeatureFactory.getFeatureFactory()
+ .getMetricsFeatureProvider()
+ .action(
+ SettingsEnums.FUELGAUGE_BATTERY_SAVER,
SettingsEnums.FIELD_BATTERY_SAVER_SCHEDULE_TYPE,
SettingsEnums.FIELD_BATTERY_SAVER_PERCENTAGE_VALUE,
currentSaverScheduleKey,
@@ -189,8 +198,8 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
}
private int getSaverPercentage() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, -1);
+ return Settings.Global.getInt(
+ mContext.getContentResolver(), Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, -1);
}
static class BatterySaverScheduleCandidateInfo extends CandidateInfo {
@@ -199,8 +208,8 @@ public class BatterySaverScheduleSettings extends RadioButtonPickerFragment {
private final CharSequence mSummary;
private final String mKey;
- BatterySaverScheduleCandidateInfo(CharSequence label, CharSequence summary, String key,
- boolean enabled) {
+ BatterySaverScheduleCandidateInfo(
+ CharSequence label, CharSequence summary, String key, boolean enabled) {
super(enabled);
mLabel = label;
mKey = key;
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java
index c86775f25a6..8e281de7bed 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java
@@ -28,9 +28,7 @@ import com.android.settingslib.HelpUtils;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.widget.FooterPreference;
-/**
- * Battery saver settings page
- */
+/** Battery saver settings page */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class BatterySaverSettings extends DashboardFragment {
private static final String TAG = "BatterySaverSettings";
@@ -63,9 +61,7 @@ public class BatterySaverSettings extends DashboardFragment {
return R.string.help_url_battery_saver_settings;
}
- /**
- * For Search.
- */
+ /** For Search. */
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.battery_saver_settings);
@@ -83,13 +79,17 @@ public class BatterySaverSettings extends DashboardFragment {
void addHelpLink() {
FooterPreference pref = getPreferenceScreen().findPreference(KEY_FOOTER_PREFERENCE);
if (pref != null) {
- pref.setLearnMoreAction(v -> {
- mMetricsFeatureProvider.action(getContext(),
- SettingsEnums.ACTION_APP_BATTERY_LEARN_MORE);
- startActivityForResult(HelpUtils.getHelpIntent(getContext(),
- getString(R.string.help_url_battery_saver_settings),
- /*backupContext=*/ ""), /*requestCode=*/ 0);
- });
+ pref.setLearnMoreAction(
+ v -> {
+ mMetricsFeatureProvider.action(
+ getContext(), SettingsEnums.ACTION_APP_BATTERY_LEARN_MORE);
+ startActivityForResult(
+ HelpUtils.getHelpIntent(
+ getContext(),
+ getString(R.string.help_url_battery_saver_settings),
+ /* backupContext= */ ""),
+ /* requestCode= */ 0);
+ });
pref.setLearnMoreText(getString(R.string.battery_saver_link_a11y));
}
}
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverStickyPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverStickyPreferenceController.java
index 0a39909f4d7..dea4e4d65ed 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverStickyPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverStickyPreferenceController.java
@@ -12,8 +12,8 @@ import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.TogglePreferenceController;
-public class BatterySaverStickyPreferenceController extends TogglePreferenceController implements
- PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+public class BatterySaverStickyPreferenceController extends TogglePreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final int DEFAULT_STICKY_SHUTOFF_LEVEL = 90;
private Context mContext;
@@ -25,34 +25,46 @@ public class BatterySaverStickyPreferenceController extends TogglePreferenceCont
@Override
public boolean isChecked() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED, 1) == 1;
+ return Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
+ 1)
+ == 1;
}
@Override
public boolean setChecked(boolean isChecked) {
- Settings.Global.putInt(mContext.getContentResolver(),
- Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
- isChecked ? 1 : 0);
+ Settings.Global.putInt(
+ mContext.getContentResolver(),
+ Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
+ isChecked ? 1 : 0);
return true;
}
@Override
protected void refreshSummary(Preference preference) {
super.refreshSummary(preference);
- final int stickyShutoffLevel = Settings.Global.getInt(mContext.getContentResolver(),
- Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL, DEFAULT_STICKY_SHUTOFF_LEVEL);
+ final int stickyShutoffLevel =
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
+ DEFAULT_STICKY_SHUTOFF_LEVEL);
final String formatPercentage = Utils.formatPercentage(stickyShutoffLevel);
- preference.setTitle(mContext.getString(R.string.battery_saver_sticky_title_percentage,
- formatPercentage));
- preference.setSummary(mContext.getString(R.string.battery_saver_sticky_description_new,
- formatPercentage));
+ preference.setTitle(
+ mContext.getString(
+ R.string.battery_saver_sticky_title_percentage, formatPercentage));
+ preference.setSummary(
+ mContext.getString(
+ R.string.battery_saver_sticky_description_new, formatPercentage));
}
@Override
public void updateState(Preference preference) {
- int setting = Settings.Global.getInt(mContext.getContentResolver(),
- Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED, 1);
+ int setting =
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
+ 1);
((TwoStatePreference) preference).setChecked(setting == 1);
refreshSummary(preference);
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobService.java
index bb73142b9be..0eaed178169 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyCleanupJobService.java
@@ -35,8 +35,7 @@ import java.util.concurrent.TimeUnit;
public class AnomalyCleanupJobService extends JobService {
private static final String TAG = "AnomalyCleanUpJobService";
- @VisibleForTesting
- static final long CLEAN_UP_FREQUENCY_MS = TimeUnit.DAYS.toMillis(1);
+ @VisibleForTesting static final long CLEAN_UP_FREQUENCY_MS = TimeUnit.DAYS.toMillis(1);
public static void scheduleCleanUp(Context context) {
final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
@@ -52,23 +51,24 @@ public class AnomalyCleanupJobService extends JobService {
// Don't schedule it if it already exists, to make sure it runs periodically even after
// reboot
- if (pending == null && jobScheduler.schedule(jobBuilder.build())
- != JobScheduler.RESULT_SUCCESS) {
+ if (pending == null
+ && jobScheduler.schedule(jobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
Log.i(TAG, "Anomaly clean up job service schedule failed.");
}
}
@Override
public boolean onStartJob(JobParameters params) {
- final BatteryDatabaseManager batteryDatabaseManager = BatteryDatabaseManager
- .getInstance(this);
+ final BatteryDatabaseManager batteryDatabaseManager =
+ BatteryDatabaseManager.getInstance(this);
final BatteryTipPolicy policy = new BatteryTipPolicy(this);
- ThreadUtils.postOnBackgroundThread(() -> {
- batteryDatabaseManager.deleteAllAnomaliesBeforeTimeStamp(
- System.currentTimeMillis() - TimeUnit.DAYS.toMillis(
- policy.dataHistoryRetainDay));
- jobFinished(params, false /* wantsReschedule */);
- });
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ batteryDatabaseManager.deleteAllAnomaliesBeforeTimeStamp(
+ System.currentTimeMillis()
+ - TimeUnit.DAYS.toMillis(policy.dataHistoryRetainDay));
+ jobFinished(params, false /* wantsReschedule */);
+ });
return true;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobService.java
index ad02c3a75b6..fe75c8e25a1 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigJobService.java
@@ -44,8 +44,7 @@ public class AnomalyConfigJobService extends JobService {
public static final String KEY_ANOMALY_CONFIG_VERSION = "anomaly_config_version";
private static final int DEFAULT_VERSION = 0;
- @VisibleForTesting
- static final long CONFIG_UPDATE_FREQUENCY_MS = TimeUnit.DAYS.toMillis(1);
+ @VisibleForTesting static final long CONFIG_UPDATE_FREQUENCY_MS = TimeUnit.DAYS.toMillis(1);
public static void scheduleConfigUpdate(Context context) {
final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
@@ -61,24 +60,25 @@ public class AnomalyConfigJobService extends JobService {
// Don't schedule it if it already exists, to make sure it runs periodically even after
// reboot
- if (pending == null && jobScheduler.schedule(jobBuilder.build())
- != JobScheduler.RESULT_SUCCESS) {
+ if (pending == null
+ && jobScheduler.schedule(jobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
Log.i(TAG, "Anomaly config update job service schedule failed.");
}
}
@Override
public boolean onStartJob(JobParameters params) {
- ThreadUtils.postOnBackgroundThread(() -> {
- final StatsManager statsManager = getSystemService(StatsManager.class);
- checkAnomalyConfig(statsManager);
- try {
- BatteryTipUtils.uploadAnomalyPendingIntent(this, statsManager);
- } catch (StatsManager.StatsUnavailableException e) {
- Log.w(TAG, "Failed to uploadAnomalyPendingIntent.", e);
- }
- jobFinished(params, false /* wantsReschedule */);
- });
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ final StatsManager statsManager = getSystemService(StatsManager.class);
+ checkAnomalyConfig(statsManager);
+ try {
+ BatteryTipUtils.uploadAnomalyPendingIntent(this, statsManager);
+ } catch (StatsManager.StatsUnavailableException e) {
+ Log.w(TAG, "Failed to uploadAnomalyPendingIntent.", e);
+ }
+ jobFinished(params, false /* wantsReschedule */);
+ });
return true;
}
@@ -90,37 +90,48 @@ public class AnomalyConfigJobService extends JobService {
@VisibleForTesting
synchronized void checkAnomalyConfig(StatsManager statsManager) {
- final SharedPreferences sharedPreferences = getSharedPreferences(PREF_DB,
- Context.MODE_PRIVATE);
- final int currentVersion = sharedPreferences.getInt(KEY_ANOMALY_CONFIG_VERSION,
- DEFAULT_VERSION);
- final int newVersion = Settings.Global.getInt(getContentResolver(),
- Settings.Global.ANOMALY_CONFIG_VERSION, DEFAULT_VERSION);
- final String rawConfig = Settings.Global.getString(getContentResolver(),
- Settings.Global.ANOMALY_CONFIG);
+ final SharedPreferences sharedPreferences =
+ getSharedPreferences(PREF_DB, Context.MODE_PRIVATE);
+ final int currentVersion =
+ sharedPreferences.getInt(KEY_ANOMALY_CONFIG_VERSION, DEFAULT_VERSION);
+ final int newVersion =
+ Settings.Global.getInt(
+ getContentResolver(),
+ Settings.Global.ANOMALY_CONFIG_VERSION,
+ DEFAULT_VERSION);
+ final String rawConfig =
+ Settings.Global.getString(getContentResolver(), Settings.Global.ANOMALY_CONFIG);
Log.i(TAG, "CurrentVersion: " + currentVersion + " new version: " + newVersion);
if (newVersion > currentVersion) {
try {
statsManager.removeConfig(StatsManagerConfig.ANOMALY_CONFIG_KEY);
} catch (StatsManager.StatsUnavailableException e) {
- Log.i(TAG, "When updating anomaly config, failed to first remove the old config "
- + StatsManagerConfig.ANOMALY_CONFIG_KEY, e);
+ Log.i(
+ TAG,
+ "When updating anomaly config, failed to first remove the old config "
+ + StatsManagerConfig.ANOMALY_CONFIG_KEY,
+ e);
}
if (!TextUtils.isEmpty(rawConfig)) {
try {
final byte[] config = Base64.decode(rawConfig, Base64.DEFAULT);
statsManager.addConfig(StatsManagerConfig.ANOMALY_CONFIG_KEY, config);
- Log.i(TAG, "Upload the anomaly config. configKey: "
- + StatsManagerConfig.ANOMALY_CONFIG_KEY);
+ Log.i(
+ TAG,
+ "Upload the anomaly config. configKey: "
+ + StatsManagerConfig.ANOMALY_CONFIG_KEY);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(KEY_ANOMALY_CONFIG_VERSION, newVersion);
editor.commit();
} catch (IllegalArgumentException e) {
Log.e(TAG, "Anomaly raw config is in wrong format", e);
} catch (StatsManager.StatsUnavailableException e) {
- Log.i(TAG, "Upload of anomaly config failed for configKey "
- + StatsManagerConfig.ANOMALY_CONFIG_KEY, e);
+ Log.i(
+ TAG,
+ "Upload of anomaly config failed for configKey "
+ + StatsManagerConfig.ANOMALY_CONFIG_KEY,
+ e);
}
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigReceiver.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigReceiver.java
index 369e61382db..538b0478b8d 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigReceiver.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigReceiver.java
@@ -23,8 +23,8 @@ import android.content.Intent;
import android.util.Log;
/**
- * Receive broadcast when {@link StatsManager} restart, then check the anomaly config and
- * prepare info for {@link StatsManager}
+ * Receive broadcast when {@link StatsManager} restart, then check the anomaly config and prepare
+ * info for {@link StatsManager}
*/
public class AnomalyConfigReceiver extends BroadcastReceiver {
private static final String TAG = "AnomalyConfigReceiver";
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDatabaseHelper.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDatabaseHelper.java
index 349a419ea27..6ec516e0fa5 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDatabaseHelper.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDatabaseHelper.java
@@ -26,9 +26,7 @@ import androidx.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-/**
- * Database controls the anomaly logging(e.g. packageName, anomalyType and time)
- */
+/** Database controls the anomaly logging(e.g. packageName, anomalyType and time) */
public class AnomalyDatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "BatteryDatabaseHelper";
@@ -36,9 +34,7 @@ public class AnomalyDatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 5;
@Retention(RetentionPolicy.SOURCE)
- @IntDef({State.NEW,
- State.HANDLED,
- State.AUTO_HANDLED})
+ @IntDef({State.NEW, State.HANDLED, State.AUTO_HANDLED})
public @interface State {
int NEW = 0;
int HANDLED = 1;
@@ -57,81 +53,92 @@ public class AnomalyDatabaseHelper extends SQLiteOpenHelper {
}
public interface AnomalyColumns {
- /**
- * The package name of the anomaly app
- */
+ /** The package name of the anomaly app */
String PACKAGE_NAME = "package_name";
- /**
- * The uid of the anomaly app
- */
+
+ /** The uid of the anomaly app */
String UID = "uid";
+
/**
* The type of the anomaly app
+ *
* @see StatsManagerConfig.AnomalyType
*/
String ANOMALY_TYPE = "anomaly_type";
+
/**
* The state of the anomaly app
+ *
* @see State
*/
String ANOMALY_STATE = "anomaly_state";
- /**
- * The time when anomaly happens
- */
+
+ /** The time when anomaly happens */
String TIME_STAMP_MS = "time_stamp_ms";
}
private static final String CREATE_ANOMALY_TABLE =
- "CREATE TABLE " + Tables.TABLE_ANOMALY +
- "(" +
- AnomalyColumns.UID +
- " INTEGER NOT NULL, " +
- AnomalyColumns.PACKAGE_NAME +
- " TEXT, " +
- AnomalyColumns.ANOMALY_TYPE +
- " INTEGER NOT NULL, " +
- AnomalyColumns.ANOMALY_STATE +
- " INTEGER NOT NULL, " +
- AnomalyColumns.TIME_STAMP_MS +
- " INTEGER NOT NULL, " +
- " PRIMARY KEY (" + AnomalyColumns.UID + "," + AnomalyColumns.ANOMALY_TYPE + ","
- + AnomalyColumns.ANOMALY_STATE + "," + AnomalyColumns.TIME_STAMP_MS + ")"
+ "CREATE TABLE "
+ + Tables.TABLE_ANOMALY
+ + "("
+ + AnomalyColumns.UID
+ + " INTEGER NOT NULL, "
+ + AnomalyColumns.PACKAGE_NAME
+ + " TEXT, "
+ + AnomalyColumns.ANOMALY_TYPE
+ + " INTEGER NOT NULL, "
+ + AnomalyColumns.ANOMALY_STATE
+ + " INTEGER NOT NULL, "
+ + AnomalyColumns.TIME_STAMP_MS
+ + " INTEGER NOT NULL, "
+ + " PRIMARY KEY ("
+ + AnomalyColumns.UID
+ + ","
+ + AnomalyColumns.ANOMALY_TYPE
+ + ","
+ + AnomalyColumns.ANOMALY_STATE
+ + ","
+ + AnomalyColumns.TIME_STAMP_MS
+ + ")"
+ ")";
-
public interface ActionColumns {
- /**
- * The package name of an app been performed an action
- */
+ /** The package name of an app been performed an action */
String PACKAGE_NAME = "package_name";
- /**
- * The uid of an app been performed an action
- */
+
+ /** The uid of an app been performed an action */
String UID = "uid";
+
/**
* The type of user action
+ *
* @see ActionType
*/
String ACTION_TYPE = "action_type";
- /**
- * The time when action been performed
- */
+
+ /** The time when action been performed */
String TIME_STAMP_MS = "time_stamp_ms";
}
private static final String CREATE_ACTION_TABLE =
- "CREATE TABLE " + Tables.TABLE_ACTION +
- "(" +
- ActionColumns.UID +
- " INTEGER NOT NULL, " +
- ActionColumns.PACKAGE_NAME +
- " TEXT, " +
- ActionColumns.ACTION_TYPE +
- " INTEGER NOT NULL, " +
- ActionColumns.TIME_STAMP_MS +
- " INTEGER NOT NULL, " +
- " PRIMARY KEY (" + ActionColumns.ACTION_TYPE + "," + ActionColumns.UID + ","
- + ActionColumns.PACKAGE_NAME + ")"
+ "CREATE TABLE "
+ + Tables.TABLE_ACTION
+ + "("
+ + ActionColumns.UID
+ + " INTEGER NOT NULL, "
+ + ActionColumns.PACKAGE_NAME
+ + " TEXT, "
+ + ActionColumns.ACTION_TYPE
+ + " INTEGER NOT NULL, "
+ + ActionColumns.TIME_STAMP_MS
+ + " INTEGER NOT NULL, "
+ + " PRIMARY KEY ("
+ + ActionColumns.ACTION_TYPE
+ + ","
+ + ActionColumns.UID
+ + ","
+ + ActionColumns.PACKAGE_NAME
+ + ")"
+ ")";
private static AnomalyDatabaseHelper sSingleton;
@@ -155,8 +162,14 @@ public class AnomalyDatabaseHelper extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < DATABASE_VERSION) {
- Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
- "Index needs to be rebuilt for schema version '" + newVersion + "'.");
+ Log.w(
+ TAG,
+ "Detected schema version '"
+ + oldVersion
+ + "'. "
+ + "Index needs to be rebuilt for schema version '"
+ + newVersion
+ + "'.");
// We need to drop the tables and recreate them
reconstruct(db);
}
@@ -164,8 +177,14 @@ public class AnomalyDatabaseHelper extends SQLiteOpenHelper {
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
- "Index needs to be rebuilt for schema version '" + newVersion + "'.");
+ Log.w(
+ TAG,
+ "Detected schema version '"
+ + oldVersion
+ + "'. "
+ + "Index needs to be rebuilt for schema version '"
+ + newVersion
+ + "'.");
// We need to drop the tables and recreate them
reconstruct(db);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 34fd72dbd71..b1018ba34cd 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -57,22 +57,20 @@ import java.util.concurrent.TimeUnit;
public class AnomalyDetectionJobService extends JobService {
private static final String TAG = "AnomalyDetectionService";
private static final int ON = 1;
- @VisibleForTesting
- static final int UID_NULL = -1;
- @VisibleForTesting
- static final int STATSD_UID_FILED = 1;
- @VisibleForTesting
- static final long MAX_DELAY_MS = TimeUnit.MINUTES.toMillis(30);
+ @VisibleForTesting static final int UID_NULL = -1;
+ @VisibleForTesting static final int STATSD_UID_FILED = 1;
+ @VisibleForTesting static final long MAX_DELAY_MS = TimeUnit.MINUTES.toMillis(30);
private final Object mLock = new Object();
+
@GuardedBy("mLock")
@VisibleForTesting
boolean mIsJobCanceled = false;
public static void scheduleAnomalyDetection(Context context, Intent intent) {
final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
- final ComponentName component = new ComponentName(context,
- AnomalyDetectionJobService.class);
+ final ComponentName component =
+ new ComponentName(context, AnomalyDetectionJobService.class);
final JobInfo.Builder jobBuilder =
new JobInfo.Builder(R.integer.job_anomaly_detection, component)
.setOverrideDeadline(MAX_DELAY_MS);
@@ -88,30 +86,40 @@ public class AnomalyDetectionJobService extends JobService {
synchronized (mLock) {
mIsJobCanceled = false;
}
- ThreadUtils.postOnBackgroundThread(() -> {
- final Context context = AnomalyDetectionJobService.this;
- final BatteryDatabaseManager batteryDatabaseManager =
- BatteryDatabaseManager.getInstance(this);
- final BatteryTipPolicy policy = new BatteryTipPolicy(this);
- final BatteryUtils batteryUtils = BatteryUtils.getInstance(this);
- final ContentResolver contentResolver = getContentResolver();
- final UserManager userManager = getSystemService(UserManager.class);
- final PowerAllowlistBackend powerAllowlistBackend =
- PowerAllowlistBackend.getInstance(context);
- final PowerUsageFeatureProvider powerUsageFeatureProvider =
- FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider();
- final MetricsFeatureProvider metricsFeatureProvider =
- FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ final Context context = AnomalyDetectionJobService.this;
+ final BatteryDatabaseManager batteryDatabaseManager =
+ BatteryDatabaseManager.getInstance(this);
+ final BatteryTipPolicy policy = new BatteryTipPolicy(this);
+ final BatteryUtils batteryUtils = BatteryUtils.getInstance(this);
+ final ContentResolver contentResolver = getContentResolver();
+ final UserManager userManager = getSystemService(UserManager.class);
+ final PowerAllowlistBackend powerAllowlistBackend =
+ PowerAllowlistBackend.getInstance(context);
+ final PowerUsageFeatureProvider powerUsageFeatureProvider =
+ FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider();
+ final MetricsFeatureProvider metricsFeatureProvider =
+ FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
- for (JobWorkItem item = dequeueWork(params); item != null; item = dequeueWork(params)) {
- saveAnomalyToDatabase(context, userManager,
- batteryDatabaseManager, batteryUtils, policy, powerAllowlistBackend,
- contentResolver, powerUsageFeatureProvider, metricsFeatureProvider,
- item.getIntent().getExtras());
+ for (JobWorkItem item = dequeueWork(params);
+ item != null;
+ item = dequeueWork(params)) {
+ saveAnomalyToDatabase(
+ context,
+ userManager,
+ batteryDatabaseManager,
+ batteryUtils,
+ policy,
+ powerAllowlistBackend,
+ contentResolver,
+ powerUsageFeatureProvider,
+ metricsFeatureProvider,
+ item.getIntent().getExtras());
- completeWork(params, item);
- }
- });
+ completeWork(params, item);
+ }
+ });
return true;
}
@@ -125,34 +133,49 @@ public class AnomalyDetectionJobService extends JobService {
}
@VisibleForTesting
- void saveAnomalyToDatabase(Context context, UserManager userManager,
- BatteryDatabaseManager databaseManager, BatteryUtils batteryUtils,
- BatteryTipPolicy policy, PowerAllowlistBackend powerAllowlistBackend,
- ContentResolver contentResolver, PowerUsageFeatureProvider powerUsageFeatureProvider,
- MetricsFeatureProvider metricsFeatureProvider, Bundle bundle) {
+ void saveAnomalyToDatabase(
+ Context context,
+ UserManager userManager,
+ BatteryDatabaseManager databaseManager,
+ BatteryUtils batteryUtils,
+ BatteryTipPolicy policy,
+ PowerAllowlistBackend powerAllowlistBackend,
+ ContentResolver contentResolver,
+ PowerUsageFeatureProvider powerUsageFeatureProvider,
+ MetricsFeatureProvider metricsFeatureProvider,
+ Bundle bundle) {
// The Example of intentDimsValue is: 35:{1:{1:{1:10013|}|}|}
final StatsDimensionsValue intentDimsValue =
bundle.getParcelable(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE);
- final long timeMs = bundle.getLong(AnomalyDetectionReceiver.KEY_ANOMALY_TIMESTAMP,
- System.currentTimeMillis());
- final ArrayList cookies = bundle.getStringArrayList(
- StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES);
- final AnomalyInfo anomalyInfo = new AnomalyInfo(
- !ArrayUtils.isEmpty(cookies) ? cookies.get(0) : "");
+ final long timeMs =
+ bundle.getLong(
+ AnomalyDetectionReceiver.KEY_ANOMALY_TIMESTAMP, System.currentTimeMillis());
+ final ArrayList cookies =
+ bundle.getStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES);
+ final AnomalyInfo anomalyInfo =
+ new AnomalyInfo(!ArrayUtils.isEmpty(cookies) ? cookies.get(0) : "");
Log.i(TAG, "Extra stats value: " + intentDimsValue.toString());
try {
final int uid = extractUidFromStatsDimensionsValue(intentDimsValue);
- final boolean autoFeatureOn = powerUsageFeatureProvider.isSmartBatterySupported()
- ? Settings.Global.getInt(contentResolver,
- Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON
- : Settings.Global.getInt(contentResolver,
- Settings.Global.APP_AUTO_RESTRICTION_ENABLED, ON) == ON;
+ final boolean autoFeatureOn =
+ powerUsageFeatureProvider.isSmartBatterySupported()
+ ? Settings.Global.getInt(
+ contentResolver,
+ Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED,
+ ON)
+ == ON
+ : Settings.Global.getInt(
+ contentResolver,
+ Settings.Global.APP_AUTO_RESTRICTION_ENABLED,
+ ON)
+ == ON;
final String packageName = batteryUtils.getPackageName(uid);
final long versionCode = batteryUtils.getAppLongVersionCode(packageName);
final String versionedPackage = packageName + "/" + versionCode;
if (batteryUtils.shouldHideAnomaly(powerAllowlistBackend, uid, anomalyInfo)) {
- metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
+ metricsFeatureProvider.action(
+ SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_ANOMALY_IGNORED,
SettingsEnums.PAGE_UNKNOWN,
versionedPackage,
@@ -160,17 +183,23 @@ public class AnomalyDetectionJobService extends JobService {
} else {
if (autoFeatureOn && anomalyInfo.autoRestriction) {
// Auto restrict this app
- batteryUtils.setForceAppStandby(uid, packageName,
- AppOpsManager.MODE_IGNORED);
- databaseManager.insertAnomaly(uid, packageName, anomalyInfo.anomalyType,
+ batteryUtils.setForceAppStandby(uid, packageName, AppOpsManager.MODE_IGNORED);
+ databaseManager.insertAnomaly(
+ uid,
+ packageName,
+ anomalyInfo.anomalyType,
AnomalyDatabaseHelper.State.AUTO_HANDLED,
timeMs);
} else {
- databaseManager.insertAnomaly(uid, packageName, anomalyInfo.anomalyType,
+ databaseManager.insertAnomaly(
+ uid,
+ packageName,
+ anomalyInfo.anomalyType,
AnomalyDatabaseHelper.State.NEW,
timeMs);
}
- metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
+ metricsFeatureProvider.action(
+ SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_ANOMALY_TRIGGERED,
SettingsEnums.PAGE_UNKNOWN,
versionedPackage,
@@ -183,12 +212,12 @@ public class AnomalyDetectionJobService extends JobService {
}
/**
- * Extract the uid from {@link StatsDimensionsValue}
- *
- * The uid dimension has the format: 1: inside the tuple list. Here are some examples:
- * 1. Excessive bg anomaly: 27:{1:10089|}
- * 2. Wakeup alarm anomaly: 35:{1:{1:{1:10013|}|}|}
- * 3. Bluetooth anomaly: 3:{1:{1:{1:10140|}|}|}
+ * Extract the uid from {@link StatsDimensionsValue}
+ *
+ * The uid dimension has the format: {1:int} inside the tuple list. Here are some examples:
+ * 1.Excessive bg anomaly: 27:{1:10089|}
+ * 2.Wakeup alarm anomaly: 35:{1:{1:{1:10013|}|}|}
+ * 3.Bluetooth anomaly: 3:{1:{1:{1:10140|}|}|}
*/
@VisibleForTesting
int extractUidFromStatsDimensionsValue(StatsDimensionsValue statsDimensionsValue) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionReceiver.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionReceiver.java
index b1bb73accec..0d43addfaa9 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionReceiver.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionReceiver.java
@@ -23,9 +23,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
-/**
- * Receive the anomaly info from {@link StatsManager}
- */
+/** Receive the anomaly info from {@link StatsManager} */
public class AnomalyDetectionReceiver extends BroadcastReceiver {
private static final String TAG = "SettingsAnomalyReceiver";
@@ -35,10 +33,16 @@ public class AnomalyDetectionReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final long configUid = intent.getLongExtra(StatsManager.EXTRA_STATS_CONFIG_UID, -1);
final long configKey = intent.getLongExtra(StatsManager.EXTRA_STATS_CONFIG_KEY, -1);
- final long subscriptionId = intent.getLongExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_ID,
- -1);
- Log.i(TAG, "Anomaly intent received. configUid = " + configUid + " configKey = "
- + configKey + " subscriptionId = " + subscriptionId);
+ final long subscriptionId =
+ intent.getLongExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_ID, -1);
+ Log.i(
+ TAG,
+ "Anomaly intent received. configUid = "
+ + configUid
+ + " configKey = "
+ + configKey
+ + " subscriptionId = "
+ + subscriptionId);
final Bundle bundle = intent.getExtras();
if (bundle == null) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyInfo.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyInfo.java
index fc157065103..da277c65cb3 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyInfo.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyInfo.java
@@ -19,9 +19,7 @@ package com.android.settings.fuelgauge.batterytip;
import android.util.KeyValueListParser;
import android.util.Log;
-/**
- * Model class to parse and store anomaly info from statsd.
- */
+/** Model class to parse and store anomaly info from statsd. */
public class AnomalyInfo {
private static final String TAG = "AnomalyInfo";
@@ -37,5 +35,4 @@ public class AnomalyInfo {
anomalyType = parser.getInt(KEY_ANOMALY_TYPE, -1);
autoRestriction = parser.getBoolean(KEY_AUTO_RESTRICTION, false);
}
-
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AppInfo.java b/src/com/android/settings/fuelgauge/batterytip/AppInfo.java
index e79b8745196..8166a3de58d 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AppInfo.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AppInfo.java
@@ -25,16 +25,17 @@ import androidx.annotation.VisibleForTesting;
import java.util.Objects;
-/**
- * Model class stores app info(e.g. package name, type..) that used in battery tip
- */
+/** Model class stores app info(e.g. package name, type..) that used in battery tip */
public class AppInfo implements Comparable, Parcelable {
public final String packageName;
+
/**
* Anomaly type of the app
+ *
* @see StatsManagerConfig.AnomalyType
*/
public final ArraySet anomalyTypes;
+
public final long screenOnTimeMs;
public final int uid;
@@ -73,7 +74,11 @@ public class AppInfo implements Comparable, Parcelable {
@Override
public String toString() {
- return "packageName=" + packageName + ",anomalyTypes=" + anomalyTypes + ",screenTime="
+ return "packageName="
+ + packageName
+ + ",anomalyTypes="
+ + anomalyTypes
+ + ",screenTime="
+ screenOnTimeMs;
}
@@ -93,15 +98,16 @@ public class AppInfo implements Comparable, Parcelable {
&& TextUtils.equals(packageName, other.packageName);
}
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public AppInfo createFromParcel(Parcel in) {
- return new AppInfo(in);
- }
+ public static final Parcelable.Creator CREATOR =
+ new Parcelable.Creator() {
+ public AppInfo createFromParcel(Parcel in) {
+ return new AppInfo(in);
+ }
- public AppInfo[] newArray(int size) {
- return new AppInfo[size];
- }
- };
+ public AppInfo[] newArray(int size) {
+ return new AppInfo[size];
+ }
+ };
public static final class Builder {
private ArraySet mAnomalyTypes = new ArraySet<>();
@@ -133,4 +139,4 @@ public class AppInfo implements Comparable, Parcelable {
return new AppInfo(this);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java b/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java
index bb6999949cd..2b0ba45c681 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java
@@ -47,8 +47,8 @@ import java.util.Map;
/**
* Database manager for battery data. Now it only contains anomaly data stored in {@link AppInfo}.
*
- * This manager may be accessed by multi-threads. All the database related methods are synchronized
- * so each operation won't be interfered by other threads.
+ * This manager may be accessed by multi-threads. All the database related methods are
+ * synchronized so each operation won't be interfered by other threads.
*/
public class BatteryDatabaseManager {
private static BatteryDatabaseManager sSingleton;
@@ -74,16 +74,15 @@ public class BatteryDatabaseManager {
/**
* Insert an anomaly log to database.
*
- * @param uid the uid of the app
- * @param packageName the package name of the app
- * @param type the type of the anomaly
+ * @param uid the uid of the app
+ * @param packageName the package name of the app
+ * @param type the type of the anomaly
* @param anomalyState the state of the anomaly
- * @param timestampMs the time when it is happened
+ * @param timestampMs the time when it is happened
* @return {@code true} if insert operation succeed
*/
- public synchronized boolean insertAnomaly(int uid, String packageName, int type,
- int anomalyState,
- long timestampMs) {
+ public synchronized boolean insertAnomaly(
+ int uid, String packageName, int type, int anomalyState, long timestampMs) {
final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(UID, uid);
@@ -105,22 +104,31 @@ public class BatteryDatabaseManager {
final String orderBy = AnomalyDatabaseHelper.AnomalyColumns.TIME_STAMP_MS + " DESC";
final Map mAppInfoBuilders = new ArrayMap<>();
final String selection = TIME_STAMP_MS + " > ? AND " + ANOMALY_STATE + " = ? ";
- final String[] selectionArgs = new String[]{String.valueOf(timestampMsAfter),
- String.valueOf(state)};
+ final String[] selectionArgs =
+ new String[] {String.valueOf(timestampMsAfter), String.valueOf(state)};
- try (Cursor cursor = db.query(TABLE_ANOMALY, projection, selection, selectionArgs,
- null /* groupBy */, null /* having */, orderBy)) {
+ try (Cursor cursor =
+ db.query(
+ TABLE_ANOMALY,
+ projection,
+ selection,
+ selectionArgs,
+ null /* groupBy */,
+ null /* having */,
+ orderBy)) {
while (cursor.moveToNext()) {
final int uid = cursor.getInt(cursor.getColumnIndex(UID));
if (!mAppInfoBuilders.containsKey(uid)) {
- final AppInfo.Builder builder = new AppInfo.Builder()
- .setUid(uid)
- .setPackageName(
- cursor.getString(cursor.getColumnIndex(PACKAGE_NAME)));
+ final AppInfo.Builder builder =
+ new AppInfo.Builder()
+ .setUid(uid)
+ .setPackageName(
+ cursor.getString(cursor.getColumnIndex(PACKAGE_NAME)));
mAppInfoBuilders.put(uid, builder);
}
- mAppInfoBuilders.get(uid).addAnomalyType(
- cursor.getInt(cursor.getColumnIndex(ANOMALY_TYPE)));
+ mAppInfoBuilders
+ .get(uid)
+ .addAnomalyType(cursor.getInt(cursor.getColumnIndex(ANOMALY_TYPE)));
}
}
@@ -133,15 +141,15 @@ public class BatteryDatabaseManager {
public synchronized void deleteAllAnomaliesBeforeTimeStamp(long timestampMs) {
final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
- db.delete(TABLE_ANOMALY, TIME_STAMP_MS + " < ?",
- new String[]{String.valueOf(timestampMs)});
+ db.delete(
+ TABLE_ANOMALY, TIME_STAMP_MS + " < ?", new String[] {String.valueOf(timestampMs)});
}
/**
* Update the type of anomalies to {@code state}
*
* @param appInfos represents the anomalies
- * @param state which state to update to
+ * @param state which state to update to
*/
public synchronized void updateAnomalies(List appInfos, int state) {
if (!appInfos.isEmpty()) {
@@ -154,8 +162,14 @@ public class BatteryDatabaseManager {
final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(ANOMALY_STATE, state);
- db.update(TABLE_ANOMALY, values, PACKAGE_NAME + " IN (" + TextUtils.join(",",
- Collections.nCopies(appInfos.size(), "?")) + ")", whereArgs);
+ db.update(
+ TABLE_ANOMALY,
+ values,
+ PACKAGE_NAME
+ + " IN ("
+ + TextUtils.join(",", Collections.nCopies(appInfos.size(), "?"))
+ + ")",
+ whereArgs);
}
}
@@ -171,10 +185,17 @@ public class BatteryDatabaseManager {
final SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
final String[] projection = {ActionColumns.UID, ActionColumns.TIME_STAMP_MS};
final String selection = ActionColumns.ACTION_TYPE + " = ? ";
- final String[] selectionArgs = new String[]{String.valueOf(type)};
+ final String[] selectionArgs = new String[] {String.valueOf(type)};
- try (Cursor cursor = db.query(TABLE_ACTION, projection, selection, selectionArgs,
- null /* groupBy */, null /* having */, null /* orderBy */)) {
+ try (Cursor cursor =
+ db.query(
+ TABLE_ACTION,
+ projection,
+ selection,
+ selectionArgs,
+ null /* groupBy */,
+ null /* having */,
+ null /* orderBy */)) {
final int uidIndex = cursor.getColumnIndex(ActionColumns.UID);
final int timestampIndex = cursor.getColumnIndex(ActionColumns.TIME_STAMP_MS);
@@ -188,11 +209,12 @@ public class BatteryDatabaseManager {
return timeStamps;
}
- /**
- * Insert an action, or update it if already existed
- */
- public synchronized boolean insertAction(@AnomalyDatabaseHelper.ActionType int type,
- int uid, String packageName, long timestampMs) {
+ /** Insert an action, or update it if already existed */
+ public synchronized boolean insertAction(
+ @AnomalyDatabaseHelper.ActionType int type,
+ int uid,
+ String packageName,
+ long timestampMs) {
final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(ActionColumns.UID, uid);
@@ -203,17 +225,21 @@ public class BatteryDatabaseManager {
return db.insertWithOnConflict(TABLE_ACTION, null, values, CONFLICT_REPLACE) != -1;
}
- /**
- * Remove an action
- */
- public synchronized boolean deleteAction(@AnomalyDatabaseHelper.ActionType int type,
- int uid, String packageName) {
+ /** Remove an action */
+ public synchronized boolean deleteAction(
+ @AnomalyDatabaseHelper.ActionType int type, int uid, String packageName) {
SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
final String where =
- ActionColumns.ACTION_TYPE + " = ? AND " + ActionColumns.UID + " = ? AND "
- + ActionColumns.PACKAGE_NAME + " = ? ";
- final String[] whereArgs = new String[]{String.valueOf(type), String.valueOf(uid),
- String.valueOf(packageName)};
+ ActionColumns.ACTION_TYPE
+ + " = ? AND "
+ + ActionColumns.UID
+ + " = ? AND "
+ + ActionColumns.PACKAGE_NAME
+ + " = ? ";
+ final String[] whereArgs =
+ new String[] {
+ String.valueOf(type), String.valueOf(uid), String.valueOf(packageName)
+ };
return db.delete(TABLE_ACTION, where, whereArgs) != 0;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
index 3989e892818..73b7523e8a9 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -46,19 +46,15 @@ import com.android.settingslib.utils.StringUtil;
import java.util.List;
-/**
- * Dialog Fragment to show action dialog for each anomaly
- */
-public class BatteryTipDialogFragment extends InstrumentedDialogFragment implements
- DialogInterface.OnClickListener {
+/** Dialog Fragment to show action dialog for each anomaly */
+public class BatteryTipDialogFragment extends InstrumentedDialogFragment
+ implements DialogInterface.OnClickListener {
private static final String ARG_BATTERY_TIP = "battery_tip";
private static final String ARG_METRICS_KEY = "metrics_key";
- @VisibleForTesting
- BatteryTip mBatteryTip;
- @VisibleForTesting
- int mMetricsKey;
+ @VisibleForTesting BatteryTip mBatteryTip;
+ @VisibleForTesting int mMetricsKey;
public static BatteryTipDialogFragment newInstance(BatteryTip batteryTip, int metricsKey) {
BatteryTipDialogFragment dialogFragment = new BatteryTipDialogFragment();
@@ -87,16 +83,17 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
.create();
case BatteryTip.TipType.HIGH_DEVICE_USAGE:
final HighUsageTip highUsageTip = (HighUsageTip) mBatteryTip;
- final RecyclerView view = (RecyclerView) LayoutInflater.from(context).inflate(
- R.layout.recycler_view,
- null);
+ final RecyclerView view =
+ (RecyclerView)
+ LayoutInflater.from(context).inflate(R.layout.recycler_view, null);
view.setLayoutManager(new LinearLayoutManager(context));
- view.setAdapter(new HighUsageAdapter(context,
- highUsageTip.getHighUsageAppList()));
+ view.setAdapter(new HighUsageAdapter(context, highUsageTip.getHighUsageAppList()));
return new AlertDialog.Builder(context)
- .setMessage(getString(R.string.battery_tip_dialog_message,
- highUsageTip.getHighUsageAppList().size()))
+ .setMessage(
+ getString(
+ R.string.battery_tip_dialog_message,
+ highUsageTip.getHighUsageAppList().size()))
.setView(view)
.setPositiveButton(android.R.string.ok, null)
.create();
@@ -104,14 +101,19 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
final RestrictAppTip restrictAppTip = (RestrictAppTip) mBatteryTip;
final List restrictedAppList = restrictAppTip.getRestrictAppList();
final int num = restrictedAppList.size();
- final CharSequence appLabel = Utils.getApplicationLabel(context,
- restrictedAppList.get(0).packageName);
+ final CharSequence appLabel =
+ Utils.getApplicationLabel(context, restrictedAppList.get(0).packageName);
- final AlertDialog.Builder builder = new AlertDialog.Builder(context)
- .setTitle(StringUtil.getIcuPluralsString(context, num,
- R.string.battery_tip_restrict_app_dialog_title))
- .setPositiveButton(R.string.battery_tip_restrict_app_dialog_ok, this)
- .setNegativeButton(android.R.string.cancel, null);
+ final AlertDialog.Builder builder =
+ new AlertDialog.Builder(context)
+ .setTitle(
+ StringUtil.getIcuPluralsString(
+ context,
+ num,
+ R.string.battery_tip_restrict_app_dialog_title))
+ .setPositiveButton(
+ R.string.battery_tip_restrict_app_dialog_ok, this)
+ .setNegativeButton(android.R.string.cancel, null);
if (num == 1) {
builder.setMessage(
getString(R.string.battery_tip_restrict_app_dialog_message, appLabel));
@@ -119,22 +121,25 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
builder.setMessage(
getString(
R.string.battery_tip_restrict_apps_less_than_5_dialog_message));
- final RecyclerView restrictionView = (RecyclerView) LayoutInflater.from(
- context).inflate(R.layout.recycler_view, null);
+ final RecyclerView restrictionView =
+ (RecyclerView)
+ LayoutInflater.from(context)
+ .inflate(R.layout.recycler_view, null);
restrictionView.setLayoutManager(new LinearLayoutManager(context));
restrictionView.setAdapter(new HighUsageAdapter(context, restrictedAppList));
builder.setView(restrictionView);
} else {
- builder.setMessage(context.getString(
- R.string.battery_tip_restrict_apps_more_than_5_dialog_message,
- restrictAppTip.getRestrictAppsString(context)));
+ builder.setMessage(
+ context.getString(
+ R.string.battery_tip_restrict_apps_more_than_5_dialog_message,
+ restrictAppTip.getRestrictAppsString(context)));
}
return builder.create();
case BatteryTip.TipType.REMOVE_APP_RESTRICTION:
final UnrestrictAppTip unrestrictAppTip = (UnrestrictAppTip) mBatteryTip;
- final CharSequence name = Utils.getApplicationLabel(context,
- unrestrictAppTip.getPackageName());
+ final CharSequence name =
+ Utils.getApplicationLabel(context, unrestrictAppTip.getPackageName());
return new AlertDialog.Builder(context)
.setTitle(getString(R.string.battery_tip_unrestrict_app_dialog_title))
@@ -158,9 +163,11 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
if (lsn == null) {
return;
}
- final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(mBatteryTip,
- (SettingsActivity) getActivity(),
- (InstrumentedPreferenceFragment) getTargetFragment());
+ final BatteryTipAction action =
+ BatteryTipUtils.getActionForBatteryTip(
+ mBatteryTip,
+ (SettingsActivity) getActivity(),
+ (InstrumentedPreferenceFragment) getTargetFragment());
if (action != null) {
action.handlePositiveAction(mMetricsKey);
}
@@ -168,10 +175,12 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
}
private boolean isPluggedIn() {
- final Intent batteryIntent = getContext().registerReceiver(null /* receiver */,
- new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
- return batteryIntent != null && batteryIntent.getIntExtra(
- BatteryManager.EXTRA_PLUGGED, 0) != 0;
+ final Intent batteryIntent =
+ getContext()
+ .registerReceiver(
+ null /* receiver */,
+ new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ return batteryIntent != null
+ && batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
}
-
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
index 34c431a846c..9fc0ce1a1f8 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
@@ -29,10 +29,7 @@ import com.android.settings.fuelgauge.batterytip.detectors.DockDefenderDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.IncompatibleChargerDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
-import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
-import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
-import com.android.settingslib.fuelgauge.EstimateKt;
import com.android.settingslib.utils.AsyncLoaderCompat;
import java.util.ArrayList;
@@ -47,8 +44,7 @@ public class BatteryTipLoader extends AsyncLoaderCompat> {
private static final String TAG = "BatteryTipLoader";
private BatteryUsageStats mBatteryUsageStats;
- @VisibleForTesting
- BatteryUtils mBatteryUtils;
+ @VisibleForTesting BatteryUtils mBatteryUtils;
public BatteryTipLoader(Context context, BatteryUsageStats batteryUsageStats) {
super(context);
@@ -75,6 +71,5 @@ public class BatteryTipLoader extends AsyncLoaderCompat> {
}
@Override
- protected void onDiscardResult(List result) {
- }
+ protected void onDiscardResult(List result) {}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java
index 3fbbf5b5f81..2feaad55da6 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java
@@ -25,10 +25,7 @@ import androidx.annotation.VisibleForTesting;
import java.time.Duration;
-/**
- * Class to store the policy for battery tips, which comes from
- * {@link Settings.Global}
- */
+/** Class to store the policy for battery tips, which comes from {@link Settings.Global} */
public class BatteryTipPolicy {
public static final String TAG = "BatteryTipPolicy";
@@ -102,9 +99,9 @@ public class BatteryTipPolicy {
public final long highUsagePeriodMs;
/**
- * The battery draining threshold to detect whether device is heavily used.
- * If battery drains more than {@link #highUsageBatteryDraining} in last {@link
- * #highUsagePeriodMs}, treat device as heavily used.
+ * The battery draining threshold to detect whether device is heavily used. If battery drains
+ * more than {@link #highUsageBatteryDraining} in last {@link #highUsagePeriodMs}, treat device
+ * as heavily used.
*
* @see Settings.Global#BATTERY_TIP_CONSTANTS
* @see #KEY_HIGH_USAGE_BATTERY_DRAINING
@@ -171,8 +168,8 @@ public class BatteryTipPolicy {
/**
* Battery drain percentage threshold for excessive background anomaly(i.e. 10%)
*
- * This is an additional check for excessive background, to check whether battery drain
- * for an app is larger than x%
+ * This is an additional check for excessive background, to check whether battery drain for
+ * an app is larger than x%
*
* @see Settings.Global#BATTERY_TIP_CONSTANTS
* @see #KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE
@@ -220,8 +217,9 @@ public class BatteryTipPolicy {
@VisibleForTesting
BatteryTipPolicy(Context context, KeyValueListParser parser) {
mParser = parser;
- final String value = Settings.Global.getString(context.getContentResolver(),
- Settings.Global.BATTERY_TIP_CONSTANTS);
+ final String value =
+ Settings.Global.getString(
+ context.getContentResolver(), Settings.Global.BATTERY_TIP_CONSTANTS);
try {
mParser.setString(value);
@@ -234,8 +232,8 @@ public class BatteryTipPolicy {
batterySaverTipEnabled = mParser.getBoolean(KEY_BATTERY_SAVER_TIP_ENABLED, true);
highUsageEnabled = mParser.getBoolean(KEY_HIGH_USAGE_ENABLED, true);
highUsageAppCount = mParser.getInt(KEY_HIGH_USAGE_APP_COUNT, 3);
- highUsagePeriodMs = mParser.getLong(KEY_HIGH_USAGE_PERIOD_MS,
- Duration.ofHours(2).toMillis());
+ highUsagePeriodMs =
+ mParser.getLong(KEY_HIGH_USAGE_PERIOD_MS, Duration.ofHours(2).toMillis());
highUsageBatteryDraining = mParser.getInt(KEY_HIGH_USAGE_BATTERY_DRAINING, 25);
appRestrictionEnabled = mParser.getBoolean(KEY_APP_RESTRICTION_ENABLED, true);
appRestrictionActiveHour = mParser.getInt(KEY_APP_RESTRICTION_ACTIVE_HOUR, 24);
@@ -251,5 +249,4 @@ public class BatteryTipPolicy {
testSmartBatteryTip = mParser.getBoolean(KEY_TEST_SMART_BATTERY_TIP, false);
testLowBatteryTip = mParser.getBoolean(KEY_TEST_LOW_BATTERY_TIP, false);
}
-
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
index 4b1f645a56d..57dd5784a81 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
@@ -40,9 +40,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
-/**
- * Controller in charge of the battery tip group
- */
+/** Controller in charge of the battery tip group */
public class BatteryTipPreferenceController extends BasePreferenceController {
public static final String PREF_NAME = "battery_tip";
@@ -57,10 +55,8 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
private SettingsActivity mSettingsActivity;
private MetricsFeatureProvider mMetricsFeatureProvider;
private boolean mNeedUpdate;
- @VisibleForTesting
- CardPreference mCardPreference;
- @VisibleForTesting
- Context mPrefContext;
+ @VisibleForTesting CardPreference mCardPreference;
+ @VisibleForTesting Context mPrefContext;
InstrumentedPreferenceFragment mFragment;
public BatteryTipPreferenceController(Context context, String preferenceKey) {
@@ -122,13 +118,15 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
final BatteryTip batteryTip = mBatteryTipMap.get(preference.getKey());
if (batteryTip != null) {
if (batteryTip.shouldShowDialog()) {
- BatteryTipDialogFragment dialogFragment = BatteryTipDialogFragment.newInstance(
- batteryTip, mFragment.getMetricsCategory());
+ BatteryTipDialogFragment dialogFragment =
+ BatteryTipDialogFragment.newInstance(
+ batteryTip, mFragment.getMetricsCategory());
dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
} else {
- final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(batteryTip,
- mSettingsActivity, mFragment);
+ final BatteryTipAction action =
+ BatteryTipUtils.getActionForBatteryTip(
+ batteryTip, mSettingsActivity, mFragment);
if (action != null) {
action.handlePositiveAction(mFragment.getMetricsCategory());
}
@@ -183,13 +181,11 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
return visibleBatteryTip.orElse(null);
}
- /**
- * Listener to give the control back to target fragment
- */
+ /** Listener to give the control back to target fragment */
public interface BatteryTipListener {
/**
- * This method is invoked once battery tip is handled, then target fragment could do
- * extra work.
+ * This method is invoked once battery tip is handled, then target fragment could do extra
+ * work.
*
* @param batteryTip that has been handled
*/
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
index 61e0fb1b110..d65bd269413 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
@@ -48,15 +48,13 @@ import java.util.List;
public class BatteryTipUtils {
private static final int REQUEST_CODE = 0;
- /**
- * Get a list of restricted apps with {@link AppOpsManager#OP_RUN_ANY_IN_BACKGROUND}
- */
+ /** Get a list of restricted apps with {@link AppOpsManager#OP_RUN_ANY_IN_BACKGROUND} */
@NonNull
- public static List getRestrictedAppsList(AppOpsManager appOpsManager,
- UserManager userManager) {
+ public static List getRestrictedAppsList(
+ AppOpsManager appOpsManager, UserManager userManager) {
final List userHandles = userManager.getUserProfiles();
- final List packageOpsList = appOpsManager.getPackagesForOps(
- new int[]{AppOpsManager.OP_RUN_ANY_IN_BACKGROUND});
+ final List packageOpsList =
+ appOpsManager.getPackagesForOps(new int[] {AppOpsManager.OP_RUN_ANY_IN_BACKGROUND});
final List appInfos = new ArrayList<>();
for (int i = 0, size = CollectionUtils.size(packageOpsList); i < size; i++) {
@@ -69,11 +67,12 @@ public class BatteryTipUtils {
}
if (entry.getMode() != AppOpsManager.MODE_ALLOWED
&& userHandles.contains(
- new UserHandle(UserHandle.getUserId(packageOps.getUid())))) {
- appInfos.add(new AppInfo.Builder()
- .setPackageName(packageOps.getPackageName())
- .setUid(packageOps.getUid())
- .build());
+ new UserHandle(UserHandle.getUserId(packageOps.getUid())))) {
+ appInfos.add(
+ new AppInfo.Builder()
+ .setPackageName(packageOps.getPackageName())
+ .setUid(packageOps.getUid())
+ .build());
}
}
}
@@ -89,8 +88,10 @@ public class BatteryTipUtils {
* @param fragment used to populate {@link BatteryTipAction}
* @return an action for {@code batteryTip}
*/
- public static BatteryTipAction getActionForBatteryTip(BatteryTip batteryTip,
- SettingsActivity settingsActivity, InstrumentedPreferenceFragment fragment) {
+ public static BatteryTipAction getActionForBatteryTip(
+ BatteryTip batteryTip,
+ SettingsActivity settingsActivity,
+ InstrumentedPreferenceFragment fragment) {
switch (batteryTip.getType()) {
case BatteryTip.TipType.SMART_BATTERY_MANAGER:
return new SmartBatteryAction(settingsActivity, fragment);
@@ -112,26 +113,33 @@ public class BatteryTipUtils {
/**
* Upload the {@link PendingIntent} to {@link StatsManager} for anomaly detection
+ *
* @throws StatsManager.StatsUnavailableException if failed to communicate with stats service
*/
public static void uploadAnomalyPendingIntent(Context context, StatsManager statsManager)
throws StatsManager.StatsUnavailableException {
final Intent extraIntent = new Intent(context, AnomalyDetectionReceiver.class);
- final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE,
- extraIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
- statsManager.setBroadcastSubscriber(pendingIntent,
- StatsManagerConfig.ANOMALY_CONFIG_KEY, StatsManagerConfig.SUBSCRIBER_ID);
+ final PendingIntent pendingIntent =
+ PendingIntent.getBroadcast(
+ context,
+ REQUEST_CODE,
+ extraIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
+ statsManager.setBroadcastSubscriber(
+ pendingIntent,
+ StatsManagerConfig.ANOMALY_CONFIG_KEY,
+ StatsManagerConfig.SUBSCRIBER_ID);
}
- /**
- * Detect and return anomaly apps after {@code timeAfterMs}
- */
+ /** Detect and return anomaly apps after {@code timeAfterMs} */
public static List detectAnomalies(Context context, long timeAfterMs) {
- final List highUsageApps = BatteryDatabaseManager.getInstance(context)
- .queryAllAnomalies(timeAfterMs, AnomalyDatabaseHelper.State.NEW);
+ final List highUsageApps =
+ BatteryDatabaseManager.getInstance(context)
+ .queryAllAnomalies(timeAfterMs, AnomalyDatabaseHelper.State.NEW);
// Remove it if it doesn't have label or been restricted
- highUsageApps.removeIf(AppLabelPredicate.getInstance(context)
- .or(AppRestrictionPredicate.getInstance(context)));
+ highUsageApps.removeIf(
+ AppLabelPredicate.getInstance(context)
+ .or(AppRestrictionPredicate.getInstance(context)));
return highUsageApps;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java b/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
index cb7b14ed8a8..3f8f8e133a9 100644
--- a/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
+++ b/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
@@ -33,9 +33,7 @@ import com.android.settings.Utils;
import java.util.List;
-/**
- * Adapter for the high usage app list
- */
+/** Adapter for the high usage app list */
public class HighUsageAdapter extends RecyclerView.Adapter {
private final Context mContext;
private final IconDrawableFactory mIconDrawableFactory;
@@ -66,8 +64,8 @@ public class HighUsageAdapter extends RecyclerView.Adapter mThreshold;
}
}
-
diff --git a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
index 153aa408698..e18d11dc5eb 100644
--- a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
+++ b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
@@ -21,244 +21,197 @@ import androidx.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-/**
- * This class provides all the configs needed if we want to use {@link android.app.StatsManager}
- */
+/** This class provides all the configs needed if we want to use {@link android.app.StatsManager} */
public class StatsManagerConfig {
/**
- * The key that represents the anomaly config.
- * This value is used in {@link android.app.StatsManager#addConfig(long, byte[])}
+ * The key that represents the anomaly config. This value is used in {@link
+ * android.app.StatsManager#addConfig(long, byte[])}
*/
public static final long ANOMALY_CONFIG_KEY = 1;
- /**
- * The key that represents subscriber, which is settings app.
- */
+ /** The key that represents subscriber, which is settings app. */
public static final long SUBSCRIBER_ID = 1;
@Retention(RetentionPolicy.SOURCE)
- @IntDef({AnomalyType.NULL,
- AnomalyType.UNKNOWN_REASON,
- AnomalyType.EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF,
- AnomalyType.EXCESSIVE_WAKEUPS_IN_BACKGROUND,
- AnomalyType.EXCESSIVE_UNOPTIMIZED_BLE_SCAN,
- AnomalyType.EXCESSIVE_BACKGROUND_SERVICE,
- AnomalyType.EXCESSIVE_WIFI_SCAN,
- AnomalyType.EXCESSIVE_FLASH_WRITES,
- AnomalyType.EXCESSIVE_MEMORY_IN_BACKGROUND,
- AnomalyType.EXCESSIVE_DAVEY_RATE,
- AnomalyType.EXCESSIVE_JANKY_FRAMES,
- AnomalyType.SLOW_COLD_START_TIME,
- AnomalyType.SLOW_HOT_START_TIME,
- AnomalyType.SLOW_WARM_START_TIME,
- AnomalyType.EXCESSIVE_BACKGROUND_SYNCS,
- AnomalyType.EXCESSIVE_GPS_SCANS_IN_BACKGROUND,
- AnomalyType.EXCESSIVE_JOB_SCHEDULING,
- AnomalyType.EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND,
- AnomalyType.EXCESSIVE_WIFI_LOCK_TIME,
- AnomalyType.JOB_TIMED_OUT,
- AnomalyType.LONG_UNOPTIMIZED_BLE_SCAN,
- AnomalyType.BACKGROUND_ANR,
- AnomalyType.BACKGROUND_CRASH_RATE,
- AnomalyType.EXCESSIVE_ANR_LOOPING,
- AnomalyType.EXCESSIVE_ANRS,
- AnomalyType.EXCESSIVE_CRASH_RATE,
- AnomalyType.EXCESSIVE_CRASH_LOOPING,
- AnomalyType.NUMBER_OF_OPEN_FILES,
- AnomalyType.EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND,
- AnomalyType.EXCESSIVE_CONTACT_ACCESS,
- AnomalyType.EXCESSIVE_AUDIO_IN_BACKGROUND,
- AnomalyType.EXCESSIVE_CRASH_ANR_IN_BACKGROUND,
- AnomalyType.BATTERY_DRAIN_FROM_UNUSED_APP,
+ @IntDef({
+ AnomalyType.NULL,
+ AnomalyType.UNKNOWN_REASON,
+ AnomalyType.EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF,
+ AnomalyType.EXCESSIVE_WAKEUPS_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_UNOPTIMIZED_BLE_SCAN,
+ AnomalyType.EXCESSIVE_BACKGROUND_SERVICE,
+ AnomalyType.EXCESSIVE_WIFI_SCAN,
+ AnomalyType.EXCESSIVE_FLASH_WRITES,
+ AnomalyType.EXCESSIVE_MEMORY_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_DAVEY_RATE,
+ AnomalyType.EXCESSIVE_JANKY_FRAMES,
+ AnomalyType.SLOW_COLD_START_TIME,
+ AnomalyType.SLOW_HOT_START_TIME,
+ AnomalyType.SLOW_WARM_START_TIME,
+ AnomalyType.EXCESSIVE_BACKGROUND_SYNCS,
+ AnomalyType.EXCESSIVE_GPS_SCANS_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_JOB_SCHEDULING,
+ AnomalyType.EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_WIFI_LOCK_TIME,
+ AnomalyType.JOB_TIMED_OUT,
+ AnomalyType.LONG_UNOPTIMIZED_BLE_SCAN,
+ AnomalyType.BACKGROUND_ANR,
+ AnomalyType.BACKGROUND_CRASH_RATE,
+ AnomalyType.EXCESSIVE_ANR_LOOPING,
+ AnomalyType.EXCESSIVE_ANRS,
+ AnomalyType.EXCESSIVE_CRASH_RATE,
+ AnomalyType.EXCESSIVE_CRASH_LOOPING,
+ AnomalyType.NUMBER_OF_OPEN_FILES,
+ AnomalyType.EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_CONTACT_ACCESS,
+ AnomalyType.EXCESSIVE_AUDIO_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_CRASH_ANR_IN_BACKGROUND,
+ AnomalyType.BATTERY_DRAIN_FROM_UNUSED_APP,
})
public @interface AnomalyType {
- /**
- * This represents an error condition in the anomaly detection.
- */
+ /** This represents an error condition in the anomaly detection. */
int NULL = -1;
- /**
- * The anomaly type does not match any other defined type.
- */
+ /** The anomaly type does not match any other defined type. */
int UNKNOWN_REASON = 0;
/**
- * The application held a partial (screen off) wake lock for a period of time that
- * exceeded the threshold with the screen off when not charging.
+ * The application held a partial (screen off) wake lock for a period of time that exceeded
+ * the threshold with the screen off when not charging.
*/
int EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF = 1;
/**
- * The application exceeded the maximum number of wakeups while in the background
- * when not charging.
+ * The application exceeded the maximum number of wakeups while in the background when not
+ * charging.
*/
int EXCESSIVE_WAKEUPS_IN_BACKGROUND = 2;
- /**
- * The application did unoptimized Bluetooth scans too frequently when not charging.
- */
+ /** The application did unoptimized Bluetooth scans too frequently when not charging. */
int EXCESSIVE_UNOPTIMIZED_BLE_SCAN = 3;
/**
- * The application ran in the background for a period of time that exceeded the
- * threshold.
+ * The application ran in the background for a period of time that exceeded the threshold.
*/
int EXCESSIVE_BACKGROUND_SERVICE = 4;
- /**
- * The application exceeded the maximum number of wifi scans when not charging.
- */
+ /** The application exceeded the maximum number of wifi scans when not charging. */
int EXCESSIVE_WIFI_SCAN = 5;
- /**
- * The application exceed the maximum number of flash writes
- */
+ /** The application exceed the maximum number of flash writes */
int EXCESSIVE_FLASH_WRITES = 6;
/**
- * The application used more than the maximum memory, while not spending any time
- * in the foreground.
+ * The application used more than the maximum memory, while not spending any time in the
+ * foreground.
*/
int EXCESSIVE_MEMORY_IN_BACKGROUND = 7;
/**
- * The application exceeded the maximum percentage of frames with a render rate of
- * greater than 700ms.
+ * The application exceeded the maximum percentage of frames with a render rate of greater
+ * than 700ms.
*/
int EXCESSIVE_DAVEY_RATE = 8;
/**
- * The application exceeded the maximum percentage of frames with a render rate
- * greater than 16ms.
+ * The application exceeded the maximum percentage of frames with a render rate greater than
+ * 16ms.
*/
int EXCESSIVE_JANKY_FRAMES = 9;
/**
- * The application exceeded the maximum cold start time - the app has not been
- * launched since last system start, died or was killed.
+ * The application exceeded the maximum cold start time - the app has not been launched
+ * since last system start, died or was killed.
*/
int SLOW_COLD_START_TIME = 10;
/**
- * The application exceeded the maximum hot start time - the app and activity are
- * already in memory.
+ * The application exceeded the maximum hot start time - the app and activity are already in
+ * memory.
*/
int SLOW_HOT_START_TIME = 11;
/**
- * The application exceeded the maximum warm start time - the app was already in
- * memory but the activity wasn’t created yet or was removed from memory.
+ * The application exceeded the maximum warm start time - the app was already in memory but
+ * the activity wasn’t created yet or was removed from memory.
*/
int SLOW_WARM_START_TIME = 12;
- /**
- * The application exceeded the maximum number of syncs while in the background.
- */
+ /** The application exceeded the maximum number of syncs while in the background. */
int EXCESSIVE_BACKGROUND_SYNCS = 13;
- /**
- * The application exceeded the maximum number of gps scans while in the background.
- */
+ /** The application exceeded the maximum number of gps scans while in the background. */
int EXCESSIVE_GPS_SCANS_IN_BACKGROUND = 14;
- /**
- * The application scheduled more than the maximum number of jobs while not charging.
- */
+ /** The application scheduled more than the maximum number of jobs while not charging. */
int EXCESSIVE_JOB_SCHEDULING = 15;
/**
- * The application exceeded the maximum amount of mobile network traffic while in
- * the background.
+ * The application exceeded the maximum amount of mobile network traffic while in the
+ * background.
*/
int EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND = 16;
/**
- * The application held the WiFi lock for more than the maximum amount of time while
- * not charging.
+ * The application held the WiFi lock for more than the maximum amount of time while not
+ * charging.
*/
int EXCESSIVE_WIFI_LOCK_TIME = 17;
- /**
- * The application scheduled a job that ran longer than the maximum amount of time.
- */
+ /** The application scheduled a job that ran longer than the maximum amount of time. */
int JOB_TIMED_OUT = 18;
/**
- * The application did an unoptimized Bluetooth scan that exceeded the maximum
- * time while in the background.
+ * The application did an unoptimized Bluetooth scan that exceeded the maximum time while in
+ * the background.
*/
int LONG_UNOPTIMIZED_BLE_SCAN = 19;
- /**
- * The application exceeded the maximum ANR rate while in the background.
- */
+ /** The application exceeded the maximum ANR rate while in the background. */
int BACKGROUND_ANR = 20;
- /**
- * The application exceeded the maximum crash rate while in the background.
- */
+ /** The application exceeded the maximum crash rate while in the background. */
int BACKGROUND_CRASH_RATE = 21;
- /**
- * The application exceeded the maximum ANR-looping rate.
- */
+ /** The application exceeded the maximum ANR-looping rate. */
int EXCESSIVE_ANR_LOOPING = 22;
- /**
- * The application exceeded the maximum ANR rate.
- */
+ /** The application exceeded the maximum ANR rate. */
int EXCESSIVE_ANRS = 23;
- /**
- * The application exceeded the maximum crash rate.
- */
+ /** The application exceeded the maximum crash rate. */
int EXCESSIVE_CRASH_RATE = 24;
- /**
- * The application exceeded the maximum crash-looping rate.
- */
+ /** The application exceeded the maximum crash-looping rate. */
int EXCESSIVE_CRASH_LOOPING = 25;
- /**
- * The application crashed because no more file descriptors were available.
- */
+ /** The application crashed because no more file descriptors were available. */
int NUMBER_OF_OPEN_FILES = 26;
- /**
- * The application used an excessive amount of CPU while in a
- * background process state.
- */
+ /** The application used an excessive amount of CPU while in a background process state. */
int EXCESSIVE_CPU_USAGE_IN_BACKGROUND = 27;
/**
- * The application kept the camera open for an excessive amount
- * of time while in a bckground process state.
+ * The application kept the camera open for an excessive amount of time while in a bckground
+ * process state.
*/
int EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND = 28;
- /**
- * The application has accessed the contacts content provider an
- * excessive amount.
- */
+ /** The application has accessed the contacts content provider an excessive amount. */
int EXCESSIVE_CONTACT_ACCESS = 29;
- /**
- * The application has played too much audio while in a background
- * process state.
- */
+ /** The application has played too much audio while in a background process state. */
int EXCESSIVE_AUDIO_IN_BACKGROUND = 30;
/**
- * The application has crashed or ANRed too many times while in a
- * background process state.
+ * The application has crashed or ANRed too many times while in a background process state.
*/
int EXCESSIVE_CRASH_ANR_IN_BACKGROUND = 31;
/**
- * An application which has not been used by the user recently
- * was detected to cause an excessive amount of battery drain.
+ * An application which has not been used by the user recently was detected to cause an
+ * excessive amount of battery drain.
*/
int BATTERY_DRAIN_FROM_UNUSED_APP = 32;
}
-
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/BatterySaverAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/BatterySaverAction.java
index 6f823e97746..42b1c2d8b57 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/BatterySaverAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/BatterySaverAction.java
@@ -28,14 +28,12 @@ public class BatterySaverAction extends BatteryTipAction {
super(context);
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
@Override
public void handlePositiveAction(int metricsKey) {
- BatterySaverUtils.setPowerSaveMode(mContext, true, /*needFirstTimeWarning*/ true,
- SAVER_ENABLED_UNKNOWN);
- mMetricsFeatureProvider.action(mContext,
- SettingsEnums.ACTION_TIP_TURN_ON_BATTERY_SAVER, metricsKey);
+ BatterySaverUtils.setPowerSaveMode(
+ mContext, true, /*needFirstTimeWarning*/ true, SAVER_ENABLED_UNKNOWN);
+ mMetricsFeatureProvider.action(
+ mContext, SettingsEnums.ACTION_TIP_TURN_ON_BATTERY_SAVER, metricsKey);
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
index 65aa07634ef..66f9c449878 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/BatteryTipAction.java
@@ -33,8 +33,6 @@ public abstract class BatteryTipAction {
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
public abstract void handlePositiveAction(int metricsKey);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java
index 1bc2ebfe56f..90730864359 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/OpenBatterySaverAction.java
@@ -22,23 +22,18 @@ import android.content.Context;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
-/**
- *
- * Action to open the {@link com.android.settings.fuelgauge.batterysaver.BatterySaverSettings}
- */
+/** Action to open the {@link com.android.settings.fuelgauge.batterysaver.BatterySaverSettings} */
public class OpenBatterySaverAction extends BatteryTipAction {
public OpenBatterySaverAction(Context context) {
super(context);
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
@Override
public void handlePositiveAction(int metricsKey) {
- mMetricsFeatureProvider.action(mContext,
- SettingsEnums.ACTION_TIP_OPEN_BATTERY_SAVER_PAGE, metricsKey);
+ mMetricsFeatureProvider.action(
+ mContext, SettingsEnums.ACTION_TIP_OPEN_BATTERY_SAVER_PAGE, metricsKey);
new SubSettingLauncher(mContext)
.setDestination(BatterySaverSettings.class.getName())
.setSourceMetricsCategory(metricsKey)
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/OpenRestrictAppFragmentAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/OpenRestrictAppFragmentAction.java
index f0d9f28e8d3..30c318ee504 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/OpenRestrictAppFragmentAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/OpenRestrictAppFragmentAction.java
@@ -30,35 +30,32 @@ import com.android.settingslib.utils.ThreadUtils;
import java.util.List;
-/**
- * Action to open the {@link com.android.settings.fuelgauge.RestrictedAppDetails}
- */
+/** Action to open the {@link com.android.settings.fuelgauge.RestrictedAppDetails} */
public class OpenRestrictAppFragmentAction extends BatteryTipAction {
private final RestrictAppTip mRestrictAppTip;
private final InstrumentedPreferenceFragment mFragment;
- @VisibleForTesting
- BatteryDatabaseManager mBatteryDatabaseManager;
+ @VisibleForTesting BatteryDatabaseManager mBatteryDatabaseManager;
- public OpenRestrictAppFragmentAction(InstrumentedPreferenceFragment fragment,
- RestrictAppTip tip) {
+ public OpenRestrictAppFragmentAction(
+ InstrumentedPreferenceFragment fragment, RestrictAppTip tip) {
super(fragment.getContext());
mFragment = fragment;
mRestrictAppTip = tip;
mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(mContext);
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
@Override
public void handlePositiveAction(int metricsKey) {
- mMetricsFeatureProvider.action(mContext,
- SettingsEnums.ACTION_TIP_OPEN_APP_RESTRICTION_PAGE, metricsKey);
+ mMetricsFeatureProvider.action(
+ mContext, SettingsEnums.ACTION_TIP_OPEN_APP_RESTRICTION_PAGE, metricsKey);
final List mAppInfos = mRestrictAppTip.getRestrictAppList();
RestrictedAppDetails.startRestrictedAppDetails(mFragment, mAppInfos);
// Mark all the anomalies as handled, so it won't show up again.
- ThreadUtils.postOnBackgroundThread(() -> mBatteryDatabaseManager.updateAnomalies(mAppInfos,
- AnomalyDatabaseHelper.State.HANDLED));
+ ThreadUtils.postOnBackgroundThread(
+ () ->
+ mBatteryDatabaseManager.updateAnomalies(
+ mAppInfos, AnomalyDatabaseHelper.State.HANDLED));
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java
index 33ac5df4a4b..83abf491c33 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java
@@ -31,15 +31,11 @@ import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import java.util.List;
-/**
- * Action to restrict the apps, then app is not allowed to run in the background.
- */
+/** Action to restrict the apps, then app is not allowed to run in the background. */
public class RestrictAppAction extends BatteryTipAction {
private RestrictAppTip mRestrictAppTip;
- @VisibleForTesting
- BatteryDatabaseManager mBatteryDatabaseManager;
- @VisibleForTesting
- BatteryUtils mBatteryUtils;
+ @VisibleForTesting BatteryDatabaseManager mBatteryDatabaseManager;
+ @VisibleForTesting BatteryUtils mBatteryUtils;
public RestrictAppAction(Context context, RestrictAppTip tip) {
super(context);
@@ -48,9 +44,7 @@ public class RestrictAppAction extends BatteryTipAction {
mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(context);
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
@Override
public void handlePositiveAction(int metricsKey) {
final List appInfos = mRestrictAppTip.getRestrictAppList();
@@ -59,18 +53,19 @@ public class RestrictAppAction extends BatteryTipAction {
final AppInfo appInfo = appInfos.get(i);
final String packageName = appInfo.packageName;
// Force app standby, then app can't run in the background
- mBatteryUtils.setForceAppStandby(appInfo.uid, packageName,
- AppOpsManager.MODE_IGNORED);
+ mBatteryUtils.setForceAppStandby(appInfo.uid, packageName, AppOpsManager.MODE_IGNORED);
if (CollectionUtils.isEmpty(appInfo.anomalyTypes)) {
// Only log context if there is no anomaly type
- mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
+ mMetricsFeatureProvider.action(
+ SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_TIP_RESTRICT_APP,
metricsKey,
packageName,
0);
} else {
for (int type : appInfo.anomalyTypes) {
- mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
+ mMetricsFeatureProvider.action(
+ SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_TIP_RESTRICT_APP,
metricsKey,
packageName,
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
index f6b9c94dfd9..55c00313040 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/SmartBatteryAction.java
@@ -36,20 +36,18 @@ public class SmartBatteryAction extends BatteryTipAction {
mFragment = fragment;
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
@Override
public void handlePositiveAction(int metricsKey) {
- mMetricsFeatureProvider.action(mContext,
- SettingsEnums.ACTION_TIP_OPEN_SMART_BATTERY, metricsKey);
+ mMetricsFeatureProvider.action(
+ mContext, SettingsEnums.ACTION_TIP_OPEN_SMART_BATTERY, metricsKey);
new SubSettingLauncher(mSettingsActivity)
- .setSourceMetricsCategory(mFragment instanceof Instrumentable
- ? ((Instrumentable) mFragment).getMetricsCategory()
- : Instrumentable.METRICS_CATEGORY_UNKNOWN)
+ .setSourceMetricsCategory(
+ mFragment instanceof Instrumentable
+ ? ((Instrumentable) mFragment).getMetricsCategory()
+ : Instrumentable.METRICS_CATEGORY_UNKNOWN)
.setDestination(SmartBatterySettings.class.getName())
.setTitleRes(R.string.smart_battery_manager_title)
.launch();
-
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java
index 0ef2c0f13bc..1d959bff8e4 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java
@@ -26,13 +26,10 @@ import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
-/**
- * Action to clear the restriction to the app
- */
+/** Action to clear the restriction to the app */
public class UnrestrictAppAction extends BatteryTipAction {
private UnrestrictAppTip mUnRestrictAppTip;
- @VisibleForTesting
- BatteryUtils mBatteryUtils;
+ @VisibleForTesting BatteryUtils mBatteryUtils;
public UnrestrictAppAction(Context context, UnrestrictAppTip tip) {
super(context);
@@ -40,15 +37,13 @@ public class UnrestrictAppAction extends BatteryTipAction {
mBatteryUtils = BatteryUtils.getInstance(context);
}
- /**
- * Handle the action when user clicks positive button
- */
+ /** Handle the action when user clicks positive button */
@Override
public void handlePositiveAction(int metricsKey) {
final AppInfo appInfo = mUnRestrictAppTip.getUnrestrictAppInfo();
// Clear force app standby, then app can run in the background
- mBatteryUtils.setForceAppStandby(appInfo.uid, appInfo.packageName,
- AppOpsManager.MODE_ALLOWED);
+ mBatteryUtils.setForceAppStandby(
+ appInfo.uid, appInfo.packageName, AppOpsManager.MODE_ALLOWED);
mMetricsFeatureProvider.action(
SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_TIP_UNRESTRICT_APP,
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
index 55d2ee49dd2..db572cdb3c3 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/BatteryDefenderDetector.java
@@ -23,9 +23,7 @@ import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.overlay.FeatureFactory;
-/**
- * Detect whether the battery is overheated
- */
+/** Detect whether the battery is overheated */
public class BatteryDefenderDetector implements BatteryTipDetector {
private final BatteryInfo mBatteryInfo;
private final Context mContext;
@@ -37,11 +35,13 @@ public class BatteryDefenderDetector implements BatteryTipDetector {
@Override
public BatteryTip detect() {
- final boolean isBasicBatteryDefend = mBatteryInfo.isBatteryDefender
- && !FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider()
- .isExtraDefend();
- final int state = isBasicBatteryDefend
- ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
+ final boolean isBasicBatteryDefend =
+ mBatteryInfo.isBatteryDefender
+ && !FeatureFactory.getFeatureFactory()
+ .getPowerUsageFeatureProvider()
+ .isExtraDefend();
+ final int state =
+ isBasicBatteryDefend ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0;
return new BatteryDefenderTip(state, isPluggedIn);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java
index 8a839d392d8..14aeecd69bb 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/DockDefenderDetector.java
@@ -23,9 +23,7 @@ import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.DockDefenderTip;
-/**
- * Detect whether the dock defender mode is enabled.
- */
+/** Detect whether the dock defender mode is enabled. */
public class DockDefenderDetector implements BatteryTipDetector {
private final BatteryInfo mBatteryInfo;
private final Context mContext;
@@ -44,5 +42,4 @@ public class DockDefenderDetector implements BatteryTipDetector {
: BatteryTip.StateType.INVISIBLE,
mode);
}
-
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
index 8126dcc2a31..8866346d1ae 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
@@ -38,8 +38,8 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
/**
- * Detector whether to show summary tip. This detector should be executed as the last
- * {@link BatteryTipDetector} since it need the most up-to-date {@code visibleTips}
+ * Detector whether to show summary tip. This detector should be executed as the last {@link
+ * BatteryTipDetector} since it need the most up-to-date {@code visibleTips}
*/
public class HighUsageDetector implements BatteryTipDetector {
private static final String TAG = "HighUsageDetector";
@@ -48,29 +48,31 @@ public class HighUsageDetector implements BatteryTipDetector {
private BatteryUsageStats mBatteryUsageStats;
private final BatteryInfo mBatteryInfo;
private List mHighUsageAppList;
- @VisibleForTesting
- HighUsageDataParser mDataParser;
- @VisibleForTesting
- BatteryUtils mBatteryUtils;
- @VisibleForTesting
- boolean mDischarging;
+ @VisibleForTesting HighUsageDataParser mDataParser;
+ @VisibleForTesting BatteryUtils mBatteryUtils;
+ @VisibleForTesting boolean mDischarging;
- public HighUsageDetector(Context context, BatteryTipPolicy policy,
- BatteryUsageStats batteryUsageStats, BatteryInfo batteryInfo) {
+ public HighUsageDetector(
+ Context context,
+ BatteryTipPolicy policy,
+ BatteryUsageStats batteryUsageStats,
+ BatteryInfo batteryInfo) {
mPolicy = policy;
mBatteryUsageStats = batteryUsageStats;
mBatteryInfo = batteryInfo;
mHighUsageAppList = new ArrayList<>();
mBatteryUtils = BatteryUtils.getInstance(context);
- mDataParser = new HighUsageDataParser(mPolicy.highUsagePeriodMs,
- mPolicy.highUsageBatteryDraining);
+ mDataParser =
+ new HighUsageDataParser(
+ mPolicy.highUsagePeriodMs, mPolicy.highUsageBatteryDraining);
mDischarging = batteryInfo.discharging;
}
@Override
public BatteryTip detect() {
- final long lastFullChargeTimeMs = mBatteryUtils.calculateLastFullChargeTime(
- mBatteryUsageStats, System.currentTimeMillis());
+ final long lastFullChargeTimeMs =
+ mBatteryUtils.calculateLastFullChargeTime(
+ mBatteryUsageStats, System.currentTimeMillis());
if (mPolicy.highUsageEnabled && mDischarging) {
parseBatteryData();
if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
@@ -80,22 +82,25 @@ public class HighUsageDetector implements BatteryTipDetector {
mBatteryUsageStats.getUidBatteryConsumers();
// Sort by descending power
uidBatteryConsumers.sort(
- (consumer1, consumer2) -> Double.compare(consumer2.getConsumedPower(),
- consumer1.getConsumedPower()));
+ (consumer1, consumer2) ->
+ Double.compare(
+ consumer2.getConsumedPower(),
+ consumer1.getConsumedPower()));
for (UidBatteryConsumer consumer : uidBatteryConsumers) {
- final double percent = mBatteryUtils.calculateBatteryPercent(
- consumer.getConsumedPower(), totalPower, dischargeAmount);
+ final double percent =
+ mBatteryUtils.calculateBatteryPercent(
+ consumer.getConsumedPower(), totalPower, dischargeAmount);
if ((percent + 0.5f < 1f)
|| mBatteryUtils.shouldHideUidBatteryConsumer(consumer)) {
// Don't show it if we should hide or usage percentage is lower than 1%
continue;
}
- mHighUsageAppList.add(new AppInfo.Builder()
- .setUid(consumer.getUid())
- .setPackageName(
- mBatteryUtils.getPackageName(consumer.getUid()))
- .build());
+ mHighUsageAppList.add(
+ new AppInfo.Builder()
+ .setUid(consumer.getUid())
+ .setPackageName(mBatteryUtils.getPackageName(consumer.getUid()))
+ .build());
if (mHighUsageAppList.size() >= mPolicy.highUsageAppCount) {
break;
}
@@ -103,10 +108,11 @@ public class HighUsageDetector implements BatteryTipDetector {
// When in test mode, add an app if necessary
if (mPolicy.testHighUsageTip && mHighUsageAppList.isEmpty()) {
- mHighUsageAppList.add(new AppInfo.Builder()
- .setPackageName(SETTINGS_PACKAGE_NAME)
- .setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3))
- .build());
+ mHighUsageAppList.add(
+ new AppInfo.Builder()
+ .setPackageName(SETTINGS_PACKAGE_NAME)
+ .setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3))
+ .build());
}
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/IncompatibleChargerDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/IncompatibleChargerDetector.java
index cfd9a2cbaa5..5a9e4f32290 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/IncompatibleChargerDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/IncompatibleChargerDetector.java
@@ -34,12 +34,12 @@ public final class IncompatibleChargerDetector implements BatteryTipDetector {
@Override
public BatteryTip detect() {
- final boolean isIncompatibleCharging =
- Utils.containsIncompatibleChargers(mContext, TAG);
- final int state = isIncompatibleCharging
- ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
- Log.d(TAG, "detect() state= " + state + " isIncompatibleCharging: "
- + isIncompatibleCharging);
+ final boolean isIncompatibleCharging = Utils.containsIncompatibleChargers(mContext, TAG);
+ final int state =
+ isIncompatibleCharging ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
+ Log.d(
+ TAG,
+ "detect() state= " + state + " isIncompatibleCharging: " + isIncompatibleCharging);
return new IncompatibleChargerTip(state);
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java
index 9e970d29aed..1ce5a8ec891 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/LowBatteryDetector.java
@@ -23,22 +23,23 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
-/**
- * Detect whether the battery is too low
- */
+/** Detect whether the battery is too low */
public class LowBatteryDetector implements BatteryTipDetector {
private final BatteryInfo mBatteryInfo;
private final BatteryTipPolicy mPolicy;
private final boolean mIsPowerSaveMode;
private final int mWarningLevel;
-
- public LowBatteryDetector(Context context, BatteryTipPolicy policy, BatteryInfo batteryInfo,
+ public LowBatteryDetector(
+ Context context,
+ BatteryTipPolicy policy,
+ BatteryInfo batteryInfo,
boolean isPowerSaveMode) {
mPolicy = policy;
mBatteryInfo = batteryInfo;
- mWarningLevel = context.getResources().getInteger(
- com.android.internal.R.integer.config_lowBatteryWarningLevel);
+ mWarningLevel =
+ context.getResources()
+ .getInteger(com.android.internal.R.integer.config_lowBatteryWarningLevel);
mIsPowerSaveMode = isPowerSaveMode;
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
index 0487ac3eafe..7f9dcd6f7b2 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/SmartBatteryDetector.java
@@ -25,9 +25,7 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
-/**
- * Detect whether to show smart battery tip.
- */
+/** Detect whether to show smart battery tip. */
public class SmartBatteryDetector implements BatteryTipDetector {
private static final int EXPECTED_BATTERY_LEVEL = 30;
@@ -36,8 +34,12 @@ public class SmartBatteryDetector implements BatteryTipDetector {
private final ContentResolver mContentResolver;
private final boolean mIsPowerSaveMode;
- public SmartBatteryDetector(Context context, BatteryTipPolicy policy, BatteryInfo batteryInfo,
- ContentResolver contentResolver, boolean isPowerSaveMode) {
+ public SmartBatteryDetector(
+ Context context,
+ BatteryTipPolicy policy,
+ BatteryInfo batteryInfo,
+ ContentResolver contentResolver,
+ boolean isPowerSaveMode) {
mPolicy = policy;
mBatteryInfo = batteryInfo;
mContentResolver = contentResolver;
@@ -46,14 +48,18 @@ public class SmartBatteryDetector implements BatteryTipDetector {
@Override
public BatteryTip detect() {
- final boolean smartBatteryOff = Settings.Global.getInt(mContentResolver,
- Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 1) == 0;
+ final boolean smartBatteryOff =
+ Settings.Global.getInt(
+ mContentResolver,
+ Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED,
+ 1)
+ == 0;
final boolean isUnderExpectedBatteryLevel =
mBatteryInfo.batteryLevel <= EXPECTED_BATTERY_LEVEL;
// Show it if in test or smart battery is off.
final boolean enableSmartBatteryTip =
smartBatteryOff && !mIsPowerSaveMode && isUnderExpectedBatteryLevel
- || mPolicy.testSmartBatteryTip;
+ || mPolicy.testSmartBatteryTip;
final int state =
enableSmartBatteryTip ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
return new SmartBatteryTip(state);
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/AppLabelPredicate.java b/src/com/android/settings/fuelgauge/batterytip/tips/AppLabelPredicate.java
index 1444b12b4ee..5bd4dc04811 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/AppLabelPredicate.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/AppLabelPredicate.java
@@ -23,9 +23,7 @@ import com.android.settings.fuelgauge.batterytip.AppInfo;
import java.util.function.Predicate;
-/**
- * {@link Predicate} for {@link AppInfo} to check whether it has label
- */
+/** {@link Predicate} for {@link AppInfo} to check whether it has label */
public class AppLabelPredicate implements Predicate {
private static AppLabelPredicate sInstance;
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/AppRestrictionPredicate.java b/src/com/android/settings/fuelgauge/batterytip/tips/AppRestrictionPredicate.java
index 43a4d900e28..a08953c4213 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/AppRestrictionPredicate.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/AppRestrictionPredicate.java
@@ -23,9 +23,7 @@ import com.android.settings.fuelgauge.batterytip.AppInfo;
import java.util.function.Predicate;
-/**
- * {@link Predicate} for {@link AppInfo} to check whether it is restricted.
- */
+/** {@link Predicate} for {@link AppInfo} to check whether it is restricted. */
public class AppRestrictionPredicate implements Predicate {
private static AppRestrictionPredicate sInstance;
@@ -46,7 +44,8 @@ public class AppRestrictionPredicate implements Predicate {
@Override
public boolean test(AppInfo appInfo) {
// Return true if app already been restricted
- return mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
- appInfo.uid, appInfo.packageName) == AppOpsManager.MODE_IGNORED;
+ return mAppOpsManager.checkOpNoThrow(
+ AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, appInfo.uid, appInfo.packageName)
+ == AppOpsManager.MODE_IGNORED;
}
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java
index 536e5f89204..b5ec522b707 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryDefenderTip.java
@@ -30,9 +30,7 @@ import com.android.settings.widget.CardPreference;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-/**
- * Tip to show current battery is overheated
- */
+/** Tip to show current battery is overheated */
public class BatteryDefenderTip extends BatteryTip {
private static final String TAG = "BatteryDefenderTip";
@@ -70,8 +68,7 @@ public class BatteryDefenderTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_BATTERY_DEFENDER_TIP,
- mState);
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_BATTERY_DEFENDER_TIP, mState);
}
@Override
@@ -97,14 +94,17 @@ public class BatteryDefenderTip extends BatteryTip {
cardPreference.setSecondaryButtonText(context.getString(R.string.learn_more));
cardPreference.setSecondaryButtonClickListener(
- button -> button.startActivityForResult(
- HelpUtils.getHelpIntent(
- context,
- context.getString(R.string.help_url_battery_defender),
- /* backupContext */ ""), /* requestCode */ 0));
+ button ->
+ button.startActivityForResult(
+ HelpUtils.getHelpIntent(
+ context,
+ context.getString(R.string.help_url_battery_defender),
+ /* backupContext */ ""), /* requestCode */
+ 0));
cardPreference.setSecondaryButtonVisible(true);
- cardPreference.setSecondaryButtonContentDescription(context.getString(
- R.string.battery_tip_limited_temporarily_sec_button_content_description));
+ cardPreference.setSecondaryButtonContentDescription(
+ context.getString(
+ R.string.battery_tip_limited_temporarily_sec_button_content_description));
}
private void resumeCharging(Context context) {
@@ -119,13 +119,14 @@ public class BatteryDefenderTip extends BatteryTip {
Log.i(TAG, "send resume charging broadcast intent=" + intent);
}
- public static final Creator CREATOR = new Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new BatteryDefenderTip(in);
- }
+ public static final Creator CREATOR =
+ new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new BatteryDefenderTip(in);
+ }
- public BatteryTip[] newArray(int size) {
- return new BatteryDefenderTip[size];
- }
- };
+ public BatteryTip[] newArray(int size) {
+ return new BatteryDefenderTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
index fdafca65c0c..7abd1ccf10c 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
@@ -35,14 +35,12 @@ import java.lang.annotation.RetentionPolicy;
/**
* Base model for a battery tip(e.g. suggest user to turn on battery saver)
*
- * Each {@link BatteryTip} contains basic data(e.g. title, summary, icon) as well as the
+ * Each {@link BatteryTip} contains basic data(e.g. title, summary, icon) as well as the
* pre-defined action(e.g. turn on battery saver)
*/
public abstract class BatteryTip implements Comparable, Parcelable {
@Retention(RetentionPolicy.SOURCE)
- @IntDef({StateType.NEW,
- StateType.HANDLED,
- StateType.INVISIBLE})
+ @IntDef({StateType.NEW, StateType.HANDLED, StateType.INVISIBLE})
public @interface StateType {
int NEW = 0;
int HANDLED = 1;
@@ -50,17 +48,19 @@ public abstract class BatteryTip implements Comparable, Parcelable {
}
@Retention(RetentionPolicy.SOURCE)
- @IntDef({TipType.SUMMARY,
- TipType.BATTERY_SAVER,
- TipType.HIGH_DEVICE_USAGE,
- TipType.SMART_BATTERY_MANAGER,
- TipType.APP_RESTRICTION,
- TipType.REDUCED_BATTERY,
- TipType.LOW_BATTERY,
- TipType.REMOVE_APP_RESTRICTION,
- TipType.BATTERY_DEFENDER,
- TipType.DOCK_DEFENDER,
- TipType.INCOMPATIBLE_CHARGER})
+ @IntDef({
+ TipType.SUMMARY,
+ TipType.BATTERY_SAVER,
+ TipType.HIGH_DEVICE_USAGE,
+ TipType.SMART_BATTERY_MANAGER,
+ TipType.APP_RESTRICTION,
+ TipType.REDUCED_BATTERY,
+ TipType.LOW_BATTERY,
+ TipType.REMOVE_APP_RESTRICTION,
+ TipType.BATTERY_DEFENDER,
+ TipType.DOCK_DEFENDER,
+ TipType.INCOMPATIBLE_CHARGER
+ })
public @interface TipType {
int SMART_BATTERY_MANAGER = 0;
int APP_RESTRICTION = 1;
@@ -75,8 +75,8 @@ public abstract class BatteryTip implements Comparable, Parcelable {
int INCOMPATIBLE_CHARGER = 10;
}
- @VisibleForTesting
- static final SparseIntArray TIP_ORDER;
+ @VisibleForTesting static final SparseIntArray TIP_ORDER;
+
static {
TIP_ORDER = new SparseIntArray();
TIP_ORDER.append(TipType.BATTERY_SAVER, 0);
@@ -97,9 +97,8 @@ public abstract class BatteryTip implements Comparable, Parcelable {
protected int mType;
protected int mState;
protected boolean mShowDialog;
- /**
- * Whether we need to update battery tip when configuration change
- */
+
+ /** Whether we need to update battery tip when configuration change */
protected boolean mNeedUpdate;
BatteryTip(Parcel in) {
@@ -146,15 +145,14 @@ public abstract class BatteryTip implements Comparable, Parcelable {
/**
* Check whether data is still make sense. If not, try recover.
+ *
* @param context used to do validate check
*/
public void validateCheck(Context context) {
// do nothing
}
- /**
- * Log the battery tip
- */
+ /** Log the battery tip */
public abstract void log(Context context, MetricsFeatureProvider metricsFeatureProvider);
public void updatePreference(Preference preference) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java
index c8cb8f2b1f3..2458351738e 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/DockDefenderTip.java
@@ -32,9 +32,7 @@ import com.android.settings.widget.CardPreference;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-/**
- * Tip to show dock defender status
- */
+/** Tip to show dock defender status */
public class DockDefenderTip extends BatteryTip {
private static final String TAG = "DockDefenderTip";
private int mMode;
@@ -84,8 +82,9 @@ public class DockDefenderTip extends BatteryTip {
@Override
public int getIconId() {
- return mMode == DockDefenderMode.ACTIVE ? R.drawable.ic_battery_status_protected_24dp :
- R.drawable.ic_battery_dock_defender_untriggered_24dp;
+ return mMode == DockDefenderMode.ACTIVE
+ ? R.drawable.ic_battery_status_protected_24dp
+ : R.drawable.ic_battery_dock_defender_untriggered_24dp;
}
@Override
@@ -98,8 +97,7 @@ public class DockDefenderTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_DOCK_DEFENDER_TIP,
- mState);
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_DOCK_DEFENDER_TIP, mState);
}
@Override
@@ -119,15 +117,19 @@ public class DockDefenderTip extends BatteryTip {
case DockDefenderMode.ACTIVE:
cardPreference.setPrimaryButtonText(
context.getString(R.string.battery_tip_charge_to_full_button));
- cardPreference.setPrimaryButtonClickListener(unused -> {
- resumeCharging(context);
- mMode = DockDefenderMode.TEMPORARILY_BYPASSED;
- context.sendBroadcast(new Intent().setAction(
- BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION).setPackage(
- context.getPackageName()).addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
- | Intent.FLAG_RECEIVER_FOREGROUND));
- updatePreference(preference);
- });
+ cardPreference.setPrimaryButtonClickListener(
+ unused -> {
+ resumeCharging(context);
+ mMode = DockDefenderMode.TEMPORARILY_BYPASSED;
+ context.sendBroadcast(
+ new Intent()
+ .setAction(BatteryUtils.BYPASS_DOCK_DEFENDER_ACTION)
+ .setPackage(context.getPackageName())
+ .addFlags(
+ Intent.FLAG_RECEIVER_REGISTERED_ONLY
+ | Intent.FLAG_RECEIVER_FOREGROUND));
+ updatePreference(preference);
+ });
cardPreference.setPrimaryButtonVisible(true);
break;
case DockDefenderMode.TEMPORARILY_BYPASSED:
@@ -140,15 +142,17 @@ public class DockDefenderTip extends BatteryTip {
cardPreference.setSecondaryButtonText(context.getString(R.string.learn_more));
cardPreference.setSecondaryButtonClickListener(
- button -> button.startActivityForResult(
- HelpUtils.getHelpIntent(
- context,
- context.getString(R.string.help_url_dock_defender),
- /* backupContext */ ""), /* requestCode */ 0));
+ button ->
+ button.startActivityForResult(
+ HelpUtils.getHelpIntent(
+ context,
+ context.getString(R.string.help_url_dock_defender),
+ /* backupContext */ ""), /* requestCode */
+ 0));
cardPreference.setSecondaryButtonVisible(true);
- cardPreference.setSecondaryButtonContentDescription(context.getString(
- R.string.battery_tip_limited_temporarily_sec_button_content_description));
-
+ cardPreference.setSecondaryButtonContentDescription(
+ context.getString(
+ R.string.battery_tip_limited_temporarily_sec_button_content_description));
}
private void resumeCharging(Context context) {
@@ -163,13 +167,14 @@ public class DockDefenderTip extends BatteryTip {
Log.i(TAG, "send resume charging broadcast intent=" + intent);
}
- public static final Creator CREATOR = new Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new DockDefenderTip(in);
- }
+ public static final Creator CREATOR =
+ new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new DockDefenderTip(in);
+ }
- public BatteryTip[] newArray(int size) {
- return new DockDefenderTip[size];
- }
- };
+ public BatteryTip[] newArray(int size) {
+ return new DockDefenderTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
index 47938fbbe1a..44e4f5ce042 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
@@ -29,17 +29,16 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import java.util.List;
-/**
- * Tip to show general summary about battery life
- */
+/** Tip to show general summary about battery life */
public class HighUsageTip extends BatteryTip {
private final long mLastFullChargeTimeMs;
- @VisibleForTesting
- final List mHighUsageAppList;
+ @VisibleForTesting final List mHighUsageAppList;
public HighUsageTip(long lastFullChargeTimeMs, List appList) {
- super(TipType.HIGH_DEVICE_USAGE, appList.isEmpty() ? StateType.INVISIBLE : StateType.NEW,
+ super(
+ TipType.HIGH_DEVICE_USAGE,
+ appList.isEmpty() ? StateType.INVISIBLE : StateType.NEW,
true /* showDialog */);
mLastFullChargeTimeMs = lastFullChargeTimeMs;
mHighUsageAppList = appList;
@@ -81,13 +80,11 @@ public class HighUsageTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_HIGH_USAGE_TIP,
- mState);
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_HIGH_USAGE_TIP, mState);
for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
final AppInfo appInfo = mHighUsageAppList.get(i);
- metricsFeatureProvider.action(context,
- SettingsEnums.ACTION_HIGH_USAGE_TIP_LIST,
- appInfo.packageName);
+ metricsFeatureProvider.action(
+ context, SettingsEnums.ACTION_HIGH_USAGE_TIP_LIST, appInfo.packageName);
}
}
@@ -112,14 +109,14 @@ public class HighUsageTip extends BatteryTip {
return stringBuilder.toString();
}
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new HighUsageTip(in);
- }
-
- public BatteryTip[] newArray(int size) {
- return new HighUsageTip[size];
- }
- };
+ public static final Parcelable.Creator CREATOR =
+ new Parcelable.Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new HighUsageTip(in);
+ }
+ public BatteryTip[] newArray(int size) {
+ return new HighUsageTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java
index 48cfb7a4889..ca42141eb66 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/IncompatibleChargerTip.java
@@ -62,8 +62,8 @@ public final class IncompatibleChargerTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_INCOMPATIBLE_CHARGING_TIP,
- mState);
+ metricsFeatureProvider.action(
+ context, SettingsEnums.ACTION_INCOMPATIBLE_CHARGING_TIP, mState);
}
@Override
@@ -79,23 +79,26 @@ public final class IncompatibleChargerTip extends BatteryTip {
cardPreference.setSelectable(false);
cardPreference.setPrimaryButtonText(context.getString(R.string.learn_more));
cardPreference.setPrimaryButtonClickListener(
- button -> button.startActivityForResult(
- HelpUtils.getHelpIntent(
- context,
- context.getString(R.string.help_url_incompatible_charging),
- /* backupContext */ ""), /* requestCode */ 0));
+ button ->
+ button.startActivityForResult(
+ HelpUtils.getHelpIntent(
+ context,
+ context.getString(R.string.help_url_incompatible_charging),
+ /* backupContext */ ""), /* requestCode */
+ 0));
cardPreference.setPrimaryButtonVisible(true);
- cardPreference.setPrimaryButtonContentDescription(context.getString(
- R.string.battery_tip_incompatible_charging_content_description));
+ cardPreference.setPrimaryButtonContentDescription(
+ context.getString(R.string.battery_tip_incompatible_charging_content_description));
}
- public static final Creator CREATOR = new Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new IncompatibleChargerTip(in);
- }
+ public static final Creator CREATOR =
+ new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new IncompatibleChargerTip(in);
+ }
- public BatteryTip[] newArray(int size) {
- return new IncompatibleChargerTip[size];
- }
- };
+ public BatteryTip[] newArray(int size) {
+ return new IncompatibleChargerTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
index aeff7e95c39..3073d126992 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
@@ -62,28 +62,27 @@ public class LowBatteryTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_LOW_BATTERY_TIP,
- mState);
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_LOW_BATTERY_TIP, mState);
}
@Override
public void updateState(BatteryTip tip) {
final LowBatteryTip lowBatteryTip = (LowBatteryTip) tip;
- mState = lowBatteryTip.mPowerSaveModeOn
- ? StateType.INVISIBLE : lowBatteryTip.getState();
+ mState = lowBatteryTip.mPowerSaveModeOn ? StateType.INVISIBLE : lowBatteryTip.getState();
}
boolean isPowerSaveModeOn() {
return mPowerSaveModeOn;
}
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new LowBatteryTip(in);
- }
+ public static final Parcelable.Creator CREATOR =
+ new Parcelable.Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new LowBatteryTip(in);
+ }
- public BatteryTip[] newArray(int size) {
- return new LowBatteryTip[size];
- }
- };
+ public BatteryTip[] newArray(int size) {
+ return new LowBatteryTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java
index cba614b5d53..2b74dd22e41 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java
@@ -34,9 +34,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-/**
- * Tip to suggest user to restrict some bad apps
- */
+/** Tip to suggest user to restrict some bad apps */
public class RestrictAppTip extends BatteryTip {
private List mRestrictAppList;
@@ -62,27 +60,32 @@ public class RestrictAppTip extends BatteryTip {
@Override
public CharSequence getTitle(Context context) {
final int num = mRestrictAppList.size();
- final CharSequence appLabel = num > 0 ? Utils.getApplicationLabel(context,
- mRestrictAppList.get(0).packageName) : "";
+ final CharSequence appLabel =
+ num > 0
+ ? Utils.getApplicationLabel(context, mRestrictAppList.get(0).packageName)
+ : "";
Map arguments = new ArrayMap<>();
arguments.put("count", num);
arguments.put("label", appLabel);
return mState == StateType.HANDLED
- ? StringUtil.getIcuPluralsString(context, arguments,
- R.string.battery_tip_restrict_handled_title)
- : StringUtil.getIcuPluralsString(context, arguments,
- R.string.battery_tip_restrict_title);
+ ? StringUtil.getIcuPluralsString(
+ context, arguments, R.string.battery_tip_restrict_handled_title)
+ : StringUtil.getIcuPluralsString(
+ context, arguments, R.string.battery_tip_restrict_title);
}
@Override
public CharSequence getSummary(Context context) {
final int num = mRestrictAppList.size();
- final CharSequence appLabel = num > 0 ? Utils.getApplicationLabel(context,
- mRestrictAppList.get(0).packageName) : "";
- final int resId = mState == StateType.HANDLED
- ? R.string.battery_tip_restrict_handled_summary
- : R.string.battery_tip_restrict_summary;
+ final CharSequence appLabel =
+ num > 0
+ ? Utils.getApplicationLabel(context, mRestrictAppList.get(0).packageName)
+ : "";
+ final int resId =
+ mState == StateType.HANDLED
+ ? R.string.battery_tip_restrict_handled_summary
+ : R.string.battery_tip_restrict_summary;
Map arguments = new ArrayMap<>();
arguments.put("count", num);
arguments.put("label", appLabel);
@@ -127,13 +130,13 @@ public class RestrictAppTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_APP_RESTRICTION_TIP,
- mState);
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_APP_RESTRICTION_TIP, mState);
if (mState == StateType.NEW) {
for (int i = 0, size = mRestrictAppList.size(); i < size; i++) {
final AppInfo appInfo = mRestrictAppList.get(i);
for (Integer anomalyType : appInfo.anomalyTypes) {
- metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
+ metricsFeatureProvider.action(
+ SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_APP_RESTRICTION_TIP_LIST,
SettingsEnums.PAGE_UNKNOWN,
appInfo.packageName,
@@ -147,14 +150,11 @@ public class RestrictAppTip extends BatteryTip {
return mRestrictAppList;
}
- /**
- * Construct the app list string(e.g. app1, app2, and app3)
- */
+ /** Construct the app list string(e.g. app1, app2, and app3) */
public CharSequence getRestrictAppsString(Context context) {
final List appLabels = new ArrayList<>();
for (int i = 0, size = mRestrictAppList.size(); i < size; i++) {
- appLabels.add(Utils.getApplicationLabel(context,
- mRestrictAppList.get(i).packageName));
+ appLabels.add(Utils.getApplicationLabel(context, mRestrictAppList.get(i).packageName));
}
return ListFormatter.getInstance().format(appLabels);
@@ -179,13 +179,14 @@ public class RestrictAppTip extends BatteryTip {
dest.writeTypedList(mRestrictAppList);
}
- public static final Creator CREATOR = new Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new RestrictAppTip(in);
- }
+ public static final Creator CREATOR =
+ new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new RestrictAppTip(in);
+ }
- public BatteryTip[] newArray(int size) {
- return new RestrictAppTip[size];
- }
- };
+ public BatteryTip[] newArray(int size) {
+ return new RestrictAppTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
index 0593e88d504..c99653b4acd 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/SmartBatteryTip.java
@@ -23,9 +23,7 @@ import android.os.Parcel;
import com.android.settings.R;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-/**
- * Tip to suggest turn on smart battery if it is not on
- */
+/** Tip to suggest turn on smart battery if it is not on */
public class SmartBatteryTip extends BatteryTip {
public SmartBatteryTip(@StateType int state) {
@@ -58,18 +56,17 @@ public class SmartBatteryTip extends BatteryTip {
@Override
public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) {
- metricsFeatureProvider.action(context, SettingsEnums.ACTION_SMART_BATTERY_TIP,
- mState);
+ metricsFeatureProvider.action(context, SettingsEnums.ACTION_SMART_BATTERY_TIP, mState);
}
- public static final Creator CREATOR = new Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new SmartBatteryTip(in);
- }
-
- public BatteryTip[] newArray(int size) {
- return new SmartBatteryTip[size];
- }
- };
+ public static final Creator CREATOR =
+ new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new SmartBatteryTip(in);
+ }
+ public BatteryTip[] newArray(int size) {
+ return new SmartBatteryTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/UnrestrictAppTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/UnrestrictAppTip.java
index 3c560f8f18e..7b5caebe90a 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/UnrestrictAppTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/UnrestrictAppTip.java
@@ -84,13 +84,14 @@ public class UnrestrictAppTip extends BatteryTip {
dest.writeParcelable(mAppInfo, flags);
}
- public static final Creator CREATOR = new Creator() {
- public BatteryTip createFromParcel(Parcel in) {
- return new UnrestrictAppTip(in);
- }
+ public static final Creator CREATOR =
+ new Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new UnrestrictAppTip(in);
+ }
- public BatteryTip[] newArray(int size) {
- return new UnrestrictAppTip[size];
- }
- };
+ public BatteryTip[] newArray(int size) {
+ return new UnrestrictAppTip[size];
+ }
+ };
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java b/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java
index 5e30d7a52ec..13c8a91472e 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/AnomalyEventWrapper.java
@@ -48,7 +48,8 @@ final class AnomalyEventWrapper {
mResourceIndex = mPowerAnomalyEvent.getKey().getNumber();
}
- private T getInfo(Function warningBannerInfoSupplier,
+ private T getInfo(
+ Function warningBannerInfoSupplier,
Function warningItemInfoSupplier) {
if (warningBannerInfoSupplier != null && mPowerAnomalyEvent.hasWarningBannerInfo()) {
return warningBannerInfoSupplier.apply(mPowerAnomalyEvent.getWarningBannerInfo());
@@ -60,15 +61,19 @@ final class AnomalyEventWrapper {
private int getResourceId(int resourceId, int resourceIndex, String defType) {
final String key = getStringFromArrayResource(resourceId, resourceIndex);
- return TextUtils.isEmpty(key) ? 0
+ return TextUtils.isEmpty(key)
+ ? 0
: mContext.getResources().getIdentifier(key, defType, mContext.getPackageName());
}
- private String getString(Function warningBannerInfoSupplier,
+ private String getString(
+ Function warningBannerInfoSupplier,
Function warningItemInfoSupplier,
- int resourceId, int resourceIndex) {
+ int resourceId,
+ int resourceIndex) {
final String string = getInfo(warningBannerInfoSupplier, warningItemInfoSupplier);
- return (!TextUtils.isEmpty(string) || resourceId <= 0) ? string
+ return (!TextUtils.isEmpty(string) || resourceId <= 0)
+ ? string
: getStringFromArrayResource(resourceId, resourceIndex);
}
@@ -78,7 +83,8 @@ final class AnomalyEventWrapper {
}
final String[] stringArray = mContext.getResources().getStringArray(resourceId);
return (resourceIndex >= 0 && resourceIndex < stringArray.length)
- ? stringArray[resourceIndex] : null;
+ ? stringArray[resourceIndex]
+ : null;
}
void setRelatedBatteryDiffEntry(BatteryDiffEntry batteryDiffEntry) {
@@ -98,13 +104,13 @@ final class AnomalyEventWrapper {
}
String getTitleString() {
- final String titleStringFromProto = getInfo(WarningBannerInfo::getTitleString,
- WarningItemInfo::getTitleString);
+ final String titleStringFromProto =
+ getInfo(WarningBannerInfo::getTitleString, WarningItemInfo::getTitleString);
if (!TextUtils.isEmpty(titleStringFromProto)) {
return titleStringFromProto;
}
- final int titleFormatResId = getResourceId(R.array.power_anomaly_title_ids,
- mResourceIndex, "string");
+ final int titleFormatResId =
+ getResourceId(R.array.power_anomaly_title_ids, mResourceIndex, "string");
if (mPowerAnomalyEvent.hasWarningBannerInfo()) {
return mContext.getString(titleFormatResId);
} else if (mPowerAnomalyEvent.hasWarningItemInfo() && mRelatedBatteryDiffEntry != null) {
@@ -115,20 +121,24 @@ final class AnomalyEventWrapper {
}
String getMainBtnString() {
- return getString(WarningBannerInfo::getMainButtonString,
+ return getString(
+ WarningBannerInfo::getMainButtonString,
WarningItemInfo::getMainButtonString,
- R.array.power_anomaly_main_btn_strings, mResourceIndex);
+ R.array.power_anomaly_main_btn_strings,
+ mResourceIndex);
}
String getDismissBtnString() {
- return getString(WarningBannerInfo::getCancelButtonString,
+ return getString(
+ WarningBannerInfo::getCancelButtonString,
WarningItemInfo::getCancelButtonString,
- R.array.power_anomaly_dismiss_btn_strings, mResourceIndex);
+ R.array.power_anomaly_dismiss_btn_strings,
+ mResourceIndex);
}
String getAnomalyHintString() {
- final String anomalyHintStringFromProto = getInfo(null,
- WarningItemInfo::getWarningInfoString);
+ final String anomalyHintStringFromProto =
+ getInfo(null, WarningItemInfo::getWarningInfoString);
return TextUtils.isEmpty(anomalyHintStringFromProto)
? getStringFromArrayResource(R.array.power_anomaly_hint_messages, mResourceIndex)
: anomalyHintStringFromProto;
@@ -148,8 +158,9 @@ final class AnomalyEventWrapper {
String getAnomalyEntryKey() {
return mPowerAnomalyEvent.hasWarningItemInfo()
- && mPowerAnomalyEvent.getWarningItemInfo().hasItemKey()
- ? mPowerAnomalyEvent.getWarningItemInfo().getItemKey() : null;
+ && mPowerAnomalyEvent.getWarningItemInfo().hasItemKey()
+ ? mPowerAnomalyEvent.getWarningItemInfo().getItemKey()
+ : null;
}
boolean hasSubSettingLauncher() {
@@ -163,23 +174,24 @@ final class AnomalyEventWrapper {
if (mSubSettingLauncher != null) {
return mSubSettingLauncher;
}
- final String destinationClassName = getInfo(
- WarningBannerInfo::getMainButtonDestination, null);
+ final String destinationClassName =
+ getInfo(WarningBannerInfo::getMainButtonDestination, null);
if (!TextUtils.isEmpty(destinationClassName)) {
- final Integer sourceMetricsCategory = getInfo(
- WarningBannerInfo::getMainButtonSourceMetricsCategory, null);
- final String preferenceHighlightKey = getInfo(
- WarningBannerInfo::getMainButtonSourceHighlightKey, null);
+ final Integer sourceMetricsCategory =
+ getInfo(WarningBannerInfo::getMainButtonSourceMetricsCategory, null);
+ final String preferenceHighlightKey =
+ getInfo(WarningBannerInfo::getMainButtonSourceHighlightKey, null);
Bundle arguments = Bundle.EMPTY;
if (!TextUtils.isEmpty(preferenceHighlightKey)) {
arguments = new Bundle(1);
- arguments.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
- preferenceHighlightKey);
+ arguments.putString(
+ SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, preferenceHighlightKey);
}
- mSubSettingLauncher = new SubSettingLauncher(mContext)
- .setDestination(destinationClassName)
- .setSourceMetricsCategory(sourceMetricsCategory)
- .setArguments(arguments);
+ mSubSettingLauncher =
+ new SubSettingLauncher(mContext)
+ .setDestination(destinationClassName)
+ .setSourceMetricsCategory(sourceMetricsCategory)
+ .setArguments(arguments);
}
return mSubSettingLauncher;
}
@@ -199,13 +211,13 @@ final class AnomalyEventWrapper {
return null;
}
final WarningItemInfo warningItemInfo = mPowerAnomalyEvent.getWarningItemInfo();
- final Long startTimestamp = warningItemInfo.hasStartTimestamp()
- ? warningItemInfo.getStartTimestamp() : null;
- final Long endTimestamp = warningItemInfo.hasEndTimestamp()
- ? warningItemInfo.getEndTimestamp() : null;
+ final Long startTimestamp =
+ warningItemInfo.hasStartTimestamp() ? warningItemInfo.getStartTimestamp() : null;
+ final Long endTimestamp =
+ warningItemInfo.hasEndTimestamp() ? warningItemInfo.getEndTimestamp() : null;
if (startTimestamp != null && endTimestamp != null) {
- mHighlightSlotPair = batteryLevelData
- .getIndexByTimestamps(startTimestamp, endTimestamp);
+ mHighlightSlotPair =
+ batteryLevelData.getIndexByTimestamps(startTimestamp, endTimestamp);
if (mHighlightSlotPair.first == BatteryChartViewModel.SELECTED_INDEX_INVALID
|| mHighlightSlotPair.second == BatteryChartViewModel.SELECTED_INDEX_INVALID) {
// Drop invalid mHighlightSlotPair index
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
index bb6593c9149..8ae8edd4be0 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartPreferenceController.java
@@ -55,8 +55,12 @@ 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, OnResume {
+ implements PreferenceControllerMixin,
+ LifecycleObserver,
+ OnCreate,
+ OnDestroy,
+ OnSaveInstanceState,
+ OnResume {
private static final String TAG = "BatteryChartPreferenceController";
private static final String PREFERENCE_KEY = "battery_chart";
@@ -73,22 +77,14 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
void onSelectedIndexUpdated();
}
- @VisibleForTesting
- Context mPrefContext;
- @VisibleForTesting
- TextView mChartSummaryTextView;
- @VisibleForTesting
- BatteryChartView mDailyChartView;
- @VisibleForTesting
- BatteryChartView mHourlyChartView;
- @VisibleForTesting
- int mDailyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
- @VisibleForTesting
- int mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
- @VisibleForTesting
- int mDailyHighlightSlotIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID;
- @VisibleForTesting
- int mHourlyHighlightSlotIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID;
+ @VisibleForTesting Context mPrefContext;
+ @VisibleForTesting TextView mChartSummaryTextView;
+ @VisibleForTesting BatteryChartView mDailyChartView;
+ @VisibleForTesting BatteryChartView mHourlyChartView;
+ @VisibleForTesting int mDailyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
+ @VisibleForTesting int mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
+ @VisibleForTesting int mDailyHighlightSlotIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID;
+ @VisibleForTesting int mHourlyHighlightSlotIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID;
private boolean mIs24HourFormat;
private View mBatteryChartViewGroup;
@@ -100,13 +96,14 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final AnimatorListenerAdapter mHourlyChartFadeInAdapter =
- createHourlyChartAnimatorListenerAdapter(/*visible=*/ true);
+ createHourlyChartAnimatorListenerAdapter(/* visible= */ true);
private final AnimatorListenerAdapter mHourlyChartFadeOutAdapter =
- createHourlyChartAnimatorListenerAdapter(/*visible=*/ false);
+ createHourlyChartAnimatorListenerAdapter(/* visible= */ false);
@VisibleForTesting
final DailyChartLabelTextGenerator mDailyChartLabelTextGenerator =
new DailyChartLabelTextGenerator();
+
@VisibleForTesting
final HourlyChartLabelTextGenerator mHourlyChartLabelTextGenerator =
new HourlyChartLabelTextGenerator();
@@ -116,8 +113,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
super(context);
mActivity = activity;
mIs24HourFormat = DateFormat.is24HourFormat(context);
- mMetricsFeatureProvider =
- FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
+ mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -128,12 +124,13 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
if (savedInstanceState == null) {
return;
}
- mDailyChartIndex =
- savedInstanceState.getInt(KEY_DAILY_CHART_INDEX, mDailyChartIndex);
- mHourlyChartIndex =
- savedInstanceState.getInt(KEY_HOURLY_CHART_INDEX, mHourlyChartIndex);
- Log.d(TAG, String.format("onCreate() dailyIndex=%d hourlyIndex=%d",
- mDailyChartIndex, mHourlyChartIndex));
+ mDailyChartIndex = savedInstanceState.getInt(KEY_DAILY_CHART_INDEX, mDailyChartIndex);
+ mHourlyChartIndex = savedInstanceState.getInt(KEY_HOURLY_CHART_INDEX, mHourlyChartIndex);
+ Log.d(
+ TAG,
+ String.format(
+ "onCreate() dailyIndex=%d hourlyIndex=%d",
+ mDailyChartIndex, mHourlyChartIndex));
}
@Override
@@ -149,8 +146,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
savedInstance.putInt(KEY_DAILY_CHART_INDEX, mDailyChartIndex);
savedInstance.putInt(KEY_HOURLY_CHART_INDEX, mHourlyChartIndex);
- Log.d(TAG, String.format("onSaveInstanceState() dailyIndex=%d hourlyIndex=%d",
- mDailyChartIndex, mHourlyChartIndex));
+ Log.d(
+ TAG,
+ String.format(
+ "onSaveInstanceState() dailyIndex=%d hourlyIndex=%d",
+ mDailyChartIndex, mHourlyChartIndex));
}
@Override
@@ -158,7 +158,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
if (mActivity == null || mActivity.isChangingConfigurations()) {
BatteryDiffEntry.clearCache();
}
- mHandler.removeCallbacksAndMessages(/*token=*/ null);
+ mHandler.removeCallbacksAndMessages(/* token= */ null);
}
@Override
@@ -204,19 +204,22 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
refreshUi();
return;
}
- mDailyViewModel = new BatteryChartViewModel(
- batteryLevelData.getDailyBatteryLevels().getLevels(),
- batteryLevelData.getDailyBatteryLevels().getTimestamps(),
- BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS,
- mDailyChartLabelTextGenerator);
+ mDailyViewModel =
+ new BatteryChartViewModel(
+ batteryLevelData.getDailyBatteryLevels().getLevels(),
+ batteryLevelData.getDailyBatteryLevels().getTimestamps(),
+ BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS,
+ mDailyChartLabelTextGenerator);
mHourlyViewModels = new ArrayList<>();
for (BatteryLevelData.PeriodBatteryLevelData hourlyBatteryLevelsPerDay :
batteryLevelData.getHourlyBatteryLevelsPerDay()) {
- mHourlyViewModels.add(new BatteryChartViewModel(
- hourlyBatteryLevelsPerDay.getLevels(),
- hourlyBatteryLevelsPerDay.getTimestamps(),
- BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS,
- mHourlyChartLabelTextGenerator.updateSpecialCaseContext(batteryLevelData)));
+ mHourlyViewModels.add(
+ new BatteryChartViewModel(
+ hourlyBatteryLevelsPerDay.getLevels(),
+ hourlyBatteryLevelsPerDay.getTimestamps(),
+ BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS,
+ mHourlyChartLabelTextGenerator.updateSpecialCaseContext(
+ batteryLevelData)));
}
refreshUi();
}
@@ -248,17 +251,21 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
mDailyChartIndex = mDailyHighlightSlotIndex;
mHourlyChartIndex = mHourlyHighlightSlotIndex;
- Log.d(TAG, String.format("onDailyChartSelect:%d, onHourlyChartSelect:%d",
- mDailyChartIndex, mHourlyChartIndex));
+ Log.d(
+ TAG,
+ String.format(
+ "onDailyChartSelect:%d, onHourlyChartSelect:%d",
+ mDailyChartIndex, mHourlyChartIndex));
refreshUi();
- mHandler.post(() -> mDailyChartView.announceForAccessibility(
- getAccessibilityAnnounceMessage()));
+ mHandler.post(
+ () -> mDailyChartView.announceForAccessibility(getAccessibilityAnnounceMessage()));
if (mOnSelectedIndexUpdatedListener != null) {
mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated();
}
}
- void setBatteryChartView(@NonNull final BatteryChartView dailyChartView,
+ void setBatteryChartView(
+ @NonNull final BatteryChartView dailyChartView,
@NonNull final BatteryChartView hourlyChartView) {
final View parentView = (View) dailyChartView.getParent();
if (parentView != null && parentView.getId() == R.id.battery_chart_group) {
@@ -270,58 +277,67 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
if (mBatteryChartViewGroup != null) {
final View grandparentView = (View) mBatteryChartViewGroup.getParent();
- mChartSummaryTextView = grandparentView != null
- ? grandparentView.findViewById(R.id.chart_summary) : null;
+ mChartSummaryTextView =
+ grandparentView != null
+ ? grandparentView.findViewById(R.id.chart_summary)
+ : null;
}
}
- private void setBatteryChartViewInner(@NonNull final BatteryChartView dailyChartView,
+ private void setBatteryChartViewInner(
+ @NonNull final BatteryChartView dailyChartView,
@NonNull final BatteryChartView hourlyChartView) {
mDailyChartView = dailyChartView;
- mDailyChartView.setOnSelectListener(trapezoidIndex -> {
- if (mDailyChartIndex == trapezoidIndex) {
- return;
- }
- Log.d(TAG, "onDailyChartSelect:" + trapezoidIndex);
- mDailyChartIndex = trapezoidIndex;
- mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
- refreshUi();
- mHandler.post(() -> mDailyChartView.announceForAccessibility(
- getAccessibilityAnnounceMessage()));
- mMetricsFeatureProvider.action(
- mPrefContext,
- trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
- ? SettingsEnums.ACTION_BATTERY_USAGE_DAILY_SHOW_ALL
- : SettingsEnums.ACTION_BATTERY_USAGE_DAILY_TIME_SLOT,
- mDailyChartIndex);
- if (mOnSelectedIndexUpdatedListener != null) {
- mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated();
- }
- });
+ mDailyChartView.setOnSelectListener(
+ trapezoidIndex -> {
+ if (mDailyChartIndex == trapezoidIndex) {
+ return;
+ }
+ Log.d(TAG, "onDailyChartSelect:" + trapezoidIndex);
+ mDailyChartIndex = trapezoidIndex;
+ mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
+ refreshUi();
+ mHandler.post(
+ () ->
+ mDailyChartView.announceForAccessibility(
+ getAccessibilityAnnounceMessage()));
+ mMetricsFeatureProvider.action(
+ mPrefContext,
+ trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
+ ? SettingsEnums.ACTION_BATTERY_USAGE_DAILY_SHOW_ALL
+ : SettingsEnums.ACTION_BATTERY_USAGE_DAILY_TIME_SLOT,
+ mDailyChartIndex);
+ if (mOnSelectedIndexUpdatedListener != null) {
+ mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated();
+ }
+ });
mHourlyChartView = hourlyChartView;
- mHourlyChartView.setOnSelectListener(trapezoidIndex -> {
- if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
- // This will happen when a daily slot and an hour slot are clicked together.
- return;
- }
- if (mHourlyChartIndex == trapezoidIndex) {
- return;
- }
- Log.d(TAG, "onHourlyChartSelect:" + trapezoidIndex);
- mHourlyChartIndex = trapezoidIndex;
- refreshUi();
- mHandler.post(() -> mHourlyChartView.announceForAccessibility(
- getAccessibilityAnnounceMessage()));
- mMetricsFeatureProvider.action(
- mPrefContext,
- trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
- ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
- : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT,
- mHourlyChartIndex);
- if (mOnSelectedIndexUpdatedListener != null) {
- mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated();
- }
- });
+ mHourlyChartView.setOnSelectListener(
+ trapezoidIndex -> {
+ if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
+ // This will happen when a daily slot and an hour slot are clicked together.
+ return;
+ }
+ if (mHourlyChartIndex == trapezoidIndex) {
+ return;
+ }
+ Log.d(TAG, "onHourlyChartSelect:" + trapezoidIndex);
+ mHourlyChartIndex = trapezoidIndex;
+ refreshUi();
+ mHandler.post(
+ () ->
+ mHourlyChartView.announceForAccessibility(
+ getAccessibilityAnnounceMessage()));
+ mMetricsFeatureProvider.action(
+ mPrefContext,
+ trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
+ ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
+ : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT,
+ mHourlyChartIndex);
+ if (mOnSelectedIndexUpdatedListener != null) {
+ mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated();
+ }
+ });
refreshUi();
}
@@ -371,18 +387,18 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
// Multiple days are selected, hide the hourly chart view.
- animateBatteryHourlyChartView(/*visible=*/ false);
+ animateBatteryHourlyChartView(/* visible= */ false);
} else {
- animateBatteryHourlyChartView(/*visible=*/ true);
- final BatteryChartViewModel hourlyViewModel =
- mHourlyViewModels.get(mDailyChartIndex);
+ animateBatteryHourlyChartView(/* visible= */ true);
+ final BatteryChartViewModel hourlyViewModel = mHourlyViewModels.get(mDailyChartIndex);
if (mHourlyChartIndex >= hourlyViewModel.size()) {
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
}
hourlyViewModel.setSelectedIndex(mHourlyChartIndex);
- hourlyViewModel.setHighlightSlotIndex((mDailyChartIndex == mDailyHighlightSlotIndex)
- ? mHourlyHighlightSlotIndex
- : BatteryChartViewModel.SELECTED_INDEX_INVALID);
+ hourlyViewModel.setHighlightSlotIndex(
+ (mDailyChartIndex == mDailyHighlightSlotIndex)
+ ? mHourlyHighlightSlotIndex
+ : BatteryChartViewModel.SELECTED_INDEX_INVALID);
mHourlyChartView.setViewModel(hourlyViewModel);
}
}
@@ -401,8 +417,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return selectedDayText;
}
- final String selectedHourText = mHourlyViewModels.get(mDailyChartIndex).getFullText(
- mHourlyChartIndex);
+ final String selectedHourText =
+ mHourlyViewModels.get(mDailyChartIndex).getFullText(mHourlyChartIndex);
if (isBatteryLevelDataInOneDay()) {
return selectedHourText;
}
@@ -422,7 +438,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private void animateBatteryChartViewGroup() {
if (mBatteryChartViewGroup != null && mBatteryChartViewGroup.getAlpha() == 0) {
- mBatteryChartViewGroup.animate().alpha(1f).setDuration(FADE_IN_ANIMATION_DURATION)
+ mBatteryChartViewGroup
+ .animate()
+ .alpha(1f)
+ .setDuration(FADE_IN_ANIMATION_DURATION)
.start();
}
}
@@ -435,13 +454,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
if (visible) {
mHourlyChartView.setVisibility(View.VISIBLE);
- mHourlyChartView.animate()
+ mHourlyChartView
+ .animate()
.alpha(1f)
.setDuration(FADE_IN_ANIMATION_DURATION)
.setListener(mHourlyChartFadeInAdapter)
.start();
} else {
- mHourlyChartView.animate()
+ mHourlyChartView
+ .animate()
.alpha(0f)
.setDuration(FADE_OUT_ANIMATION_DURATION)
.setListener(mHourlyChartFadeOutAdapter)
@@ -467,6 +488,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mHourlyChartView.setVisibility(visibility);
}
}
+
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
@@ -483,7 +505,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
private boolean isAllSelected() {
return (isBatteryLevelDataInOneDay()
- || mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL)
+ || mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL)
&& mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL;
}
@@ -493,8 +515,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return 0;
}
List dailyTimestamps = batteryLevelData.getDailyBatteryLevels().getTimestamps();
- return (int) ((dailyTimestamps.get(dailyTimestamps.size() - 1) - dailyTimestamps.get(0))
- / DateUtils.HOUR_IN_MILLIS);
+ return (int)
+ ((dailyTimestamps.get(dailyTimestamps.size() - 1) - dailyTimestamps.get(0))
+ / DateUtils.HOUR_IN_MILLIS);
}
/** Used for {@link AppBatteryPreferenceController}. */
@@ -505,17 +528,21 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
if (batteryHistoryMap == null || batteryHistoryMap.isEmpty()) {
return null;
}
- Log.d(TAG, String.format("getBatterySinceLastFullChargeUsageData() size=%d time=%d/ms",
- batteryHistoryMap.size(), (System.currentTimeMillis() - start)));
+ Log.d(
+ TAG,
+ String.format(
+ "getBatterySinceLastFullChargeUsageData() size=%d time=%d/ms",
+ batteryHistoryMap.size(), (System.currentTimeMillis() - start)));
final Map> batteryUsageData =
DataProcessor.getBatteryUsageData(context, batteryHistoryMap);
if (batteryUsageData == null) {
return null;
}
- BatteryDiffData allBatteryDiffData = batteryUsageData.get(
- BatteryChartViewModel.SELECTED_INDEX_ALL).get(
- BatteryChartViewModel.SELECTED_INDEX_ALL);
+ BatteryDiffData allBatteryDiffData =
+ batteryUsageData
+ .get(BatteryChartViewModel.SELECTED_INDEX_ALL)
+ .get(BatteryChartViewModel.SELECTED_INDEX_ALL);
return allBatteryDiffData == null ? null : allBatteryDiffData.getAppDiffEntryList();
}
@@ -546,23 +573,23 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return null;
}
- private final class DailyChartLabelTextGenerator implements
- BatteryChartViewModel.LabelTextGenerator {
+ private final class DailyChartLabelTextGenerator
+ implements BatteryChartViewModel.LabelTextGenerator {
@Override
public String generateText(List timestamps, int index) {
- return ConvertUtils.utcToLocalTimeDayOfWeek(mContext,
- timestamps.get(index), /* isAbbreviation= */ true);
+ return ConvertUtils.utcToLocalTimeDayOfWeek(
+ mContext, timestamps.get(index), /* isAbbreviation= */ true);
}
@Override
public String generateFullText(List timestamps, int index) {
- return ConvertUtils.utcToLocalTimeDayOfWeek(mContext,
- timestamps.get(index), /* isAbbreviation= */ false);
+ return ConvertUtils.utcToLocalTimeDayOfWeek(
+ mContext, timestamps.get(index), /* isAbbreviation= */ false);
}
}
- private final class HourlyChartLabelTextGenerator implements
- BatteryChartViewModel.LabelTextGenerator {
+ private final class HourlyChartLabelTextGenerator
+ implements BatteryChartViewModel.LabelTextGenerator {
private static final int FULL_CHARGE_BATTERY_LEVEL = 100;
private boolean mIsFromFullCharge;
@@ -593,8 +620,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
public String generateFullText(List timestamps, int index) {
return index == timestamps.size() - 1
? generateText(timestamps, index)
- : mContext.getString(R.string.battery_usage_timestamps_hyphen,
- generateText(timestamps, index), generateText(timestamps, index + 1));
+ : mContext.getString(
+ R.string.battery_usage_timestamps_hyphen,
+ generateText(timestamps, index),
+ generateText(timestamps, index + 1));
}
HourlyChartLabelTextGenerator updateSpecialCaseContext(
@@ -604,8 +633,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
this.mIsFromFullCharge =
firstDayLevelData.getLevels().get(0) == FULL_CHARGE_BATTERY_LEVEL;
this.mFistTimestamp = firstDayLevelData.getTimestamps().get(0);
- this.mLatestTimestamp = getLast(getLast(
- batteryLevelData.getHourlyBatteryLevelsPerDay()).getTimestamps());
+ this.mLatestTimestamp =
+ getLast(
+ getLast(batteryLevelData.getHourlyBatteryLevelsPerDay())
+ .getTimestamps());
return this;
}
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java
index bb468fe35d6..ad5d4203842 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartView.java
@@ -74,7 +74,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private final String[] mPercentages = getPercentages();
private final Rect mIndent = new Rect();
- private final Rect[] mPercentageBounds = new Rect[]{new Rect(), new Rect(), new Rect()};
+ private final Rect[] mPercentageBounds = new Rect[] {new Rect(), new Rect(), new Rect()};
private final List mAxisLabelsBounds = new ArrayList<>();
private final Set mLabelDrawnIndexes = new ArraySet<>();
private final int mLayoutDirection =
@@ -106,11 +106,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private AccessibilityNodeProvider mAccessibilityNodeProvider;
private BatteryChartView.OnSelectListener mOnSelectListener;
- @VisibleForTesting
- TrapezoidSlot[] mTrapezoidSlots;
+ @VisibleForTesting TrapezoidSlot[] mTrapezoidSlots;
// Records the location to calculate selected index.
- @VisibleForTesting
- float mTouchUpEventX = Float.MIN_VALUE;
+ @VisibleForTesting float mTouchUpEventX = Float.MIN_VALUE;
public BatteryChartView(Context context) {
super(context, null);
@@ -133,9 +131,13 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
return;
}
- Log.d(TAG, String.format(
- "setViewModel(): size: %d, selectedIndex: %d, getHighlightSlotIndex: %d",
- viewModel.size(), viewModel.selectedIndex(), viewModel.getHighlightSlotIndex()));
+ Log.d(
+ TAG,
+ String.format(
+ "setViewModel(): size: %d, selectedIndex: %d, getHighlightSlotIndex: %d",
+ viewModel.size(),
+ viewModel.selectedIndex(),
+ viewModel.getHighlightSlotIndex()));
mViewModel = viewModel;
initializeAxisLabelsBounds();
initializeTrapezoidSlots(viewModel.size() - 1);
@@ -169,7 +171,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTextPaint.setTextAlign(Paint.Align.LEFT);
for (int index = 0; index < mPercentages.length; index++) {
mTextPaint.getTextBounds(
- mPercentages[index], 0, mPercentages[index].length(),
+ mPercentages[index],
+ 0,
+ mPercentages[index].length(),
mPercentageBounds[index]);
}
// Updates the indent configurations.
@@ -292,7 +296,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Selects all if users click the same trapezoid item two times.
mOnSelectListener.onSelect(
index == mViewModel.selectedIndex()
- ? BatteryChartViewModel.SELECTED_INDEX_ALL : index);
+ ? BatteryChartViewModel.SELECTED_INDEX_ALL
+ : index);
}
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
}
@@ -327,8 +332,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
setBackgroundColor(Color.TRANSPARENT);
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);
mTrapezoidColor = Utils.getDisabled(context, mTrapezoidSolidColor);
- mTrapezoidHoverColor = Utils.getColorAttrDefaultColor(context,
- com.android.internal.R.attr.materialColorSecondaryContainer);
+ mTrapezoidHoverColor =
+ Utils.getColorAttrDefaultColor(
+ context, com.android.internal.R.attr.materialColorSecondaryContainer);
// Initializes the divider line paint.
final Resources resources = getContext().getResources();
mDividerWidth = resources.getDimensionPixelSize(R.dimen.chartview_divider_width);
@@ -353,25 +359,26 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Initializes for drawing text information.
mTextPadding = resources.getDimensionPixelSize(R.dimen.chartview_text_padding);
// Initializes the padding top for drawing text information.
- mTransomViewHeight = resources.getDimensionPixelSize(
- R.dimen.chartview_transom_layout_height);
+ mTransomViewHeight =
+ resources.getDimensionPixelSize(R.dimen.chartview_transom_layout_height);
}
private void initializeTransomPaint() {
- if (mTransomLinePaint != null && mTransomSelectedSlotPaint != null
+ if (mTransomLinePaint != null
+ && mTransomSelectedSlotPaint != null
&& mTransomIcon != null) {
return;
}
// Initializes the transom line paint.
final Resources resources = getContext().getResources();
- final int transomLineWidth = resources.getDimensionPixelSize(
- R.dimen.chartview_transom_width);
+ final int transomLineWidth =
+ resources.getDimensionPixelSize(R.dimen.chartview_transom_width);
final int transomRadius = resources.getDimensionPixelSize(R.dimen.chartview_transom_radius);
mTransomPadding = transomRadius * .5f;
mTransomTop = resources.getDimensionPixelSize(R.dimen.chartview_transom_padding_top);
mTransomLineDefaultColor = Utils.getDisabled(mContext, DIVIDER_COLOR);
- mTransomLineSelectedColor = resources.getColor(
- R.color.color_battery_anomaly_yellow_selector);
+ mTransomLineSelectedColor =
+ resources.getColor(R.color.color_battery_anomaly_yellow_selector);
final int slotHighlightColor = Utils.getDisabled(mContext, mTransomLineSelectedColor);
mTransomIconSize = resources.getDimensionPixelSize(R.dimen.chartview_transom_icon_size);
mTransomLinePaint = new Paint();
@@ -396,18 +403,16 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
final float availableSpace = bottomOffsetY - topOffsetY;
mDividerPaint.setColor(DIVIDER_COLOR);
- final float dividerOffsetUnit =
- availableSpace / (float) (HORIZONTAL_DIVIDER_COUNT - 1);
+ final float dividerOffsetUnit = availableSpace / (float) (HORIZONTAL_DIVIDER_COUNT - 1);
// Draws 5 divider lines.
for (int index = 0; index < HORIZONTAL_DIVIDER_COUNT; index++) {
float offsetY = topOffsetY + dividerOffsetUnit * index;
- canvas.drawLine(mIndent.left, offsetY,
- mIndent.left + width, offsetY, mDividerPaint);
+ canvas.drawLine(mIndent.left, offsetY, mIndent.left + width, offsetY, mDividerPaint);
// Draws percentage text only for 100% / 50% / 0%
if (index % 2 == 0) {
- drawPercentage(canvas, /*index=*/ (index + 1) / 2, offsetY);
+ drawPercentage(canvas, /* index= */ (index + 1) / 2, offsetY);
}
}
}
@@ -438,21 +443,23 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
Rect[] axisLabelDisplayAreas;
switch (mViewModel.axisLabelPosition()) {
case CENTER_OF_TRAPEZOIDS:
- axisLabelDisplayAreas = getAxisLabelDisplayAreas(
- /* size= */ mViewModel.size() - 1,
- /* baselineX= */ mIndent.left + mDividerWidth + unitWidth * .5f,
- /* offsetX= */ mDividerWidth + unitWidth,
- baselineY,
- /* shiftFirstAndLast= */ false);
+ axisLabelDisplayAreas =
+ getAxisLabelDisplayAreas(
+ /* size= */ mViewModel.size() - 1,
+ /* baselineX= */ mIndent.left + mDividerWidth + unitWidth * .5f,
+ /* offsetX= */ mDividerWidth + unitWidth,
+ baselineY,
+ /* shiftFirstAndLast= */ false);
break;
case BETWEEN_TRAPEZOIDS:
default:
- axisLabelDisplayAreas = getAxisLabelDisplayAreas(
- /* size= */ mViewModel.size(),
- /* baselineX= */ mIndent.left + mDividerWidth * .5f,
- /* offsetX= */ mDividerWidth + unitWidth,
- baselineY,
- /* shiftFirstAndLast= */ true);
+ axisLabelDisplayAreas =
+ getAxisLabelDisplayAreas(
+ /* size= */ mViewModel.size(),
+ /* baselineX= */ mIndent.left + mDividerWidth * .5f,
+ /* offsetX= */ mDividerWidth + unitWidth,
+ baselineY,
+ /* shiftFirstAndLast= */ true);
break;
}
drawAxisLabels(canvas, axisLabelDisplayAreas, baselineY);
@@ -481,8 +488,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
/** Gets all the axis label texts displaying area positions if they are shown. */
- private Rect[] getAxisLabelDisplayAreas(final int size, final float baselineX,
- final float offsetX, final float baselineY, final boolean shiftFirstAndLast) {
+ private Rect[] getAxisLabelDisplayAreas(
+ final int size,
+ final float baselineX,
+ final float offsetX,
+ final float baselineY,
+ final boolean shiftFirstAndLast) {
final Rect[] result = new Rect[size];
for (int index = 0; index < result.length; index++) {
final float width = mAxisLabelsBounds.get(index).width();
@@ -522,8 +533,11 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
* labels and then recursively draw the 3 parts. If there are any overlaps, skip drawing and go
* back to the uplevel of the recursion.
*/
- private void drawAxisLabelsBetweenStartIndexAndEndIndex(Canvas canvas,
- final Rect[] displayAreas, final int startIndex, final int endIndex,
+ private void drawAxisLabelsBetweenStartIndexAndEndIndex(
+ Canvas canvas,
+ final Rect[] displayAreas,
+ final int startIndex,
+ final int endIndex,
final float baselineY) {
if (endIndex - startIndex <= 1) {
return;
@@ -576,15 +590,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTextPaint.setTextAlign(Paint.Align.CENTER);
// Reverse the sort of axis labels for RTL
if (isRTL()) {
- index = mViewModel.axisLabelPosition() == BETWEEN_TRAPEZOIDS
- ? mViewModel.size() - index - 1 // for hourly
- : mViewModel.size() - index - 2; // for daily
+ index =
+ mViewModel.axisLabelPosition() == BETWEEN_TRAPEZOIDS
+ ? mViewModel.size() - index - 1 // for hourly
+ : mViewModel.size() - index - 2; // for daily
}
- canvas.drawText(
- mViewModel.getText(index),
- displayArea.centerX(),
- baselineY,
- mTextPaint);
+ canvas.drawText(mViewModel.getText(index), displayArea.centerX(), baselineY, mTextPaint);
mLabelDrawnIndexes.add(index);
}
@@ -594,8 +605,7 @@ 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 - mTrapezoidVOffset;
final float unitHeight = availableSpace / 100f;
@@ -608,17 +618,24 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
continue;
}
// Configures the trapezoid paint color.
- final int trapezoidColor = (mViewModel.selectedIndex() == index
- || mViewModel.selectedIndex() == BatteryChartViewModel.SELECTED_INDEX_ALL)
- ? mTrapezoidSolidColor : mTrapezoidColor;
- final boolean isHoverState = mHoveredIndex == index && isValidToDraw(mViewModel,
- mHoveredIndex);
+ final int trapezoidColor =
+ (mViewModel.selectedIndex() == index
+ || mViewModel.selectedIndex()
+ == BatteryChartViewModel.SELECTED_INDEX_ALL)
+ ? mTrapezoidSolidColor
+ : mTrapezoidColor;
+ final boolean isHoverState =
+ mHoveredIndex == index && isValidToDraw(mViewModel, mHoveredIndex);
mTrapezoidPaint.setColor(isHoverState ? mTrapezoidHoverColor : trapezoidColor);
- float leftTop = round(
- trapezoidBottom - requireNonNull(mViewModel.getLevel(index)) * unitHeight);
- float rightTop = round(trapezoidBottom
- - requireNonNull(mViewModel.getLevel(index + 1)) * unitHeight);
+ float leftTop =
+ round(
+ trapezoidBottom
+ - requireNonNull(mViewModel.getLevel(index)) * unitHeight);
+ float rightTop =
+ round(
+ trapezoidBottom
+ - requireNonNull(mViewModel.getLevel(index + 1)) * unitHeight);
// Mirror the shape of the trapezoid for RTL
if (isRTL()) {
float temp = leftTop;
@@ -639,8 +656,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
private boolean isHighlightSlotValid() {
- return mViewModel != null && mViewModel.getHighlightSlotIndex()
- != BatteryChartViewModel.SELECTED_INDEX_INVALID;
+ return mViewModel != null
+ && mViewModel.getHighlightSlotIndex()
+ != BatteryChartViewModel.SELECTED_INDEX_INVALID;
}
private void drawTransomLine(Canvas canvas) {
@@ -652,10 +670,13 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTransomLinePaint.setColor(mTransomLineDefaultColor);
final int width = getWidth() - abs(mIndent.width());
final float transomOffset = mTrapezoidHOffset + mDividerWidth * .5f + mTransomPadding;
- final float trapezoidBottom = getHeight() - mIndent.bottom - mDividerHeight - mDividerWidth
- - mTrapezoidVOffset;
- canvas.drawLine(mIndent.left + transomOffset, mTransomTop,
- mIndent.left + width - transomOffset, mTransomTop,
+ final float trapezoidBottom =
+ getHeight() - mIndent.bottom - mDividerHeight - mDividerWidth - mTrapezoidVOffset;
+ canvas.drawLine(
+ mIndent.left + transomOffset,
+ mTransomTop,
+ mIndent.left + width - transomOffset,
+ mTransomTop,
mTransomLinePaint);
drawTransomIcon(canvas);
// Draw selected segment of transom line and a highlight slot
@@ -663,22 +684,28 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
final int index = mViewModel.getHighlightSlotIndex();
final float startX = mTrapezoidSlots[index].mLeft;
final float endX = mTrapezoidSlots[index].mRight;
- canvas.drawLine(startX + mTransomPadding, mTransomTop,
- endX - mTransomPadding, mTransomTop,
+ canvas.drawLine(
+ startX + mTransomPadding,
+ mTransomTop,
+ endX - mTransomPadding,
+ mTransomTop,
mTransomLinePaint);
- canvas.drawRect(startX, mTransomTop, endX, trapezoidBottom,
- mTransomSelectedSlotPaint);
+ canvas.drawRect(startX, mTransomTop, endX, trapezoidBottom, mTransomSelectedSlotPaint);
}
private void drawTransomIcon(Canvas canvas) {
if (mTransomIcon == null) {
return;
}
- final int left = isRTL()
- ? mIndent.left - mTextPadding - mTransomIconSize
- : getWidth() - abs(mIndent.width()) + mTextPadding;
- mTransomIcon.setBounds(left, mTransomTop - mTransomIconSize / 2,
- left + mTransomIconSize, mTransomTop + mTransomIconSize / 2);
+ final int left =
+ isRTL()
+ ? mIndent.left - mTextPadding - mTransomIconSize
+ : getWidth() - abs(mIndent.width()) + mTextPadding;
+ mTransomIcon.setBounds(
+ left,
+ mTransomTop - mTransomIconSize / 2,
+ left + mTransomIconSize,
+ mTransomTop + mTransomIconSize / 2);
mTransomIcon.draw(canvas);
}
@@ -689,8 +716,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
for (int index = 0; index < mTrapezoidSlots.length; index++) {
final TrapezoidSlot slot = mTrapezoidSlots[index];
- if (x >= slot.mLeft - mTrapezoidHOffset
- && x <= slot.mRight + mTrapezoidHOffset) {
+ if (x >= slot.mLeft - mTrapezoidHOffset && x <= slot.mRight + mTrapezoidHOffset) {
return index;
}
}
@@ -712,9 +738,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private static boolean isTrapezoidIndexValid(
@NonNull BatteryChartViewModel viewModel, int trapezoidIndex) {
- return viewModel != null
- && trapezoidIndex >= 0
- && trapezoidIndex < viewModel.size() - 1;
+ return viewModel != null && trapezoidIndex >= 0 && trapezoidIndex < viewModel.size() - 1;
}
private static boolean isValidToDraw(BatteryChartViewModel viewModel, int trapezoidIndex) {
@@ -733,10 +757,11 @@ 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)
+ };
}
private class BatteryChartAccessibilityNodeProvider extends AccessibilityNodeProvider {
@@ -772,8 +797,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
@Override
- public boolean performAction(int virtualViewId, int action,
- @Nullable Bundle arguments) {
+ public boolean performAction(int virtualViewId, int action, @Nullable Bundle arguments) {
if (virtualViewId == AccessibilityNodeProvider.HOST_VIEW_ID) {
return performAccessibilityAction(action, arguments);
}
@@ -783,11 +807,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
return true;
case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
- return sendAccessibilityEvent(virtualViewId,
- AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
+ return sendAccessibilityEvent(
+ virtualViewId, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
- return sendAccessibilityEvent(virtualViewId,
+ return sendAccessibilityEvent(
+ virtualViewId,
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
default:
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewModel.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewModel.java
index bf8a771a117..6ec01a4c344 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewModel.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryChartViewModel.java
@@ -57,14 +57,18 @@ class BatteryChartViewModel {
private int mSelectedIndex = SELECTED_INDEX_ALL;
private int mHighlightSlotIndex = SELECTED_INDEX_INVALID;
- BatteryChartViewModel(@NonNull List levels, @NonNull List timestamps,
+ BatteryChartViewModel(
+ @NonNull List levels,
+ @NonNull List timestamps,
@NonNull AxisLabelPosition axisLabelPosition,
@NonNull LabelTextGenerator labelTextGenerator) {
Preconditions.checkArgument(
levels.size() == timestamps.size() && levels.size() >= MIN_LEVELS_DATA_SIZE,
- String.format(Locale.ENGLISH,
+ String.format(
+ Locale.ENGLISH,
"Invalid BatteryChartViewModel levels.size: %d, timestamps.size: %d.",
- levels.size(), timestamps.size()));
+ levels.size(),
+ timestamps.size()));
mLevels = levels;
mTimestamps = timestamps;
mAxisLabelPosition = axisLabelPosition;
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
index b186c60866e..a8be398d144 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
@@ -64,8 +64,7 @@ public class BatteryDiffEntry {
private static final Map> SPECIAL_ENTRY_MAP =
Map.of(
SYSTEM_APPS_KEY,
- Pair.create(
- R.string.battery_usage_system_apps, R.drawable.ic_power_system),
+ Pair.create(R.string.battery_usage_system_apps, R.drawable.ic_power_system),
UNINSTALLED_APPS_KEY,
Pair.create(
R.string.battery_usage_uninstalled_apps,
@@ -100,16 +99,11 @@ 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,
@@ -150,12 +144,24 @@ public class BatteryDiffEntry {
}
public BatteryDiffEntry(Context context, String key, String legacyLabel, int consumerType) {
- this(context, /*uid=*/ 0, /*userId=*/ 0, key, /*isHidden=*/ false, /*componentId=*/ -1,
- /*legacyPackageName=*/ null, legacyLabel, consumerType,
- /*foregroundUsageTimeInMs=*/ 0, /*backgroundUsageTimeInMs=*/ 0,
- /*screenOnTimeInMs=*/ 0, /*consumePower=*/ 0, /*foregroundUsageConsumePower=*/ 0,
- /*foregroundServiceUsageConsumePower=*/ 0, /*backgroundUsageConsumePower=*/ 0,
- /*cachedUsageConsumePower=*/ 0);
+ this(
+ context,
+ /* uid= */ 0,
+ /* userId= */ 0,
+ key,
+ /* isHidden= */ false,
+ /* componentId= */ -1,
+ /* legacyPackageName= */ null,
+ legacyLabel,
+ consumerType,
+ /* foregroundUsageTimeInMs= */ 0,
+ /* backgroundUsageTimeInMs= */ 0,
+ /* screenOnTimeInMs= */ 0,
+ /* consumePower= */ 0,
+ /* foregroundUsageConsumePower= */ 0,
+ /* foregroundServiceUsageConsumePower= */ 0,
+ /* backgroundUsageConsumePower= */ 0,
+ /* cachedUsageConsumePower= */ 0);
}
/** Sets the total consumed power in a specific time slot. */
@@ -286,7 +292,8 @@ public class BatteryDiffEntry {
/** Whether the current BatteryDiffEntry is uninstalled app or not. */
public boolean isUninstalledEntry() {
final String packageName = getPackageName();
- if (TextUtils.isEmpty(packageName) || isSystemEntry()
+ if (TextUtils.isEmpty(packageName)
+ || isSystemEntry()
// Some special package UIDs could be 0. Those packages are not installed by users.
|| mUid == BatteryUtils.UID_ZERO) {
return false;
@@ -468,8 +475,9 @@ public class BatteryDiffEntry {
mAppIcon = nameAndIcon.mIcon;
}
- final BatteryEntry.NameAndIcon nameAndIcon = BatteryEntry.loadNameAndIcon(
- mContext, uid, /*batteryEntry=*/ null, packageName, mAppLabel, mAppIcon);
+ final BatteryEntry.NameAndIcon nameAndIcon =
+ BatteryEntry.loadNameAndIcon(
+ mContext, uid, /* batteryEntry= */ null, packageName, mAppLabel, mAppIcon);
// Clears BatteryEntry internal cache since we will have another one.
BatteryEntry.clearUidCache();
if (nameAndIcon != null) {
@@ -489,25 +497,48 @@ 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",
- mPercentage, mConsumePower, mTotalConsumePower))
- .append(String.format("\n\tconsume power= foreground:%f foregroundService:%f",
- mForegroundUsageConsumePower, mForegroundServiceUsageConsumePower))
- .append(String.format("\n\tconsume power= background:%f cached:%f",
- mBackgroundUsageConsumePower, mCachedUsageConsumePower))
- .append(String.format("\n\ttime= foreground:%s background:%s screen-on:%s",
- StringUtil.formatElapsedTime(mContext, (double) mForegroundUsageTimeInMs,
- /*withSeconds=*/ true, /*collapseTimeUnit=*/ false),
- StringUtil.formatElapsedTime(mContext, (double) mBackgroundUsageTimeInMs,
- /*withSeconds=*/ true, /*collapseTimeUnit=*/ false),
- StringUtil.formatElapsedTime(mContext, (double) mScreenOnTimeInMs,
- /*withSeconds=*/ true, /*collapseTimeUnit=*/ false)))
- .append(String.format("\n\tpackage:%s|%s uid:%d userId:%d",
- mLegacyPackageName, getPackageName(), mUid, mUserId));
+ 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",
+ mPercentage, mConsumePower, mTotalConsumePower))
+ .append(
+ String.format(
+ "\n\tconsume power= foreground:%f foregroundService:%f",
+ mForegroundUsageConsumePower,
+ mForegroundServiceUsageConsumePower))
+ .append(
+ String.format(
+ "\n\tconsume power= background:%f cached:%f",
+ mBackgroundUsageConsumePower, mCachedUsageConsumePower))
+ .append(
+ String.format(
+ "\n\ttime= foreground:%s background:%s screen-on:%s",
+ StringUtil.formatElapsedTime(
+ mContext,
+ (double) mForegroundUsageTimeInMs,
+ /* withSeconds= */ true,
+ /* collapseTimeUnit= */ false),
+ StringUtil.formatElapsedTime(
+ mContext,
+ (double) mBackgroundUsageTimeInMs,
+ /* withSeconds= */ true,
+ /* collapseTimeUnit= */ false),
+ StringUtil.formatElapsedTime(
+ mContext,
+ (double) mScreenOnTimeInMs,
+ /* withSeconds= */ true,
+ /* collapseTimeUnit= */ false)))
+ .append(
+ String.format(
+ "\n\tpackage:%s|%s uid:%d userId:%d",
+ mLegacyPackageName, getPackageName(), mUid, mUserId));
return builder.toString();
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
index 5d873028920..751e7ad0665 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryEntry.java
@@ -45,8 +45,7 @@ import java.util.Comparator;
import java.util.Locale;
/**
- * Wraps the power usage data of a BatterySipper with information about package name
- * and icon image.
+ * Wraps the power usage data of a BatterySipper with information about package name and icon image.
*/
public class BatteryEntry {
@@ -58,11 +57,10 @@ public class BatteryEntry {
public final int mIconId;
public NameAndIcon(String name, Drawable icon, int iconId) {
- this(name, /*packageName=*/ null, icon, iconId);
+ this(name, /* packageName= */ null, icon, iconId);
}
- public NameAndIcon(
- String name, String packageName, Drawable icon, int iconId) {
+ public NameAndIcon(String name, String packageName, Drawable icon, int iconId) {
this.mName = name;
this.mIcon = icon;
this.mIconId = iconId;
@@ -78,17 +76,20 @@ public class BatteryEntry {
static final int BATTERY_USAGE_INDEX_BACKGROUND = 2;
static final int BATTERY_USAGE_INDEX_CACHED = 3;
- static final Dimensions[] BATTERY_DIMENSIONS = new Dimensions[] {
- new Dimensions(
- BatteryConsumer.POWER_COMPONENT_ANY, BatteryConsumer.PROCESS_STATE_FOREGROUND),
- new Dimensions(
- BatteryConsumer.POWER_COMPONENT_ANY,
- BatteryConsumer.PROCESS_STATE_FOREGROUND_SERVICE),
- new Dimensions(
- BatteryConsumer.POWER_COMPONENT_ANY, BatteryConsumer.PROCESS_STATE_BACKGROUND),
- new Dimensions(
- BatteryConsumer.POWER_COMPONENT_ANY, BatteryConsumer.PROCESS_STATE_CACHED),
- };
+ static final Dimensions[] BATTERY_DIMENSIONS =
+ new Dimensions[] {
+ new Dimensions(
+ BatteryConsumer.POWER_COMPONENT_ANY,
+ BatteryConsumer.PROCESS_STATE_FOREGROUND),
+ new Dimensions(
+ BatteryConsumer.POWER_COMPONENT_ANY,
+ BatteryConsumer.PROCESS_STATE_FOREGROUND_SERVICE),
+ new Dimensions(
+ BatteryConsumer.POWER_COMPONENT_ANY,
+ BatteryConsumer.PROCESS_STATE_BACKGROUND),
+ new Dimensions(
+ BatteryConsumer.POWER_COMPONENT_ANY, BatteryConsumer.PROCESS_STATE_CACHED),
+ };
static final ArrayMap sUidCache = new ArrayMap<>();
@@ -106,10 +107,8 @@ public class BatteryEntry {
private final BatteryConsumer mBatteryConsumer;
private final int mUid;
private final boolean mIsHidden;
- @ConvertUtils.ConsumerType
- private final int mConsumerType;
- @BatteryConsumer.PowerComponent
- private final int mPowerComponentId;
+ @ConvertUtils.ConsumerType private final int mConsumerType;
+ @BatteryConsumer.PowerComponent private final int mPowerComponentId;
private long mUsageDurationMs;
private long mTimeInForegroundMs;
private long mTimeInBackgroundMs;
@@ -131,13 +130,25 @@ public class BatteryEntry {
Drawable mIcon;
}
- public BatteryEntry(Context context, UserManager um, BatteryConsumer batteryConsumer,
- boolean isHidden, int uid, String[] packages, String packageName) {
+ public BatteryEntry(
+ Context context,
+ UserManager um,
+ BatteryConsumer batteryConsumer,
+ boolean isHidden,
+ int uid,
+ String[] packages,
+ String packageName) {
this(context, um, batteryConsumer, isHidden, uid, packages, packageName, true);
}
- public BatteryEntry(Context context, UserManager um, BatteryConsumer batteryConsumer,
- boolean isHidden, int uid, String[] packages, String packageName,
+ public BatteryEntry(
+ Context context,
+ UserManager um,
+ BatteryConsumer batteryConsumer,
+ boolean isHidden,
+ int uid,
+ String[] packages,
+ String packageName,
boolean loadDataInBackground) {
mContext = context;
mBatteryConsumer = batteryConsumer;
@@ -156,8 +167,10 @@ public class BatteryEntry {
if (packages != null && packages.length == 1) {
mDefaultPackageName = packages[0];
} else {
- mDefaultPackageName = isSystemUid(uid)
- ? PACKAGE_SYSTEM : uidBatteryConsumer.getPackageWithHighestDrain();
+ mDefaultPackageName =
+ isSystemUid(uid)
+ ? PACKAGE_SYSTEM
+ : uidBatteryConsumer.getPackageWithHighestDrain();
}
}
if (mDefaultPackageName != null) {
@@ -167,8 +180,10 @@ public class BatteryEntry {
pm.getApplicationInfo(mDefaultPackageName, 0 /* no flags */);
mName = pm.getApplicationLabel(appInfo).toString();
} catch (NameNotFoundException e) {
- Log.d(TAG, "PackageManager failed to retrieve ApplicationInfo for: "
- + mDefaultPackageName);
+ Log.d(
+ TAG,
+ "PackageManager failed to retrieve ApplicationInfo for: "
+ + mDefaultPackageName);
mName = mDefaultPackageName;
}
}
@@ -176,20 +191,26 @@ public class BatteryEntry {
uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND);
mTimeInBackgroundMs =
uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND);
- mConsumedPowerInForeground = safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND]);
- mConsumedPowerInForegroundService = safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND_SERVICE]);
- mConsumedPowerInBackground = safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_BACKGROUND]);
- mConsumedPowerInCached = safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_CACHED]);
+ mConsumedPowerInForeground =
+ safeGetConsumedPower(
+ uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND]);
+ mConsumedPowerInForegroundService =
+ safeGetConsumedPower(
+ uidBatteryConsumer,
+ BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND_SERVICE]);
+ mConsumedPowerInBackground =
+ safeGetConsumedPower(
+ uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_BACKGROUND]);
+ mConsumedPowerInCached =
+ safeGetConsumedPower(
+ uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_CACHED]);
} else if (batteryConsumer instanceof UserBatteryConsumer) {
mUid = Process.INVALID_UID;
mConsumerType = ConvertUtils.CONSUMER_TYPE_USER_BATTERY;
mConsumedPower = batteryConsumer.getConsumedPower();
- final NameAndIcon nameAndIcon = getNameAndIconFromUserId(
- context, ((UserBatteryConsumer) batteryConsumer).getUserId());
+ final NameAndIcon nameAndIcon =
+ getNameAndIconFromUserId(
+ context, ((UserBatteryConsumer) batteryConsumer).getUserId());
mIcon = nameAndIcon.mIcon;
mName = nameAndIcon.mName;
} else {
@@ -198,8 +219,12 @@ public class BatteryEntry {
}
/** Battery entry for a power component of AggregateBatteryConsumer */
- public BatteryEntry(Context context, int powerComponentId, double devicePowerMah,
- long usageDurationMs, boolean isHidden) {
+ public BatteryEntry(
+ Context context,
+ int powerComponentId,
+ double devicePowerMah,
+ long usageDurationMs,
+ boolean isHidden) {
mContext = context;
mBatteryConsumer = null;
mUid = Process.INVALID_UID;
@@ -209,8 +234,7 @@ public class BatteryEntry {
mUsageDurationMs = usageDurationMs;
mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
- final NameAndIcon nameAndIcon =
- getNameAndIconFromPowerComponent(context, powerComponentId);
+ final NameAndIcon nameAndIcon = getNameAndIconFromPowerComponent(context, powerComponentId);
mIconId = nameAndIcon.mIconId;
mName = nameAndIcon.mName;
if (mIconId != 0) {
@@ -219,7 +243,10 @@ public class BatteryEntry {
}
/** Battery entry for a custom power component of AggregateBatteryConsumer */
- public BatteryEntry(Context context, int powerComponentId, String powerComponentName,
+ public BatteryEntry(
+ Context context,
+ int powerComponentId,
+ String powerComponentName,
double devicePowerMah) {
mContext = context;
mBatteryConsumer = null;
@@ -266,8 +293,8 @@ public class BatteryEntry {
}
final PackageManager pm = context.getPackageManager();
- final String[] packages = isSystemUid(uid)
- ? new String[]{PACKAGE_SYSTEM} : pm.getPackagesForUid(uid);
+ final String[] packages =
+ isSystemUid(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);
@@ -277,11 +304,15 @@ public class BatteryEntry {
final int userId = UserHandle.getUserId(uid);
for (int i = 0; i < packageLabels.length; i++) {
try {
- final ApplicationInfo ai = ipm.getApplicationInfo(packageLabels[i],
- 0 /* no flags */, userId);
+ final ApplicationInfo ai =
+ ipm.getApplicationInfo(packageLabels[i], 0 /* no flags */, userId);
if (ai == null) {
- Log.d(TAG, "Retrieving null app info for package "
- + packageLabels[i] + ", user " + userId);
+ Log.d(
+ TAG,
+ "Retrieving null app info for package "
+ + packageLabels[i]
+ + ", user "
+ + userId);
continue;
}
final CharSequence label = ai.loadLabel(pm);
@@ -294,8 +325,13 @@ public class BatteryEntry {
break;
}
} catch (RemoteException e) {
- Log.d(TAG, "Error while retrieving app info for package "
- + packageLabels[i] + ", user " + userId, e);
+ Log.d(
+ TAG,
+ "Error while retrieving app info for package "
+ + packageLabels[i]
+ + ", user "
+ + userId,
+ e);
}
}
@@ -307,13 +343,17 @@ public class BatteryEntry {
try {
final PackageInfo pi = ipm.getPackageInfo(pkgName, 0, userId);
if (pi == null) {
- Log.d(TAG, "Retrieving null package info for package "
- + pkgName + ", user " + userId);
+ Log.d(
+ TAG,
+ "Retrieving null package info for package "
+ + pkgName
+ + ", user "
+ + userId);
continue;
}
if (pi.sharedUserLabel != 0) {
- final CharSequence nm = pm.getText(pkgName,
- pi.sharedUserLabel, pi.applicationInfo);
+ final CharSequence nm =
+ pm.getText(pkgName, pi.sharedUserLabel, pi.applicationInfo);
if (nm != null) {
name = nm.toString();
if (pi.applicationInfo.icon != 0) {
@@ -324,8 +364,13 @@ public class BatteryEntry {
}
}
} catch (RemoteException e) {
- Log.d(TAG, "Error while retrieving package info for package "
- + pkgName + ", user " + userId, e);
+ Log.d(
+ TAG,
+ "Error while retrieving package info for package "
+ + pkgName
+ + ", user "
+ + userId,
+ e);
}
}
}
@@ -342,7 +387,7 @@ public class BatteryEntry {
utd.mPackageName = defaultPackageName;
sUidCache.put(uidString, utd);
- return new NameAndIcon(name, defaultPackageName, icon, /*iconId=*/ 0);
+ return new NameAndIcon(name, defaultPackageName, icon, /* iconId= */ 0);
}
/** Returns a string that uniquely identifies this battery consumer. */
@@ -375,16 +420,13 @@ public class BatteryEntry {
}
/**
- * Returns the package name that should be used to represent the UID described
- * by this entry.
+ * Returns the package name that should be used to represent the UID described by this entry.
*/
public String getDefaultPackageName() {
return mDefaultPackageName;
}
- /**
- * Returns the UID of the app described by this entry.
- */
+ /** Returns the UID of the app described by this entry. */
public int getUid() {
return mUid;
}
@@ -407,9 +449,7 @@ public class BatteryEntry {
}
}
- /**
- * Returns total amount of power (in milli-amp-hours) that is attributed to this entry.
- */
+ /** Returns total amount of power (in milli-amp-hours) that is attributed to this entry. */
public double getConsumedPower() {
return mConsumedPower;
}
@@ -462,25 +502,30 @@ public class BatteryEntry {
}
/**
- * Adds the consumed power of the supplied BatteryConsumer to this entry. Also
- * uses its package with highest drain, if necessary.
+ * Adds the consumed power of the supplied BatteryConsumer to this entry. Also uses its package
+ * with highest drain, if necessary.
*/
public void add(BatteryConsumer batteryConsumer) {
mConsumedPower += batteryConsumer.getConsumedPower();
if (batteryConsumer instanceof UidBatteryConsumer) {
UidBatteryConsumer uidBatteryConsumer = (UidBatteryConsumer) batteryConsumer;
- mTimeInForegroundMs += uidBatteryConsumer.getTimeInStateMs(
- UidBatteryConsumer.STATE_FOREGROUND);
- mTimeInBackgroundMs += uidBatteryConsumer.getTimeInStateMs(
- UidBatteryConsumer.STATE_BACKGROUND);
- mConsumedPowerInForeground += safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND]);
- mConsumedPowerInForegroundService += safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND_SERVICE]);
- mConsumedPowerInBackground += safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_BACKGROUND]);
- mConsumedPowerInCached += safeGetConsumedPower(
- uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_CACHED]);
+ mTimeInForegroundMs +=
+ uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND);
+ mTimeInBackgroundMs +=
+ uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND);
+ mConsumedPowerInForeground +=
+ safeGetConsumedPower(
+ uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND]);
+ mConsumedPowerInForegroundService +=
+ safeGetConsumedPower(
+ uidBatteryConsumer,
+ BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND_SERVICE]);
+ mConsumedPowerInBackground +=
+ safeGetConsumedPower(
+ uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_BACKGROUND]);
+ mConsumedPowerInCached +=
+ safeGetConsumedPower(
+ uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_CACHED]);
if (mDefaultPackageName == null) {
mDefaultPackageName = uidBatteryConsumer.getPackageWithHighestDrain();
}
@@ -488,8 +533,7 @@ public class BatteryEntry {
}
/** Gets name and icon resource from UserBatteryConsumer userId. */
- public static NameAndIcon getNameAndIconFromUserId(
- Context context, final int userId) {
+ public static NameAndIcon getNameAndIconFromUserId(Context context, final int userId) {
UserManager um = context.getSystemService(UserManager.class);
UserInfo info = um.getUserInfo(userId);
@@ -499,27 +543,27 @@ public class BatteryEntry {
icon = Utils.getUserIcon(context, um, info);
name = Utils.getUserLabel(context, info);
} else {
- name = context.getResources().getString(
- R.string.running_process_item_removed_user_label);
+ name =
+ context.getResources()
+ .getString(R.string.running_process_item_removed_user_label);
}
return new NameAndIcon(name, icon, 0 /* iconId */);
}
/** Gets name and icon resource from UidBatteryConsumer uid. */
- public static NameAndIcon getNameAndIconFromUid(
- Context context, String name, final int uid) {
+ public static NameAndIcon getNameAndIconFromUid(Context context, String name, final int uid) {
Drawable icon = context.getDrawable(R.drawable.ic_power_system);
if (uid == 0) {
- name = context.getResources()
- .getString(com.android.settingslib.R.string.process_kernel_label);
+ name =
+ context.getResources()
+ .getString(com.android.settingslib.R.string.process_kernel_label);
} else if (uid == BatteryUtils.UID_REMOVED_APPS) {
name = context.getResources().getString(R.string.process_removed_apps);
} else if (uid == BatteryUtils.UID_TETHERING) {
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 */);
@@ -531,12 +575,12 @@ public class BatteryEntry {
String name;
int iconId;
switch (powerComponentId) {
- // Please see go/battery-usage-system-component-map
- case BatteryConsumer.POWER_COMPONENT_SCREEN: // id: 0
+ // Please see go/battery-usage-system-component-map
+ case BatteryConsumer.POWER_COMPONENT_SCREEN: // id: 0
name = context.getResources().getString(R.string.power_screen);
iconId = R.drawable.ic_settings_display;
break;
- case BatteryConsumer.POWER_COMPONENT_CPU: // id: 1
+ case BatteryConsumer.POWER_COMPONENT_CPU: // id: 1
name = context.getResources().getString(R.string.power_cpu);
iconId = R.drawable.ic_settings_cpu;
break;
@@ -544,11 +588,11 @@ public class BatteryEntry {
name = context.getResources().getString(R.string.power_bluetooth);
iconId = R.drawable.ic_settings_bluetooth;
break;
- case BatteryConsumer.POWER_COMPONENT_CAMERA: // id: 3
+ case BatteryConsumer.POWER_COMPONENT_CAMERA: // id: 3
name = context.getResources().getString(R.string.power_camera);
iconId = R.drawable.ic_settings_camera;
break;
- case BatteryConsumer.POWER_COMPONENT_FLASHLIGHT: // id: 6
+ case BatteryConsumer.POWER_COMPONENT_FLASHLIGHT: // id: 6
name = context.getResources().getString(R.string.power_flashlight);
iconId = R.drawable.ic_settings_flashlight;
break;
@@ -556,25 +600,30 @@ public class BatteryEntry {
name = context.getResources().getString(R.string.power_cell);
iconId = R.drawable.ic_settings_cellular;
break;
- case BatteryConsumer.POWER_COMPONENT_GNSS: // id: 10
+ case BatteryConsumer.POWER_COMPONENT_GNSS: // id: 10
name = context.getResources().getString(R.string.power_gps);
iconId = R.drawable.ic_settings_gps;
break;
- case BatteryConsumer.POWER_COMPONENT_WIFI: // id: 11
+ case BatteryConsumer.POWER_COMPONENT_WIFI: // id: 11
name = context.getResources().getString(R.string.power_wifi);
iconId = R.drawable.ic_settings_wireless_no_theme;
break;
- case BatteryConsumer.POWER_COMPONENT_PHONE: // id: 14
+ case BatteryConsumer.POWER_COMPONENT_PHONE: // id: 14
name = context.getResources().getString(R.string.power_phone);
iconId = R.drawable.ic_settings_voice_calls;
break;
- case BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY: // id :15
+ case BatteryConsumer.POWER_COMPONENT_AMBIENT_DISPLAY: // id :15
name = context.getResources().getString(R.string.ambient_display_screen_title);
iconId = R.drawable.ic_settings_aod;
break;
default:
- Log.w(TAG, "unknown attribute:" + DebugUtils.constantToString(
- BatteryConsumer.class, "POWER_COMPONENT_", powerComponentId));
+ Log.w(
+ TAG,
+ "unknown attribute:"
+ + DebugUtils.constantToString(
+ BatteryConsumer.class,
+ "POWER_COMPONENT_",
+ powerComponentId));
name = null;
iconId = R.drawable.ic_power_system;
break;
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
index 6f785668d02..97cdc34030d 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistEntry.java
@@ -29,6 +29,7 @@ public class BatteryHistEntry {
/** Keys for accessing {@link ContentValues} or {@link Cursor}. */
public static final String KEY_UID = "uid";
+
public static final String KEY_USER_ID = "userId";
public static final String KEY_PACKAGE_NAME = "packageName";
public static final String KEY_TIMESTAMP = "timestamp";
@@ -57,10 +58,8 @@ public class BatteryHistEntry {
public final double mPercentOfTotal;
public final long mForegroundUsageTimeInMs;
public final long mBackgroundUsageTimeInMs;
- @BatteryConsumer.PowerComponent
- public final int mDrainType;
- @ConvertUtils.ConsumerType
- public final int mConsumerType;
+ @BatteryConsumer.PowerComponent public final int mDrainType;
+ @ConvertUtils.ConsumerType public final int mConsumerType;
// Records the battery intent relative information.
public final int mBatteryLevel;
public final int mBatteryStatus;
@@ -190,25 +189,45 @@ public class BatteryHistEntry {
@Override
public String toString() {
final String recordAtDateTime = ConvertUtils.utcToLocalTimeForLogging(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",
- mPercentOfTotal, mTotalPower, mConsumePower))
- .append(String.format("\n\tforeground=%f|foregroundService=%f",
- mForegroundUsageConsumePower, mForegroundServiceUsageConsumePower))
- .append(String.format("\n\tbackground=%f|cached=%f",
- mBackgroundUsageConsumePower, mCachedUsageConsumePower))
- .append(String.format("\n\telapsedTime=%d|%d",
- 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));
+ 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",
+ mPercentOfTotal, mTotalPower, mConsumePower))
+ .append(
+ String.format(
+ "\n\tforeground=%f|foregroundService=%f",
+ mForegroundUsageConsumePower,
+ mForegroundServiceUsageConsumePower))
+ .append(
+ String.format(
+ "\n\tbackground=%f|cached=%f",
+ mBackgroundUsageConsumePower, mCachedUsageConsumePower))
+ .append(
+ String.format(
+ "\n\telapsedTime=%d|%d",
+ 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();
}
@@ -270,65 +289,81 @@ public class BatteryHistEntry {
double ratio,
BatteryHistEntry lowerHistEntry,
BatteryHistEntry upperHistEntry) {
- final double totalPower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mTotalPower,
- upperHistEntry.mTotalPower,
- ratio);
- final double consumePower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mConsumePower,
- upperHistEntry.mConsumePower,
- ratio);
- final double foregroundUsageConsumePower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundUsageConsumePower,
- upperHistEntry.mForegroundUsageConsumePower,
- ratio);
- final double foregroundServiceUsageConsumePower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundServiceUsageConsumePower,
- upperHistEntry.mForegroundServiceUsageConsumePower,
- ratio);
- final double backgroundUsageConsumePower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageConsumePower,
- upperHistEntry.mBackgroundUsageConsumePower,
- ratio);
- final double cachedUsageConsumePower = interpolate(
- lowerHistEntry == null ? 0 : lowerHistEntry.mCachedUsageConsumePower,
- upperHistEntry.mCachedUsageConsumePower,
- ratio);
- final double foregroundUsageTimeInMs = interpolate(
- (double) (lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundUsageTimeInMs),
- (double) upperHistEntry.mForegroundUsageTimeInMs,
- ratio);
- final double backgroundUsageTimeInMs = interpolate(
- (double) (lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageTimeInMs),
- (double) upperHistEntry.mBackgroundUsageTimeInMs,
- ratio);
+ final double totalPower =
+ interpolate(
+ lowerHistEntry == null ? 0 : lowerHistEntry.mTotalPower,
+ upperHistEntry.mTotalPower,
+ ratio);
+ final double consumePower =
+ interpolate(
+ lowerHistEntry == null ? 0 : lowerHistEntry.mConsumePower,
+ upperHistEntry.mConsumePower,
+ ratio);
+ final double foregroundUsageConsumePower =
+ interpolate(
+ lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundUsageConsumePower,
+ upperHistEntry.mForegroundUsageConsumePower,
+ ratio);
+ final double foregroundServiceUsageConsumePower =
+ interpolate(
+ lowerHistEntry == null
+ ? 0
+ : lowerHistEntry.mForegroundServiceUsageConsumePower,
+ upperHistEntry.mForegroundServiceUsageConsumePower,
+ ratio);
+ final double backgroundUsageConsumePower =
+ interpolate(
+ lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageConsumePower,
+ upperHistEntry.mBackgroundUsageConsumePower,
+ ratio);
+ final double cachedUsageConsumePower =
+ interpolate(
+ lowerHistEntry == null ? 0 : lowerHistEntry.mCachedUsageConsumePower,
+ upperHistEntry.mCachedUsageConsumePower,
+ ratio);
+ final double foregroundUsageTimeInMs =
+ interpolate(
+ (double)
+ (lowerHistEntry == null
+ ? 0
+ : lowerHistEntry.mForegroundUsageTimeInMs),
+ (double) upperHistEntry.mForegroundUsageTimeInMs,
+ ratio);
+ final double backgroundUsageTimeInMs =
+ interpolate(
+ (double)
+ (lowerHistEntry == null
+ ? 0
+ : lowerHistEntry.mBackgroundUsageTimeInMs),
+ (double) upperHistEntry.mBackgroundUsageTimeInMs,
+ ratio);
// Checks whether there is any abnormal cases!
if (upperHistEntry.mConsumePower < consumePower
|| upperHistEntry.mForegroundUsageConsumePower < foregroundUsageConsumePower
|| upperHistEntry.mForegroundServiceUsageConsumePower
- < foregroundServiceUsageConsumePower
+ < foregroundServiceUsageConsumePower
|| upperHistEntry.mBackgroundUsageConsumePower < backgroundUsageConsumePower
|| upperHistEntry.mCachedUsageConsumePower < cachedUsageConsumePower
|| upperHistEntry.mForegroundUsageTimeInMs < foregroundUsageTimeInMs
|| upperHistEntry.mBackgroundUsageTimeInMs < backgroundUsageTimeInMs) {
if (DEBUG) {
- Log.w(TAG, String.format(
- "abnormal interpolation:\nupper:%s\nlower:%s",
- upperHistEntry, lowerHistEntry));
+ Log.w(
+ TAG,
+ String.format(
+ "abnormal interpolation:\nupper:%s\nlower:%s",
+ upperHistEntry, lowerHistEntry));
}
}
final double batteryLevel =
lowerHistEntry == null
? upperHistEntry.mBatteryLevel
: interpolate(
- lowerHistEntry.mBatteryLevel,
- upperHistEntry.mBatteryLevel,
- ratio);
+ lowerHistEntry.mBatteryLevel, upperHistEntry.mBatteryLevel, ratio);
return new BatteryHistEntry(
upperHistEntry,
- /*bootTimestamp=*/ upperHistEntry.mBootTimestamp
- - (upperTimestamp - slotTimestamp),
- /*timestamp=*/ slotTimestamp,
+ /* bootTimestamp= */ upperHistEntry.mBootTimestamp
+ - (upperTimestamp - slotTimestamp),
+ /* timestamp= */ slotTimestamp,
totalPower,
consumePower,
foregroundUsageConsumePower,
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java
index d64bf34fc1e..2063f2dbee2 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryHistoryPreference.java
@@ -26,9 +26,7 @@ import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
-/**
- * Custom preference for displaying the battery level as chart graph.
- */
+/** Custom preference for displaying the battery level as chart graph. */
public class BatteryHistoryPreference extends Preference {
private static final String TAG = "BatteryHistoryPreference";
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java
index 09d66c704dc..231c730a176 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryLevelData.java
@@ -47,13 +47,14 @@ public final class BatteryLevelData {
private final List mLevels;
public PeriodBatteryLevelData(
- @NonNull Map batteryLevelMap,
- @NonNull List timestamps) {
+ @NonNull Map batteryLevelMap, @NonNull List timestamps) {
mTimestamps = timestamps;
mLevels = new ArrayList<>(timestamps.size());
for (Long timestamp : timestamps) {
- mLevels.add(batteryLevelMap.containsKey(timestamp)
- ? batteryLevelMap.get(timestamp) : BATTERY_LEVEL_UNKNOWN);
+ mLevels.add(
+ batteryLevelMap.containsKey(timestamp)
+ ? batteryLevelMap.get(timestamp)
+ : BATTERY_LEVEL_UNKNOWN);
}
}
@@ -67,8 +68,11 @@ public final class BatteryLevelData {
@Override
public String toString() {
- return String.format(Locale.ENGLISH, "timestamps: %s; levels: %s",
- Objects.toString(mTimestamps), Objects.toString(mLevels));
+ return String.format(
+ Locale.ENGLISH,
+ "timestamps: %s; levels: %s",
+ Objects.toString(mTimestamps),
+ Objects.toString(mLevels));
}
private int getIndexByTimestamps(long startTimestamp, long endTimestamp) {
@@ -83,14 +87,15 @@ public final class BatteryLevelData {
}
/**
- * There could be 2 cases for the daily battery levels:
+ * There could be 2 cases for the daily battery levels:
* 1) length is 2: The usage data is within 1 day. Only contains start and end data, such as
- * data of 2022-01-01 06:00 and 2022-01-01 16:00.
+ * data of 2022-01-01 06:00 and 2022-01-01 16:00.
* 2) length > 2: The usage data is more than 1 days. The data should be the start, end and 0am
- * data of every day between the start and end, such as data of 2022-01-01 06:00,
- * 2022-01-02 00:00, 2022-01-03 00:00 and 2022-01-03 08:00.
+ * data of every day between the start and end, such as data of 2022-01-01 06:00, 2022-01-02
+ * 00:00, 2022-01-03 00:00 and 2022-01-03 08:00.
*/
private final PeriodBatteryLevelData mDailyBatteryLevels;
+
// The size of hourly data must be the size of daily data - 1.
private final List mHourlyBatteryLevelsPerDay;
@@ -118,8 +123,9 @@ public final class BatteryLevelData {
final int hourlyHighlightIndex =
(dailyHighlightIndex == BatteryChartViewModel.SELECTED_INDEX_INVALID)
? BatteryChartViewModel.SELECTED_INDEX_INVALID
- : mHourlyBatteryLevelsPerDay.get(dailyHighlightIndex)
- .getIndexByTimestamps(startTimestamp, endTimestamp);
+ : mHourlyBatteryLevelsPerDay
+ .get(dailyHighlightIndex)
+ .getIndexByTimestamps(startTimestamp, endTimestamp);
return Pair.create(dailyHighlightIndex, hourlyHighlightIndex);
}
@@ -133,14 +139,16 @@ public final class BatteryLevelData {
@Override
public String toString() {
- return String.format(Locale.ENGLISH,
+ return String.format(
+ Locale.ENGLISH,
"dailyBatteryLevels: %s; hourlyBatteryLevelsPerDay: %s",
Objects.toString(mDailyBatteryLevels),
Objects.toString(mHourlyBatteryLevelsPerDay));
}
@Nullable
- static BatteryLevelData combine(@Nullable BatteryLevelData existingBatteryLevelData,
+ static BatteryLevelData combine(
+ @Nullable BatteryLevelData existingBatteryLevelData,
List batteryLevelRecordEvents) {
final Map batteryLevelMap = new ArrayMap<>(batteryLevelRecordEvents.size());
for (BatteryEvent event : batteryLevelRecordEvents) {
@@ -152,7 +160,8 @@ public final class BatteryLevelData {
for (int dayIndex = 0; dayIndex < multiDaysData.size(); dayIndex++) {
PeriodBatteryLevelData oneDayData = multiDaysData.get(dayIndex);
for (int hourIndex = 0; hourIndex < oneDayData.getLevels().size(); hourIndex++) {
- batteryLevelMap.put(oneDayData.getTimestamps().get(hourIndex),
+ batteryLevelMap.put(
+ oneDayData.getTimestamps().get(hourIndex),
oneDayData.getLevels().get(hourIndex));
}
}
@@ -163,11 +172,10 @@ public final class BatteryLevelData {
/**
* Computes expected daily timestamp slots.
*
- * The valid result should be composed of 3 parts:
- * 1) start timestamp
- * 2) every 00:00 timestamp (default timezone) between the start and end
- * 3) end timestamp
- * Otherwise, returns an empty list.
+ * The valid result should be composed of 3 parts:
+ * 1) start timestamp
+ * 2) every 00:00 timestamp (default timezone) between the start and end
+ * 3) end timestamp Otherwise, returns an empty list.
*/
@VisibleForTesting
static List getDailyTimestamps(final List timestampList) {
@@ -176,7 +184,8 @@ public final class BatteryLevelData {
final List dailyTimestampList = new ArrayList<>();
final long startTimestamp = timestampList.get(0);
final long endTimestamp = timestampList.get(timestampList.size() - 1);
- for (long timestamp = startTimestamp; timestamp < endTimestamp;
+ for (long timestamp = startTimestamp;
+ timestamp < endTimestamp;
timestamp = TimestampUtils.getNextDayTimestamp(timestamp)) {
dailyTimestampList.add(timestamp);
}
@@ -193,7 +202,8 @@ public final class BatteryLevelData {
hourlyTimestampsPerDay.add(startTime);
for (long timestamp = TimestampUtils.getNextEvenHourTimestamp(startTime);
- timestamp < endTime; timestamp += TIME_SLOT) {
+ timestamp < endTime;
+ timestamp += TIME_SLOT) {
hourlyTimestampsPerDay.add(timestamp);
}
hourlyTimestampsPerDay.add(endTime);
@@ -203,4 +213,3 @@ public final class BatteryLevelData {
return hourlyTimestamps;
}
}
-
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java
index 2c799fada57..7eec8167bd4 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsCardPreference.java
@@ -34,9 +34,7 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.google.android.material.button.MaterialButton;
-/**
- * A preference for displaying the battery tips card view.
- */
+/** A preference for displaying the battery tips card view. */
public class BatteryTipsCardPreference extends Preference implements View.OnClickListener {
private static final String TAG = "BatteryTipsCardPreference";
@@ -55,10 +53,8 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
private int mIconResourceId = 0;
private int mMainButtonStrokeColorResourceId = 0;
- @VisibleForTesting
- CharSequence mMainButtonLabel;
- @VisibleForTesting
- CharSequence mDismissButtonLabel;
+ @VisibleForTesting CharSequence mMainButtonLabel;
+ @VisibleForTesting CharSequence mDismissButtonLabel;
public BatteryTipsCardPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -76,9 +72,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
mOnRejectListener = listener;
}
- /**
- * Sets the icon in tips card.
- */
+ /** Sets the icon in tips card. */
public void setIconResourceId(int resourceId) {
if (mIconResourceId != resourceId) {
mIconResourceId = resourceId;
@@ -86,9 +80,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
}
}
- /**
- * Sets the stroke color of main button in tips card.
- */
+ /** Sets the stroke color of main button in tips card. */
public void setMainButtonStrokeColorResourceId(int resourceId) {
if (mMainButtonStrokeColorResourceId != resourceId) {
mMainButtonStrokeColorResourceId = resourceId;
@@ -96,9 +88,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
}
}
- /**
- * Sets the label of main button in tips card.
- */
+ /** Sets the label of main button in tips card. */
public void setMainButtonLabel(CharSequence label) {
if (!TextUtils.equals(mMainButtonLabel, label)) {
mMainButtonLabel = label;
@@ -106,9 +96,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
}
}
- /**
- * Sets the label of dismiss button in tips card.
- */
+ /** Sets the label of dismiss button in tips card. */
public void setDismissButtonLabel(CharSequence label) {
if (!TextUtils.equals(mDismissButtonLabel, label)) {
mDismissButtonLabel = label;
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
index 44b24214d04..5a1fb2614dd 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryTipsController.java
@@ -51,12 +51,9 @@ public class BatteryTipsController extends BasePreferenceController {
private OnAnomalyConfirmListener mOnAnomalyConfirmListener;
private OnAnomalyRejectListener mOnAnomalyRejectListener;
- @VisibleForTesting
- BatteryTipsCardPreference mCardPreference;
- @VisibleForTesting
- AnomalyEventWrapper mAnomalyEventWrapper = null;
- @VisibleForTesting
- Boolean mIsAcceptable = false;
+ @VisibleForTesting BatteryTipsCardPreference mCardPreference;
+ @VisibleForTesting AnomalyEventWrapper mAnomalyEventWrapper = null;
+ @VisibleForTesting Boolean mIsAcceptable = false;
public BatteryTipsController(Context context) {
super(context, ROOT_PREFERENCE_KEY);
@@ -94,7 +91,8 @@ public class BatteryTipsController extends BasePreferenceController {
}
mCardPreference.setVisible(false);
mMetricsFeatureProvider.action(
- mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT,
+ mContext,
+ SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT,
mAnomalyEventWrapper.getEventId());
}
@@ -117,28 +115,31 @@ public class BatteryTipsController extends BasePreferenceController {
}
// Set battery tips card listener
- mCardPreference.setOnConfirmListener(() -> {
- mCardPreference.setVisible(false);
- if (mOnAnomalyConfirmListener != null) {
- mOnAnomalyConfirmListener.onAnomalyConfirm();
- } else if (mAnomalyEventWrapper.launchSubSetting()) {
- mMetricsFeatureProvider.action(
- mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT, eventId);
- }
- });
- mCardPreference.setOnRejectListener(() -> {
- mCardPreference.setVisible(false);
- if (mOnAnomalyRejectListener != null) {
- mOnAnomalyRejectListener.onAnomalyReject();
- }
- // For anomaly events with same record key, dismissed until next time full charged.
- final String dismissRecordKey = mAnomalyEventWrapper.getDismissRecordKey();
- if (!TextUtils.isEmpty(dismissRecordKey)) {
- DatabaseUtils.setDismissedPowerAnomalyKeys(mContext, dismissRecordKey);
- }
- mMetricsFeatureProvider.action(
- mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_DISMISS, eventId);
- });
+ mCardPreference.setOnConfirmListener(
+ () -> {
+ mCardPreference.setVisible(false);
+ if (mOnAnomalyConfirmListener != null) {
+ mOnAnomalyConfirmListener.onAnomalyConfirm();
+ } else if (mAnomalyEventWrapper.launchSubSetting()) {
+ mMetricsFeatureProvider.action(
+ mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT, eventId);
+ }
+ });
+ mCardPreference.setOnRejectListener(
+ () -> {
+ mCardPreference.setVisible(false);
+ if (mOnAnomalyRejectListener != null) {
+ mOnAnomalyRejectListener.onAnomalyReject();
+ }
+ // For anomaly events with same record key, dismissed until next time full
+ // charged.
+ final String dismissRecordKey = mAnomalyEventWrapper.getDismissRecordKey();
+ if (!TextUtils.isEmpty(dismissRecordKey)) {
+ DatabaseUtils.setDismissedPowerAnomalyKeys(mContext, dismissRecordKey);
+ }
+ mMetricsFeatureProvider.action(
+ mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_DISMISS, eventId);
+ });
mCardPreference.setVisible(true);
mMetricsFeatureProvider.action(
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
index 983524f39ca..d6f8709f590 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
@@ -58,7 +58,7 @@ import java.util.Set;
/** Controller for battery usage breakdown preference group. */
public class BatteryUsageBreakdownController extends BasePreferenceController
- implements LifecycleObserver, OnResume, OnDestroy {
+ implements LifecycleObserver, OnResume, OnDestroy {
private static final String TAG = "BatteryUsageBreakdownController";
private static final String ROOT_PREFERENCE_KEY = "battery_usage_breakdown";
private static final String FOOTER_PREFERENCE_KEY = "battery_usage_footer";
@@ -74,45 +74,33 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final Handler mHandler = new Handler(Looper.getMainLooper());
- @VisibleForTesting
- final Map mPreferenceCache = new ArrayMap<>();
+ @VisibleForTesting final Map mPreferenceCache = new ArrayMap<>();
private int mSpinnerPosition;
private String mSlotTimestamp;
- @VisibleForTesting
- Context mPrefContext;
- @VisibleForTesting
- PreferenceCategory mRootPreference;
- @VisibleForTesting
- SpinnerPreference mSpinnerPreference;
- @VisibleForTesting
- PreferenceGroup mAppListPreferenceGroup;
- @VisibleForTesting
- FooterPreference mFooterPreference;
- @VisibleForTesting
- BatteryDiffData mBatteryDiffData;
- @VisibleForTesting
- String mPercentLessThanThresholdText;
- @VisibleForTesting
- boolean mIsHighlightSlot;
- @VisibleForTesting
- String mAnomalyEventId;
- @VisibleForTesting
- String mAnomalyEntryKey;
- @VisibleForTesting
- String mAnomalyHintString;
- @VisibleForTesting
- String mAnomalyHintPrefKey;
+ @VisibleForTesting Context mPrefContext;
+ @VisibleForTesting PreferenceCategory mRootPreference;
+ @VisibleForTesting SpinnerPreference mSpinnerPreference;
+ @VisibleForTesting PreferenceGroup mAppListPreferenceGroup;
+ @VisibleForTesting FooterPreference mFooterPreference;
+ @VisibleForTesting BatteryDiffData mBatteryDiffData;
+ @VisibleForTesting String mPercentLessThanThresholdText;
+ @VisibleForTesting boolean mIsHighlightSlot;
+ @VisibleForTesting String mAnomalyEventId;
+ @VisibleForTesting String mAnomalyEntryKey;
+ @VisibleForTesting String mAnomalyHintString;
+ @VisibleForTesting String mAnomalyHintPrefKey;
public BatteryUsageBreakdownController(
- Context context, Lifecycle lifecycle, SettingsActivity activity,
+ Context context,
+ Lifecycle lifecycle,
+ SettingsActivity activity,
InstrumentedPreferenceFragment fragment) {
super(context, ROOT_PREFERENCE_KEY);
mActivity = activity;
mFragment = fragment;
- mMetricsFeatureProvider =
- FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
+ mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -133,7 +121,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
@Override
public void onDestroy() {
- mHandler.removeCallbacksAndMessages(/*token=*/ null);
+ mHandler.removeCallbacksAndMessages(/* token= */ null);
mPreferenceCache.clear();
mAppListPreferenceGroup.removeAll();
}
@@ -149,14 +137,17 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
}
private boolean isAnomalyBatteryDiffEntry(BatteryDiffEntry entry) {
- return mIsHighlightSlot && mAnomalyEntryKey != null
+ return mIsHighlightSlot
+ && mAnomalyEntryKey != null
&& mAnomalyEntryKey.equals(entry.getKey());
}
private String getActionKey(BatteryDiffEntry entry) {
- final String actionKey = TextUtils.isEmpty(entry.getPackageName())
- ? PACKAGE_NAME_NONE : entry.getPackageName();
- return !isAnomalyBatteryDiffEntry(entry) ? actionKey : actionKey + "|" + mAnomalyEventId;
+ final String actionKey =
+ TextUtils.isEmpty(entry.getPackageName())
+ ? PACKAGE_NAME_NONE
+ : entry.getPackageName();
+ return !isAnomalyBatteryDiffEntry(entry) ? actionKey : actionKey + "|" + mAnomalyEventId;
}
@Override
@@ -174,15 +165,24 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
/* pageId */ SettingsEnums.OPEN_BATTERY_USAGE,
getActionKey(diffEntry),
(int) Math.round(diffEntry.getPercentage()));
- Log.d(TAG, String.format("handleClick() label=%s key=%s package=%s",
- diffEntry.getAppLabel(), diffEntry.getKey(), diffEntry.getPackageName()));
- final String anomalyHintPrefKey = isAnomalyBatteryDiffEntry(diffEntry)
- ? mAnomalyHintPrefKey : null;
- final String anomalyHintText = isAnomalyBatteryDiffEntry(diffEntry)
- ? mAnomalyHintString : null;
- AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment.getMetricsCategory(),
- diffEntry, powerPref.getPercentage(), mSlotTimestamp,
- /*showTimeInformation=*/ true, anomalyHintPrefKey, anomalyHintText);
+ Log.d(
+ TAG,
+ String.format(
+ "handleClick() label=%s key=%s package=%s",
+ diffEntry.getAppLabel(), diffEntry.getKey(), diffEntry.getPackageName()));
+ final String anomalyHintPrefKey =
+ isAnomalyBatteryDiffEntry(diffEntry) ? mAnomalyHintPrefKey : null;
+ final String anomalyHintText =
+ isAnomalyBatteryDiffEntry(diffEntry) ? mAnomalyHintString : null;
+ AdvancedPowerUsageDetail.startBatteryDetailPage(
+ mActivity,
+ mFragment.getMetricsCategory(),
+ diffEntry,
+ powerPref.getPercentage(),
+ mSlotTimestamp,
+ /* showTimeInformation= */ true,
+ anomalyHintPrefKey,
+ anomalyHintText);
return true;
}
@@ -194,15 +194,16 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
mSpinnerPreference = screen.findPreference(SPINNER_PREFERENCE_KEY);
mAppListPreferenceGroup = screen.findPreference(APP_LIST_PREFERENCE_KEY);
mFooterPreference = screen.findPreference(FOOTER_PREFERENCE_KEY);
- mPercentLessThanThresholdText = mPrefContext.getString(
- R.string.battery_usage_less_than_percent,
- Utils.formatPercentage(BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD, false));
+ mPercentLessThanThresholdText =
+ mPrefContext.getString(
+ R.string.battery_usage_less_than_percent,
+ Utils.formatPercentage(BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD, false));
mAppListPreferenceGroup.setOrderingAsAdded(false);
mSpinnerPreference.initializeSpinner(
- new String[]{
- mPrefContext.getString(R.string.battery_usage_spinner_view_by_apps),
- mPrefContext.getString(R.string.battery_usage_spinner_view_by_systems)
+ new String[] {
+ mPrefContext.getString(R.string.battery_usage_spinner_view_by_apps),
+ mPrefContext.getString(R.string.battery_usage_spinner_view_by_systems)
},
new AdapterView.OnItemSelectedListener() {
@Override
@@ -210,35 +211,38 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
AdapterView> parent, View view, int position, long id) {
if (mSpinnerPosition != position) {
mSpinnerPosition = position;
- mHandler.post(() -> {
- removeAndCacheAllUnusedPreferences();
- addAllPreferences();
- mMetricsFeatureProvider.action(
- mPrefContext,
- SettingsEnums.ACTION_BATTERY_USAGE_SPINNER,
- mSpinnerPosition);
- });
+ mHandler.post(
+ () -> {
+ removeAndCacheAllUnusedPreferences();
+ addAllPreferences();
+ mMetricsFeatureProvider.action(
+ mPrefContext,
+ SettingsEnums.ACTION_BATTERY_USAGE_SPINNER,
+ mSpinnerPosition);
+ });
}
}
@Override
- public void onNothingSelected(AdapterView> parent) {
- }
+ public void onNothingSelected(AdapterView> parent) {}
});
}
/**
* Updates UI when the battery usage is updated.
- * @param slotUsageData The battery usage diff data for the selected slot. This is used in
- * the app list.
+ *
+ * @param slotUsageData The battery usage diff data for the selected slot. This is used in the
+ * app list.
* @param slotTimestamp The selected slot timestamp information. This is used in the battery
- * usage breakdown category.
- * @param isAllUsageDataEmpty Whether all the battery usage data is null or empty. This is
- * used when showing the footer.
+ * usage breakdown category.
+ * @param isAllUsageDataEmpty Whether all the battery usage data is null or empty. This is used
+ * when showing the footer.
*/
void handleBatteryUsageUpdated(
- BatteryDiffData slotUsageData, String slotTimestamp,
- boolean isAllUsageDataEmpty, boolean isHighlightSlot,
+ BatteryDiffData slotUsageData,
+ String slotTimestamp,
+ boolean isAllUsageDataEmpty,
+ boolean isHighlightSlot,
Optional optionalAnomalyEventWrapper) {
mBatteryDiffData = slotUsageData;
mSlotTimestamp = slotTimestamp;
@@ -247,14 +251,15 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
if (optionalAnomalyEventWrapper != null) {
final AnomalyEventWrapper anomalyEventWrapper =
optionalAnomalyEventWrapper.orElse(null);
- mAnomalyEventId = anomalyEventWrapper != null
- ? anomalyEventWrapper.getEventId() : null;
- mAnomalyEntryKey = anomalyEventWrapper != null
- ? anomalyEventWrapper.getAnomalyEntryKey() : null;
- mAnomalyHintString = anomalyEventWrapper != null
- ? anomalyEventWrapper.getAnomalyHintString() : null;
- mAnomalyHintPrefKey = anomalyEventWrapper != null
- ? anomalyEventWrapper.getAnomalyHintPrefKey() : null;
+ mAnomalyEventId = anomalyEventWrapper != null ? anomalyEventWrapper.getEventId() : null;
+ mAnomalyEntryKey =
+ anomalyEventWrapper != null ? anomalyEventWrapper.getAnomalyEntryKey() : null;
+ mAnomalyHintString =
+ anomalyEventWrapper != null ? anomalyEventWrapper.getAnomalyHintString() : null;
+ mAnomalyHintPrefKey =
+ anomalyEventWrapper != null
+ ? anomalyEventWrapper.getAnomalyHintPrefKey()
+ : null;
}
showCategoryTitle(slotTimestamp);
@@ -263,35 +268,39 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
}
private void showCategoryTitle(String slotTimestamp) {
- mRootPreference.setTitle(slotTimestamp == null
- ? mPrefContext.getString(
- R.string.battery_usage_breakdown_title_since_last_full_charge)
- : mPrefContext.getString(
- R.string.battery_usage_breakdown_title_for_slot, slotTimestamp));
+ mRootPreference.setTitle(
+ slotTimestamp == null
+ ? mPrefContext.getString(
+ R.string.battery_usage_breakdown_title_since_last_full_charge)
+ : mPrefContext.getString(
+ R.string.battery_usage_breakdown_title_for_slot, slotTimestamp));
mRootPreference.setVisible(true);
}
private void showFooterPreference(boolean isAllBatteryUsageEmpty) {
- mFooterPreference.setTitle(mPrefContext.getString(
- isAllBatteryUsageEmpty
- ? R.string.battery_usage_screen_footer_empty
- : R.string.battery_usage_screen_footer));
+ mFooterPreference.setTitle(
+ mPrefContext.getString(
+ isAllBatteryUsageEmpty
+ ? R.string.battery_usage_screen_footer_empty
+ : R.string.battery_usage_screen_footer));
mFooterPreference.setVisible(true);
}
private void showSpinnerAndAppList() {
if (mBatteryDiffData == null) {
- mHandler.post(() -> {
- removeAndCacheAllUnusedPreferences();
- });
+ mHandler.post(
+ () -> {
+ removeAndCacheAllUnusedPreferences();
+ });
return;
}
mSpinnerPreference.setVisible(true);
mAppListPreferenceGroup.setVisible(true);
- mHandler.post(() -> {
- removeAndCacheAllUnusedPreferences();
- addAllPreferences();
- });
+ mHandler.post(
+ () -> {
+ removeAndCacheAllUnusedPreferences();
+ addAllPreferences();
+ });
}
private List getBatteryDiffEntries() {
@@ -348,8 +357,11 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
}
prefIndex++;
}
- Log.d(TAG, String.format("addAllPreferences() is finished in %d/ms",
- (System.currentTimeMillis() - start)));
+ Log.d(
+ TAG,
+ String.format(
+ "addAllPreferences() is finished in %d/ms",
+ (System.currentTimeMillis() - start)));
}
@VisibleForTesting
@@ -372,8 +384,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
}
@VisibleForTesting
- void setPreferencePercentage(
- PowerGaugePreference preference, BatteryDiffEntry entry) {
+ void setPreferencePercentage(PowerGaugePreference preference, BatteryDiffEntry entry) {
preference.setPercentage(
entry.getPercentage() < BatteryDiffData.SMALL_PERCENTAGE_THRESHOLD
? mPercentLessThanThresholdText
@@ -383,11 +394,13 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
}
@VisibleForTesting
- void setPreferenceSummary(
- PowerGaugePreference preference, BatteryDiffEntry entry) {
+ void setPreferenceSummary(PowerGaugePreference preference, BatteryDiffEntry entry) {
preference.setSummary(
- BatteryUtils.buildBatteryUsageTimeSummary(mPrefContext, entry.isSystemEntry(),
- entry.mForegroundUsageTimeInMs, entry.mBackgroundUsageTimeInMs,
+ BatteryUtils.buildBatteryUsageTimeSummary(
+ mPrefContext,
+ entry.isSystemEntry(),
+ entry.mForegroundUsageTimeInMs,
+ entry.mBackgroundUsageTimeInMs,
entry.mScreenOnTimeInMs));
}
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java
index 006928ab232..9fb70faa636 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBroadcastReceiver.java
@@ -36,23 +36,23 @@ import java.util.concurrent.Executors;
/** A {@link BatteryUsageBroadcastReceiver} for battery usage data requesting. */
public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "BatteryUsageBroadcastReceiver";
+
/** An intent action to request Settings to clear cache data. */
public static final String ACTION_CLEAR_BATTERY_CACHE_DATA =
"com.android.settings.battery.action.CLEAR_BATTERY_CACHE_DATA";
+
/** An intent action for power is plugging. */
public static final String ACTION_BATTERY_PLUGGING =
"com.android.settings.battery.action.ACTION_BATTERY_PLUGGING";
+
/** An intent action for power is unplugging. */
public static final String ACTION_BATTERY_UNPLUGGING =
"com.android.settings.battery.action.ACTION_BATTERY_UNPLUGGING";
- @VisibleForTesting
- static long sBroadcastDelayFromBoot = Duration.ofMinutes(40).toMillis();
- @VisibleForTesting
- static boolean sIsDebugMode = Build.TYPE.equals("userdebug");
+ @VisibleForTesting static long sBroadcastDelayFromBoot = Duration.ofMinutes(40).toMillis();
+ @VisibleForTesting static boolean sIsDebugMode = Build.TYPE.equals("userdebug");
- @VisibleForTesting
- boolean mFetchBatteryUsageData = false;
+ @VisibleForTesting boolean mFetchBatteryUsageData = false;
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
@@ -68,9 +68,10 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
return;
}
DatabaseUtils.recordDateTime(context, action);
- final String fullChargeIntentAction = FeatureFactory.getFeatureFactory()
- .getPowerUsageFeatureProvider()
- .getFullChargeIntentAction();
+ final String fullChargeIntentAction =
+ FeatureFactory.getFeatureFactory()
+ .getPowerUsageFeatureProvider()
+ .getFullChargeIntentAction();
switch (action) {
case Intent.ACTION_BATTERY_LEVEL_CHANGED:
// Only when fullChargeIntentAction is ACTION_BATTERY_LEVEL_CHANGED,
@@ -117,13 +118,16 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
final long broadcastDelay = sBroadcastDelayFromBoot - SystemClock.elapsedRealtime();
// If current boot time is smaller than expected delay, cancel sending the broadcast.
if (delayHourlyJobWhenBooting && broadcastDelay > 0) {
- Log.d(TAG, "cancel sendBroadcastToFetchUsageData when broadcastDelay is "
- + broadcastDelay + "ms.");
+ Log.d(
+ TAG,
+ "cancel sendBroadcastToFetchUsageData when broadcastDelay is "
+ + broadcastDelay
+ + "ms.");
return;
}
mFetchBatteryUsageData = true;
- BatteryUsageDataLoader.enqueueWork(context, /*isFullChargeStart=*/ true);
+ BatteryUsageDataLoader.enqueueWork(context, /* isFullChargeStart= */ true);
BootBroadcastReceiver.invokeJobRecheck(context);
}
@@ -131,7 +135,11 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
final long timestamp = System.currentTimeMillis();
final Intent intent = BatteryUtils.getBatteryIntent(context);
final int batteryLevel = BatteryStatus.getBatteryLevel(intent);
- mExecutor.execute(() -> DatabaseUtils.sendBatteryEventData(context,
- ConvertUtils.convertToBatteryEvent(timestamp, batteryEventType, batteryLevel)));
+ mExecutor.execute(
+ () ->
+ DatabaseUtils.sendBatteryEventData(
+ context,
+ ConvertUtils.convertToBatteryEvent(
+ timestamp, batteryEventType, batteryLevel)));
}
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageContentProvider.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageContentProvider.java
index edba7c445ae..4f2ee79d367 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageContentProvider.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageContentProvider.java
@@ -53,6 +53,7 @@ public class BatteryUsageContentProvider extends ContentProvider {
/** Codes */
private static final int BATTERY_STATE_CODE = 1;
+
private static final int APP_USAGE_LATEST_TIMESTAMP_CODE = 2;
private static final int APP_USAGE_EVENT_CODE = 3;
private static final int BATTERY_EVENT_CODE = 4;
@@ -67,32 +68,32 @@ public class BatteryUsageContentProvider extends ContentProvider {
static {
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.BATTERY_STATE_TABLE,
- /*code=*/ BATTERY_STATE_CODE);
+ /* path= */ DatabaseUtils.BATTERY_STATE_TABLE,
+ /* code= */ BATTERY_STATE_CODE);
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.APP_USAGE_LATEST_TIMESTAMP_PATH,
- /*code=*/ APP_USAGE_LATEST_TIMESTAMP_CODE);
+ /* path= */ DatabaseUtils.APP_USAGE_LATEST_TIMESTAMP_PATH,
+ /* code= */ APP_USAGE_LATEST_TIMESTAMP_CODE);
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.APP_USAGE_EVENT_TABLE,
- /*code=*/ APP_USAGE_EVENT_CODE);
+ /* path= */ DatabaseUtils.APP_USAGE_EVENT_TABLE,
+ /* code= */ APP_USAGE_EVENT_CODE);
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.BATTERY_EVENT_TABLE,
- /*code=*/ BATTERY_EVENT_CODE);
+ /* path= */ DatabaseUtils.BATTERY_EVENT_TABLE,
+ /* code= */ BATTERY_EVENT_CODE);
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.LAST_FULL_CHARGE_TIMESTAMP_PATH,
- /*code=*/ LAST_FULL_CHARGE_TIMESTAMP_CODE);
+ /* path= */ DatabaseUtils.LAST_FULL_CHARGE_TIMESTAMP_PATH,
+ /* code= */ LAST_FULL_CHARGE_TIMESTAMP_CODE);
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.BATTERY_STATE_LATEST_TIMESTAMP_PATH,
- /*code=*/ BATTERY_STATE_LATEST_TIMESTAMP_CODE);
+ /* path= */ DatabaseUtils.BATTERY_STATE_LATEST_TIMESTAMP_PATH,
+ /* code= */ BATTERY_STATE_LATEST_TIMESTAMP_CODE);
sUriMatcher.addURI(
DatabaseUtils.AUTHORITY,
- /*path=*/ DatabaseUtils.BATTERY_USAGE_SLOT_TABLE,
- /*code=*/ BATTERY_USAGE_SLOT_CODE);
+ /* path= */ DatabaseUtils.BATTERY_USAGE_SLOT_TABLE,
+ /* code= */ BATTERY_USAGE_SLOT_CODE);
}
private Clock mClock;
@@ -177,7 +178,7 @@ public class BatteryUsageContentProvider extends ContentProvider {
throw new IllegalArgumentException("unknown URI: " + uri);
}
} catch (RuntimeException e) {
- if (e instanceof IllegalArgumentException) {
+ if (e instanceof IllegalArgumentException) {
throw e;
}
Log.e(TAG, "insert() from:" + uri + " error:", e);
@@ -208,8 +209,10 @@ public class BatteryUsageContentProvider extends ContentProvider {
} catch (RuntimeException e) {
Log.e(TAG, "query() from:" + uri + " error:", e);
}
- Log.d(TAG, String.format("getLastFullChargeTimestamp() in %d/ms",
- mClock.millis() - timestamp));
+ Log.d(
+ TAG,
+ String.format(
+ "getLastFullChargeTimestamp() in %d/ms", mClock.millis() - timestamp));
return cursor;
}
@@ -222,8 +225,11 @@ public class BatteryUsageContentProvider extends ContentProvider {
} catch (RuntimeException e) {
Log.e(TAG, "query() from:" + uri + " error:", e);
}
- Log.d(TAG, String.format("getBatteryStateLatestTimestamp() no later than %d in %d/ms",
- queryTimestamp, mClock.millis() - timestamp));
+ Log.d(
+ TAG,
+ String.format(
+ "getBatteryStateLatestTimestamp() no later than %d in %d/ms",
+ queryTimestamp, mClock.millis() - timestamp));
return cursor;
}
@@ -236,8 +242,11 @@ public class BatteryUsageContentProvider extends ContentProvider {
} catch (RuntimeException e) {
Log.e(TAG, "query() from:" + uri + " error:", e);
}
- Log.d(TAG, String.format("getBatteryStates() after %d in %d/ms",
- queryTimestamp, mClock.millis() - timestamp));
+ Log.d(
+ TAG,
+ String.format(
+ "getBatteryStates() after %d in %d/ms",
+ queryTimestamp, mClock.millis() - timestamp));
return cursor;
}
@@ -270,8 +279,11 @@ public class BatteryUsageContentProvider extends ContentProvider {
} catch (RuntimeException e) {
Log.e(TAG, "query() from:" + uri + " error:", e);
}
- Log.d(TAG, String.format("getAppUsageLatestTimestamp() for user %d in %d/ms",
- queryUserId, (mClock.millis() - timestamp)));
+ Log.d(
+ TAG,
+ String.format(
+ "getAppUsageLatestTimestamp() for user %d in %d/ms",
+ queryUserId, (mClock.millis() - timestamp)));
return cursor;
}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
index 4a336eb4a8a..ead580be5ad 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageDataLoader.java
@@ -39,21 +39,18 @@ public final class BatteryUsageDataLoader {
private static final String TAG = "BatteryUsageDataLoader";
// For testing only.
- @VisibleForTesting
- static Supplier> sFakeBatteryEntryListSupplier;
- @VisibleForTesting
- static Supplier