Screenshots: [in bg - banner] https://screenshot.googleplex.com/MzLC6LfX93TkkYf [in bg - hints] https://screenshot.googleplex.com/9JLXNsRiVG8arAU [in fg - banner] https://screenshot.googleplex.com/9oYbwUkeeLbQX2t [in fg - hints] https://screenshot.googleplex.com/53DTTUCUnf8rsoE [apps anomaly highlight hint + settings anomaly banner] https://screenshot.googleplex.com/8NdS2VMrSzwv2DM Bug: 291689643 Bug: 291689623 Bug: 284893240 Test: manual Change-Id: Ic02db49cb3794ef134759d9dcec5f5ef32454a95 Merged-In: Ic02db49cb3794ef134759d9dcec5f5ef32454a95 Merged-In: I7015cdf5a96d518febb160934d780ae84fe14427
148 lines
5.6 KiB
Java
148 lines
5.6 KiB
Java
/*
|
|
* Copyright (C) 2023 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
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
package com.android.settings.fuelgauge.batteryusage;
|
|
|
|
import android.app.settings.SettingsEnums;
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
|
|
import androidx.preference.PreferenceScreen;
|
|
|
|
import com.android.internal.annotations.VisibleForTesting;
|
|
import com.android.settings.core.BasePreferenceController;
|
|
import com.android.settings.overlay.FeatureFactory;
|
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
|
|
|
/** Controls the update for battery tips card */
|
|
public class BatteryTipsController extends BasePreferenceController {
|
|
|
|
private static final String TAG = "BatteryTipsController";
|
|
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
|
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
|
|
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
|
|
|
/** A callback listener for the battery tips is confirmed. */
|
|
interface OnAnomalyConfirmListener {
|
|
/** The callback function for the battery tips is confirmed. */
|
|
void onAnomalyConfirm();
|
|
}
|
|
|
|
/** A callback listener for the battery tips is rejected. */
|
|
interface OnAnomalyRejectListener {
|
|
/** The callback function for the battery tips is rejected. */
|
|
void onAnomalyReject();
|
|
}
|
|
|
|
private OnAnomalyConfirmListener mOnAnomalyConfirmListener;
|
|
private OnAnomalyRejectListener mOnAnomalyRejectListener;
|
|
|
|
@VisibleForTesting
|
|
BatteryTipsCardPreference mCardPreference;
|
|
@VisibleForTesting
|
|
AnomalyEventWrapper mAnomalyEventWrapper = null;
|
|
@VisibleForTesting
|
|
Boolean mIsAcceptable = false;
|
|
|
|
public BatteryTipsController(Context context) {
|
|
super(context, ROOT_PREFERENCE_KEY);
|
|
final FeatureFactory featureFactory = FeatureFactory.getFactory(context);
|
|
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
|
}
|
|
|
|
@Override
|
|
public int getAvailabilityStatus() {
|
|
return AVAILABLE;
|
|
}
|
|
|
|
@Override
|
|
public void displayPreference(PreferenceScreen screen) {
|
|
super.displayPreference(screen);
|
|
mCardPreference = screen.findPreference(CARD_PREFERENCE_KEY);
|
|
}
|
|
|
|
void setOnAnomalyConfirmListener(OnAnomalyConfirmListener listener) {
|
|
mOnAnomalyConfirmListener = listener;
|
|
}
|
|
|
|
void setOnAnomalyRejectListener(OnAnomalyRejectListener listener) {
|
|
mOnAnomalyRejectListener = listener;
|
|
}
|
|
|
|
void acceptTipsCard() {
|
|
if (mAnomalyEventWrapper == null || !mIsAcceptable) {
|
|
return;
|
|
}
|
|
// For anomaly events with same record key, dismissed until next time full charged.
|
|
final String dismissRecordKey = mAnomalyEventWrapper.getDismissRecordKey();
|
|
if (!TextUtils.isEmpty(dismissRecordKey)) {
|
|
DatabaseUtils.setDismissedPowerAnomalyKeys(mContext, dismissRecordKey);
|
|
}
|
|
mCardPreference.setVisible(false);
|
|
mMetricsFeatureProvider.action(
|
|
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT,
|
|
mAnomalyEventWrapper.getEventId());
|
|
}
|
|
|
|
void handleBatteryTipsCardUpdated(
|
|
AnomalyEventWrapper anomalyEventWrapper, boolean isAcceptable) {
|
|
mAnomalyEventWrapper = anomalyEventWrapper;
|
|
mIsAcceptable = isAcceptable;
|
|
if (mAnomalyEventWrapper == null) {
|
|
mCardPreference.setVisible(false);
|
|
return;
|
|
}
|
|
|
|
// Get card preference strings and navigate fragment info
|
|
final String eventId = mAnomalyEventWrapper.getEventId();
|
|
|
|
// Update card & buttons preference
|
|
if (!mAnomalyEventWrapper.updateTipsCardPreference(mCardPreference)) {
|
|
mCardPreference.setVisible(false);
|
|
return;
|
|
}
|
|
|
|
// Set battery tips card listener
|
|
mCardPreference.setOnConfirmListener(() -> {
|
|
mCardPreference.setVisible(false);
|
|
if (mOnAnomalyConfirmListener != null) {
|
|
mOnAnomalyConfirmListener.onAnomalyConfirm();
|
|
} else if (mAnomalyEventWrapper.launchSubSetting()) {
|
|
mMetricsFeatureProvider.action(
|
|
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT, eventId);
|
|
}
|
|
});
|
|
mCardPreference.setOnRejectListener(() -> {
|
|
mCardPreference.setVisible(false);
|
|
if (mOnAnomalyRejectListener != null) {
|
|
mOnAnomalyRejectListener.onAnomalyReject();
|
|
}
|
|
// For anomaly events with same record key, dismissed until next time full charged.
|
|
final String dismissRecordKey = mAnomalyEventWrapper.getDismissRecordKey();
|
|
if (!TextUtils.isEmpty(dismissRecordKey)) {
|
|
DatabaseUtils.setDismissedPowerAnomalyKeys(mContext, dismissRecordKey);
|
|
}
|
|
mMetricsFeatureProvider.action(
|
|
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_DISMISS, eventId);
|
|
});
|
|
|
|
mCardPreference.setVisible(true);
|
|
mMetricsFeatureProvider.action(
|
|
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW, eventId);
|
|
}
|
|
}
|