예제 #1
0
        private void CallNativeVoidMethod(string methodName, string methodSig, object[] args)
        {
            if (!CanRunJNI())
            {
                return;
            }
            bool isAttached = bsg_unity_isJNIAttached();

            if (!isAttached)
            {
                AndroidJNI.AttachCurrentThread();
            }

            object[] itemsAsJavaObjects = new object[args.Length];
            for (int i = 0; i < args.Length; i++)
            {
                var obj = args[i];

                if (obj is string)
                {
                    //TODO:SM Leaking ref here
                    itemsAsJavaObjects[i] = BuildJavaStringDisposable(obj as string);
                }
                else
                {
                    itemsAsJavaObjects[i] = obj;
                }
            }

            jvalue[] jargs    = AndroidJNIHelper.CreateJNIArgArray(itemsAsJavaObjects);
            IntPtr   methodID = AndroidJNI.GetStaticMethodID(BugsnagNativeInterface, methodName, methodSig);

            AndroidJNI.CallStaticVoidMethod(BugsnagNativeInterface, methodID, jargs);
            AndroidJNIHelper.DeleteJNIArgArray(itemsAsJavaObjects, jargs);
            if (!isAttached)
            {
                AndroidJNI.DetachCurrentThread();
            }
        }
예제 #2
0
 private static void LaunchBridgeIntent(IntPtr bridgedIntent)
 {
     object[] objArray    = new object[2];
     jvalue[] jniArgArray = AndroidJNIHelper.CreateJNIArgArray(objArray);
     try
     {
         using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.google.games.bridge.NativeBridgeActivity"))
         {
             using (AndroidJavaObject activity = AndroidTokenClient.GetActivity())
             {
                 IntPtr staticMethodId = AndroidJNI.GetStaticMethodID(((AndroidJavaObject)androidJavaClass).GetRawClass(), "launchBridgeIntent", "(Landroid/app/Activity;Landroid/content/Intent;)V");
                 jniArgArray[0].l = (__Null)activity.GetRawObject();
                 jniArgArray[1].l = (__Null)bridgedIntent;
                 AndroidJNI.CallStaticVoidMethod(((AndroidJavaObject)androidJavaClass).GetRawClass(), staticMethodId, jniArgArray);
             }
         }
     }
     finally
     {
         AndroidJNIHelper.DeleteJNIArgArray(objArray, jniArgArray);
     }
 }
예제 #3
0
        public static void initOuyaPlugin(string jsonData)
        {
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmInitOuyaPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jmInitOuyaPlugin is not initialized");
                return;
            }
            IntPtr arg1 = AndroidJNI.NewStringUTF(jsonData);

            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmInitOuyaPlugin, new jvalue[] { new jvalue()
                                                                                                  {
                                                                                                      l = arg1
                                                                                                  } });
            AndroidJNI.DeleteLocalRef(arg1);
        }
