Closed Bug 1650891 Opened 4 years ago Closed 4 years ago

Change the location of the geckoview profile used by geckodriver in order to support root-less Android testing

Categories

(Testing :: geckodriver, enhancement, P1)

enhancement

Tracking

(firefox84 fixed)

RESOLVED FIXED
84 Branch
Tracking Status
firefox84 --- fixed

People

(Reporter: bc, Assigned: whimboo)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

In bug 1486004, we are updating mozdevice to support testing on unrooted android devices. When running on an unrooted device we create the test_root inside the app's directory as /data/data/<app>/test_root though if we are running on a rooted device, we create the test_root in /data/local/tmp/test_root.

geckodriver needs to change the location of the profile in AndroidHandler new() and how the profile is populated in AndroidHandler prepare(). It isn't strictly necessary that the storage permissions be granted in AndroidHandler prepare

If the device is rooted (either adbd is running as root or can be restarted as root, su -c id or su 0 id reports uid=0), then the profile should be pushed directly to /data/local/tmp/test_root/profile and then chmod -R run on it.

If the device is not rooted, then the profile should be pushed to an intermediate directory on /data/local/tmp, then run-as <app> cp -R intermediate /data/data/<app>/test_root/profile to copy the profile into the app's directory then chmod -R must be run on it and the intermediate directory must be deleted after the copy.

NOTE:
There are device specific issues which can possibly be worked around though it adds complexity to the logic to do so. In the future, I expect there to be more device specific limiations or work arounds that may be necessary if the device is to be supported.

  • Sony Xperia Z5 Compact (E5823) can hang if adb root is called and should the adb root call should be excluded if possible. See _check_adb_root() in the D79650 patch.
  • Samsung S10g SM-G973F will fail to execute run-as if the global setting art_verifier_verify_debuggable is set. mozdevice will raise an exception if it is set with the S10g. See run_as_package() in the D79650 patch.
  • su 0 id should be tested last only if the other approaches to detect if the device is rooted due to potential hangs if the device is rooted using Magisk.

The new logic is outlined in the phabricator revision D79650

It might be advisable to allow the original logic or this new logic to be selected via a command line argument.

I believe this covers the requirements. I will be available to test any new versions of geckodriver to make sure they work with the mozdevice.

Blocks: 1649094
Severity: -- → S3
Priority: -- → P3
Blocks: 1650872

FYI, I found out why Fenix only now started crashing with Browsertime/geckodriver on Android 10 devices.
They just upgraded to Android10 sdk July 9th:
https://github.com/mozilla-mobile/fenix/pull/11014/commits/02533afb73889cb76f26ce2a9ac12ffeed85cc85

It is definitely the Android 10 Scoped Storage causing the issue since reverting to legacy storage in the manifest allows the app to run.
i.e. <application ... android:requestLegacyExternalStorage="true" ...

Would either of you be able to make a patch with this change?

A custom build of geckodriver would unblock numerous folks working on Fenix performance using Browsertime/geckodriver on unrooted Android 10 devices.

Flags: needinfo?(hskupin)
Flags: needinfo?(bob)

I second this part: "It might be advisable to allow the original logic or this new logic to be selected via a command line argument."
Having this would give testers much more flexibility in the future.

I haven't done any work in Rust before. I could try but it might be a bit before I got something worth while. Whimboo is out until August 10 which seems like a long time for you to wait. I'll ask if this is something I can work on.

Flags: needinfo?(bob)

I can help with Rust and GeckoDriver; please reach out if you get stuck.

No longer blocks: 1650872

(In reply to Andrew Creskey [:acreskey] [he/him] from comment #1)

It is definitely the Android 10 Scoped Storage causing the issue since reverting to legacy storage in the manifest allows the app to run.
i.e. <application ... android:requestLegacyExternalStorage="true" ...

Is that something that needs to be done at build time? Or is it possible to set this flag later? If Geckodriver could set it, it might be a workaround for the time being. I know that it would only work until we upgraded to SDK11, which will ignore that flag.

Flags: needinfo?(hskupin) → needinfo?(acreskey)

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+2] from comment #6)

