Move battery usage files to a separate folder.

Bug: 202118250
Test: presubmit
Change-Id: I21aa58ebc02327849ed2161dbbafcdc806c007f2
This commit is contained in:
xuezaiyue
2022-06-08 21:53:23 +08:00
committed by YK Hung
parent 23eecdc87d
commit ac7318419a
49 changed files with 1126 additions and 1028 deletions

View File

@@ -2846,7 +2846,7 @@
<category android:name="com.android.settings.SHORTCUT" /> <category android:name="com.android.settings.SHORTCUT" />
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.PowerUsageSummary" /> android:value="com.android.settings.fuelgauge.batteryusage.PowerUsageSummary" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY" <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_battery"/> android:value="@string/menu_key_battery"/>
</activity> </activity>

View File

@@ -31,7 +31,7 @@
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:text="@string/battery_usage_chart_graph_hint" /> android:text="@string/battery_usage_chart_graph_hint" />
<com.android.settings.fuelgauge.BatteryChartView <com.android.settings.fuelgauge.batteryusage.BatteryChartView
android:id="@+id/battery_chart" android:id="@+id/battery_chart"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="170dp" android:layout_height="170dp"

View File

@@ -21,7 +21,7 @@
android:title="@string/advanced_battery_title" android:title="@string/advanced_battery_title"
settings:keywords="@string/keywords_battery_usage"> settings:keywords="@string/keywords_battery_usage">
<com.android.settings.fuelgauge.BatteryHistoryPreference <com.android.settings.fuelgauge.batteryusage.BatteryHistoryPreference
android:key="battery_graph"/> android:key="battery_graph"/>
<PreferenceCategory <PreferenceCategory

View File

@@ -39,7 +39,7 @@
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" /> settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" />
<Preference <Preference
android:fragment="com.android.settings.fuelgauge.PowerUsageAdvanced" android:fragment="com.android.settings.fuelgauge.batteryusage.PowerUsageAdvanced"
android:key="battery_usage_summary" android:key="battery_usage_summary"
android:title="@string/advanced_battery_preference_title" android:title="@string/advanced_battery_preference_title"
settings:keywords="@string/keywords_battery_usage" /> settings:keywords="@string/keywords_battery_usage" />

View File

@@ -59,7 +59,7 @@
settings:highlightableMenuKey="@string/menu_key_notifications"/> settings:highlightableMenuKey="@string/menu_key_notifications"/>
<com.android.settings.widget.HomepagePreference <com.android.settings.widget.HomepagePreference
android:fragment="com.android.settings.fuelgauge.PowerUsageSummary" android:fragment="com.android.settings.fuelgauge.batteryusage.PowerUsageSummary"
android:icon="@drawable/ic_settings_battery_white" android:icon="@drawable/ic_settings_battery_white"
android:key="top_level_battery" android:key="top_level_battery"
android:order="-110" android:order="-110"

View File

@@ -38,12 +38,12 @@ import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail; import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.BatteryChartPreferenceController;
import com.android.settings.fuelgauge.BatteryDiffEntry;
import com.android.settings.fuelgauge.BatteryEntry;
import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
import com.android.settings.fuelgauge.BatteryUtils; import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider; import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.fuelgauge.batteryusage.BatteryChartPreferenceController;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.AppUtils; import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;

View File

@@ -99,9 +99,9 @@ import com.android.settings.display.darkmode.DarkModeSettingsFragment;
import com.android.settings.dream.DreamSettings; import com.android.settings.dream.DreamSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings; import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail; import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.batterysaver.BatterySaverScheduleSettings; import com.android.settings.fuelgauge.batterysaver.BatterySaverScheduleSettings;
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings; import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.AssistGestureSettings; import com.android.settings.gestures.AssistGestureSettings;
import com.android.settings.gestures.ButtonNavigationSettingsFragment; import com.android.settings.gestures.ButtonNavigationSettingsFragment;
import com.android.settings.gestures.DoubleTapPowerSettings; import com.android.settings.gestures.DoubleTapPowerSettings;

View File

@@ -31,9 +31,9 @@ import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.display.NightDisplaySettings; import com.android.settings.display.NightDisplaySettings;
import com.android.settings.emergency.EmergencyDashboardFragment; import com.android.settings.emergency.EmergencyDashboardFragment;
import com.android.settings.enterprise.EnterprisePrivacySettings; import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.SmartBatterySettings; import com.android.settings.fuelgauge.SmartBatterySettings;
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings; import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.GestureSettings; import com.android.settings.gestures.GestureSettings;
import com.android.settings.homepage.TopLevelSettings; import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.language.LanguageAndInputSettings; import com.android.settings.language.LanguageAndInputSettings;

View File

@@ -45,6 +45,9 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
import com.android.settings.widget.EntityHeaderController; import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.HelpUtils; import com.android.settingslib.HelpUtils;
import com.android.settingslib.applications.AppUtils; import com.android.settingslib.applications.AppUtils;

View File