예제 #4
0
 public void ShowDefaultPage()
 {
     using (var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
         using (var gameActivityObject = unityPlayerClass.GetStatic <AndroidJavaObject>("currentActivity"))
             using (var zapicClass = new AndroidJavaClass("com.zapic.sdk.android.Zapic"))
             {
                 var methodId = AndroidJNI.GetStaticMethodID(
                     zapicClass.GetRawClass(),
                     "showDefaultPage",
                     "(Landroid/app/Activity;)V");
                 var objectArray = new object[1];
                 var argArray    = AndroidJNIHelper.CreateJNIArgArray(objectArray);
                 try
                 {
                     argArray[0].l = gameActivityObject.GetRawObject();
                     AndroidJNI.CallStaticVoidMethod(zapicClass.GetRawClass(), methodId, argArray);
                 }
                 finally
                 {
                     AndroidJNIHelper.DeleteJNIArgArray(objectArray, argArray);
                 }
             }
 }
예제 #5
0
    public static void PlayVideo(string path, string drmLicenseUrl, System.IntPtr surfaceObj)
    {
        if (playVideoMethodId == System.IntPtr.Zero)
        {
            playVideoMethodId = AndroidJNI.GetStaticMethodID(VideoPlayerClass, "playVideo", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Landroid/view/Surface;)V");
        }

        System.IntPtr filePathJString      = AndroidJNI.NewStringUTF(path);
        System.IntPtr drmLicenseUrlJString = AndroidJNI.NewStringUTF(drmLicenseUrl);

        AndroidJNI.CallStaticVoidMethod(VideoPlayerClass, playVideoMethodId, new jvalue[] { new jvalue {
                                                                                                l = Activity
                                                                                            }, new jvalue {
                                                                                                l = filePathJString
                                                                                            }, new jvalue {
                                                                                                l = drmLicenseUrlJString
                                                                                            }, new jvalue {
                                                                                                l = surfaceObj
                                                                                            } });

        AndroidJNI.DeleteLocalRef(filePathJString);
        AndroidJNI.DeleteLocalRef(drmLicenseUrlJString);
    }
예제 #6
0
        public static void Register(string apiKey)
        {
            // Get the current Activity
            AndroidJavaClass  unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity         = unityPlayerClass.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject app = activity.Call <AndroidJavaObject>("getApplicationContext");

            jvalue[] args = new jvalue[2] {
                new jvalue()
                {
                    l = app.GetRawObject()
                },
                new jvalue()
                {
                    l = AndroidJNI.NewStringUTF(apiKey)
                },
            };
            IntPtr methodId = AndroidJNI.GetStaticMethodID(BugsnagUnity.GetRawClass(), "init", "(Landroid/content/Context;Ljava/lang/String;)V");

            AndroidJNI.CallStaticVoidMethod(BugsnagUnity.GetRawClass(), methodId, args);
            registered_ = true;
            Notify("errorClass", "error message", "error", "", new System.Diagnostics.StackTrace(1, true).ToString(), null, true, "");
        }
예제 #7
0
        private void CallNativeVoidMethod(string methodName, string methodSig, object[] args)
        {
            if (!CanRunJNI())
            {
                return;
            }
            bool isAttached = bsg_unity_isJNIAttached();

            if (!isAttached)
            {
                AndroidJNI.AttachCurrentThread();
            }

            var jargs    = AndroidJNIHelper.CreateJNIArgArray(args);
            var methodID = AndroidJNI.GetStaticMethodID(BugsnagNativeInterface, methodName, methodSig);

            AndroidJNI.CallStaticVoidMethod(BugsnagNativeInterface, methodID, jargs);
            AndroidJNIHelper.DeleteJNIArgArray(args, jargs);
            if (!isAttached)
            {
                AndroidJNI.DetachCurrentThread();
            }
        }
예제 #8
0
        public void SubmitEvent(Dictionary <string, object> param)
        {
            var json = MiniJSON.Json.Serialize(param);

            using (var parametersObject = new AndroidJavaObject("java.lang.String", json))
                using (var zapicClass = new AndroidJavaClass("com.zapic.sdk.android.Zapic"))
                {
                    var methodId = AndroidJNI.GetStaticMethodID(
                        zapicClass.GetRawClass(),
                        "submitEvent",
                        "(Ljava/lang/String;)V");
                    var objectArray = new object[1];
                    var argArray    = AndroidJNIHelper.CreateJNIArgArray(objectArray);
                    try
                    {
                        argArray[0].l = parametersObject.GetRawObject();
                        AndroidJNI.CallStaticVoidMethod(zapicClass.GetRawClass(), methodId, argArray);
                    }
                    finally
                    {
                        AndroidJNIHelper.DeleteJNIArgArray(objectArray, argArray);
                    }
                }
        }
예제 #9
0
    static void AndroidConfigure(string app_version, string app_id, string[] zone_ids)
    {
        if (!adr_initialized)
        {
            AndroidInitializePlugin();
        }
        // Prepare call arguments.
        class_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

        var j_activity    = class_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        var j_app_version = AndroidJNI.NewStringUTF(app_version);
        var j_app_id      = AndroidJNI.NewStringUTF(app_id);
        var j_strings     = AndroidJNIHelper.ConvertToJNIArray(zone_ids);

        // Call UnityADC.configure( version, app_version, app_id, ids )
        jvalue[] args = new jvalue[4];
        args[0].l = j_activity.GetRawObject();
        args[1].l = j_app_version;
        args[2].l = j_app_id;
        args[3].l = j_strings;

        AndroidJNI.CallStaticVoidMethod(class_UnityADC, method_configure, args);
        configured = true;
    }
예제 #10
0
    /// <summary>
    /// Sets the surface for our GeckoView plugin when the OVROverlay is ready and the plugin is initialized
    /// Also we sign up for the sign in event so we can load the first webpage/initialize history
    /// when the user signs ins
    /// </summary>
    /// <returns>The start function</returns>
    private IEnumerator Start()
    {
#if UNITY_EDITOR
        yield break;
#endif
        // Wait for surface to be available.
        while (_overlay.externalSurfaceObject == IntPtr.Zero || _ajc == null)
        {
            yield return(null);
        }
        Debug.Log("Browser Start!");
        string jniClass        = classString.Replace(".", "/");
        var    pluginClass     = AndroidJNI.FindClass(jniClass);
        var    surfaceMethodId =
            AndroidJNI.GetStaticMethodID(pluginClass, "PassStaticSurface", "(Landroid/view/Surface;)V");

        AndroidJNI.CallStaticVoidMethod(pluginClass, surfaceMethodId,
                                        new jvalue[] { new jvalue {
                                                           l = _overlay.externalSurfaceObject
                                                       } });

        AndroidJNI.DeleteLocalRef(pluginClass);
        OnGeckoViewReady();
    }
예제 #11
0
        public static void contentDelete(OuyaMod ouyaMod)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmContentDelete == IntPtr.Zero)
            {
                Debug.LogError("_jmContentDelete is not initialized");
                return;
            }

            IntPtr arg1 = ouyaMod.GetInstance();
            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmContentDelete, new jvalue[] { new jvalue()
                                                                                                 {
                                                                                                     l = arg1
                                                                                                 } });
        }
