From 656c9652220423629c349d3ba039f6138d5a6f68 Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Fri, 13 Aug 2021 14:35:31 +0000 Subject: [PATCH] [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 bda8c222673b840527376b52cf7da561f66e537d) --- .../network/telephony/MobileNetworkUtils.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java index 6e5d4b7b8eb..ba519f1dfe2 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java +++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java @@ -84,6 +84,8 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class MobileNetworkUtils { @@ -258,9 +260,16 @@ public class MobileNetworkUtils { public static boolean showEuiccSettings(Context context) { long timeForAccess = SystemClock.elapsedRealtime(); try { - return ((Future) ThreadUtils.postOnBackgroundThread(() - -> showEuiccSettingsDetecting(context))).get(); - } catch (ExecutionException | InterruptedException exception) { + Boolean isShow = ((Future) ThreadUtils.postOnBackgroundThread(() -> { + try { + 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; Log.w(TAG, "Accessing Euicc takes too long: +" + timeForAccess + "ms"); }