Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/GosCompatTests/GosCompatCheckApp/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.grapheneos.goscompat.checks">

<queries>
<package android:name="app.grapheneos.goscompat.securespawn" />
</queries>

<application
android:debuggable="true"
android:label="GOS Compat Checks"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package app.grapheneos.goscompat.checks

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.graphics.Color as AndroidColor
import android.os.Bundle
import android.os.DeadObjectException
import android.view.Window
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -89,6 +92,9 @@ class GosCompatCheckActivity : ComponentActivity() {
reflectiveMapsScanRunning,
)
},
onRunSecureSpawn = {
startSecureSpawn()
},
dmaBufReleaseContent = {
DmaBufReleasePanel(this@GosCompatCheckActivity)
},
Expand All @@ -98,6 +104,17 @@ class GosCompatCheckActivity : ComponentActivity() {
}
}

private fun startSecureSpawn() {
try {
startActivity(Intent().setClassName(
GosCompatContract.SecureSpawn.PACKAGE_NAME,
GosCompatContract.SecureSpawn.ACTIVITY_CLASS,
))
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, "Secure spawn app is not installed", Toast.LENGTH_SHORT).show()
}
}

private fun startMapsScan(
method: String,
result: MutableState<MapsScanResult?>,
Expand Down Expand Up @@ -152,6 +169,7 @@ private fun GosCompatCheckScreen(
reflectiveMapsScanRunning: Boolean,
onRunDirectMapsScan: () -> Unit,
onRunReflectiveMapsScan: () -> Unit,
onRunSecureSpawn: () -> Unit,
dmaBufReleaseContent: @Composable () -> Unit,
) {
Column(
Expand All @@ -168,6 +186,27 @@ private fun GosCompatCheckScreen(
fontWeight = FontWeight.SemiBold,
)

Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(8.dp),
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(14.dp),
) {
Text(
text = "Secure app spawning",
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.SemiBold,
)
Button(onClick = onRunSecureSpawn) {
Text("Open check")
}
}
}

Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(8.dp),
Expand Down
21 changes: 21 additions & 0 deletions tests/GosCompatTests/GosCompatSecureSpawnTests/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
java_test_host {
name: "GosCompatSecureSpawnTests",
srcs: [
"src/**/*.java",
":GosPackageStateFlags",
],
libs: [
"tradefed",
"compatibility-tradefed",
"compatibility-host-util",
],
static_libs: [
"framework-annotations-lib",
],
test_suites: [
"general-tests",
],
device_common_data: [
":GosCompatSecureSpawnApp",
],
}
15 changes: 15 additions & 0 deletions tests/GosCompatTests/GosCompatSecureSpawnTests/AndroidTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration description="Runs GosCompatSecureSpawnTests">
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="install-arg" value="-r" />
<option name="install-arg" value="-d" />
<option name="install-arg" value="-g" />
<option name="install-arg" value="-t" />
<option name="test-file-name" value="GosCompatSecureSpawnApp.apk" />
</target_preparer>

<test class="com.android.compatibility.common.tradefed.testtype.JarHostTest">
<option name="jar" value="GosCompatSecureSpawnTests.jar" />
</test>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cc_library_shared {
name: "libgoscompat_secure_spawn_jni",
srcs: ["jni/secure_spawn_jni.c"],
sdk_version: "current",
header_libs: ["jni_headers"],
cflags: [
"-Wall",
"-Wextra",
"-Werror",
],
stl: "none",
}

android_test_helper_app {
name: "GosCompatSecureSpawnApp",
srcs: [
"src/**/*.java",
"src/**/*.kt",
],
manifest: "AndroidManifest.xml",
jni_libs: [
"libgoscompat_secure_spawn_jni",
],
use_embedded_native_libs: true,
compile_multilib: "both",
libs: [
"android.test.runner.stubs",
],
static_libs: [
"androidx.activity_activity",
"androidx.activity_activity-compose",
"androidx.core_core",
"androidx.compose.foundation_foundation",
"androidx.compose.foundation_foundation-layout",
"androidx.compose.material3_material3",
"androidx.compose.runtime_runtime",
"androidx.compose.ui_ui",
"androidx.compose.ui_ui-graphics",
"androidx.compose.ui_ui-text",
"androidx.compose.ui_ui-unit",
"androidx.test.ext.junit",
"androidx.test.runner",
"truth",
],
kotlincflags: [
"-Xjvm-default=all",
"-P plugin:androidx.compose.compiler.plugins.kotlin:sourceInformation=true",
],
sdk_version: "current",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.grapheneos.goscompat.securespawn">

<application
android:debuggable="false"
android:label="GOS Secure Spawn Checks"
android:theme="@android:style/Theme.DeviceDefault.DayNight">
<uses-library android:name="android.test.runner" />

<activity
android:name=".SecureSpawnActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="app.grapheneos.goscompat.securespawn" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <jni.h>
#include <sys/system_properties.h>

JNIEXPORT jstring JNICALL
Java_app_grapheneos_goscompat_securespawn_SecureSpawnCheck_nativeSystemProperty(
JNIEnv* env, jclass clazz, jstring key) {
(void) clazz;

const char* key_chars = (*env)->GetStringUTFChars(env, key, NULL);
if (key_chars == NULL) {
return NULL;
}

char value[PROP_VALUE_MAX] = "";
__system_property_get(key_chars, value);
(*env)->ReleaseStringUTFChars(env, key, key_chars);
return (*env)->NewStringUTF(env, value);
}
Loading