Complete Android adaptive and accessibility hardening (#105)
This commit is contained in:
1 parent
f4a6edbc68
commit
45d78aa5b3
33 files changed
+4596
-1376
No files matched your search
+19
-1
@@ -1,5 +1,6 @@
|
||||
package de.rfc1437.ironstorage.platform
|
||||
|
||||
import android.os.Build
|
||||
import android.security.keystore.KeyInfo
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.filters.SdkSuppress
|
||||
@@ -35,7 +36,7 @@ class AndroidKeystoreTest {
|
||||
) = KeystoreKeySpecification(
|
||||
alias,
|
||||
auth,
|
||||
true,
|
||||
Build.VERSION.SDK_INT >= 28,
|
||||
auth == KeystoreAuthorization.StrongBiometric,
|
||||
false
|
||||
)
|
||||
@@ -51,6 +52,23 @@ class AndroidKeystoreTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SdkSuppress(maxSdkVersion = 27)
|
||||
fun unsupportedUnlockedDeviceFlagDoesNotCreateAKey() {
|
||||
val os = AndroidKeystoreAdapter(context)
|
||||
val alias = alias()
|
||||
try {
|
||||
failure(KeystoreFailure.UnsupportedProtection) {
|
||||
os.createKey(
|
||||
KeystoreKeySpecification(alias, KeystoreAuthorization.None, true, false, false)
|
||||
)
|
||||
}
|
||||
assertFalse(os.aliases().contains(alias))
|
||||
} finally {
|
||||
os.deleteKey(alias)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun deviceUnlockedRoundtripReplaceDeleteAndTamper() {
|
||||
val os = AndroidKeystoreAdapter(context)
|
||||
assertFalse(os.deviceState().locked)
|
||||
|
||||
+35
@@ -2,16 +2,51 @@ package de.rfc1437.ironstorage.platform
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class AndroidQrCameraTest {
|
||||
@Test fun backgroundStopsAnalysisAndResumeRestartsPreview() {
|
||||
val frames = AtomicInteger()
|
||||
val received = AtomicReference(CountDownLatch(1))
|
||||
ActivityScenario.launch(KeystoreTestActivity::class.java).use { activity ->
|
||||
var camera: AndroidQrCamera? = null
|
||||
activity.onActivity { host ->
|
||||
camera = AndroidQrCamera(host, { frame ->
|
||||
try {
|
||||
frames.incrementAndGet()
|
||||
received.get().countDown()
|
||||
} finally {
|
||||
frame.pixels.fill(0)
|
||||
}
|
||||
}, { throw AssertionError("CameraX failed to bind") })
|
||||
host.setContentView(requireNotNull(camera).view)
|
||||
}
|
||||
try {
|
||||
assertTrue(received.get().await(15, TimeUnit.SECONDS))
|
||||
activity.moveToState(Lifecycle.State.CREATED)
|
||||
Thread.sleep(500)
|
||||
val stopped = frames.get()
|
||||
Thread.sleep(500)
|
||||
assertEquals("Background camera analysis must stop", stopped, frames.get())
|
||||
received.set(CountDownLatch(1))
|
||||
activity.moveToState(Lifecycle.State.RESUMED)
|
||||
assertTrue("Camera preview must resume", received.get().await(15, TimeUnit.SECONDS))
|
||||
} finally {
|
||||
activity.onActivity { camera?.close() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun livePreviewDeliversBoundedPlanesAndCanBeClosedAndReopened() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals(
|
||||
|
||||
Reference in new issue
Block a user