diff options
| author | 2016-06-15 21:09:31 +0000 | |
|---|---|---|
| committer | 2016-06-15 21:09:33 +0000 | |
| commit | 9a31e8be4873251fff535e4cf35ac25c42b647fd (patch) | |
| tree | 58c4dcd4acc27f2852d48388f85097cc0343dcda | |
| parent | 07a375186e9c5f4417d8f106a2f1962a7524d9c8 (diff) | |
| parent | c3d8a529c69b754fbd77231d8fd480db94763143 (diff) | |
Merge "Send VR mode notification to AR app on context hub" into nyc-dev
| -rw-r--r-- | core/java/android/hardware/location/ContextHubService.java | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/core/java/android/hardware/location/ContextHubService.java b/core/java/android/hardware/location/ContextHubService.java index 8176189dffa0..43e596fe5566 100644 --- a/core/java/android/hardware/location/ContextHubService.java +++ b/core/java/android/hardware/location/ContextHubService.java @@ -21,12 +21,15 @@ import android.content.Context; import android.content.pm.PackageManager; import android.os.RemoteCallbackList; import android.os.RemoteException; +import android.os.ServiceManager; +import android.service.vr.IVrManager; +import android.service.vr.IVrStateCallbacks; import android.util.Log; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; /** * @hide @@ -57,8 +60,11 @@ public class ContextHubService extends IContextHubService.Stub { private static final int OS_APP_INSTANCE = -1; + private static final long APP_ID_ACTIVITY_RECOGNITION = 0x476f6f676c001000L; + private final Context mContext; - private final HashMap<Integer, NanoAppInstanceInfo> mNanoAppHash = new HashMap<>(); + private final ConcurrentHashMap<Integer, NanoAppInstanceInfo> mNanoAppHash = + new ConcurrentHashMap<>(); private final ContextHubInfo[] mContextHubInfo; private final RemoteCallbackList<IContextHubCallback> mCallbacksList = new RemoteCallbackList<>(); @@ -66,6 +72,18 @@ public class ContextHubService extends IContextHubService.Stub { private native int nativeSendMessage(int[] header, byte[] data); private native ContextHubInfo[] nativeInitialize(); + private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() { + @Override + public void onVrStateChanged(boolean enabled) { + for (NanoAppInstanceInfo app : mNanoAppHash.values()) { + if (app.getAppId() == APP_ID_ACTIVITY_RECOGNITION) { + sendVrStateChangeMessageToApp(app, enabled); + break; + } + } + } + }; + public ContextHubService(Context context) { mContext = context; mContextHubInfo = nativeInitialize(); @@ -74,6 +92,18 @@ public class ContextHubService extends IContextHubService.Stub { Log.d(TAG, "ContextHub[" + i + "] id: " + mContextHubInfo[i].getId() + ", name: " + mContextHubInfo[i].getName()); } + + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_VR_MODE)) { + IVrManager vrManager = + IVrManager.Stub.asInterface(ServiceManager.getService("vrmanager")); + if (vrManager != null) { + try { + vrManager.registerListener(mVrStateCallbacks); + } catch (RemoteException e) { + Log.e(TAG, "VR state listener registration failed", e); + } + } + } } @Override @@ -277,4 +307,19 @@ public class ContextHubService extends IContextHubService.Stub { return 0; } + + private void sendVrStateChangeMessageToApp(NanoAppInstanceInfo app, boolean vrModeEnabled) { + int[] msgHeader = new int[MSG_HEADER_SIZE]; + msgHeader[MSG_FIELD_TYPE] = 0; + msgHeader[MSG_FIELD_VERSION] = 0; + msgHeader[MSG_FIELD_HUB_HANDLE] = ANY_HUB; + msgHeader[MSG_FIELD_APP_INSTANCE] = app.getHandle(); + + byte[] data = new byte[1]; + data[0] = (byte) ((vrModeEnabled) ? 1 : 0); + int ret = nativeSendMessage(msgHeader, data); + if (ret != 0) { + Log.e(TAG, "Couldn't send VR state change notification (" + ret + ")!"); + } + } } |