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

Commit ec90572f authored by Ting-Kang Chang's avatar Ting-Kang Chang
Browse files

Add debug logs for updateBatteryStatus and TopLevelBatteryPreferenceController updating.

Bug: 271665638
Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge"
Change-Id: I1c9cc3cfcb54051223df2ad46947d7f0c1ebbdb0
parent 0f90688e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -116,12 +116,21 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
            return;
        }
        final String action = intent.getAction();
        Log.d(TAG, "updateBatteryStatus: action=" + action);
        if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
            final String batteryLevel = Utils.getBatteryPercentage(intent);
            final String batteryStatus =
                    Utils.getBatteryStatus(mContext, intent, /* compactStatus= */ false);
            final int batteryHealth = intent.getIntExtra(
                    BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN);
            Log.d(
                    TAG,
                    "Battery changed: level="
                            + batteryLevel
                            + ", status="
                            + batteryStatus
                            + ", health="
                            + batteryHealth);
            if (!Utils.isBatteryPresent(intent)) {
                Log.w(TAG, "Problem reading the battery meter.");
                mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_NOT_PRESENT);
+7 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;

import android.content.ComponentName;
import android.content.Context;
import android.util.Log;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -34,6 +35,8 @@ import com.android.settingslib.utils.ThreadUtils;
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
        LifecycleObserver, OnStart, OnStop, BatteryPreferenceController {

    private static final String TAG = "TopLvBatteryPrefControl";

    @VisibleForTesting
    protected boolean mIsBatteryPresent = true;
    @VisibleForTesting
@@ -47,6 +50,7 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
        super(context, preferenceKey);
        mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
        mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
            Log.d(TAG, "onBatteryChanged: type=" + type);
            if (type == BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_NOT_PRESENT) {
                mIsBatteryPresent = false;
            }
@@ -101,6 +105,8 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
            return null;
        }

        Log.d(TAG, "getDashboardLabel: batteryStatusUpdate=" + batteryStatusUpdate);

        if (batteryStatusUpdate) {
            setSummaryAsync(info);
        }
@@ -137,6 +143,7 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
    /**
     * Callback which receives text for the label.
     */
    @Override
    public void updateBatteryStatus(String label, BatteryInfo info) {
        mBatteryStatusLabel = label; // Null if adaptive charging is not active