Add a VR listener service.
Bug: 22855417
Bug: 26724891
Bug: 27364145
- Add an API for VrListenerService, which is bound/unbound
from the framework when the system VR mode changes.
- Allow only a single bound VrListenerService at a time.
- Monitor allowed VrListenerService implementations from
VrManagerService and evict services as needed when packages,
users, or settings change.
- Remove previous VR functionality in NotificationListenerService.
- Add component target to Activity#setVrMode to allow
explicit selection of the running VrListenerService from
the current VR activity.
Change-Id: I776335f4441be0e793d3126f2d16faf86a8c621a
diff --git a/Android.mk b/Android.mk
index 3ac5889..44c88a0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -241,6 +241,7 @@
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/IVrListener.aidl \
core/java/android/print/ILayoutResultCallback.aidl \
core/java/android/print/IPrinterDiscoveryObserver.aidl \
core/java/android/print/IPrintDocumentAdapter.aidl \
diff --git a/api/current.txt b/api/current.txt
index 799ad0f..f0d5e04 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -38,6 +38,7 @@
field public static final java.lang.String BIND_TV_INPUT = "android.permission.BIND_TV_INPUT";
field public static final java.lang.String BIND_VOICE_INTERACTION = "android.permission.BIND_VOICE_INTERACTION";
field public static final java.lang.String BIND_VPN_SERVICE = "android.permission.BIND_VPN_SERVICE";
+ field public static final java.lang.String BIND_VR_LISTENER_SERVICE = "android.permission.BIND_VR_LISTENER_SERVICE";
field public static final java.lang.String BIND_WALLPAPER = "android.permission.BIND_WALLPAPER";
field public static final java.lang.String BLUETOOTH = "android.permission.BLUETOOTH";
field public static final java.lang.String BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN";
@@ -3604,7 +3605,7 @@
method public deprecated void setTitleColor(int);
method public void setVisible(boolean);
method public final void setVolumeControlStream(int);
- method public void setVrMode(boolean);
+ method public void setVrModeEnabled(boolean, android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
method public boolean shouldShowRequestPermissionRationale(java.lang.String);
method public boolean shouldUpRecreateTask(android.content.Intent);
method public boolean showAssist(android.os.Bundle);
@@ -32169,6 +32170,7 @@
field public static final java.lang.String ACTION_VOICE_CONTROL_BATTERY_SAVER_MODE = "android.settings.VOICE_CONTROL_BATTERY_SAVER_MODE";
field public static final java.lang.String ACTION_VOICE_CONTROL_DO_NOT_DISTURB_MODE = "android.settings.VOICE_CONTROL_DO_NOT_DISTURB_MODE";
field public static final java.lang.String ACTION_VOICE_INPUT_SETTINGS = "android.settings.VOICE_INPUT_SETTINGS";
+ field public static final java.lang.String ACTION_VR_LISTENER_SETTINGS = "android.settings.VR_LISTENER_SETTINGS";
field public static final java.lang.String ACTION_WIFI_IP_SETTINGS = "android.settings.WIFI_IP_SETTINGS";
field public static final java.lang.String ACTION_WIFI_SETTINGS = "android.settings.WIFI_SETTINGS";
field public static final java.lang.String ACTION_WIRELESS_SETTINGS = "android.settings.WIRELESS_SETTINGS";
@@ -34486,7 +34488,6 @@
method public static void requestRebind(android.content.ComponentName) throws android.os.RemoteException;
method public final void requestUnbind() throws android.os.RemoteException;
method public final void setNotificationsShown(java.lang.String[]);
- field public static final java.lang.String CATEGORY_VR_NOTIFICATIONS = "android.intent.category.vr.notifications";
field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
field public static final int INTERRUPTION_FILTER_ALARMS = 4; // 0x4
field public static final int INTERRUPTION_FILTER_ALL = 1; // 0x1
@@ -34781,6 +34782,17 @@
}
+package android.service.vr {
+
+ public abstract class VrListenerService extends android.app.Service {
+ ctor public VrListenerService();
+ method public static final boolean isVrModePackageEnabled(android.content.Context, android.content.ComponentName);
+ method public android.os.IBinder onBind(android.content.Intent);
+ field public static final java.lang.String SERVICE_INTERFACE = "android.service.vr.VrListenerService";
+ }
+
+}
+
package android.service.wallpaper {
public abstract class WallpaperService extends android.app.Service {
diff --git a/api/system-current.txt b/api/system-current.txt
index 9a84d1a..82ea797 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -52,6 +52,7 @@
field public static final java.lang.String BIND_TV_INPUT = "android.permission.BIND_TV_INPUT";
field public static final java.lang.String BIND_VOICE_INTERACTION = "android.permission.BIND_VOICE_INTERACTION";
field public static final java.lang.String BIND_VPN_SERVICE = "android.permission.BIND_VPN_SERVICE";
+ field public static final java.lang.String BIND_VR_LISTENER_SERVICE = "android.permission.BIND_VR_LISTENER_SERVICE";
field public static final java.lang.String BIND_WALLPAPER = "android.permission.BIND_WALLPAPER";
field public static final java.lang.String BLUETOOTH = "android.permission.BLUETOOTH";
field public static final java.lang.String BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN";
@@ -3721,7 +3722,7 @@
method public deprecated void setTitleColor(int);
method public void setVisible(boolean);
method public final void setVolumeControlStream(int);
- method public void setVrMode(boolean);
+ method public void setVrModeEnabled(boolean, android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
method public boolean shouldShowRequestPermissionRationale(java.lang.String);
method public boolean shouldUpRecreateTask(android.content.Intent);
method public boolean showAssist(android.os.Bundle);
@@ -34656,6 +34657,7 @@
field public static final java.lang.String ACTION_VOICE_CONTROL_BATTERY_SAVER_MODE = "android.settings.VOICE_CONTROL_BATTERY_SAVER_MODE";
field public static final java.lang.String ACTION_VOICE_CONTROL_DO_NOT_DISTURB_MODE = "android.settings.VOICE_CONTROL_DO_NOT_DISTURB_MODE";
field public static final java.lang.String ACTION_VOICE_INPUT_SETTINGS = "android.settings.VOICE_INPUT_SETTINGS";
+ field public static final java.lang.String ACTION_VR_LISTENER_SETTINGS = "android.settings.VR_LISTENER_SETTINGS";
field public static final java.lang.String ACTION_WIFI_IP_SETTINGS = "android.settings.WIFI_IP_SETTINGS";
field public static final java.lang.String ACTION_WIFI_SETTINGS = "android.settings.WIFI_SETTINGS";
field public static final java.lang.String ACTION_WIRELESS_SETTINGS = "android.settings.WIRELESS_SETTINGS";
@@ -37013,7 +37015,6 @@
method public final void setNotificationsShown(java.lang.String[]);
method public final void setOnNotificationPostedTrim(int);
method public void unregisterAsSystemService() throws android.os.RemoteException;
- field public static final java.lang.String CATEGORY_VR_NOTIFICATIONS = "android.intent.category.vr.notifications";
field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
field public static final int INTERRUPTION_FILTER_ALARMS = 4; // 0x4
field public static final int INTERRUPTION_FILTER_ALL = 1; // 0x1
@@ -37366,6 +37367,17 @@
}
+package android.service.vr {
+
+ public abstract class VrListenerService extends android.app.Service {
+ ctor public VrListenerService();
+ method public static final boolean isVrModePackageEnabled(android.content.Context, android.content.ComponentName);
+ method public android.os.IBinder onBind(android.content.Intent);
+ field public static final java.lang.String SERVICE_INTERFACE = "android.service.vr.VrListenerService";
+ }
+
+}
+
package android.service.wallpaper {
public abstract class WallpaperService extends android.app.Service {
diff --git a/api/test-current.txt b/api/test-current.txt
index f18f4e1..cdfdef4 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -38,6 +38,7 @@
field public static final java.lang.String BIND_TV_INPUT = "android.permission.BIND_TV_INPUT";
field public static final java.lang.String BIND_VOICE_INTERACTION = "android.permission.BIND_VOICE_INTERACTION";
field public static final java.lang.String BIND_VPN_SERVICE = "android.permission.BIND_VPN_SERVICE";
+ field public static final java.lang.String BIND_VR_LISTENER_SERVICE = "android.permission.BIND_VR_LISTENER_SERVICE";
field public static final java.lang.String BIND_WALLPAPER = "android.permission.BIND_WALLPAPER";
field public static final java.lang.String BLUETOOTH = "android.permission.BLUETOOTH";
field public static final java.lang.String BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN";
@@ -3604,7 +3605,7 @@
method public deprecated void setTitleColor(int);
method public void setVisible(boolean);
method public final void setVolumeControlStream(int);
- method public void setVrMode(boolean);
+ method public void setVrModeEnabled(boolean, android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
method public boolean shouldShowRequestPermissionRationale(java.lang.String);
method public boolean shouldUpRecreateTask(android.content.Intent);
method public boolean showAssist(android.os.Bundle);
@@ -32184,6 +32185,7 @@
field public static final java.lang.String ACTION_VOICE_CONTROL_BATTERY_SAVER_MODE = "android.settings.VOICE_CONTROL_BATTERY_SAVER_MODE";
field public static final java.lang.String ACTION_VOICE_CONTROL_DO_NOT_DISTURB_MODE = "android.settings.VOICE_CONTROL_DO_NOT_DISTURB_MODE";
field public static final java.lang.String ACTION_VOICE_INPUT_SETTINGS = "android.settings.VOICE_INPUT_SETTINGS";
+ field public static final java.lang.String ACTION_VR_LISTENER_SETTINGS = "android.settings.VR_LISTENER_SETTINGS";
field public static final java.lang.String ACTION_WIFI_IP_SETTINGS = "android.settings.WIFI_IP_SETTINGS";
field public static final java.lang.String ACTION_WIFI_SETTINGS = "android.settings.WIFI_SETTINGS";
field public static final java.lang.String ACTION_WIRELESS_SETTINGS = "android.settings.WIRELESS_SETTINGS";
@@ -34503,7 +34505,6 @@
method public static void requestRebind(android.content.ComponentName) throws android.os.RemoteException;
method public final void requestUnbind() throws android.os.RemoteException;
method public final void setNotificationsShown(java.lang.String[]);
- field public static final java.lang.String CATEGORY_VR_NOTIFICATIONS = "android.intent.category.vr.notifications";
field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
field public static final int INTERRUPTION_FILTER_ALARMS = 4; // 0x4
field public static final int INTERRUPTION_FILTER_ALL = 1; // 0x1
@@ -34798,6 +34799,17 @@
}
+package android.service.vr {
+
+ public abstract class VrListenerService extends android.app.Service {
+ ctor public VrListenerService();
+ method public static final boolean isVrModePackageEnabled(android.content.Context, android.content.ComponentName);
+ method public android.os.IBinder onBind(android.content.Intent);
+ field public static final java.lang.String SERVICE_INTERFACE = "android.service.vr.VrListenerService";
+ }
+
+}
+
package android.service.wallpaper {
public abstract class WallpaperService extends android.app.Service {
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index b87e9fa2..6b67b95 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -6177,14 +6177,24 @@
/**
* Enable or disable virtual reality (VR) mode.
*
- * <p>VR mode is a hint to Android system services to switch to modes optimized for
- * high-performance stereoscopic rendering.</p>
+ * <p>VR mode is a hint to Android system services to switch to a mode optimized for
+ * high-performance stereoscopic rendering. This mode will be enabled while this Activity has
+ * focus.</p>
*
* @param enabled {@code true} to enable this mode.
+ * @param requestedComponent the name of the component to use as a
+ * {@link android.service.vr.VrListenerService} while VR mode is enabled.
+ *
+ * @throws android.content.pm.PackageManager.NameNotFoundException;
*/
- public void setVrMode(boolean enabled) {
+ public void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent)
+ throws PackageManager.NameNotFoundException {
try {
- ActivityManagerNative.getDefault().setVrMode(mToken, enabled);
+ if (ActivityManagerNative.getDefault().setVrMode(mToken, enabled, requestedComponent)
+ != 0) {
+ throw new PackageManager.NameNotFoundException(
+ requestedComponent.flattenToString());
+ }
} catch (RemoteException e) {
// pass
}
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index a4e5b90..f64bf1d 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -3371,6 +3371,15 @@
}
}
+ /** {@hide} */
+ public boolean isVrModePackageEnabled(ComponentName component) {
+ try {
+ return ActivityManagerNative.getDefault().isVrModePackageEnabled(component);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
/**
* Perform a system dump of various state associated with the given application
* package name. This call blocks while the dump is being performed, so should
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index ff7f70d..6fbb430 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -2902,8 +2902,18 @@
data.enforceInterface(IActivityManager.descriptor);
final IBinder token = data.readStrongBinder();
final boolean enable = data.readInt() == 1;
- setVrMode(token, enable);
+ final ComponentName packageName = ComponentName.CREATOR.createFromParcel(data);
+ int res = setVrMode(token, enable, packageName);
reply.writeNoException();
+ reply.writeInt(res);
+ return true;
+ }
+ case IS_VR_PACKAGE_ENABLED_TRANSACTION: {
+ data.enforceInterface(IActivityManager.descriptor);
+ final ComponentName packageName = ComponentName.CREATOR.createFromParcel(data);
+ boolean res = isVrModePackageEnabled(packageName);
+ reply.writeNoException();
+ reply.writeInt(res ? 1 : 0);
return true;
}
case IS_APP_FOREGROUND_TRANSACTION: {
@@ -6247,16 +6257,34 @@
return res;
}
- public void setVrMode(IBinder token, boolean enabled) throws RemoteException {
+ public int setVrMode(IBinder token, boolean enabled, ComponentName packageName)
+ throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(token);
data.writeInt(enabled ? 1 : 0);
+ packageName.writeToParcel(data, 0);
mRemote.transact(SET_VR_MODE_TRANSACTION, data, reply, 0);
reply.readException();
+ int res = reply.readInt();
data.recycle();
reply.recycle();
+ return res;
+ }
+
+ public boolean isVrModePackageEnabled(ComponentName packageName)
+ throws RemoteException {
+ Parcel data = Parcel.obtain();
+ Parcel reply = Parcel.obtain();
+ data.writeInterfaceToken(IActivityManager.descriptor);
+ packageName.writeToParcel(data, 0);
+ mRemote.transact(IS_VR_PACKAGE_ENABLED_TRANSACTION, data, reply, 0);
+ reply.readException();
+ int res = reply.readInt();
+ data.recycle();
+ reply.recycle();
+ return res == 1;
}
@Override
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 70bff80..eadf497 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -33,6 +33,7 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
@@ -599,7 +600,10 @@
public void enterPictureInPicture(IBinder token) throws RemoteException;
- public void setVrMode(IBinder token, boolean enabled) throws RemoteException;
+ public int setVrMode(IBinder token, boolean enabled, ComponentName packageName)
+ throws RemoteException;
+
+ public boolean isVrModePackageEnabled(ComponentName packageName) throws RemoteException;
public boolean isAppForeground(int uid) throws RemoteException;
@@ -993,4 +997,5 @@
int SET_LENIENT_BACKGROUND_CHECK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+368;
int GET_MEMORY_TRIM_LEVEL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+369;
int RESIZE_PINNED_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 370;
+ int IS_VR_PACKAGE_ENABLED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 371;
}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index a40cf96..940ac48 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1254,6 +1254,19 @@
public static final String ACTION_SHOW_REMOTE_BUGREPORT_DIALOG
= "android.settings.SHOW_REMOTE_BUGREPORT_DIALOG";
+ /**
+ * Activity Action: Show VR listener settings.
+ * <p>
+ * Input: Nothing.
+ * <p>
+ * Output: Nothing.
+ *
+ * @see android.service.vr.VrListenerService
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_VR_LISTENER_SETTINGS
+ = "android.settings.VR_LISTENER_SETTINGS";
+
// End of Intent actions for Settings
/**
@@ -6041,6 +6054,14 @@
public static final String BRIGHTNESS_USE_TWILIGHT = "brightness_use_twilight";
/**
+ * Names of the service components that the current user has explicitly allowed to
+ * be a VR mode listener, separated by ':'.
+ *
+ * @hide
+ */
+ public static final String ENABLED_VR_LISTENERS = "enabled_vr_listeners";
+
+ /**
* This are the settings to be backed up.
*
* NOTE: Settings are backed up and restored in the order they appear
@@ -6067,6 +6088,7 @@
BACKUP_AUTO_RESTORE,
ENABLED_ACCESSIBILITY_SERVICES,
ENABLED_NOTIFICATION_LISTENERS,
+ ENABLED_VR_LISTENERS,
ENABLED_INPUT_METHODS,
TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
TOUCH_EXPLORATION_ENABLED,
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 73a890f..b8f9812 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -69,16 +69,6 @@
* <action android:name="android.service.notification.NotificationListenerService" />
* </intent-filter>
* </service></pre>
- * <p> Typically, while enabled in user settings, this service will be bound on boot or when a
- * settings change occurs that could affect whether this service should run. However, for some
- * system usage modes, the you may instead specify that this service is instead bound and unbound
- * in response to mode changes by including a category in the intent filter. Currently
- * supported categories are:
- * <ul>
- * <li>{@link #CATEGORY_VR_NOTIFICATIONS} - this service is bound when an Activity has enabled
- * VR mode. {@see android.app.Activity#setVrMode(boolean)}.</li>
- * </ul>
- * </p>
*/
public abstract class NotificationListenerService extends Service {
// TAG = "NotificationListenerService[MySubclass]"
@@ -195,17 +185,6 @@
public static final String SERVICE_INTERFACE
= "android.service.notification.NotificationListenerService";
- /**
- * If this category is declared in the application manifest for a service of this type, this
- * service will be bound when VR mode is enabled, and unbound when VR mode is disabled rather
- * than the normal lifecycle for a notification service.
- *
- * {@see android.app.Activity#setVrMode(boolean)}
- */
- @SdkConstant(SdkConstant.SdkConstantType.INTENT_CATEGORY)
- public static final String CATEGORY_VR_NOTIFICATIONS =
- "android.intent.category.vr.notifications";
-
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
diff --git a/core/java/android/service/vr/IVrListener.aidl b/core/java/android/service/vr/IVrListener.aidl
new file mode 100644
index 0000000..b7273ba
--- /dev/null
+++ b/core/java/android/service/vr/IVrListener.aidl
@@ -0,0 +1,22 @@
+/**
+ * Copyright (c) 2016, 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 IVrListener {
+
+}
\ No newline at end of file
diff --git a/core/java/android/service/vr/VrListenerService.java b/core/java/android/service/vr/VrListenerService.java
new file mode 100644
index 0000000..5f1f659
--- /dev/null
+++ b/core/java/android/service/vr/VrListenerService.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright (C) 2016 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;
+
+import android.annotation.NonNull;
+import android.annotation.SdkConstant;
+import android.app.ActivityManager;
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+
+/**
+ * A service that is bound from the system while running in virtual reality (VR) mode.
+ *
+ * <p>To extend this class, you must declare the service in your manifest file with
+ * the {@link android.Manifest.permission#BIND_VR_LISTENER_SERVICE} permission
+ * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p>
+ * <pre>
+ * <service android:name=".VrListener"
+ * android:label="@string/service_name"
+ * android:permission="android.permission.BIND_VR_LISTENER_SERVICE">
+ * <intent-filter>
+ * <action android:name="android.service.vr.VrListenerService" />
+ * </intent-filter>
+ * </service>
+ * </pre>
+ *
+ * <p>
+ * This service is bound when the system enters VR mode and is unbound when the system leaves VR
+ * mode.
+ * {@see android.app.Activity#setVrMode(boolean)}
+ * </p>
+ */
+public abstract class VrListenerService extends Service {
+
+ /**
+ * The {@link Intent} that must be declared as handled by the service.
+ */
+ @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
+ public static final String SERVICE_INTERFACE = "android.service.vr.VrListenerService";
+
+ /**
+ * @hide
+ */
+ public static class VrListenerBinder extends IVrListener.Stub {
+ }
+
+ private final VrListenerBinder mBinder = new VrListenerBinder();
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
+ /**
+ * Check if the given package is available to be enabled/disabled in VR mode settings.
+ *
+ * @param context the {@link Context} to use for looking up the requested component.
+ * @param requestedComponent the name of the component that implements
+ * {@link android.service.vr.VrListenerService} to check.
+ *
+ * @return {@code true} if this package is enabled in settings.
+ */
+ public static final boolean isVrModePackageEnabled(@NonNull Context context,
+ @NonNull ComponentName requestedComponent) {
+ ActivityManager am = context.getSystemService(ActivityManager.class);
+ if (am == null) {
+ return false;
+ }
+ return am.isVrModePackageEnabled(requestedComponent);
+ }
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 8f85d4a..a5136db 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2929,6 +2929,12 @@
<permission android:name="android.permission.WRITE_BLOCKED_NUMBERS"
android:protectionLevel="signature" />
+ <!-- Must be required by an {@link android.service.vr.VrListenerService}, to ensure that only
+ the system can bind to it.
+ <p>Protection level: signature -->
+ <permission android:name="android.permission.BIND_VR_LISTENER_SERVICE"
+ android:protectionLevel="signature" />
+
<application android:process="system"
android:persistent="true"
android:hasCode="false"
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index d8efd63..ee4e665 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -3135,6 +3135,8 @@
<!-- Label to show for a service that is running because it is observing
the user's notifications. -->
<string name="notification_listener_binding_label">Notification listener</string>
+ <!-- Label to show for a service that is running because the system is in VR mode. -->
+ <string name="vr_listener_binding_label">VR listener</string>
<!-- Label to show for a service that is running because it is providing conditions. -->
<string name="condition_provider_service_binding_label">Condition provider</string>
<!-- Label to show for a service that is running because it is observing and modifying the
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 15521e4..4c6f98c 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1842,6 +1842,7 @@
<java-symbol type="string" name="low_internal_storage_view_text_no_boot" />
<java-symbol type="string" name="low_internal_storage_view_title" />
<java-symbol type="string" name="notification_listener_binding_label" />
+ <java-symbol type="string" name="vr_listener_binding_label" />
<java-symbol type="string" name="condition_provider_service_binding_label" />
<java-symbol type="string" name="notification_assistant_binding_label" />
<java-symbol type="string" name="report" />
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index d89abf42..b79ce80 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -62,8 +62,9 @@
*/
private static final ArraySet<String> sBroadcastOnRestore;
static {
- sBroadcastOnRestore = new ArraySet<String>(3);
+ sBroadcastOnRestore = new ArraySet<String>(4);
sBroadcastOnRestore.add(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
+ sBroadcastOnRestore.add(Settings.Secure.ENABLED_VR_LISTENERS);
sBroadcastOnRestore.add(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
sBroadcastOnRestore.add(Settings.Secure.ENABLED_INPUT_METHODS);
}
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto
index f3140d2..65654a8 100644
--- a/proto/src/metrics_constants.proto
+++ b/proto/src/metrics_constants.proto
@@ -1953,8 +1953,10 @@
// a notification.
ACTION_TOUCH_GEAR = 333;
+ // Logs that the user has edited the enabled VR listeners.
+ VR_MANAGE_LISTENERS = 334;
+
// Add new aosp constants above this line.
// END OF AOSP CONSTANTS
-
}
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 037ec59..8a5e501 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -2156,15 +2156,20 @@
} break;
case VR_MODE_CHANGE_MSG: {
VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
- final boolean vrMode = msg.arg1 != 0;
- vrService.setVrMode(vrMode);
-
- if (mInVrMode != vrMode) {
- synchronized (ActivityManagerService.this) {
+ final ActivityRecord r = (ActivityRecord) msg.obj;
+ boolean vrMode;
+ ComponentName requestedPackage;
+ int userId;
+ synchronized (ActivityManagerService.this) {
+ vrMode = r.requestedVrComponent != null;
+ requestedPackage = r.requestedVrComponent;
+ userId = r.userId;
+ if (mInVrMode != vrMode) {
mInVrMode = vrMode;
mShowDialogs = shouldShowDialogs(mConfiguration, mInVrMode);
}
}
+ vrService.setVrMode(vrMode, requestedPackage, userId);
} break;
}
}
@@ -2937,7 +2942,7 @@
final void applyUpdateVrModeLocked(ActivityRecord r) {
mHandler.sendMessage(
- mHandler.obtainMessage(VR_MODE_CHANGE_MSG, (r.isVrActivity) ? 1 : 0, 0));
+ mHandler.obtainMessage(VR_MODE_CHANGE_MSG, 0, 0, r));
}
final void showAskCompatModeDialogLocked(ActivityRecord r) {
@@ -12030,25 +12035,51 @@
}
@Override
- public void setVrMode(IBinder token, boolean enabled) {
+ public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) {
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_VR_MODE)) {
throw new UnsupportedOperationException("VR mode not supported on this device!");
}
+ final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
+
+ ActivityRecord r;
+ synchronized (this) {
+ r = ActivityRecord.isInStackLocked(token);
+ }
+
+ if (r == null) {
+ throw new IllegalArgumentException();
+ }
+
+ int err;
+ if ((err = vrService.hasVrPackage(packageName, r.userId)) !=
+ VrManagerInternal.NO_ERROR) {
+ return err;
+ }
+
synchronized(this) {
- final ActivityRecord r = ActivityRecord.isInStackLocked(token);
- if (r == null) {
- throw new IllegalArgumentException();
- }
- r.isVrActivity = enabled;
+ r.requestedVrComponent = (enabled) ? packageName : null;
// Update associated state if this activity is currently focused
if (r == mFocusedActivity) {
applyUpdateVrModeLocked(r);
}
+ return 0;
}
}
+ @Override
+ public boolean isVrModePackageEnabled(ComponentName packageName) {
+ if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_VR_MODE)) {
+ throw new UnsupportedOperationException("VR mode not supported on this device!");
+ }
+
+ final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
+
+ return vrService.hasVrPackage(packageName, UserHandle.getCallingUserId()) ==
+ VrManagerInternal.NO_ERROR;
+ }
+
public boolean isTopActivityImmersive() {
enforceNotIsolatedCaller("startActivity");
synchronized (this) {
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index e430dad..2ea5d15 100755
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -123,7 +123,7 @@
final boolean stateNotNeeded; // As per ActivityInfo.flags
boolean fullscreen; // covers the full screen?
final boolean noDisplay; // activity is not displayed?
- final boolean componentSpecified; // did caller specifiy an explicit component?
+ final boolean componentSpecified; // did caller specify an explicit component?
final boolean rootVoiceInteraction; // was this the root activity of a voice interaction?
static final int APPLICATION_ACTIVITY_TYPE = 0;
@@ -190,7 +190,7 @@
boolean forceNewConfig; // force re-create with new config next time
int launchCount; // count of launches since last state
long lastLaunchTime; // time of last launch of this activity
- boolean isVrActivity; // is the activity running in VR mode?
+ ComponentName requestedVrComponent; // the requested component for handling VR mode.
ArrayList<ActivityContainer> mChildContainers = new ArrayList<>();
String stringName; // for caching of toString().
@@ -354,7 +354,11 @@
pw.print(" forceNewConfig="); pw.println(forceNewConfig);
pw.print(prefix); pw.print("mActivityType=");
pw.println(activityTypeToString(mActivityType));
- pw.print(prefix); pw.print("vrMode="); pw.println(isVrActivity);
+ if (requestedVrComponent != null) {
+ pw.print(prefix);
+ pw.print("requestedVrComponent=");
+ pw.println(requestedVrComponent);
+ }
if (displayStartTime != 0 || startTime != 0) {
pw.print(prefix); pw.print("displayStartTime=");
if (displayStartTime == 0) pw.print("0");
@@ -718,7 +722,6 @@
}
immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
- isVrActivity = (aInfo.flags & ActivityInfo.FLAG_ENABLE_VR_MODE) != 0;
} else {
realActivity = null;
taskAffinity = null;
@@ -730,7 +733,6 @@
noDisplay = false;
mActivityType = APPLICATION_ACTIVITY_TYPE;
immersive = false;
- isVrActivity = false;
}
}
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index 0d6e3e5..17313b6 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -16,6 +16,7 @@
package com.android.server.notification;
+import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@@ -301,7 +302,9 @@
* */
public void registerGuestService(ManagedServiceInfo guest) {
checkNotNull(guest.service);
- checkType(guest.service);
+ if (!checkType(guest.service)) {
+ throw new IllegalArgumentException();
+ }
if (registerServiceImpl(guest) != null) {
onServiceAdded(guest);
}
@@ -920,9 +923,9 @@
public static class UserProfiles {
// Profiles of the current user.
- private final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<UserInfo>();
+ private final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<>();
- public void updateCache(Context context) {
+ public void updateCache(@NonNull Context context) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (userManager != null) {
int currentUserId = ActivityManager.getCurrentUser();
@@ -954,12 +957,12 @@
}
}
- protected static class Config {
- String caption;
- String serviceInterface;
- String secureSettingName;
- String bindPermission;
- String settingsAction;
- int clientLabel;
+ public static class Config {
+ public String caption;
+ public String serviceInterface;
+ public String secureSettingName;
+ public String bindPermission;
+ public String settingsAction;
+ public int clientLabel;
}
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 3855579..881e8f0 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -128,10 +128,9 @@
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.notification.ManagedServices.ManagedServiceInfo;
-import com.android.server.notification.ManagedServices.UserProfiles;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
-import com.android.server.vr.VrStateListener;
+import com.android.server.notification.ManagedServices.UserProfiles;
import libcore.io.IoUtils;
@@ -220,7 +219,6 @@
StatusBarManagerInternal mStatusBar;
Vibrator mVibrator;
private VrManagerInternal mVrManagerInternal;
- private final NotificationVrListener mVrListener = new NotificationVrListener();
final IBinder mForegroundToken = new Binder();
private WorkerHandler mHandler;
@@ -856,14 +854,6 @@
}
}
- private final class NotificationVrListener extends VrStateListener {
- @Override
- public void onVrStateChanged(final boolean enabled) {
- mListeners.setCategoryState(NotificationListenerService.CATEGORY_VR_NOTIFICATIONS,
- enabled);
- }
- }
-
private SettingsObserver mSettingsObserver;
private ZenModeHelper mZenModeHelper;
@@ -1064,7 +1054,6 @@
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManagerInternal = getLocalService(AudioManagerInternal.class);
mVrManagerInternal = getLocalService(VrManagerInternal.class);
- mVrManagerInternal.registerListener(mVrListener);
mZenModeHelper.onSystemReady();
} else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
// This observer will force an update when observe is called, causing us to
diff --git a/services/core/java/com/android/server/utils/ManagedApplicationService.java b/services/core/java/com/android/server/utils/ManagedApplicationService.java
new file mode 100644
index 0000000..a645701
--- /dev/null
+++ b/services/core/java/com/android/server/utils/ManagedApplicationService.java
@@ -0,0 +1,220 @@
+/**
+ * Copyright (c) 2016, 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.utils;
+
+import android.annotation.NonNull;
+import android.app.PendingIntent;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.os.IBinder.DeathRecipient;
+import android.os.IInterface;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.util.Slog;
+
+import java.util.Objects;
+
+/**
+ * Manages the lifecycle of an application-provided service bound from system server.
+ *
+ * @hide
+ */
+public class ManagedApplicationService {
+ private final String TAG = getClass().getSimpleName();
+
+ private final Context mContext;
+ private final int mUserId;
+ private final ComponentName mComponent;
+ private final int mClientLabel;
+ private final String mSettingsAction;
+ private final BinderChecker mChecker;
+
+ private final DeathRecipient mDeathRecipient = new DeathRecipient() {
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ mBoundInterface = null;
+ }
+ }
+ };
+
+ private final Object mLock = new Object();
+
+ // State protected by mLock
+ private ServiceConnection mPendingConnection;
+ private ServiceConnection mConnection;
+ private IInterface mBoundInterface;
+
+
+ private ManagedApplicationService(final Context context, final ComponentName component,
+ final int userId, int clientLabel, String settingsAction,
+ BinderChecker binderChecker) {
+ mContext = context;
+ mComponent = component;
+ mUserId = userId;
+ mClientLabel = clientLabel;
+ mSettingsAction = settingsAction;
+ mChecker = binderChecker;
+ }
+
+ /**
+ * Implement to validate returned IBinder instance.
+ */
+ public interface BinderChecker {
+ IInterface asInterface(IBinder binder);
+ boolean checkType(IInterface service);
+ }
+
+ /**
+ * Create a new ManagedApplicationService object but do not yet bind to the user service.
+ *
+ * @param context a Context to use for binding the application service.
+ * @param component the {@link ComponentName} of the application service to bind.
+ * @param userId the user ID of user to bind the application service as.
+ * @param clientLabel the resource ID of a label displayed to the user indicating the
+ * binding service.
+ * @param settingsAction an action that can be used to open the Settings UI to enable/disable
+ * binding to these services.
+ * @param binderChecker an interface used to validate the returned binder object.
+ * @return a ManagedApplicationService instance.
+ */
+ public static ManagedApplicationService build(@NonNull final Context context,
+ @NonNull final ComponentName component, final int userId, @NonNull int clientLabel,
+ @NonNull String settingsAction, @NonNull BinderChecker binderChecker) {
+ return new ManagedApplicationService(context, component, userId, clientLabel,
+ settingsAction, binderChecker);
+ }
+
+ /**
+ * @return the user ID of the user that owns the bound service.
+ */
+ public int getUserId() {
+ return mUserId;
+ }
+
+ /**
+ * @return the component of the bound service.
+ */
+ public ComponentName getComponent() {
+ return mComponent;
+ }
+
+ /**
+ * Asynchronously unbind from the application service if the bound service component and user
+ * does not match the given signature.
+ *
+ * @param componentName the component that must match.
+ * @param userId the user ID that must match.
+ * @return {@code true} if not matching.
+ */
+ public boolean disconnectIfNotMatching(final ComponentName componentName, final int userId) {
+ if (matches(componentName, userId)) {
+ return false;
+ }
+ disconnect();
+ return true;
+ }
+
+ /**
+ * Asynchronously unbind from the application service if bound.
+ */
+ public void disconnect() {
+ synchronized (mLock) {
+ // Wipe out pending connections
+ mPendingConnection = null;
+
+ // Unbind existing connection, if it exists
+ if (mConnection != null) {
+ mContext.unbindService(mConnection);
+ mConnection = null;
+ }
+
+ mBoundInterface = null;
+ }
+ }
+
+ /**
+ * Asynchronously bind to the application service if not bound.
+ */
+ public void connect() {
+ synchronized (mLock) {
+ if (mConnection != null || mPendingConnection != null) {
+ // We're already connected or are trying to connect
+ return;
+ }
+
+ final PendingIntent pendingIntent = PendingIntent.getActivity(
+ mContext, 0, new Intent(mSettingsAction), 0);
+ final Intent intent = new Intent().setComponent(mComponent).
+ putExtra(Intent.EXTRA_CLIENT_LABEL, mClientLabel).
+ putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
+
+ final ServiceConnection serviceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
+ synchronized (mLock) {
+ if (mPendingConnection == this) {
+ // No longer pending, remove from pending connection
+ mPendingConnection = null;
+ mConnection = this;
+ } else {
+ // Service connection wasn't pending, must have been disconnected
+ mContext.unbindService(this);
+ }
+
+ try {
+ iBinder.linkToDeath(mDeathRecipient, 0);
+ mBoundInterface = mChecker.asInterface(iBinder);
+ if (!mChecker.checkType(mBoundInterface)) {
+ // Received an invalid binder, disconnect
+ mContext.unbindService(this);
+ mBoundInterface = null;
+ }
+ } catch (RemoteException e) {
+ // DOA
+ Slog.w(TAG, "Unable to bind service: " + intent, e);
+ mBoundInterface = null;
+ }
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName componentName) {
+ Slog.w(TAG, "Service disconnected: " + intent);
+ }
+ };
+
+ mPendingConnection = serviceConnection;
+
+ try {
+ if (!mContext.bindServiceAsUser(intent, serviceConnection,
+ Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
+ new UserHandle(mUserId))) {
+ Slog.w(TAG, "Unable to bind service: " + intent);
+ }
+ } catch (SecurityException e) {
+ Slog.w(TAG, "Unable to bind service: " + intent, e);
+ }
+ }
+ }
+
+ private boolean matches(final ComponentName component, final int userId) {
+ return Objects.equals(mComponent, component) && mUserId == userId;
+ }
+}
diff --git a/services/core/java/com/android/server/vr/EnabledComponentsObserver.java b/services/core/java/com/android/server/vr/EnabledComponentsObserver.java
new file mode 100644
index 0000000..1363fb9
--- /dev/null
+++ b/services/core/java/com/android/server/vr/EnabledComponentsObserver.java
@@ -0,0 +1,282 @@
+/**
+ * Copyright (C) 2016 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;
+
+import android.annotation.NonNull;
+import android.app.ActivityManager;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.pm.UserInfo;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.ArraySet;
+import android.util.Slog;
+import android.util.SparseArray;
+
+import com.android.internal.content.PackageMonitor;
+import com.android.server.vr.SettingsObserver.SettingChangeListener;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Detects changes in packages, settings, and current users that may affect whether components
+ * implementing a given service can be run.
+ *
+ * @hide
+ */
+public class EnabledComponentsObserver implements SettingChangeListener {
+
+ private static final String TAG = EnabledComponentsObserver.class.getSimpleName();
+ private static final String ENABLED_SERVICES_SEPARATOR = ":";
+
+ public static final int NO_ERROR = 0;
+ public static final int DISABLED = -1;
+ public static final int NOT_INSTALLED = -2;
+
+ private final Object mLock;
+ private final Context mContext;
+ private final String mSettingName;
+ private final String mServiceName;
+ private final String mServicePermission;
+ private final SparseArray<ArraySet<ComponentName>> mInstalledSet = new SparseArray<>();
+ private final SparseArray<ArraySet<ComponentName>> mEnabledSet = new SparseArray<>();
+ private final Set<EnabledComponentChangeListener> mEnabledComponentListeners = new ArraySet<>();
+
+ /**
+ * Implement this to receive callbacks when relevant changes to the allowed components occur.
+ */
+ public interface EnabledComponentChangeListener {
+
+ /**
+ * Called when a change in the allowed components occurs.
+ */
+ void onEnabledComponentChanged();
+ }
+
+ private EnabledComponentsObserver(@NonNull Context context, @NonNull String settingName,
+ @NonNull String servicePermission, @NonNull String serviceName, @NonNull Object lock,
+ @NonNull Collection<EnabledComponentChangeListener> listeners) {
+ mLock = lock;
+ mContext = context;
+ mSettingName = settingName;
+ mServiceName = serviceName;
+ mServicePermission = servicePermission;
+ mEnabledComponentListeners.addAll(listeners);
+ }
+
+ /**
+ * Create a EnabledComponentObserver instance.
+ *
+ * @param context the context to query for changes.
+ * @param handler a handler to receive lifecycle events from system services on.
+ * @param settingName the name of a setting to monitor for a list of enabled components.
+ * @param looper a {@link Looper} to use for receiving package callbacks.
+ * @param servicePermission the permission required by the components to be bound.
+ * @param serviceName the intent action implemented by the tracked components.
+ * @param lock a lock object used to guard instance state in all callbacks and method calls.
+ * @return an EnableComponentObserver instance.
+ */
+ public static EnabledComponentsObserver build(@NonNull Context context,
+ @NonNull Handler handler, @NonNull String settingName, @NonNull Looper looper,
+ @NonNull String servicePermission, @NonNull String serviceName,
+ @NonNull final Object lock,
+ @NonNull Collection<EnabledComponentChangeListener> listeners) {
+
+ SettingsObserver s = SettingsObserver.build(context, handler, settingName);
+
+ final EnabledComponentsObserver o = new EnabledComponentsObserver(context, settingName,
+ servicePermission, serviceName, lock, listeners);
+
+ PackageMonitor packageMonitor = new PackageMonitor() {
+ @Override
+ public void onSomePackagesChanged() {
+ o.onPackagesChanged();
+
+ }
+
+ @Override
+ public void onPackageDisappeared(String packageName, int reason) {
+ o.onPackagesChanged();
+
+ }
+
+ @Override
+ public void onPackageModified(String packageName) {
+ o.onPackagesChanged();
+
+ }
+
+ @Override
+ public boolean onHandleForceStop(Intent intent, String[] packages, int uid,
+ boolean doit) {
+ o.onPackagesChanged();
+
+ return super.onHandleForceStop(intent, packages, uid, doit);
+ }
+ };
+
+ packageMonitor.register(context, looper, UserHandle.ALL, true);
+
+ s.addListener(o);
+
+ return o;
+
+ }
+
+ public void onPackagesChanged() {
+ rebuildAll();
+ }
+
+ @Override
+ public void onSettingChanged() {
+ rebuildAll();
+ }
+
+ @Override
+ public void onSettingRestored(String prevValue, String newValue, int userId) {
+ rebuildAll();
+ }
+
+ public void onUsersChanged() {
+ rebuildAll();
+ }
+
+ /**
+ * Rebuild the sets of allowed components for each current user profile.
+ */
+ public void rebuildAll() {
+ synchronized (mLock) {
+ mInstalledSet.clear();
+ mEnabledSet.clear();
+ final int[] userIds = getCurrentProfileIds();
+ for (int i : userIds) {
+ ArraySet<ComponentName> implementingPackages = loadComponentNamesForUser(i);
+ ArraySet<ComponentName> packagesFromSettings =
+ loadComponentNamesFromSetting(mSettingName, i);
+ packagesFromSettings.retainAll(implementingPackages);
+
+ mInstalledSet.put(i, implementingPackages);
+ mEnabledSet.put(i, packagesFromSettings);
+
+ }
+ }
+ sendSettingChanged();
+ }
+
+ /**
+ * Check whether a given component is present and enabled for the given user.
+ *
+ * @param component the component to check.
+ * @param userId the user ID for the component to check.
+ * @return {@code true} if present and enabled.
+ */
+ public int isValid(ComponentName component, int userId) {
+ synchronized (mLock) {
+ ArraySet<ComponentName> installedComponents = mInstalledSet.get(userId);
+ if (installedComponents == null || !installedComponents.contains(component)) {
+ return NOT_INSTALLED;
+ }
+ ArraySet<ComponentName> validComponents = mEnabledSet.get(userId);
+ if (validComponents == null || !validComponents.contains(component)) {
+ return DISABLED;
+ }
+ return NO_ERROR;
+ }
+ }
+
+ private int[] getCurrentProfileIds() {
+ UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ if (userManager == null) {
+ return null;
+ }
+ int currentUserId = ActivityManager.getCurrentUser();
+ List<UserInfo> profiles = userManager.getProfiles(currentUserId);
+ if (profiles == null) {
+ return null;
+ }
+ final int s = profiles.size();
+ int[] userIds = new int[s];
+ int ctr = 0;
+ for (UserInfo info : profiles) {
+ userIds[ctr++] = info.id;
+ }
+ return userIds;
+ }
+
+ private ArraySet<ComponentName> loadComponentNamesForUser(int userId) {
+ ArraySet<ComponentName> installed = new ArraySet<>();
+ PackageManager pm = mContext.getPackageManager();
+ Intent queryIntent = new Intent(mServiceName);
+ List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
+ queryIntent,
+ PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
+ userId);
+ if (installedServices != null) {
+ for (int i = 0, count = installedServices.size(); i < count; i++) {
+ ResolveInfo resolveInfo = installedServices.get(i);
+ ServiceInfo info = resolveInfo.serviceInfo;
+
+ ComponentName component = new ComponentName(info.packageName, info.name);
+ if (!mServicePermission.equals(info.permission)) {
+ Slog.w(TAG, "Skipping service " + info.packageName + "/" + info.name
+ + ": it does not require the permission "
+ + mServicePermission);
+ continue;
+ }
+ installed.add(component);
+ }
+ }
+ return installed;
+ }
+
+ private ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
+ int userId) {
+ final ContentResolver cr = mContext.getContentResolver();
+ String settingValue = Settings.Secure.getStringForUser(
+ cr,
+ settingName,
+ userId);
+ if (TextUtils.isEmpty(settingValue))
+ return new ArraySet<>();
+ String[] restored = settingValue.split(ENABLED_SERVICES_SEPARATOR);
+ ArraySet<ComponentName> result = new ArraySet<>(restored.length);
+ for (int i = 0; i < restored.length; i++) {
+ ComponentName value = ComponentName.unflattenFromString(restored[i]);
+ if (null != value) {
+ result.add(value);
+ }
+ }
+ return result;
+ }
+
+ private void sendSettingChanged() {
+ for (EnabledComponentChangeListener l : mEnabledComponentListeners) {
+ l.onEnabledComponentChanged();
+ }
+ }
+
+}
diff --git a/services/core/java/com/android/server/vr/SettingsObserver.java b/services/core/java/com/android/server/vr/SettingsObserver.java
new file mode 100644
index 0000000..ce76863
--- /dev/null
+++ b/services/core/java/com/android/server/vr/SettingsObserver.java
@@ -0,0 +1,145 @@
+/**
+ * Copyright (C) 2016 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;
+
+import android.annotation.NonNull;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.ArraySet;
+
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Detects changes in a given setting.
+ *
+ * @hide
+ */
+public class SettingsObserver {
+
+ private final String mSecureSettingName;
+ private final BroadcastReceiver mSettingRestorReceiver;
+ private final ContentObserver mContentObserver;
+ private final Set<SettingChangeListener> mSettingsListeners = new ArraySet<>();
+
+ /**
+ * Implement this to receive callbacks when the setting tracked by this observer changes.
+ */
+ public interface SettingChangeListener {
+
+ /**
+ * Called when the tracked setting has changed.
+ */
+ void onSettingChanged();
+
+
+ /**
+ * Called when the tracked setting has been restored for a particular user.
+ *
+ * @param prevValue the previous value of the setting.
+ * @param newValue the new value of the setting.
+ * @param userId the user ID for which this setting has been restored.
+ */
+ void onSettingRestored(String prevValue, String newValue, int userId);
+ }
+
+ private SettingsObserver(@NonNull final Context context, @NonNull final Handler handler,
+ @NonNull final Uri settingUri, @NonNull final String secureSettingName) {
+
+ mSecureSettingName = secureSettingName;
+ mSettingRestorReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_SETTING_RESTORED.equals(intent.getAction())) {
+ String element = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
+ if (Objects.equals(element, secureSettingName)) {
+ String prevValue = intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE);
+ String newValue = intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE);
+ sendSettingRestored(prevValue, newValue, getSendingUserId());
+ }
+ }
+ }
+ };
+
+ mContentObserver = new ContentObserver(handler) {
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ if (uri == null || settingUri.equals(uri)) {
+ sendSettingChanged();
+ }
+ }
+ };
+
+ ContentResolver resolver = context.getContentResolver();
+ resolver.registerContentObserver(settingUri, false, mContentObserver,
+ UserHandle.USER_ALL);
+ }
+
+ /**
+ * Create a SettingsObserver instance.
+ *
+ * @param context the context to query for settings changes.
+ * @param handler the handler to use for a settings ContentObserver.
+ * @param settingName the setting to track.
+ * @return a SettingsObserver instance.
+ */
+ public static SettingsObserver build(@NonNull Context context, @NonNull Handler handler,
+ @NonNull String settingName) {
+ Uri settingUri = Settings.Secure.getUriFor(settingName);
+
+ return new SettingsObserver(context, handler, settingUri, settingName);
+ }
+
+ /**
+ * Add a listener for setting changes.
+ *
+ * @param listener a {@link SettingChangeListener} instance.
+ */
+ public void addListener(@NonNull SettingChangeListener listener) {
+ mSettingsListeners.add(listener);
+
+ }
+
+ /**
+ * Remove a listener for setting changes.
+ *
+ * @param listener a {@link SettingChangeListener} instance.
+ */
+ public void removeListener(@NonNull SettingChangeListener listener) {
+ mSettingsListeners.remove(listener);
+
+ }
+
+ private void sendSettingChanged() {
+ for (SettingChangeListener l : mSettingsListeners) {
+ l.onSettingChanged();
+ }
+ }
+
+ private void sendSettingRestored(final String prevValue, final String newValue, final int userId) {
+ for (SettingChangeListener l : mSettingsListeners) {
+ l.onSettingRestored(prevValue, newValue, userId);
+ }
+ }
+
+}
diff --git a/services/core/java/com/android/server/vr/VrManagerInternal.java b/services/core/java/com/android/server/vr/VrManagerInternal.java
index 42db364..6b5523f 100644
--- a/services/core/java/com/android/server/vr/VrManagerInternal.java
+++ b/services/core/java/com/android/server/vr/VrManagerInternal.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,14 +15,22 @@
*/
package com.android.server.vr;
+import android.annotation.NonNull;
+import android.content.ComponentName;
+
/**
- * VR mode local system service interface.
+ * Service for accessing the VR mode manager.
*
* @hide Only for use within system server.
*/
public abstract class VrManagerInternal {
/**
+ * The error code returned on success.
+ */
+ public static final int NO_ERROR = 0;
+
+ /**
* Return current VR mode state.
*
* @return {@code true} if VR mode is enabled.
@@ -33,8 +41,11 @@
* Set the current VR mode state.
*
* @param enabled {@code true} to enable VR mode.
+ * @param packageName The package name of the requested VrListenerService to bind.
+ * @param userId the user requesting the VrListenerService component.
*/
- public abstract void setVrMode(boolean enabled);
+ public abstract void setVrMode(boolean enabled, @NonNull ComponentName packageName,
+ int userId);
/**
* Add a listener for VR mode state changes.
@@ -43,13 +54,23 @@
* </p>
* @param listener the listener instance to add.
*/
- public abstract void registerListener(VrStateListener listener);
+ public abstract void registerListener(@NonNull VrStateListener listener);
/**
* Remove the listener from the current set of listeners.
*
* @param listener the listener to remove.
*/
- public abstract void unregisterListener(VrStateListener listener);
+ public abstract void unregisterListener(@NonNull VrStateListener listener);
+
+ /**
+ * Return NO_ERROR if the given package is installed on the device and enabled as a
+ * VrListenerService for the given current user, or a negative error code indicating a failure.
+ *
+ * @param packageName the name of the package to check, or null to select the default package.
+ * @return NO_ERROR if the given package is installed and is enabled, or a negative error code
+ * given in {@link android.service.vr.VrModeException} on failure.
+ */
+ public abstract int hasVrPackage(@NonNull ComponentName packageName, int userId);
}
diff --git a/services/core/java/com/android/server/vr/VrManagerService.java b/services/core/java/com/android/server/vr/VrManagerService.java
index 7611527..f5914faf 100644
--- a/services/core/java/com/android/server/vr/VrManagerService.java
+++ b/services/core/java/com/android/server/vr/VrManagerService.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,26 +16,53 @@
package com.android.server.vr;
import android.app.AppOpsManager;
+import android.annotation.NonNull;
import android.content.Context;
+import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Binder;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.IInterface;
+import android.os.Looper;
import android.os.UserHandle;
+import android.provider.Settings;
+import android.service.vr.IVrListener;
+import android.service.vr.VrListenerService;
import android.util.ArraySet;
import android.util.Slog;
+import com.android.internal.R;
import com.android.server.SystemService;
+import com.android.server.vr.EnabledComponentsObserver.EnabledComponentChangeListener;
+import com.android.server.utils.ManagedApplicationService;
+import com.android.server.utils.ManagedApplicationService.BinderChecker;
import java.util.ArrayList;
+import java.util.Set;
/**
- * Service tracking whether VR mode is active, and notifying listening system services of state
- * changes.
+ * Service tracking whether VR mode is active, and notifying listening services of state changes.
+ * <p/>
+ * Services running in system server may modify the state of VrManagerService via the interface in
+ * VrManagerInternal, and may register to receive callbacks when the system VR mode changes via the
+ * interface given in VrStateListener.
+ * <p/>
+ * Device vendors may choose to receive VR state changes by implementing the VR mode HAL, e.g.:
+ * hardware/libhardware/modules/vr
+ * <p/>
+ * In general applications may enable or disable VR mode by calling
+ * {@link android.app.Activity#setVrMode)}. An application may also implement a service to be run
+ * while in VR mode by implementing {@link android.service.vr.VrListenerService}.
*
- * {@hide}
+ * @see {@link android.service.vr.VrListenerService}
+ * @see {@link com.android.server.vr.VrManagerInternal}
+ * @see {@link com.android.server.vr.VrStateListener}
+ *
+ * @hide
*/
-public class VrManagerService extends SystemService {
+public class VrManagerService extends SystemService implements EnabledComponentChangeListener{
public static final String TAG = "VrManagerService";
@@ -46,9 +73,45 @@
private final IBinder mOverlayToken = new Binder();
+ // State protected by mLock
private boolean mVrModeEnabled = false;
- private ArraySet<VrStateListener> mListeners = new ArraySet<>();
+ private final Set<VrStateListener> mListeners = new ArraySet<>();
+ private EnabledComponentsObserver mComponentObserver;
+ private ManagedApplicationService mCurrentVrService;
+ private Context mContext;
+ private static final BinderChecker sBinderChecker = new BinderChecker() {
+ @Override
+ public IInterface asInterface(IBinder binder) {
+ return IVrListener.Stub.asInterface(binder);
+ }
+
+ @Override
+ public boolean checkType(IInterface service) {
+ return service instanceof IVrListener;
+ }
+ };
+
+ /**
+ * Called when a user, package, or setting changes that could affect whether or not the
+ * currently bound VrListenerService is changed.
+ */
+ @Override
+ public void onEnabledComponentChanged() {
+ synchronized (mLock) {
+ if (mCurrentVrService == null) {
+ return; // No active services
+ }
+
+ // There is an active service, update it if needed
+ updateCurrentVrServiceLocked(mVrModeEnabled, mCurrentVrService.getComponent(),
+ mCurrentVrService.getUserId());
+ }
+ }
+
+ /**
+ * Implementation of VrManagerInternal. Callable only from system services.
+ */
private final class LocalService extends VrManagerInternal {
@Override
public boolean isInVrMode() {
@@ -56,8 +119,8 @@
}
@Override
- public void setVrMode(boolean enabled) {
- VrManagerService.this.setVrMode(enabled);
+ public void setVrMode(boolean enabled, ComponentName packageName, int userId) {
+ VrManagerService.this.setVrMode(enabled, packageName, userId);
}
@Override
@@ -69,6 +132,11 @@
public void unregisterListener(VrStateListener listener) {
VrManagerService.this.removeListener(listener);
}
+
+ @Override
+ public int hasVrPackage(ComponentName packageName, int userId) {
+ return VrManagerService.this.hasVrPackage(packageName, userId);
+ }
}
public VrManagerService(Context context) {
@@ -79,36 +147,60 @@
public void onStart() {
synchronized(mLock) {
initializeNative();
+ mContext = getContext();
}
publishLocalService(VrManagerInternal.class, new LocalService());
}
- private void addListener(VrStateListener listener) {
- synchronized (mLock) {
- mListeners.add(listener);
- }
- }
+ @Override
+ public void onBootPhase(int phase) {
+ if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
+ synchronized (mLock) {
+ Looper looper = Looper.getMainLooper();
+ Handler handler = new Handler(looper);
+ ArrayList<EnabledComponentChangeListener> listeners = new ArrayList<>();
+ listeners.add(this);
+ mComponentObserver = EnabledComponentsObserver.build(mContext, handler,
+ Settings.Secure.ENABLED_VR_LISTENERS, looper,
+ android.Manifest.permission.BIND_VR_LISTENER_SERVICE,
+ VrListenerService.SERVICE_INTERFACE, mLock, listeners);
- private void removeListener(VrStateListener listener) {
- synchronized (mLock) {
- mListeners.remove(listener);
- }
- }
-
- private void setVrMode(boolean enabled) {
- synchronized (mLock) {
- if (mVrModeEnabled != enabled) {
- mVrModeEnabled = enabled;
- // Log mode change event.
- Slog.i(TAG, "VR mode " + ((mVrModeEnabled) ? "enabled" : "disabled"));
- setVrModeNative(mVrModeEnabled);
- updateOverlayStateLocked();
- onVrModeChangedLocked();
+ mComponentObserver.rebuildAll();
}
}
}
+ @Override
+ public void onStartUser(int userHandle) {
+ synchronized (mLock) {
+ mComponentObserver.onUsersChanged();
+ }
+ }
+
+ @Override
+ public void onSwitchUser(int userHandle) {
+ synchronized (mLock) {
+ mComponentObserver.onUsersChanged();
+ }
+
+ }
+
+ @Override
+ public void onStopUser(int userHandle) {
+ synchronized (mLock) {
+ mComponentObserver.onUsersChanged();
+ }
+
+ }
+
+ @Override
+ public void onCleanupUser(int userHandle) {
+ synchronized (mLock) {
+ mComponentObserver.onUsersChanged();
+ }
+ }
+
private void updateOverlayStateLocked() {
final long identity = Binder.clearCallingIdentity();
try {
@@ -122,18 +214,134 @@
}
}
+ /**
+ * Send VR mode changes (if the mode state has changed), and update the bound/unbound state of
+ * the currently selected VR listener service. If the component selected for the VR listener
+ * service has changed, unbind the previous listener and bind the new listener (if enabled).
+ * <p/>
+ * Note: Must be called while holding {@code mLock}.
+ *
+ * @param enabled new state for VR mode.
+ * @param component new component to be bound as a VR listener.
+ * @param userId user owning the component to be bound.
+ *
+ * @return {@code true} if the component/user combination specified is valid.
+ */
+ private boolean updateCurrentVrServiceLocked(boolean enabled,
+ @NonNull ComponentName component, int userId) {
+
+ // Always send mode change events.
+ changeVrModeLocked(enabled);
+
+ boolean validUserComponent = (mComponentObserver.isValid(component, userId) ==
+ EnabledComponentsObserver.NO_ERROR);
+
+ if (!enabled || !validUserComponent) {
+ // Unbind whatever is running
+ if (mCurrentVrService != null) {
+ Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + " for user " +
+ mCurrentVrService.getUserId());
+ mCurrentVrService.disconnect();
+ mCurrentVrService = null;
+ }
+ return validUserComponent;
+ }
+
+ if (mCurrentVrService != null) {
+ // Unbind any running service that doesn't match the component/user selection
+ if (mCurrentVrService.disconnectIfNotMatching(component, userId)) {
+ Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + " for user " +
+ mCurrentVrService.getUserId());
+ mCurrentVrService = VrManagerService.create(mContext, component, userId);
+ mCurrentVrService.connect();
+ Slog.i(TAG, "Connecting " + mCurrentVrService.getComponent() + " for user " +
+ mCurrentVrService.getUserId());
+ }
+ // The service with the correct component/user is bound
+ } else {
+ // Nothing was previously running, bind a new service
+ mCurrentVrService = VrManagerService.create(mContext, component, userId);
+ mCurrentVrService.connect();
+ Slog.i(TAG, "Connecting " + mCurrentVrService.getComponent() + " for user " +
+ mCurrentVrService.getUserId());
+ }
+
+ return validUserComponent;
+ }
+
+ /**
+ * Send VR mode change callbacks to HAL and system services if mode has actually changed.
+ * <p/>
+ * Note: Must be called while holding {@code mLock}.
+ *
+ * @param enabled new state of the VR mode.
+ */
+ private void changeVrModeLocked(boolean enabled) {
+ if (mVrModeEnabled != enabled) {
+ mVrModeEnabled = enabled;
+
+ // Log mode change event.
+ Slog.i(TAG, "VR mode " + ((mVrModeEnabled) ? "enabled" : "disabled"));
+ setVrModeNative(mVrModeEnabled);
+
+ updateOverlayStateLocked();
+ onVrModeChangedLocked();
+ }
+ }
+
+ /**
+ * Notify system services of VR mode change.
+ * <p/>
+ * Note: Must be called while holding {@code mLock}.
+ */
+ private void onVrModeChangedLocked() {
+ for (VrStateListener l : mListeners) {
+ l.onVrStateChanged(mVrModeEnabled);
+ }
+ }
+
+ /**
+ * Helper function for making ManagedApplicationService instances.
+ */
+ private static ManagedApplicationService create(@NonNull Context context,
+ @NonNull ComponentName component, int userId) {
+ return ManagedApplicationService.build(context, component, userId,
+ R.string.vr_listener_binding_label, Settings.ACTION_VR_LISTENER_SETTINGS,
+ sBinderChecker);
+ }
+
+ /*
+ * Implementation of VrManagerInternal calls. These are callable from system services.
+ */
+
+ private boolean setVrMode(boolean enabled, @NonNull ComponentName targetPackageName,
+ int userId) {
+ synchronized (mLock) {
+ return updateCurrentVrServiceLocked(enabled, targetPackageName, userId);
+ }
+ }
+
private boolean getVrMode() {
synchronized (mLock) {
return mVrModeEnabled;
}
}
- /**
- * Notify system services of VR mode change.
- */
- private void onVrModeChangedLocked() {
- for (VrStateListener l : mListeners) {
- l.onVrStateChanged(mVrModeEnabled);
+ private void addListener(VrStateListener listener) {
+ synchronized (mLock) {
+ mListeners.add(listener);
+ }
+ }
+
+ private void removeListener(VrStateListener listener) {
+ synchronized (mLock) {
+ mListeners.remove(listener);
+ }
+ }
+
+ private int hasVrPackage(@NonNull ComponentName targetPackageName, int userId) {
+ synchronized (mLock) {
+ return mComponentObserver.isValid(targetPackageName, userId);
}
}
}
diff --git a/services/core/java/com/android/server/vr/VrStateListener.java b/services/core/java/com/android/server/vr/VrStateListener.java
index b8af4b2..b0603c80 100644
--- a/services/core/java/com/android/server/vr/VrStateListener.java
+++ b/services/core/java/com/android/server/vr/VrStateListener.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,9 @@
package com.android.server.vr;
/**
- * Listener for state changes in VrManagerService,
+ * Listener for state changes in VrManagerService.
+ *
+ * @hide Only for use within system server.
*/
public abstract class VrStateListener {