Refactor Power Usage Time Page.
- Show use time category Screenshot: [Screen time with hint] https://screenshot.googleplex.com/3cRLrwevzw4iytb [Background time with hint] https://screenshot.googleplex.com/zEf8PcWopCVCRZR [without hint] https://screenshot.googleplex.com/9bao9sVd8s7VRwM [enter from app info (without category)] https://screenshot.googleplex.com/8sozxMrq8ojadiF Bug: 302063050 Test: Manual Change-Id: Ic967d05a173afa76c2a958e1332dedd9f83cd687
This commit is contained in:
@@ -35,33 +35,10 @@
|
|||||||
|
|
||||||
<Space
|
<Space
|
||||||
android:layout_width="@dimen/secondary_app_icon_size"
|
android:layout_width="@dimen/secondary_app_icon_size"
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:layout_marginEnd="16dp"/>
|
||||||
android:padding="8dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:background="@drawable/battery_hints_chip_bg_ripple">
|
|
||||||
|
|
||||||
<ImageView
|
<include layout="@layout/power_anomaly_hints" />
|
||||||
android:layout_width="16dp"
|
|
||||||
android:layout_height="16dp"
|
|
||||||
android:layout_gravity="center_vertical|start"
|
|
||||||
android:contentDescription="@string/battery_hints_warning_icon_a11y"
|
|
||||||
android:src="@drawable/ic_battery_tips_warning_icon" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/warning_info"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingHorizontal="8dp"
|
|
||||||
android:layout_gravity="center_vertical|start"
|
|
||||||
android:textAlignment="viewStart"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
42
res/layout/power_anomaly_hints.xml
Normal file
42
res/layout/power_anomaly_hints.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2023 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical|start"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:background="@drawable/battery_hints_chip_bg_ripple">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:contentDescription="@string/battery_hints_warning_icon_a11y"
|
||||||
|
android:src="@drawable/ic_battery_tips_warning_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/warning_info"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingHorizontal="8dp"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
49
res/layout/power_usage_time.xml
Normal file
49
res/layout/power_usage_time.xml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2023 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/time_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:textColor="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/time_summary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginVertical="4dp"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
|
|
||||||
|
<include layout="@layout/power_anomaly_hints"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/anomaly_hints"
|
||||||
|
android:paddingBottom="20dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@@ -5307,6 +5307,10 @@
|
|||||||
<string name="power_discharge_remaining"><xliff:g id="remain">%1$s</xliff:g> remaining</string>
|
<string name="power_discharge_remaining"><xliff:g id="remain">%1$s</xliff:g> remaining</string>
|
||||||
<!-- Display time remaining until battery is charged [CHAR_LIMIT=60] -->
|
<!-- Display time remaining until battery is charged [CHAR_LIMIT=60] -->
|
||||||
<string name="power_charge_remaining"><xliff:g id="until_charged">%1$s</xliff:g> to charge</string>
|
<string name="power_charge_remaining"><xliff:g id="until_charged">%1$s</xliff:g> to charge</string>
|
||||||
|
<!-- Title for app screen time in power usage detail page [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="power_usage_detail_screen_time">Screen time</string>
|
||||||
|
<!-- Title for app background time in power usage detail page [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="power_usage_detail_background_time">Background time</string>
|
||||||
|
|
||||||
<!-- Description of battery state and remaining time (e.g. Charging rapidly • 1hr 23 min left until full)-->
|
<!-- Description of battery state and remaining time (e.g. Charging rapidly • 1hr 23 min left until full)-->
|
||||||
<string name="battery_state_and_duration" translatable="false"><xliff:g id="state">%1$s</xliff:g> • <xliff:g id="time">%2$s</xliff:g></string>
|
<string name="battery_state_and_duration" translatable="false"><xliff:g id="state">%1$s</xliff:g> • <xliff:g id="time">%2$s</xliff:g></string>
|
||||||
@@ -5322,6 +5326,8 @@
|
|||||||
<!-- Dialog message when app can't been restricted because it is not optimized [CHAR_LIMIT=120] -->
|
<!-- Dialog message when app can't been restricted because it is not optimized [CHAR_LIMIT=120] -->
|
||||||
<string name="background_activity_disabled_dialog_text">Since this app is not set to optimize battery, you can\u2019t restrict it.\n\nTo restrict the app, first turn on battery optimization.</string>
|
<string name="background_activity_disabled_dialog_text">Since this app is not set to optimize battery, you can\u2019t restrict it.\n\nTo restrict the app, first turn on battery optimization.</string>
|
||||||
|
|
||||||
|
<!-- Category title for battery background settings in power usage detail page [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="manager_battery_usage_category_title">Manage battery usage</string>
|
||||||
<!-- Title for the battery unrestricted settings [CHAR_LIMIT=40] -->
|
<!-- Title for the battery unrestricted settings [CHAR_LIMIT=40] -->
|
||||||
<string name="manager_battery_usage_unrestricted_title">Unrestricted</string>
|
<string name="manager_battery_usage_unrestricted_title">Unrestricted</string>
|
||||||
<!-- Title for the battery optimized settings [CHAR_LIMIT=40] -->
|
<!-- Title for the battery optimized settings [CHAR_LIMIT=40] -->
|
||||||
@@ -5668,6 +5674,8 @@
|
|||||||
<string name="battery_usage_background_less_than_one_minute">Background: less than a min</string>
|
<string name="battery_usage_background_less_than_one_minute">Background: less than a min</string>
|
||||||
<!-- [CHAR_LIMIT=NONE] Device screen on time less than a minute -->
|
<!-- [CHAR_LIMIT=NONE] Device screen on time less than a minute -->
|
||||||
<string name="battery_usage_screen_time_less_than_one_minute">Screen time: less than a min</string>
|
<string name="battery_usage_screen_time_less_than_one_minute">Screen time: less than a min</string>
|
||||||
|
<!-- [CHAR_LIMIT=NONE] Power usage time less than a minute -->
|
||||||
|
<string name="power_usage_time_less_than_one_minute">Less than a min</string>
|
||||||
<!-- [CHAR_LIMIT=NONE] Battery usage item for total usage time -->
|
<!-- [CHAR_LIMIT=NONE] Battery usage item for total usage time -->
|
||||||
<string name="battery_usage_for_total_time">Total: <xliff:g id="time">%s</xliff:g></string>
|
<string name="battery_usage_for_total_time">Total: <xliff:g id="time">%s</xliff:g></string>
|
||||||
<!-- [CHAR_LIMIT=NONE] Battery usage item for background usage time -->
|
<!-- [CHAR_LIMIT=NONE] Battery usage item for background usage time -->
|
||||||
|
@@ -27,23 +27,48 @@
|
|||||||
<com.android.settingslib.widget.ActionButtonsPreference
|
<com.android.settingslib.widget.ActionButtonsPreference
|
||||||
android:key="action_buttons"/>
|
android:key="action_buttons"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
<PreferenceCategory
|
||||||
android:key="unrestricted_pref"
|
android:key="battery_usage_time_category"
|
||||||
android:summary="@string/manager_battery_usage_unrestricted_summary"
|
settings:isPreferenceVisible="false"
|
||||||
android:title="@string/manager_battery_usage_unrestricted_title"
|
settings:selectable="false"
|
||||||
settings:controller="com.android.settings.fuelgauge.UnrestrictedPreferenceController"/>
|
settings:controller=
|
||||||
|
"com.android.settings.fuelgauge.PowerUsageTimeController">
|
||||||
|
|
||||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
<com.android.settings.fuelgauge.PowerUsageTimePreference
|
||||||
android:key="optimized_pref"
|
settings:isPreferenceVisible="false"
|
||||||
android:summary="@string/manager_battery_usage_optimized_summary"
|
settings:selectable="false"
|
||||||
android:title="@string/manager_battery_usage_optimized_title"
|
android:key="battery_usage_screen_time"/>
|
||||||
settings:controller="com.android.settings.fuelgauge.OptimizedPreferenceController"/>
|
|
||||||
|
|
||||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
<com.android.settings.fuelgauge.PowerUsageTimePreference
|
||||||
android:key="restricted_pref"
|
settings:isPreferenceVisible="false"
|
||||||
android:summary="@string/manager_battery_usage_restricted_summary"
|
settings:selectable="false"
|
||||||
android:title="@string/manager_battery_usage_restricted_title"
|
android:key="battery_usage_background_time"/>
|
||||||
settings:controller="com.android.settings.fuelgauge.RestrictedPreferenceController"/>
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/manager_battery_usage_category_title"
|
||||||
|
android:key="manage_battery_usage_category">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||||
|
android:key="unrestricted_pref"
|
||||||
|
android:summary="@string/manager_battery_usage_unrestricted_summary"
|
||||||
|
android:title="@string/manager_battery_usage_unrestricted_title"
|
||||||
|
settings:controller="com.android.settings.fuelgauge.UnrestrictedPreferenceController"/>
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||||
|
android:key="optimized_pref"
|
||||||
|
android:summary="@string/manager_battery_usage_optimized_summary"
|
||||||
|
android:title="@string/manager_battery_usage_optimized_title"
|
||||||
|
settings:controller="com.android.settings.fuelgauge.OptimizedPreferenceController"/>
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||||
|
android:key="restricted_pref"
|
||||||
|
android:summary="@string/manager_battery_usage_restricted_summary"
|
||||||
|
android:title="@string/manager_battery_usage_restricted_title"
|
||||||
|
settings:controller="com.android.settings.fuelgauge.RestrictedPreferenceController"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settingslib.widget.FooterPreference
|
<com.android.settingslib.widget.FooterPreference
|
||||||
android:key="app_usage_footer_preference"
|
android:key="app_usage_footer_preference"
|
||||||
|
@@ -124,8 +124,9 @@ public class AppBatteryPreferenceController extends BasePreferenceController
|
|||||||
mParent.getMetricsCategory(),
|
mParent.getMetricsCategory(),
|
||||||
mBatteryDiffEntry,
|
mBatteryDiffEntry,
|
||||||
Utils.formatPercentage(
|
Utils.formatPercentage(
|
||||||
mBatteryDiffEntry.getPercentage(), /* round */ true),
|
mBatteryDiffEntry.getPercentage(), /*round=*/ true),
|
||||||
/*slotInformation=*/ null, /*showTimeInformation=*/ false);
|
/*slotInformation=*/ null, /*showTimeInformation=*/ false,
|
||||||
|
/*anomalyHintPrefKey=*/ null, /*anomalyHintText=*/ null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -75,6 +75,9 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
public static final String EXTRA_FOREGROUND_TIME = "extra_foreground_time";
|
public static final String EXTRA_FOREGROUND_TIME = "extra_foreground_time";
|
||||||
public static final String EXTRA_BACKGROUND_TIME = "extra_background_time";
|
public static final String EXTRA_BACKGROUND_TIME = "extra_background_time";
|
||||||
public static final String EXTRA_SCREEN_ON_TIME = "extra_screen_on_time";
|
public static final String EXTRA_SCREEN_ON_TIME = "extra_screen_on_time";
|
||||||
|
public static final String EXTRA_ANOMALY_HINT_PREF_KEY = "extra_anomaly_hint_pref_key";
|
||||||
|
public static final String EXTRA_ANOMALY_HINT_TEXT = "extra_anomaly_hint_text";
|
||||||
|
public static final String EXTRA_SHOW_TIME_INFO = "extra_show_time_info";
|
||||||
public static final String EXTRA_SLOT_TIME = "extra_slot_time";
|
public static final String EXTRA_SLOT_TIME = "extra_slot_time";
|
||||||
public static final String EXTRA_LABEL = "extra_label";
|
public static final String EXTRA_LABEL = "extra_label";
|
||||||
public static final String EXTRA_ICON_ID = "extra_icon_id";
|
public static final String EXTRA_ICON_ID = "extra_icon_id";
|
||||||
@@ -120,6 +123,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
StringBuilder mLogStringBuilder;
|
StringBuilder mLogStringBuilder;
|
||||||
|
|
||||||
private AppButtonsPreferenceController mAppButtonsPreferenceController;
|
private AppButtonsPreferenceController mAppButtonsPreferenceController;
|
||||||
|
private PowerUsageTimeController mPowerUsageTimeController;
|
||||||
|
|
||||||
// A wrapper class to carry LaunchBatteryDetailPage required arguments.
|
// A wrapper class to carry LaunchBatteryDetailPage required arguments.
|
||||||
private static final class LaunchBatteryDetailPageArgs {
|
private static final class LaunchBatteryDetailPageArgs {
|
||||||
@@ -127,29 +131,23 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private String mAppLabel;
|
private String mAppLabel;
|
||||||
private String mSlotInformation;
|
private String mSlotInformation;
|
||||||
|
private String mAnomalyHintText;
|
||||||
|
private String mAnomalyHintPrefKey;
|
||||||
private int mUid;
|
private int mUid;
|
||||||
private int mIconId;
|
private int mIconId;
|
||||||
private int mConsumedPower;
|
private int mConsumedPower;
|
||||||
private long mForegroundTimeMs;
|
private long mForegroundTimeMs;
|
||||||
private long mBackgroundTimeMs;
|
private long mBackgroundTimeMs;
|
||||||
private long mScreenOnTimeMs;
|
private long mScreenOnTimeMs;
|
||||||
|
private boolean mShowTimeInformation;
|
||||||
private boolean mIsUserEntry;
|
private boolean mIsUserEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Launches battery details page for an individual battery consumer. */
|
|
||||||
public static void startBatteryDetailPage(
|
|
||||||
Activity caller, InstrumentedPreferenceFragment fragment,
|
|
||||||
BatteryDiffEntry diffEntry, String usagePercent, String slotInformation) {
|
|
||||||
startBatteryDetailPage(
|
|
||||||
caller, fragment.getMetricsCategory(), diffEntry, usagePercent, slotInformation,
|
|
||||||
/*showTimeInformation=*/ true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Launches battery details page for an individual battery consumer fragment. */
|
/** Launches battery details page for an individual battery consumer fragment. */
|
||||||
public static void startBatteryDetailPage(
|
public static void startBatteryDetailPage(
|
||||||
Context context, int sourceMetricsCategory,
|
Context context, int sourceMetricsCategory,
|
||||||
BatteryDiffEntry diffEntry, String usagePercent, String slotInformation,
|
BatteryDiffEntry diffEntry, String usagePercent, String slotInformation,
|
||||||
boolean showTimeInformation) {
|
boolean showTimeInformation, String anomalyHintPrefKey, String anomalyHintText) {
|
||||||
final LaunchBatteryDetailPageArgs launchArgs = new LaunchBatteryDetailPageArgs();
|
final LaunchBatteryDetailPageArgs launchArgs = new LaunchBatteryDetailPageArgs();
|
||||||
// configure the launch argument.
|
// configure the launch argument.
|
||||||
launchArgs.mUsagePercent = usagePercent;
|
launchArgs.mUsagePercent = usagePercent;
|
||||||
@@ -159,10 +157,13 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
launchArgs.mUid = (int) diffEntry.mUid;
|
launchArgs.mUid = (int) diffEntry.mUid;
|
||||||
launchArgs.mIconId = diffEntry.getAppIconId();
|
launchArgs.mIconId = diffEntry.getAppIconId();
|
||||||
launchArgs.mConsumedPower = (int) diffEntry.mConsumePower;
|
launchArgs.mConsumedPower = (int) diffEntry.mConsumePower;
|
||||||
if (showTimeInformation) {
|
launchArgs.mShowTimeInformation = showTimeInformation;
|
||||||
|
if (launchArgs.mShowTimeInformation) {
|
||||||
launchArgs.mForegroundTimeMs = diffEntry.mForegroundUsageTimeInMs;
|
launchArgs.mForegroundTimeMs = diffEntry.mForegroundUsageTimeInMs;
|
||||||
launchArgs.mBackgroundTimeMs = diffEntry.mBackgroundUsageTimeInMs;
|
launchArgs.mBackgroundTimeMs = diffEntry.mBackgroundUsageTimeInMs;
|
||||||
launchArgs.mScreenOnTimeMs = diffEntry.mScreenOnTimeInMs;
|
launchArgs.mScreenOnTimeMs = diffEntry.mScreenOnTimeInMs;
|
||||||
|
launchArgs.mAnomalyHintPrefKey = anomalyHintPrefKey;
|
||||||
|
launchArgs.mAnomalyHintText = anomalyHintText;
|
||||||
}
|
}
|
||||||
launchArgs.mIsUserEntry = isUserConsumer(diffEntry.mConsumerType);
|
launchArgs.mIsUserEntry = isUserConsumer(diffEntry.mConsumerType);
|
||||||
startBatteryDetailPage(context, sourceMetricsCategory, launchArgs);
|
startBatteryDetailPage(context, sourceMetricsCategory, launchArgs);
|
||||||
@@ -180,6 +181,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
launchArgs.mIconId = entry.mIconId;
|
launchArgs.mIconId = entry.mIconId;
|
||||||
launchArgs.mConsumedPower = (int) entry.getConsumedPower();
|
launchArgs.mConsumedPower = (int) entry.getConsumedPower();
|
||||||
launchArgs.mIsUserEntry = entry.isUserEntry();
|
launchArgs.mIsUserEntry = entry.isUserEntry();
|
||||||
|
launchArgs.mShowTimeInformation = false;
|
||||||
startBatteryDetailPage(caller, fragment.getMetricsCategory(), launchArgs);
|
startBatteryDetailPage(caller, fragment.getMetricsCategory(), launchArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +205,9 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
args.putString(EXTRA_SLOT_TIME, launchArgs.mSlotInformation);
|
args.putString(EXTRA_SLOT_TIME, launchArgs.mSlotInformation);
|
||||||
args.putString(EXTRA_POWER_USAGE_PERCENT, launchArgs.mUsagePercent);
|
args.putString(EXTRA_POWER_USAGE_PERCENT, launchArgs.mUsagePercent);
|
||||||
args.putInt(EXTRA_POWER_USAGE_AMOUNT, launchArgs.mConsumedPower);
|
args.putInt(EXTRA_POWER_USAGE_AMOUNT, launchArgs.mConsumedPower);
|
||||||
|
args.putBoolean(EXTRA_SHOW_TIME_INFO, launchArgs.mShowTimeInformation);
|
||||||
|
args.putString(EXTRA_ANOMALY_HINT_PREF_KEY, launchArgs.mAnomalyHintPrefKey);
|
||||||
|
args.putString(EXTRA_ANOMALY_HINT_TEXT, launchArgs.mAnomalyHintText);
|
||||||
final int userId = launchArgs.mIsUserEntry ? ActivityManager.getCurrentUser()
|
final int userId = launchArgs.mIsUserEntry ? ActivityManager.getCurrentUser()
|
||||||
: UserHandle.getUserId(launchArgs.mUid);
|
: UserHandle.getUserId(launchArgs.mUid);
|
||||||
|
|
||||||
@@ -335,7 +340,15 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
|
controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.setSummary(getHeaderSummary(bundle));
|
if (mPowerUsageTimeController != null) {
|
||||||
|
final String slotTime = bundle.getString(EXTRA_SLOT_TIME);
|
||||||
|
final long screenOnTimeInMs = bundle.getLong(EXTRA_SCREEN_ON_TIME);
|
||||||
|
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
|
||||||
|
final String anomalyHintPrefKey = bundle.getString(EXTRA_ANOMALY_HINT_PREF_KEY);
|
||||||
|
final String anomalyHintText = bundle.getString(EXTRA_ANOMALY_HINT_TEXT);
|
||||||
|
mPowerUsageTimeController.handleScreenTimeUpdated(slotTime, screenOnTimeInMs,
|
||||||
|
backgroundTimeMs, anomalyHintPrefKey, anomalyHintText);
|
||||||
|
}
|
||||||
controller.done(true /* rebindActions */);
|
controller.done(true /* rebindActions */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,6 +407,10 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
mAppButtonsPreferenceController = new AppButtonsPreferenceController(
|
mAppButtonsPreferenceController = new AppButtonsPreferenceController(
|
||||||
(SettingsActivity) getActivity(), this, getSettingsLifecycle(),
|
(SettingsActivity) getActivity(), this, getSettingsLifecycle(),
|
||||||
packageName, mState, REQUEST_UNINSTALL, REQUEST_REMOVE_DEVICE_ADMIN);
|
packageName, mState, REQUEST_UNINSTALL, REQUEST_REMOVE_DEVICE_ADMIN);
|
||||||
|
if (bundle.getBoolean(EXTRA_SHOW_TIME_INFO, false)) {
|
||||||
|
mPowerUsageTimeController = new PowerUsageTimeController(getContext());
|
||||||
|
controllers.add(mPowerUsageTimeController);
|
||||||
|
}
|
||||||
controllers.add(mAppButtonsPreferenceController);
|
controllers.add(mAppButtonsPreferenceController);
|
||||||
controllers.add(new UnrestrictedPreferenceController(context, uid, packageName));
|
controllers.add(new UnrestrictedPreferenceController(context, uid, packageName));
|
||||||
controllers.add(new OptimizedPreferenceController(context, uid, packageName));
|
controllers.add(new OptimizedPreferenceController(context, uid, packageName));
|
||||||
@@ -490,23 +507,6 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getHeaderSummary(Bundle bundle) {
|
|
||||||
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
|
|
||||||
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
|
|
||||||
final long screenOnTimeInMs = bundle.getLong(EXTRA_SCREEN_ON_TIME);
|
|
||||||
final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
|
|
||||||
final String usageSummary = BatteryUtils.buildBatteryUsageTimeSummary(getContext(),
|
|
||||||
/* isSystem= */ false, foregroundTimeMs, backgroundTimeMs, screenOnTimeInMs);
|
|
||||||
|
|
||||||
if (usageSummary.isEmpty()) {
|
|
||||||
return getText(R.string.battery_usage_without_time);
|
|
||||||
} else {
|
|
||||||
CharSequence slotSummary = slotTime == null
|
|
||||||
? getText(R.string.battery_usage_since_last_full_charge) : slotTime;
|
|
||||||
return String.format("%s\n(%s)", usageSummary, slotSummary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getLoggingPackageName(Context context, String originalPackingName) {
|
private static String getLoggingPackageName(Context context, String originalPackingName) {
|
||||||
return BatteryUtils.isAppInstalledFromGooglePlayStore(context, originalPackingName)
|
return BatteryUtils.isAppInstalledFromGooglePlayStore(context, originalPackingName)
|
||||||
? originalPackingName : PACKAGE_NAME_NONE;
|
? originalPackingName : PACKAGE_NAME_NONE;
|
||||||
|
108
src/com/android/settings/fuelgauge/PowerUsageTimeController.java
Normal file
108
src/com/android/settings/fuelgauge/PowerUsageTimeController.java
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
|
import static com.android.settings.fuelgauge.BatteryUtils.formatElapsedTimeWithoutComma;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
public class PowerUsageTimeController extends BasePreferenceController {
|
||||||
|
private static final String TAG = "PowerUsageTimeController";
|
||||||
|
|
||||||
|
private static final String KEY_POWER_USAGE_TIME = "battery_usage_time_category";
|
||||||
|
private static final String KEY_SCREEN_TIME_PREF = "battery_usage_screen_time";
|
||||||
|
private static final String KEY_BACKGROUND_TIME_PREF = "battery_usage_background_time";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
PreferenceCategory mPowerUsageTimeCategory;
|
||||||
|
@VisibleForTesting
|
||||||
|
PowerUsageTimePreference mScreenTimePreference;
|
||||||
|
@VisibleForTesting
|
||||||
|
PowerUsageTimePreference mBackgroundTimePreference;
|
||||||
|
|
||||||
|
public PowerUsageTimeController(Context context) {
|
||||||
|
super(context, KEY_POWER_USAGE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPowerUsageTimeCategory = screen.findPreference(KEY_POWER_USAGE_TIME);
|
||||||
|
mScreenTimePreference = screen.findPreference(KEY_SCREEN_TIME_PREF);
|
||||||
|
mBackgroundTimePreference = screen.findPreference(KEY_BACKGROUND_TIME_PREF);
|
||||||
|
mPowerUsageTimeCategory.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleScreenTimeUpdated(final String slotTime,
|
||||||
|
final long screenOnTimeInMs, final long backgroundTimeInMs,
|
||||||
|
final String anomalyHintPrefKey, final String anomalyHintText) {
|
||||||
|
final boolean isShowScreenOnTime = showTimePreference(
|
||||||
|
mScreenTimePreference, R.string.power_usage_detail_screen_time,
|
||||||
|
screenOnTimeInMs, anomalyHintPrefKey, anomalyHintText);
|
||||||
|
final boolean isShowBackgroundTime = showTimePreference(
|
||||||
|
mBackgroundTimePreference, R.string.power_usage_detail_background_time,
|
||||||
|
backgroundTimeInMs, anomalyHintPrefKey, anomalyHintText);
|
||||||
|
if (isShowScreenOnTime || isShowBackgroundTime) {
|
||||||
|
showCategoryTitle(slotTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean showTimePreference(PowerUsageTimePreference preference,
|
||||||
|
int titleResId, long summaryTimeMs, String anomalyHintKey, String anomalyHintText) {
|
||||||
|
if (preference == null
|
||||||
|
|| (summaryTimeMs == 0 && !TextUtils.equals(anomalyHintKey, preference.getKey()))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
preference.setTimeTitle(mContext.getString(titleResId));
|
||||||
|
preference.setTimeSummary(getPowerUsageTimeInfo(summaryTimeMs));
|
||||||
|
if (TextUtils.equals(anomalyHintKey, preference.getKey())) {
|
||||||
|
preference.setAnomalyHint(anomalyHintText);
|
||||||
|
}
|
||||||
|
preference.setVisible(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CharSequence getPowerUsageTimeInfo(long timeInMs) {
|
||||||
|
if (timeInMs < DateUtils.MINUTE_IN_MILLIS) {
|
||||||
|
return mContext.getString(R.string.power_usage_time_less_than_one_minute);
|
||||||
|
}
|
||||||
|
return formatElapsedTimeWithoutComma(mContext, (double) timeInMs,
|
||||||
|
/*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void showCategoryTitle(String slotTimestamp) {
|
||||||
|
mPowerUsageTimeCategory.setTitle(slotTimestamp == null
|
||||||
|
? mContext.getString(R.string.battery_app_usage)
|
||||||
|
: mContext.getString(R.string.battery_app_usage_for, slotTimestamp));
|
||||||
|
mPowerUsageTimeCategory.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom preference for displaying the app power usage time.
|
||||||
|
*/
|
||||||
|
public class PowerUsageTimePreference extends Preference {
|
||||||
|
private static final String TAG = "PowerUsageTimePreference";
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
CharSequence mTimeTitle;
|
||||||
|
@VisibleForTesting
|
||||||
|
CharSequence mTimeSummary;
|
||||||
|
@VisibleForTesting
|
||||||
|
CharSequence mAnomalyHintText;
|
||||||
|
|
||||||
|
public PowerUsageTimePreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
setLayoutResource(R.layout.power_usage_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTimeTitle(CharSequence timeTitle) {
|
||||||
|
if (!TextUtils.equals(mTimeTitle, timeTitle)) {
|
||||||
|
mTimeTitle = timeTitle;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTimeSummary(CharSequence timeSummary) {
|
||||||
|
if (!TextUtils.equals(mTimeSummary, timeSummary)) {
|
||||||
|
mTimeSummary = timeSummary;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAnomalyHint(CharSequence anomalyHintText) {
|
||||||
|
if (!TextUtils.equals(mAnomalyHintText, anomalyHintText)) {
|
||||||
|
mAnomalyHintText = anomalyHintText;
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAnomalyHint(PreferenceViewHolder view) {
|
||||||
|
if (TextUtils.isEmpty(mAnomalyHintText)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final View anomalyHintView = view.findViewById(R.id.anomaly_hints);
|
||||||
|
if (anomalyHintView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final TextView warningInfo = anomalyHintView.findViewById(R.id.warning_info);
|
||||||
|
if (warningInfo == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
warningInfo.setText(mAnomalyHintText);
|
||||||
|
anomalyHintView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
|
super.onBindViewHolder(view);
|
||||||
|
|
||||||
|
((TextView) view.findViewById(R.id.time_title)).setText(mTimeTitle);
|
||||||
|
((TextView) view.findViewById(R.id.time_summary)).setText(mTimeSummary);
|
||||||
|
|
||||||
|
showAnomalyHint(view);
|
||||||
|
}
|
||||||
|
}
|
@@ -98,10 +98,10 @@ final class AnomalyEventWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getTitleString() {
|
String getTitleString() {
|
||||||
final String protoTitleString = getInfo(WarningBannerInfo::getTitleString,
|
final String titleStringFromProto = getInfo(WarningBannerInfo::getTitleString,
|
||||||
WarningItemInfo::getTitleString);
|
WarningItemInfo::getTitleString);
|
||||||
if (!TextUtils.isEmpty(protoTitleString)) {
|
if (!TextUtils.isEmpty(titleStringFromProto)) {
|
||||||
return protoTitleString;
|
return titleStringFromProto;
|
||||||
}
|
}
|
||||||
final int titleFormatResId = getResourceId(R.array.power_anomaly_title_ids,
|
final int titleFormatResId = getResourceId(R.array.power_anomaly_title_ids,
|
||||||
mResourceIndex, "string");
|
mResourceIndex, "string");
|
||||||
@@ -127,7 +127,15 @@ final class AnomalyEventWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getAnomalyHintString() {
|
String getAnomalyHintString() {
|
||||||
return getStringFromArrayResource(R.array.power_anomaly_hint_messages, mResourceIndex);
|
final String anomalyHintStringFromProto = getInfo(null,
|
||||||
|
WarningItemInfo::getWarningInfoString);
|
||||||
|
return TextUtils.isEmpty(anomalyHintStringFromProto)
|
||||||
|
? getStringFromArrayResource(R.array.power_anomaly_hint_messages, mResourceIndex)
|
||||||
|
: anomalyHintStringFromProto;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getAnomalyHintPrefKey() {
|
||||||
|
return getInfo(null, WarningItemInfo::getAnomalyHintPrefKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDismissRecordKey() {
|
String getDismissRecordKey() {
|
||||||
|
@@ -102,6 +102,8 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
String mAnomalyEntryKey;
|
String mAnomalyEntryKey;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String mAnomalyHintString;
|
String mAnomalyHintString;
|
||||||
|
@VisibleForTesting
|
||||||
|
String mAnomalyHintPrefKey;
|
||||||
|
|
||||||
public BatteryUsageBreakdownController(
|
public BatteryUsageBreakdownController(
|
||||||
Context context, Lifecycle lifecycle, SettingsActivity activity,
|
Context context, Lifecycle lifecycle, SettingsActivity activity,
|
||||||
@@ -174,8 +176,13 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
(int) Math.round(diffEntry.getPercentage()));
|
(int) Math.round(diffEntry.getPercentage()));
|
||||||
Log.d(TAG, String.format("handleClick() label=%s key=%s package=%s",
|
Log.d(TAG, String.format("handleClick() label=%s key=%s package=%s",
|
||||||
diffEntry.getAppLabel(), diffEntry.getKey(), diffEntry.getPackageName()));
|
diffEntry.getAppLabel(), diffEntry.getKey(), diffEntry.getPackageName()));
|
||||||
AdvancedPowerUsageDetail.startBatteryDetailPage(
|
final String anomalyHintPrefKey = isAnomalyBatteryDiffEntry(diffEntry)
|
||||||
mActivity, mFragment, diffEntry, powerPref.getPercentage(), mSlotTimestamp);
|
? mAnomalyHintPrefKey : null;
|
||||||
|
final String anomalyHintText = isAnomalyBatteryDiffEntry(diffEntry)
|
||||||
|
? mAnomalyHintString : null;
|
||||||
|
AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment.getMetricsCategory(),
|
||||||
|
diffEntry, powerPref.getPercentage(), mSlotTimestamp,
|
||||||
|
/*showTimeInformation=*/ true, anomalyHintPrefKey, anomalyHintText);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +253,8 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
? anomalyEventWrapper.getAnomalyEntryKey() : null;
|
? anomalyEventWrapper.getAnomalyEntryKey() : null;
|
||||||
mAnomalyHintString = anomalyEventWrapper != null
|
mAnomalyHintString = anomalyEventWrapper != null
|
||||||
? anomalyEventWrapper.getAnomalyHintString() : null;
|
? anomalyEventWrapper.getAnomalyHintString() : null;
|
||||||
|
mAnomalyHintPrefKey = anomalyEventWrapper != null
|
||||||
|
? anomalyEventWrapper.getAnomalyHintPrefKey() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
showCategoryTitle(slotTimestamp);
|
showCategoryTitle(slotTimestamp);
|
||||||
|
@@ -67,4 +67,6 @@ message WarningItemInfo {
|
|||||||
optional string main_button_string = 6;
|
optional string main_button_string = 6;
|
||||||
optional string cancel_button_string = 7;
|
optional string cancel_button_string = 7;
|
||||||
optional string item_key = 8;
|
optional string item_key = 8;
|
||||||
|
optional string warning_info_string = 9;
|
||||||
|
optional string anomaly_hint_pref_key = 10;
|
||||||
}
|
}
|
||||||
|
@@ -126,8 +126,10 @@ private class AppBatteryPresenter(private val context: Context, private val app:
|
|||||||
AppInfoSettingsProvider.METRICS_CATEGORY,
|
AppInfoSettingsProvider.METRICS_CATEGORY,
|
||||||
this,
|
this,
|
||||||
Utils.formatPercentage(percentage, true),
|
Utils.formatPercentage(percentage, true),
|
||||||
null,
|
/*slotInformation=*/ null,
|
||||||
false,
|
/*showTimeInformation=*/ false,
|
||||||
|
/*anomalyHintPrefKey=*/ null,
|
||||||
|
/*anomalyHintText=*/ null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -163,6 +163,8 @@ class AppBatteryPreferenceTest {
|
|||||||
"10%",
|
"10%",
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
|
null,
|
||||||
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user