mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 16:07:39 +00:00
Added permission check for installing/downloading modules
This commit is contained in:
parent
faf077b494
commit
88d917b662
@ -1,8 +1,10 @@
|
|||||||
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,15 +12,12 @@ 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 {
|
|
||||||
onSuccess {
|
|
||||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||||
intent.type = "application/zip"
|
intent.type = "application/zip"
|
||||||
activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
|
activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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
|
|||||||
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(
|
|||||||
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 @@
|
|||||||
<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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user