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

Commit 25400fdc authored by Abhijoy Saha's avatar Abhijoy Saha
Browse files

DO NOT MERGE Have volume UI dismiss on home button press.

Register a receiver that listens for Intent.ACTION_CLOSE_SYSTEM_DIALOGS
and dismisses the volume UI when such an intent is received.

Bug: 149228466
Test: Manual
Change-Id: Iabb706b1d4cc54cb84f228aad95bfdb7e6f75851
parent e59b568a
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -26,8 +26,11 @@ import android.app.KeyguardManager;
import android.car.Car;
import android.car.Car.CarServiceLifecycleListener;
import android.car.media.CarAudioManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Color;
@@ -39,6 +42,7 @@ import android.os.Debug;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
@@ -175,6 +179,17 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        mCarAudioManager.registerCarVolumeCallback(mVolumeChangeCallback);
    };

    private final BroadcastReceiver mHomeButtonPressedBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (!intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
                return;
            }

            dismiss(Events.DISMISS_REASON_VOLUME_CONTROLLER);
        }
    };

    public CarVolumeDialogImpl(Context context) {
        mContext = context;
        mKeyguard = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
@@ -204,6 +219,10 @@ public class CarVolumeDialogImpl implements VolumeDialog {
    public void init(int windowType, Callback callback) {
        initDialog();

        mContext.registerReceiverAsUser(mHomeButtonPressedBroadcastReceiver, UserHandle.CURRENT,
                new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), /* broadcastPermission= */
                null, /* scheduler= */ null);

        ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext)
                .addListener(mCarServiceLifecycleListener);
    }
@@ -212,6 +231,8 @@ public class CarVolumeDialogImpl implements VolumeDialog {
    public void destroy() {
        mHandler.removeCallbacksAndMessages(/* token= */ null);

        mContext.unregisterReceiver(mHomeButtonPressedBroadcastReceiver);

        cleanupAudioManager();
    }