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

Commit ab6df3a3 authored by Evan Laird's avatar Evan Laird
Browse files

Listen for EXTRA_PRESENT changes

ACTION_BATTERY_CHANGED can pass a boolean EXTRA_PRESENT which would
alert listeners that a battery may or may not be present. SystemUI now
wants to show an error battery state instead of a potentially misleading
status in this situation.

Bug: 169935148
Test: adb shell cmd battery set present 1
Change-Id: I7d576248bb9931059100facb67ca6b46e81e554e
parent 429fc8c1
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.os.BatteryManager.EXTRA_LEVEL;
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT;
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE;
import static android.os.BatteryManager.EXTRA_PLUGGED;
import static android.os.BatteryManager.EXTRA_PRESENT;
import static android.os.BatteryManager.EXTRA_STATUS;

import android.content.Context;
@@ -49,14 +50,16 @@ public class BatteryStatus {
    public final int plugged;
    public final int health;
    public final int maxChargingWattage;
    public final boolean present;

    public BatteryStatus(int status, int level, int plugged, int health,
            int maxChargingWattage) {
            int maxChargingWattage, boolean present) {
        this.status = status;
        this.level = level;
        this.plugged = plugged;
        this.health = health;
        this.maxChargingWattage = maxChargingWattage;
        this.present = present;
    }

    public BatteryStatus(Intent batteryChangedIntent) {
@@ -64,6 +67,7 @@ public class BatteryStatus {
        plugged = batteryChangedIntent.getIntExtra(EXTRA_PLUGGED, 0);
        level = batteryChangedIntent.getIntExtra(EXTRA_LEVEL, 0);
        health = batteryChangedIntent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
        present = batteryChangedIntent.getBooleanExtra(EXTRA_PRESENT, true);

        final int maxChargingMicroAmp = batteryChangedIntent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT,
                -1);
+24 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2020 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="12dp"
        android:height="24dp"
        android:viewportWidth="12.0"
        android:viewportHeight="24.0">
    <path
        android:pathData="M10.404,2.4L8.4,2.4L8.4,0L3.6,0L3.6,2.4L1.596,2.4C0.72,2.4 0,3.12 0,3.996L0,22.392C0,23.28 0.72,24 1.596,24L10.392,24C11.28,24 12,23.28 12,22.404L12,3.996C12,3.12 11.28,2.4 10.404,2.4ZM7.14,19.14L4.86,19.14L4.86,16.86L7.14,16.86L7.14,19.14ZM8.76,12.828C8.76,12.828 8.304,13.332 7.956,13.68C7.38,14.256 6.96,15.06 6.96,15.6L5.04,15.6C5.04,14.604 5.592,13.776 6.156,13.2L7.272,12.072C7.596,11.748 7.8,11.292 7.8,10.8C7.8,9.804 6.996,9 6,9C5.004,9 4.2,9.804 4.2,10.8L2.4,10.8C2.4,8.808 4.008,7.2 6,7.2C7.992,7.2 9.6,8.808 9.6,10.8C9.6,11.592 9.276,12.312 8.76,12.828L8.76,12.828Z"
      android:fillColor="#ffffff" />
</vector>
+5 −0
Original line number Diff line number Diff line
@@ -571,4 +571,9 @@

    <!-- The duraction of the hide animation for the volume dialog in milliseconds -->
    <integer name="config_dialogHideAnimationDurationMs">250</integer>

    <!-- Whether or not to show a notification for an unknown battery state -->
    <bool name="config_showNotificationForUnknownBatteryState">false</bool>
    <!-- content URL in a notification when ACTION_BATTERY_CHANGED.EXTRA_PRESENT field is false -->
    <string translatable="false" name="config_batteryStateUnknownUrl"></string>
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -437,6 +437,8 @@
    <string name="accessibility_battery_three_bars">Battery three bars.</string>
    <!-- Content description of the battery when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_battery_full">Battery full.</string>
    <!-- Content description of the battery when battery state is unknown for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_battery_unknown">Battery percentage unknown.</string>

    <!-- Content description of the phone signal when no signal for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_no_phone">No phone.</string>
@@ -2848,4 +2850,10 @@
    <!-- Status for conversation without interaction data [CHAR LIMIT=120] -->
    <string name="basic_status" translatable="false">Open conversation</string>

    <!-- Title to display in a notification when ACTION_BATTERY_CHANGED.EXTRA_PRESENT field is false
    [CHAR LIMIT=NONE] -->
    <string name="battery_state_unknown_notification_title">Problem reading your battery meter</string>
    <!-- Text to display in a notification when ACTION_BATTERY_CHANGED.EXTRA_PRESENT field is false
    [CHAR LIMIT=NONE] -->
    <string name="battery_state_unknown_notification_text">Tap for more information</string>
</resources>
+8 −1
Original line number Diff line number Diff line
@@ -1708,7 +1708,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }

        // Take a guess at initial SIM state, battery status and PLMN until we get an update
        mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0, 0);
        mBatteryStatus = new BatteryStatus(BATTERY_STATUS_UNKNOWN, 100, 0, 0, 0, true);

        // Watch for interesting updates
        final IntentFilter filter = new IntentFilter();
@@ -2581,6 +2581,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        final boolean wasPluggedIn = old.isPluggedIn();
        final boolean stateChangedWhilePluggedIn = wasPluggedIn && nowPluggedIn
                && (old.status != current.status);
        final boolean nowPresent = current.present;
        final boolean wasPresent = old.present;

        // change in plug state is always interesting
        if (wasPluggedIn != nowPluggedIn || stateChangedWhilePluggedIn) {
@@ -2597,6 +2599,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            return true;
        }

        // Battery either showed up or disappeared
        if (wasPresent != nowPresent) {
            return true;
        }

        return false;
    }

Loading