예제 #12
0
        public static void setSafeArea(float percentage)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return;
            }
            if (_jmSetSafeArea == IntPtr.Zero)
            {
                Debug.LogError("_jmSetSafeArea is not initialized");
                return;
            }
            AndroidJNI.CallStaticVoidMethod(_jcOuyaUnityPlugin, _jmSetSafeArea, new jvalue[1] {
                new jvalue()
                {
                    f = percentage
                }
            });
        }
예제 #13
0
    private static void AndroidConfigure(string token, string bundleId, string unitName)
    {
        if (!dre_initialized)
        {
            AndroidInitializePlugin();
        }
        // Prepare call arguments.
        class_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

        var j_activity = class_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
        var j_token    = AndroidJNI.NewStringUTF(token);
        var j_bundleId = AndroidJNI.NewStringUTF(bundleId);
        var j_unitName = AndroidJNI.NewStringUTF(unitName);

        // Call UnityDre.configure( token, bundleId, unitName )
        jvalue[] args = new jvalue[4];
        args[0].l = j_activity.GetRawObject();
        args[1].l = j_token;
        args[2].l = j_bundleId;
        args[3].l = j_unitName;

        AndroidJNI.CallStaticVoidMethod(class_UnityDre, method_configure, args);
        configured = true;
    }
