mirror of
https://invent.kde.org/network/kdeconnect-android.git
synced 2025-10-06 00:23:01 +02:00
Add way to send an error when trying to use a plugin that lacks permissions
Plugins can opt-in to be loaded even when missing permissions, so they can react if the user tries to remotely use the plugin for example to show an error. This is used in the SFTP plugin to display a message when trying to use it without having granted filesystem permissions. I also renamed the name of the plugin shown when missing permissions, from "filesystem expose" to something hopefully more understandable.
This commit is contained in:
@@ -24,7 +24,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
|
||||
<string name="pref_plugin_battery_desc">Periodically report battery status</string>
|
||||
<string name="pref_plugin_connectivity_report">Connectivity report</string>
|
||||
<string name="pref_plugin_connectivity_report_desc">Report network signal strength and status</string>
|
||||
<string name="pref_plugin_sftp">Filesystem expose</string>
|
||||
<string name="pref_plugin_sftp">Filesystem access</string>
|
||||
<string name="pref_plugin_sftp_desc">Allows to browse this device\'s filesystem remotely</string>
|
||||
<string name="pref_plugin_clipboard">Clipboard sync</string>
|
||||
<string name="pref_plugin_clipboard_desc">Share the clipboard content</string>
|
||||
@@ -312,6 +312,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
|
||||
<string name="sftp_no_storage_locations_configured">No storage locations configured</string>
|
||||
<string name="sftp_saf_permission_explanation">To access files remotely you have to configure storage locations</string>
|
||||
<string name="sftp_manage_storage_permission_explanation">To allow remote access to files on this device you need to allow KDE Connect to manage the storage.</string>
|
||||
<string name="sftp_missing_permission_error">Permissions missing: filesystem access</string>
|
||||
<string name="no_players_connected">No players found</string>
|
||||
<string name="send_files">Send files</string>
|
||||
|
||||
|
@@ -558,9 +558,13 @@ class Device : PacketReceiver {
|
||||
|
||||
if (!plugin.checkRequiredPermissions()) {
|
||||
Log.d("KDE/addPlugin", "No permission $pluginKey")
|
||||
loadedPlugins.remove(pluginKey)
|
||||
pluginsWithoutPermissions[pluginKey] = plugin
|
||||
return false
|
||||
if (plugin.loadPluginWhenRequiredPermissionsMissing()) {
|
||||
loadedPlugins[pluginKey] = plugin
|
||||
} else {
|
||||
loadedPlugins.remove(pluginKey)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
Log.d("KDE/addPlugin", "Permissions OK $pluginKey")
|
||||
loadedPlugins[pluginKey] = plugin
|
||||
|
@@ -272,6 +272,8 @@ abstract class Plugin {
|
||||
return arePermissionsGranted(optionalPermissions)
|
||||
}
|
||||
|
||||
open fun loadPluginWhenRequiredPermissionsMissing(): Boolean = false
|
||||
|
||||
open fun onDeviceUnpaired(context: Context, deviceId: String) {}
|
||||
|
||||
open val minSdk: Int = Build.VERSION_CODES.BASE
|
||||
|
@@ -74,9 +74,19 @@ class SftpPlugin : Plugin(), OnSharedPreferenceChangeListener {
|
||||
preferences?.unregisterOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun loadPluginWhenRequiredPermissionsMissing() = true
|
||||
|
||||
override fun onPacketReceived(np: NetworkPacket): Boolean {
|
||||
if (!np.getBoolean("startBrowsing")) return false
|
||||
|
||||
if (!checkRequiredPermissions()) {
|
||||
val noPermissionsPacket = NetworkPacket(PACKET_TYPE_SFTP).apply {
|
||||
this["errorMessage"] = context.getString(R.string.sftp_missing_permission_error)
|
||||
}
|
||||
device.sendPacket(noPermissionsPacket)
|
||||
return true
|
||||
}
|
||||
|
||||
if (!server.isInitialized || server.isClosed) {
|
||||
try {
|
||||
server.initialize(context, device)
|
||||
|
Reference in New Issue
Block a user