From f2930aad5d48fcb9398662a1e6d567edd2239e4f Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Thu, 6 Jun 2024 14:19:33 +0800 Subject: [PATCH] Fix mSubscriptionInfoEntity NullPointerException Due to concurrent, mSubscriptionInfoEntity could become null when inference. Save the subscriptionInfoEntity to local variable to fix. Fix: 345319514 Test: manual on MobileNetworkSettings Change-Id: I9d286b30ade65dabdfd4a394cdbe1c1c87435d02 --- .../telephony/MobileNetworkSettings.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java index 1c3c78d9706..8b927a9f1ca 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java @@ -68,7 +68,6 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.function.Consumer; @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) public class MobileNetworkSettings extends AbstractMobileNetworkSettings implements @@ -359,23 +358,17 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme } private void onSubscriptionDetailChanged() { - if (mSubscriptionInfoEntity != null) { - /** - * Update the title when SIM stats got changed - */ - final Consumer renameTitle = activity -> { - if (activity != null && !activity.isFinishing()) { - if (activity instanceof SettingsActivity) { - ((SettingsActivity) activity).setTitle(mSubscriptionInfoEntity.uniqueName); - } - } - }; - - ThreadUtils.postOnMainThread(() -> { - renameTitle.accept(getActivity()); - redrawPreferenceControllers(); - }); + final SubscriptionInfoEntity subscriptionInfoEntity = mSubscriptionInfoEntity; + if (subscriptionInfoEntity == null) { + return; } + ThreadUtils.postOnMainThread(() -> { + if (getActivity() instanceof SettingsActivity activity && !activity.isFinishing()) { + // Update the title when SIM stats got changed + activity.setTitle(subscriptionInfoEntity.uniqueName); + } + redrawPreferenceControllers(); + }); } @Override