From 9b683aec85f49630447b7dff08ce61dd86257676 Mon Sep 17 00:00:00 2001 From: George G Date: Sat, 2 Jul 2016 22:01:03 +0300 Subject: [PATCH] InstalledApp: show link to Google Play Shows a Google Play store icon in the App Info actionbar of apps Excludes aosp built ones, but still works for apps generally found in /system, like SuperSU The openPlayStore() code was created by @nicholaschum for Substratum, thank you! BenzoEdit: fixed it for pie and updated drawable Change-Id: Ic55e572405d97b1f8ae3f8e3b5aceaa38b6a991e Signed-off-by: mydongistiny Signed-off-by: SagarMakhar --- res/drawable/ic_menu_play_store.xml | 13 ++++++++++ res/values/evolution_strings.xml | 3 +++ .../appinfo/AppInfoDashboardFragment.java | 25 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 res/drawable/ic_menu_play_store.xml diff --git a/res/drawable/ic_menu_play_store.xml b/res/drawable/ic_menu_play_store.xml new file mode 100644 index 00000000000..1ffc79e17f0 --- /dev/null +++ b/res/drawable/ic_menu_play_store.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/res/values/evolution_strings.xml b/res/values/evolution_strings.xml index e8d54f3698a..9bda65a4b38 100644 --- a/res/values/evolution_strings.xml +++ b/res/values/evolution_strings.xml @@ -126,4 +126,7 @@ USB configuration Choose the default behavior when connected to a device via USB + + + Google Play diff --git a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java index a87fc0d5cb9..93a8b667d96 100644 --- a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java +++ b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java @@ -37,6 +37,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; import android.hardware.biometrics.BiometricManager; import android.hardware.biometrics.BiometricPrompt; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.CancellationSignal; @@ -56,6 +57,7 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.Utils; import com.android.settings.applications.manageapplications.ManageApplications; import com.android.settings.applications.specialaccess.interactacrossprofiles.InteractAcrossProfilesDetailsPreferenceController; import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetailPreferenceController; @@ -94,6 +96,7 @@ public class AppInfoDashboardFragment extends DashboardFragment static final int UNINSTALL_UPDATES = 2; static final int INSTALL_INSTANT_APP_MENU = 3; static final int ACCESS_RESTRICTED_SETTINGS = 4; + public static final int PLAY_STORE = 5; // Result code identifiers @VisibleForTesting @@ -402,6 +405,9 @@ public class AppInfoDashboardFragment extends DashboardFragment @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); + menu.add(0, PLAY_STORE, 0, R.string.app_play_store) + .setIcon(R.drawable.ic_menu_play_store) + .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); menu.add(0, UNINSTALL_UPDATES, 0, R.string.app_factory_reset) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text) @@ -437,6 +443,10 @@ public class AppInfoDashboardFragment extends DashboardFragment RestrictedLockUtilsInternal.setMenuItemAsDisabledByAdmin(getActivity(), uninstallUpdatesItem, mAppsControlDisallowedAdmin); } + // Utils.isSystemPackage doesn't include all aosp built apps, like Contacts etc. Add them + // and grab the Google Play Store itself (com.android.vending) in the process + menu.findItem(PLAY_STORE).setVisible(!Utils.isSystemPackage(getContext().getResources(), mPm, mPackageInfo) + && !isAospOrStore(mAppEntry.info.packageName)); } /** Shows the lock screen if the keyguard is secured. */ @@ -490,6 +500,9 @@ public class AppInfoDashboardFragment extends DashboardFragment case UNINSTALL_UPDATES: uninstallPkg(mAppEntry.info.packageName, false, false); return true; + case PLAY_STORE: + openPlayStore(mAppEntry.info.packageName); + return true; case ACCESS_RESTRICTED_SETTINGS: showLockScreen(getContext(), () -> { if (android.permission.flags.Flags.enhancedConfirmationModeApisEnabled() @@ -515,7 +528,6 @@ public class AppInfoDashboardFragment extends DashboardFragment mAppEntry.label); Toast.makeText(getContext(), toastString, Toast.LENGTH_LONG).show(); }); - return true; } return super.onOptionsItemSelected(item); } @@ -638,6 +650,17 @@ public class AppInfoDashboardFragment extends DashboardFragment return true; } + private void openPlayStore(String packageName) { + // Launch an intent to the play store entry + String playURL = "https://play.google.com/store/apps/details?id=" + packageName; + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(playURL)); + startActivity(i); + } + private boolean isAospOrStore(String packageName) { + return packageName.contains("com.android"); + } + private void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) { stopListeningToPackageRemove(); // Create new intent to launch Uninstaller activity