예제 #14
0
        public override void RecordCustomException(string name, string reason, string stackTraceString)
        {
            references.Clear();

            // new Exception(message)
            var exceptionClass       = AndroidJNI.FindClass("java/lang/Exception");
            var exceptionConstructor = AndroidJNI.GetMethodID(exceptionClass, "<init>", "(Ljava/lang/String;)V");
            var exceptionArgs        = new jvalue[1];

            exceptionArgs[0].l = AndroidJNI.NewStringUTF(name + " : " + reason);

            var exceptionObj = AndroidJNI.NewObject(exceptionClass, exceptionConstructor, exceptionArgs);

            references.Add(exceptionArgs [0].l);
            references.Add(exceptionObj);

            // stackTrace = [StackTraceElement, ...]
            var stackTraceElClass       = AndroidJNI.FindClass("java/lang/StackTraceElement");
            var stackTraceElConstructor = AndroidJNI.GetMethodID(stackTraceElClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
            var parsedStackTrace        = ParseStackTraceString(stackTraceString);
            var stackTraceArray         = AndroidJNI.NewObjectArray(parsedStackTrace.Length, stackTraceElClass, IntPtr.Zero);

            references.Add(stackTraceArray);

            for (var i = 0; i < parsedStackTrace.Length; i++)
            {
                var frame = parsedStackTrace[i];
                // new StackTraceElement()
                var stackTraceArgs = new jvalue[4];

                stackTraceArgs[0].l = AndroidJNI.NewStringUTF(frame["class"]);
                stackTraceArgs[1].l = AndroidJNI.NewStringUTF(frame["method"]);
                stackTraceArgs[2].l = AndroidJNI.NewStringUTF(frame["file"]);

                references.Add(stackTraceArgs [0].l);
                references.Add(stackTraceArgs [1].l);
                references.Add(stackTraceArgs [2].l);

                stackTraceArgs[3].i = Int32.Parse(frame["line"]);

                var stackTraceEl = AndroidJNI.NewObject(stackTraceElClass, stackTraceElConstructor, stackTraceArgs);

                references.Add(stackTraceEl);

                AndroidJNI.SetObjectArrayElement(stackTraceArray, i, stackTraceEl);
            }

            // exception.setStackTrace(stackTraceArray)
            var setStackTraceMethod = AndroidJNI.GetMethodID(exceptionClass, "setStackTrace", "([Ljava/lang/StackTraceElement;)V");
            var setStackTraceArgs   = new jvalue[1];

            setStackTraceArgs[0].l = stackTraceArray;
            AndroidJNI.CallVoidMethod(exceptionObj, setStackTraceMethod, setStackTraceArgs);

            // Crashlytics.logException(exception)
            var crashClass         = AndroidJNI.FindClass("com/crashlytics/android/Crashlytics");
            var logExceptionMethod = AndroidJNI.GetStaticMethodID(crashClass, "logException", "(Ljava/lang/Throwable;)V");
            var logExceptionArgs   = new jvalue[1];

            logExceptionArgs[0].l = exceptionObj;
            AndroidJNI.CallStaticVoidMethod(crashClass, logExceptionMethod, logExceptionArgs);

            foreach (IntPtr reference in references)
            {
                AndroidJNI.DeleteLocalRef(reference);
            }
        }
예제 #15
0
        public NativeInterface(AndroidJavaObject config)
        {
            Unity2019OrNewer = IsUnity2019OrNewer();
            MainThread       = Thread.CurrentThread;
            using (var system = new AndroidJavaClass("java.lang.System"))
            {
                var arch = system.CallStatic <string>("getProperty", "os.arch");
                CanRunOnBackgroundThread = (arch != "x86" && arch != "i686" && arch != "x86_64");
            }
            using (var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
                using (var activity = unityPlayerClass.GetStatic <AndroidJavaObject>("currentActivity"))
                    using (var context = activity.Call <AndroidJavaObject>("getApplicationContext"))
                    {
                        // lookup the NativeInterface class and set the client to the local object.
                        // all subsequent communication should go through the NativeInterface.
                        var client             = new AndroidJavaObject("com.bugsnag.android.Client", context, config);
                        var nativeInterfaceRef = AndroidJNI.FindClass("com/bugsnag/android/NativeInterface");
                        BugsnagNativeInterface = AndroidJNI.NewGlobalRef(nativeInterfaceRef);
                        AndroidJNI.DeleteLocalRef(nativeInterfaceRef);
                        var setClient = AndroidJNI.GetStaticMethodID(BugsnagNativeInterface, "setClient", "(Lcom/bugsnag/android/Client;)V");

                        jvalue[] args = AndroidJNIHelper.CreateJNIArgArray(new object[] { client });
                        AndroidJNI.CallStaticVoidMethod(BugsnagNativeInterface, setClient, args);

                        // Cache JNI refs which will be used to load report data later in the
                        // app lifecycle to avoid repeated lookups
                        var unityRef = AndroidJNI.FindClass("com/bugsnag/android/unity/BugsnagUnity");
                        BugsnagUnityClass = AndroidJNI.NewGlobalRef(unityRef);
                        AndroidJNI.DeleteLocalRef(unityRef);
                        var crumbRef = AndroidJNI.FindClass("com/bugsnag/android/Breadcrumb");
                        BreadcrumbClass = AndroidJNI.NewGlobalRef(crumbRef);
                        AndroidJNI.DeleteLocalRef(crumbRef);
                        var crumbTypeRef = AndroidJNI.FindClass("com/bugsnag/android/BreadcrumbType");
                        BreadcrumbTypeClass = AndroidJNI.NewGlobalRef(crumbTypeRef);
                        AndroidJNI.DeleteLocalRef(crumbTypeRef);
                        var collectionRef = AndroidJNI.FindClass("java/util/Collection");
                        CollectionClass = AndroidJNI.NewGlobalRef(collectionRef);
                        AndroidJNI.DeleteLocalRef(collectionRef);
                        var iterRef = AndroidJNI.FindClass("java/util/Iterator");
                        IteratorClass = AndroidJNI.NewGlobalRef(iterRef);
                        AndroidJNI.DeleteLocalRef(iterRef);
                        var listRef = AndroidJNI.FindClass("java/util/List");
                        ListClass = AndroidJNI.NewGlobalRef(listRef);
                        AndroidJNI.DeleteLocalRef(listRef);
                        var mapRef = AndroidJNI.FindClass("java/util/Map");
                        MapClass = AndroidJNI.NewGlobalRef(mapRef);
                        AndroidJNI.DeleteLocalRef(mapRef);
                        var entryRef = AndroidJNI.FindClass("java/util/Map$Entry");
                        MapEntryClass = AndroidJNI.NewGlobalRef(entryRef);
                        AndroidJNI.DeleteLocalRef(entryRef);
                        var setRef = AndroidJNI.FindClass("java/util/Set");
                        SetClass = AndroidJNI.NewGlobalRef(setRef);
                        AndroidJNI.DeleteLocalRef(setRef);
                        var stringRef = AndroidJNI.FindClass("java/lang/String");
                        StringClass = AndroidJNI.NewGlobalRef(stringRef);
                        AndroidJNI.DeleteLocalRef(stringRef);

                        BreadcrumbGetMetadata  = AndroidJNI.GetMethodID(BreadcrumbClass, "getMetadata", "()Ljava/util/Map;");
                        BreadcrumbGetType      = AndroidJNI.GetMethodID(BreadcrumbClass, "getType", "()Lcom/bugsnag/android/BreadcrumbType;");
                        BreadcrumbGetTimestamp = AndroidJNI.GetMethodID(BreadcrumbClass, "getTimestamp", "()Ljava/lang/String;");
                        BreadcrumbGetName      = AndroidJNI.GetMethodID(BreadcrumbClass, "getName", "()Ljava/lang/String;");
                        CollectionIterator     = AndroidJNI.GetMethodID(CollectionClass, "iterator", "()Ljava/util/Iterator;");
                        IteratorHasNext        = AndroidJNI.GetMethodID(IteratorClass, "hasNext", "()Z");
                        IteratorNext           = AndroidJNI.GetMethodID(IteratorClass, "next", "()Ljava/lang/Object;");
                        MapEntryGetKey         = AndroidJNI.GetMethodID(MapEntryClass, "getKey", "()Ljava/lang/Object;");
                        MapEntryGetValue       = AndroidJNI.GetMethodID(MapEntryClass, "getValue", "()Ljava/lang/Object;");
                        MapEntrySet            = AndroidJNI.GetMethodID(MapClass, "entrySet", "()Ljava/util/Set;");
                        var objectRef = AndroidJNI.FindClass("java/lang/Object");
                        ObjectToString = AndroidJNI.GetMethodID(objectRef, "toString", "()Ljava/lang/String;");
                        ObjectGetClass = AndroidJNI.GetMethodID(objectRef, "getClass", "()Ljava/lang/Class;");
                        AndroidJNI.DeleteLocalRef(objectRef);
                        var classRef = AndroidJNI.FindClass("java/lang/Class");
                        ClassIsArray = AndroidJNI.GetMethodID(classRef, "isArray", "()Z");
                        AndroidJNI.DeleteLocalRef(classRef);

                        // the bugsnag-android notifier uses Activity lifecycle tracking to
                        // determine if the application is in the foreground. As the unity
                        // activity has already started at this point we need to tell the
                        // notifier about the activity and the fact that it has started.
                        using (var sessionTracker = client.Get <AndroidJavaObject>("sessionTracker"))
                            using (var activityClass = activity.Call <AndroidJavaObject>("getClass"))
                            {
                                string activityName       = null;
                                var    activityNameObject = activityClass.Call <AndroidJavaObject>("getSimpleName");
                                if (activityNameObject != null)
                                {
                                    activityName = AndroidJNI.GetStringUTFChars(activityNameObject.GetRawObject());
                                }
                                sessionTracker.Call("updateForegroundTracker", activityName, true, 0L);
                            }
                    }
        }
예제 #16
0
 private static void BurstlyAdWrapper_destroyAdPlacement(string placementName)
 {
     jvalue[] args = new jvalue[1];
     args[0].l = AndroidJNI.NewStringUTF(placementName);
     AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_destroyAdPlacement, args);
 }
예제 #17
0
 private void CallStaticVoidMethod(IntPtr method, jvalue[] args)
 {
     AndroidJNI.CallStaticVoidMethod(m_pluginClassRaw, method, args);
 }
예제 #18
0
 private static void BurstlyAdWrapper_removeBannerFromView(string placementName)
 {
     jvalue[] args = new jvalue[1];
     args[0].l = AndroidJNI.NewStringUTF(placementName);
     AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_removeBannerFromView, args);
 }
