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
import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.annotation.RequiresPermission
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.base.BaseActivity
import com.topjohnwu.magisk.core.intent
......@@ -10,14 +12,11 @@ import com.topjohnwu.magisk.legacy.flash.FlashActivity
class InstallExternalModuleEvent : ViewEvent(), ActivityExecutor {
@RequiresPermission(allOf = [Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE])
override fun invoke(activity: BaseActivity) {
activity.withExternalRW {
onSuccess {
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "application/zip"
activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
}
}
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "application/zip"
activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
}
companion object {
......
package com.topjohnwu.magisk.ui.module
import android.Manifest
import androidx.annotation.WorkerThread
import androidx.databinding.Bindable
import androidx.databinding.ObservableArrayList
......@@ -20,6 +21,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import com.topjohnwu.magisk.model.entity.recycler.*
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent
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.ui.base.*
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
......@@ -330,11 +332,27 @@ class ModuleViewModel(
else -> Unit
}
fun downloadPressed(item: RepoItem) = ModuleInstallDialog(item.item).publish()
fun installPressed() = InstallExternalModuleEvent().publish()
fun downloadPressed(item: RepoItem) = withPermissions(
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: ModuleItem) {
OpenChangelogEvent(item.repo ?: return).publish()
}
private fun permissionDenied() {
SnackbarEvent(R.string.module_permission_declined).publish()
}
}
......@@ -136,6 +136,7 @@
<string name="update_available">Update Available</string>
<string name="module_installed">@string/home_installed_version</string>
<string name="sorting_order">Sorting Order</string>
<string name="module_permission_declined">Grant storage permission to enable this functionality</string>
<!--Settings -->
<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