Snap for 7349343 from d8d5335096 to sc-release

Change-Id: I43c66bc843a38666239070440ff7416a8c35b92b
This commit is contained in:
android-build-team Robot
2021-05-09 23:08:30 +00:00
8 changed files with 47 additions and 13 deletions

View File

@@ -36,6 +36,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="165dp" android:layout_height="165dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:visibility="invisible"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
settings:textColor="?android:attr/textColorSecondary" /> settings:textColor="?android:attr/textColorSecondary" />
<TextView <TextView

View File

@@ -25,8 +25,7 @@
android:key="battery_graph"/> android:key="battery_graph"/>
<PreferenceCategory <PreferenceCategory
android:key="app_list" android:key="app_list"/>
android:title="@string/power_usage_list_summary"/>
<com.android.settingslib.widget.FooterPreference <com.android.settingslib.widget.FooterPreference
android:title="@string/battery_usage_screen_footer" android:title="@string/battery_usage_screen_footer"

View File

@@ -167,6 +167,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
super.displayPreference(screen); super.displayPreference(screen);
mPrefContext = screen.getContext(); mPrefContext = screen.getContext();
mAppListGroup = screen.findPreference(mPreferenceKey); mAppListGroup = screen.findPreference(mPreferenceKey);
mAppListGroup.setTitle(mPrefContext.getString(R.string.power_usage_list_summary));
} }
@Override @Override

View File

@@ -33,6 +33,7 @@ import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import java.util.Locale; import java.util.Locale;
@@ -59,6 +60,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private int mSelectedIndex; private int mSelectedIndex;
private float mTrapezoidVOffset; private float mTrapezoidVOffset;
private float mTrapezoidHOffset; private float mTrapezoidHOffset;
private boolean mIsSlotsClickable;
// Colors for drawing the trapezoid shape and dividers. // Colors for drawing the trapezoid shape and dividers.
private int mTrapezoidColor; private int mTrapezoidColor;
private int mTrapezoidSolidColor; private int mTrapezoidSolidColor;
@@ -73,7 +76,6 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private final Rect[] mTimestampsBounds = private final Rect[] mTimestampsBounds =
new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()}; new Rect[] {new Rect(), new Rect(), new Rect(), new Rect()};
private int[] mLevels; private int[] mLevels;
private Paint mTextPaint; private Paint mTextPaint;
private Paint mDividerPaint; private Paint mDividerPaint;
@@ -92,9 +94,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
initializeColors(context); initializeColors(context);
// Registers the click event listener. // Registers the click event listener.
setOnClickListener(this); setOnClickListener(this);
setClickable(false);
setSelectedIndex(SELECTED_INDEX_ALL); setSelectedIndex(SELECTED_INDEX_ALL);
setTrapezoidCount(DEFAULT_TRAPEZOID_COUNT); setTrapezoidCount(DEFAULT_TRAPEZOID_COUNT);
setClickable(false);
} }
/** Sets the total trapezoid count for drawing. */ /** Sets the total trapezoid count for drawing. */
@@ -157,6 +159,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
} else { } else {
mTextPaint = null; mTextPaint = null;
} }
setVisibility(View.VISIBLE);
requestLayout(); requestLayout();
} }
@@ -240,6 +243,23 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK); view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
} }
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
final Context context = mContext;
mIsSlotsClickable =
FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
.isChartGraphSlotsEnabled(context);
Log.d(TAG, "isChartGraphSlotsEnabled:" + mIsSlotsClickable);
setClickable(isClickable());
}
@Override
public void setClickable(boolean clickable) {
super.setClickable(mIsSlotsClickable && clickable);
}
private void initializeColors(Context context) { private void initializeColors(Context context) {
setBackgroundColor(Color.TRANSPARENT); setBackgroundColor(Color.TRANSPARENT);
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context); mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);

View File

