android / android/android-test

Orchestrator fails to run tests on Android Automotive / Polestar

Open
#555 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
11h 29m
Merged PRs (30d)
2

Description

### 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
* Install the Polestar Automotive Emulator: https://developer.polestar.com/
* Create a new project with the wizard: File -> New -> New Project
* Add the test orchestrator dependencies to the project's build.gradle:
```
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestUtil 'androidx.test:orchestrator:1.2.0'
```
* Start the Automotive emulator
* Run `./gradlew connectedAndroidTest`

### 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.

Contributor guide

Open the contributing guide

Research direction

Start with AndroidTestOrchestrator.grantRuntimePermissions() and onStart(), then inspect the Automotive emulator's multiple-user behavior using the provided adb shell pm list users output. Reproduce with connectedAndroidTest and verify that the orchestrator grants permissions for the active user and completes the test run without the reported crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.