(In reply to Andrew Creskey [:acreskey] [he/him] from comment #1)

It is definitely the Android 10 Scoped Storage causing the issue since reverting to legacy storage in the manifest allows the app to run.
i.e. <application ... android:requestLegacyExternalStorage="true" ...

Is that something that needs to be done at build time? Or is it possible to set this flag later? If Geckodriver could set it, it might be a workaround for the time being. I know that it would only work until we upgraded to SDK11, which will ignore that flag.

Unfortunately this flag has to be included in the manifest at build time.

Flags: needinfo?(acreskey)
Assignee: nobody → bob
Status: NEW → ASSIGNED

Bob, please note that I already started with this bug earlier today but didn't assign myself yet due to some open questions. Does it mean that you want to work on it now?

Flags: needinfo?(bob)

No. Just that I hadn't heard anything from you and I wanted to discuss it via the phabricator request and which would only take the patch if I gave the bug number and which resulted in the bug being assigned. I've assigned it to you to take forward. If you would like to discuss it before you continue, I think that would be a good idea.

Assignee: bob → hskupin
Flags: needinfo?(bob)
Attachment #9170725 - Attachment is obsolete: true
Attachment #9170725 - Attachment is obsolete: false

feedback ni...

Flags: needinfo?(hskupin)

I will have a look at the review request soon.

Flags: needinfo?(hskupin)

Looks like I'll be taking this forward after all.

Assignee: hskupin → bob

The initial motivation for my patch was to illustrate the issues that needed to be handled. The current version of this patch does do that but not in an acceptable "Rust" way. I think it is a better use of resources if someone who actually knows rust continues this forward.

Assignee: bob → nobody
Status: ASSIGNED → NEW
Assignee: nobody → bob
Status: NEW → ASSIGNED
Attachment #9170725 - Attachment is obsolete: true

I guess Phabricator won't let me go unless I abandon the the patch.

Assignee: bob → nobody
Status: ASSIGNED → NEW

(In reply to Bob Clary [:bc] from comment #15)

I guess Phabricator won't let me go unless I abandon the the patch.

Thanks a lot for all your hard work on this bug Bob! It's really appreciated. So I will pick-up the remaining work for refactoring and would hope that you can test the final bits again before we get it landed.

Regarding the patch, lets reopen the revision but I will commandeer it.

Assignee: nobody → hskupin
Attachment #9170725 - Attachment is obsolete: false
Status: NEW → ASSIGNED
Priority: P3 → P1
Attachment #9170725 - Attachment description: Bug 1650891 - make profile customizable to support root-less android devices. → Bug 1650891 - [geckodriver] Make profile customizable to support root-less Android devices.
Attachment #9170725 - Attachment description: Bug 1650891 - [geckodriver] Make profile customizable to support root-less Android devices. → Bug 1650891 - make profile customizable to support root-less android devices.
Attachment #9170725 - Attachment description: Bug 1650891 - make profile customizable to support root-less android devices. → Bug 1650891 - [geckodriver] Make profile customizable to support root-less Android devices.

This is a proposed change on top of D87464 which means we don't expose the
unconnected state of AndroidHandler, allowing us to simplify the code.

Blocks: 1578424
Attachment #9182568 - Attachment is obsolete: true
Pushed by hskupin@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1a272b971b33
[geckodriver] Make profile customizable to support root-less Android devices. r=webdriver-reviewers,jgraham,bc,marionette-reviewers

Various problems here. So first the compiler fails to build geckodriver. I'm not sure if that is related to the unused AndroidStorage input or not. For me it runs all fine locally. So I just removed that import, and lets see if that works with the next try build.

Also the tests in android.rs cannot be run in CI. As such we would have to mark those as ignored, but still allow them to run locally with cargo test -- --ignored. The same for most of the mozdevice tests. Some of the latter could still be run in CI, and as such I will add mozdevice to the rust crates to test beside geckodriver.

Also com.android.calendar doesn't seem to be a package that is available everywhere, even I thought so because it's part of the gapps suite. Bob, maybe you don't have gapps installed, or just a smaller package that doesn't include the calendar? Which package could we use in the interim to get tests working?

Flags: needinfo?(hskupin) → needinfo?(bob)

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+2] from comment #20)

Also com.android.calendar doesn't seem to be a package that is available everywhere, even I thought so because it's part of the gapps suite. Bob, maybe you don't have gapps installed, or just a smaller package that doesn't include the calendar? Which package could we use in the interim to get tests working?

Maybe we add a requirement to the tests that org.mozilla.firefox needs to be installed? That would give us better results too.

org.mozilla.firefox won't work since it isn't debuggable as far as I know. As I mentioned on Element, perhaps your idea of ignoring these unless --ignored is passed and checking that org.mozilla.geckoview_example is installed before running the tests is sufficient.

Flags: needinfo?(bob)

Ok, that sounds good. I will make that change and have an updated patch soon.

Pushed by hskupin@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/21370b0569b6
[geckodriver] Make profile customizable to support root-less Android devices. r=webdriver-reviewers,jgraham,bc,marionette-reviewers
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 84 Branch

I believe there is an error in the implementation of this: in the latest GeckoDriver, fenix crashes on start up. I believe this happens because the profile path does not exist because the adb commands to create the profile fail. They fail because, on unrooted devices, we don't have access to the app's data directory. The description in comment 0 mentions:

If the device is not rooted, then the profile should be pushed to an intermediate directory on /data/local/tmp, then run-as <app> cp -R intermediate /data/data/<app>/test_root/profile to copy the profile into the app's directory...

However, when I try using run-as <app> ... on my unrooted Pixel 2 with Android 11, I get: run-as: package not debuggable: org.mozilla.fenix. I similarly found that output when run through mozdevice (those commands return a non-zero exit code but mozdevice returns success for them). See my investigation in https://bugzilla.mozilla.org/show_bug.cgi?id=1680407#c8 for further details. I suggest we try to implement the correct behavior in that bug.

Depends on: 1680407

I guess you won't see this but others will.

If your device is not rooted, and your app is not debuggable and you have Android 11 which enforces the scope storage restrictions which prevent the use of the sdcard and requires either a test root in /data/local/tmp or the app's directory, then you are out of luck. In that circumstance, we can not use /data/local/tmp since it will result in files and directories in the test root which are owned by the app's user and which are not accessible to the shell user and we can not use the app's directory since we can not use run-as to run commands as the app's user.

We have an idea to improve the auto detection to use the sdcard in the case where the device is not rooted and the app is not debuggable but only if scoped storage restriction is not in effect which means typically Android 8 or before though 9 may work.

Work for that will happen on bug 1680041, and it's dependencies.

Regressions: 1680407
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: