diff options
author | Jose <jose@zeroc.com> | 2012-12-14 17:32:22 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2012-12-14 17:32:22 +0100 |
commit | 301cc174e4804045f66ce23b34bff84942db7a09 (patch) | |
tree | da51c05094cb3c379c9c4cb00cdf63e094568f1a /java/src/IceInternal/Util.java | |
parent | Fixed (ICE-4913) - Deprecate Ice::Stats (diff) | |
download | ice-301cc174e4804045f66ce23b34bff84942db7a09.tar.bz2 ice-301cc174e4804045f66ce23b34bff84942db7a09.tar.xz ice-301cc174e4804045f66ce23b34bff84942db7a09.zip |
Fixed (ICE-5114) - android library demo exceptions.
Diffstat (limited to 'java/src/IceInternal/Util.java')
-rw-r--r-- | java/src/IceInternal/Util.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/java/src/IceInternal/Util.java b/java/src/IceInternal/Util.java index d63ed0ea43e..04df20c01ae 100644 --- a/java/src/IceInternal/Util.java +++ b/java/src/IceInternal/Util.java @@ -193,4 +193,45 @@ public final class Util } return java.lang.Thread.NORM_PRIORITY; } + + // + // Return true if the given thread is the android main thread, also know as the GUI thread. + // + public static boolean + isAndroidMainThread(Thread thread) + { + if(!System.getProperty("java.vm.name").startsWith("Dalvik")) + { + return false; + } + + if(_androidMainThread == null) + { + try + { + Class<?> c = Util.findClass("android.os.Looper", null); + java.lang.reflect.Method getMainLooper = c.getDeclaredMethod("getMainLooper", (Class<?>[])null); + java.lang.reflect.Method getThread = c.getDeclaredMethod("getThread", (Class<?>[])null); + + Object looper = getMainLooper.invoke(null); + _androidMainThread = (Thread)getThread.invoke(looper); + } + catch(java.lang.reflect.InvocationTargetException ex) + { + assert false; + } + catch(java.lang.NoSuchMethodException ex) + { + assert false; + } + catch(IllegalAccessException ex) + { + assert false; + } + } + + return thread != null && _androidMainThread == thread; + } + + private static Thread _androidMainThread; } |