@@ -190,7 +190,7 @@ public class BatteryUtils {
* Returns true if the specified battery consumer should be excluded from * Returns true if the specified battery consumer should be excluded from
* battery consumption lists, either short or full. * battery consumption lists, either short or full.
*/ */
boolean shouldHideUidBatteryConsumerUnconditionally(UidBatteryConsumer consumer, public boolean shouldHideUidBatteryConsumerUnconditionally(UidBatteryConsumer consumer,
String[] packages) { String[] packages) {
final int uid = consumer.getUid(); final int uid = consumer.getUid();
return uid == UID_TETHERING return uid == UID_TETHERING

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
import com.android.settingslib.fuelgauge.Estimate; import com.android.settingslib.fuelgauge.Estimate;
import java.util.Map; import java.util.Map;
@@ -73,6 +74,7 @@ public interface PowerUsageFeatureProvider {
/** /**
* Returns an improved projection curve for future battery level. * Returns an improved projection curve for future battery level.
*
* @param zeroTime timestamps (array keys) are shifted by this amount * @param zeroTime timestamps (array keys) are shifted by this amount
*/ */
SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime); SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime);
@@ -84,21 +86,20 @@ public interface PowerUsageFeatureProvider {
/** /**
* Checks whether debugging should be enabled for battery estimates. * Checks whether debugging should be enabled for battery estimates.
* @return
*/ */
boolean isEstimateDebugEnabled(); boolean isEstimateDebugEnabled();
/** /**
* Converts the provided string containing the remaining time into a debug string for enhanced * Converts the provided string containing the remaining time into a debug string for enhanced
* estimates. * estimates.
* @param timeRemaining *
* @return A string containing the estimate and a label indicating it is an enhanced estimate * @return A string containing the estimate and a label indicating it is an enhanced estimate
*/ */
String getEnhancedEstimateDebugString(String timeRemaining); String getEnhancedEstimateDebugString(String timeRemaining);
/** /**
* Converts the provided string containing the remaining time into a debug string. * Converts the provided string containing the remaining time into a debug string.
* @param timeRemaining *
* @return A string containing the estimate and a label indicating it is a normal estimate * @return A string containing the estimate and a label indicating it is a normal estimate
*/ */
String getOldEstimateDebugString(String timeRemaining); String getOldEstimateDebugString(String timeRemaining);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -26,11 +26,13 @@ import android.util.SparseIntArray;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
import com.android.settingslib.fuelgauge.Estimate; import com.android.settingslib.fuelgauge.Estimate;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/** Implementation of {@code PowerUsageFeatureProvider} */
public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider { public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar"; private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar";

View File

@@ -21,12 +21,13 @@ import android.os.Parcel;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.batterytip.AppInfo; import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
/** /**
* Tip to suggest user to remove app restriction. This is the empty tip and it is only used in * Tip to suggest user to remove app restriction. This is the empty tip and it is only used in
* {@link com.android.settings.fuelgauge.AdvancedPowerUsageDetail} to create dialog. * {@link AdvancedPowerUsageDetail} to create dialog.
*/ */
public class UnrestrictAppTip extends BatteryTip { public class UnrestrictAppTip extends BatteryTip {
private AppInfo mAppInfo; private AppInfo mAppInfo;

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@@ -11,11 +12,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@@ -35,8 +34,8 @@ import android.os.UserManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.SparseArray;
import android.util.Log; import android.util.Log;
import android.util.SparseArray;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
@@ -48,6 +47,8 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -72,6 +73,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 20; private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 20;
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10; private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
private static final String MEDIASERVER_PACKAGE_NAME = "mediaserver"; private static final String MEDIASERVER_PACKAGE_NAME = "mediaserver";
private static final String NOT_AVAILABLE = "not_available";
@VisibleForTesting @VisibleForTesting
PreferenceGroup mAppListGroup; PreferenceGroup mAppListGroup;
@@ -458,8 +460,8 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
private void cacheRemoveAllPrefs(PreferenceGroup group) { private void cacheRemoveAllPrefs(PreferenceGroup group) {
mPreferenceCache = new ArrayMap<>(); mPreferenceCache = new ArrayMap<>();
final int N = group.getPreferenceCount(); final int n = group.getPreferenceCount();
for (int i = 0; i < N; i++) { for (int i = 0; i < n; i++) {
Preference p = group.getPreference(i); Preference p = group.getPreference(i);
if (TextUtils.isEmpty(p.getKey())) { if (TextUtils.isEmpty(p.getKey())) {
continue; continue;
@@ -563,7 +565,6 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
} }
private void addNotAvailableMessage() { private void addNotAvailableMessage() {
final String NOT_AVAILABLE = "not_available";
Preference notAvailable = getCachedPreference(NOT_AVAILABLE); Preference notAvailable = getCachedPreference(NOT_AVAILABLE);
if (notAvailable == null) { if (notAvailable == null) {
notAvailable = new Preference(mPrefContext); notAvailable = new Preference(mPrefContext);

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@@ -11,10 +12,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
@@ -38,6 +38,8 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -82,16 +84,25 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
@VisibleForTesting @VisibleForTesting
Map<Integer, List<BatteryDiffEntry>> mBatteryIndexedMap; Map<Integer, List<BatteryDiffEntry>> mBatteryIndexedMap;
@VisibleForTesting Context mPrefContext; @VisibleForTesting
@VisibleForTesting BatteryUtils mBatteryUtils; Context mPrefContext;
@VisibleForTesting PreferenceGroup mAppListPrefGroup; @VisibleForTesting
@VisibleForTesting BatteryChartView mBatteryChartView; BatteryUtils mBatteryUtils;
@VisibleForTesting ExpandDividerPreference mExpandDividerPreference; @VisibleForTesting
PreferenceGroup mAppListPrefGroup;
@VisibleForTesting
BatteryChartView mBatteryChartView;
@VisibleForTesting
ExpandDividerPreference mExpandDividerPreference;
@VisibleForTesting boolean mIsExpanded = false; @VisibleForTesting
@VisibleForTesting int[] mBatteryHistoryLevels; boolean mIsExpanded = false;
@VisibleForTesting long[] mBatteryHistoryKeys; @VisibleForTesting
@VisibleForTesting int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID; int[] mBatteryHistoryLevels;
@VisibleForTesting
long[] mBatteryHistoryKeys;
@VisibleForTesting
int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID;
private boolean mIs24HourFormat = false; private boolean mIs24HourFormat = false;
private boolean mIsFooterPrefAdded = false; private boolean mIsFooterPrefAdded = false;
@@ -496,7 +507,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} else { } else {
return isApp return isApp
? mPrefContext.getString(R.string.battery_app_usage_for, slotInformation) ? mPrefContext.getString(R.string.battery_app_usage_for, slotInformation)
: mPrefContext.getString(R.string.battery_system_usage_for ,slotInformation); : mPrefContext.getString(R.string.battery_system_usage_for, slotInformation);
} }
} }

View File

@@ -1,22 +1,24 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * Licensed under the Apache License, Version 2.0 (the "License");
* except in compliance with the License. You may obtain a copy of the License at * 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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the * Unless required by applicable law or agreed to in writing, software
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * distributed under the License is distributed on an "AS IS" BASIS,
* KIND, either express or implied. See the License for the specific language governing * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* permissions and limitations under the License. * See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static java.lang.Math.round;
import static com.android.settings.Utils.formatPercentage; import static com.android.settings.Utils.formatPercentage;
import static java.lang.Math.round;
import android.accessibilityservice.AccessibilityServiceInfo; import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
@@ -37,8 +39,8 @@ import android.view.View;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.appcompat.widget.AppCompatImageView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
@@ -68,6 +70,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
/** A callback listener for selected group index is updated. */ /** A callback listener for selected group index is updated. */
public interface OnSelectListener { public interface OnSelectListener {
/** The callback function for selected group index is updated. */
void onSelect(int trapezoidIndex); void onSelect(int trapezoidIndex);
} }
@@ -79,9 +82,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private boolean mIsSlotsClickabled; private boolean mIsSlotsClickabled;
private String[] mPercentages = getPercentages(); private String[] mPercentages = getPercentages();
@VisibleForTesting int mHoveredIndex = SELECTED_INDEX_INVALID; @VisibleForTesting
@VisibleForTesting int mSelectedIndex = SELECTED_INDEX_INVALID; int mHoveredIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting String[] mTimestamps; @VisibleForTesting
int mSelectedIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting
String[] mTimestamps;
// Colors for drawing the trapezoid shape and dividers. // Colors for drawing the trapezoid shape and dividers.
private int mTrapezoidColor; private int mTrapezoidColor;
@@ -91,10 +97,10 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private int mTextPadding; private int mTextPadding;
private final Rect mIndent = new Rect(); private final Rect mIndent = new Rect();
private final Rect[] mPercentageBounds = private final Rect[] mPercentageBounds =
new Rect[] {new Rect(), new Rect(), new Rect()}; new Rect[]{new Rect(), new Rect(), new Rect()};
// For drawing the timestamp information. // For drawing the timestamp information.
private final Rect[] mTimestampsBounds = private final Rect[] mTimestampsBounds =
new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()}; new Rect[]{new Rect(), new Rect(), new Rect(), new Rect()};
@VisibleForTesting @VisibleForTesting
Handler mHandler = new Handler(); Handler mHandler = new Handler();
@@ -208,7 +214,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTimestamps[index] = mTimestamps[index] =
ConvertUtils.utcToLocalTimeHour( ConvertUtils.utcToLocalTimeHour(
getContext(), getContext(),
latestTimestamp - (TIMESTAMP_GAPS_COUNT - index) * timeSlotOffset, latestTimestamp - (TIMESTAMP_GAPS_COUNT - index)
* timeSlotOffset,
is24HourFormat); is24HourFormat);
} }
requestLayout(); requestLayout();
@@ -429,8 +436,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
if (mTextPaint != null) { if (mTextPaint != null) {
canvas.drawText( canvas.drawText(
mPercentages[index], mPercentages[index],
getWidth() - mPercentageBounds[index].width() - mPercentageBounds[index].left, getWidth() - mPercentageBounds[index].width()
offsetY + mPercentageBounds[index].height() *.5f, - mPercentageBounds[index].left,
offsetY + mPercentageBounds[index].height() * .5f,
mTextPaint); mTextPaint);
} }
} }
@@ -485,8 +493,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
for (int index = 1; index <= DEFAULT_TIMESTAMP_COUNT - 2; index++) { for (int index = 1; index <= DEFAULT_TIMESTAMP_COUNT - 2; index++) {
canvas.drawText( canvas.drawText(
mTimestamps[index], mTimestamps[index],
xOffsets[index] - xOffsets[index]
(mTimestampsBounds[index].width() - mTimestampsBounds[index].left) * .5f, - (mTimestampsBounds[index].width() - mTimestampsBounds[index].left)
* .5f,
getTimestampY(index), mTextPaint); getTimestampY(index), mTextPaint);
} }
@@ -546,7 +555,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Generates path for non-clickable trapezoid curve. // Generates path for non-clickable trapezoid curve.
if (mTrapezoidCurvePaint != null) { if (mTrapezoidCurvePaint != null) {
if (trapezoidCurvePath == null) { if (trapezoidCurvePath == null) {
trapezoidCurvePath= new Path(); trapezoidCurvePath = new Path();
trapezoidCurvePath.moveTo(mTrapezoidSlots[index].mLeft, leftTop); trapezoidCurvePath.moveTo(mTrapezoidSlots[index].mLeft, leftTop);
} else { } else {
trapezoidCurvePath.lineTo(mTrapezoidSlots[index].mLeft, leftTop); trapezoidCurvePath.lineTo(mTrapezoidSlots[index].mLeft, leftTop);
@@ -582,7 +591,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
} }
private static String[] getPercentages() { private static String[] getPercentages() {
return new String[] { return new String[]{
formatPercentage(/*percentage=*/ 100, /*round=*/ true), formatPercentage(/*percentage=*/ 100, /*round=*/ true),
formatPercentage(/*percentage=*/ 50, /*round=*/ true), formatPercentage(/*percentage=*/ 50, /*round=*/ true),
formatPercentage(/*percentage=*/ 0, /*round=*/ true)}; formatPercentage(/*percentage=*/ 0, /*round=*/ true)};

View File

@@ -1,17 +1,19 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * Licensed under the Apache License, Version 2.0 (the "License");
* except in compliance with the License. You may obtain a copy of the License at * 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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the * Unless required by applicable law or agreed to in writing, software
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * distributed under the License is distributed on an "AS IS" BASIS,
* KIND, either express or implied. See the License for the specific language governing * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* permissions and limitations under the License. * See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
@@ -26,6 +28,7 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settingslib.utils.StringUtil; import com.android.settingslib.utils.StringUtil;
import java.util.Comparator; import java.util.Comparator;
@@ -61,11 +64,16 @@ public class BatteryDiffEntry {
private UserManager mUserManager; private UserManager mUserManager;
private String mDefaultPackageName = null; private String mDefaultPackageName = null;
@VisibleForTesting int mAppIconId; @VisibleForTesting
@VisibleForTesting String mAppLabel = null; int mAppIconId;
@VisibleForTesting Drawable mAppIcon = null; @VisibleForTesting
@VisibleForTesting boolean mIsLoaded = false; String mAppLabel = null;
@VisibleForTesting boolean mValidForRestriction = true; @VisibleForTesting
Drawable mAppIcon = null;
@VisibleForTesting
boolean mIsLoaded = false;
@VisibleForTesting
boolean mValidForRestriction = true;
public BatteryDiffEntry( public BatteryDiffEntry(
Context context, Context context,
@@ -135,9 +143,9 @@ public class BatteryDiffEntry {
} }
// Removes potential appended process name in the PackageName. // Removes potential appended process name in the PackageName.
// From "com.opera.browser:privileged_process0" to "com.opera.browser" // From "com.opera.browser:privileged_process0" to "com.opera.browser"
final String[] splittedPackageNames = packageName.split(":"); final String[] splitPackageNames = packageName.split(":");
return splittedPackageNames != null && splittedPackageNames.length > 0 return splitPackageNames != null && splitPackageNames.length > 0
? splittedPackageNames[0] : packageName; ? splitPackageNames[0] : packageName;
} }
/** Whether this item is valid for users to launch restriction page? */ /** Whether this item is valid for users to launch restriction page? */

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2014 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.app.AppGlobals; import android.app.AppGlobals;
import android.content.Context; import android.content.Context;
@@ -36,9 +36,8 @@ import android.os.UserManager;
import android.util.DebugUtils; import android.util.DebugUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import java.util.ArrayList; import java.util.ArrayList;
@@ -52,6 +51,7 @@ import java.util.Locale;
*/ */
public class BatteryEntry { public class BatteryEntry {
/** The app name and icon in app list. */
public static final class NameAndIcon { public static final class NameAndIcon {
public final String mName; public final String mName;
public final String mPackageName; public final String mPackageName;
@@ -84,10 +84,10 @@ public class BatteryEntry {
static Locale sCurrentLocale = null; static Locale sCurrentLocale = null;
static private class NameAndIconLoader extends Thread { private static class NameAndIconLoader extends Thread {
private boolean mAbort = false; private boolean mAbort = false;
public NameAndIconLoader() { NameAndIconLoader() {
super("BatteryUsage Icon Loader"); super("BatteryUsage Icon Loader");
} }
@@ -121,35 +121,38 @@ public class BatteryEntry {
} }
} }
private static NameAndIconLoader mRequestThread; private static NameAndIconLoader sRequestThread;
/** Starts the request queue. */
public static void startRequestQueue() { public static void startRequestQueue() {
if (sHandler != null) { if (sHandler != null) {
synchronized (sRequestQueue) { synchronized (sRequestQueue) {
if (!sRequestQueue.isEmpty()) { if (!sRequestQueue.isEmpty()) {
if (mRequestThread != null) { if (sRequestThread != null) {
mRequestThread.abort(); sRequestThread.abort();
} }
mRequestThread = new NameAndIconLoader(); sRequestThread = new NameAndIconLoader();
mRequestThread.setPriority(Thread.MIN_PRIORITY); sRequestThread.setPriority(Thread.MIN_PRIORITY);
mRequestThread.start(); sRequestThread.start();
sRequestQueue.notify(); sRequestQueue.notify();
} }
} }
} }
} }
/** Stops the request queue. */
public static void stopRequestQueue() { public static void stopRequestQueue() {
synchronized (sRequestQueue) { synchronized (sRequestQueue) {
if (mRequestThread != null) { if (sRequestThread != null) {
mRequestThread.abort(); sRequestThread.abort();
mRequestThread = null; sRequestThread = null;
sRequestQueue.clear(); sRequestQueue.clear();
sHandler = null; sHandler = null;
} }
} }
} }
/** Clears the UID cache. */
public static void clearUidCache() { public static void clearUidCache() {
sUidCache.clear(); sUidCache.clear();
} }
@@ -354,7 +357,7 @@ public class BatteryEntry {
final PackageManager pm = context.getPackageManager(); final PackageManager pm = context.getPackageManager();
final String[] packages = isSystemUid(uid) final String[] packages = isSystemUid(uid)
? new String[] {PACKAGE_SYSTEM} : pm.getPackagesForUid(uid); ? new String[]{PACKAGE_SYSTEM} : pm.getPackagesForUid(uid);
if (packages != null) { if (packages != null) {
final String[] packageLabels = new String[packages.length]; final String[] packageLabels = new String[packages.length];
System.arraycopy(packages, 0, packageLabels, 0, packages.length); System.arraycopy(packages, 0, packageLabels, 0, packages.length);
@@ -552,8 +555,8 @@ public class BatteryEntry {
name = context.getResources().getString(R.string.process_network_tethering); name = context.getResources().getString(R.string.process_network_tethering);
} else if ("mediaserver".equals(name)) { } else if ("mediaserver".equals(name)) {
name = context.getResources().getString(R.string.process_mediaserver_label); name = context.getResources().getString(R.string.process_mediaserver_label);
} else if ("dex2oat".equals(name) || "dex2oat32".equals(name) || } else if ("dex2oat".equals(name) || "dex2oat32".equals(name)
"dex2oat64".equals(name)) { || "dex2oat64".equals(name)) {
name = context.getResources().getString(R.string.process_dex2oat_label); name = context.getResources().getString(R.string.process_dex2oat_label);
} }
return new NameAndIcon(name, icon, 0 /* iconId */); return new NameAndIcon(name, icon, 0 /* iconId */);
@@ -612,7 +615,8 @@ public class BatteryEntry {
return new NameAndIcon(name, null /* icon */, iconId); return new NameAndIcon(name, null /* icon */, iconId);
} }
static boolean isSystemUid(int uid) { /** Whether the uid is system uid. */
public static boolean isSystemUid(int uid) {
return uid == Process.SYSTEM_UID; return uid == Process.SYSTEM_UID;
} }
} }

View File

@@ -1,17 +1,19 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * Licensed under the Apache License, Version 2.0 (the "License");
* except in compliance with the License. You may obtain a copy of the License at * 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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the * Unless required by applicable law or agreed to in writing, software
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * distributed under the License is distributed on an "AS IS" BASIS,
* KIND, either express or implied. See the License for the specific language governing * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* permissions and limitations under the License. * See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
@@ -207,7 +209,7 @@ public class BatteryHistEntry {
private int getInteger(ContentValues values, String key) { private int getInteger(ContentValues values, String key) {
if (values != null && values.containsKey(key)) { if (values != null && values.containsKey(key)) {
return values.getAsInteger(key); return values.getAsInteger(key);
}; }
mIsValidEntry = false; mIsValidEntry = false;
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.Context; import android.content.Context;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.utils.AsyncLoaderCompat; import com.android.settingslib.utils.AsyncLoaderCompat;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2010 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.Context; import android.content.Context;
import android.os.BatteryUsageStats; import android.os.BatteryUsageStats;
@@ -29,6 +29,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.UsageView; import com.android.settings.widget.UsageView;
@@ -38,8 +40,10 @@ import com.android.settings.widget.UsageView;
public class BatteryHistoryPreference extends Preference { public class BatteryHistoryPreference extends Preference {
private static final String TAG = "BatteryHistoryPreference"; private static final String TAG = "BatteryHistoryPreference";
@VisibleForTesting boolean mHideSummary; @VisibleForTesting
@VisibleForTesting BatteryInfo mBatteryInfo; boolean mHideSummary;
@VisibleForTesting
BatteryInfo mBatteryInfo;
private boolean mIsChartGraphEnabled; private boolean mIsChartGraphEnabled;
@@ -61,6 +65,7 @@ public class BatteryHistoryPreference extends Preference {
setSelectable(false); setSelectable(false);
} }
/** Sets the text of bottom summary. */
public void setBottomSummary(CharSequence text) { public void setBottomSummary(CharSequence text) {
mSummaryContent = text; mSummaryContent = text;
if (mSummaryView != null) { if (mSummaryView != null) {
@@ -70,6 +75,7 @@ public class BatteryHistoryPreference extends Preference {
mHideSummary = false; mHideSummary = false;
} }
/** Hides the bottom summary. */
public void hideBottomSummary() { public void hideBottomSummary() {
if (mSummaryView != null) { if (mSummaryView != null) {
mSummaryView.setVisibility(View.GONE); mSummaryView.setVisibility(View.GONE);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.Context; import android.content.Context;
import android.os.BatteryStatsManager; import android.os.BatteryStatsManager;

View File

@@ -1,17 +1,19 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * Licensed under the Apache License, Version 2.0 (the "License");
* except in compliance with the License. You may obtain a copy of the License at * 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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the * Unless required by applicable law or agreed to in writing, software
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * distributed under the License is distributed on an "AS IS" BASIS,
* KIND, either express or implied. See the License for the specific language governing * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* permissions and limitations under the License. * See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.content.ContentValues; import android.content.ContentValues;
@@ -70,15 +72,18 @@ public final class ConvertUtils {
CONSUMER_TYPE_SYSTEM_BATTERY, CONSUMER_TYPE_SYSTEM_BATTERY,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public static @interface ConsumerType {} public static @interface ConsumerType {
}
public static final int CONSUMER_TYPE_UNKNOWN = 0; public static final int CONSUMER_TYPE_UNKNOWN = 0;
public static final int CONSUMER_TYPE_UID_BATTERY = 1; public static final int CONSUMER_TYPE_UID_BATTERY = 1;
public static final int CONSUMER_TYPE_USER_BATTERY = 2; public static final int CONSUMER_TYPE_USER_BATTERY = 2;
public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3; public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3;
private ConvertUtils() {} private ConvertUtils() {
}
/** Converts to content values */
public static ContentValues convert( public static ContentValues convert(
BatteryEntry entry, BatteryEntry entry,
BatteryUsageStats batteryUsageStats, BatteryUsageStats batteryUsageStats,

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@@ -33,8 +32,10 @@ public class ExpandDividerPreference extends Preference {
@VisibleForTesting @VisibleForTesting
static final String PREFERENCE_KEY = "expandable_divider"; static final String PREFERENCE_KEY = "expandable_divider";
@VisibleForTesting TextView mTextView; @VisibleForTesting
@VisibleForTesting ImageView mImageView; TextView mTextView;
@VisibleForTesting
ImageView mImageView;
private OnExpandListener mOnExpandListener; private OnExpandListener mOnExpandListener;
private boolean mIsExpanded = false; private boolean mIsExpanded = false;
@@ -42,6 +43,7 @@ public class ExpandDividerPreference extends Preference {
/** A callback listener for expand state is changed by users. */ /** A callback listener for expand state is changed by users. */
public interface OnExpandListener { public interface OnExpandListener {
/** Callback function for expand state is changed by users. */
void onExpand(boolean isExpanded); void onExpand(boolean isExpanded);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@@ -67,34 +67,41 @@ public class PowerGaugePreference extends AppPreference {
mShowAnomalyIcon = false; mShowAnomalyIcon = false;
} }
/** Sets the content description. */
public void setContentDescription(String name) { public void setContentDescription(String name) {
mContentDescription = name; mContentDescription = name;
notifyChanged(); notifyChanged();
} }
/** Sets the percent of total. */
public void setPercent(double percentOfTotal) { public void setPercent(double percentOfTotal) {
mProgress = Utils.formatPercentage(percentOfTotal, true); mProgress = Utils.formatPercentage(percentOfTotal, true);
notifyChanged(); notifyChanged();
} }
/** Gets the percent of total. */
public String getPercent() { public String getPercent() {
return mProgress.toString(); return mProgress.toString();
} }
/** Sets the subtitle. */
public void setSubtitle(CharSequence subtitle) { public void setSubtitle(CharSequence subtitle) {
mProgress = subtitle; mProgress = subtitle;
notifyChanged(); notifyChanged();
} }
/** Gets the subtitle. */
public CharSequence getSubtitle() { public CharSequence getSubtitle() {
return mProgress; return mProgress;
} }
/** Sets whether to show anomaly icon */
public void shouldShowAnomalyIcon(boolean showAnomalyIcon) { public void shouldShowAnomalyIcon(boolean showAnomalyIcon) {
mShowAnomalyIcon = showAnomalyIcon; mShowAnomalyIcon = showAnomalyIcon;
notifyChanged(); notifyChanged();
} }
/** Gets whether to show anomaly icon */
public boolean showAnomalyIcon() { public boolean showAnomalyIcon() {
return mShowAnomalyIcon; return mShowAnomalyIcon;
} }

View File

@@ -1,17 +1,19 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * Licensed under the Apache License, Version 2.0 (the "License");
* except in compliance with the License. You may obtain a copy of the License at * 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 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the * Unless required by applicable law or agreed to in writing, software
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * distributed under the License is distributed on an "AS IS" BASIS,
* KIND, either express or implied. See the License for the specific language governing * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* permissions and limitations under the License. * See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType; import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
@@ -35,6 +37,7 @@ import androidx.loader.content.Loader;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver; import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
@@ -45,6 +48,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/** Advanced power usage. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class PowerUsageAdvanced extends PowerUsageBase { public class PowerUsageAdvanced extends PowerUsageBase {
private static final String TAG = "AdvancedBatteryUsage"; private static final String TAG = "AdvancedBatteryUsage";

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType; import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
@@ -23,7 +23,6 @@ import android.os.BatteryUsageStats;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserManager; import android.os.UserManager;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -31,6 +30,8 @@ import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader; import androidx.loader.content.Loader;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
import com.android.settings.fuelgauge.BatteryUtils;
/** /**
* Common base class for things that need to show the battery usage graph. * Common base class for things that need to show the battery usage graph.
@@ -99,6 +100,7 @@ public abstract class PowerUsageBase extends DashboardFragment {
} }
protected abstract void refreshUi(@BatteryUpdateType int refreshType); protected abstract void refreshUi(@BatteryUpdateType int refreshType);
protected abstract boolean isBatteryHistoryNeeded(); protected abstract boolean isBatteryHistoryNeeded();
protected void updatePreference(BatteryHistoryPreference historyPref) { protected void updatePreference(BatteryHistoryPreference historyPref) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType; import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
@@ -34,6 +34,11 @@ import androidx.preference.Preference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.fuelgauge.BatteryHeaderPreferenceController;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryInfoLoader;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
@@ -255,9 +260,9 @@ public class PowerUsageSummary extends PowerUsageBase implements
void initPreference() { void initPreference() {
mBatteryUsagePreference = findPreference(KEY_BATTERY_USAGE); mBatteryUsagePreference = findPreference(KEY_BATTERY_USAGE);
mBatteryUsagePreference.setSummary( mBatteryUsagePreference.setSummary(
mPowerFeatureProvider.isChartGraphEnabled(getContext()) ? mPowerFeatureProvider.isChartGraphEnabled(getContext())
getString(R.string.advanced_battery_preference_summary_with_hours) : ? getString(R.string.advanced_battery_preference_summary_with_hours)
getString(R.string.advanced_battery_preference_summary)); : getString(R.string.advanced_battery_preference_summary));
mHelpPreference = findPreference(KEY_BATTERY_ERROR); mHelpPreference = findPreference(KEY_BATTERY_ERROR);
mHelpPreference.setVisible(false); mHelpPreference.setVisible(false);

View File

@@ -44,11 +44,11 @@ import androidx.slice.builders.SliceAction;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SubSettings; import com.android.settings.SubSettings;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.slices.CustomSliceable; import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBackgroundWorker; import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBuilderUtils; import com.android.settings.slices.SliceBuilderUtils;

View File

@@ -21,8 +21,8 @@ import android.util.ArrayMap;
import com.android.settings.backup.UserBackupSettingsActivity; import com.android.settings.backup.UserBackupSettingsActivity;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment; import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment; import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
import com.android.settings.fuelgauge.PowerUsageAdvanced; import com.android.settings.fuelgauge.batteryusage.PowerUsageAdvanced;
import com.android.settings.fuelgauge.PowerUsageSummary; import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.GestureNavigationSettingsFragment; import com.android.settings.gestures.GestureNavigationSettingsFragment;
import com.android.settings.gestures.SystemNavigationGestureSettings; import com.android.settings.gestures.SystemNavigationGestureSettings;
import com.android.settings.location.LocationSettings; import com.android.settings.location.LocationSettings;

View File

@@ -40,8 +40,8 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.BatteryDiffEntry;
import com.android.settings.fuelgauge.BatteryUtils; import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before; import org.junit.Before;

View File

@@ -45,7 +45,6 @@ import android.os.BatteryStats;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Pair;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager; import androidx.loader.app.LoaderManager;
@@ -54,6 +53,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowActivityManager; import com.android.settings.testutils.shadow.ShadowActivityManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController; import com.android.settings.testutils.shadow.ShadowEntityHeaderController;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +35,7 @@ import androidx.preference.PreferenceGroup;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
@@ -81,9 +82,9 @@ public class BatteryAppListPreferenceControllerTest {
when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getApplicationContext()).thenReturn(mContext); when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {}); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
when(mFeatureFactory.powerUsageFeatureProvider.getHideApplicationSummary(mContext)) when(mFeatureFactory.powerUsageFeatureProvider.getHideApplicationSummary(mContext))
.thenReturn(new String[] {"com.android.googlequicksearchbox"}); .thenReturn(new String[]{"com.android.googlequicksearchbox"});
mPreference = new PowerGaugePreference(mContext); mPreference = new PowerGaugePreference(mContext);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,22 +14,20 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
@@ -37,15 +35,14 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.LocaleList; import android.os.LocaleList;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.Pair;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceGroup;
import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -58,11 +55,10 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.List;
import java.util.Map; import java.util.Map;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@@ -72,18 +68,22 @@ public final class BatteryChartPreferenceControllerTest {
private static final int DESIRED_HISTORY_SIZE = private static final int DESIRED_HISTORY_SIZE =
BatteryChartPreferenceController.DESIRED_HISTORY_SIZE; BatteryChartPreferenceController.DESIRED_HISTORY_SIZE;
@Mock private InstrumentedPreferenceFragment mFragment; @Mock
@Mock private SettingsActivity mSettingsActivity; private InstrumentedPreferenceFragment mFragment;
@Mock private PreferenceGroup mAppListGroup; @Mock
@Mock private PackageManager mPackageManager; private SettingsActivity mSettingsActivity;
@Mock private Drawable mDrawable; @Mock
@Mock private BatteryHistEntry mBatteryHistEntry; private PreferenceGroup mAppListGroup;
@Mock private BatteryChartView mBatteryChartView; @Mock
@Mock private PowerGaugePreference mPowerGaugePreference; private Drawable mDrawable;
@Mock private ExpandDividerPreference mExpandDividerPreference; @Mock
@Mock private BatteryUtils mBatteryUtils; private BatteryHistEntry mBatteryHistEntry;
@Mock private Configuration mConfiguration; @Mock
@Mock private Resources mResources; private BatteryChartView mBatteryChartView;
@Mock
private PowerGaugePreference mPowerGaugePreference;
@Mock
private BatteryUtils mBatteryUtils;
private Context mContext; private Context mContext;
private FakeFeatureFactory mFeatureFactory; private FakeFeatureFactory mFeatureFactory;
@@ -102,10 +102,10 @@ public final class BatteryChartPreferenceControllerTest {
final Resources resources = spy(mContext.getResources()); final Resources resources = spy(mContext.getResources());
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US"))); resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
doReturn(resources).when(mContext).getResources(); doReturn(resources).when(mContext).getResources();
doReturn(new String[] {"com.android.googlequicksearchbox"}) doReturn(new String[]{"com.android.googlequicksearchbox"})
.when(mFeatureFactory.powerUsageFeatureProvider) .when(mFeatureFactory.powerUsageFeatureProvider)
.getHideApplicationSummary(mContext); .getHideApplicationSummary(mContext);
doReturn(new String[] {"com.android.gms.persistent"}) doReturn(new String[]{"com.android.gms.persistent"})
.when(mFeatureFactory.powerUsageFeatureProvider) .when(mFeatureFactory.powerUsageFeatureProvider)
.getHideApplicationEntries(mContext); .getHideApplicationEntries(mContext);
mBatteryChartPreferenceController = createController(); mBatteryChartPreferenceController = createController();
@@ -611,7 +611,7 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController = createController(); mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mBatteryChartView = mBatteryChartPreferenceController.mBatteryChartView =
spy(new BatteryChartView(mContext)); spy(new BatteryChartView(mContext));
mBatteryChartPreferenceController.mBatteryHistoryKeys = new long[] {0L}; mBatteryChartPreferenceController.mBatteryHistoryKeys = new long[]{0L};
mBatteryChartPreferenceController.setTimestampLabel(); mBatteryChartPreferenceController.setTimestampLabel();
@@ -686,7 +686,7 @@ public final class BatteryChartPreferenceControllerTest {
private void setUpBatteryHistoryKeys() { private void setUpBatteryHistoryKeys() {
mBatteryChartPreferenceController.mBatteryHistoryKeys = mBatteryChartPreferenceController.mBatteryHistoryKeys =
new long[] {1619196786769L, 0L, 1619247636826L}; new long[]{1619196786769L, 0L, 1619247636826L};
ConvertUtils.utcToLocalTimeHour( ConvertUtils.utcToLocalTimeHour(
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false); mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
} }

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@@ -11,14 +12,11 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -30,6 +28,7 @@ import android.content.Context;
import android.os.LocaleList; import android.os.LocaleList;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
@@ -40,8 +39,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@@ -52,8 +51,10 @@ public final class BatteryChartViewTest {
private FakeFeatureFactory mFeatureFactory; private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider; private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@Mock private AccessibilityServiceInfo mockAccessibilityServiceInfo; @Mock
@Mock private AccessibilityManager mockAccessibilityManager; private AccessibilityServiceInfo mMockAccessibilityServiceInfo;
@Mock
private AccessibilityManager mMockAccessibilityManager;
@Before @Before
public void setUp() { public void setUp() {
@@ -64,25 +65,25 @@ public final class BatteryChartViewTest {
mContext.getResources().getConfiguration().setLocales( mContext.getResources().getConfiguration().setLocales(
new LocaleList(new Locale("en_US"))); new LocaleList(new Locale("en_US")));
mBatteryChartView = new BatteryChartView(mContext); mBatteryChartView = new BatteryChartView(mContext);
doReturn(mockAccessibilityManager).when(mContext) doReturn(mMockAccessibilityManager).when(mContext)
.getSystemService(AccessibilityManager.class); .getSystemService(AccessibilityManager.class);
doReturn("TalkBackService").when(mockAccessibilityServiceInfo).getId(); doReturn("TalkBackService").when(mMockAccessibilityServiceInfo).getId();
doReturn(Arrays.asList(mockAccessibilityServiceInfo)) doReturn(Arrays.asList(mMockAccessibilityServiceInfo))
.when(mockAccessibilityManager) .when(mMockAccessibilityManager)
.getEnabledAccessibilityServiceList(anyInt()); .getEnabledAccessibilityServiceList(anyInt());
} }
@Test @Test
public void testIsAccessibilityEnabled_disable_returnFalse() { public void testIsAccessibilityEnabled_disable_returnFalse() {
doReturn(false).when(mockAccessibilityManager).isEnabled(); doReturn(false).when(mMockAccessibilityManager).isEnabled();
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse(); assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse();
} }
@Test @Test
public void testIsAccessibilityEnabled_emptyInfo_returnFalse() { public void testIsAccessibilityEnabled_emptyInfo_returnFalse() {
doReturn(true).when(mockAccessibilityManager).isEnabled(); doReturn(true).when(mMockAccessibilityManager).isEnabled();
doReturn(new ArrayList<AccessibilityServiceInfo>()) doReturn(new ArrayList<AccessibilityServiceInfo>())
.when(mockAccessibilityManager) .when(mMockAccessibilityManager)
.getEnabledAccessibilityServiceList(anyInt()); .getEnabledAccessibilityServiceList(anyInt());
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse(); assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse();
@@ -90,13 +91,13 @@ public final class BatteryChartViewTest {
@Test @Test
public void testIsAccessibilityEnabled_validServiceId_returnTrue() { public void testIsAccessibilityEnabled_validServiceId_returnTrue() {
doReturn(true).when(mockAccessibilityManager).isEnabled(); doReturn(true).when(mMockAccessibilityManager).isEnabled();
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isTrue(); assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isTrue();
} }
@Test @Test
public void testSetSelectedIndex_invokesCallback() { public void testSetSelectedIndex_invokesCallback() {
final int selectedIndex[] = new int[1]; final int[] selectedIndex = new int[1];
final int expectedIndex = 2; final int expectedIndex = 2;
mBatteryChartView.mSelectedIndex = 1; mBatteryChartView.mSelectedIndex = 1;
mBatteryChartView.setOnSelectListener( mBatteryChartView.setOnSelectListener(
@@ -113,7 +114,7 @@ public final class BatteryChartViewTest {
@Test @Test
public void testSetSelectedIndex_sameIndex_notInvokesCallback() { public void testSetSelectedIndex_sameIndex_notInvokesCallback() {
final int selectedIndex[] = new int[1]; final int[] selectedIndex = new int[1];
final int expectedIndex = 1; final int expectedIndex = 1;
mBatteryChartView.mSelectedIndex = expectedIndex; mBatteryChartView.mSelectedIndex = expectedIndex;
mBatteryChartView.setOnSelectListener( mBatteryChartView.setOnSelectListener(
@@ -142,7 +143,7 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true); mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext)) when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true); .thenReturn(true);
doReturn(false).when(mockAccessibilityManager).isEnabled(); doReturn(false).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow(); mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isTrue(); assertThat(mBatteryChartView.isClickable()).isTrue();
@@ -154,9 +155,9 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true); mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext)) when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true); .thenReturn(true);
doReturn(true).when(mockAccessibilityManager).isEnabled(); doReturn(true).when(mMockAccessibilityManager).isEnabled();
doReturn(new ArrayList<AccessibilityServiceInfo>()) doReturn(new ArrayList<AccessibilityServiceInfo>())
.when(mockAccessibilityManager) .when(mMockAccessibilityManager)
.getEnabledAccessibilityServiceList(anyInt()); .getEnabledAccessibilityServiceList(anyInt());
mBatteryChartView.onAttachedToWindow(); mBatteryChartView.onAttachedToWindow();
@@ -169,7 +170,7 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true); mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext)) when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true); .thenReturn(true);
doReturn(true).when(mockAccessibilityManager).isEnabled(); doReturn(true).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow(); mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isFalse(); assertThat(mBatteryChartView.isClickable()).isFalse();
@@ -187,12 +188,12 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true); mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext)) when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true); .thenReturn(true);
doReturn(true).when(mockAccessibilityManager).isEnabled(); doReturn(true).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow(); mBatteryChartView.onAttachedToWindow();
// Ensures the testing environment is correct. // Ensures the testing environment is correct.
assertThat(mBatteryChartView.isClickable()).isFalse(); assertThat(mBatteryChartView.isClickable()).isFalse();
// Turns off accessibility service. // Turns off accessibility service.
doReturn(false).when(mockAccessibilityManager).isEnabled(); doReturn(false).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow(); mBatteryChartView.onAttachedToWindow();
@@ -202,7 +203,7 @@ public final class BatteryChartViewTest {
@Test @Test
public void testOnAttachedToWindow_addAccessibilityStateChangeListener() { public void testOnAttachedToWindow_addAccessibilityStateChangeListener() {
mBatteryChartView.onAttachedToWindow(); mBatteryChartView.onAttachedToWindow();
verify(mockAccessibilityManager) verify(mMockAccessibilityManager)
.addAccessibilityStateChangeListener(mBatteryChartView); .addAccessibilityStateChangeListener(mBatteryChartView);
} }
@@ -214,7 +215,7 @@ public final class BatteryChartViewTest {
mBatteryChartView.onDetachedFromWindow(); mBatteryChartView.onDetachedFromWindow();
verify(mockAccessibilityManager) verify(mMockAccessibilityManager)
.removeAccessibilityStateChangeListener(mBatteryChartView); .removeAccessibilityStateChangeListener(mBatteryChartView);
assertThat(mBatteryChartView.mHandler.hasCallbacks( assertThat(mBatteryChartView.mHandler.hasCallbacks(
mBatteryChartView.mUpdateClickableStateRun)) mBatteryChartView.mUpdateClickableStateRun))

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +35,7 @@ import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -59,15 +60,24 @@ public final class BatteryDiffEntryTest {
private Context mContext; private Context mContext;
@Mock private ApplicationInfo mockAppInfo; @Mock
@Mock private PackageManager mockPackageManager; private ApplicationInfo mMockAppInfo;
@Mock private UserManager mockUserManager; @Mock
@Mock private Drawable mockDrawable; private PackageManager mMockPackageManager;
@Mock private Drawable mockDrawable2; @Mock
@Mock private Drawable mockBadgedDrawable; private UserManager mMockUserManager;
@Mock private BatteryHistEntry mBatteryHistEntry; @Mock
@Mock private PackageInfo mockPackageInfo; private Drawable mMockDrawable;
@Mock private ConstantState mockConstantState; @Mock
private Drawable mMockDrawable2;
@Mock
private Drawable mMockBadgedDrawable;
@Mock
private BatteryHistEntry mBatteryHistEntry;
@Mock
private PackageInfo mMockPackageInfo;
@Mock
private ConstantState mMockConstantState;
@Before @Before
public void setUp() { public void setUp() {
@@ -75,8 +85,8 @@ public final class BatteryDiffEntryTest {
ShadowUserHandle.reset(); ShadowUserHandle.reset();
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
doReturn(mContext).when(mContext).getApplicationContext(); doReturn(mContext).when(mContext).getApplicationContext();
doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class); doReturn(mMockUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(mockPackageManager).when(mContext).getPackageManager(); doReturn(mMockPackageManager).when(mContext).getPackageManager();
BatteryDiffEntry.clearCache(); BatteryDiffEntry.clearCache();
} }
@@ -150,7 +160,7 @@ public final class BatteryDiffEntryTest {
@Test @Test
public void testLoadLabelAndIcon_forUserBattery_returnExpectedResult() { public void testLoadLabelAndIcon_forUserBattery_returnExpectedResult() {
final String expectedName = "Removed user"; final String expectedName = "Removed user";
doReturn(null).when(mockUserManager).getUserInfo(1001); doReturn(null).when(mMockUserManager).getUserInfo(1001);
// Generates fake testing data. // Generates fake testing data.
final ContentValues values = getContentValuesWithType( final ContentValues values = getContentValuesWithType(
ConvertUtils.CONSUMER_TYPE_USER_BATTERY); ConvertUtils.CONSUMER_TYPE_USER_BATTERY);
@@ -181,10 +191,10 @@ public final class BatteryDiffEntryTest {
ConvertUtils.CONSUMER_TYPE_UID_BATTERY); ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("uid", /*invalid uid*/ 10001); values.put("uid", /*invalid uid*/ 10001);
values.put("packageName", fakePackageName); values.put("packageName", fakePackageName);
doReturn(mockAppInfo).when(mockPackageManager) doReturn(mMockAppInfo).when(mMockPackageManager)
.getApplicationInfo(fakePackageName, 0); .getApplicationInfo(fakePackageName, 0);
doReturn(expectedAppLabel).when(mockPackageManager) doReturn(expectedAppLabel).when(mMockPackageManager)
.getApplicationLabel(mockAppInfo); .getApplicationLabel(mMockAppInfo);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values); final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry); final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
@@ -238,13 +248,13 @@ public final class BatteryDiffEntryTest {
final ContentValues values = getContentValuesWithType( final ContentValues values = getContentValuesWithType(
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY); ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values); final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
mockConstantState(mockDrawable); mockConstantState(mMockDrawable);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry); final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
entry.mIsLoaded = true; entry.mIsLoaded = true;
entry.mAppIcon = mockDrawable; entry.mAppIcon = mMockDrawable;
assertThat(entry.getAppIcon()).isEqualTo(mockDrawable); assertThat(entry.getAppIcon()).isEqualTo(mMockDrawable);
assertThat(BatteryDiffEntry.sResourceCache).isEmpty(); assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
} }
@@ -252,29 +262,29 @@ public final class BatteryDiffEntryTest {
public void testGetAppIcon_uidConsumerForNonOwner_returnDefaultActivityIconWithBadge() public void testGetAppIcon_uidConsumerForNonOwner_returnDefaultActivityIconWithBadge()
throws Exception { throws Exception {
ShadowUserHandle.setUid(10); ShadowUserHandle.setUid(10);
final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable); final BatteryDiffEntry entry = createBatteryDiffEntry(mMockDrawable);
mockConstantState(mockDrawable); mockConstantState(mMockDrawable);
mockConstantState(mockBadgedDrawable); mockConstantState(mMockBadgedDrawable);
doReturn(mockBadgedDrawable).when(mockUserManager) doReturn(mMockBadgedDrawable).when(mMockUserManager)
.getBadgedIconForUser(eq(mockDrawable), any()); .getBadgedIconForUser(eq(mMockDrawable), any());
entry.mAppIcon = null; entry.mAppIcon = null;
assertThat(entry.getAppIcon()).isEqualTo(mockBadgedDrawable); assertThat(entry.getAppIcon()).isEqualTo(mMockBadgedDrawable);
} }
@Test @Test
public void testGetAppIcon_uidConsumerWithNullIcon_returnDefaultActivityIcon() public void testGetAppIcon_uidConsumerWithNullIcon_returnDefaultActivityIcon()
throws Exception { throws Exception {
final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable); final BatteryDiffEntry entry = createBatteryDiffEntry(mMockDrawable);
mockConstantState(mockDrawable); mockConstantState(mMockDrawable);
entry.mAppIcon = null; entry.mAppIcon = null;
assertThat(entry.getAppIcon()).isEqualTo(mockDrawable); assertThat(entry.getAppIcon()).isEqualTo(mMockDrawable);
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1); assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache. // Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon = final BatteryEntry.NameAndIcon nameAndIcon =
BatteryDiffEntry.sResourceCache.get(entry.getKey()); BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.mIcon).isEqualTo(mockDrawable); assertThat(nameAndIcon.mIcon).isEqualTo(mMockDrawable);
} }
@Test @Test
@@ -295,21 +305,21 @@ public final class BatteryDiffEntryTest {
public void testClearCache_switchLocale_clearCacheIconAndLabel() throws Exception { public void testClearCache_switchLocale_clearCacheIconAndLabel() throws Exception {
final int userId = UserHandle.getUserId(1001); final int userId = UserHandle.getUserId(1001);
Locale.setDefault(new Locale("en_US")); Locale.setDefault(new Locale("en_US"));
final BatteryDiffEntry entry1 = createBatteryDiffEntry(mockDrawable); final BatteryDiffEntry entry1 = createBatteryDiffEntry(mMockDrawable);
mockConstantState(mockDrawable); mockConstantState(mMockDrawable);
assertThat(entry1.getAppIcon()).isEqualTo(mockDrawable); assertThat(entry1.getAppIcon()).isEqualTo(mMockDrawable);
// Switch the locale into another one. // Switch the locale into another one.
Locale.setDefault(new Locale("zh_TW")); Locale.setDefault(new Locale("zh_TW"));
final BatteryDiffEntry entry2 = createBatteryDiffEntry(mockDrawable2); final BatteryDiffEntry entry2 = createBatteryDiffEntry(mMockDrawable2);
// We should get new drawable without caching. // We should get new drawable without caching.
mockConstantState(mockDrawable2); mockConstantState(mMockDrawable2);
assertThat(entry2.getAppIcon()).isEqualTo(mockDrawable2); assertThat(entry2.getAppIcon()).isEqualTo(mMockDrawable2);
// Verifies the cache is updated into the new drawable. // Verifies the cache is updated into the new drawable.
final BatteryEntry.NameAndIcon nameAndIcon = final BatteryEntry.NameAndIcon nameAndIcon =
BatteryDiffEntry.sResourceCache.get(entry2.getKey()); BatteryDiffEntry.sResourceCache.get(entry2.getKey());
assertThat(nameAndIcon.mIcon).isEqualTo(mockDrawable2); assertThat(nameAndIcon.mIcon).isEqualTo(mMockDrawable2);
} }
@Test @Test
@@ -390,19 +400,19 @@ public final class BatteryDiffEntryTest {
// Sets false if the app entry cannot be found. // Sets false if the app entry cannot be found.
assertThat(entry.mValidForRestriction).isFalse(); assertThat(entry.mValidForRestriction).isFalse();
doReturn(BatteryUtils.UID_NULL).when(mockPackageManager).getPackageUid( doReturn(BatteryUtils.UID_NULL).when(mMockPackageManager).getPackageUid(
entry.getPackageName(), PackageManager.GET_META_DATA); entry.getPackageName(), PackageManager.GET_META_DATA);
entry.updateRestrictionFlagState(); entry.updateRestrictionFlagState();
// Sets false if the app is invalid package name. // Sets false if the app is invalid package name.
assertThat(entry.mValidForRestriction).isFalse(); assertThat(entry.mValidForRestriction).isFalse();
doReturn(1000).when(mockPackageManager).getPackageUid( doReturn(1000).when(mMockPackageManager).getPackageUid(
entry.getPackageName(), PackageManager.GET_META_DATA); entry.getPackageName(), PackageManager.GET_META_DATA);
entry.updateRestrictionFlagState(); entry.updateRestrictionFlagState();
// Sets false if the app PackageInfo cannot be found. // Sets false if the app PackageInfo cannot be found.
assertThat(entry.mValidForRestriction).isFalse(); assertThat(entry.mValidForRestriction).isFalse();
doReturn(mockPackageInfo).when(mockPackageManager).getPackageInfo( doReturn(mMockPackageInfo).when(mMockPackageManager).getPackageInfo(
eq(entry.getPackageName()), anyInt()); eq(entry.getPackageName()), anyInt());
entry.updateRestrictionFlagState(); entry.updateRestrictionFlagState();
// Sets true if package is valid and PackageInfo can be found. // Sets true if package is valid and PackageInfo can be found.
@@ -472,16 +482,16 @@ public final class BatteryDiffEntryTest {
values.put("uid", 1001); values.put("uid", 1001);
values.put("packageName", "com.a.b.c"); values.put("packageName", "com.a.b.c");
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values); final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
doReturn(drawable).when(mockPackageManager).getDefaultActivityIcon(); doReturn(drawable).when(mMockPackageManager).getDefaultActivityIcon();
doReturn(null).when(mockPackageManager).getApplicationInfo("com.a.b.c", 0); doReturn(null).when(mMockPackageManager).getApplicationInfo("com.a.b.c", 0);
doReturn(new String[] {"com.a.b.c"}).when(mockPackageManager) doReturn(new String[]{"com.a.b.c"}).when(mMockPackageManager)
.getPackagesForUid(1001); .getPackagesForUid(1001);
return createBatteryDiffEntry(10, batteryHistEntry); return createBatteryDiffEntry(10, batteryHistEntry);
} }
private void mockConstantState(Drawable drawable) { private void mockConstantState(Drawable drawable) {
doReturn(mockConstantState).when(drawable).getConstantState(); doReturn(mMockConstantState).when(drawable).getConstantState();
doReturn(drawable).when(mockConstantState).newDrawable(); doReturn(drawable).when(mMockConstantState).newDrawable();
} }
@Implements(UserHandle.class) @Implements(UserHandle.class)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -37,7 +37,8 @@ import android.os.UserBatteryConsumer;
import android.os.UserManager; import android.os.UserManager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryEntry.NameAndIcon; import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry.NameAndIcon;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@@ -62,31 +63,36 @@ public class BatteryEntryTest {
private static final String HIGH_DRAIN_PACKAGE = "com.android.test.screen"; private static final String HIGH_DRAIN_PACKAGE = "com.android.test.screen";
private static final String ANDROID_PACKAGE = "android"; private static final String ANDROID_PACKAGE = "android";
@Rule public MockitoRule mocks = MockitoJUnit.rule(); @Rule
public MockitoRule mocks = MockitoJUnit.rule();
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mMockContext; private Context mMockContext;
private Context mContext; private Context mContext;
@Mock private Handler mockHandler; @Mock
@Mock private PackageManager mockPackageManager; private Handler mMockHandler;
@Mock private UserManager mockUserManager; @Mock
@Mock private UidBatteryConsumer mUidBatteryConsumer; private PackageManager mMockPackageManager;
@Mock
private UserManager mMockUserManager;
@Mock
private UidBatteryConsumer mUidBatteryConsumer;
@Before @Before
public void stubContextToReturnMockPackageManager() { public void stubContextToReturnMockPackageManager() {
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
when(mMockContext.getPackageManager()).thenReturn(mockPackageManager); when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
} }
@Before @Before
public void stubPackageManagerToReturnAppPackageAndName() throws NameNotFoundException { public void stubPackageManagerToReturnAppPackageAndName() throws NameNotFoundException {
when(mockPackageManager.getApplicationInfo(anyString(), eq(0) /* no flags */)) when(mMockPackageManager.getApplicationInfo(anyString(), eq(0) /* no flags */))
.thenAnswer(invocation -> { .thenAnswer(invocation -> {
ApplicationInfo info = new ApplicationInfo(); ApplicationInfo info = new ApplicationInfo();
info.packageName = invocation.getArgument(0); info.packageName = invocation.getArgument(0);
return info; return info;
}); });
when(mockPackageManager.getApplicationLabel(any(ApplicationInfo.class))) when(mMockPackageManager.getApplicationLabel(any(ApplicationInfo.class)))
.thenAnswer(invocation -> LABEL_PREFIX .thenAnswer(invocation -> LABEL_PREFIX
+ ((ApplicationInfo) invocation.getArgument(0)).packageName); + ((ApplicationInfo) invocation.getArgument(0)).packageName);
} }
@@ -96,7 +102,7 @@ public class BatteryEntryTest {
UidBatteryConsumer consumer = mock(UidBatteryConsumer.class); UidBatteryConsumer consumer = mock(UidBatteryConsumer.class);
when(consumer.getUid()).thenReturn(APP_UID); when(consumer.getUid()).thenReturn(APP_UID);
when(consumer.getPackageWithHighestDrain()).thenReturn(highDrainPackage); when(consumer.getPackageWithHighestDrain()).thenReturn(highDrainPackage);
return new BatteryEntry(mMockContext, mockHandler, mockUserManager, return new BatteryEntry(mMockContext, mMockHandler, mMockUserManager,
consumer, false, APP_UID, packages, packageName); consumer, false, APP_UID, packages, packageName);
} }
@@ -111,7 +117,7 @@ public class BatteryEntryTest {
private BatteryEntry createUserBatteryConsumer(int userId) { private BatteryEntry createUserBatteryConsumer(int userId) {
UserBatteryConsumer consumer = mock(UserBatteryConsumer.class); UserBatteryConsumer consumer = mock(UserBatteryConsumer.class);
when(consumer.getUserId()).thenReturn(userId); when(consumer.getUserId()).thenReturn(userId);
return new BatteryEntry(mMockContext, mockHandler, mockUserManager, return new BatteryEntry(mMockContext, mMockHandler, mMockUserManager,
consumer, false, 0, null, null); consumer, false, 0, null, null);
} }
@@ -127,7 +133,7 @@ public class BatteryEntryTest {
@Test @Test
public void batteryEntryForApp_shouldSetLabelAsPackageName_whenPackageCannotBeFound() public void batteryEntryForApp_shouldSetLabelAsPackageName_whenPackageCannotBeFound()
throws Exception { throws Exception {
when(mockPackageManager.getApplicationInfo(APP_DEFAULT_PACKAGE_NAME, 0 /* no flags */)) when(mMockPackageManager.getApplicationInfo(APP_DEFAULT_PACKAGE_NAME, 0 /* no flags */))
.thenThrow(new NameNotFoundException()); .thenThrow(new NameNotFoundException());
BatteryEntry entry = createBatteryEntryForApp(null, APP_DEFAULT_PACKAGE_NAME, null); BatteryEntry entry = createBatteryEntryForApp(null, APP_DEFAULT_PACKAGE_NAME, null);
@@ -137,7 +143,7 @@ public class BatteryEntryTest {
@Test @Test
public void batteryEntryForApp_shouldSetHighestDrainPackage_whenPackagesCannotBeFoundForUid() { public void batteryEntryForApp_shouldSetHighestDrainPackage_whenPackagesCannotBeFoundForUid() {
when(mockPackageManager.getPackagesForUid(APP_UID)).thenReturn(null); when(mMockPackageManager.getPackagesForUid(APP_UID)).thenReturn(null);
BatteryEntry entry = createBatteryEntryForApp(null, null, HIGH_DRAIN_PACKAGE); BatteryEntry entry = createBatteryEntryForApp(null, null, HIGH_DRAIN_PACKAGE);
@@ -147,7 +153,7 @@ public class BatteryEntryTest {
@Test @Test
public void batteryEntryForApp_shouldSetHighestDrainPackage_whenMultiplePackagesFoundForUid() { public void batteryEntryForApp_shouldSetHighestDrainPackage_whenMultiplePackagesFoundForUid() {
BatteryEntry entry = createBatteryEntryForApp( BatteryEntry entry = createBatteryEntryForApp(
new String[] {APP_DEFAULT_PACKAGE_NAME, "package2", "package3"}, null, new String[]{APP_DEFAULT_PACKAGE_NAME, "package2", "package3"}, null,
HIGH_DRAIN_PACKAGE); HIGH_DRAIN_PACKAGE);
assertThat(entry.getLabel()).isEqualTo(LABEL_PREFIX + HIGH_DRAIN_PACKAGE); assertThat(entry.getLabel()).isEqualTo(LABEL_PREFIX + HIGH_DRAIN_PACKAGE);
@@ -176,8 +182,8 @@ public class BatteryEntryTest {
when(mUidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND)) when(mUidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND))
.thenReturn(100L); .thenReturn(100L);
final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mockHandler, final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mMockHandler,
mockUserManager, mUidBatteryConsumer, false, 0, null, null); mMockUserManager, mUidBatteryConsumer, false, 0, null, null);
assertThat(entry.getTimeInForegroundMs()).isEqualTo(100L); assertThat(entry.getTimeInForegroundMs()).isEqualTo(100L);
} }
@@ -195,8 +201,8 @@ public class BatteryEntryTest {
when(mUidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND)) when(mUidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND))
.thenReturn(100L); .thenReturn(100L);
final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mockHandler, final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mMockHandler,
mockUserManager, mUidBatteryConsumer, false, 0, null, null); mMockUserManager, mUidBatteryConsumer, false, 0, null, null);
assertThat(entry.getTimeInBackgroundMs()).isEqualTo(100L); assertThat(entry.getTimeInBackgroundMs()).isEqualTo(100L);
} }
@@ -247,7 +253,7 @@ public class BatteryEntryTest {
@Test @Test
public void getKey_UserBatteryConsumer_returnUserId() { public void getKey_UserBatteryConsumer_returnUserId() {
doReturn(mockUserManager).when(mMockContext).getSystemService(UserManager.class); doReturn(mMockUserManager).when(mMockContext).getSystemService(UserManager.class);
final BatteryEntry entry = createUserBatteryConsumer(2); final BatteryEntry entry = createUserBatteryConsumer(2);
final String key = entry.getKey(); final String key = entry.getKey();
assertThat(key).isEqualTo("U|2"); assertThat(key).isEqualTo("U|2");
@@ -256,8 +262,8 @@ public class BatteryEntryTest {
@Test @Test
public void getNameAndIconFromUserId_nullUserInfo_returnDefaultNameAndIcon() { public void getNameAndIconFromUserId_nullUserInfo_returnDefaultNameAndIcon() {
final int userId = 1001; final int userId = 1001;
doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class); doReturn(mMockUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(null).when(mockUserManager).getUserInfo(userId); doReturn(null).when(mMockUserManager).getUserInfo(userId);
final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUserId( final NameAndIcon nameAndIcon = BatteryEntry.getNameAndIconFromUserId(
mContext, userId); mContext, userId);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -38,7 +38,7 @@ import java.util.TimeZone;
public final class BatteryHistEntryTest { public final class BatteryHistEntryTest {
@Mock @Mock
private BatteryEntry mockBatteryEntry; private BatteryEntry mMockBatteryEntry;
@Mock @Mock
private BatteryUsageStats mBatteryUsageStats; private BatteryUsageStats mBatteryUsageStats;
@@ -50,22 +50,22 @@ public final class BatteryHistEntryTest {
@Test @Test
public void testConstructor_contentValues_returnsExpectedResult() { public void testConstructor_contentValues_returnsExpectedResult() {
final int expectedType = 3; final int expectedType = 3;
when(mockBatteryEntry.getUid()).thenReturn(1001); when(mMockBatteryEntry.getUid()).thenReturn(1001);
when(mockBatteryEntry.getLabel()).thenReturn("Settings"); when(mMockBatteryEntry.getLabel()).thenReturn("Settings");
when(mockBatteryEntry.getDefaultPackageName()) when(mMockBatteryEntry.getDefaultPackageName())
.thenReturn("com.google.android.settings.battery"); .thenReturn("com.google.android.settings.battery");
when(mockBatteryEntry.isHidden()).thenReturn(true); when(mMockBatteryEntry.isHidden()).thenReturn(true);
when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1); when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1);
when(mockBatteryEntry.getConsumedPower()).thenReturn(1.1); when(mMockBatteryEntry.getConsumedPower()).thenReturn(1.1);
mockBatteryEntry.mPercent = 0.3; mMockBatteryEntry.mPercent = 0.3;
when(mockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L); when(mMockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
when(mockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L); when(mMockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
when(mockBatteryEntry.getPowerComponentId()).thenReturn(expectedType); when(mMockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
when(mockBatteryEntry.getConsumerType()) when(mMockBatteryEntry.getConsumerType())
.thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY); .thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final ContentValues values = final ContentValues values =
ConvertUtils.convert( ConvertUtils.convert(
mockBatteryEntry, mMockBatteryEntry,
mBatteryUsageStats, mBatteryUsageStats,
/*batteryLevel=*/ 12, /*batteryLevel=*/ 12,
/*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL, /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
@@ -76,7 +76,7 @@ public final class BatteryHistEntryTest {
assertBatteryHistEntry( assertBatteryHistEntry(
new BatteryHistEntry(values), new BatteryHistEntry(values),
/*drainType=*/ expectedType, /*drainType=*/ expectedType,
/*percentOfTotal=*/ mockBatteryEntry.mPercent); /*percentOfTotal=*/ mMockBatteryEntry.mPercent);
} }
@Test @Test
@@ -305,7 +305,7 @@ public final class BatteryHistEntryTest {
long backgroundUsageTimeInMs, long backgroundUsageTimeInMs,
int batteryLevel) { int batteryLevel) {
final MatrixCursor cursor = new MatrixCursor( final MatrixCursor cursor = new MatrixCursor(
new String[] { new String[]{
BatteryHistEntry.KEY_UID, BatteryHistEntry.KEY_UID,
BatteryHistEntry.KEY_USER_ID, BatteryHistEntry.KEY_USER_ID,
BatteryHistEntry.KEY_APP_LABEL, BatteryHistEntry.KEY_APP_LABEL,
@@ -325,7 +325,7 @@ public final class BatteryHistEntryTest {
BatteryHistEntry.KEY_BATTERY_STATUS, BatteryHistEntry.KEY_BATTERY_STATUS,
BatteryHistEntry.KEY_BATTERY_HEALTH}); BatteryHistEntry.KEY_BATTERY_HEALTH});
cursor.addRow( cursor.addRow(
new Object[] { new Object[]{
Long.valueOf(1001), Long.valueOf(1001),
Long.valueOf(UserHandle.getUserId(1001)), Long.valueOf(UserHandle.getUserId(1001)),
"Settings", "Settings",

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,18 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import android.content.Context; import android.content.Context;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -32,6 +30,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import java.util.HashMap;
import java.util.Map;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public final class BatteryHistoryLoaderTest { public final class BatteryHistoryLoaderTest {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -31,6 +31,7 @@ import android.widget.TextView;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.widget.UsageView; import com.android.settings.widget.UsageView;
import org.junit.Before; import org.junit.Before;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -27,6 +27,7 @@ import android.os.BatteryUsageStats;
import android.os.LocaleList; import android.os.LocaleList;
import android.os.UserHandle; import android.os.UserHandle;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
@@ -37,7 +38,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -54,7 +54,7 @@ public final class ConvertUtilsTest {
@Mock @Mock
private BatteryUsageStats mBatteryUsageStats; private BatteryUsageStats mBatteryUsageStats;
@Mock @Mock
private BatteryEntry mockBatteryEntry; private BatteryEntry mMockBatteryEntry;
private FakeFeatureFactory mFeatureFactory; private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider; private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -70,23 +70,23 @@ public final class ConvertUtilsTest {
@Test @Test
public void convert_returnsExpectedContentValues() { public void convert_returnsExpectedContentValues() {
final int expectedType = 3; final int expectedType = 3;
when(mockBatteryEntry.getUid()).thenReturn(1001); when(mMockBatteryEntry.getUid()).thenReturn(1001);
when(mockBatteryEntry.getLabel()).thenReturn("Settings"); when(mMockBatteryEntry.getLabel()).thenReturn("Settings");
when(mockBatteryEntry.getDefaultPackageName()) when(mMockBatteryEntry.getDefaultPackageName())
.thenReturn("com.google.android.settings.battery"); .thenReturn("com.google.android.settings.battery");
when(mockBatteryEntry.isHidden()).thenReturn(true); when(mMockBatteryEntry.isHidden()).thenReturn(true);
when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1); when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1);
when(mockBatteryEntry.getConsumedPower()).thenReturn(1.1); when(mMockBatteryEntry.getConsumedPower()).thenReturn(1.1);
mockBatteryEntry.mPercent = 0.3; mMockBatteryEntry.mPercent = 0.3;
when(mockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L); when(mMockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
when(mockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L); when(mMockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
when(mockBatteryEntry.getPowerComponentId()).thenReturn(expectedType); when(mMockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
when(mockBatteryEntry.getConsumerType()) when(mMockBatteryEntry.getConsumerType())
.thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY); .thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final ContentValues values = final ContentValues values =
ConvertUtils.convert( ConvertUtils.convert(
mockBatteryEntry, mMockBatteryEntry,
mBatteryUsageStats, mBatteryUsageStats,
/*batteryLevel=*/ 12, /*batteryLevel=*/ 12,
/*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL, /*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
@@ -154,7 +154,7 @@ public final class ConvertUtilsTest {
@Test @Test
public void getIndexedUsageMap_nullOrEmptyHistoryMap_returnEmptyCollection() { public void getIndexedUsageMap_nullOrEmptyHistoryMap_returnEmptyCollection() {
final int timeSlotSize = 2; final int timeSlotSize = 2;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L}; final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L, 104L, 105L};
assertThat(ConvertUtils.getIndexedUsageMap( assertThat(ConvertUtils.getIndexedUsageMap(
mContext, timeSlotSize, batteryHistoryKeys, mContext, timeSlotSize, batteryHistoryKeys,
@@ -166,11 +166,12 @@ public final class ConvertUtilsTest {
/*purgeLowPercentageAndFakeData=*/ true)) /*purgeLowPercentageAndFakeData=*/ true))
.isEmpty(); .isEmpty();
} }
@Test @Test
public void getIndexedUsageMap_returnsExpectedResult() { public void getIndexedUsageMap_returnsExpectedResult() {
// Creates the fake testing data. // Creates the fake testing data.
final int timeSlotSize = 2; final int timeSlotSize = 2;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L}; final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L, 104L, 105L};
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap =
new HashMap<>(); new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry( final BatteryHistEntry fakeEntry = createBatteryHistEntry(
@@ -281,7 +282,7 @@ public final class ConvertUtilsTest {
@Test @Test
public void getIndexedUsageMap_usageTimeExceed_returnsExpectedResult() { public void getIndexedUsageMap_usageTimeExceed_returnsExpectedResult() {
final int timeSlotSize = 1; final int timeSlotSize = 1;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L}; final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L};
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap =
new HashMap<>(); new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry( final BatteryHistEntry fakeEntry = createBatteryHistEntry(
@@ -322,7 +323,7 @@ public final class ConvertUtilsTest {
@Test @Test
public void getIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() { public void getIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() {
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L}; final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L};
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>(); final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry( final BatteryHistEntry fakeEntry = createBatteryHistEntry(
ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L); ConvertUtils.FAKE_PACKAGE_NAME, "fake_label", 0, 0L, 0L, 0L);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -14,14 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.widget.ImageView; import android.widget.ImageView;
@@ -74,7 +73,7 @@ public final class ExpandDividerPreferenceTest {
@Test @Test
public void testOnClick_switchExpandStateAndInvokeCallback() { public void testOnClick_switchExpandStateAndInvokeCallback() {
final boolean[] isExpandedArray = new boolean[] {false}; final boolean[] isExpandedArray = new boolean[]{false};
mExpandDividerPreference.mImageView = mImageView; mExpandDividerPreference.mImageView = mImageView;
mExpandDividerPreference.setOnExpandListener( mExpandDividerPreference.setOnExpandListener(
isExpanded -> isExpandedArray[0] = isExpanded); isExpanded -> isExpandedArray[0] = isExpanded);
@@ -94,7 +93,7 @@ public final class ExpandDividerPreferenceTest {
@Test @Test
public void testSetIsExpanded_updateStateButNotInvokeCallback() { public void testSetIsExpanded_updateStateButNotInvokeCallback() {
final boolean[] isExpandedArray = new boolean[] {false}; final boolean[] isExpandedArray = new boolean[]{false};
mExpandDividerPreference.mImageView = mImageView; mExpandDividerPreference.mImageView = mImageView;
mExpandDividerPreference.setOnExpandListener( mExpandDividerPreference.setOnExpandListener(
isExpanded -> isExpandedArray[0] = isExpanded); isExpanded -> isExpandedArray[0] = isExpanded);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.PowerUsageSummary.BATTERY_INFO_LOADER; import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.BATTERY_INFO_LOADER;
import static com.android.settings.fuelgauge.PowerUsageSummary.KEY_BATTERY_ERROR; import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.KEY_BATTERY_ERROR;
import static com.android.settings.fuelgauge.PowerUsageSummary.KEY_BATTERY_USAGE; import static com.android.settings.fuelgauge.batteryusage.PowerUsageSummary.KEY_BATTERY_USAGE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -44,6 +44,8 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.XmlTestUtils;
@@ -55,6 +57,7 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@@ -74,6 +77,7 @@ public class PowerUsageSummaryTest {
public static void beforeClass() { public static void beforeClass() {
sAdditionalBatteryInfoIntent = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO"); sAdditionalBatteryInfoIntent = new Intent("com.example.app.ADDITIONAL_BATTERY_INFO");
} }
@Mock @Mock
private SettingsActivity mSettingsActivity; private SettingsActivity mSettingsActivity;
@Mock @Mock
@@ -111,7 +115,7 @@ public class PowerUsageSummaryTest {
.thenReturn(sAdditionalBatteryInfoIntent); .thenReturn(sAdditionalBatteryInfoIntent);
when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mRealContext)) when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mRealContext))
.thenReturn(true); .thenReturn(true);
mFragment.mBatteryUtils = spy(new BatteryUtils(mRealContext)); mFragment.mBatteryUtils = Mockito.spy(new BatteryUtils(mRealContext));
ReflectionHelpers.setField(mFragment, "mVisibilityLoggerMixin", mVisibilityLoggerMixin); ReflectionHelpers.setField(mFragment, "mVisibilityLoggerMixin", mVisibilityLoggerMixin);
ReflectionHelpers.setField(mFragment, "mBatteryBroadcastReceiver", ReflectionHelpers.setField(mFragment, "mBatteryBroadcastReceiver",
mBatteryBroadcastReceiver); mBatteryBroadcastReceiver);

View File

@@ -31,13 +31,13 @@ import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData; import androidx.slice.widget.SliceLiveData;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUsageStatsLoader;
import com.android.settings.fuelgauge.batterytip.AppInfo; import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip; import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip; import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader;
import com.android.settings.slices.SliceBackgroundWorker; import com.android.settings.slices.SliceBackgroundWorker;
import org.junit.After; import org.junit.After;

View File

@@ -23,8 +23,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.backup.UserBackupSettingsActivity; import com.android.settings.backup.UserBackupSettingsActivity;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment; import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment; import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
import com.android.settings.fuelgauge.PowerUsageAdvanced; import com.android.settings.fuelgauge.batteryusage.PowerUsageAdvanced;
import com.android.settings.fuelgauge.PowerUsageSummary; import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.GestureNavigationSettingsFragment; import com.android.settings.gestures.GestureNavigationSettingsFragment;
import com.android.settings.gestures.SystemNavigationGestureSettings; import com.android.settings.gestures.SystemNavigationGestureSettings;
import com.android.settings.location.LocationSettings; import com.android.settings.location.LocationSettings;