diff options
| author | 2024-03-13 14:53:35 -0700 | |
|---|---|---|
| committer | 2024-03-13 14:53:35 -0700 | |
| commit | 02f5de97510fe412bdeaba72728dfc32639bcc88 (patch) | |
| tree | 4cb0f7a8130615137cfccf80d01ad2d81e800162 | |
| parent | 2fd9434406b1d00739bbb36b39b0c338c3f8647c (diff) | |
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
| -rw-r--r-- | packages/PackageInstaller/src/com/android/packageinstaller/InstallSuccess.java | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/InstallSuccess.java b/packages/PackageInstaller/src/com/android/packageinstaller/InstallSuccess.java index 215ead367148..167d50614783 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/InstallSuccess.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/InstallSuccess.java @@ -108,18 +108,19 @@ public class InstallSuccess extends Activity { mDialog = builder.create(); mDialog.show(); mDialog.requireViewById(R.id.install_success).setVisibility(View.VISIBLE); - // Enable or disable "launch" button - boolean enabled = false; + // Show or hide "launch" button + boolean visible = false; if (mLaunchIntent != null) { List<ResolveInfo> list = getPackageManager().queryIntentActivities(mLaunchIntent, 0); if (list != null && list.size() > 0) { - enabled = true; + visible = true; } } + visible = visible && isLauncherActivityEnabled(mLaunchIntent); Button launchButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE); - if (enabled) { + if (visible) { launchButton.setOnClickListener(view -> { try { startActivity(mLaunchIntent.addFlags( @@ -130,7 +131,15 @@ public class InstallSuccess extends Activity { finish(); }); } 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; + } } |