[Settings] Avoid from main UI thread blocking on accessing eSIM
1. Add timeout on background thread when accessing eSIM
2. Print log for debugging in the future.
Bug: 177843016
Change-Id: I64225af6ce87c98119c7a93c0944ad08d1390137
Test: local
(cherry picked from commit bda8c22267
)
This commit is contained in:
@@ -84,6 +84,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
public class MobileNetworkUtils {
|
public class MobileNetworkUtils {
|
||||||
|
|
||||||
@@ -258,9 +260,16 @@ public class MobileNetworkUtils {
|
|||||||
public static boolean showEuiccSettings(Context context) {
|
public static boolean showEuiccSettings(Context context) {
|
||||||
long timeForAccess = SystemClock.elapsedRealtime();
|
long timeForAccess = SystemClock.elapsedRealtime();
|
||||||
try {
|
try {
|
||||||
return ((Future<Boolean>) ThreadUtils.postOnBackgroundThread(()
|
Boolean isShow = ((Future<Boolean>) ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
-> showEuiccSettingsDetecting(context))).get();
|
try {
|
||||||
} catch (ExecutionException | InterruptedException exception) {
|
return showEuiccSettingsDetecting(context);
|
||||||
|
} catch (Exception threadException) {
|
||||||
|
Log.w(TAG, "Accessing Euicc failure", threadException);
|
||||||
|
}
|
||||||
|
return Boolean.FALSE;
|
||||||
|
})).get(3, TimeUnit.SECONDS);
|
||||||
|
return ((isShow != null) && isShow.booleanValue());
|
||||||
|
} catch (ExecutionException | InterruptedException | TimeoutException exception) {
|
||||||
timeForAccess = SystemClock.elapsedRealtime() - timeForAccess;
|
timeForAccess = SystemClock.elapsedRealtime() - timeForAccess;
|
||||||
Log.w(TAG, "Accessing Euicc takes too long: +" + timeForAccess + "ms");
|
Log.w(TAG, "Accessing Euicc takes too long: +" + timeForAccess + "ms");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user