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

Commit 9472fee0 authored by oli's avatar oli
Browse files

Fix InteratAcrossProfilesDetails window leak

activity was being finished without dismissing alertdialog when activity
is launched from an app. causing window leak

1. dismiss dialog and remove reference when activity is destroyed
2. dismiss dialog if it is already showing when mDialog.show() is called

Test: Manually tested
Flag: EXEMPT bugfix
Bug: 417379811
Change-Id: I27a4ac2ade083594240d635a403c47a75351afa1
parent eba6276a
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.provider.Settings.Global.CONNECTED_APPS_ALLOWED_PACKAGES;
import static android.provider.Settings.Global.CONNECTED_APPS_DISALLOWED_PACKAGES;

import android.Manifest;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActionBar;
import android.app.AppOpsManager;
@@ -107,6 +108,8 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
    private String mAppLabel;
    private Intent mInstallAppIntent;
    private boolean mIsPageLaunchedByApp;
    @Nullable
    private AlertDialog mDialog = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
@@ -307,6 +310,9 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
    }

    private void showConsentDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
        final View dialogView = getLayoutInflater().inflate(
                R.layout.interact_across_profiles_consent_dialog, null);

@@ -343,13 +349,14 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(dialogView)
        mDialog = builder.setView(dialogView)
                .setPositiveButton(R.string.allow, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        logEvent(DevicePolicyEnums.CROSS_PROFILE_SETTINGS_PAGE_USER_CONSENTED);
                        enableInteractAcrossProfiles(true);
                        refreshUi();
                        if (mIsPageLaunchedByApp) {
                            dialog.dismiss();
                            setIntentAndFinish(/* appChanged= */ true);
                        }
                    }
@@ -361,7 +368,8 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
                        refreshUi();
                    }
                })
                .create().show();
                .create();
        mDialog.show();
    }

    private boolean isInteractAcrossProfilesEnabled() {
@@ -536,7 +544,8 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
        mSwitchPref.setChecked(true);
        mSwitchPref.setTitle(R.string.interact_across_profiles_switch_enabled);
        final ImageView horizontalArrowIcon =
                mHeader.findViewById(com.android.settingslib.widget.preference.layout.R.id.entity_header_swap_horiz);
                mHeader.findViewById(
                        com.android.settingslib.widget.preference.layout.R.id.entity_header_swap_horiz);
        if (horizontalArrowIcon != null) {
            horizontalArrowIcon.setImageDrawable(
                    mContext.getDrawable(
@@ -548,7 +557,8 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
        mSwitchPref.setChecked(false);
        mSwitchPref.setTitle(R.string.interact_across_profiles_switch_disabled);
        final ImageView horizontalArrowIcon =
                mHeader.findViewById(com.android.settingslib.widget.preference.layout.R.id.entity_header_swap_horiz);
                mHeader.findViewById(
                        com.android.settingslib.widget.preference.layout.R.id.entity_header_swap_horiz);
        if (horizontalArrowIcon != null) {
            horizontalArrowIcon.setImageDrawable(
                    mContext.getDrawable(
@@ -556,6 +566,15 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
        }
    }

    @Override
    public void onDestroy() {
        if (mDialog != null) {
            mDialog.dismiss();
        }
        mDialog = null;
        super.onDestroy();
    }

    @Override
    protected AlertDialog createDialog(int id, int errorCode) {
        return null;