protected void _SetStatic <FieldType>(string fieldName, FieldType val) { IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true); bool flag = AndroidReflection.IsPrimitive(typeof(FieldType)); if (flag) { bool flag2 = typeof(FieldType) == typeof(int); if (flag2) { AndroidJNISafe.SetStaticIntField(this.m_jclass, fieldID, (int)((object)val)); } else { bool flag3 = typeof(FieldType) == typeof(bool); if (flag3) { AndroidJNISafe.SetStaticBooleanField(this.m_jclass, fieldID, (bool)((object)val)); } else { bool flag4 = typeof(FieldType) == typeof(byte); if (flag4) { Debug.LogWarning("Field type <Byte> for Java set field call is obsolete, use field type <SByte> instead"); AndroidJNISafe.SetStaticSByteField(this.m_jclass, fieldID, (sbyte)((byte)((object)val))); } else { bool flag5 = typeof(FieldType) == typeof(sbyte); if (flag5) { AndroidJNISafe.SetStaticSByteField(this.m_jclass, fieldID, (sbyte)((object)val)); } else { bool flag6 = typeof(FieldType) == typeof(short); if (flag6) { AndroidJNISafe.SetStaticShortField(this.m_jclass, fieldID, (short)((object)val)); } else { bool flag7 = typeof(FieldType) == typeof(long); if (flag7) { AndroidJNISafe.SetStaticLongField(this.m_jclass, fieldID, (long)((object)val)); } else { bool flag8 = typeof(FieldType) == typeof(float); if (flag8) { AndroidJNISafe.SetStaticFloatField(this.m_jclass, fieldID, (float)((object)val)); } else { bool flag9 = typeof(FieldType) == typeof(double); if (flag9) { AndroidJNISafe.SetStaticDoubleField(this.m_jclass, fieldID, (double)((object)val)); } else { bool flag10 = typeof(FieldType) == typeof(char); if (flag10) { AndroidJNISafe.SetStaticCharField(this.m_jclass, fieldID, (char)((object)val)); } } } } } } } } } } else { bool flag11 = typeof(FieldType) == typeof(string); if (flag11) { AndroidJNISafe.SetStaticStringField(this.m_jclass, fieldID, (string)((object)val)); } else { bool flag12 = typeof(FieldType) == typeof(AndroidJavaClass); if (flag12) { AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, (val == null) ? IntPtr.Zero : ((AndroidJavaClass)((object)val)).m_jclass); } else { bool flag13 = typeof(FieldType) == typeof(AndroidJavaObject); if (flag13) { AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, (val == null) ? IntPtr.Zero : ((AndroidJavaObject)((object)val)).m_jobject); } else { bool flag14 = AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)); if (!flag14) { string arg_3B5_0 = "JNI: Unknown field type '"; Type expr_3A4 = typeof(FieldType); throw new Exception(arg_3B5_0 + ((expr_3A4 != null) ? expr_3A4.ToString() : null) + "'"); } IntPtr val2 = AndroidJNIHelper.ConvertToJNIArray((Array)((object)val)); AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, val2); } } } } }
protected ReturnType _CallStatic <ReturnType>(string methodName, params object[] args) { if (args == null) { args = new object[1]; } IntPtr methodID = AndroidJNIHelper.GetMethodID <ReturnType>(this.m_jclass, methodName, args, true); jvalue[] array = AndroidJNIHelper.CreateJNIArgArray(args); ReturnType result; try { if (AndroidReflection.IsPrimitive(typeof(ReturnType))) { if (typeof(ReturnType) == typeof(int)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticIntMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(bool)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticBooleanMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(byte)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticByteMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(short)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticShortMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(long)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticLongMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(float)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticFloatMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(double)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticDoubleMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(char)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticCharMethod(this.m_jclass, methodID, array)); } else { result = default(ReturnType); } } else if (typeof(ReturnType) == typeof(string)) { result = (ReturnType)((object)AndroidJNISafe.CallStaticStringMethod(this.m_jclass, methodID, array)); } else if (typeof(ReturnType) == typeof(AndroidJavaClass)) { IntPtr intPtr = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array); result = ((!(intPtr == IntPtr.Zero)) ? ((ReturnType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(intPtr))) : default(ReturnType)); } else if (typeof(ReturnType) == typeof(AndroidJavaObject)) { IntPtr intPtr2 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array); result = ((!(intPtr2 == IntPtr.Zero)) ? ((ReturnType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(intPtr2))) : default(ReturnType)); } else { if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(ReturnType))) { throw new Exception("JNI: Unknown return type '" + typeof(ReturnType) + "'"); } IntPtr intPtr3 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array); result = ((!(intPtr3 == IntPtr.Zero)) ? ((ReturnType)((object)AndroidJNIHelper.ConvertFromJNIArray <ReturnType>(intPtr3))) : default(ReturnType)); } } finally { AndroidJNIHelper.DeleteJNIArgArray(args, array); } return(result); }
protected ReturnType _CallStatic <ReturnType>(string methodName, params object[] args) { bool flag = args == null; if (flag) { args = new object[1]; } IntPtr methodID = AndroidJNIHelper.GetMethodID <ReturnType>(this.m_jclass, methodName, args, true); jvalue[] array = AndroidJNIHelper.CreateJNIArgArray(args); ReturnType result; try { bool flag2 = AndroidReflection.IsPrimitive(typeof(ReturnType)); if (flag2) { bool flag3 = typeof(ReturnType) == typeof(int); if (flag3) { result = (ReturnType)((object)AndroidJNISafe.CallStaticIntMethod(this.m_jclass, methodID, array)); } else { bool flag4 = typeof(ReturnType) == typeof(bool); if (flag4) { result = (ReturnType)((object)AndroidJNISafe.CallStaticBooleanMethod(this.m_jclass, methodID, array)); } else { bool flag5 = typeof(ReturnType) == typeof(byte); if (flag5) { Debug.LogWarning("Return type <Byte> for Java method call is obsolete, use return type <SByte> instead"); result = (ReturnType)((object)((byte)AndroidJNISafe.CallStaticSByteMethod(this.m_jclass, methodID, array))); } else { bool flag6 = typeof(ReturnType) == typeof(sbyte); if (flag6) { result = (ReturnType)((object)AndroidJNISafe.CallStaticSByteMethod(this.m_jclass, methodID, array)); } else { bool flag7 = typeof(ReturnType) == typeof(short); if (flag7) { result = (ReturnType)((object)AndroidJNISafe.CallStaticShortMethod(this.m_jclass, methodID, array)); } else { bool flag8 = typeof(ReturnType) == typeof(long); if (flag8) { result = (ReturnType)((object)AndroidJNISafe.CallStaticLongMethod(this.m_jclass, methodID, array)); } else { bool flag9 = typeof(ReturnType) == typeof(float); if (flag9) { result = (ReturnType)((object)AndroidJNISafe.CallStaticFloatMethod(this.m_jclass, methodID, array)); } else { bool flag10 = typeof(ReturnType) == typeof(double); if (flag10) { result = (ReturnType)((object)AndroidJNISafe.CallStaticDoubleMethod(this.m_jclass, methodID, array)); } else { bool flag11 = typeof(ReturnType) == typeof(char); if (flag11) { result = (ReturnType)((object)AndroidJNISafe.CallStaticCharMethod(this.m_jclass, methodID, array)); } else { result = default(ReturnType); } } } } } } } } } } else { bool flag12 = typeof(ReturnType) == typeof(string); if (flag12) { result = (ReturnType)((object)AndroidJNISafe.CallStaticStringMethod(this.m_jclass, methodID, array)); } else { bool flag13 = typeof(ReturnType) == typeof(AndroidJavaClass); if (flag13) { IntPtr intPtr = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array); result = ((intPtr == IntPtr.Zero) ? default(ReturnType) : ((ReturnType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(intPtr)))); } else { bool flag14 = typeof(ReturnType) == typeof(AndroidJavaObject); if (flag14) { IntPtr intPtr2 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array); result = ((intPtr2 == IntPtr.Zero) ? default(ReturnType) : ((ReturnType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(intPtr2)))); } else { bool flag15 = AndroidReflection.IsAssignableFrom(typeof(Array), typeof(ReturnType)); if (!flag15) { string arg_408_0 = "JNI: Unknown return type '"; Type expr_3F7 = typeof(ReturnType); throw new Exception(arg_408_0 + ((expr_3F7 != null) ? expr_3F7.ToString() : null) + "'"); } IntPtr intPtr3 = AndroidJNISafe.CallStaticObjectMethod(this.m_jclass, methodID, array); result = ((intPtr3 == IntPtr.Zero) ? default(ReturnType) : ((ReturnType)((object)AndroidJNIHelper.ConvertFromJNIArray <ReturnType>(intPtr3)))); } } } } } finally { AndroidJNIHelper.DeleteJNIArgArray(args, array); } return(result); }
protected FieldType _GetStatic <FieldType>(string fieldName) { IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true); bool flag = AndroidReflection.IsPrimitive(typeof(FieldType)); FieldType result; if (flag) { bool flag2 = typeof(FieldType) == typeof(int); if (flag2) { result = (FieldType)((object)AndroidJNISafe.GetStaticIntField(this.m_jclass, fieldID)); } else { bool flag3 = typeof(FieldType) == typeof(bool); if (flag3) { result = (FieldType)((object)AndroidJNISafe.GetStaticBooleanField(this.m_jclass, fieldID)); } else { bool flag4 = typeof(FieldType) == typeof(byte); if (flag4) { Debug.LogWarning("Field type <Byte> for Java get field call is obsolete, use field type <SByte> instead"); result = (FieldType)((object)((byte)AndroidJNISafe.GetStaticSByteField(this.m_jclass, fieldID))); } else { bool flag5 = typeof(FieldType) == typeof(sbyte); if (flag5) { result = (FieldType)((object)AndroidJNISafe.GetStaticSByteField(this.m_jclass, fieldID)); } else { bool flag6 = typeof(FieldType) == typeof(short); if (flag6) { result = (FieldType)((object)AndroidJNISafe.GetStaticShortField(this.m_jclass, fieldID)); } else { bool flag7 = typeof(FieldType) == typeof(long); if (flag7) { result = (FieldType)((object)AndroidJNISafe.GetStaticLongField(this.m_jclass, fieldID)); } else { bool flag8 = typeof(FieldType) == typeof(float); if (flag8) { result = (FieldType)((object)AndroidJNISafe.GetStaticFloatField(this.m_jclass, fieldID)); } else { bool flag9 = typeof(FieldType) == typeof(double); if (flag9) { result = (FieldType)((object)AndroidJNISafe.GetStaticDoubleField(this.m_jclass, fieldID)); } else { bool flag10 = typeof(FieldType) == typeof(char); if (flag10) { result = (FieldType)((object)AndroidJNISafe.GetStaticCharField(this.m_jclass, fieldID)); } else { result = default(FieldType); } } } } } } } } } } else { bool flag11 = typeof(FieldType) == typeof(string); if (flag11) { result = (FieldType)((object)AndroidJNISafe.GetStaticStringField(this.m_jclass, fieldID)); } else { bool flag12 = typeof(FieldType) == typeof(AndroidJavaClass); if (flag12) { IntPtr staticObjectField = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID); result = ((staticObjectField == IntPtr.Zero) ? default(FieldType) : ((FieldType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(staticObjectField)))); } else { bool flag13 = typeof(FieldType) == typeof(AndroidJavaObject); if (flag13) { IntPtr staticObjectField2 = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID); result = ((staticObjectField2 == IntPtr.Zero) ? default(FieldType) : ((FieldType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(staticObjectField2)))); } else { bool flag14 = AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType)); if (!flag14) { string arg_3D3_0 = "JNI: Unknown field type '"; Type expr_3C2 = typeof(FieldType); throw new Exception(arg_3D3_0 + ((expr_3C2 != null) ? expr_3C2.ToString() : null) + "'"); } IntPtr staticObjectField3 = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID); result = ((staticObjectField3 == IntPtr.Zero) ? default(FieldType) : ((FieldType)((object)AndroidJNIHelper.ConvertFromJNIArray <FieldType>(staticObjectField3)))); } } } } return(result); }
public static string GetSignature(object obj) { string result; if (obj == null) { result = "Ljava/lang/Object;"; } else { Type type = (!(obj is Type)) ? obj.GetType() : ((Type)obj); if (AndroidReflection.IsPrimitive(type)) { if (type.Equals(typeof(int))) { result = "I"; } else if (type.Equals(typeof(bool))) { result = "Z"; } else if (type.Equals(typeof(byte))) { result = "B"; } else if (type.Equals(typeof(short))) { result = "S"; } else if (type.Equals(typeof(long))) { result = "J"; } else if (type.Equals(typeof(float))) { result = "F"; } else if (type.Equals(typeof(double))) { result = "D"; } else if (type.Equals(typeof(char))) { result = "C"; } else { result = ""; } } else if (type.Equals(typeof(string))) { result = "Ljava/lang/String;"; } else if (obj is AndroidJavaProxy) { AndroidJavaObject androidJavaObject = new AndroidJavaObject(((AndroidJavaProxy)obj).javaInterface.GetRawClass()); result = "L" + androidJavaObject.Call <string>("getName", new object[0]) + ";"; } else if (type.Equals(typeof(AndroidJavaRunnable))) { result = "Ljava/lang/Runnable;"; } else if (type.Equals(typeof(AndroidJavaClass))) { result = "Ljava/lang/Class;"; } else { if (type.Equals(typeof(AndroidJavaObject))) { if (obj == type) { result = "Ljava/lang/Object;"; return(result); } AndroidJavaObject androidJavaObject2 = (AndroidJavaObject)obj; using (AndroidJavaObject androidJavaObject3 = androidJavaObject2.Call <AndroidJavaObject>("getClass", new object[0])) { result = "L" + androidJavaObject3.Call <string>("getName", new object[0]) + ";"; return(result); } } if (!AndroidReflection.IsAssignableFrom(typeof(Array), type)) { throw new Exception(string.Concat(new object[] { "JNI: Unknown signature for type '", type, "' (obj = ", obj, ") ", (type != obj) ? "instance" : "equal" })); } if (type.GetArrayRank() != 1) { throw new Exception("JNI: System.Array in n dimensions is not allowed"); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('['); stringBuilder.Append(_AndroidJNIHelper.GetSignature(type.GetElementType())); result = stringBuilder.ToString(); } } return(result); }
public static IntPtr CreateJavaProxy(int delegateHandle, AndroidJavaProxy proxy) { return(AndroidReflection.NewProxyInstance(delegateHandle, proxy.javaInterface.GetRawClass())); }
public static jvalue[] CreateJNIArgArray(object[] args) { jvalue[] array = new jvalue[args.GetLength(0)]; int num = 0; for (int i = 0; i < args.Length; i++) { object obj = args[i]; if (obj == null) { array[num].l = IntPtr.Zero; } else if (AndroidReflection.IsPrimitive(obj.GetType())) { if (obj is int) { array[num].i = (int)obj; } else if (obj is bool) { array[num].z = (bool)obj; } else if (obj is byte) { array[num].b = (byte)obj; } else if (obj is short) { array[num].s = (short)obj; } else if (obj is long) { array[num].j = (long)obj; } else if (obj is float) { array[num].f = (float)obj; } else if (obj is double) { array[num].d = (double)obj; } else if (obj is char) { array[num].c = (char)obj; } } else if (obj is string) { array[num].l = AndroidJNISafe.NewStringUTF((string)obj); } else if (obj is AndroidJavaClass) { array[num].l = ((AndroidJavaClass)obj).GetRawClass(); } else if (obj is AndroidJavaObject) { array[num].l = ((AndroidJavaObject)obj).GetRawObject(); } else if (obj is Array) { array[num].l = _AndroidJNIHelper.ConvertToJNIArray((Array)obj); } else if (obj is AndroidJavaProxy) { array[num].l = ((AndroidJavaProxy)obj).GetProxy().GetRawObject(); } else { if (!(obj is AndroidJavaRunnable)) { throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'"); } array[num].l = AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj); } num++; } return(array); }
public static jvalue[] CreateJNIArgArray(object[] args) { jvalue[] jvalueArray = new jvalue[args.GetLength(0)]; int index = 0; foreach (object obj2 in args) { if (obj2 == null) { jvalueArray[index].l = IntPtr.Zero; } else if (AndroidReflection.IsPrimitive(obj2.GetType())) { if (obj2 is int) { jvalueArray[index].i = (int)obj2; } else if (obj2 is bool) { jvalueArray[index].z = (bool)obj2; } else if (obj2 is byte) { jvalueArray[index].b = (byte)obj2; } else if (obj2 is short) { jvalueArray[index].s = (short)obj2; } else if (obj2 is long) { jvalueArray[index].j = (long)obj2; } else if (obj2 is float) { jvalueArray[index].f = (float)obj2; } else if (obj2 is double) { jvalueArray[index].d = (double)obj2; } else if (obj2 is char) { jvalueArray[index].c = (char)obj2; } } else if (obj2 is string) { jvalueArray[index].l = AndroidJNISafe.NewStringUTF((string)obj2); } else if (obj2 is AndroidJavaClass) { jvalueArray[index].l = ((AndroidJavaClass)obj2).GetRawClass(); } else if (obj2 is AndroidJavaObject) { jvalueArray[index].l = ((AndroidJavaObject)obj2).GetRawObject(); } else if (obj2 is Array) { jvalueArray[index].l = ConvertToJNIArray((Array)obj2); } else if (obj2 is AndroidJavaProxy) { jvalueArray[index].l = AndroidJNIHelper.CreateJavaProxy((AndroidJavaProxy)obj2); } else { if (!(obj2 is AndroidJavaRunnable)) { throw new Exception("JNI; Unknown argument type '" + obj2.GetType() + "'"); } jvalueArray[index].l = AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj2); } index++; } return(jvalueArray); }
public static AndroidJavaObject Box(object obj) { AndroidJavaObject result; if (obj == null) { result = null; } else if (AndroidReflection.IsPrimitive(obj.GetType())) { if (obj is int) { result = new AndroidJavaObject("java.lang.Integer", new object[] { (int)obj }); } else if (obj is bool) { result = new AndroidJavaObject("java.lang.Boolean", new object[] { (bool)obj }); } else if (obj is byte) { result = new AndroidJavaObject("java.lang.Byte", new object[] { (byte)obj }); } else if (obj is short) { result = new AndroidJavaObject("java.lang.Short", new object[] { (short)obj }); } else if (obj is long) { result = new AndroidJavaObject("java.lang.Long", new object[] { (long)obj }); } else if (obj is float) { result = new AndroidJavaObject("java.lang.Float", new object[] { (float)obj }); } else if (obj is double) { result = new AndroidJavaObject("java.lang.Double", new object[] { (double)obj }); } else { if (!(obj is char)) { throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'"); } result = new AndroidJavaObject("java.lang.Character", new object[] { (char)obj }); } } else if (obj is string) { result = new AndroidJavaObject("java.lang.String", new object[] { (string)obj }); } else if (obj is AndroidJavaClass) { result = new AndroidJavaObject(((AndroidJavaClass)obj).GetRawClass()); } else if (obj is AndroidJavaObject) { result = (AndroidJavaObject)obj; } else if (obj is Array) { result = AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(_AndroidJNIHelper.ConvertToJNIArray((Array)obj)); } else if (obj is AndroidJavaProxy) { result = ((AndroidJavaProxy)obj).GetProxy(); } else { if (!(obj is AndroidJavaRunnable)) { throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'"); } result = AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj)); } return(result); }
public static IntPtr ConvertToJNIArray(Array array) { Type elementType = array.GetType().GetElementType(); IntPtr result; if (AndroidReflection.IsPrimitive(elementType)) { if (elementType == typeof(int)) { result = AndroidJNISafe.ToIntArray((int[])array); } else if (elementType == typeof(bool)) { result = AndroidJNISafe.ToBooleanArray((bool[])array); } else if (elementType == typeof(byte)) { result = AndroidJNISafe.ToByteArray((byte[])array); } else if (elementType == typeof(short)) { result = AndroidJNISafe.ToShortArray((short[])array); } else if (elementType == typeof(long)) { result = AndroidJNISafe.ToLongArray((long[])array); } else if (elementType == typeof(float)) { result = AndroidJNISafe.ToFloatArray((float[])array); } else if (elementType == typeof(double)) { result = AndroidJNISafe.ToDoubleArray((double[])array); } else if (elementType == typeof(char)) { result = AndroidJNISafe.ToCharArray((char[])array); } else { result = IntPtr.Zero; } } else if (elementType == typeof(string)) { string[] array2 = (string[])array; int length = array.GetLength(0); IntPtr intPtr = AndroidJNISafe.FindClass("java/lang/String"); IntPtr intPtr2 = AndroidJNI.NewObjectArray(length, intPtr, IntPtr.Zero); for (int i = 0; i < length; i++) { IntPtr intPtr3 = AndroidJNISafe.NewStringUTF(array2[i]); AndroidJNI.SetObjectArrayElement(intPtr2, i, intPtr3); AndroidJNISafe.DeleteLocalRef(intPtr3); } AndroidJNISafe.DeleteLocalRef(intPtr); result = intPtr2; } else { if (elementType != typeof(AndroidJavaObject)) { throw new Exception("JNI; Unknown array type '" + elementType + "'"); } AndroidJavaObject[] array3 = (AndroidJavaObject[])array; int length2 = array.GetLength(0); IntPtr[] array4 = new IntPtr[length2]; IntPtr intPtr4 = AndroidJNISafe.FindClass("java/lang/Object"); IntPtr intPtr5 = IntPtr.Zero; for (int j = 0; j < length2; j++) { if (array3[j] != null) { array4[j] = array3[j].GetRawObject(); IntPtr rawClass = array3[j].GetRawClass(); if (intPtr5 != rawClass) { if (intPtr5 == IntPtr.Zero) { intPtr5 = rawClass; } else { intPtr5 = intPtr4; } } } else { array4[j] = IntPtr.Zero; } } IntPtr intPtr6 = AndroidJNISafe.ToObjectArray(array4, intPtr5); AndroidJNISafe.DeleteLocalRef(intPtr4); result = intPtr6; } return(result); }
protected FieldType _Get <FieldType>(string fieldName) { IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(m_jclass, fieldName, isStatic: false); if (AndroidReflection.IsPrimitive(typeof(FieldType))) { if (typeof(FieldType) == typeof(int)) { return((FieldType)(object)AndroidJNISafe.GetIntField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(bool)) { return((FieldType)(object)AndroidJNISafe.GetBooleanField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(byte)) { return((FieldType)(object)AndroidJNISafe.GetByteField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(short)) { return((FieldType)(object)AndroidJNISafe.GetShortField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(long)) { return((FieldType)(object)AndroidJNISafe.GetLongField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(float)) { return((FieldType)(object)AndroidJNISafe.GetFloatField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(double)) { return((FieldType)(object)AndroidJNISafe.GetDoubleField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(char)) { return((FieldType)(object)AndroidJNISafe.GetCharField(m_jobject, fieldID)); } return(default(FieldType)); } if (typeof(FieldType) == typeof(string)) { return((FieldType)(object)AndroidJNISafe.GetStringField(m_jobject, fieldID)); } if (typeof(FieldType) == typeof(AndroidJavaClass)) { IntPtr objectField = AndroidJNISafe.GetObjectField(m_jobject, fieldID); return((!(objectField == IntPtr.Zero)) ? ((FieldType)(object)AndroidJavaClassDeleteLocalRef(objectField)) : default(FieldType)); } if (typeof(FieldType) == typeof(AndroidJavaObject)) { IntPtr objectField2 = AndroidJNISafe.GetObjectField(m_jobject, fieldID); return((!(objectField2 == IntPtr.Zero)) ? ((FieldType)(object)AndroidJavaObjectDeleteLocalRef(objectField2)) : default(FieldType)); } if (AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType))) { IntPtr objectField3 = AndroidJNISafe.GetObjectField(m_jobject, fieldID); return((!(objectField3 == IntPtr.Zero)) ? ((FieldType)(object)AndroidJNIHelper.ConvertFromJNIArray <FieldType>(objectField3)) : default(FieldType)); } throw new Exception("JNI: Unknown field type '" + typeof(FieldType) + "'"); }
public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array) { System.Type elementType = typeof(ArrayType).GetElementType(); if (AndroidReflection.IsPrimitive(elementType)) { if (elementType == typeof(int)) { return((ArrayType)AndroidJNISafe.FromIntArray(array)); } if (elementType == typeof(bool)) { return((ArrayType)AndroidJNISafe.FromBooleanArray(array)); } if (elementType == typeof(byte)) { return((ArrayType)AndroidJNISafe.FromByteArray(array)); } if (elementType == typeof(short)) { return((ArrayType)AndroidJNISafe.FromShortArray(array)); } if (elementType == typeof(long)) { return((ArrayType)AndroidJNISafe.FromLongArray(array)); } if (elementType == typeof(float)) { return((ArrayType)AndroidJNISafe.FromFloatArray(array)); } if (elementType == typeof(double)) { return((ArrayType)AndroidJNISafe.FromDoubleArray(array)); } if (elementType == typeof(char)) { return((ArrayType)AndroidJNISafe.FromCharArray(array)); } } else { if (elementType == typeof(string)) { int num = AndroidJNISafe.GetArrayLength(array); string[] strArray = new string[num]; for (int j = 0; j < num; j++) { IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, j); strArray[j] = AndroidJNISafe.GetStringUTFChars(objectArrayElement); AndroidJNISafe.DeleteLocalRef(objectArrayElement); } return((ArrayType)strArray); } if (elementType != typeof(AndroidJavaObject)) { throw new Exception("JNI: Unknown generic array type '" + elementType + "'"); } int arrayLength = AndroidJNISafe.GetArrayLength(array); AndroidJavaObject[] objArray = new AndroidJavaObject[arrayLength]; for (int i = 0; i < arrayLength; i++) { IntPtr jobject = AndroidJNI.GetObjectArrayElement(array, i); objArray[i] = new AndroidJavaObject(jobject); AndroidJNISafe.DeleteLocalRef(jobject); } return((ArrayType)objArray); } return(default(ArrayType)); }
public static string GetSignature(object obj) { if (obj == null) { return("Ljava/lang/Object;"); } System.Type t = !(obj is System.Type) ? obj.GetType() : ((System.Type)obj); if (AndroidReflection.IsPrimitive(t)) { if (t.Equals(typeof(int))) { return("I"); } if (t.Equals(typeof(bool))) { return("Z"); } if (t.Equals(typeof(byte))) { return("B"); } if (t.Equals(typeof(short))) { return("S"); } if (t.Equals(typeof(long))) { return("J"); } if (t.Equals(typeof(float))) { return("F"); } if (t.Equals(typeof(double))) { return("D"); } if (t.Equals(typeof(char))) { return("C"); } } else { if (t.Equals(typeof(string))) { return("Ljava/lang/String;"); } if (obj is AndroidJavaProxy) { AndroidJavaObject obj2 = new AndroidJavaObject(((AndroidJavaProxy)obj).javaInterface.GetRawClass()); return("L" + obj2.Call <string>("getName", new object[0]) + ";"); } if (t.Equals(typeof(AndroidJavaRunnable))) { return("Ljava/lang/Runnable;"); } if (t.Equals(typeof(AndroidJavaClass))) { return("Ljava/lang/Class;"); } if (t.Equals(typeof(AndroidJavaObject))) { if (obj == t) { return("Ljava/lang/Object;"); } AndroidJavaObject obj3 = (AndroidJavaObject)obj; using (AndroidJavaObject obj4 = obj3.Call <AndroidJavaObject>("getClass", new object[0])) { return("L" + obj4.Call <string>("getName", new object[0]) + ";"); } } if (AndroidReflection.IsAssignableFrom(typeof(Array), t)) { if (t.GetArrayRank() != 1) { throw new Exception("JNI: System.Array in n dimensions is not allowed"); } StringBuilder builder = new StringBuilder(); builder.Append('['); builder.Append(GetSignature(t.GetElementType())); return(builder.ToString()); } object[] objArray1 = new object[] { "JNI: Unknown signature for type '", t, "' (obj = ", obj, ") ", (t != obj) ? "instance" : "equal" }; throw new Exception(string.Concat(objArray1)); } return(""); }
protected FieldType _GetStatic <FieldType>(string fieldName) { IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true); FieldType result; if (AndroidReflection.IsPrimitive(typeof(FieldType))) { if (typeof(FieldType) == typeof(int)) { result = (FieldType)((object)AndroidJNISafe.GetStaticIntField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(bool)) { result = (FieldType)((object)AndroidJNISafe.GetStaticBooleanField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(byte)) { result = (FieldType)((object)AndroidJNISafe.GetStaticByteField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(short)) { result = (FieldType)((object)AndroidJNISafe.GetStaticShortField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(long)) { result = (FieldType)((object)AndroidJNISafe.GetStaticLongField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(float)) { result = (FieldType)((object)AndroidJNISafe.GetStaticFloatField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(double)) { result = (FieldType)((object)AndroidJNISafe.GetStaticDoubleField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(char)) { result = (FieldType)((object)AndroidJNISafe.GetStaticCharField(this.m_jclass, fieldID)); } else { result = default(FieldType); } } else if (typeof(FieldType) == typeof(string)) { result = (FieldType)((object)AndroidJNISafe.GetStaticStringField(this.m_jclass, fieldID)); } else if (typeof(FieldType) == typeof(AndroidJavaClass)) { IntPtr staticObjectField = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID); result = ((!(staticObjectField == IntPtr.Zero)) ? ((FieldType)((object)AndroidJavaObject.AndroidJavaClassDeleteLocalRef(staticObjectField))) : default(FieldType)); } else if (typeof(FieldType) == typeof(AndroidJavaObject)) { IntPtr staticObjectField2 = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID); result = ((!(staticObjectField2 == IntPtr.Zero)) ? ((FieldType)((object)AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(staticObjectField2))) : default(FieldType)); } else { if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType))) { throw new Exception("JNI: Unknown field type '" + typeof(FieldType) + "'"); } IntPtr staticObjectField3 = AndroidJNISafe.GetStaticObjectField(this.m_jclass, fieldID); result = ((!(staticObjectField3 == IntPtr.Zero)) ? ((FieldType)((object)AndroidJNIHelper.ConvertFromJNIArray <FieldType>(staticObjectField3))) : default(FieldType)); } return(result); }
public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array) { Type elementType = typeof(ArrayType).GetElementType(); ArrayType result; if (AndroidReflection.IsPrimitive(elementType)) { if (elementType == typeof(int)) { result = (ArrayType)((object)AndroidJNISafe.FromIntArray(array)); } else if (elementType == typeof(bool)) { result = (ArrayType)((object)AndroidJNISafe.FromBooleanArray(array)); } else if (elementType == typeof(byte)) { result = (ArrayType)((object)AndroidJNISafe.FromByteArray(array)); } else if (elementType == typeof(short)) { result = (ArrayType)((object)AndroidJNISafe.FromShortArray(array)); } else if (elementType == typeof(long)) { result = (ArrayType)((object)AndroidJNISafe.FromLongArray(array)); } else if (elementType == typeof(float)) { result = (ArrayType)((object)AndroidJNISafe.FromFloatArray(array)); } else if (elementType == typeof(double)) { result = (ArrayType)((object)AndroidJNISafe.FromDoubleArray(array)); } else if (elementType == typeof(char)) { result = (ArrayType)((object)AndroidJNISafe.FromCharArray(array)); } else { result = default(ArrayType); } } else if (elementType == typeof(string)) { int arrayLength = AndroidJNISafe.GetArrayLength(array); string[] array2 = new string[arrayLength]; for (int i = 0; i < arrayLength; i++) { IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, i); array2[i] = AndroidJNISafe.GetStringUTFChars(objectArrayElement); AndroidJNISafe.DeleteLocalRef(objectArrayElement); } result = (ArrayType)((object)array2); } else { if (elementType != typeof(AndroidJavaObject)) { throw new Exception("JNI: Unknown generic array type '" + elementType + "'"); } int arrayLength2 = AndroidJNISafe.GetArrayLength(array); AndroidJavaObject[] array3 = new AndroidJavaObject[arrayLength2]; for (int j = 0; j < arrayLength2; j++) { IntPtr objectArrayElement2 = AndroidJNI.GetObjectArrayElement(array, j); array3[j] = new AndroidJavaObject(objectArrayElement2); AndroidJNISafe.DeleteLocalRef(objectArrayElement2); } result = (ArrayType)((object)array3); } return(result); }
protected void _SetStatic <FieldType>(string fieldName, FieldType val) { IntPtr fieldID = AndroidJNIHelper.GetFieldID <FieldType>(this.m_jclass, fieldName, true); if (AndroidReflection.IsPrimitive(typeof(FieldType))) { if (typeof(FieldType) == typeof(int)) { AndroidJNISafe.SetStaticIntField(this.m_jclass, fieldID, (int)((object)val)); } else if (typeof(FieldType) == typeof(bool)) { AndroidJNISafe.SetStaticBooleanField(this.m_jclass, fieldID, (bool)((object)val)); } else if (typeof(FieldType) == typeof(byte)) { AndroidJNISafe.SetStaticByteField(this.m_jclass, fieldID, (byte)((object)val)); } else if (typeof(FieldType) == typeof(short)) { AndroidJNISafe.SetStaticShortField(this.m_jclass, fieldID, (short)((object)val)); } else if (typeof(FieldType) == typeof(long)) { AndroidJNISafe.SetStaticLongField(this.m_jclass, fieldID, (long)((object)val)); } else if (typeof(FieldType) == typeof(float)) { AndroidJNISafe.SetStaticFloatField(this.m_jclass, fieldID, (float)((object)val)); } else if (typeof(FieldType) == typeof(double)) { AndroidJNISafe.SetStaticDoubleField(this.m_jclass, fieldID, (double)((object)val)); } else if (typeof(FieldType) == typeof(char)) { AndroidJNISafe.SetStaticCharField(this.m_jclass, fieldID, (char)((object)val)); } } else if (typeof(FieldType) == typeof(string)) { AndroidJNISafe.SetStaticStringField(this.m_jclass, fieldID, (string)((object)val)); } else if (typeof(FieldType) == typeof(AndroidJavaClass)) { AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, ((AndroidJavaClass)((object)val)).m_jclass); } else if (typeof(FieldType) == typeof(AndroidJavaObject)) { AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, ((AndroidJavaObject)((object)val)).m_jobject); } else { if (!AndroidReflection.IsAssignableFrom(typeof(Array), typeof(FieldType))) { throw new Exception("JNI: Unknown field type '" + typeof(FieldType) + "'"); } IntPtr val2 = AndroidJNIHelper.ConvertToJNIArray((Array)((object)val)); AndroidJNISafe.SetStaticObjectField(this.m_jclass, fieldID, val2); } }
public static IntPtr ConvertToJNIArray(Array array) { System.Type elementType = array.GetType().GetElementType(); if (AndroidReflection.IsPrimitive(elementType)) { if (elementType == typeof(int)) { return(AndroidJNISafe.ToIntArray((int[])array)); } if (elementType == typeof(bool)) { return(AndroidJNISafe.ToBooleanArray((bool[])array)); } if (elementType == typeof(byte)) { return(AndroidJNISafe.ToByteArray((byte[])array)); } if (elementType == typeof(short)) { return(AndroidJNISafe.ToShortArray((short[])array)); } if (elementType == typeof(long)) { return(AndroidJNISafe.ToLongArray((long[])array)); } if (elementType == typeof(float)) { return(AndroidJNISafe.ToFloatArray((float[])array)); } if (elementType == typeof(double)) { return(AndroidJNISafe.ToDoubleArray((double[])array)); } if (elementType == typeof(char)) { return(AndroidJNISafe.ToCharArray((char[])array)); } } else { if (elementType == typeof(string)) { string[] strArray = (string[])array; int size = array.GetLength(0); IntPtr clazz = AndroidJNISafe.FindClass("java/lang/String"); IntPtr ptr3 = AndroidJNI.NewObjectArray(size, clazz, IntPtr.Zero); for (int j = 0; j < size; j++) { IntPtr ptr4 = AndroidJNISafe.NewStringUTF(strArray[j]); AndroidJNI.SetObjectArrayElement(ptr3, j, ptr4); AndroidJNISafe.DeleteLocalRef(ptr4); } AndroidJNISafe.DeleteLocalRef(clazz); return(ptr3); } if (elementType != typeof(AndroidJavaObject)) { throw new Exception("JNI; Unknown array type '" + elementType + "'"); } AndroidJavaObject[] objArray = (AndroidJavaObject[])array; int length = array.GetLength(0); IntPtr[] ptrArray = new IntPtr[length]; IntPtr localref = AndroidJNISafe.FindClass("java/lang/Object"); IntPtr zero = IntPtr.Zero; for (int i = 0; i < length; i++) { if (objArray[i] != null) { ptrArray[i] = objArray[i].GetRawObject(); IntPtr rawClass = objArray[i].GetRawClass(); if (zero != rawClass) { if (zero == IntPtr.Zero) { zero = rawClass; } else { zero = localref; } } } else { ptrArray[i] = IntPtr.Zero; } } IntPtr ptr8 = AndroidJNISafe.ToObjectArray(ptrArray, zero); AndroidJNISafe.DeleteLocalRef(localref); return(ptr8); } return(IntPtr.Zero); }