From 9ba80e76b38ce8c23e29dd15372c8688451b8c83 Mon Sep 17 00:00:00 2001 From: Arc Wang Date: Fri, 25 Feb 2022 12:35:20 +0800 Subject: [PATCH] Only show 2-pane deep link when homepage is available DeepLinkHomepageActivity is disabled by default and may be enabled after receiving the PRE_BOOT_COMPLETED broadcast. On some virtual devices, DeepLinkHomepageActivity may not be enabled for test cases. This is a fallback option to show a full screen Activity to pass tests. Bug: 221149428 Test: make RunSettingsRoboTests ROBOTEST_FILTER=SettingsActivityTest Change-Id: I4bbe785176fe3fe8831484141aff7367e4ca25ce --- src/com/android/settings/SettingsActivity.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index d9dc590c708..37d4a4e99eb 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -24,6 +24,7 @@ import static com.android.settings.applications.appinfo.AppButtonsPreferenceCont import android.app.ActionBar; import android.app.ActivityManager; +import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -253,8 +254,7 @@ public class SettingsActivity extends SettingsBaseActivity getMetaData(); final Intent intent = getIntent(); - if (shouldShowTwoPaneDeepLink(intent)) { - launchHomepageForTwoPaneDeepLink(intent); + if (shouldShowTwoPaneDeepLink(intent) && tryStartTwoPaneDeepLink(intent)) { finishAndRemoveTask(); super.onCreate(savedState); return; @@ -412,7 +412,7 @@ public class SettingsActivity extends SettingsBaseActivity return trampolineIntent; } - private void launchHomepageForTwoPaneDeepLink(Intent intent) { + private boolean tryStartTwoPaneDeepLink(Intent intent) { final Intent trampolineIntent; if (intent.getBooleanExtra(EXTRA_IS_FROM_SLICE, false)) { // Get menu key for slice deep link case. @@ -426,7 +426,14 @@ public class SettingsActivity extends SettingsBaseActivity } else { trampolineIntent = getTrampolineIntent(intent, mHighlightMenuKey); } - startActivity(trampolineIntent); + + try { + startActivity(trampolineIntent); + } catch (ActivityNotFoundException e) { + Log.e(LOG_TAG, "Deep link homepage is not available to show 2-pane UI"); + return false; + } + return true; } private boolean shouldShowTwoPaneDeepLink(Intent intent) {