Add logging to shortcut pin request handler

This commit is contained in:
MM20 2023-10-02 10:54:51 +02:00
parent e08e9a370c
commit 633cc0214d
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 19 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package de.mm20.launcher2.activity
import android.app.Activity
import android.os.Bundle
import android.util.Log
import de.mm20.launcher2.searchable.SearchableRepository
import de.mm20.launcher2.search.data.AppShortcut
import de.mm20.launcher2.services.favorites.FavoritesService
@ -16,6 +17,8 @@ class AddItemActivity : Activity() {
val shortcut = AppShortcut.fromPinRequestIntent(this, intent)
if (shortcut != null) {
favoritesService.pinItem(shortcut)
} else {
Log.w("MM20", "Shortcut could not be added")
}
finish()
}

View File

@ -9,6 +9,7 @@ import android.content.pm.ShortcutInfo
import android.graphics.drawable.AdaptiveIconDrawable
import android.os.Bundle
import android.os.Process
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import de.mm20.launcher2.appshortcuts.R
@ -143,8 +144,19 @@ data class LauncherShortcut(
val launcherApps =
context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val pinRequest = launcherApps.getPinItemRequest(data)
val shortcutInfo = pinRequest?.shortcutInfo ?: return null
if (!pinRequest.accept()) return null
if (pinRequest == null) {
Log.w("MM20", "Pin request could not be retrieved from intent")
return null
}
val shortcutInfo = pinRequest.shortcutInfo
if (shortcutInfo == null) {
Log.w("MM20", "Pin request is missing shortcut info")
return null
}
if (!pinRequest.accept()) {
Log.w("MM20", "Pin request could not be accepted")
return null
}
return LauncherShortcut(
context,
shortcutInfo,

View File

@ -5,6 +5,7 @@ import android.content.Intent
import android.content.Intent.ShortcutIconResource
import android.graphics.drawable.AdaptiveIconDrawable
import android.os.Bundle
import android.util.Log
import de.mm20.launcher2.icons.*
import de.mm20.launcher2.ktx.getDrawableOrNull
import de.mm20.launcher2.ktx.isAtLeastApiLevel
@ -85,6 +86,7 @@ data class LegacyShortcut(
data.extras?.getParcelable(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)
if (intent == null || name == null) {
Log.w("MM20", "Pin request intent is missing required extras: intent=$intent, name=$name")
return null
}