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

Commit 02f5de97 authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Hide the open button when launcher activity is disabled

If the newly installed app cannot be opened, do not show the launch
button to prevent confusing the users.

Bug: 316619479
Test: atest CtsPackageInstallTestCases:IntentTest

Change-Id: Ibd7f5b006118fdbe1c01671ac7bcabafd334e3fa
parent 2fd94344
Loading
Loading
Loading
Loading
+14 −5
Original line number Original line Diff line number Diff line
@@ -108,18 +108,19 @@ public class InstallSuccess extends Activity {
        mDialog = builder.create();
        mDialog = builder.create();
        mDialog.show();
        mDialog.show();
        mDialog.requireViewById(R.id.install_success).setVisibility(View.VISIBLE);
        mDialog.requireViewById(R.id.install_success).setVisibility(View.VISIBLE);
        // Enable or disable "launch" button
        // Show or hide "launch" button
        boolean enabled = false;
        boolean visible = false;
        if (mLaunchIntent != null) {
        if (mLaunchIntent != null) {
            List<ResolveInfo> list = getPackageManager().queryIntentActivities(mLaunchIntent,
            List<ResolveInfo> list = getPackageManager().queryIntentActivities(mLaunchIntent,
                    0);
                    0);
            if (list != null && list.size() > 0) {
            if (list != null && list.size() > 0) {
                enabled = true;
                visible = true;
            }
            }
        }
        }
        visible = visible && isLauncherActivityEnabled(mLaunchIntent);


        Button launchButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        Button launchButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        if (enabled) {
        if (visible) {
            launchButton.setOnClickListener(view -> {
            launchButton.setOnClickListener(view -> {
                try {
                try {
                    startActivity(mLaunchIntent.addFlags(
                    startActivity(mLaunchIntent.addFlags(
@@ -130,7 +131,15 @@ public class InstallSuccess extends Activity {
                finish();
                finish();
            });
            });
        } else {
        } else {
            launchButton.setEnabled(false);
            launchButton.setVisibility(View.GONE);
        }
        }
    }
    }

    private boolean isLauncherActivityEnabled(Intent intent) {
        if (intent == null || intent.getComponent() == null) {
            return false;
        }
        return getPackageManager().getComponentEnabledSetting(intent.getComponent())
            != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }
}
}