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:
@@ -23,15 +23,19 @@ import android.annotation.Nullable;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityTaskManager;
|
import android.app.ActivityTaskManager;
|
||||||
import android.car.Car;
|
import android.car.Car;
|
||||||
|
import android.car.CarNotConnectedException;
|
||||||
import android.car.drivingstate.CarDrivingStateEvent;
|
import android.car.drivingstate.CarDrivingStateEvent;
|
||||||
import android.car.drivingstate.CarUxRestrictionsManager;
|
import android.car.drivingstate.CarUxRestrictionsManager;
|
||||||
import android.car.hardware.power.CarPowerManager.CarPowerStateListener;
|
import android.car.hardware.power.CarPowerManager.CarPowerStateListener;
|
||||||
|
import android.car.media.CarAudioManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.GestureDetector;
|
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.KeyguardMonitor;
|
||||||
import com.android.systemui.statusbar.policy.UserSwitcherController;
|
import com.android.systemui.statusbar.policy.UserSwitcherController;
|
||||||
import com.android.systemui.statusbar.policy.ZenModeController;
|
import com.android.systemui.statusbar.policy.ZenModeController;
|
||||||
|
import com.android.systemui.volume.VolumeUI;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -155,6 +160,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt
|
|||||||
private NotificationDataManager mNotificationDataManager;
|
private NotificationDataManager mNotificationDataManager;
|
||||||
private NotificationClickHandlerFactory mNotificationClickHandlerFactory;
|
private NotificationClickHandlerFactory mNotificationClickHandlerFactory;
|
||||||
private ScreenLifecycle mScreenLifecycle;
|
private ScreenLifecycle mScreenLifecycle;
|
||||||
|
private CarAudioManager mCarAudioManager;
|
||||||
|
private VolumeUI mVolumeUI;
|
||||||
|
|
||||||
// The container for the notifications.
|
// The container for the notifications.
|
||||||
private CarNotificationView mNotificationView;
|
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
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
// Non blocking call to connect to car service. Call this early so that we'll be connected
|
// 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 = new PowerManagerHelper(mContext, mCarPowerStateListener);
|
||||||
mPowerManagerHelper.connectToCarService();
|
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() {
|
private void restartNavBarsIfNecessary() {
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ public class CarVolumeDialogComponent extends VolumeDialogComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected VolumeDialog createDefault() {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void init(int windowType, Callback callback) {
|
public void init(int windowType, Callback callback) {
|
||||||
initDialog();
|
initDialog();
|
||||||
|
|
||||||
((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext)
|
((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext)
|
||||||
.addListener(mCarServiceLifecycleListener);
|
.addListener(mCarServiceLifecycleListener);
|
||||||
}
|
}
|
||||||
@@ -265,6 +266,19 @@ public class CarVolumeDialogImpl implements VolumeDialog {
|
|||||||
mListView.setLayoutManager(new LinearLayoutManager(mContext));
|
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) {
|
private void showH(int reason) {
|
||||||
if (D.BUG) {
|
if (D.BUG) {
|
||||||
|
|||||||
Reference in New Issue
Block a user