Lazy load VolumeDialogComponent
Bug: 147455109 Test: manual (compare boot time of car.volume.VolumeUI vs volume.VolumeUI) Change-Id: I1ebb67d06fe5c7f1253ae970223128d3b53a3df5
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user