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

Commit 40e124ca authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Have volume UI dismiss on home button press." into qt-qpr1-dev

parents 79a42a6c 25400fdc
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();
    }