Merge "Add dump log for BatteryTip." into pi-dev

am: 26b5b5b5db

Change-Id: I0738c5dce35fa045b4393a246d4df2c2cba1c986
This commit is contained in:
jackqdyulei
2018-03-07 19:19:06 +00:00
committed by android-build-merger
7 changed files with 64 additions and 10 deletions

View File

@@ -68,6 +68,12 @@ public class AppInfo implements Comparable<AppInfo>, Parcelable {
dest.writeInt(uid);
}
@Override
public String toString() {
return "packageName=" + packageName + ",anomalyType=" + anomalyType + ",screenTime="
+ screenOnTimeMs;
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public AppInfo createFromParcel(Parcel in) {
return new AppInfo(in);

View File

@@ -158,4 +158,9 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
public int compareTo(BatteryTip o) {
return TIP_ORDER.get(mType) - TIP_ORDER.get(o.mType);
}
@Override
public String toString() {
return "type=" + mType + " state=" + mState;
}
}

View File

@@ -86,6 +86,19 @@ public class HighUsageTip extends BatteryTip {
return mHighUsageAppList;
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder(super.toString());
stringBuilder.append(" {");
for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
final AppInfo appInfo = mHighUsageAppList.get(i);
stringBuilder.append(" " + appInfo.toString() + " ");
}
stringBuilder.append('}');
return stringBuilder.toString();
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public BatteryTip createFromParcel(Parcel in) {
return new HighUsageTip(in);

View File

@@ -97,6 +97,19 @@ public class RestrictAppTip extends BatteryTip {
return mRestrictAppList;
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder(super.toString());
stringBuilder.append(" {");
for (int i = 0, size = mRestrictAppList.size(); i < size; i++) {
final AppInfo appInfo = mRestrictAppList.get(i);
stringBuilder.append(" " + appInfo.toString() + " ");
}
stringBuilder.append('}');
return stringBuilder.toString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);

View File

@@ -52,7 +52,7 @@ public class BatteryTipTest {
}
@Test
public void testBuildPreference() {
public void buildPreference() {
final Preference preference = mBatteryTip.buildPreference(mContext);
assertThat(preference.getTitle()).isEqualTo(TITLE);
@@ -61,7 +61,7 @@ public class BatteryTipTest {
}
@Test
public void testParcelable() {
public void parcelable() {
final BatteryTip batteryTip = new TestBatteryTip();
Parcel parcel = Parcel.obtain();
@@ -76,7 +76,7 @@ public class BatteryTipTest {
}
@Test
public void testTipOrder_orderUnique() {
public void tipOrder_orderUnique() {
final List<Integer> orders = new ArrayList<>();
for (int i = 0, size = BatteryTip.TIP_ORDER.size(); i < size; i++) {
orders.add(BatteryTip.TIP_ORDER.valueAt(i));
@@ -85,6 +85,11 @@ public class BatteryTipTest {
assertThat(orders).containsNoDuplicates();
}
@Test
public void toString_containBatteryTipData() {
assertThat(mBatteryTip.toString()).isEqualTo("type=6 state=0");
}
/**
* Used to test the non abstract methods in {@link TestBatteryTip}
*/

View File

@@ -73,4 +73,10 @@ public class HighUsageTipTest {
assertThat(app.packageName).isEqualTo(PACKAGE_NAME);
assertThat(app.screenOnTimeMs).isEqualTo(SCREEN_TIME);
}
@Test
public void toString_containsAppData() {
assertThat(mBatteryTip.toString()).isEqualTo(
"type=2 state=0 { packageName=com.android.app,anomalyType=0,screenTime=1800000 }");
}
}

View File

@@ -71,7 +71,7 @@ public class RestrictAppTipTest {
}
@Test
public void testParcelable() {
public void parcelable() {
Parcel parcel = Parcel.obtain();
mNewBatteryTip.writeToParcel(parcel, mNewBatteryTip.describeContents());
parcel.setDataPosition(0);
@@ -85,40 +85,46 @@ public class RestrictAppTipTest {
}
@Test
public void testGetTitle_stateNew_showRestrictTitle() {
public void getTitle_stateNew_showRestrictTitle() {
assertThat(mNewBatteryTip.getTitle(mContext)).isEqualTo("Restrict 1 app");
}
@Test
public void testGetTitle_stateHandled_showHandledTitle() {
public void getTitle_stateHandled_showHandledTitle() {
assertThat(mHandledBatteryTip.getTitle(mContext)).isEqualTo("1 recently restricted");
}
@Test
public void testGetSummary_stateNew_showRestrictSummary() {
public void getSummary_stateNew_showRestrictSummary() {
assertThat(mNewBatteryTip.getSummary(mContext))
.isEqualTo("app has high battery usage");
}
@Test
public void testGetSummary_stateHandled_showHandledSummary() {
public void getSummary_stateHandled_showHandledSummary() {
assertThat(mHandledBatteryTip.getSummary(mContext))
.isEqualTo("App changes are in progress");
}
@Test
public void testUpdate_anomalyBecomeInvisible_stateHandled() {
public void update_anomalyBecomeInvisible_stateHandled() {
mNewBatteryTip.updateState(mInvisibleBatteryTip);
assertThat(mNewBatteryTip.getState()).isEqualTo(BatteryTip.StateType.HANDLED);
}
@Test
public void testUpdate_newAnomalyComes_stateNew() {
public void update_newAnomalyComes_stateNew() {
mInvisibleBatteryTip.updateState(mNewBatteryTip);
assertThat(mInvisibleBatteryTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
mHandledBatteryTip.updateState(mNewBatteryTip);
assertThat(mHandledBatteryTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
}
@Test
public void toString_containsAppData() {
assertThat(mNewBatteryTip.toString()).isEqualTo(
"type=1 state=0 { packageName=com.android.app,anomalyType=0,screenTime=0 }");
}
}