From fe1c396c90310ac21caf2df083c6c98788d3192d Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Mon, 25 Nov 2024 09:46:10 +0100 Subject: [PATCH] Check storage permissions before installing local addons Addons can be installed from locally downloadable XPI files with the correct MIME type. Installing those local files require android storage permissions. Those permissions were not checked when installing (and are not granted by default) so local installations used to silently fail in those cases. From now on a dialog is shown in case the permission is not granted. --- .../ui/views/library/DownloadsView.java | 43 +++++++++++-------- app/src/main/res/values/strings.xml | 3 ++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java b/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java index 2016cef247..883f1bc7c8 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java @@ -5,6 +5,7 @@ package com.igalia.wolvic.ui.views.library; +import android.Manifest; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.PointF; @@ -162,24 +163,32 @@ public void onClick(@NonNull View view, @NonNull Download item) { if (item.getMediaType().equals(UrlUtils.EXTENSION_MIME_TYPE)) { if (SettingsStore.getInstance(getContext()).isLocalAddonAllowed()) { - mWidgetManager.getFocusedWindow().showConfirmPrompt( - getContext().getString(R.string.download_addon_install), - item.getFilename(), - new String[]{ - getContext().getString(R.string.download_addon_install_cancel), - getContext().getString(R.string.download_addon_install_confirm_install), - }, - (index, isChecked) -> { - if (index == PromptDialogWidget.POSITIVE) { - LocalExtension.install( - SessionStore.get().getWebExtensionRuntime(), - UUID.randomUUID().toString(), - item.getOutputFileUriAsString(), - ((VRBrowserActivity) getContext()).getServicesProvider().getAddons() - ); + if (mWidgetManager.isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + mWidgetManager.getFocusedWindow().showConfirmPrompt( + getContext().getString(R.string.download_addon_install), + item.getFilename(), + new String[]{ + getContext().getString(R.string.download_addon_install_cancel), + getContext().getString(R.string.download_addon_install_confirm_install), + }, + (index, isChecked) -> { + if (index == PromptDialogWidget.POSITIVE) { + LocalExtension.install( + SessionStore.get().getWebExtensionRuntime(), + UUID.randomUUID().toString(), + item.getOutputFileUriAsString(), + ((VRBrowserActivity) getContext()).getServicesProvider().getAddons() + ); + } } - } - ); + ); + } else { + mWidgetManager.getFocusedWindow().showAlert( + getContext().getString(R.string.download_addon_install_blocked), + getContext().getString(R.string.download_addon_install_blocked_permissions_body), + null + ); + } } else { mWidgetManager.getFocusedWindow().showAlert( getContext().getString(R.string.download_addon_install_blocked), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7d2fbdfe1..f57b8e6d82 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2323,6 +2323,9 @@ the Select` button. When clicked it bookmarks all the previously selected tabs - Allow local addon installation in Developer Options to proceed. + + Allow storage permissions in Privacy Options to proceed. + Permission to write the external storage is required to download the environment.