예제 #19
0
 private static void BurstlyAdWrapper_setCallbackGameObjectName(string callbackGameObjectName)
 {
     jvalue[] args = new jvalue[1];
     args[0].l = AndroidJNI.NewStringUTF(callbackGameObjectName);
     AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_setCallbackGameObjectName, args);
 }
예제 #20
0
        public static void Notify(string errorClass, string errorMessage, string severity, string context, string stackTrace, string type, bool warmup, string severityReason)
        {
            if (!CheckRegistration())
            {
                return;
            }
            var stackFrames = new ArrayList();

            ParseStackTrace(stackTrace, stack => {
                var stackFrame = new AndroidJavaObject("java.lang.StackTraceElement", stack.className, stack.method, stack.file, stack.line);
                stackFrames.Add(stackFrame);
            });

            if (stackFrames.Count > 0 && warmup == false)
            {
                IntPtr stackFrameArrayObject = AndroidJNI.NewObjectArray(stackFrames.Count, ((AndroidJavaObject)(stackFrames[0])).GetRawClass(), ((AndroidJavaObject)(stackFrames[0])).GetRawObject());

                for (var i = 1; i < stackFrames.Count; i++)
                {
                    AndroidJNI.SetObjectArrayElement(stackFrameArrayObject, i, ((AndroidJavaObject)(stackFrames[i])).GetRawObject());
                }

                var Severity         = new AndroidJavaClass("com.bugsnag.android.Severity");
                var severityInstance = Severity.GetStatic <AndroidJavaObject>("ERROR");

                if (severity == "info")
                {
                    severityInstance = Severity.GetStatic <AndroidJavaObject>("INFO");
                }
                else if (severity == "warning")
                {
                    severityInstance = Severity.GetStatic <AndroidJavaObject>("WARNING");
                }

                // Build the arguments
                jvalue[] args = new jvalue[7] {
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(errorClass)
                    },
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(errorMessage)
                    },
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(context)
                    },
                    new jvalue()
                    {
                        l = (IntPtr)stackFrameArrayObject
                    },
                    new jvalue()
                    {
                        l = severityInstance.GetRawObject()
                    },
                    new jvalue()
                    {
                        l = String.IsNullOrEmpty(type) ? IntPtr.Zero : AndroidJNI.NewStringUTF(type)
                    },
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(String.IsNullOrEmpty(severityReason) ? "handledException" : severityReason)
                    }
                };

                // Call Android's notify method
                IntPtr clientConstructorId = AndroidJNI.GetStaticMethodID(BugsnagUnity.GetRawClass(), "notify", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/StackTraceElement;Lcom/bugsnag/android/Severity;Ljava/lang/String;Ljava/lang/String;)V");
                if (warmup == false)
                {
                    AndroidJNI.CallStaticVoidMethod(BugsnagUnity.GetRawClass(), clientConstructorId, args);
                }
            }
        }
