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

Unverified Commit b2cb619f authored by Bruno Martins's avatar Bruno Martins Committed by Michael Bestas
Browse files

power: Extend custom charging sounds

Handle also the cases where the device gets disconnected from power sources.

Change-Id: I36ae79f0709846784b4b3d313ff97ebadebc06c5
parent 6dd29186
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -118,6 +118,8 @@ public class Notifier {
    private static final int MSG_PROFILE_TIMED_OUT = 5;
    private static final int MSG_WIRED_CHARGING_STARTED = 6;
    private static final int MSG_SCREEN_POLICY = 7;
    private static final int MSG_WIRED_CHARGING_DISCONNECTED = 8;
    private static final int MSG_WIRELESS_CHARGING_INTERRUPTED = 9;

    private static final long[] CHARGING_VIBRATION_TIME = {
            40, 40, 40, 40, 40, 40, 40, 40, 40, // ramp-up sampling rate = 40ms
@@ -929,6 +931,21 @@ public class Notifier {
        mHandler.sendMessage(msg);
    }

    /**
     * Called when wireless charging has been interrupted - to provide user feedback (sound only).
     */
    public void onWirelessChargingInterrupted(@UserIdInt int userId) {
        if (DEBUG) {
            Slog.d(TAG, "onWirelessChargingInterrupted");
        }

        mSuspendBlocker.acquire();
        Message msg = mHandler.obtainMessage(MSG_WIRELESS_CHARGING_INTERRUPTED);
        msg.setAsynchronous(true);
        msg.arg1 = userId;
        mHandler.sendMessage(msg);
    }

    /**
     * Called when wired charging has started - to provide user feedback
     */
@@ -944,6 +961,21 @@ public class Notifier {
        mHandler.sendMessage(msg);
    }

    /**
     * Called when wired charging has been disconnected - to provide user feedback
     */
    public void onWiredChargingDisconnected(@UserIdInt int userId) {
        if (DEBUG) {
            Slog.d(TAG, "onWiredChargingDisconnected");
        }

        mSuspendBlocker.acquire();
        Message msg = mHandler.obtainMessage(MSG_WIRED_CHARGING_DISCONNECTED);
        msg.setAsynchronous(true);
        msg.arg1 = userId;
        mHandler.sendMessage(msg);
    }

    /**
     * Called when the screen policy changes.
     */
@@ -1191,6 +1223,11 @@ public class Notifier {
        mSuspendBlocker.release();
    }

    private void showChargingStopped(@UserIdInt int userId, boolean wireless) {
        playChargingStartedFeedback(userId, wireless);
        mSuspendBlocker.release();
    }

    private void screenPolicyChanging(int displayGroupId, int screenPolicy) {
        mScreenUndimDetector.recordScreenPolicy(displayGroupId, screenPolicy);
    }
@@ -1472,6 +1509,9 @@ public class Notifier {
                case MSG_BROADCAST:
                    sendNextBroadcast();
                    break;
                case MSG_WIRELESS_CHARGING_INTERRUPTED:
                    showChargingStopped(msg.arg1, true /* wireless */);
                    break;
                case MSG_WIRELESS_CHARGING_STARTED:
                    showWirelessChargingStarted(msg.arg1, msg.arg2);
                    break;
@@ -1482,6 +1522,9 @@ public class Notifier {
                case MSG_PROFILE_TIMED_OUT:
                    lockProfile(msg.arg1);
                    break;
                case MSG_WIRED_CHARGING_DISCONNECTED:
                    showChargingStopped(msg.arg1, false /* wireless */);
                    break;
                case MSG_WIRED_CHARGING_STARTED:
                    showWiredChargingStarted(msg.arg1);
                    break;
+6 −0
Original line number Diff line number Diff line
@@ -2726,6 +2726,12 @@ public final class PowerManagerService extends SystemService
                    if (mIsPowered && !BatteryManager.isPlugWired(oldPlugType)
                            && BatteryManager.isPlugWired(mPlugType)) {
                        mNotifier.onWiredChargingStarted(mUserId);
                    } else if (wasPowered && !mIsPowered) {
                        if (oldPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
                            mNotifier.onWirelessChargingInterrupted(mUserId);
                        } else {
                            mNotifier.onWiredChargingDisconnected(mUserId);
                        }
                    } else if (dockedOnWirelessCharger) {
                        mNotifier.onWirelessChargingStarted(mBatteryLevel, mUserId);
                    }