Esempio n. 1
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'xamarin.test.NotificationCompatBase.Action.Factory'.");
     }
     return(handle);
 }
Esempio n. 2
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.internal.controllers.BrokerOperationExecutor.BrokerOperation"));
     }
     return(handle);
 }
Esempio n. 3
0
        internal static void Activate(IJavaPeerable?o, IntPtr jobject, ConstructorInfo cinfo, object? []?parms)
        {
            try {
                var activator = ConstructorBuilder.CreateDelegate(cinfo);
                activator(jobject, parms);
            } catch (Exception e) {
                var m = string.Format("Could not activate JNI Handle 0x{0} (key_handle 0x{1}) of Java type '{2}' as managed type '{3}'.",
                                      jobject.ToString("x"), JNIEnv.IdentityHash !(jobject).ToString("x"), JNIEnv.GetClassNameFromInstance(jobject), cinfo.DeclaringType.FullName);
                Logger.Log(LogLevel.Warn, "monodroid", m);
                Logger.Log(LogLevel.Warn, "monodroid", CreateJavaLocationException().ToString());

                throw new NotSupportedException(m, e);
            }
        }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.adal.internal.tokensharing.ITokenShareInternal"));
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.aad.adal.IBrokerAccountService"));
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.internal.authscheme.IPoPAuthenticationSchemeParams"));
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'test.me.TestInterface'.");
     }
     return(handle);
 }
 private static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, IIndexableInvoker.java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.google.firebase.IIndexable"));
     }
     return(handle);
 }
Esempio n. 9
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance(handle)}' to type 'com.ogury.ed.OguryAdListener'.");
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'android.view.View.OnClickListener'.");
     }
     return(handle);
 }
Esempio n. 11
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.internal.cache.registry.IBrokerApplicationRegistry"));
     }
     return(handle);
 }
Esempio n. 12
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver"));
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.google.android.exoplayer.drm.ExoMediaDrm"));
     }
     return(handle);
 }
 public void NewArray_JavaLangString()
 {
     using (var stringArray = new Java.Lang.Object(JNIEnv.NewArray(new[] { new Java.Lang.String("a"), new Java.Lang.String("b") }), JniHandleOwnership.TransferLocalRef)) {
         Assert.AreEqual("[Ljava/lang/String;", JNIEnv.GetClassNameFromInstance(stringArray.Handle));
     }
 }
Esempio n. 15
0
        static void n_Activate(IntPtr jnienv, IntPtr jclass, IntPtr typename_ptr, IntPtr signature_ptr, IntPtr jobject, IntPtr parameters_ptr)
        {
            var o  = Java.Lang.Object.PeekObject(jobject);
            var ex = o as IJavaObjectEx;

            if (ex != null)
            {
                if (!ex.NeedsActivation && !ex.IsProxy)
                {
                    return;
                }
            }
            if (!ActivationEnabled)
            {
                if (Logger.LogGlobalRef)
                {
                    Logger.Log(LogLevel.Info, "monodroid-gref",
                               string.Format("warning: Skipping managed constructor invocation for handle 0x{0} (key_handle 0x{1}). " +
                                             "Please use JNIEnv.StartCreateInstance() + JNIEnv.FinishCreateInstance() instead of " +
                                             "JNIEnv.NewObject() and/or JNIEnv.CreateInstance().",
                                             jobject.ToString("x"), JNIEnv.IdentityHash !(jobject).ToString("x")));
                }
                return;
            }

            Type type = Type.GetType(JNIEnv.GetString(typename_ptr, JniHandleOwnership.DoNotTransfer) !, throwOnError: true) !;

            if (type.IsGenericTypeDefinition)
            {
                throw new NotSupportedException(
                          "Constructing instances of generic types from Java is not supported, as the type parameters cannot be determined.",
                          CreateJavaLocationException());
            }
            Type[] ptypes = GetParameterTypes(JNIEnv.GetString(signature_ptr, JniHandleOwnership.DoNotTransfer));
            var    parms  = JNIEnv.GetObjectArray(parameters_ptr, ptypes);
            var    cinfo  = type.GetConstructor(ptypes);

            if (cinfo == null)
            {
                throw CreateMissingConstructorException(type, ptypes);
            }
            if (o != null)
            {
                cinfo.Invoke(o, parms);
                return;
            }
            try {
                var activator = ConstructorBuilder.CreateDelegate(type, cinfo, ptypes);
                activator(jobject, parms);
            } catch (Exception e) {
                var m = string.Format("Could not activate JNI Handle 0x{0} (key_handle 0x{1}) of Java type '{2}' as managed type '{3}'.",
                                      jobject.ToString("x"), JNIEnv.IdentityHash !(jobject).ToString("x"), JNIEnv.GetClassNameFromInstance(jobject), type.FullName);
                Logger.Log(LogLevel.Warn, "monodroid", m);
                Logger.Log(LogLevel.Warn, "monodroid", CreateJavaLocationException().ToString());

                throw new NotSupportedException(m, e);
            }
        }
