From 11d1c414cec871f02645c9ebb5dba3b9c6a84468 Mon Sep 17 00:00:00 2001 From: Ashish Yadav <48384865+criticalAY@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:54:45 +0530 Subject: [PATCH] revert: Disable widget if no storage access * On (<= API 30 [Android 11]), widgets cannot be enabled in code if defined as enabled=false in the manifest (Android bug #15745). --- AnkiDroid/src/main/AndroidManifest.xml | 3 +- .../main/java/com/ichi2/anki/IntentHandler.kt | 30 ------------------- .../ichi2/anki/NavigationDrawerActivity.kt | 2 ++ .../permissions/PermissionsActivity.kt | 7 ----- 4 files changed, 3 insertions(+), 39 deletions(-) diff --git a/AnkiDroid/src/main/AndroidManifest.xml b/AnkiDroid/src/main/AndroidManifest.xml index b58750ca0921..e65573492be2 100644 --- a/AnkiDroid/src/main/AndroidManifest.xml +++ b/AnkiDroid/src/main/AndroidManifest.xml @@ -496,11 +496,11 @@ android:foregroundServiceType="dataSync" /> + @@ -517,7 +517,6 @@ diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt b/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt index 64e55de71ac0..fb39c3f31c83 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt @@ -17,10 +17,8 @@ package com.ichi2.anki import android.app.Activity -import android.content.ComponentName import android.content.Context import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.os.Message @@ -48,8 +46,6 @@ import com.ichi2.utils.Permissions import com.ichi2.utils.Permissions.hasStorageAccessPermission import com.ichi2.utils.copyToClipboard import com.ichi2.utils.trimToLength -import com.ichi2.widget.AddNoteWidget -import com.ichi2.widget.AnkiDroidWidgetSmall import timber.log.Timber import java.io.File import kotlin.math.max @@ -76,12 +72,6 @@ class IntentHandler : Activity() { // #6157 - We want to block actions that need permissions we don't have, but not the default case // as this requires nothing val runIfStoragePermissions = { runnable: () -> Unit -> performActionIfStorageAccessible(reloadIntent, action) { runnable() } } - - runIfStoragePermissions { - enableWidgets(this) - NavigationDrawerActivity.enablePostShortcut(this) - } - when (getLaunchType(intent)) { LaunchType.FILE_IMPORT -> runIfStoragePermissions { handleFileImport(fileIntent, reloadIntent, action) @@ -278,26 +268,6 @@ class IntentHandler : Activity() { return !isInvalidViewIntent(intent) } - /** - * Enables the widgets if the storage permission is granted. It enables both the small widget - * and the "Add Note" widget by setting their component enabled state to ENABLED. - **/ - fun enableWidgets(context: Context) { - val smallWidgetComponentName = ComponentName(context, AnkiDroidWidgetSmall::class.java) - context.packageManager.setComponentEnabledSetting( - smallWidgetComponentName, - PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP - ) - - val addNoteWidgetComponentName = ComponentName(context, AddNoteWidget::class.java) - context.packageManager.setComponentEnabledSetting( - addNoteWidgetComponentName, - PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP - ) - } - @VisibleForTesting @CheckResult fun getLaunchType(intent: Intent): LaunchType { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/NavigationDrawerActivity.kt b/AnkiDroid/src/main/java/com/ichi2/anki/NavigationDrawerActivity.kt index 0d046d36429d..f1039a3226a5 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/NavigationDrawerActivity.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/NavigationDrawerActivity.kt @@ -174,6 +174,8 @@ abstract class NavigationDrawerActivity : } drawerToggle.isDrawerSlideAnimationEnabled = animationEnabled() drawerLayout.addDrawerListener(drawerToggle) + + enablePostShortcut(this) } /** diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionsActivity.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionsActivity.kt index de022343fa00..225735865d06 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionsActivity.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/permissions/PermissionsActivity.kt @@ -24,8 +24,6 @@ import androidx.appcompat.widget.AppCompatButton import androidx.core.content.IntentCompat import androidx.fragment.app.commit import com.ichi2.anki.AnkiActivity -import com.ichi2.anki.IntentHandler -import com.ichi2.anki.NavigationDrawerActivity import com.ichi2.anki.PermissionSet import com.ichi2.anki.R import com.ichi2.annotations.NeedsTest @@ -70,11 +68,6 @@ class PermissionsActivity : AnkiActivity() { fun setContinueButtonEnabled(isEnabled: Boolean) { findViewById(R.id.continue_button).isEnabled = isEnabled - // in case it's not play build - if (isEnabled) { - IntentHandler.enableWidgets(this) - NavigationDrawerActivity.enablePostShortcut(this) - } } companion object {