@@ -214,13 +214,11 @@ public final class ConvertUtils {
currentEntry.mBackgroundUsageTimeInMs, currentEntry.mBackgroundUsageTimeInMs,
nextEntry.mBackgroundUsageTimeInMs, nextEntry.mBackgroundUsageTimeInMs,
nextTwoEntry.mBackgroundUsageTimeInMs); nextTwoEntry.mBackgroundUsageTimeInMs);
final double consumePower = double consumePower =
getDiffValue( getDiffValue(
currentEntry.mConsumePower, currentEntry.mConsumePower,
nextEntry.mConsumePower, nextEntry.mConsumePower,
nextTwoEntry.mConsumePower); nextTwoEntry.mConsumePower);
totalConsumePower += consumePower;
// Excludes entry since we don't have enough data to calculate. // Excludes entry since we don't have enough data to calculate.
if (foregroundUsageTimeInMs == 0 if (foregroundUsageTimeInMs == 0
&& backgroundUsageTimeInMs == 0 && backgroundUsageTimeInMs == 0
@@ -246,7 +244,9 @@ public final class ConvertUtils {
Math.round(foregroundUsageTimeInMs * ratio); Math.round(foregroundUsageTimeInMs * ratio);
backgroundUsageTimeInMs = backgroundUsageTimeInMs =
Math.round(backgroundUsageTimeInMs * ratio); Math.round(backgroundUsageTimeInMs * ratio);
consumePower = consumePower * ratio;
} }
totalConsumePower += consumePower;
batteryDiffEntryList.add( batteryDiffEntryList.add(
new BatteryDiffEntry( new BatteryDiffEntry(
context, context,
@@ -260,10 +260,10 @@ public final class ConvertUtils {
diffEntry.setTotalConsumePower(totalConsumePower); diffEntry.setTotalConsumePower(totalConsumePower);
} }
} }
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
if (purgeLowPercentageAndFakeData) { if (purgeLowPercentageAndFakeData) {
purgeLowPercentageAndFakeData(resultMap); purgeLowPercentageAndFakeData(resultMap);
} }
insert24HoursData(BatteryChartView.SELECTED_INDEX_ALL, resultMap);
return resultMap; return resultMap;
} }

View File

@@ -132,6 +132,11 @@ public interface PowerUsageFeatureProvider {
*/ */
boolean isChartGraphEnabled(Context context); boolean isChartGraphEnabled(Context context);
/**
* Checks whether we should show usage information by slots or not.
*/
boolean isChartGraphSlotsEnabled(Context context);
/** /**
* Returns battery history data with corresponding timestamp key. * Returns battery history data with corresponding timestamp key.
*/ */

View File

@@ -158,6 +158,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return false; return false;
} }
@Override
public boolean isChartGraphSlotsEnabled(Context context) {
return false;
}
@Override @Override
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) { public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
return null; return null;

View File

@@ -246,12 +246,10 @@ public final class ConvertUtilsTest {
assertBatteryDiffEntry(entryList.get(0), 75, 40L, 50L); assertBatteryDiffEntry(entryList.get(0), 75, 40L, 50L);
// Verifies the last 24 hours aggregate result. // Verifies the last 24 hours aggregate result.
entryList = purgedResultMap.get(Integer.valueOf(-1)); entryList = purgedResultMap.get(Integer.valueOf(-1));
assertThat(entryList).hasSize(2); assertThat(entryList).hasSize(1);
// Verifies the fake data is cleared out. // Verifies the fake data is cleared out.
assertThat(entryList.get(0).getPackageName()) assertThat(entryList.get(0).getPackageName())
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME); .isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
assertThat(entryList.get(1).getPackageName())
.isNotEqualTo(ConvertUtils.FAKE_PACKAGE_NAME);
} }
@Test @Test
@@ -286,9 +284,14 @@ public final class ConvertUtilsTest {
final List<BatteryDiffEntry> entryList = purgedResultMap.get(0); final List<BatteryDiffEntry> entryList = purgedResultMap.get(0);
assertThat(entryList).hasSize(1); assertThat(entryList).hasSize(1);
// Verifies the clipped usage time. // Verifies the clipped usage time.
final float ratio = (float) (7200) / (float) (3600 + 7200);
final BatteryDiffEntry resultEntry = entryList.get(0); final BatteryDiffEntry resultEntry = entryList.get(0);
assertThat(resultEntry.mForegroundUsageTimeInMs).isEqualTo(2400000); assertThat(resultEntry.mForegroundUsageTimeInMs)
assertThat(resultEntry.mBackgroundUsageTimeInMs).isEqualTo(4800000); .isEqualTo(Math.round(entry.mForegroundUsageTimeInMs * ratio));
assertThat(resultEntry.mBackgroundUsageTimeInMs)
.isEqualTo(Math.round(entry.mBackgroundUsageTimeInMs * ratio));
assertThat(resultEntry.mConsumePower)
.isEqualTo(entry.mConsumePower * ratio);
} }
@Test @Test