Switching between 2 active activities(projection and phone) in a runtime (Android Auto)

Hi, everyone.
I have an application under the test which has android auto projection functionality. In order to start the projection I am running DHU emulator from google (https://developer.android.com/training/cars/testing).
The projection is inside the web view and I am able to switch to its context and interact with it. But the projection has a native wrapper which is unreachable for me inside the native context of the app. As far as I understand the projection is running in the separate activity (GeminiCarActivity) in the same time with the MainActivity of the app on the phone and both of them in the same native context. Is there a way to switch between 2 active activities. Driver.startactivity(packageName, activityName) is not an option, because the activity is launched from the moment the device is connected to the emulator. May be someone know a work around how to switch a focus from one activity to another in a runtime.
Thank you in advance.

You can check for the abd command and see if you can start activity at a point

public void your_functionName(){
ProcessBuilder pb = new ProcessBuilder(“adb”, “shell”, “am”,“start”,"-d",“YOUR_ACTIVITY_NAME”);
try {
Process pc = pb.start();
pc.waitFor();
}catch (IOException |InterruptedException e){
System.out.println(“Exception occured . Failed to open activity”);
}
}

Thanks for the quick reply.
But what the difference between your solution and driver.start() activity?
I tried your solution, but adb couldn’t find a proper intent.
But I don’t need to start anything, I need to change the focus of android driver somehow, because I am only able to interact with native part of the phone, but not the DHU emulator.

Hi Pomidorum,

Wondering if you ever figured out how to connect appium to the dhu? I was only able to connect to the android auto app on my phone.

Thanks,
Nick

I had no problem connecting to DHU at the first place, because our DHU has android OS so I have just created an additional driver session.

@Pomidorum

did you succeed? you can try enableMultiWindows capability to see more… → GitHub - appium/appium-uiautomator2-driver: Appium driver for Android UIAutomator2

To be honest no. I have also tried this capability, but it didn’t bring any result. But I have found the work around. I am using open CV for clicking on the screens which are out of reach in the context scope (lucky for me I have only couple of them). I am guessing that the screens which are not available for interaction is rendered on the android auto application side and should be found there. The application on the phone is only sending the data there. If my theory is correct that explains why I can’t find elements in the phone native context or headunit. As you can see on the screenshot all the elements are inside some kind of frame which can’t be expanded.

Yes. Screens may be closed for debug. We need ask developers to make them debuggable.

I totally understand that. But as far as I understand this is happening on the android auto side and in order to reach it I need to make android auto interface debuggable. To do so I need to make android auto component debuggable and complications are added starting from android 10+. Now android auto not a separated app, but a part of OS. And AA component is developed by Google and it’s up to them to make it debuggable.

Sad true…

1 Like