Skip to content

Commit

Permalink
Permission check fix for GitRepoActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
nevenz committed Mar 2, 2022
1 parent 990594e commit 4bbec3d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.orgzly.android.ui.repos

import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.ContextMenu
import android.view.MenuItem
Expand Down Expand Up @@ -199,7 +200,7 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
when (requestCode) {
ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE -> {
val granted = grantResults.zip(permissions)
.find { (_, perm) -> perm == READ_WRITE_EXTERNAL_STORAGE }
.find { (_, perm) -> perm == Manifest.permission.WRITE_EXTERNAL_STORAGE }
?.let { (grantResult, _) -> grantResult == PackageManager.PERMISSION_GRANTED }
if (granted == true) {
GitRepoActivity.start(this)
Expand All @@ -216,11 +217,14 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
}

R.id.repos_options_menu_item_new_git -> {
if (ContextCompat.checkSelfPermission(this, READ_WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
GitRepoActivity.start(this)
} else {
// TODO: Show explanation why possibly, if ActivityCompat.shouldShowRequestPermissionRationale() says so?
ActivityCompat.requestPermissions(this, arrayOf(READ_WRITE_EXTERNAL_STORAGE), ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE)
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE)
}
return
}
Expand Down Expand Up @@ -273,7 +277,6 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
companion object {
val TAG: String = ReposActivity::class.java.name

const val READ_WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE
const val ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE = 0
}
}

2 comments on commit 4bbec3d

@amberin
Copy link
Contributor

@amberin amberin commented on 4bbec3d Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nevenz On a new emulated Pixel 5, with either API 30 or 31, this leads to

  1. no permission prompt appears
  2. Orgzly is denied permission to access the file system (android.system.ErrnoException: open failed: EACCES (Permission denied))
  3. If I manually give the app access to files/media, I still get the same error.

I experienced this on the current master, and then I checked out this commit, to rule out that the issue was caused by some later commit, but there was no difference.

@amberin
Copy link
Contributor

@amberin amberin commented on 4bbec3d Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in #916 solves my problem. But please consider #941.

Please sign in to comment.