Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90f009eb authored by Robin Lee's avatar Robin Lee Committed by android-build-merger
Browse files

Merge "[VpnSettings]Crash when activity has been recycled" am: fb81f50c

am: c834ed1e

Change-Id: I32ddda40ed4654288eef45dfdb2f53b2f9aba988
parents 76fb361b c834ed1e
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.vpn2;
import android.annotation.UiThread;
import android.annotation.WorkerThread;
import android.app.AppOpsManager;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
@@ -208,9 +209,16 @@ public class VpnSettings extends RestrictedSettingsFragment implements
    public boolean handleMessage(Message message) {
        mUpdater.removeMessages(RESCAN_MESSAGE);

        //Return if activity has been recycled
        final Activity activity = getActivity();
        if (activity == null) {
            return true;
        }
        final Context context = activity.getApplicationContext();

        // Run heavy RPCs before switching to UI thread
        final List<VpnProfile> vpnProfiles = loadVpnProfiles(mKeyStore);
        final List<AppVpnInfo> vpnApps = getVpnApps(getActivity(), /* includeProfiles */ true);
        final List<AppVpnInfo> vpnApps = getVpnApps(context, /* includeProfiles */ true);

        final Map<String, LegacyVpnInfo> connectedLegacyVpns = getConnectedLegacyVpns();
        final Set<AppVpnInfo> connectedAppVpns = getConnectedAppVpns();
@@ -219,7 +227,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
        final String lockdownVpnKey = VpnUtils.getLockdownVpn();

        // Refresh list of VPNs
        getActivity().runOnUiThread(new Runnable() {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // Can't do anything useful if the context has gone away
@@ -271,7 +279,6 @@ public class VpnSettings extends RestrictedSettingsFragment implements
                }
            }
        });

        mUpdater.sendEmptyMessageDelayed(RESCAN_MESSAGE, RESCAN_INTERVAL_MS);
        return true;
    }