Loading packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java +10 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.ViewMediatorCallback; import com.android.systemui.car.CarServiceProvider; import com.android.systemui.statusbar.car.CarFacetButtonController; import com.android.systemui.statusbar.car.CarStatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; Loading @@ -36,6 +37,7 @@ import dagger.Component; public class CarSystemUIFactory extends SystemUIFactory { private CarDependencyComponent mCarDependencyComponent; private CarServiceProvider mCarServiceProvider; @Override protected SystemUIRootComponent buildSystemUIRootComponent(Context context) { Loading @@ -48,6 +50,14 @@ public class CarSystemUIFactory extends SystemUIFactory { .build(); } /** Gets a {@link CarServiceProvider}. */ public CarServiceProvider getCarServiceProvider(Context context) { if (mCarServiceProvider == null) { mCarServiceProvider = new CarServiceProvider(context); } return mCarServiceProvider; } public CarDependencyComponent getCarDependencyComponent() { return mCarDependencyComponent; } Loading packages/CarSystemUI/src/com/android/systemui/car/CarServiceProvider.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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; import android.car.Car; import android.car.Car.CarServiceLifecycleListener; import android.content.Context; import java.util.ArrayList; import java.util.List; /** * Connects to the car service a single time for shared use across all of system ui. */ public class CarServiceProvider { private final Context mContext; private final List<CarServiceLifecycleListener> mListeners = new ArrayList<>(); private Car mCar; public CarServiceProvider(Context context) { mContext = context; mCar = Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT, (car, ready) -> { mCar = car; synchronized (mListeners) { for (CarServiceLifecycleListener listener : mListeners) { listener.onLifecycleChanged(mCar, ready); } } }); } /** * Let's other components hook into the connection to the car service. If we're already * connected * to the car service, the callback is immediately triggered. */ public void addListener(CarServiceLifecycleListener listener) { if (mCar.isConnected()) { listener.onLifecycleChanged(mCar, /* ready= */ true); } mListeners.add(listener); } } packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +6 −5 Original line number Diff line number Diff line Loading @@ -199,6 +199,10 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt @Override public void start() { // Non blocking call to connect to car service. Call this early so that we'll be connected // asap. ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext); // get the provisioned state before calling the parent class since it's that flow that // builds the nav bar mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); Loading Loading @@ -482,11 +486,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt CarNotificationListener carNotificationListener = new CarNotificationListener(); mCarUxRestrictionManagerWrapper = new CarUxRestrictionManagerWrapper(); // This can take time if car service is not ready up to this time. // TODO(b/142808072) Refactor CarUxRestrictionManagerWrapper to allow setting // CarUxRestrictionsManager later and switch to Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT. Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_WAIT_FOREVER, (car, ready) -> { ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext) .addListener((car, ready) -> { if (!ready) { return; } Loading packages/CarSystemUI/src/com/android/systemui/statusbar/car/DrivingStateHelper.java +5 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ import android.util.Log; import androidx.annotation.NonNull; import com.android.systemui.CarSystemUIFactory; import com.android.systemui.SystemUIFactory; /** * Helper class for connecting to the {@link CarDrivingStateManager} and listening for driving state * changes. Loading @@ -35,7 +38,6 @@ public class DrivingStateHelper { private final Context mContext; private CarDrivingStateManager mDrivingStateManager; private Car mCar; private CarDrivingStateEventListener mDrivingStateHandler; public DrivingStateHelper(Context context, Loading Loading @@ -64,8 +66,8 @@ public class DrivingStateHelper { * Establishes connection with the Car service. */ public void connectToCarService() { mCar = Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT, mCarServiceLifecycleListener); ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext) .addListener(mCarServiceLifecycleListener); } private final CarServiceLifecycleListener mCarServiceLifecycleListener = (car, ready) -> { Loading packages/CarSystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java +4 −3 Original line number Diff line number Diff line Loading @@ -34,7 +34,9 @@ import android.view.ViewStub; import androidx.recyclerview.widget.GridLayoutManager; import com.android.systemui.CarSystemUIFactory; import com.android.systemui.R; import com.android.systemui.SystemUIFactory; import com.android.systemui.statusbar.car.CarTrustAgentUnlockDialogHelper.OnHideListener; import com.android.systemui.statusbar.car.UserGridRecyclerView.UserRecord; Loading Loading @@ -65,7 +67,6 @@ public class FullscreenUserSwitcher { mContext.unregisterReceiver(mUserUnlockReceiver); } }; private final Car mCar; public FullscreenUserSwitcher(CarStatusBar statusBar, ViewStub containerStub, Context context) { mStatusBar = statusBar; Loading @@ -85,8 +86,8 @@ public class FullscreenUserSwitcher { mUnlockDialogHelper = new CarTrustAgentUnlockDialogHelper(mContext); mUserManager = mContext.getSystemService(UserManager.class); mCar = Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT, (car, ready) -> { ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext) .addListener((car, ready) -> { if (!ready) { return; } Loading Loading
packages/CarSystemUI/src/com/android/systemui/CarSystemUIFactory.java +10 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.ViewMediatorCallback; import com.android.systemui.car.CarServiceProvider; import com.android.systemui.statusbar.car.CarFacetButtonController; import com.android.systemui.statusbar.car.CarStatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; Loading @@ -36,6 +37,7 @@ import dagger.Component; public class CarSystemUIFactory extends SystemUIFactory { private CarDependencyComponent mCarDependencyComponent; private CarServiceProvider mCarServiceProvider; @Override protected SystemUIRootComponent buildSystemUIRootComponent(Context context) { Loading @@ -48,6 +50,14 @@ public class CarSystemUIFactory extends SystemUIFactory { .build(); } /** Gets a {@link CarServiceProvider}. */ public CarServiceProvider getCarServiceProvider(Context context) { if (mCarServiceProvider == null) { mCarServiceProvider = new CarServiceProvider(context); } return mCarServiceProvider; } public CarDependencyComponent getCarDependencyComponent() { return mCarDependencyComponent; } Loading
packages/CarSystemUI/src/com/android/systemui/car/CarServiceProvider.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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; import android.car.Car; import android.car.Car.CarServiceLifecycleListener; import android.content.Context; import java.util.ArrayList; import java.util.List; /** * Connects to the car service a single time for shared use across all of system ui. */ public class CarServiceProvider { private final Context mContext; private final List<CarServiceLifecycleListener> mListeners = new ArrayList<>(); private Car mCar; public CarServiceProvider(Context context) { mContext = context; mCar = Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT, (car, ready) -> { mCar = car; synchronized (mListeners) { for (CarServiceLifecycleListener listener : mListeners) { listener.onLifecycleChanged(mCar, ready); } } }); } /** * Let's other components hook into the connection to the car service. If we're already * connected * to the car service, the callback is immediately triggered. */ public void addListener(CarServiceLifecycleListener listener) { if (mCar.isConnected()) { listener.onLifecycleChanged(mCar, /* ready= */ true); } mListeners.add(listener); } }
packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +6 −5 Original line number Diff line number Diff line Loading @@ -199,6 +199,10 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt @Override public void start() { // Non blocking call to connect to car service. Call this early so that we'll be connected // asap. ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext); // get the provisioned state before calling the parent class since it's that flow that // builds the nav bar mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); Loading Loading @@ -482,11 +486,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt CarNotificationListener carNotificationListener = new CarNotificationListener(); mCarUxRestrictionManagerWrapper = new CarUxRestrictionManagerWrapper(); // This can take time if car service is not ready up to this time. // TODO(b/142808072) Refactor CarUxRestrictionManagerWrapper to allow setting // CarUxRestrictionsManager later and switch to Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT. Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_WAIT_FOREVER, (car, ready) -> { ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext) .addListener((car, ready) -> { if (!ready) { return; } Loading
packages/CarSystemUI/src/com/android/systemui/statusbar/car/DrivingStateHelper.java +5 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ import android.util.Log; import androidx.annotation.NonNull; import com.android.systemui.CarSystemUIFactory; import com.android.systemui.SystemUIFactory; /** * Helper class for connecting to the {@link CarDrivingStateManager} and listening for driving state * changes. Loading @@ -35,7 +38,6 @@ public class DrivingStateHelper { private final Context mContext; private CarDrivingStateManager mDrivingStateManager; private Car mCar; private CarDrivingStateEventListener mDrivingStateHandler; public DrivingStateHelper(Context context, Loading Loading @@ -64,8 +66,8 @@ public class DrivingStateHelper { * Establishes connection with the Car service. */ public void connectToCarService() { mCar = Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT, mCarServiceLifecycleListener); ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext) .addListener(mCarServiceLifecycleListener); } private final CarServiceLifecycleListener mCarServiceLifecycleListener = (car, ready) -> { Loading
packages/CarSystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java +4 −3 Original line number Diff line number Diff line Loading @@ -34,7 +34,9 @@ import android.view.ViewStub; import androidx.recyclerview.widget.GridLayoutManager; import com.android.systemui.CarSystemUIFactory; import com.android.systemui.R; import com.android.systemui.SystemUIFactory; import com.android.systemui.statusbar.car.CarTrustAgentUnlockDialogHelper.OnHideListener; import com.android.systemui.statusbar.car.UserGridRecyclerView.UserRecord; Loading Loading @@ -65,7 +67,6 @@ public class FullscreenUserSwitcher { mContext.unregisterReceiver(mUserUnlockReceiver); } }; private final Car mCar; public FullscreenUserSwitcher(CarStatusBar statusBar, ViewStub containerStub, Context context) { mStatusBar = statusBar; Loading @@ -85,8 +86,8 @@ public class FullscreenUserSwitcher { mUnlockDialogHelper = new CarTrustAgentUnlockDialogHelper(mContext); mUserManager = mContext.getSystemService(UserManager.class); mCar = Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT, (car, ready) -> { ((CarSystemUIFactory) SystemUIFactory.getInstance()).getCarServiceProvider(mContext) .addListener((car, ready) -> { if (!ready) { return; } Loading