Update the detect & show pipeline for PowerAnomalyEventList.
Test: make SettingsLibRoboTests Bug: 293813663 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f978f8b045c2d08e07735f0e7c2b343d53fb5580) Change-Id: I4a5a550b8c1a2317468e8cc4bd8c2b594c4208ac
This commit is contained in:
@@ -28,7 +28,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:maxLines="2"
|
|
||||||
android:textAlignment="viewStart"
|
android:textAlignment="viewStart"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:textColor="?android:attr/textColorPrimary" />
|
android:textColor="?android:attr/textColorPrimary" />
|
||||||
@@ -45,7 +44,7 @@
|
|||||||
style="@style/Widget.Material3.Button.TextButton"
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end|center_vertical"
|
||||||
android:paddingHorizontal="16dp"
|
android:paddingHorizontal="16dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:text="@string/battery_tips_card_dismiss_button"
|
android:text="@string/battery_tips_card_dismiss_button"
|
||||||
@@ -59,7 +58,7 @@
|
|||||||
android:paddingHorizontal="16dp"
|
android:paddingHorizontal="16dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end|center_vertical"
|
||||||
android:text="@string/battery_tips_card_action_button"
|
android:text="@string/battery_tips_card_action_button"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
@@ -44,6 +44,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnDestroy;
|
import com.android.settingslib.core.lifecycle.events.OnDestroy;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||||
|
|
||||||
@@ -51,14 +52,17 @@ import com.google.common.base.Objects;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/** Controls the update for chart graph and the list items. */
|
/** Controls the update for chart graph and the list items. */
|
||||||
public class BatteryChartPreferenceController extends AbstractPreferenceController
|
public class BatteryChartPreferenceController extends AbstractPreferenceController
|
||||||
implements PreferenceControllerMixin, LifecycleObserver, OnCreate, OnDestroy,
|
implements PreferenceControllerMixin, LifecycleObserver, OnCreate, OnDestroy, OnPause,
|
||||||
OnSaveInstanceState, OnResume {
|
OnSaveInstanceState, OnResume {
|
||||||
private static final String TAG = "BatteryChartPreferenceController";
|
private static final String TAG = "BatteryChartPreferenceController";
|
||||||
private static final String PREFERENCE_KEY = "battery_chart";
|
private static final String PREFERENCE_KEY = "battery_chart";
|
||||||
@@ -136,6 +140,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
private OnBatteryUsageUpdatedListener mOnBatteryUsageUpdatedListener;
|
private OnBatteryUsageUpdatedListener mOnBatteryUsageUpdatedListener;
|
||||||
private OnScreenOnTimeUpdatedListener mOnScreenOnTimeUpdatedListener;
|
private OnScreenOnTimeUpdatedListener mOnScreenOnTimeUpdatedListener;
|
||||||
private OnBatteryTipsUpdatedListener mOnBatteryTipsUpdatedListener;
|
private OnBatteryTipsUpdatedListener mOnBatteryTipsUpdatedListener;
|
||||||
|
private AtomicBoolean mIsAppResume = new AtomicBoolean(false);
|
||||||
|
|
||||||
private final SettingsActivity mActivity;
|
private final SettingsActivity mActivity;
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
@@ -180,9 +185,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
Log.d(TAG, String.format("onCreate() dailyIndex=%d hourlyIndex=%d",
|
Log.d(TAG, String.format("onCreate() dailyIndex=%d hourlyIndex=%d",
|
||||||
mDailyChartIndex, mHourlyChartIndex));
|
mDailyChartIndex, mHourlyChartIndex));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
mIsAppResume.compareAndSet(/* expect= */ true, /* update= */ false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
mIsAppResume.compareAndSet(/* expect= */ false, /* update= */ true);
|
||||||
mIs24HourFormat = DateFormat.is24HourFormat(mContext);
|
mIs24HourFormat = DateFormat.is24HourFormat(mContext);
|
||||||
mMetricsFeatureProvider.action(mPrefContext, SettingsEnums.OPEN_BATTERY_USAGE);
|
mMetricsFeatureProvider.action(mPrefContext, SettingsEnums.OPEN_BATTERY_USAGE);
|
||||||
}
|
}
|
||||||
@@ -370,14 +381,22 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
mOnBatteryUsageUpdatedListener.onBatteryUsageUpdated(
|
mOnBatteryUsageUpdatedListener.onBatteryUsageUpdated(
|
||||||
slotUsageData, getSlotInformation(), isBatteryUsageMapNullOrEmpty());
|
slotUsageData, getSlotInformation(), isBatteryUsageMapNullOrEmpty());
|
||||||
|
|
||||||
|
Log.d(TAG, "isBatteryTipsEnabled = "
|
||||||
|
+ mPowerUsageFeatureProvider.isBatteryTipsEnabled());
|
||||||
if (mOnBatteryTipsUpdatedListener != null) {
|
if (mOnBatteryTipsUpdatedListener != null) {
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
final PowerAnomalyEventList anomalyEventList = mPowerUsageFeatureProvider
|
final PowerAnomalyEventList anomalyEventList = mPowerUsageFeatureProvider
|
||||||
.detectSettingsAnomaly(mContext, /* displayDrain= */ 0);
|
.detectSettingsAnomaly(mContext, /* displayDrain= */ 0);
|
||||||
|
Log.d(TAG, "anomalyEventList = " + anomalyEventList);
|
||||||
final PowerAnomalyEvent displayEvent =
|
final PowerAnomalyEvent displayEvent =
|
||||||
getHighestScoreAnomalyEvent(anomalyEventList);
|
getHighestScoreAnomalyEvent(anomalyEventList);
|
||||||
mHandler.post(()
|
mHandler.post(() -> {
|
||||||
-> mOnBatteryTipsUpdatedListener.onBatteryTipsUpdated(displayEvent));
|
if (mIsAppResume.get()) {
|
||||||
|
mOnBatteryTipsUpdatedListener
|
||||||
|
.onBatteryTipsUpdated(displayEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,13 +407,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
if (anomalyEventList == null || anomalyEventList.getPowerAnomalyEventsCount() == 0) {
|
if (anomalyEventList == null || anomalyEventList.getPowerAnomalyEventsCount() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PowerAnomalyEvent highestScoreEvent = null;
|
return Collections.max(anomalyEventList.getPowerAnomalyEventsList(),
|
||||||
for (PowerAnomalyEvent event : anomalyEventList.getPowerAnomalyEventsList()) {
|
Comparator.comparing(PowerAnomalyEvent::getScore));
|
||||||
if (highestScoreEvent == null || event.getScore() > highestScoreEvent.getScore()) {
|
|
||||||
highestScoreEvent = event;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return highestScoreEvent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean refreshUiWithNoLevelDataCase() {
|
private boolean refreshUiWithNoLevelDataCase() {
|
||||||
|
@@ -101,6 +101,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
|
|||||||
.setDestination(mDestinationComponentName)
|
.setDestination(mDestinationComponentName)
|
||||||
.setSourceMetricsCategory(mSourceMetricsCategory)
|
.setSourceMetricsCategory(mSourceMetricsCategory)
|
||||||
.launch();
|
.launch();
|
||||||
|
setVisible(false);
|
||||||
} else if (viewId == R.id.dismiss_button) {
|
} else if (viewId == R.id.dismiss_button) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user