예제 #21
0
        public static void Notify(string errorClass, string errorMessage, string severity, string context, string stackTrace, bool warmup)
        {
            var stackFrames = new ArrayList();

            foreach (Match frameMatch in unityExpression.Matches(stackTrace))
            {
                var method    = frameMatch.Groups[1].Value;
                var className = "";
                if (method == "")
                {
                    method = "Unknown method";
                }
                else
                {
                    var index = method.LastIndexOf(".");
                    if (index >= 0)
                    {
                        className = method.Substring(0, index);
                        method    = method.Substring(index + 1);
                    }
                }
                var file = frameMatch.Groups[2].Value;
                if (file == "" || file == "<filename unknown>")
                {
                    file = "unknown file";
                }
                var line = frameMatch.Groups[3].Value;
                if (line == "")
                {
                    line = "0";
                }

                var stackFrame = new AndroidJavaObject("java.lang.StackTraceElement", className, method, file, Convert.ToInt32(line));
                stackFrames.Add(stackFrame);
            }

            if (stackFrames.Count > 0 && warmup == false)
            {
                IntPtr stackFrameArrayObject = AndroidJNI.NewObjectArray(stackFrames.Count, ((AndroidJavaObject)(stackFrames[0])).GetRawClass(), ((AndroidJavaObject)(stackFrames[0])).GetRawObject());

                for (var i = 1; i < stackFrames.Count; i++)
                {
                    AndroidJNI.SetObjectArrayElement(stackFrameArrayObject, i, ((AndroidJavaObject)(stackFrames[i])).GetRawObject());
                }

                var Severity         = new AndroidJavaClass("com.bugsnag.android.Severity");
                var severityInstance = Severity.GetStatic <AndroidJavaObject>("ERROR");

                if (severity == "info")
                {
                    severityInstance = Severity.GetStatic <AndroidJavaObject>("INFO");
                }
                else if (severity == "warning")
                {
                    severityInstance = Severity.GetStatic <AndroidJavaObject>("WARNING");
                }

                var metaData = new AndroidJavaObject("com.bugsnag.android.MetaData");

                // Build the arguments
                jvalue[] args = new jvalue[6] {
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(errorClass)
                    },
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(errorMessage)
                    },
                    new jvalue()
                    {
                        l = AndroidJNI.NewStringUTF(context)
                    },
                    new jvalue()
                    {
                        l = (IntPtr)stackFrameArrayObject
                    },
                    new jvalue()
                    {
                        l = severityInstance.GetRawObject()
                    },
                    new jvalue()
                    {
                        l = metaData.GetRawObject()
                    }
                };

                // Call Android's notify method
                IntPtr clientConstructorId = AndroidJNI.GetStaticMethodID(Bugsnag.GetRawClass(), "notify", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/StackTraceElement;Lcom/bugsnag/android/Severity;Lcom/bugsnag/android/MetaData;)V");
                if (warmup == false)
                {
                    AndroidJNI.CallStaticVoidMethod(Bugsnag.GetRawClass(), clientConstructorId, args);
                }
            }
        }
