From 2abf1c60cc2fc6ec9bc590cb35e94581ecf93c2e Mon Sep 17 00:00:00 2001 From: Jin Qian Date: Tue, 21 Mar 2017 00:04:53 +0000 Subject: Revert "Add remote callbacks for persistent vr mode" This reverts commit 504c6d67d0c2e4cda5201372551914f94acce710. Change-Id: Ia0f8d508272211736d421cf097abaa0bcbc3abab --- Android.mk | 1 - .../service/vr/IPersistentVrStateCallbacks.aidl | 24 ------ core/java/android/service/vr/IVrManager.aidl | 15 ---- .../android/server/policy/PhoneWindowManager.java | 6 +- .../server/vr/PersistentVrStateListener.java | 31 ++++++++ .../com/android/server/vr/VrManagerInternal.java | 3 +- .../com/android/server/vr/VrManagerService.java | 92 ++++++++-------------- 7 files changed, 67 insertions(+), 105 deletions(-) delete mode 100644 core/java/android/service/vr/IPersistentVrStateCallbacks.aidl create mode 100644 services/core/java/com/android/server/vr/PersistentVrStateListener.java diff --git a/Android.mk b/Android.mk index 5672d638cb8a..0e5dfed53607 100644 --- a/Android.mk +++ b/Android.mk @@ -282,7 +282,6 @@ LOCAL_SRC_FILES += \ core/java/android/service/notification/IStatusBarNotificationHolder.aidl \ core/java/android/service/notification/IConditionListener.aidl \ core/java/android/service/notification/IConditionProvider.aidl \ - core/java/android/service/vr/IPersistentVrStateCallbacks.aidl \ core/java/android/service/vr/IVrListener.aidl \ core/java/android/service/vr/IVrManager.aidl \ core/java/android/service/vr/IVrStateCallbacks.aidl \ diff --git a/core/java/android/service/vr/IPersistentVrStateCallbacks.aidl b/core/java/android/service/vr/IPersistentVrStateCallbacks.aidl deleted file mode 100644 index 7de8b6362d89..000000000000 --- a/core/java/android/service/vr/IPersistentVrStateCallbacks.aidl +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2017, 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 android.service.vr; - -/** @hide */ -oneway interface IPersistentVrStateCallbacks { - - void onPersistentVrStateChanged(in boolean enabled); - -} diff --git a/core/java/android/service/vr/IVrManager.aidl b/core/java/android/service/vr/IVrManager.aidl index fce06d6d91c2..6034c1820972 100644 --- a/core/java/android/service/vr/IVrManager.aidl +++ b/core/java/android/service/vr/IVrManager.aidl @@ -17,7 +17,6 @@ package android.service.vr; import android.service.vr.IVrStateCallbacks; -import android.service.vr.IPersistentVrStateCallbacks; /** @hide */ interface IVrManager { @@ -36,20 +35,6 @@ interface IVrManager { */ void unregisterListener(in IVrStateCallbacks cb); - /** - * Add a callback to be notified when persistent VR mode state changes. - * - * @param cb the callback instance to add. - */ - void registerPersistentVrStateListener(in IPersistentVrStateCallbacks cb); - - /** - * Remove the callack from the current set of registered callbacks. - * - * @param cb the callback to remove. - */ - void unregisterPersistentVrStateListener(in IPersistentVrStateCallbacks cb); - /** * Return current VR mode state. * diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 47cc4703cd18..548fa1ec6d75 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -182,7 +182,6 @@ import android.provider.Settings; import android.service.dreams.DreamManagerInternal; import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; -import android.service.vr.IPersistentVrStateCallbacks; import android.speech.RecognizerIntent; import android.telecom.TelecomManager; import android.util.DisplayMetrics; @@ -237,6 +236,7 @@ import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback; import com.android.server.statusbar.StatusBarManagerInternal; import com.android.server.wm.AppTransition; import com.android.server.vr.VrManagerInternal; +import com.android.server.vr.PersistentVrStateListener; import java.io.File; import java.io.FileReader; @@ -999,8 +999,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { } MyOrientationListener mOrientationListener; - final IPersistentVrStateCallbacks mPersistentVrModeListener = - new IPersistentVrStateCallbacks.Stub() { + final PersistentVrStateListener mPersistentVrModeListener = + new PersistentVrStateListener() { @Override public void onPersistentVrStateChanged(boolean enabled) { mPersistentVrModeEnabled = enabled; diff --git a/services/core/java/com/android/server/vr/PersistentVrStateListener.java b/services/core/java/com/android/server/vr/PersistentVrStateListener.java new file mode 100644 index 000000000000..bccd5f165aed --- /dev/null +++ b/services/core/java/com/android/server/vr/PersistentVrStateListener.java @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2017 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.server.vr; + +/** + * Listener for state changes to persistent VR mode. + * + * @hide Only for use within system server. + */ +public abstract class PersistentVrStateListener { + + /** + * Called when the Persistent VR mode state changes. + * + * @param enabled {@code true} if persistent VR mode is enabled. + */ + public abstract void onPersistentVrStateChanged(boolean enabled); +} diff --git a/services/core/java/com/android/server/vr/VrManagerInternal.java b/services/core/java/com/android/server/vr/VrManagerInternal.java index 358861d0c9c4..210aa44c0c03 100644 --- a/services/core/java/com/android/server/vr/VrManagerInternal.java +++ b/services/core/java/com/android/server/vr/VrManagerInternal.java @@ -17,7 +17,6 @@ package com.android.server.vr; import android.annotation.NonNull; import android.content.ComponentName; -import android.service.vr.IPersistentVrStateCallbacks; /** * Service for accessing the VR mode manager. @@ -102,5 +101,5 @@ public abstract class VrManagerInternal { /** * Adds listener that reports state changes to persistent VR mode. */ - public abstract void addPersistentVrModeStateListener(IPersistentVrStateCallbacks listener); + public abstract void addPersistentVrModeStateListener(PersistentVrStateListener listener); } diff --git a/services/core/java/com/android/server/vr/VrManagerService.java b/services/core/java/com/android/server/vr/VrManagerService.java index 5bcdd4cd036e..a00115cba2a2 100644 --- a/services/core/java/com/android/server/vr/VrManagerService.java +++ b/services/core/java/com/android/server/vr/VrManagerService.java @@ -40,7 +40,6 @@ import android.os.RemoteException; import android.os.UserHandle; import android.provider.Settings; import android.service.notification.NotificationListenerService; -import android.service.vr.IPersistentVrStateCallbacks; import android.service.vr.IVrListener; import android.service.vr.IVrManager; import android.service.vr.IVrStateCallbacks; @@ -124,10 +123,10 @@ public class VrManagerService extends SystemService implements EnabledComponentC private int mCurrentVrModeUser; private boolean mWasDefaultGranted; private boolean mGuard; - private final RemoteCallbackList mVrStateRemoteCallbacks = + private final RemoteCallbackList mRemoteCallbacks = new RemoteCallbackList<>(); - private final RemoteCallbackList - mPersistentVrStateRemoteCallbacks = new RemoteCallbackList<>(); + private final ArrayList mPersistentVrStateListeners = + new ArrayList<>(); private int mPreviousCoarseLocationMode = INVALID_APPOPS_MODE; private int mPreviousManageOverlayMode = INVALID_APPOPS_MODE; private VrState mPendingState; @@ -203,16 +202,16 @@ public class VrManagerService extends SystemService implements EnabledComponentC switch(msg.what) { case MSG_VR_STATE_CHANGE : { boolean state = (msg.arg1 == 1); - int i = mVrStateRemoteCallbacks.beginBroadcast(); + int i = mRemoteCallbacks.beginBroadcast(); while (i > 0) { i--; try { - mVrStateRemoteCallbacks.getBroadcastItem(i).onVrStateChanged(state); + mRemoteCallbacks.getBroadcastItem(i).onVrStateChanged(state); } catch (RemoteException e) { // Noop } } - mVrStateRemoteCallbacks.finishBroadcast(); + mRemoteCallbacks.finishBroadcast(); } break; case MSG_PENDING_VR_STATE_CHANGE : { synchronized(mLock) { @@ -223,17 +222,10 @@ public class VrManagerService extends SystemService implements EnabledComponentC } break; case MSG_PERSISTENT_VR_MODE_STATE_CHANGE : { boolean state = (msg.arg1 == 1); - int i = mPersistentVrStateRemoteCallbacks.beginBroadcast(); - while (i > 0) { - i--; - try { - mPersistentVrStateRemoteCallbacks.getBroadcastItem(i) - .onPersistentVrStateChanged(state); - } catch (RemoteException e) { - // Noop - } + for (int i = 0; i < mPersistentVrStateListeners.size(); i++) { + mPersistentVrStateListeners.get(i).onPersistentVrStateChanged( + state); } - mPersistentVrStateRemoteCallbacks.finishBroadcast(); } break; default : throw new IllegalStateException("Unknown message type: " + msg.what); @@ -390,26 +382,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC VrManagerService.this.removeStateCallback(cb); } - @Override - public void registerPersistentVrStateListener(IPersistentVrStateCallbacks cb) { - enforceCallerPermission(Manifest.permission.ACCESS_VR_MANAGER); - if (cb == null) { - throw new IllegalArgumentException("Callback binder object is null."); - } - - VrManagerService.this.addPersistentStateCallback(cb); - } - - @Override - public void unregisterPersistentVrStateListener(IPersistentVrStateCallbacks cb) { - enforceCallerPermission(Manifest.permission.ACCESS_VR_MANAGER); - if (cb == null) { - throw new IllegalArgumentException("Callback binder object is null."); - } - - VrManagerService.this.removePersistentStateCallback(cb); - } - @Override public boolean getVrModeState() { return VrManagerService.this.getVrMode(); @@ -442,21 +414,13 @@ public class VrManagerService extends SystemService implements EnabledComponentC String tab = " "; dumpStateTransitions(pw); pw.println("\n\nRemote Callbacks:"); - int i=mVrStateRemoteCallbacks.beginBroadcast(); // create the broadcast item array - while(i-->0) { - pw.print(tab); - pw.print(mVrStateRemoteCallbacks.getBroadcastItem(i)); - if (i>0) pw.println(","); - } - mVrStateRemoteCallbacks.finishBroadcast(); - pw.println("\n\nPersistent Vr State Remote Callbacks:"); - i=mPersistentVrStateRemoteCallbacks.beginBroadcast(); + int i=mRemoteCallbacks.beginBroadcast(); // create the broadcast item array while(i-->0) { pw.print(tab); - pw.print(mPersistentVrStateRemoteCallbacks.getBroadcastItem(i)); + pw.print(mRemoteCallbacks.getBroadcastItem(i)); if (i>0) pw.println(","); } - mPersistentVrStateRemoteCallbacks.finishBroadcast(); + mRemoteCallbacks.finishBroadcast(); pw.println("\n"); pw.println("Installed VrListenerService components:"); int userId = mCurrentVrModeUser; @@ -479,6 +443,16 @@ public class VrManagerService extends SystemService implements EnabledComponentC pw.println(n.flattenToString()); } } + pw.println("Attached persistent mode listeners:"); + if (mPersistentVrStateListeners == null || + mPersistentVrStateListeners.size() == 0) { + pw.println("None"); + } else { + for (PersistentVrStateListener l : mPersistentVrStateListeners) { + pw.print(tab); + pw.println("listener: " + l); + } + } pw.println("\n"); pw.println("********* End of VrManagerService Dump *********"); } @@ -533,8 +507,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC } @Override - public void addPersistentVrModeStateListener(IPersistentVrStateCallbacks listener) { - VrManagerService.this.addPersistentStateCallback(listener); + public void addPersistentVrModeStateListener(PersistentVrStateListener listener) { + VrManagerService.this.addPersistentVrModeStateListener(listener); } } @@ -1110,6 +1084,12 @@ public class VrManagerService extends SystemService implements EnabledComponentC (mPersistentVrModeEnabled) ? 1 : 0, 0)); } + private void addPersistentVrModeStateListener(PersistentVrStateListener listener) { + synchronized (mLock) { + mPersistentVrStateListeners.add(listener); + } + } + private int hasVrPackage(@NonNull ComponentName targetPackageName, int userId) { synchronized (mLock) { return mComponentObserver.isValid(targetPackageName, userId); @@ -1131,19 +1111,11 @@ public class VrManagerService extends SystemService implements EnabledComponentC */ private void addStateCallback(IVrStateCallbacks cb) { - mVrStateRemoteCallbacks.register(cb); + mRemoteCallbacks.register(cb); } private void removeStateCallback(IVrStateCallbacks cb) { - mVrStateRemoteCallbacks.unregister(cb); - } - - private void addPersistentStateCallback(IPersistentVrStateCallbacks cb) { - mPersistentVrStateRemoteCallbacks.register(cb); - } - - private void removePersistentStateCallback(IPersistentVrStateCallbacks cb) { - mPersistentVrStateRemoteCallbacks.unregister(cb); + mRemoteCallbacks.unregister(cb); } private boolean getVrMode() { -- cgit v1.2.3-59-g8ed1b