diff --git a/vector/src/debug/AndroidManifest.xml b/vector/src/debug/AndroidManifest.xml
index b97384099f..8ffcec6bc1 100644
--- a/vector/src/debug/AndroidManifest.xml
+++ b/vector/src/debug/AndroidManifest.xml
@@ -4,6 +4,7 @@
+
diff --git a/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt
index aa871c5fb5..5d94f312b2 100644
--- a/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt
+++ b/vector/src/debug/java/im/vector/app/features/debug/DebugMenuActivity.kt
@@ -20,15 +20,20 @@ import android.app.Activity
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Intent
+import android.content.pm.PackageManager
import android.os.Build
+import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
+import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.platform.VectorBaseActivity
+import im.vector.app.core.utils.PERMISSIONS_ALL
import im.vector.app.core.utils.PERMISSIONS_FOR_TAKING_PHOTO
import im.vector.app.core.utils.checkPermissions
import im.vector.app.core.utils.registerForPermissionsResult
@@ -113,6 +118,9 @@ class DebugMenuActivity : VectorBaseActivity() {
}
views.debugTestCrash.setOnClickListener { testCrash() }
views.debugScanQrCode.setOnClickListener { scanQRCode() }
+ views.debugPermission.setOnClickListener {
+ startActivity(Intent(this, DebugPermissionActivity::class.java))
+ }
}
private fun renderQrCode(text: String) {
diff --git a/vector/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt b/vector/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt
new file mode 100644
index 0000000000..660e6c4312
--- /dev/null
+++ b/vector/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2019 New Vector Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package im.vector.app.features.debug
+
+import android.content.pm.PackageManager
+import android.os.Build
+import android.widget.Toast
+import androidx.core.app.ActivityCompat
+import androidx.core.content.ContextCompat
+import im.vector.app.R
+import im.vector.app.core.platform.VectorBaseActivity
+import im.vector.app.core.utils.PERMISSIONS_ALL
+import im.vector.app.core.utils.checkPermissions
+import im.vector.app.core.utils.registerForPermissionsResult
+import im.vector.app.databinding.ActivityDebugPermissionBinding
+import timber.log.Timber
+
+class DebugPermissionActivity : VectorBaseActivity() {
+
+ override fun getBinding() = ActivityDebugPermissionBinding.inflate(layoutInflater)
+
+ override fun initUiAndData() {
+ views.status.setOnClickListener { refresh() }
+
+ listOf(
+ views.audio,
+ views.camera,
+ views.write,
+ views.read,
+ views.contact
+ ).forEach { button ->
+ button.setOnClickListener {
+ checkPermissions(listOf(button.text.toString()), this, launcher, R.string.debug_rationale)
+ }
+ }
+ }
+
+ private val launcher = registerForPermissionsResult { allGranted ->
+ if (allGranted) {
+ Toast.makeText(this, "All granted", Toast.LENGTH_SHORT).show()
+ } else {
+ Toast.makeText(this, "Denied", Toast.LENGTH_SHORT).show()
+ }
+ }
+
+ override fun onResume() {
+ super.onResume()
+ refresh()
+ }
+
+ private fun refresh() {
+ views.status.text = getStatus()
+ }
+
+ private fun getStatus(): String {
+ return buildString {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Timber.v("## debugPermission() : log the permissions status used by the app")
+ PERMISSIONS_ALL.forEach { permission ->
+ append("[$permission] : ")
+ if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this@DebugPermissionActivity, permission)) {
+ append("PERMISSION_GRANTED")
+ } else {
+ append("PERMISSION_DENIED")
+ }
+ append(" show rational: ")
+ append(ActivityCompat.shouldShowRequestPermissionRationale(this@DebugPermissionActivity, permission))
+ append("\n")
+ }
+ } else {
+ append("Before M!")
+ }
+ append("\n")
+ append("(Click to refresh)")
+ }
+ }
+}
diff --git a/vector/src/debug/res/layout/activity_debug_menu.xml b/vector/src/debug/res/layout/activity_debug_menu.xml
index a83f61266a..976fe625e5 100644
--- a/vector/src/debug/res/layout/activity_debug_menu.xml
+++ b/vector/src/debug/res/layout/activity_debug_menu.xml
@@ -152,6 +152,12 @@
android:layout_height="200dp"
tools:src="@drawable/ic_qr_code_add" />
+
+
diff --git a/vector/src/debug/res/layout/activity_debug_permission.xml b/vector/src/debug/res/layout/activity_debug_permission.xml
new file mode 100644
index 0000000000..30c18b2538
--- /dev/null
+++ b/vector/src/debug/res/layout/activity_debug_permission.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vector/src/debug/res/values/strings.xml b/vector/src/debug/res/values/strings.xml
new file mode 100644
index 0000000000..a7b8e38634
--- /dev/null
+++ b/vector/src/debug/res/values/strings.xml
@@ -0,0 +1,4 @@
+
+
+ Rationale!
+
\ No newline at end of file
diff --git a/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt b/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt
index 879a53f0ae..54823c0750 100644
--- a/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt
+++ b/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt
@@ -18,7 +18,6 @@ package im.vector.app.core.utils
import android.Manifest
import android.app.Activity
-import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.widget.Toast
@@ -45,30 +44,13 @@ val PERMISSIONS_FOR_PICKING_CONTACT = listOf(Manifest.permission.READ_CONTACTS)
val PERMISSIONS_EMPTY = emptyList()
-/**
- * Log the used permissions statuses.
- */
-fun logPermissionStatuses(context: Context) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- val permissions = listOf(
- Manifest.permission.CAMERA,
- Manifest.permission.RECORD_AUDIO,
- Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.READ_EXTERNAL_STORAGE,
- Manifest.permission.READ_CONTACTS)
-
- Timber.v("## logPermissionStatuses() : log the permissions status used by the app")
-
- for (permission in permissions) {
- Timber.v(("Status of [$permission] : " +
- if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(context, permission)) {
- "PERMISSION_GRANTED"
- } else {
- "PERMISSION_DENIED"
- }))
- }
- }
-}
+// For debug
+val PERMISSIONS_ALL = listOf(
+ Manifest.permission.CAMERA,
+ Manifest.permission.RECORD_AUDIO,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_EXTERNAL_STORAGE,
+ Manifest.permission.READ_CONTACTS)
fun ComponentActivity.registerForPermissionsResult(allGranted: (Boolean) -> Unit): ActivityResultLauncher> {
return registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result ->