Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 618045d

Browse files
authored
Remove org.mozilla.gecko.util.ThreadUtils usage (#3076)
1 parent ee26bb6 commit 618045d

File tree

10 files changed

+89
-12
lines changed

10 files changed

+89
-12
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/engine/SessionStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import androidx.annotation.NonNull;
99
import androidx.annotation.Nullable;
1010

11-
import org.mozilla.gecko.util.ThreadUtils;
1211
import org.mozilla.geckoview.GeckoRuntime;
1312
import org.mozilla.geckoview.GeckoSession;
1413
import org.mozilla.vrbrowser.VRBrowserApplication;
@@ -19,6 +18,7 @@
1918
import org.mozilla.vrbrowser.browser.content.TrackingProtectionStore;
2019
import org.mozilla.vrbrowser.db.SitePermission;
2120
import org.mozilla.vrbrowser.utils.SystemUtils;
21+
import org.mozilla.vrbrowser.utils.ThreadUtils;
2222
import org.mozilla.vrbrowser.utils.UrlUtils;
2323

2424
import java.util.ArrayList;

app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/LanguagesAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import androidx.databinding.DataBindingUtil;
1616
import androidx.recyclerview.widget.RecyclerView;
1717

18-
import org.mozilla.gecko.util.ThreadUtils;
1918
import org.mozilla.vrbrowser.R;
2019
import org.mozilla.vrbrowser.databinding.LanguageItemBinding;
2120
import org.mozilla.vrbrowser.ui.callbacks.LanguageItemCallback;
21+
import org.mozilla.vrbrowser.utils.ThreadUtils;
2222
import org.mozilla.vrbrowser.utils.ViewUtils;
2323

2424
import java.util.Collections;

app/src/common/shared/org/mozilla/vrbrowser/ui/views/UIButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import androidx.annotation.Nullable;
2626
import androidx.appcompat.widget.AppCompatImageButton;
2727

28-
import org.mozilla.gecko.util.ThreadUtils;
2928
import org.mozilla.vrbrowser.R;
3029
import org.mozilla.vrbrowser.ui.widgets.TooltipWidget;
3130
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
3231
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
32+
import org.mozilla.vrbrowser.utils.ThreadUtils;
3333
import org.mozilla.vrbrowser.utils.ViewUtils;
3434

3535
public class UIButton extends AppCompatImageButton implements CustomUIButton {

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/NotificationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import androidx.annotation.NonNull;
1010
import androidx.annotation.StringRes;
1111

12-
import org.mozilla.gecko.util.ThreadUtils;
1312
import org.mozilla.vrbrowser.R;
1413
import org.mozilla.vrbrowser.ui.views.UIButton;
1514
import org.mozilla.vrbrowser.ui.widgets.NotificationManager.Notification.NotificationPosition;
15+
import org.mozilla.vrbrowser.utils.ThreadUtils;
1616

1717
import java.util.HashMap;
1818
import java.util.Iterator;

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.mozilla.speechlibrary.MozillaSpeechService;
2626
import com.mozilla.speechlibrary.STTResult;
2727

28-
import org.mozilla.gecko.util.ThreadUtils;
2928
import org.mozilla.vrbrowser.R;
3029
import org.mozilla.vrbrowser.browser.SettingsStore;
3130
import org.mozilla.vrbrowser.browser.engine.EngineProvider;
@@ -34,6 +33,7 @@
3433
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
3534
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
3635
import org.mozilla.vrbrowser.utils.LocaleUtils;
36+
import org.mozilla.vrbrowser.utils.ThreadUtils;
3737

3838
public class VoiceSearchWidget extends UIDialog implements WidgetManagerDelegate.PermissionListener,
3939
Application.ActivityLifecycleCallbacks {

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/ContentLanguageOptionsView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
import androidx.databinding.DataBindingUtil;
1414

15-
import org.mozilla.gecko.util.ThreadUtils;
1615
import org.mozilla.vrbrowser.R;
17-
import org.mozilla.vrbrowser.browser.SettingsStore;
1816
import org.mozilla.vrbrowser.browser.engine.SessionStore;
1917
import org.mozilla.vrbrowser.databinding.OptionsLanguageContentBinding;
2018
import org.mozilla.vrbrowser.ui.adapters.Language;
@@ -23,6 +21,7 @@
2321
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
2422
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
2523
import org.mozilla.vrbrowser.utils.LocaleUtils;
24+
import org.mozilla.vrbrowser.utils.ThreadUtils;
2625

2726
import java.util.Collections;
2827
import java.util.List;

app/src/common/shared/org/mozilla/vrbrowser/utils/AnimationHelper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.animation.Animator;
44
import android.animation.AnimatorListenerAdapter;
55
import android.animation.ValueAnimator;
6-
import android.util.Log;
76
import android.view.View;
87
import android.view.animation.AccelerateDecelerateInterpolator;
98
import android.view.animation.AccelerateInterpolator;
@@ -13,8 +12,6 @@
1312

1413
import androidx.annotation.NonNull;
1514

16-
import org.mozilla.gecko.util.ThreadUtils;
17-
1815
public class AnimationHelper {
1916
public static final long FADE_ANIMATION_DURATION = 150;
2017

app/src/common/shared/org/mozilla/vrbrowser/utils/SystemUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import androidx.annotation.NonNull;
1010

11-
import org.mozilla.gecko.util.ThreadUtils;
1211
import org.mozilla.geckoview.CrashReporter;
1312
import org.mozilla.geckoview.GeckoResult;
1413
import org.mozilla.vrbrowser.BuildConfig;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.mozilla.vrbrowser.utils;
2+
3+
import android.os.Handler;
4+
import android.os.Looper;
5+
6+
public class ThreadUtils extends Thread {
7+
private static final Handler sUiHandler = new Handler(Looper.getMainLooper());
8+
9+
private static final String LOOPER_NAME = "VRBBackgroundThread";
10+
11+
// Guarded by 'ThreadUtils.class'.
12+
private static Handler mBackgroundHandler;
13+
private static Thread mBackgroundThread;
14+
15+
// The initial Runnable to run on the new mBackgroundThread. Its purpose
16+
// is to avoid us having to wait for the new mBackgroundThread to start.
17+
private Runnable mInitialRunnable;
18+
19+
// Singleton, so private constructor.
20+
private ThreadUtils(final Runnable initialRunnable) {
21+
mInitialRunnable = initialRunnable;
22+
}
23+
24+
@Override
25+
public void run() {
26+
setName(LOOPER_NAME);
27+
Looper.prepare();
28+
29+
synchronized (ThreadUtils.class) {
30+
mBackgroundHandler = new Handler();
31+
ThreadUtils.class.notifyAll();
32+
}
33+
34+
if (mInitialRunnable != null) {
35+
mInitialRunnable.run();
36+
mInitialRunnable = null;
37+
}
38+
39+
Looper.loop();
40+
}
41+
42+
private static void startThread(final Runnable initialRunnable) {
43+
mBackgroundThread = new ThreadUtils(initialRunnable);
44+
mBackgroundThread.setDaemon(true);
45+
mBackgroundThread.start();
46+
}
47+
48+
// Get a Handler for a looper mBackgroundThread, or create one if it doesn't yet exist.
49+
/*package*/ static synchronized Handler getHandler() {
50+
if (mBackgroundThread == null) {
51+
startThread(null);
52+
}
53+
54+
while (mBackgroundHandler == null) {
55+
try {
56+
ThreadUtils.class.wait();
57+
} catch (final InterruptedException e) {
58+
}
59+
}
60+
return mBackgroundHandler;
61+
}
62+
63+
public static synchronized void postToBackgroundThread(final Runnable runnable) {
64+
if (mBackgroundThread == null) {
65+
startThread(runnable);
66+
return;
67+
}
68+
getHandler().post(runnable);
69+
}
70+
71+
public static void postToUiThread(final Runnable runnable) {
72+
sUiHandler.post(runnable);
73+
}
74+
75+
public static void postDelayedToUiThread(final Runnable runnable, final long timeout) {
76+
sUiHandler.postDelayed(runnable, timeout);
77+
}
78+
79+
public static void removeCallbacksFromUiThread(final Runnable runnable) {
80+
sUiHandler.removeCallbacks(runnable);
81+
}
82+
}

versions.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ext.deps = [:]
2424
def versions = [:]
2525
// GeckoView versions can be found here:
2626
// https://maven.mozilla.org/?prefix=maven2/org/mozilla/geckoview/
27-
versions.gecko_view = "76.0.20200324093140"
27+
versions.gecko_view = "76.0.20200330094747"
2828
versions.android_components = "28.0.1"
2929
// Note that android-components also depends on application-services,
3030
// and in fact is our main source of appservices-related functionality.

0 commit comments

Comments
 (0)