Esempio n. 16
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "android.view.View.OnClickListener"));
     }
     return(handle);
 }
Esempio n. 17
0
        internal static IJavaPeerable CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type?targetType)
        {
            Type?  type       = null;
            IntPtr class_ptr  = JNIEnv.GetObjectClass(handle);
            string class_name = GetClassName(class_ptr);

            lock (TypeManagerMapDictionaries.AccessLock) {
                while (class_ptr != IntPtr.Zero && !TypeManagerMapDictionaries.JniToManaged.TryGetValue(class_name, out type))
                {
                    type = GetJavaToManagedType(class_name);
                    if (type != null)
                    {
                        TypeManagerMapDictionaries.JniToManaged.Add(class_name, type);
                        break;
                    }

                    IntPtr super_class_ptr = JNIEnv.GetSuperclass(class_ptr);
                    JNIEnv.DeleteLocalRef(class_ptr);
                    class_ptr  = super_class_ptr;
                    class_name = GetClassName(class_ptr);
                }
            }

            JNIEnv.DeleteLocalRef(class_ptr);

            if (type == null)
            {
                JNIEnv.DeleteRef(handle, transfer);
                throw new NotSupportedException(
                          string.Format("Internal error finding wrapper class for '{0}'. (Where is the Java.Lang.Object wrapper?!)",
                                        JNIEnv.GetClassNameFromInstance(handle)),
                          CreateJavaLocationException());
            }

            if (targetType != null && !targetType.IsAssignableFrom(type))
            {
                type = targetType;
            }

            if (type.IsInterface || type.IsAbstract)
            {
                var invokerType = JavaObjectExtensions.GetHelperType(type, "Invoker");
                if (invokerType == null)
                {
                    throw new NotSupportedException("Unable to find Invoker for type '" + type.FullName + "'. Was it linked away?",
                                                    CreateJavaLocationException());
                }
                type = invokerType;
            }


            IJavaPeerable?result = null;

            try {
                result = (IJavaPeerable)CreateProxy(type, handle, transfer);
                if (Runtime.IsGCUserPeer(result.PeerReference.Handle))
                {
                    result.SetJniManagedPeerState(JniManagedPeerStates.Replaceable);
                }
            } catch (MissingMethodException e) {
                var key_handle = JNIEnv.IdentityHash !(handle);
                JNIEnv.DeleteRef(handle, transfer);
                throw new NotSupportedException(
                          string.Format("Unable to activate instance of type {0} from native handle 0x{1} (key_handle 0x{2}).",
                                        type, handle.ToString("x"), key_handle.ToString("x")),
                          e);
            }
            return(result);
        }
Esempio n. 18
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.internal.providers.oauth2.ISuccessResponse"));
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'com.google.android.exoplayer.drm.ExoMediaDrm.OnEventListener'.");
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.common.internal.ui.webview.challengehandlers.IAuthorizationCompletionCallback"));
     }
     return(handle);
 }
Esempio n. 21
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.iflytek.cloud.LexiconListener"));
     }
     return(handle);
 }
Esempio n. 22
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "com.microsoft.identity.client.ILoggerCallback"));
     }
     return(handle);
 }
Esempio n. 23
0
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException(string.Format("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance(handle), "xamarin.test.Adapter"));
     }
     return(handle);
 }
 static IntPtr Validate(IntPtr handle)
 {
     if (!JNIEnv.IsInstanceOf(handle, java_class_ref))
     {
         throw new InvalidCastException($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'com.squareup.picasso.Callback'.");
     }
     return(handle);
 }