Commit 88d917b6 authored by Viktor De Pasquale's avatar Viktor De Pasquale Committed by John Wu

Added permission check for installing/downloading modules

parent faf077b4
package com.topjohnwu.magisk.model.events package com.topjohnwu.magisk.model.events
import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.annotation.RequiresPermission
import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.base.BaseActivity import com.topjohnwu.magisk.core.base.BaseActivity
import com.topjohnwu.magisk.core.intent import com.topjohnwu.magisk.core.intent
...@@ -10,14 +12,11 @@ import com.topjohnwu.magisk.legacy.flash.FlashActivity ...@@ -10,14 +12,11 @@ import com.topjohnwu.magisk.legacy.flash.FlashActivity
class InstallExternalModuleEvent : ViewEvent(), ActivityExecutor { class InstallExternalModuleEvent : ViewEvent(), ActivityExecutor {
@RequiresPermission(allOf = [Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE])
override fun invoke(activity: BaseActivity) { override fun invoke(activity: BaseActivity) {
activity.withExternalRW { val intent = Intent(Intent.ACTION_GET_CONTENT)
onSuccess { intent.type = "application/zip"
val intent = Intent(Intent.ACTION_GET_CONTENT) activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
intent.type = "application/zip"
activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
}
}
} }
companion object { companion object {
......
package com.topjohnwu.magisk.ui.module package com.topjohnwu.magisk.ui.module
import android.Manifest
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import androidx.databinding.Bindable import androidx.databinding.Bindable
import androidx.databinding.ObservableArrayList import androidx.databinding.ObservableArrayList
...@@ -20,6 +21,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject ...@@ -20,6 +21,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import com.topjohnwu.magisk.model.entity.recycler.* import com.topjohnwu.magisk.model.entity.recycler.*
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent
import com.topjohnwu.magisk.model.events.OpenChangelogEvent import com.topjohnwu.magisk.model.events.OpenChangelogEvent
import com.topjohnwu.magisk.model.events.SnackbarEvent
import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog
import com.topjohnwu.magisk.ui.base.* import com.topjohnwu.magisk.ui.base.*
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
...@@ -330,11 +332,27 @@ class ModuleViewModel( ...@@ -330,11 +332,27 @@ class ModuleViewModel(
else -> Unit else -> Unit
} }
fun downloadPressed(item: RepoItem) = ModuleInstallDialog(item.item).publish() fun downloadPressed(item: RepoItem) = withPermissions(
fun installPressed() = InstallExternalModuleEvent().publish() Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
).any { it }.subscribeK(onError = { permissionDenied() }) {
ModuleInstallDialog(item.item).publish()
}.add()
fun installPressed() = withPermissions(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
).any { it }.subscribeK(onError = { permissionDenied() }) {
InstallExternalModuleEvent().publish()
}.add()
fun infoPressed(item: RepoItem) = OpenChangelogEvent(item.item).publish() fun infoPressed(item: RepoItem) = OpenChangelogEvent(item.item).publish()
fun infoPressed(item: ModuleItem) { fun infoPressed(item: ModuleItem) {
OpenChangelogEvent(item.repo ?: return).publish() OpenChangelogEvent(item.repo ?: return).publish()
} }
private fun permissionDenied() {
SnackbarEvent(R.string.module_permission_declined).publish()
}
} }
...@@ -136,6 +136,7 @@ ...@@ -136,6 +136,7 @@
<string name="update_available">Update Available</string> <string name="update_available">Update Available</string>
<string name="module_installed">@string/home_installed_version</string> <string name="module_installed">@string/home_installed_version</string>
<string name="sorting_order">Sorting Order</string> <string name="sorting_order">Sorting Order</string>
<string name="module_permission_declined">Grant storage permission to enable this functionality</string>
<!--Settings --> <!--Settings -->
<string name="settings_dark_mode_title">Theme Mode</string> <string name="settings_dark_mode_title">Theme Mode</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment