If VrManagerService is not started, vrManager will be null. Need
add check for it.
Test: robotests
Bug:
116427118
Change-Id: I899337bb5a996efffe82970fa690f2c5d59c1bb5
Merged-In: I899337bb5a996efffe82970fa690f2c5d59c1bb5
+ IVrManager safeGetVrManager() {
+ return IVrManager.Stub.asInterface(ServiceManager.getService(
+ Context.VR_SERVICE));
+ }
+
+ @VisibleForTesting
- try {
- return IVrManager.Stub.asInterface(ServiceManager.getService(Context.VR_SERVICE))
- .getVrModeState();
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to check vr mode!", e);
+ IVrManager vrManager = safeGetVrManager();
+ if (vrManager != null) {
+ try {
+ return vrManager.getVrModeState();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to check vr mode!", e);
+ }
+ public void isInVrMode_noVrManager_shouldAlwaysReturnFalse() {
+ doReturn(null).when(mController).safeGetVrManager();
+ assertThat(mController.isInVrMode()).isFalse();
+ }
+
+ @Test
public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(mContext, null);
public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(mContext, null);