1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.android_webview; 6 7 import android.os.Handler; 8 9 import org.chromium.base.ThreadUtils; 10 11 /** 12 * Provides WebView-specific threading utilities. 13 */ 14 public class AwThreadUtils { 15 /** 16 * Post a task to the current thread, ensuring that it runs on the underlying Android looper 17 * without any native code present on the stack. This allows uncaught Java exceptions to be 18 * handled correctly by Android's crash reporting mechanisms. 19 */ postToCurrentLooper(Runnable r)20 public static void postToCurrentLooper(Runnable r) { 21 new Handler().post(r); 22 } 23 24 /** 25 * Post a task to the UI thread, ensuring that it runs on the underlying Android looper without 26 * any native code present on the stack. This allows uncaught Java exceptions to be handled 27 * correctly by Android's crash reporting mechanisms. 28 */ postToUiThreadLooper(Runnable r)29 public static void postToUiThreadLooper(Runnable r) { 30 ThreadUtils.getUiThreadHandler().post(r); 31 } 32 } 33