Skip to content

Commit 6ac2f11

Browse files
committed
Merge pull request #72 from hotchemi/fix-45
Add support for PERMISSION_DENIED_APP_OP.
2 parents b6c92f4 + f4a4ba8 commit 6ac2f11

File tree

2 files changed

+116
-3
lines changed

2 files changed

+116
-3
lines changed

processor/src/main/kotlin/permissions/dispatcher/processor/impl/BaseProcessorUnit.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import javax.lang.model.element.Modifier
2020
public abstract class BaseProcessorUnit : ProcessorUnit {
2121

2222
protected val PERMISSION_UTILS = ClassName.get("permissions.dispatcher", "PermissionUtils")
23-
2423
private val MANIFEST_WRITE_SETTING = "android.permission.WRITE_SETTINGS"
2524
private val MANIFEST_SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW"
2625
private val ADD_WITH_CHECK_BODY_MAP = hashMapOf(MANIFEST_SYSTEM_ALERT_WINDOW to SystemAlertWindowHelper(), MANIFEST_WRITE_SETTING to WriteSettingsHelper())
@@ -268,6 +267,18 @@ public abstract class BaseProcessorUnit : ProcessorUnit {
268267
}
269268

270269
private fun addResultCaseBody(builder: MethodSpec.Builder, needsMethod: ExecutableElement, rpe: RuntimePermissionsElement, targetParam: String, grantResultsParam: String) {
270+
271+
// just workaround, see https://github.com/hotchemi/PermissionsDispatcher/issues/45
272+
val onDenied: ExecutableElement? = rpe.findOnDeniedForNeeds(needsMethod)
273+
val hasDenied = onDenied != null
274+
if (hasDenied) {
275+
builder.beginControlFlow("if (!\$T.hasSelfPermissions(\$N, \$N))",
276+
PERMISSION_UTILS, getActivityName(targetParam), permissionFieldName(needsMethod))
277+
builder.addStatement("\$N.\$N()", targetParam, onDenied!!.simpleString())
278+
builder.addStatement("return")
279+
builder.endControlFlow()
280+
}
281+
271282
val needsPermissionParameter = needsMethod.getAnnotation(NeedsPermission::class.java).value[0]
272283

273284
// Add the conditional for "permission verified"
@@ -285,8 +296,6 @@ public abstract class BaseProcessorUnit : ProcessorUnit {
285296
}
286297

287298
// Add the conditional for "permission denied" and/or "never ask again", if present
288-
val onDenied: ExecutableElement? = rpe.findOnDeniedForNeeds(needsMethod)
289-
val hasDenied = onDenied != null
290299
val onNeverAsk: ExecutableElement? = rpe.findOnNeverAskForNeeds(needsMethod)
291300
val hasNeverAsk = onNeverAsk != null
292301

0 commit comments

Comments
 (0)