From dcebd83e9f1b19191dc1400db57f94e6139f151b Mon Sep 17 00:00:00 2001 From: bswe Date: Thu, 3 Oct 2019 12:02:51 -0700 Subject: [PATCH] Issue #5233: Added doesPrivateBrowsingPinnedShortcutExist function to determine whether a shortcut already exists (only available in API >=25). --- .../PrivateShortcutCreateManager.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/PrivateShortcutCreateManager.kt b/app/src/main/java/org/mozilla/fenix/components/PrivateShortcutCreateManager.kt index d2e0316d6..13157bb02 100644 --- a/app/src/main/java/org/mozilla/fenix/components/PrivateShortcutCreateManager.kt +++ b/app/src/main/java/org/mozilla/fenix/components/PrivateShortcutCreateManager.kt @@ -14,12 +14,30 @@ import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.home.intent.StartSearchIntentProcessor import java.util.UUID +import android.content.pm.ShortcutManager +import android.os.Build +import android.os.Build.VERSION.SDK_INT /** - * Handles the creation of pinned shortcuts. + * Handles the creation and existence of pinned shortcuts. */ object PrivateShortcutCreateManager { + fun doesPrivateBrowsingPinnedShortcutExist(context: Context) : Boolean { + return if (SDK_INT >= Build.VERSION_CODES.N_MR1) { + val pinnedShortcuts = context.getSystemService(ShortcutManager::class.java).pinnedShortcuts + for (s in pinnedShortcuts) { + if (s.intent?.extras?.getString(HomeActivity.OPEN_TO_SEARCH) == + StartSearchIntentProcessor.PRIVATE_BROWSING_PINNED_SHORTCUT) { + return true + } + } + false + } else { + false + } + } + fun createPrivateShortcut(context: Context) { if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) return