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:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user