diff options
5 files changed, 144 insertions, 3 deletions
diff --git a/packages/CarSystemUI/res/values/config.xml b/packages/CarSystemUI/res/values/config.xml index aeff35d88e23..52d13c3f5b4a 100644 --- a/packages/CarSystemUI/res/values/config.xml +++ b/packages/CarSystemUI/res/values/config.xml @@ -87,7 +87,7 @@ <item>com.android.systemui.util.NotificationChannels</item> <item>com.android.systemui.keyguard.KeyguardViewMediator</item> <!-- <item>com.android.systemui.recents.Recents</item>--> - <item>com.android.systemui.volume.VolumeUI</item> +<!-- <item>com.android.systemui.volume.VolumeUI</item>--> <!-- <item>com.android.systemui.stackdivider.Divider</item>--> <!-- <item>com.android.systemui.statusbar.phone.StatusBar</item>--> <item>com.android.systemui.usb.StorageNotification</item> @@ -110,5 +110,6 @@ <item>com.android.systemui.toast.ToastUI</item> <item>com.android.systemui.car.voicerecognition.ConnectedDeviceVoiceRecognitionNotifier</item> <item>com.android.systemui.window.SystemUIOverlayWindowManager</item> + <item>com.android.systemui.car.volume.VolumeUI</item> </string-array> </resources> diff --git a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java index a69c92f0bd05..91e222c325a3 100644 --- a/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java +++ b/packages/CarSystemUI/src/com/android/systemui/CarSystemUIBinder.java @@ -20,6 +20,7 @@ import com.android.systemui.biometrics.AuthController; import com.android.systemui.bubbles.dagger.BubbleModule; import com.android.systemui.car.notification.CarNotificationModule; import com.android.systemui.car.voicerecognition.ConnectedDeviceVoiceRecognitionNotifier; +import com.android.systemui.car.volume.VolumeUI; import com.android.systemui.globalactions.GlobalActionsComponent; import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.keyguard.dagger.KeyguardModule; @@ -39,7 +40,6 @@ import com.android.systemui.statusbar.tv.TvStatusBar; import com.android.systemui.theme.ThemeOverlayController; import com.android.systemui.toast.ToastUI; import com.android.systemui.util.leak.GarbageMonitor; -import com.android.systemui.volume.VolumeUI; import com.android.systemui.window.OverlayWindowModule; import com.android.systemui.window.SystemUIOverlayWindowManager; @@ -65,7 +65,7 @@ public abstract class CarSystemUIBinder { @ClassKey(Divider.class) public abstract SystemUI bindDivider(Divider sysui); - /** */ + /** Inject Car Navigation Bar. */ @Binds @IntoMap @ClassKey(CarNavigationBar.class) diff --git a/packages/CarSystemUI/src/com/android/systemui/car/volume/VolumeUI.java b/packages/CarSystemUI/src/com/android/systemui/car/volume/VolumeUI.java new file mode 100644 index 000000000000..2bdb85ff9acc --- /dev/null +++ b/packages/CarSystemUI/src/com/android/systemui/car/volume/VolumeUI.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.car.volume; + +import android.car.Car; +import android.car.media.CarAudioManager; +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Handler; +import android.util.Log; + +import com.android.systemui.R; +import com.android.systemui.SystemUI; +import com.android.systemui.car.CarServiceProvider; +import com.android.systemui.dagger.qualifiers.Main; +import com.android.systemui.volume.VolumeDialogComponent; + +import java.io.FileDescriptor; +import java.io.PrintWriter; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import dagger.Lazy; + +/** The entry point for controlling the volume ui in cars. */ +@Singleton +public class VolumeUI extends SystemUI { + + private static final String TAG = "VolumeUI"; + private final Resources mResources; + private final Handler mMainHandler; + private final CarServiceProvider mCarServiceProvider; + private final Lazy<VolumeDialogComponent> mVolumeDialogComponentLazy; + + private final CarAudioManager.CarVolumeCallback mVolumeChangeCallback = + new CarAudioManager.CarVolumeCallback() { + @Override + public void onGroupVolumeChanged(int zoneId, int groupId, int flags) { + if (mVolumeDialogComponent == null) { + mMainHandler.post(() -> { + mVolumeDialogComponent = mVolumeDialogComponentLazy.get(); + mVolumeDialogComponent.register(); + }); + mCarAudioManager.unregisterCarVolumeCallback(mVolumeChangeCallback); + } + } + + @Override + public void onMasterMuteChanged(int zoneId, int flags) { + // ignored + } + }; + + private boolean mEnabled; + private CarAudioManager mCarAudioManager; + private VolumeDialogComponent mVolumeDialogComponent; + + @Inject + public VolumeUI( + Context context, + @Main Resources resources, + @Main Handler mainHandler, + CarServiceProvider carServiceProvider, + Lazy<VolumeDialogComponent> volumeDialogComponentLazy + ) { + super(context); + mResources = resources; + mMainHandler = mainHandler; + mCarServiceProvider = carServiceProvider; + mVolumeDialogComponentLazy = volumeDialogComponentLazy; + } + + @Override + public void start() { + boolean enableVolumeUi = mResources.getBoolean(R.bool.enable_volume_ui); + mEnabled = enableVolumeUi; + if (!mEnabled) return; + + mCarServiceProvider.addListener(car -> { + if (mCarAudioManager != null) { + return; + } + + mCarAudioManager = (CarAudioManager) car.getCarManager(Car.AUDIO_SERVICE); + Log.d(TAG, "Registering mVolumeChangeCallback."); + // This volume call back is never unregistered because CarStatusBar is + // never destroyed. + mCarAudioManager.registerCarVolumeCallback(mVolumeChangeCallback); + }); + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (!mEnabled) return; + if (mVolumeDialogComponent != null) { + mVolumeDialogComponent.onConfigurationChanged(newConfig); + } + } + + @Override + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.print("mEnabled="); pw.println(mEnabled); + if (!mEnabled) return; + if (mVolumeDialogComponent != null) { + mVolumeDialogComponent.dump(fd, pw, args); + } + } +} diff --git a/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java b/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java index 5a3443674cf4..35ab322374e4 100644 --- a/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java +++ b/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogComponent.java @@ -45,6 +45,7 @@ public class CarVolumeDialogComponent extends VolumeDialogComponent { @Override protected VolumeDialog createDefault() { mCarVolumeDialog = new CarVolumeDialogImpl(mContext); + mCarVolumeDialog.show(Events.SHOW_REASON_VOLUME_CHANGED); return mCarVolumeDialog; } } diff --git a/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogImpl.java b/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogImpl.java index 873d7d7975e0..2218eb587d9e 100644 --- a/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogImpl.java +++ b/packages/CarSystemUI/src/com/android/systemui/volume/CarVolumeDialogImpl.java @@ -234,6 +234,20 @@ public class CarVolumeDialogImpl implements VolumeDialog { cleanupAudioManager(); } + /** + * Reveals volume dialog. + */ + public void show(int reason) { + mHandler.obtainMessage(H.SHOW, reason).sendToTarget(); + } + + /** + * Hides volume dialog. + */ + public void dismiss(int reason) { + mHandler.obtainMessage(H.DISMISS, reason).sendToTarget(); + } + private void initDialog() { loadAudioUsageItems(); mCarVolumeLineItems.clear(); |