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

Commit cfc712a2 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB] Invalidate battery drawable on shield change; dump more info.

It seems other aspects of the battery drawable like `charging` would
invalidate the drawable directly, whereas `displayShield` wasn't. This
adds that invalidation. I'm not sure if that was what was causing the
bug, but it couldn't hurt.

This also adds more info to the `BatteryController` dump so we can see
who's registered as listening for events and the current state of the
battery drawables. See bug for sample dump.

Bug: 286998719
Test: `adb shell am broadcast -a com.android.systemui.demo -e command
battery -e defender true` -> shield shown
Test: `adb shell am broadcast -a com.android.systemui.demo -e command
battery -e defender false` -> shield hidden
Test: `adb shell dumpsys activity service
com.android.systemui/.SystemUIService BatteryController` -> additional
info is dumped
Test: atest BatteryMeterViewControllerTest
BatteryControllerImplGoogleTest

Change-Id: Idef1e6a883dd09012671ffc19520e8c3664f7dd2
parent e6ac1838
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.keyguard.CarrierText;
import com.android.systemui.R;
import com.android.systemui.battery.BatteryMeterView;
import com.android.systemui.statusbar.phone.KeyguardStatusBarView;
import com.android.systemui.statusbar.phone.StatusBarLocation;
import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserSwitcherContainer;

import dagger.Module;
@@ -41,6 +42,13 @@ public abstract class KeyguardStatusBarViewModule {
        return view.findViewById(R.id.battery);
    }

    /** */
    @Provides
    @KeyguardStatusBarViewScope
    static StatusBarLocation getStatusBarLocation() {
        return StatusBarLocation.KEYGUARD;
    }

    /** */
    @Provides
    @KeyguardStatusBarViewScope
+11 −0
Original line number Diff line number Diff line
@@ -87,6 +87,10 @@ class AccessorizedBatteryDrawable(
    }

    var displayShield: Boolean = false
        set(value) {
            field = value
            postInvalidate()
        }

    private fun updateSizes() {
        val b = bounds
@@ -204,4 +208,11 @@ class AccessorizedBatteryDrawable(
        val shieldPathString = context.resources.getString(R.string.config_batterymeterShieldPath)
        shieldPath.set(PathParser.createPathFromPathData(shieldPathString))
    }

    private val invalidateRunnable: () -> Unit = { invalidateSelf() }

    private fun postInvalidate() {
        unscheduleSelf(invalidateRunnable)
        scheduleSelf(invalidateRunnable, 0)
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -464,9 +464,11 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {

    public void dump(PrintWriter pw, String[] args) {
        String powerSave = mDrawable == null ? null : mDrawable.getPowerSaveEnabled() + "";
        String displayShield = mDrawable == null ? null : mDrawable.getDisplayShield() + "";
        CharSequence percent = mBatteryPercentView == null ? null : mBatteryPercentView.getText();
        pw.println("  BatteryMeterView:");
        pw.println("    mDrawable.getPowerSave: " + powerSave);
        pw.println("    mDrawable.getDisplayShield: " + displayShield);
        pw.println("    mBatteryPercentView.getText(): " + percent);
        pw.println("    mTextColor: #" + Integer.toHexString(mTextColor));
        pw.println("    mBatteryStateUnknown: " + mBatteryStateUnknown);
+13 −0
Original line number Diff line number Diff line
@@ -35,11 +35,14 @@ import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.phone.StatusBarLocation;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.util.ViewController;

import java.io.PrintWriter;

import javax.inject.Inject;

/** Controller for {@link BatteryMeterView}. **/
@@ -53,6 +56,7 @@ public class BatteryMeterViewController extends ViewController<BatteryMeterView>
    private final String mSlotBattery;
    private final SettingObserver mSettingObserver;
    private final UserTracker mUserTracker;
    private final StatusBarLocation mLocation;

    private final ConfigurationController.ConfigurationListener mConfigurationListener =
            new ConfigurationController.ConfigurationListener() {
@@ -94,6 +98,13 @@ public class BatteryMeterViewController extends ViewController<BatteryMeterView>
                public void onIsBatteryDefenderChanged(boolean isBatteryDefender) {
                    mView.onIsBatteryDefenderChanged(isBatteryDefender);
                }

                @Override
                public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
                    pw.print(super.toString());
                    pw.println(" location=" + mLocation);
                    mView.dump(pw, args);
                }
            };

    private final UserTracker.Callback mUserChangedCallback =
@@ -113,6 +124,7 @@ public class BatteryMeterViewController extends ViewController<BatteryMeterView>
    @Inject
    public BatteryMeterViewController(
            BatteryMeterView view,
            StatusBarLocation location,
            UserTracker userTracker,
            ConfigurationController configurationController,
            TunerService tunerService,
@@ -121,6 +133,7 @@ public class BatteryMeterViewController extends ViewController<BatteryMeterView>
            FeatureFlags featureFlags,
            BatteryController batteryController) {
        super(view);
        mLocation = location;
        mUserTracker = userTracker;
        mConfigurationController = configurationController;
        mTunerService = tunerService;
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.systemui.statusbar.notification.row.dagger.NotificationShelfC
import com.android.systemui.statusbar.notification.shelf.ui.viewbinder.NotificationShelfViewBinderWrapperControllerImpl
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout
import com.android.systemui.statusbar.phone.KeyguardBottomAreaView
import com.android.systemui.statusbar.phone.StatusBarLocation
import com.android.systemui.statusbar.phone.StatusIconContainer
import com.android.systemui.statusbar.phone.TapAgainView
import com.android.systemui.statusbar.policy.BatteryController
@@ -286,6 +287,7 @@ abstract class ShadeModule {
        ): BatteryMeterViewController {
            return BatteryMeterViewController(
                batteryMeterView,
                StatusBarLocation.QS,
                userTracker,
                configurationController,
                tunerService,
Loading