android / android-test

An extensive framework for testing Android apps
https://android.github.io/android-test
Apache License 2.0
1.16k stars 314 forks source link

Orchestrator fails to run tests on Android Automotive / Polestar #555

Open DonJogi opened 4 years ago

DonJogi commented 4 years ago

Description

The Androidx Test Orchestrator fails to run on an Automotive Emulator because it fails to grant the requested runtime permissions (permission.WRITE_EXTERNAL_STORAGE, permission.READ_EXTERNAL_STORAGE).

Steps to Reproduce

Expected Results

The tests should run

Actual Results

The test orchestrator crashes and no tests are executed. Logcat:

2020-03-03 21:43:53.623 18314-18330/? E/AndroidTestOrchestrator: Fatal exception when setting up.
    java.lang.IllegalStateException: Permission requested but not granted!
        at androidx.test.orchestrator.AndroidTestOrchestrator.grantRuntimePermissions(AndroidTestOrchestrator.java:231)
        at androidx.test.orchestrator.AndroidTestOrchestrator.onStart(AndroidTestOrchestrator.java:201)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
2020-03-03 21:43:53.630 18314-18330/? E/AndroidRuntime: FATAL EXCEPTION: Instr: androidx.test.orchestrator.AndroidTestOrchestrator
    Process: androidx.test.orchestrator, PID: 18314
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Instrumentation.getContext()' on a null object reference
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.createOutputResultStream(OrchestrationXmlTestRunListener.java:253)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.generateDocument(OrchestrationXmlTestRunListener.java:191)
        at androidx.test.orchestrator.listeners.OrchestrationXmlTestRunListener.orchestrationRunFinished(OrchestrationXmlTestRunListener.java:178)
        at androidx.test.orchestrator.AndroidTestOrchestrator.finish(AndroidTestOrchestrator.java:443)
        at androidx.test.orchestrator.AndroidTestOrchestrator.onStart(AndroidTestOrchestrator.java:210)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)

AndroidX Test and Android OS Versions

Android Automotive 9 / Polestar Emulator Android Test Orchestrator 1.2.0 (also tested without success on 1.3.0-alpha04)

Link to a public git repo demonstrating the problem:

Not dependent on the app code, but on the Automotive emulator.

Debug

I think this crash occurs because the Automotive emulator has two users set up, whereas a standard Android emulator only has one user. On Automotive, adb shell pm list users prints:

Users:
    UserInfo{0:Owner:13} running
    UserInfo{10:Owner:12} running

On standard Android, adb shell pm list users prints:

Users:
    UserInfo{0:Owner:13} running

I suspect that when the AndroidTestOrchestrator tries to grant the needed runtime permissions, these get assigned to the wrong user (ID 0), while it should be the user with ID 10.

anantshah93 commented 4 years ago

Same error anyone found the solution?

Lilefisk commented 4 years ago

There is workaround: Grant manually permissions to Orchestrator for user 10. adb shell pm grant android.permission.WRITE_EXTERNAL_STORAGE --user 10 Androidx.test.orchestrator adb shell pm grant android.permission.READ_EXTERNAL_STORAGE --user 10 Androidx.test.orchestrator