Merge "Move battery usage files to a separate folder." into tm-qpr-dev am: 3b7953eac2 am: 6470ada117

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18797446

Change-Id: I3d6a155e80a5d54c309061c41d0b6436e61cc4cb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Zaiyue Xue
2022-06-20 09:42:01 +00:00
committed by Automerger Merge Worker
49 changed files with 1126 additions and 1027 deletions

View File

@@ -2855,7 +2855,7 @@
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<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"
android:value="@string/menu_key_battery"/>
</activity>

View File

@@ -31,7 +31,7 @@
android:textColor="?android:attr/textColorSecondary"
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:layout_width="match_parent"
android:layout_height="170dp"

View File

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

View File

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

View File

@@ -59,7 +59,7 @@
settings:highlightableMenuKey="@string/menu_key_notifications"/>
<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:key="top_level_battery"
android:order="-110"

View File

@@ -38,12 +38,12 @@ import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
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.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.settingslib.applications.AppUtils;
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.enterprise.EnterprisePrivacySettings;
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.BatterySaverSettings;
import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.AssistGestureSettings;
import com.android.settings.gestures.ButtonNavigationSettingsFragment;
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.emergency.EmergencyDashboardFragment;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.SmartBatterySettings;
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
import com.android.settings.gestures.GestureSettings;
import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.language.LanguageAndInputSettings;

View File

@@ -42,6 +42,9 @@ import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.applications.AppUtils;

