This source file includes following definitions.
- JNINamespace
 
- SuppressWarnings
 
- runNestedLoopTillIdle
 
- SuppressWarnings
 
- create
 
package org.chromium.content.browser.test;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@JNINamespace("content")
class NestedSystemMessageHandler {
    
    
    private static final int QUIT_MESSAGE = 10;
    private static final Handler mHandler = new Handler();
    private NestedSystemMessageHandler() {
    }
    
    @SuppressWarnings("unused")
    @CalledByNative
    private boolean runNestedLoopTillIdle() {
        boolean quitLoop = false;
        MessageQueue queue = Looper.myQueue();
        queue.addIdleHandler(new MessageQueue.IdleHandler() {
            @Override
            public boolean queueIdle() {
                mHandler.sendMessage(mHandler.obtainMessage(QUIT_MESSAGE));
                return false;
            }
        });
        Class<?> messageQueueClazz = queue.getClass();
        Method nextMethod = null;
        try {
            nextMethod = messageQueueClazz.getDeclaredMethod("next");
        } catch (SecurityException e) {
            e.printStackTrace();
            return false;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            return false;
        }
        nextMethod.setAccessible(true);
        while (!quitLoop) {
            Message msg = null;
            try {
                msg = (Message) nextMethod.invoke(queue);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                return false;
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                return false;
            } catch (InvocationTargetException e) {
                e.printStackTrace();
                return false;
            }
            if (msg != null) {
                if (msg.what == QUIT_MESSAGE) {
                    quitLoop = true;
                }
                Class messageClazz = msg.getClass();
                Field targetFiled = null;
                try {
                    targetFiled = messageClazz.getDeclaredField("target");
                } catch (SecurityException e) {
                    e.printStackTrace();
                    return false;
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                    return false;
                }
                targetFiled.setAccessible(true);
                Handler target = null;
                try {
                    target = (Handler) targetFiled.get(msg);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                    return false;
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                    return false;
                }
                if (target == null) {
                    
                    quitLoop = true;
                } else {
                    target.dispatchMessage(msg);
                }
                msg.recycle();
            } else {
                quitLoop = true;
            }
        }
        return true;
    }
    @SuppressWarnings("unused")
    @CalledByNative
    private static NestedSystemMessageHandler create() {
        return new NestedSystemMessageHandler();
    }
}