Initial Commit
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using Oculus.Voice.Core.Bindings.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Core.Bindings.Android
|
||||
{
|
||||
public class AndroidServiceConnection : IConnection
|
||||
{
|
||||
private AndroidJavaObject mAssistantServiceConnection;
|
||||
|
||||
private string serviceFragmentClass;
|
||||
private string serviceGetter;
|
||||
|
||||
public bool IsConnected => null != mAssistantServiceConnection;
|
||||
|
||||
public AndroidJavaObject AssistantServiceConnection => mAssistantServiceConnection;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a connection manager of the given type
|
||||
/// </summary>
|
||||
/// <param name="serviceFragmentClassName">The fully qualified class name of the service fragment that will manage this connection</param>
|
||||
/// <param name="serviceGetterMethodName">The name of the method that will return an instance of the service</param>
|
||||
/// TODO: We should make the getBlahService simply getService() within each fragment implementation.
|
||||
public AndroidServiceConnection(string serviceFragmentClassName, string serviceGetterMethodName)
|
||||
{
|
||||
serviceFragmentClass = serviceFragmentClassName;
|
||||
serviceGetter = serviceGetterMethodName;
|
||||
}
|
||||
|
||||
public void Connect(string version)
|
||||
{
|
||||
if (null == mAssistantServiceConnection)
|
||||
{
|
||||
AndroidJNIHelper.debug = true;
|
||||
|
||||
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
||||
AndroidJavaObject activity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
|
||||
using (AndroidJavaClass assistantBackgroundFragment = new AndroidJavaClass(serviceFragmentClass))
|
||||
{
|
||||
mAssistantServiceConnection =
|
||||
assistantBackgroundFragment.CallStatic<AndroidJavaObject>("createAndAttach", activity, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
mAssistantServiceConnection.Call("detach");
|
||||
}
|
||||
|
||||
public AndroidJavaObject GetService()
|
||||
{
|
||||
return mAssistantServiceConnection.Call<AndroidJavaObject>(serviceGetter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85f4ff04745e1ab459e49eb38bc288b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Core.Bindings.Android
|
||||
{
|
||||
public class BaseAndroidConnectionImpl<T> where T : BaseServiceBinding
|
||||
{
|
||||
private string fragmentClassName;
|
||||
protected T service;
|
||||
protected readonly AndroidServiceConnection serviceConnection;
|
||||
|
||||
public bool IsConnected => serviceConnection.IsConnected;
|
||||
|
||||
public BaseAndroidConnectionImpl(string className)
|
||||
{
|
||||
fragmentClassName = className;
|
||||
serviceConnection = new AndroidServiceConnection(className, "getService");
|
||||
}
|
||||
|
||||
#region Service Connection
|
||||
|
||||
public virtual void Connect(string version)
|
||||
{
|
||||
serviceConnection.Connect(version);
|
||||
var serviceInstance = serviceConnection.GetService();
|
||||
if (null == serviceInstance)
|
||||
{
|
||||
throw new Exception("Unable to get service connection from " + fragmentClassName);
|
||||
}
|
||||
|
||||
service = (T) Activator.CreateInstance(typeof(T), serviceInstance);
|
||||
}
|
||||
|
||||
public virtual void Disconnect()
|
||||
{
|
||||
service.Shutdown();
|
||||
serviceConnection.Disconnect();
|
||||
service = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class BaseServiceBinding
|
||||
{
|
||||
protected AndroidJavaObject binding;
|
||||
|
||||
protected BaseServiceBinding(AndroidJavaObject sdkInstance)
|
||||
{
|
||||
binding = sdkInstance;
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
binding.Call("shutdown");
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa5e9cb2d6b763f4c983b82092bb192d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e17b7500d9de2e4fbb25afa6264094e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
using Oculus.Voice.Core.Bindings.Interfaces;
|
||||
using Oculus.Voice.Core.Utilities;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace Oculus.Voice.Core.Bindings.Android.PlatformLogger
|
||||
{
|
||||
public class VoiceSDKConsoleLoggerImpl : IVoiceSDKLogger
|
||||
{
|
||||
public bool IsUsingPlatformIntegration { get; set; }
|
||||
public string WitApplication { get; set; }
|
||||
public bool ShouldLogToConsole { get; set; }
|
||||
private static readonly string TAG = "VoiceSDKConsoleLogger";
|
||||
|
||||
private bool loggedFirstTranscriptionTime = false;
|
||||
public void LogInteractionStart(string requestId, string witApi)
|
||||
{
|
||||
if (!ShouldLogToConsole) return;
|
||||
loggedFirstTranscriptionTime = false;
|
||||
Debug.Log($"{TAG}: Interaction started with request ID: " + requestId);
|
||||
Debug.Log($"{TAG}: WitApi: " + witApi);
|
||||
Debug.Log($"{TAG}: request_start_time: " + DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
Debug.Log($"{TAG}: WitAppID: " + WitApplication);
|
||||
Debug.Log($"{TAG}: PackageName: " + Application.identifier);
|
||||
}
|
||||
|
||||
public void LogInteractionEndSuccess()
|
||||
{
|
||||
if (!ShouldLogToConsole) return;
|
||||
Debug.Log($"{TAG}: Interaction finished successfully");
|
||||
Debug.Log($"{TAG}: request_end_time: " + DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
}
|
||||
|
||||
public void LogInteractionEndFailure(string errorMessage)
|
||||
{
|
||||
if (!ShouldLogToConsole) return;
|
||||
Debug.Log($"{TAG}: Interaction finished with error: " + errorMessage);
|
||||
Debug.Log($"{TAG}: request_end_time: " + DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
}
|
||||
|
||||
public void LogInteractionPoint(string interactionPoint)
|
||||
{
|
||||
if (!ShouldLogToConsole) return;
|
||||
Debug.Log($"{TAG}: Interaction point: " + interactionPoint);
|
||||
Debug.Log($"{TAG}: {interactionPoint}_start_time: " + DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
}
|
||||
|
||||
public void LogAnnotation(string annotationKey, string annotationValue)
|
||||
{
|
||||
if (!ShouldLogToConsole) return;
|
||||
Debug.Log($"{TAG}: Logging key-value pair: {annotationKey}::{annotationValue}");
|
||||
}
|
||||
|
||||
public void LogFirstTranscriptionTime()
|
||||
{
|
||||
if (!loggedFirstTranscriptionTime)
|
||||
{
|
||||
loggedFirstTranscriptionTime = true;
|
||||
LogInteractionPoint("firstPartialTranscriptionTime");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbb89bbe77dad204f9e4a1322943320d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Core.Bindings.Android.PlatformLogger
|
||||
{
|
||||
public class VoiceSDKLoggerBinding : BaseServiceBinding
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public VoiceSDKLoggerBinding(AndroidJavaObject loggerInstance) : base(loggerInstance) {}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
binding.Call<bool>("connect");
|
||||
}
|
||||
|
||||
public void LogInteractionStart(string requestId, string startTime)
|
||||
{
|
||||
binding.Call("logInteractionStart", requestId, startTime);
|
||||
}
|
||||
|
||||
public void LogInteractionEndSuccess(string endTime)
|
||||
{
|
||||
binding.Call("logInteractionEndSuccess", endTime);
|
||||
}
|
||||
|
||||
public void LogInteractionEndFailure(string endTime, string errorMessage)
|
||||
{
|
||||
binding.Call("logInteractionEndFailure", endTime, errorMessage);
|
||||
}
|
||||
|
||||
public void LogInteractionPoint(string interactionPoint, string time)
|
||||
{
|
||||
binding.Call("logInteractionPoint", interactionPoint, time);
|
||||
}
|
||||
|
||||
public void LogAnnotation(string annotationKey, string annotationValue)
|
||||
{
|
||||
binding.Call("logAnnotation", annotationKey, annotationValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02f219e3a02e4055b3df9be4f5786e5a
|
||||
timeCreated: 1652919643
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using Oculus.Voice.Core.Bindings.Interfaces;
|
||||
using Oculus.Voice.Core.Utilities;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace Oculus.Voice.Core.Bindings.Android.PlatformLogger
|
||||
{
|
||||
public class VoiceSDKPlatformLoggerImpl : BaseAndroidConnectionImpl<VoiceSDKLoggerBinding>, IVoiceSDKLogger
|
||||
{
|
||||
public bool IsUsingPlatformIntegration { get; set; }
|
||||
public string WitApplication { get; set; }
|
||||
public bool ShouldLogToConsole
|
||||
{
|
||||
get => consoleLoggerImpl.ShouldLogToConsole;
|
||||
set => consoleLoggerImpl.ShouldLogToConsole = value;
|
||||
}
|
||||
private VoiceSDKConsoleLoggerImpl consoleLoggerImpl = new VoiceSDKConsoleLoggerImpl();
|
||||
public VoiceSDKPlatformLoggerImpl() : base(
|
||||
"com.oculus.assistant.api.unity.logging.UnityPlatformLoggerServiceFragment")
|
||||
{
|
||||
}
|
||||
|
||||
private bool loggedFirstTranscriptionTime = false;
|
||||
|
||||
public override void Connect(string version)
|
||||
{
|
||||
base.Connect(version);
|
||||
service.Connect();
|
||||
Debug.Log(
|
||||
$"Logging Platform integration initialization complete.");
|
||||
}
|
||||
|
||||
public override void Disconnect()
|
||||
{
|
||||
Debug.Log("Logging Platform integration shutdown");
|
||||
base.Disconnect();
|
||||
}
|
||||
|
||||
public void LogInteractionStart(string requestId, string witApi)
|
||||
{
|
||||
loggedFirstTranscriptionTime = false;
|
||||
consoleLoggerImpl.LogInteractionStart(requestId, witApi);
|
||||
service.LogInteractionStart(requestId, DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
LogAnnotation("isUsingPlatform", IsUsingPlatformIntegration.ToString());
|
||||
LogAnnotation("witApi", witApi);
|
||||
LogAnnotation("witAppId", WitApplication);
|
||||
LogAnnotation("package", Application.identifier);
|
||||
}
|
||||
|
||||
public void LogInteractionEndSuccess()
|
||||
{
|
||||
consoleLoggerImpl.LogInteractionEndSuccess();
|
||||
service.LogInteractionEndSuccess(DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
}
|
||||
|
||||
public void LogInteractionEndFailure(string errorMessage)
|
||||
{
|
||||
consoleLoggerImpl.LogInteractionEndFailure(errorMessage);
|
||||
service.LogInteractionEndFailure(DateTimeUtility.ElapsedMilliseconds.ToString(), errorMessage);
|
||||
}
|
||||
|
||||
public void LogInteractionPoint(string interactionPoint)
|
||||
{
|
||||
consoleLoggerImpl.LogInteractionPoint(interactionPoint);
|
||||
service.LogInteractionPoint(interactionPoint, DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
}
|
||||
|
||||
public void LogAnnotation(string annotationKey, string annotationValue)
|
||||
{
|
||||
consoleLoggerImpl.LogAnnotation(annotationKey, annotationValue);
|
||||
service.LogAnnotation(annotationKey, annotationValue);
|
||||
}
|
||||
|
||||
public void LogFirstTranscriptionTime()
|
||||
{
|
||||
if (!loggedFirstTranscriptionTime)
|
||||
{
|
||||
loggedFirstTranscriptionTime = true;
|
||||
LogInteractionPoint("firstPartialTranscriptionTime");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eee6ea0d8b185f54b8cba025115dea67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user