build/mobile/robocop/RobocopUtils.java

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko;
     7 import java.util.concurrent.SynchronousQueue;
     8 import java.util.concurrent.TimeUnit;
    10 import android.app.Activity;
    12 public final class RobocopUtils {
    13     private static final int MAX_WAIT_MS = 20000;
    15     private RobocopUtils() {}
    17     public static void runOnUiThreadSync(Activity activity, final Runnable runnable) {
    18         final SynchronousQueue syncQueue = new SynchronousQueue();
    19         activity.runOnUiThread(
    20             new Runnable() {
    21                 public void run() {
    22                     runnable.run();
    23                     try {
    24                         syncQueue.put(new Object());
    25                     } catch (InterruptedException e) {
    26                         FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR, e);
    27                     }
    28                 }
    29             });
    30         try {
    31             // Wait for the UiThread code to finish running
    32             if (syncQueue.poll(MAX_WAIT_MS, TimeUnit.MILLISECONDS) == null) {
    33                 FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR,
    34                                        "time-out waiting for UI thread");
    35                 FennecNativeDriver.logAllStackTraces(FennecNativeDriver.LogLevel.ERROR);
    36             }
    37         } catch (InterruptedException e) {
    38             FennecNativeDriver.log(FennecNativeDriver.LogLevel.ERROR, e);
    39         }
    40     }
    41 }

mercurial