예제 #22
0
    static void AndroidConfigure(string app_version, string app_id, string[] zone_ids)
    {
        bool   success = true;
        IntPtr local_class_UnityADC = AndroidJNI.FindClass("com/jirbo/unityadc/UnityADC");

        if (local_class_UnityADC != IntPtr.Zero)
        {
            class_UnityADC = AndroidJNI.NewGlobalRef(local_class_UnityADC);
            AndroidJNI.DeleteLocalRef(local_class_UnityADC);
            var local_class_AdColony = AndroidJNI.FindClass("com/jirbo/adcolony/AdColony");
            if (local_class_AdColony != IntPtr.Zero)
            {
                AndroidJNI.DeleteLocalRef(local_class_AdColony);
            }
            else
            {
                success = false;
            }
        }
        else
        {
            success = false;
        }

        if (success)
        {
            // Insert the app_id in with the other ids.
            string[] id_strings = new string[zone_ids.Length + 1];
            id_strings[0] = app_id;
            for (int i = 0; i < zone_ids.Length; ++i)
            {
                id_strings[i + 1] = zone_ids[i];
            }

            // Prepare call arguments.
            class_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

            var j_activity    = class_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            var j_app_version = AndroidJNI.NewStringUTF(app_version);
            var j_strings     = AndroidJNIHelper.ConvertToJNIArray(id_strings);

            // Call UnityADC.configure( version, app_version, ids )
            var method_configure = AndroidJNI.GetStaticMethodID(class_UnityADC, "configure",
                                                                "(Landroid/app/Activity;Ljava/lang/String;[Ljava/lang/String;)V");

            jvalue[] args = new jvalue[3];
            args[0].l = j_activity.GetRawObject();
            args[1].l = j_app_version;
            args[2].l = j_strings;

            AndroidJNI.CallStaticVoidMethod(class_UnityADC, method_configure, args);

            // Get additional method IDs for later use.
            method_pause = AndroidJNI.GetStaticMethodID(class_UnityADC, "pause",
                                                        "(Landroid/app/Activity;)V");
            method_resume = AndroidJNI.GetStaticMethodID(class_UnityADC, "resume",
                                                         "(Landroid/app/Activity;)V");
            method_isVideoAvailable = AndroidJNI.GetStaticMethodID(class_UnityADC, "isVideoAvailable",
                                                                   "(Ljava/lang/String;)Z");
            method_isV4VCAvailable = AndroidJNI.GetStaticMethodID(class_UnityADC, "isV4VCAvailable",
                                                                  "(Ljava/lang/String;)Z");
            method_getDeviceID = AndroidJNI.GetStaticMethodID(class_UnityADC, "getDeviceID",
                                                              "()Ljava/lang/String;");
            method_getV4VCAmount = AndroidJNI.GetStaticMethodID(class_UnityADC, "getV4VCAmount",
                                                                "(Ljava/lang/String;)I");
            method_getV4VCName = AndroidJNI.GetStaticMethodID(class_UnityADC, "getV4VCName",
                                                              "(Ljava/lang/String;)Ljava/lang/String;");
            method_showVideo = AndroidJNI.GetStaticMethodID(class_UnityADC, "showVideo",
                                                            "(Ljava/lang/String;)Z");
            method_showV4VC = AndroidJNI.GetStaticMethodID(class_UnityADC, "showV4VC",
                                                           "(ZLjava/lang/String;)Z");
            method_offerV4VC = AndroidJNI.GetStaticMethodID(class_UnityADC, "offerV4VC",
                                                            "(ZLjava/lang/String;)V");

            configured = true;
        }
        else
        {
            // adcolony.jar and unityadc.jar most both be in Assets/Plugins/Android/ !
            Debug.LogError("AdColony configuration error - make sure adcolony.jar and "
                           + "unityadc.jar libraries are in your Unity project's Assets/Plugins/Android folder.");
        }
    }
