DO NOT MERGE Initialize VolumeUI when volume change event is received.

We can reduce boot time, by having CarStatusBar listen for Volume change events and have it initialize VolumeUI when the first of such an event is received.

Bug: 143107490
Test: Manual
Change-Id: Iee8a68197bbb40b8d93d2cf4cfd3e8a1f41d2212
(cherry picked from commit 4d45b5557929b1390d75c9b1c3ee8622b18023a7)
This commit is contained in:
Abhijoy Saha
2019-11-07 14:03:21 -08:00
parent 6e7337a1f8
commit 5d45afee03
3 changed files with 64 additions and 1 deletions

View File

@@ -23,15 +23,19 @@ import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.car.Car;
import android.car.CarNotConnectedException;
import android.car.drivingstate.CarDrivingStateEvent;
import android.car.drivingstate.CarUxRestrictionsManager;
import android.car.hardware.power.CarPowerManager.CarPowerStateListener;
import android.car.media.CarAudioManager;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.InputMethodService;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
@@ -99,6 +103,7 @@ import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
import com.android.systemui.statusbar.policy.UserSwitcherController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.volume.VolumeUI;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -155,6 +160,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
private NotificationDataManager mNotificationDataManager;
private NotificationClickHandlerFactory mNotificationClickHandlerFactory;
private ScreenLifecycle mScreenLifecycle;
private CarAudioManager mCarAudioManager;
private VolumeUI mVolumeUI;
// The container for the notifications.
private CarNotificationView mNotificationView;
@@ -216,6 +223,28 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
}
};
private final CarAudioManager.CarVolumeCallback mVolumeChangeCallback =
new CarAudioManager.CarVolumeCallback() {
@Override
public void onGroupVolumeChanged(int zoneId, int groupId, int flags) {
if (mVolumeUI == null) {
new Handler(Looper.getMainLooper()).post(() -> {
// Initialize Volume UI
mVolumeUI = new VolumeUI();
mVolumeUI.mComponents = mComponents;
mVolumeUI.mContext = mContext;
mVolumeUI.start();
});
mCarAudioManager.unregisterCarVolumeCallback(mVolumeChangeCallback);
}
}
@Override
public void onMasterMuteChanged(int zoneId, int flags) {
// ignored
}
};
@Override
public void start() {
// Non blocking call to connect to car service. Call this early so that we'll be connected
@@ -301,6 +330,22 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
mPowerManagerHelper = new PowerManagerHelper(mContext, mCarPowerStateListener);
mPowerManagerHelper.connectToCarService();
((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext)
.addListener((car, ready) -> {
if (!ready || mCarAudioManager != null) {
return;
}
try {
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);
} catch (CarNotConnectedException e) {
Log.wtf(TAG, " mVolumeChangeCallback failed to connect to car ", e);
}
});
}
private void restartNavBarsIfNecessary() {

View File

@@ -31,6 +31,10 @@ public class CarVolumeDialogComponent extends VolumeDialogComponent {
}
protected VolumeDialog createDefault() {
return new CarVolumeDialogImpl(mContext);
CarVolumeDialogImpl carVolumeDialog = new CarVolumeDialogImpl(mContext);
// Since VolumeUI is initialized when the first Volume Up/Down event is received we need to
// show the dialog on initialization too.
carVolumeDialog.show(Events.SHOW_REASON_VOLUME_CHANGED);
return carVolumeDialog;
}
}

View File

@@ -197,6 +197,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
@Override
public void init(int windowType, Callback callback) {
initDialog();
((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext)
.addListener(mCarServiceLifecycleListener);
}
@@ -265,6 +266,19 @@ public class CarVolumeDialogImpl implements VolumeDialog {
mListView.setLayoutManager(new LinearLayoutManager(mContext));
}
/**
* 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 showH(int reason) {
if (D.BUG) {