From 37b179fa8cdde8e00a745cbf030bcb1836e921c4 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Thu, 17 Mar 2016 10:20:29 +0000 Subject: [PATCH] vpn: check fragment is visible before adding prefs As VPN settings listens to network events it may get woken up again while it's in the background. Bug: 23596799 Change-Id: If6e07493da447d7ded324ff86b6e7d57c5c615e3 --- src/com/android/settings/vpn2/VpnSettings.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java index 4e21c05da77..e5a78b68f7e 100644 --- a/src/com/android/settings/vpn2/VpnSettings.java +++ b/src/com/android/settings/vpn2/VpnSettings.java @@ -222,6 +222,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements public boolean handleMessage(Message message) { mUpdater.removeMessages(RESCAN_MESSAGE); + // Run heavy RPCs before switching to UI thread final List vpnProfiles = loadVpnProfiles(mKeyStore); final List vpnApps = getVpnApps(getActivity(), /* includeProfiles */ true); @@ -230,10 +231,15 @@ public class VpnSettings extends RestrictedSettingsFragment implements final Set readOnlyUsers = getReadOnlyUserProfiles(); - // Refresh the PreferenceGroup which lists VPNs + // Refresh list of VPNs getActivity().runOnUiThread(new Runnable() { @Override public void run() { + // Can't do anything useful if the context has gone away + if (!isAdded()) { + return; + } + // Find new VPNs by subtracting existing ones from the full set final Set updates = new ArraySet<>();