Align main thread checking by calling ThreadUtils

Since ThreadUtils encapsules method to ensure main thread, it is
suggested to call this method rather than maintaining our copy.

Bug: 258270052
Test: atest and manual.
Change-Id: I4c5fcdd6e5bcc7d1d08f526eedb3aa123926d8a1
This commit is contained in:
Shen Lin
2022-10-30 16:57:42 +08:00
parent 08d03390ae
commit ce0e8b9a4b

View File

@@ -26,6 +26,7 @@ import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.OnLifecycleEvent;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.utils.ThreadUtils;
import java.util.HashSet;
@@ -74,7 +75,7 @@ public final class EthernetTetherPreferenceController extends TetherBasePreferen
@Override
public boolean shouldEnable() {
ensureRunningOnMainLoopThread();
ThreadUtils.ensureMainThread();
String[] available = mTm.getTetherableIfaces();
for (String s : available) {
if (mAvailableInterfaces.contains(s)) {
@@ -94,11 +95,4 @@ public final class EthernetTetherPreferenceController extends TetherBasePreferen
return TetheringManager.TETHERING_ETHERNET;
}
private void ensureRunningOnMainLoopThread() {
if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
throw new IllegalStateException(
"Not running on main loop thread: "
+ Thread.currentThread().getName());
}
}
}