Skip to content

Commit 794adeb

Browse files
committed
use run-as
1 parent b743721 commit 794adeb

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

.github/workflows/llm-android.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ jobs:
129129
if [ "$MODEL_PRESET" = "custom" ]; then GRADLE_ARGS="-PmodelPreset=$MODEL_PRESET -PcustomPteUrl=$CUSTOM_PTE_URL -PcustomTokenizerUrl=$CUSTOM_TOKENIZER_URL"; else GRADLE_ARGS="-PmodelPreset=$MODEL_PRESET"; fi
130130
./gradlew connectedCheck $GRADLE_ARGS; TEST_EXIT_CODE=$?
131131
echo "=== Checking for response file ==="
132-
adb shell ls -la /sdcard/Android/data/com.example.executorchllamademo/files/ || echo "Directory not found"
133-
adb shell cat /sdcard/Android/data/com.example.executorchllamademo/files/response.txt || echo "File not found or empty"
134-
adb pull /sdcard/Android/data/com.example.executorchllamademo/files/response.txt /tmp/response.txt || true
132+
adb shell run-as com.example.executorchllamademo ls -la /data/data/com.example.executorchllamademo/files/ || echo "Directory not found"
133+
adb shell run-as com.example.executorchllamademo cat /data/data/com.example.executorchllamademo/files/response.txt || echo "File not found or empty"
134+
adb shell run-as com.example.executorchllamademo cat /data/data/com.example.executorchllamademo/files/response.txt > /tmp/response.txt || true
135135
kill $LOGCAT_PID || true
136136
exit $TEST_EXIT_CODE
137137

llm/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/UIWorkflowTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,19 @@ private boolean waitForModelLoaded(ActivityScenario<MainActivity> scenario, long
248248

249249
/**
250250
* Writes the model response to a file that can be pulled from the device.
251-
* Writes to app's external files directory which is accessible via adb.
251+
* Writes to app's internal files directory, accessible via adb run-as.
252252
* Appends to the file to support multiple test cases.
253253
*/
254254
private void writeResponseToFile(String response) {
255255
try {
256256
Context context = ApplicationProvider.getApplicationContext();
257-
// Use external files dir which is accessible without root
258-
File externalDir = context.getExternalFilesDir(null);
259-
if (externalDir != null) {
260-
File outputFile = new File(externalDir, "response.txt");
261-
// Append mode (true) to support multiple test cases
262-
try (FileWriter writer = new FileWriter(outputFile, true)) {
263-
writer.write(response);
264-
}
265-
android.util.Log.i("UIWorkflowTest", "Response written to: " + outputFile.getAbsolutePath());
257+
// Use internal files dir - accessible via "adb shell run-as <package>"
258+
File outputFile = new File(context.getFilesDir(), "response.txt");
259+
// Append mode (true) to support multiple test cases
260+
try (FileWriter writer = new FileWriter(outputFile, true)) {
261+
writer.write(response);
266262
}
263+
android.util.Log.i("UIWorkflowTest", "Response written to: " + outputFile.getAbsolutePath());
267264
} catch (IOException e) {
268265
android.util.Log.e("UIWorkflowTest", "Failed to write response file", e);
269266
}

0 commit comments

Comments
 (0)