Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb902fcd authored by Salvador Martinez's avatar Salvador Martinez
Browse files

Add flag to SysUI for Hybrid notification

This CL adds some configurable flags to the logic for showing the
hybrid notification.

Test: Tests still pass
Bug: 72122935
Change-Id: I8b13346167a79691ecc3cb21e45b42f8ae99e7b8
parent d66cfdfc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -43,6 +43,12 @@ import java.util.Set;
@SmallTest
public class SettingsBackupTest {

    /**
     * see {@link com.google.android.systemui.power.EnhancedEstimatesGoogleImpl} for more details
     */
    public static final String HYBRID_SYSUI_BATTERY_WARNING_FLAGS =
            "hybrid_sysui_battery_warning_flags";

    /**
     * The following blacklists contain settings that should *not* be backed up and restored to
     * another device.  As a general rule, anything that is not user configurable should be
@@ -226,6 +232,7 @@ public class SettingsBackupTest {
                    Settings.Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
                    Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                    Settings.Global.HTTP_PROXY,
                    HYBRID_SYSUI_BATTERY_WARNING_FLAGS,
                    Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
                    Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
                    Settings.Global.INSTANT_APP_DEXOPT_ENABLED,
+18 −0
Original line number Diff line number Diff line
@@ -2,7 +2,25 @@ package com.android.systemui.power;

public interface EnhancedEstimates {

    /**
     * Returns a boolean indicating if the hybrid notification should be used.
     */
    boolean isHybridNotificationEnabled();

    /**
     * Returns an estimate object if the feature is enabled.
     */
    Estimate getEstimate();

    /**
     * Returns a long indicating the amount of time remaining in milliseconds under which we will
     * show a regular warning to the user.
     */
    long getLowWarningThreshold();

    /**
     * Returns a long indicating the amount of time remaining in milliseconds under which we will
     * show a severe warning to the user.
     */
    long getSevereWarningThreshold();
}
+10 −0
Original line number Diff line number Diff line
@@ -13,4 +13,14 @@ public class EnhancedEstimatesImpl implements EnhancedEstimates {
    public Estimate getEstimate() {
        return null;
    }

    @Override
    public long getLowWarningThreshold() {
        return 0;
    }

    @Override
    public long getSevereWarningThreshold() {
        return 0;
    }
}
+14 −3
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    private long mWarningTriggerTimeMs;

    private Estimate mEstimate;
    private long mLowWarningThreshold;
    private long mSevereWarningThreshold;
    private boolean mWarning;
    private boolean mPlaySound;
    private boolean mInvalidCharger;
@@ -142,11 +144,18 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    @Override
    public void updateEstimate(Estimate estimate) {
        mEstimate = estimate;
        if (estimate.estimateMillis <= PowerUI.THREE_HOURS_IN_MILLIS) {
        if (estimate.estimateMillis <= mLowWarningThreshold) {
            mWarningTriggerTimeMs = System.currentTimeMillis();
        }
    }

    @Override
    public void updateThresholds(long lowThreshold, long severeThreshold) {
        mLowWarningThreshold = lowThreshold;
        mSevereWarningThreshold = severeThreshold;
    }


    private void updateNotification() {
        if (DEBUG) Slog.d(TAG, "updateNotification mWarning=" + mWarning + " mPlaySound="
                + mPlaySound + " mInvalidCharger=" + mInvalidCharger);
@@ -181,7 +190,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    }

    protected void showWarningNotification() {
        final String percentage = NumberFormat.getPercentInstance().format((double) mBatteryLevel / 100.0);
        final String percentage = NumberFormat.getPercentInstance()
                .format((double) mBatteryLevel / 100.0);

        // get standard notification copy
        String title = mContext.getString(R.string.battery_low_title);
@@ -214,7 +224,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
        }
        // Make the notification red if the percentage goes below a certain amount or the time
        // remaining estimate is disabled
        if (mEstimate == null || mBucket < 0) {
        if (mEstimate == null || mBucket < 0
                || mEstimate.estimateMillis < mSevereWarningThreshold) {
            nb.setColor(Utils.getColorAttr(mContext, android.R.attr.colorError));
        }
        nb.addAction(0,
+5 −2
Original line number Diff line number Diff line
@@ -269,6 +269,8 @@ public class PowerUI extends SystemUI {
            if (estimate != null) {
                mTimeRemaining = estimate.estimateMillis;
                mWarnings.updateEstimate(estimate);
                mWarnings.updateThresholds(mEnhancedEstimates.getLowWarningThreshold(),
                        mEnhancedEstimates.getSevereWarningThreshold());
            }
        }

@@ -292,7 +294,7 @@ public class PowerUI extends SystemUI {
                && !isPowerSaver
                && (((bucket < oldBucket || oldPlugged) && bucket < 0)
                        || (mEnhancedEstimates.isHybridNotificationEnabled()
                                && timeRemaining < THREE_HOURS_IN_MILLIS
                                && timeRemaining < mEnhancedEstimates.getLowWarningThreshold()
                                && isHourLess(oldTimeRemaining, timeRemaining)))
                && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN;
    }
@@ -306,7 +308,7 @@ public class PowerUI extends SystemUI {
    boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket,
            long timeRemaining, boolean isPowerSaver) {
        final boolean hybridWouldDismiss = mEnhancedEstimates.isHybridNotificationEnabled()
                && timeRemaining > THREE_HOURS_IN_MILLIS;
                && timeRemaining > mEnhancedEstimates.getLowWarningThreshold();
        final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0);
        return isPowerSaver
                || plugged
@@ -485,6 +487,7 @@ public class PowerUI extends SystemUI {
    public interface WarningsUI {
        void update(int batteryLevel, int bucket, long screenOffTime);
        void updateEstimate(Estimate estimate);
        void updateThresholds(long lowThreshold, long severeThreshold);
        void dismissLowBatteryWarning();
        void showLowBatteryWarning(boolean playSound);
        void dismissInvalidChargerWarning();
Loading