34 lines
2.0 KiB
Kotlin
34 lines
2.0 KiB
Kotlin
import com.gorios.lanvoice.expression.CameraPermissionGate
|
|
import com.gorios.lanvoice.expression.CameraPermissionGate.Action
|
|
|
|
fun main() {
|
|
fun gate() = CameraPermissionGate().apply { check(onForeground() == Action.NONE) }
|
|
check(CameraPermissionGate().click(false, false) == Action.NONE)
|
|
for (resultBeforeForeground in listOf(true, false)) {
|
|
val g=gate();check(g.click(false,false)==Action.REQUEST_PERMISSION)
|
|
g.onBackground();check(g.permissionPending)
|
|
if (resultBeforeForeground) {
|
|
check(g.permissionResult(true)==Action.NONE)
|
|
check(g.onForeground()==Action.START)
|
|
} else {
|
|
check(g.onForeground()==Action.NONE)
|
|
check(g.permissionResult(true)==Action.START)
|
|
}
|
|
check(g.onForeground()==Action.NONE) // one-shot continuation
|
|
g.onBackground();check(g.onForeground()==Action.NONE) // no auto-resume of active camera
|
|
}
|
|
val denied=gate();check(denied.click(false,false)==Action.REQUEST_PERMISSION)
|
|
denied.onBackground();check(denied.permissionResult(false)==Action.DENIED)
|
|
check(denied.onForeground()==Action.NONE)
|
|
val cancel=gate();check(cancel.click(false,false)==Action.REQUEST_PERMISSION)
|
|
check(cancel.click(false,false)==Action.STOP);check(cancel.permissionResult(true)==Action.NONE)
|
|
val released=gate();released.click(false,false);released.release()
|
|
check(released.permissionResult(true)==Action.NONE);check(released.onForeground()==Action.NONE)
|
|
val hungUp=gate();hungUp.click(false,false);hungUp.cancel()
|
|
check(hungUp.permissionResult(true)==Action.NONE);check(hungUp.onForeground()==Action.NONE)
|
|
val granted=gate();check(granted.click(false,true)==Action.START)
|
|
check(granted.click(true,true)==Action.STOP)
|
|
check(granted.permissionResult(true)==Action.NONE) // duplicate/stale result
|
|
println("PASS: camera authorization survives onStop in both callback orders; foreground-only, denial/cancel/release, default off, no automatic resume")
|
|
}
|