View File

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

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

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");
* you may not use this file except in compliance with the License.
@@ -26,11 +26,13 @@ import android.util.SparseIntArray;
import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settings.fuelgauge.batteryusage.BatteryHistEntry;
import com.android.settingslib.fuelgauge.Estimate;
import java.util.Map;
import java.util.Set;
/** Implementation of {@code PowerUsageFeatureProvider} */
public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider {
private static final String PACKAGE_CALENDAR_PROVIDER = "com.android.providers.calendar";

View File

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

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

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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -11,10 +12,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import android.app.settings.SettingsEnums;
import android.content.Context;
@@ -38,6 +38,8 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -82,16 +84,25 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
@VisibleForTesting
Map<Integer, List<BatteryDiffEntry>> mBatteryIndexedMap;
@VisibleForTesting Context mPrefContext;
@VisibleForTesting BatteryUtils mBatteryUtils;
@VisibleForTesting PreferenceGroup mAppListPrefGroup;
@VisibleForTesting BatteryChartView mBatteryChartView;
@VisibleForTesting ExpandDividerPreference mExpandDividerPreference;
@VisibleForTesting
Context mPrefContext;
@VisibleForTesting
BatteryUtils mBatteryUtils;
@VisibleForTesting
PreferenceGroup mAppListPrefGroup;
@VisibleForTesting
BatteryChartView mBatteryChartView;
@VisibleForTesting
ExpandDividerPreference mExpandDividerPreference;
@VisibleForTesting boolean mIsExpanded = false;
@VisibleForTesting int[] mBatteryHistoryLevels;
@VisibleForTesting long[] mBatteryHistoryKeys;
@VisibleForTesting int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID;
@VisibleForTesting
boolean mIsExpanded = false;
@VisibleForTesting
int[] mBatteryHistoryLevels;
@VisibleForTesting
long[] mBatteryHistoryKeys;
@VisibleForTesting
int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID;
private boolean mIs24HourFormat = false;
private boolean mIsFooterPrefAdded = false;
@@ -496,7 +507,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} else {
return isApp
? mPrefContext.getString(R.string.battery_app_usage_for, slotInformation)
: mPrefContext.getString(R.string.battery_system_usage_for ,slotInformation);
: mPrefContext.getString(R.string.battery_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
* except in compliance with the License. You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language governing
* permissions and limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
import static java.lang.Math.round;
package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.Utils.formatPercentage;
import static java.lang.Math.round;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.content.res.Resources;
@@ -37,8 +39,8 @@ import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.widget.AppCompatImageView;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
@@ -68,6 +70,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
/** A callback listener for selected group index is updated. */
public interface OnSelectListener {
/** The callback function for selected group index is updated. */
void onSelect(int trapezoidIndex);
}
@@ -79,9 +82,12 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private boolean mIsSlotsClickabled;
private String[] mPercentages = getPercentages();
@VisibleForTesting int mHoveredIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting int mSelectedIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting String[] mTimestamps;
@VisibleForTesting
int mHoveredIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting
int mSelectedIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting
String[] mTimestamps;
// Colors for drawing the trapezoid shape and dividers.
private int mTrapezoidColor;
@@ -91,10 +97,10 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private int mTextPadding;
private final Rect mIndent = new Rect();
private final Rect[] mPercentageBounds =
new Rect[] {new Rect(), new Rect(), new Rect()};
new Rect[]{new Rect(), new Rect(), new Rect()};
// For drawing the timestamp information.
private final Rect[] mTimestampsBounds =
new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()};
new Rect[]{new Rect(), new Rect(), new Rect(), new Rect()};
@VisibleForTesting
Handler mHandler = new Handler();
@@ -208,7 +214,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
mTimestamps[index] =
ConvertUtils.utcToLocalTimeHour(
getContext(),
latestTimestamp - (TIMESTAMP_GAPS_COUNT - index) * timeSlotOffset,
latestTimestamp - (TIMESTAMP_GAPS_COUNT - index)
* timeSlotOffset,
is24HourFormat);
}
requestLayout();
@@ -429,8 +436,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
if (mTextPaint != null) {
canvas.drawText(
mPercentages[index],
getWidth() - mPercentageBounds[index].width() - mPercentageBounds[index].left,
offsetY + mPercentageBounds[index].height() *.5f,
getWidth() - mPercentageBounds[index].width()
- mPercentageBounds[index].left,
offsetY + mPercentageBounds[index].height() * .5f,
mTextPaint);
}
}
@@ -485,8 +493,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
for (int index = 1; index <= DEFAULT_TIMESTAMP_COUNT - 2; index++) {
canvas.drawText(
mTimestamps[index],
xOffsets[index] -
(mTimestampsBounds[index].width() - mTimestampsBounds[index].left) * .5f,
xOffsets[index]
- (mTimestampsBounds[index].width() - mTimestampsBounds[index].left)
* .5f,
getTimestampY(index), mTextPaint);
}
@@ -546,7 +555,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Generates path for non-clickable trapezoid curve.
if (mTrapezoidCurvePaint != null) {
if (trapezoidCurvePath == null) {
trapezoidCurvePath= new Path();
trapezoidCurvePath = new Path();
trapezoidCurvePath.moveTo(mTrapezoidSlots[index].mLeft, leftTop);
} else {
trapezoidCurvePath.lineTo(mTrapezoidSlots[index].mLeft, leftTop);
@@ -582,7 +591,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
}
private static String[] getPercentages() {
return new String[] {
return new String[]{
formatPercentage(/*percentage=*/ 100, /*round=*/ true),
formatPercentage(/*percentage=*/ 50, /*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
* except in compliance with the License. You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language governing
* permissions and limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -26,6 +28,7 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settingslib.utils.StringUtil;
import java.util.Comparator;
@@ -61,11 +64,16 @@ public class BatteryDiffEntry {
private UserManager mUserManager;
private String mDefaultPackageName = null;
@VisibleForTesting int mAppIconId;
@VisibleForTesting String mAppLabel = null;
@VisibleForTesting Drawable mAppIcon = null;
@VisibleForTesting boolean mIsLoaded = false;
@VisibleForTesting boolean mValidForRestriction = true;
@VisibleForTesting
int mAppIconId;
@VisibleForTesting
String mAppLabel = null;
@VisibleForTesting
Drawable mAppIcon = null;
@VisibleForTesting
boolean mIsLoaded = false;
@VisibleForTesting
boolean mValidForRestriction = true;
public BatteryDiffEntry(
Context context,
@@ -135,9 +143,9 @@ public class BatteryDiffEntry {
}
// Removes potential appended process name in the PackageName.
// From "com.opera.browser:privileged_process0" to "com.opera.browser"
final String[] splittedPackageNames = packageName.split(":");
return splittedPackageNames != null && splittedPackageNames.length > 0
? splittedPackageNames[0] : packageName;
final String[] splitPackageNames = packageName.split(":");
return splitPackageNames != null && splitPackageNames.length > 0
? splitPackageNames[0] : packageName;
}
/** Whether this item is valid for users to launch restriction page? */

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

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

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

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");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import android.content.Context;
import android.os.BatteryStatsManager;

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

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

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

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

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

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

View File

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

View File

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

View File

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

View File

@@ -52,6 +52,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowActivityManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;

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

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");
* you may not use this file except in compliance with the License.
@@ -14,22 +14,20 @@
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -37,15 +35,14 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.LocaleList;
import android.text.format.DateUtils;
import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -58,11 +55,10 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.List;
import java.util.Map;
@RunWith(RobolectricTestRunner.class)
@@ -72,18 +68,22 @@ public final class BatteryChartPreferenceControllerTest {
private static final int DESIRED_HISTORY_SIZE =
BatteryChartPreferenceController.DESIRED_HISTORY_SIZE;
@Mock private InstrumentedPreferenceFragment mFragment;
@Mock private SettingsActivity mSettingsActivity;
@Mock private PreferenceGroup mAppListGroup;
@Mock private PackageManager mPackageManager;
@Mock private Drawable mDrawable;
@Mock private BatteryHistEntry mBatteryHistEntry;
@Mock private BatteryChartView mBatteryChartView;
@Mock private PowerGaugePreference mPowerGaugePreference;
@Mock private ExpandDividerPreference mExpandDividerPreference;
@Mock private BatteryUtils mBatteryUtils;
@Mock private Configuration mConfiguration;
@Mock private Resources mResources;
@Mock
private InstrumentedPreferenceFragment mFragment;
@Mock
private SettingsActivity mSettingsActivity;
@Mock
private PreferenceGroup mAppListGroup;
@Mock
private Drawable mDrawable;
@Mock
private BatteryHistEntry mBatteryHistEntry;
@Mock
private BatteryChartView mBatteryChartView;
@Mock
private PowerGaugePreference mPowerGaugePreference;
@Mock
private BatteryUtils mBatteryUtils;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@@ -102,10 +102,10 @@ public final class BatteryChartPreferenceControllerTest {
final Resources resources = spy(mContext.getResources());
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
doReturn(resources).when(mContext).getResources();
doReturn(new String[] {"com.android.googlequicksearchbox"})
doReturn(new String[]{"com.android.googlequicksearchbox"})
.when(mFeatureFactory.powerUsageFeatureProvider)
.getHideApplicationSummary(mContext);
doReturn(new String[] {"com.android.gms.persistent"})
doReturn(new String[]{"com.android.gms.persistent"})
.when(mFeatureFactory.powerUsageFeatureProvider)
.getHideApplicationEntries(mContext);
mBatteryChartPreferenceController = createController();
@@ -611,7 +611,7 @@ public final class BatteryChartPreferenceControllerTest {
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mBatteryChartView =
spy(new BatteryChartView(mContext));
mBatteryChartPreferenceController.mBatteryHistoryKeys = new long[] {0L};
mBatteryChartPreferenceController.mBatteryHistoryKeys = new long[]{0L};
mBatteryChartPreferenceController.setTimestampLabel();
@@ -686,7 +686,7 @@ public final class BatteryChartPreferenceControllerTest {
private void setUpBatteryHistoryKeys() {
mBatteryChartPreferenceController.mBatteryHistoryKeys =
new long[] {1619196786769L, 0L, 1619247636826L};
new long[]{1619196786769L, 0L, 1619247636826L};
ConvertUtils.utcToLocalTimeHour(
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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -11,14 +12,11 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -30,6 +28,7 @@ import android.content.Context;
import android.os.LocaleList;
import android.view.accessibility.AccessibilityManager;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -40,8 +39,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
@RunWith(RobolectricTestRunner.class)
@@ -52,8 +51,10 @@ public final class BatteryChartViewTest {
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@Mock private AccessibilityServiceInfo mockAccessibilityServiceInfo;
@Mock private AccessibilityManager mockAccessibilityManager;
@Mock
private AccessibilityServiceInfo mMockAccessibilityServiceInfo;
@Mock
private AccessibilityManager mMockAccessibilityManager;
@Before
public void setUp() {
@@ -64,25 +65,25 @@ public final class BatteryChartViewTest {
mContext.getResources().getConfiguration().setLocales(
new LocaleList(new Locale("en_US")));
mBatteryChartView = new BatteryChartView(mContext);
doReturn(mockAccessibilityManager).when(mContext)
doReturn(mMockAccessibilityManager).when(mContext)
.getSystemService(AccessibilityManager.class);
doReturn("TalkBackService").when(mockAccessibilityServiceInfo).getId();
doReturn(Arrays.asList(mockAccessibilityServiceInfo))
.when(mockAccessibilityManager)
doReturn("TalkBackService").when(mMockAccessibilityServiceInfo).getId();
doReturn(Arrays.asList(mMockAccessibilityServiceInfo))
.when(mMockAccessibilityManager)
.getEnabledAccessibilityServiceList(anyInt());
}
@Test
public void testIsAccessibilityEnabled_disable_returnFalse() {
doReturn(false).when(mockAccessibilityManager).isEnabled();
doReturn(false).when(mMockAccessibilityManager).isEnabled();
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse();
}
@Test
public void testIsAccessibilityEnabled_emptyInfo_returnFalse() {
doReturn(true).when(mockAccessibilityManager).isEnabled();
doReturn(true).when(mMockAccessibilityManager).isEnabled();
doReturn(new ArrayList<AccessibilityServiceInfo>())
.when(mockAccessibilityManager)
.when(mMockAccessibilityManager)
.getEnabledAccessibilityServiceList(anyInt());
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isFalse();
@@ -90,13 +91,13 @@ public final class BatteryChartViewTest {
@Test
public void testIsAccessibilityEnabled_validServiceId_returnTrue() {
doReturn(true).when(mockAccessibilityManager).isEnabled();
doReturn(true).when(mMockAccessibilityManager).isEnabled();
assertThat(BatteryChartView.isAccessibilityEnabled(mContext)).isTrue();
}
@Test
public void testSetSelectedIndex_invokesCallback() {
final int selectedIndex[] = new int[1];
final int[] selectedIndex = new int[1];
final int expectedIndex = 2;
mBatteryChartView.mSelectedIndex = 1;
mBatteryChartView.setOnSelectListener(
@@ -113,7 +114,7 @@ public final class BatteryChartViewTest {
@Test
public void testSetSelectedIndex_sameIndex_notInvokesCallback() {
final int selectedIndex[] = new int[1];
final int[] selectedIndex = new int[1];
final int expectedIndex = 1;
mBatteryChartView.mSelectedIndex = expectedIndex;
mBatteryChartView.setOnSelectListener(
@@ -142,7 +143,7 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true);
doReturn(false).when(mockAccessibilityManager).isEnabled();
doReturn(false).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isTrue();
@@ -154,9 +155,9 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true);
doReturn(true).when(mockAccessibilityManager).isEnabled();
doReturn(true).when(mMockAccessibilityManager).isEnabled();
doReturn(new ArrayList<AccessibilityServiceInfo>())
.when(mockAccessibilityManager)
.when(mMockAccessibilityManager)
.getEnabledAccessibilityServiceList(anyInt());
mBatteryChartView.onAttachedToWindow();
@@ -169,7 +170,7 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true);
doReturn(true).when(mockAccessibilityManager).isEnabled();
doReturn(true).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
assertThat(mBatteryChartView.isClickable()).isFalse();
@@ -187,12 +188,12 @@ public final class BatteryChartViewTest {
mBatteryChartView.setClickableForce(true);
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
.thenReturn(true);
doReturn(true).when(mockAccessibilityManager).isEnabled();
doReturn(true).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
// Ensures the testing environment is correct.
assertThat(mBatteryChartView.isClickable()).isFalse();
// Turns off accessibility service.
doReturn(false).when(mockAccessibilityManager).isEnabled();
doReturn(false).when(mMockAccessibilityManager).isEnabled();
mBatteryChartView.onAttachedToWindow();
@@ -202,7 +203,7 @@ public final class BatteryChartViewTest {
@Test
public void testOnAttachedToWindow_addAccessibilityStateChangeListener() {
mBatteryChartView.onAttachedToWindow();
verify(mockAccessibilityManager)
verify(mMockAccessibilityManager)
.addAccessibilityStateChangeListener(mBatteryChartView);
}
@@ -214,7 +215,7 @@ public final class BatteryChartViewTest {
mBatteryChartView.onDetachedFromWindow();
verify(mockAccessibilityManager)
verify(mMockAccessibilityManager)
.removeAccessibilityStateChangeListener(mBatteryChartView);
assertThat(mBatteryChartView.mHandler.hasCallbacks(
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");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +35,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
import org.junit.Before;
import org.junit.Test;
@@ -59,15 +60,24 @@ public final class BatteryDiffEntryTest {
private Context mContext;
@Mock private ApplicationInfo mockAppInfo;
@Mock private PackageManager mockPackageManager;
@Mock private UserManager mockUserManager;
@Mock private Drawable mockDrawable;
@Mock private Drawable mockDrawable2;
@Mock private Drawable mockBadgedDrawable;
@Mock private BatteryHistEntry mBatteryHistEntry;
@Mock private PackageInfo mockPackageInfo;
@Mock private ConstantState mockConstantState;
@Mock
private ApplicationInfo mMockAppInfo;
@Mock
private PackageManager mMockPackageManager;
@Mock
private UserManager mMockUserManager;
@Mock
private Drawable mMockDrawable;
@Mock
private Drawable mMockDrawable2;
@Mock
private Drawable mMockBadgedDrawable;
@Mock
private BatteryHistEntry mBatteryHistEntry;
@Mock
private PackageInfo mMockPackageInfo;
@Mock
private ConstantState mMockConstantState;
@Before
public void setUp() {
@@ -75,8 +85,8 @@ public final class BatteryDiffEntryTest {
ShadowUserHandle.reset();
mContext = spy(RuntimeEnvironment.application);
doReturn(mContext).when(mContext).getApplicationContext();
doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(mockPackageManager).when(mContext).getPackageManager();
doReturn(mMockUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(mMockPackageManager).when(mContext).getPackageManager();
BatteryDiffEntry.clearCache();
}
@@ -150,7 +160,7 @@ public final class BatteryDiffEntryTest {
@Test
public void testLoadLabelAndIcon_forUserBattery_returnExpectedResult() {
final String expectedName = "Removed user";
doReturn(null).when(mockUserManager).getUserInfo(1001);
doReturn(null).when(mMockUserManager).getUserInfo(1001);
// Generates fake testing data.
final ContentValues values = getContentValuesWithType(
ConvertUtils.CONSUMER_TYPE_USER_BATTERY);
@@ -181,10 +191,10 @@ public final class BatteryDiffEntryTest {
ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
values.put("uid", /*invalid uid*/ 10001);
values.put("packageName", fakePackageName);
doReturn(mockAppInfo).when(mockPackageManager)
doReturn(mMockAppInfo).when(mMockPackageManager)
.getApplicationInfo(fakePackageName, 0);
doReturn(expectedAppLabel).when(mockPackageManager)
.getApplicationLabel(mockAppInfo);
doReturn(expectedAppLabel).when(mMockPackageManager)
.getApplicationLabel(mMockAppInfo);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
@@ -238,13 +248,13 @@ public final class BatteryDiffEntryTest {
final ContentValues values = getContentValuesWithType(
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
mockConstantState(mockDrawable);
mockConstantState(mMockDrawable);
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
entry.mIsLoaded = true;
entry.mAppIcon = mockDrawable;
assertThat(entry.getAppIcon()).isEqualTo(mockDrawable);
entry.mAppIcon = mMockDrawable;
assertThat(entry.getAppIcon()).isEqualTo(mMockDrawable);
assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
}
@@ -252,29 +262,29 @@ public final class BatteryDiffEntryTest {
public void testGetAppIcon_uidConsumerForNonOwner_returnDefaultActivityIconWithBadge()
throws Exception {
ShadowUserHandle.setUid(10);
final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable);
mockConstantState(mockDrawable);
mockConstantState(mockBadgedDrawable);
doReturn(mockBadgedDrawable).when(mockUserManager)
.getBadgedIconForUser(eq(mockDrawable), any());
final BatteryDiffEntry entry = createBatteryDiffEntry(mMockDrawable);
mockConstantState(mMockDrawable);
mockConstantState(mMockBadgedDrawable);
doReturn(mMockBadgedDrawable).when(mMockUserManager)
.getBadgedIconForUser(eq(mMockDrawable), any());
entry.mAppIcon = null;
assertThat(entry.getAppIcon()).isEqualTo(mockBadgedDrawable);
assertThat(entry.getAppIcon()).isEqualTo(mMockBadgedDrawable);
}
@Test
public void testGetAppIcon_uidConsumerWithNullIcon_returnDefaultActivityIcon()
throws Exception {
final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable);
mockConstantState(mockDrawable);
final BatteryDiffEntry entry = createBatteryDiffEntry(mMockDrawable);
mockConstantState(mMockDrawable);
entry.mAppIcon = null;
assertThat(entry.getAppIcon()).isEqualTo(mockDrawable);
assertThat(entry.getAppIcon()).isEqualTo(mMockDrawable);
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
// Verifies the app label in the cache.
final BatteryEntry.NameAndIcon nameAndIcon =
BatteryDiffEntry.sResourceCache.get(entry.getKey());
assertThat(nameAndIcon.mIcon).isEqualTo(mockDrawable);
assertThat(nameAndIcon.mIcon).isEqualTo(mMockDrawable);
}
@Test
@@ -295,21 +305,21 @@ public final class BatteryDiffEntryTest {
public void testClearCache_switchLocale_clearCacheIconAndLabel() throws Exception {
final int userId = UserHandle.getUserId(1001);
Locale.setDefault(new Locale("en_US"));
final BatteryDiffEntry entry1 = createBatteryDiffEntry(mockDrawable);
mockConstantState(mockDrawable);
assertThat(entry1.getAppIcon()).isEqualTo(mockDrawable);
final BatteryDiffEntry entry1 = createBatteryDiffEntry(mMockDrawable);
mockConstantState(mMockDrawable);
assertThat(entry1.getAppIcon()).isEqualTo(mMockDrawable);
// Switch the locale into another one.
Locale.setDefault(new Locale("zh_TW"));
final BatteryDiffEntry entry2 = createBatteryDiffEntry(mockDrawable2);
final BatteryDiffEntry entry2 = createBatteryDiffEntry(mMockDrawable2);
// We should get new drawable without caching.
mockConstantState(mockDrawable2);
assertThat(entry2.getAppIcon()).isEqualTo(mockDrawable2);
mockConstantState(mMockDrawable2);
assertThat(entry2.getAppIcon()).isEqualTo(mMockDrawable2);
// Verifies the cache is updated into the new drawable.
final BatteryEntry.NameAndIcon nameAndIcon =
BatteryDiffEntry.sResourceCache.get(entry2.getKey());
assertThat(nameAndIcon.mIcon).isEqualTo(mockDrawable2);
assertThat(nameAndIcon.mIcon).isEqualTo(mMockDrawable2);
}
@Test
@@ -390,19 +400,19 @@ public final class BatteryDiffEntryTest {
// Sets false if the app entry cannot be found.
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.updateRestrictionFlagState();
// Sets false if the app is invalid package name.
assertThat(entry.mValidForRestriction).isFalse();
doReturn(1000).when(mockPackageManager).getPackageUid(
doReturn(1000).when(mMockPackageManager).getPackageUid(
entry.getPackageName(), PackageManager.GET_META_DATA);
entry.updateRestrictionFlagState();
// Sets false if the app PackageInfo cannot be found.
assertThat(entry.mValidForRestriction).isFalse();
doReturn(mockPackageInfo).when(mockPackageManager).getPackageInfo(
doReturn(mMockPackageInfo).when(mMockPackageManager).getPackageInfo(
eq(entry.getPackageName()), anyInt());
entry.updateRestrictionFlagState();
// 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("packageName", "com.a.b.c");
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
doReturn(drawable).when(mockPackageManager).getDefaultActivityIcon();
doReturn(null).when(mockPackageManager).getApplicationInfo("com.a.b.c", 0);
doReturn(new String[] {"com.a.b.c"}).when(mockPackageManager)
doReturn(drawable).when(mMockPackageManager).getDefaultActivityIcon();
doReturn(null).when(mMockPackageManager).getApplicationInfo("com.a.b.c", 0);
doReturn(new String[]{"com.a.b.c"}).when(mMockPackageManager)
.getPackagesForUid(1001);
return createBatteryDiffEntry(10, batteryHistEntry);
}
private void mockConstantState(Drawable drawable) {
doReturn(mockConstantState).when(drawable).getConstantState();
doReturn(drawable).when(mockConstantState).newDrawable();
doReturn(mMockConstantState).when(drawable).getConstantState();
doReturn(drawable).when(mMockConstantState).newDrawable();
}
@Implements(UserHandle.class)

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

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

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");
* you may not use this file except in compliance with the License.
@@ -13,18 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import android.content.Context;
import com.android.settings.testutils.FakeFeatureFactory;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,6 +30,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.HashMap;
import java.util.Map;
@RunWith(RobolectricTestRunner.class)
public final class BatteryHistoryLoaderTest {

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");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -31,6 +31,7 @@ import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.widget.UsageView;
import org.junit.Before;

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");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;

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");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
@@ -27,6 +27,7 @@ import android.os.BatteryUsageStats;
import android.os.LocaleList;
import android.os.UserHandle;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -37,7 +38,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -54,7 +54,7 @@ public final class ConvertUtilsTest {
@Mock
private BatteryUsageStats mBatteryUsageStats;
@Mock
private BatteryEntry mockBatteryEntry;
private BatteryEntry mMockBatteryEntry;
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
@@ -70,23 +70,23 @@ public final class ConvertUtilsTest {
@Test
public void convert_returnsExpectedContentValues() {
final int expectedType = 3;
when(mockBatteryEntry.getUid()).thenReturn(1001);
when(mockBatteryEntry.getLabel()).thenReturn("Settings");
when(mockBatteryEntry.getDefaultPackageName())
when(mMockBatteryEntry.getUid()).thenReturn(1001);
when(mMockBatteryEntry.getLabel()).thenReturn("Settings");
when(mMockBatteryEntry.getDefaultPackageName())
.thenReturn("com.google.android.settings.battery");
when(mockBatteryEntry.isHidden()).thenReturn(true);
when(mMockBatteryEntry.isHidden()).thenReturn(true);
when(mBatteryUsageStats.getConsumedPower()).thenReturn(5.1);
when(mockBatteryEntry.getConsumedPower()).thenReturn(1.1);
mockBatteryEntry.mPercent = 0.3;
when(mockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
when(mockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
when(mockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
when(mockBatteryEntry.getConsumerType())
when(mMockBatteryEntry.getConsumedPower()).thenReturn(1.1);
mMockBatteryEntry.mPercent = 0.3;
when(mMockBatteryEntry.getTimeInForegroundMs()).thenReturn(1234L);
when(mMockBatteryEntry.getTimeInBackgroundMs()).thenReturn(5689L);
when(mMockBatteryEntry.getPowerComponentId()).thenReturn(expectedType);
when(mMockBatteryEntry.getConsumerType())
.thenReturn(ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
final ContentValues values =
ConvertUtils.convert(
mockBatteryEntry,
mMockBatteryEntry,
mBatteryUsageStats,
/*batteryLevel=*/ 12,
/*batteryStatus=*/ BatteryManager.BATTERY_STATUS_FULL,
@@ -154,7 +154,7 @@ public final class ConvertUtilsTest {
@Test
public void getIndexedUsageMap_nullOrEmptyHistoryMap_returnEmptyCollection() {
final int timeSlotSize = 2;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L, 104L, 105L};
assertThat(ConvertUtils.getIndexedUsageMap(
mContext, timeSlotSize, batteryHistoryKeys,
@@ -166,11 +166,12 @@ public final class ConvertUtilsTest {
/*purgeLowPercentageAndFakeData=*/ true))
.isEmpty();
}
@Test
public void getIndexedUsageMap_returnsExpectedResult() {
// Creates the fake testing data.
final int timeSlotSize = 2;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L, 104L, 105L};
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap =
new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry(
@@ -281,7 +282,7 @@ public final class ConvertUtilsTest {
@Test
public void getIndexedUsageMap_usageTimeExceed_returnsExpectedResult() {
final int timeSlotSize = 1;
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
final long[] batteryHistoryKeys = new long[]{101L, 102L, 103L};
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap =
new HashMap<>();
final BatteryHistEntry fakeEntry = createBatteryHistEntry(
@@ -322,7 +323,7 @@ public final class ConvertUtilsTest {
@Test
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 BatteryHistEntry fakeEntry = createBatteryHistEntry(
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");
* you may not use this file except in compliance with the License.
@@ -14,14 +14,13 @@
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.widget.ImageView;
@@ -74,7 +73,7 @@ public final class ExpandDividerPreferenceTest {
@Test
public void testOnClick_switchExpandStateAndInvokeCallback() {
final boolean[] isExpandedArray = new boolean[] {false};
final boolean[] isExpandedArray = new boolean[]{false};
mExpandDividerPreference.mImageView = mImageView;
mExpandDividerPreference.setOnExpandListener(
isExpanded -> isExpandedArray[0] = isExpanded);
@@ -94,7 +93,7 @@ public final class ExpandDividerPreferenceTest {
@Test
public void testSetIsExpanded_updateStateButNotInvokeCallback() {
final boolean[] isExpandedArray = new boolean[] {false};
final boolean[] isExpandedArray = new boolean[]{false};
mExpandDividerPreference.mImageView = mImageView;
mExpandDividerPreference.setOnExpandListener(
isExpanded -> isExpandedArray[0] = isExpanded);

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");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static com.google.common.truth.Truth.assertThat;

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");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
package com.android.settings.fuelgauge.batteryusage;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;

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

View File

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

View File

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