Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The launcher name on Android 11 is returned as com.android.settings instead of the actual launcher package name #348

Open
pkarmaka opened this issue Nov 25, 2020 · 6 comments

Comments

@pkarmaka
Copy link

pkarmaka commented Nov 25, 2020

getLauncherPackagename() returns com.android.settings. So mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); doesn't really wait for the launcher package.
I believe this is due to the package visibility changes on Android 11.

Our test setup consisted of this check before starting with the tests:
String currentPackageName = device.getCurrentPackageName(); if (currentPackageName != null) { assertEquals(packageName, currentPackageName); }

This failed as currentPackageName returned as com.google.android.apps.nexuslauncher and getLauncherPackagename() returned com.android.settings.

@adil-hussain-84
Copy link

I created an issue in IssueTracker about this here but sadly the Google engineer who picked it up marked it as "Won't fix (Intended behaviour)" 😔 In hindsight, now that I know a bit more about the issue, I probably should have created it as an issue in the uiautomator library.

@brettchabot
Copy link
Collaborator

I think this behavior is WAI. At least on Android 11 com.android.settings does define a launcher activity as well. During the boot process once the phone is unlocked, this settings FallbackHome disables itself, allowing the com.google.android.apps.nexuslauncher activity to take over.

@adil-hussain-84
Copy link

adil-hussain-84 commented Oct 28, 2021

The device continues to report com.android.settings as the launcher package name even after the boot process has completed and the phone is unlocked. The only way I've found to get the UiDevice.getLauncherPackageName() method to return the correct launcher package name, as further described here, is to add the following item in my app's AndroidManifest.xml file:

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME" />
    </intent>
</queries>

However, as I'm sure most developers would agree, it's not a great solution to have to add an entry in the app's manifest file which is only for testing.

I'll raise an issue in the android-test repo this weekend proposing that the implementation of the UiDevice.getLauncherPackageName() method should be revised to work on Android 11+ devices or that its supporting documentation comment should be revised to call out its limitations.

@adil-hussain-84
Copy link

I've created an issue in the android-test GitHub repo here.

@pkarmaka
Copy link
Author

pkarmaka commented Nov 1, 2021

Thank you @adil-hussain-84 for creating the issue.

Going back to your previous point, you could also create a test specific manifest file and add in the modifications there.

@adil-hussain-84
Copy link

@pkarmaka I wish it worked that way. Sadly, entries in the androidTest/AndroidManifest.xml file are not picked up by the application under test. You can verify this by moving the debug/AndroidManifest.xml file in the UiAutomatorExperiments/app2 application module so it sits at androidTest/AndroidManifest.xml. You'll see that the test methods in the UiAutomatorTest test class start to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants