Format battery java code
After this CL, we can follow Guideline:go/hc-mainline-dev#format-code to keep java format consistent. Test: manual Bug: 304439460 Change-Id: I5bb77f81b0bd9be618e34942eaaee8296bc42796
This commit is contained in:
@@ -64,8 +64,7 @@ public class BatteryDiffEntry {
|
||||
private static final Map<String, Pair<Integer, Integer>> SPECIAL_ENTRY_MAP =
|
||||
Map.of(
|
||||
SYSTEM_APPS_KEY,
|
||||
Pair.create(
|
||||
R.string.battery_usage_system_apps, R.drawable.ic_power_system),
|
||||
Pair.create(R.string.battery_usage_system_apps, R.drawable.ic_power_system),
|
||||
UNINSTALLED_APPS_KEY,
|
||||
Pair.create(
|
||||
R.string.battery_usage_uninstalled_apps,
|
||||
@@ -100,16 +99,11 @@ public class BatteryDiffEntry {
|
||||
private UserManager mUserManager;
|
||||
private String mDefaultPackageName = null;
|
||||
|
||||
@VisibleForTesting
|
||||
int mAppIconId;
|
||||
@VisibleForTesting
|
||||
String mAppLabel = null;
|
||||
@VisibleForTesting
|
||||
Drawable mAppIcon = null;
|
||||
@VisibleForTesting
|
||||
boolean mIsLoaded = false;
|
||||
@VisibleForTesting
|
||||
boolean mValidForRestriction = true;
|
||||
@VisibleForTesting int mAppIconId;
|
||||
@VisibleForTesting String mAppLabel = null;
|
||||
@VisibleForTesting Drawable mAppIcon = null;
|
||||
@VisibleForTesting boolean mIsLoaded = false;
|
||||
@VisibleForTesting boolean mValidForRestriction = true;
|
||||
|
||||
public BatteryDiffEntry(
|
||||
Context context,
|
||||
@@ -150,12 +144,24 @@ public class BatteryDiffEntry {
|
||||
}
|
||||
|
||||
public BatteryDiffEntry(Context context, String key, String legacyLabel, int consumerType) {
|
||||
this(context, /*uid=*/ 0, /*userId=*/ 0, key, /*isHidden=*/ false, /*componentId=*/ -1,
|
||||
/*legacyPackageName=*/ null, legacyLabel, consumerType,
|
||||
/*foregroundUsageTimeInMs=*/ 0, /*backgroundUsageTimeInMs=*/ 0,
|
||||
/*screenOnTimeInMs=*/ 0, /*consumePower=*/ 0, /*foregroundUsageConsumePower=*/ 0,
|
||||
/*foregroundServiceUsageConsumePower=*/ 0, /*backgroundUsageConsumePower=*/ 0,
|
||||
/*cachedUsageConsumePower=*/ 0);
|
||||
this(
|
||||
context,
|
||||
/* uid= */ 0,
|
||||
/* userId= */ 0,
|
||||
key,
|
||||
/* isHidden= */ false,
|
||||
/* componentId= */ -1,
|
||||
/* legacyPackageName= */ null,
|
||||
legacyLabel,
|
||||
consumerType,
|
||||
/* foregroundUsageTimeInMs= */ 0,
|
||||
/* backgroundUsageTimeInMs= */ 0,
|
||||
/* screenOnTimeInMs= */ 0,
|
||||
/* consumePower= */ 0,
|
||||
/* foregroundUsageConsumePower= */ 0,
|
||||
/* foregroundServiceUsageConsumePower= */ 0,
|
||||
/* backgroundUsageConsumePower= */ 0,
|
||||
/* cachedUsageConsumePower= */ 0);
|
||||
}
|
||||
|
||||
/** Sets the total consumed power in a specific time slot. */
|
||||
@@ -286,7 +292,8 @@ public class BatteryDiffEntry {
|
||||
/** Whether the current BatteryDiffEntry is uninstalled app or not. */
|
||||
public boolean isUninstalledEntry() {
|
||||
final String packageName = getPackageName();
|
||||
if (TextUtils.isEmpty(packageName) || isSystemEntry()
|
||||
if (TextUtils.isEmpty(packageName)
|
||||
|| isSystemEntry()
|
||||
// Some special package UIDs could be 0. Those packages are not installed by users.
|
||||
|| mUid == BatteryUtils.UID_ZERO) {
|
||||
return false;
|
||||
@@ -468,8 +475,9 @@ public class BatteryDiffEntry {
|
||||
mAppIcon = nameAndIcon.mIcon;
|
||||
}
|
||||
|
||||
final BatteryEntry.NameAndIcon nameAndIcon = BatteryEntry.loadNameAndIcon(
|
||||
mContext, uid, /*batteryEntry=*/ null, packageName, mAppLabel, mAppIcon);
|
||||
final BatteryEntry.NameAndIcon nameAndIcon =
|
||||
BatteryEntry.loadNameAndIcon(
|
||||
mContext, uid, /* batteryEntry= */ null, packageName, mAppLabel, mAppIcon);
|
||||
// Clears BatteryEntry internal cache since we will have another one.
|
||||
BatteryEntry.clearUidCache();
|
||||
if (nameAndIcon != null) {
|
||||
@@ -489,25 +497,48 @@ public class BatteryDiffEntry {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder()
|
||||
.append("BatteryDiffEntry{")
|
||||
.append(String.format("\n\tname=%s restrictable=%b",
|
||||
mAppLabel, mValidForRestriction))
|
||||
.append(String.format("\n\tconsume=%.2f%% %f/%f",
|
||||
mPercentage, mConsumePower, mTotalConsumePower))
|
||||
.append(String.format("\n\tconsume power= foreground:%f foregroundService:%f",
|
||||
mForegroundUsageConsumePower, mForegroundServiceUsageConsumePower))
|
||||
.append(String.format("\n\tconsume power= background:%f cached:%f",
|
||||
mBackgroundUsageConsumePower, mCachedUsageConsumePower))
|
||||
.append(String.format("\n\ttime= foreground:%s background:%s screen-on:%s",
|
||||
StringUtil.formatElapsedTime(mContext, (double) mForegroundUsageTimeInMs,
|
||||
/*withSeconds=*/ true, /*collapseTimeUnit=*/ false),
|
||||
StringUtil.formatElapsedTime(mContext, (double) mBackgroundUsageTimeInMs,
|
||||
/*withSeconds=*/ true, /*collapseTimeUnit=*/ false),
|
||||
StringUtil.formatElapsedTime(mContext, (double) mScreenOnTimeInMs,
|
||||
/*withSeconds=*/ true, /*collapseTimeUnit=*/ false)))
|
||||
.append(String.format("\n\tpackage:%s|%s uid:%d userId:%d",
|
||||
mLegacyPackageName, getPackageName(), mUid, mUserId));
|
||||
final StringBuilder builder =
|
||||
new StringBuilder()
|
||||
.append("BatteryDiffEntry{")
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tname=%s restrictable=%b",
|
||||
mAppLabel, mValidForRestriction))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tconsume=%.2f%% %f/%f",
|
||||
mPercentage, mConsumePower, mTotalConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tconsume power= foreground:%f foregroundService:%f",
|
||||
mForegroundUsageConsumePower,
|
||||
mForegroundServiceUsageConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tconsume power= background:%f cached:%f",
|
||||
mBackgroundUsageConsumePower, mCachedUsageConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\ttime= foreground:%s background:%s screen-on:%s",
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mForegroundUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mBackgroundUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mScreenOnTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false)))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tpackage:%s|%s uid:%d userId:%d",
|
||||
mLegacyPackageName, getPackageName(), mUid, mUserId));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user