From 43f9adea620edad452210ce56712d16ce93bbb8b Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Mon, 1 Jun 2020 10:31:46 +0100 Subject: [PATCH] Improved UX when no debuggable apps are available. In AppPicker, add an extra to exclude the "Nothing" sentinel. This is used when selecting a debug app, and makes sense in that context. However it does not makes sense when choosing an app to modify compatibilty options for, so exclude it. Also update the AppPicker to return a new result code in the case that there are no apps available which match the criteria given. This result code can only be used when the new extra is defined which keep this change low risk. In PlatformCompatDashboard, use the new extra and handle the new result code, showing a dialog to explain that only debuggable apps are shown in user builds. This also results in the "Nothing" item being shown at the top of the app list. Bug: 157633308 Test: Manual Change-Id: Ifb055dd7c030cda42556bca8a9d7e87606f0ff72 --- res/values/strings.xml | 4 ++++ .../android/settings/development/AppPicker.java | 14 +++++++++++--- .../compat/PlatformCompatDashboard.java | 12 +++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 366254f2bc7..38676a12f4e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11267,6 +11267,10 @@ Default disabled changes Enabled for targetSdkVersion > %d + + No apps available + + App compatibility changes can only be modified for debuggable apps. Install a debuggable app and try again. diff --git a/src/com/android/settings/development/AppPicker.java b/src/com/android/settings/development/AppPicker.java index d819bc23fec..7854de22c93 100644 --- a/src/com/android/settings/development/AppPicker.java +++ b/src/com/android/settings/development/AppPicker.java @@ -46,10 +46,14 @@ public class AppPicker extends ListActivity { = "com.android.settings.extra.REQUESTIING_PERMISSION"; public static final String EXTRA_DEBUGGABLE = "com.android.settings.extra.DEBUGGABLE"; public static final String EXTRA_NON_SYSTEM = "com.android.settings.extra.NON_SYSTEM"; + public static final String EXTRA_INCLUDE_NOTHING = "com.android.settings.extra.INCLUDE_NOTHING"; + + public static final int RESULT_NO_MATCHING_APPS = -2; private String mPermissionName; private boolean mDebuggableOnly; private boolean mNonSystemOnly; + private boolean mIncludeNothing; @Override protected void onCreate(Bundle icicle) { @@ -58,9 +62,11 @@ public class AppPicker extends ListActivity { mPermissionName = getIntent().getStringExtra(EXTRA_REQUESTIING_PERMISSION); mDebuggableOnly = getIntent().getBooleanExtra(EXTRA_DEBUGGABLE, false); mNonSystemOnly = getIntent().getBooleanExtra(EXTRA_NON_SYSTEM, false); + mIncludeNothing = getIntent().getBooleanExtra(EXTRA_INCLUDE_NOTHING, true); mAdapter = new AppListAdapter(this); if (mAdapter.getCount() <= 0) { + setResult(RESULT_NO_MATCHING_APPS); finish(); } else { setListAdapter(mAdapter); @@ -140,9 +146,11 @@ public class AppPicker extends ListActivity { mPackageInfoList.add(info); } Collections.sort(mPackageInfoList, sDisplayNameComparator); - MyApplicationInfo info = new MyApplicationInfo(); - info.label = context.getText(R.string.no_application); - mPackageInfoList.add(0, info); + if (mIncludeNothing) { + MyApplicationInfo info = new MyApplicationInfo(); + info.label = context.getText(R.string.no_application); + mPackageInfoList.add(0, info); + } addAll(mPackageInfoList); } diff --git a/src/com/android/settings/development/compat/PlatformCompatDashboard.java b/src/com/android/settings/development/compat/PlatformCompatDashboard.java index 2f2c7509851..fe64948e905 100644 --- a/src/com/android/settings/development/compat/PlatformCompatDashboard.java +++ b/src/com/android/settings/development/compat/PlatformCompatDashboard.java @@ -20,6 +20,7 @@ import static com.android.internal.compat.OverrideAllowedState.ALLOWED; import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_COMPAT_CHANGE_APP; import android.app.Activity; +import android.app.AlertDialog; import android.app.settings.SettingsEnums; import android.compat.Compatibility.ChangeConfig; import android.content.Context; @@ -124,6 +125,14 @@ public class PlatformCompatDashboard extends DashboardFragment { } catch (PackageManager.NameNotFoundException e) { startAppPicker(); } + } else if (resultCode == AppPicker.RESULT_NO_MATCHING_APPS) { + new AlertDialog.Builder(getContext()) + .setTitle(R.string.platform_compat_dialog_title_no_apps) + .setMessage(R.string.platform_compat_dialog_text_no_apps) + .setPositiveButton(R.string.okay, (dialog, which) -> finish()) + .setOnDismissListener(dialog -> finish()) + .setCancelable(false) + .show(); } return; } @@ -254,7 +263,8 @@ public class PlatformCompatDashboard extends DashboardFragment { } private void startAppPicker() { - final Intent intent = new Intent(getContext(), AppPicker.class); + final Intent intent = new Intent(getContext(), AppPicker.class) + .putExtra(AppPicker.EXTRA_INCLUDE_NOTHING, false); // If build is neither userdebug nor eng, only include debuggable apps final boolean debuggableBuild = mAndroidBuildClassifier.isDebuggableBuild(); if (!debuggableBuild) {