예제 #23
0
    IEnumerator DoTransfer()
    {
        string contentPath = Application.streamingAssetsPath + "/lances.jpg";
        string stylePath   = Application.streamingAssetsPath + "/cat.jpg";
        string outPath     = Application.persistentDataPath + "/outimage.jpg";

        Debug.Log(string.Format("Transfer Param: {0} : {1} :{2}", contentPath, stylePath, outPath));



        yield return(StartCoroutine(LoadContentTexture(contentPath)));

        yield return(StartCoroutine(LoadStyleTexture(stylePath)));


#if UNITY_ANDROID //&& !UNITY_EDITOR
        AndroidJNI.AttachCurrentThread();
        //Unity侧调用Android侧代码
        using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        {
            using (AndroidJavaObject jcurrentActivity = jc.GetStatic <AndroidJavaObject>("currentActivity"))
            {
                AndroidJavaClass jinterface = new AndroidJavaClass("com.bh.utflibrary.UtfLibraryInterface");

                jinterface.CallStatic("Init", jcurrentActivity);


                //AndroidJavaObject outArrayObj = jinterface.CallStatic<AndroidJavaObject>("TryArrayOutput");
                //int[] outArray = AndroidJNIHelper.ConvertFromJNIArray<int[]>(outArrayObj.GetRawObject());
                //Debug.Log("ConvertFromJNIArray:" + outArray.Length);

                //IntPtr outputClass = AndroidJNI.FindClass("com/bh/utflibrary/UtfLibraryInterface");
                //IntPtr outputMethod = AndroidJNI.GetStaticMethodID(outputClass, "TryArrayOutput", "()[I");

                //Debug.Log("Call TryArrayOutput:" + outputClass + ":" + outputMethod);
                //AndroidJNI.CallStaticObjectMethod(outputClass, outputMethod,null);


                //float[] farr = new float[6] { 5,4, 3, 2, 1,0};
                //IntPtr faddr = AndroidJNIHelper.ConvertToJNIArray(farr);


                //jvalue[] fparam = new jvalue[1];
                //fparam[0] = ConvertFloatArrayToJNI(farr);

                //IntPtr jinterfaceAddr = AndroidJNI.FindClass("com/bh/utflibrary/UtfLibraryInterface");
                //IntPtr methodAddr = AndroidJNI.GetStaticMethodID(jinterfaceAddr, "TryArrayInput", "([F)V");

                //Debug.Log("Call TryArrayInput:" + jinterfaceAddr + ":" + methodAddr);
                //AndroidJNI.CallStaticVoidMethod(jinterfaceAddr, methodAddr, fparam);



                //AndroidJavaClass jenvironment = new AndroidJavaClass("android.os.Environment");
                //string path = jinterface.CallStatic<AndroidJavaObject>("getExternalStorageDirectory").Call<string>("toString");

                Debug.Log("Start Convert Array");



                jvalue[] jparam = new jvalue[6];

                jvalue contentJArr, styleJArr;
                jparam[0].i = contentWidth;
                jparam[1].i = contentHeight;
                jparam[2]   = contentJArr = ConvertFloatArrayToJNI(contentData);

                jparam[3].i = styleWidth;
                jparam[4].i = styleHeight;
                jparam[5]   = styleJArr = ConvertFloatArrayToJNI(styleData);


                Debug.Log("Start Transfer");

                string sig            = "(II[FII[F)V";
                IntPtr interfaceClass = AndroidJNI.FindClass("com/bh/utflibrary/UtfLibraryInterface");
                IntPtr transferMethod = AndroidJNI.GetStaticMethodID(interfaceClass, "Transfer", sig);


                Debug.Log("Method Transfer:" + interfaceClass + ":" + transferMethod);

                Debug.Log("Call Transfer");
                AndroidJNI.CallStaticVoidMethod(interfaceClass, transferMethod, jparam);

                AndroidJavaObject outputsObj = jinterface.CallStatic <AndroidJavaObject>("GetOutputs");
                outimageData = AndroidJNIHelper.ConvertFromJNIArray <int[]>(outputsObj.GetRawObject());
                Debug.Log("End Transfer:" + outimageData.Length);

                //int[] arrObj = jinterface.CallStatic<int[]>("Transfer", contentWidth, contentHeight, contentData, styleWidth, styleHeight, styleData);

                //Debug.Log("End Transfer:" + arrObj.Length);
                //if (arrObj.GetRawObject().ToInt32() != 0)
                //{
                //    // String[] returned with some data!
                //    outimageData = AndroidJNIHelper.ConvertFromJNIArray<int[]>
                //                          (arrObj.GetRawObject());

                //    Debug.Log("outimageData Has Values");

                //}
                //else
                //{

                //    Debug.Log("outimageData zero");
                //}
            }
        }
#endif
        Debug.Log("Start Gan");
        if (outimageData != null)
        {
            Debug.Log("Gan Succ");
            Color[] outColor = new Color[outimageData.Length / 3];

            for (int i = 0; i < outimageData.Length / 3; i++)
            {
                Color c = new Color();
                c.r = outimageData[i * 3];
                c.g = outimageData[i * 3 + 1];
                c.b = outimageData[i * 3 + 2];

                outColor[i] = c;
            }


            Texture2D outTex = new Texture2D(contentWidth, contentHeight);
            outTex.SetPixels(outColor);
            Debug.Log("Gan Length:" + outimageData.Length);

            byte[] outData = outTex.EncodeToJPG(100);
            File.WriteAllBytes(outPath, outData);

            OutImage.texture = outTex;
        }
        else
        {
            Debug.Log("Gan Failed");
        }
    }
예제 #24
0
 private static void BurstlyCurrencyWrapper_updateBalancesFromServer()
 {
     jvalue[] args = new jvalue[0];
     AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_updateBalancesFromServer, args);
 }