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

Commit c46e4fc6 authored by Will Leshner's avatar Will Leshner
Browse files

Fix a bug with the screen incorrectly turning off on power button press.

In certain situations, when the device is docked and the power button is
single pressed, the screen turns off instead of initiating a dream. It
appears that when this happens, DreamManagerService doesn't think the
device is charging even though PowerManagerService thinks it is. This
change reworks the charge detection logic in DreamManagerService so that
it works the same as the logic in PowerManagerService in an attempt to
fix the issue.

Bug: 329125239
Test: atest DreamManagerServiceTests
Flag: ACONFIG android.service.dreams.use_battery_changed_broadcast STAGING
Change-Id: I5344c12d471cbfc889bdf511a7e9e36c6c3b84e6
parent 69b03fa3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -256,6 +256,7 @@ java_library_static {
        "stats_flags_lib",
        "core_os_flags_lib",
        "connectivity_flags_lib",
        "dreams_flags_lib",
    ],
    javac_shard_size: 50,
    javacflags: [
+11 −0
Original line number Diff line number Diff line
aconfig_declarations {
    name: "dreams_flags",
    package: "com.android.server.dreams",
    container: "system",
    srcs: ["*.aconfig"],
}

java_aconfig_library {
    name: "dreams_flags_lib",
    aconfig_declarations: "dreams_flags",
}
+21 −3
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.database.ContentObserver;
import android.hardware.display.AmbientDisplayConfiguration;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.BatteryManagerInternal;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
@@ -118,6 +119,7 @@ public final class DreamManagerService extends SystemService {
    private final DreamController mController;
    private final PowerManager mPowerManager;
    private final PowerManagerInternal mPowerManagerInternal;
    private final BatteryManagerInternal mBatteryManagerInternal;
    private final PowerManager.WakeLock mDozeWakeLock;
    private final ActivityTaskManagerInternal mAtmInternal;
    private final PackageManagerInternal mPmInternal;
@@ -186,8 +188,12 @@ public final class DreamManagerService extends SystemService {
    private final BroadcastReceiver mChargingReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Flags.useBatteryChangedBroadcast()) {
                mIsCharging = mBatteryManagerInternal.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
            } else {
                mIsCharging = (BatteryManager.ACTION_CHARGING.equals(intent.getAction()));
            }
        }
    };

    private final BroadcastReceiver mDockStateReceiver = new BroadcastReceiver() {
@@ -251,6 +257,12 @@ public final class DreamManagerService extends SystemService {
                com.android.internal.R.bool.config_keepDreamingWhenUnplugging);
        mDreamsDisabledByAmbientModeSuppressionConfig = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig);

        if (Flags.useBatteryChangedBroadcast()) {
            mBatteryManagerInternal = getLocalService(BatteryManagerInternal.class);
        } else {
            mBatteryManagerInternal = null;
        }
    }

    @Override
@@ -279,9 +291,15 @@ public final class DreamManagerService extends SystemService {

            mContext.registerReceiver(
                    mDockStateReceiver, new IntentFilter(Intent.ACTION_DOCK_EVENT));

            IntentFilter chargingIntentFilter = new IntentFilter();
            if (Flags.useBatteryChangedBroadcast()) {
                chargingIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
                chargingIntentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
            } else {
                chargingIntentFilter.addAction(BatteryManager.ACTION_CHARGING);
                chargingIntentFilter.addAction(BatteryManager.ACTION_DISCHARGING);
            }
            mContext.registerReceiver(mChargingReceiver, chargingIntentFilter);

            mSettingsObserver = new SettingsObserver(mHandler);
+12 −0
Original line number Diff line number Diff line
package: "com.android.server.dreams"
container: "system"

flag {
    name: "use_battery_changed_broadcast"
    namespace: "communal"
    description: "Use ACTION_BATTERY_CHANGED broadcast to track charging state"
    bug: "329125239"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file