Skip to content

Conversation

rickclephas
Copy link
Contributor

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

The goal is to automatically enable and disable the clean status bar so that you don't have to do this manually with for example the QuickDemo app.

Description

I have added the options clean_status_bar and clean_status_bar_config to screengrab.
With clean_status_bar the clean status bar can be enabled.
Use the clean_status_bar_config option to customise the appearance of the clean status bar.

The configuration options are based on the commands described here:
https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/docs/demo_mode.md

ToDos

  • We probably need some documentation for the possible configuration keys and their values
  • It seems that the configuration for the mobile network icons are reset when screengrab changes the local to anything other then the device local. Maybe we should move this functionality to the screengrab-lib so that it can set the clean status bar after every local change?

@janpio any thoughts?

@janpio
Copy link
Member

janpio commented Sep 8, 2019

Thanks for tackling this @rickclephas!

If you don't want to put the options description into the description of the option, we should probably put it into the full documentation that can be edited via https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/docs/capture_android_screenshots.md Maybe a headline before https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/docs/capture_android_screenshots.md#tips?

  • It seems that the configuration for the mobile network icons are reset when screengrab changes the local to anything other then the device local. Maybe we should move this functionality to the screengrab-lib so that it can set the clean status bar after every local change?

Sounds valid, and I am sure you know more about this right now - so I trust your judgement to decide how to do this.

@rickclephas
Copy link
Contributor Author

we should probably put it into the full documentation

Yeah that is probably best since there are 25 configuration options.

Sounds valid, and I am sure you know more about this right now - so I trust your judgement to decide how to do this.

Alright I will see if moving it to the screengrab-lib works better.
If it does we could allow the customisation of the status bar in the test classes.
Would that be preferable over configuring it in the Screengrabfile?

@janpio
Copy link
Member

janpio commented Sep 8, 2019

I honestly can't answer that as I don't know enough about that functionality.

If I understood everything correctly: In general it feels like configuring the screenshots should maybe not be in the tests, but in the screenshot taking configuration - so lane/action options.

@rickclephas
Copy link
Contributor Author

rickclephas commented Sep 8, 2019

So I have now moved all the configuration to the screengrab-lib.

To use the feature users will need to add the following lines to their debug/AndroidManifest.xml

<uses-feature android:name="tools.fastlane.screengrab.cleanstatusbar"/>
<uses-permission android:name="android.permission.DUMP" tools:ignore="ProtectedPermissions" />

The android.permission.DUMP permission is required to allow the app to configure the status bar.
Screengrab will need to grant this permission before running the test.
With the tools.fastlane.screengrab.cleanstatusbar feature we can detect if the users wants to use the clean status bar option and grant the permission.
NOTE: We could also detect the permission but for the clean status bar to work we also set the sysui_demo_allowed global setting and I am not sure if the DUMP permission is used by any other tools.

Then in the test class you can enable and disable the clean status bar at any moment.
You probably want to put this in the @BeforeClass and @AfterClass methods.

@BeforeClass
public static void beforeAll() {
    Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());

    CleanStatusBar.enableWithDefaults();
}

@AfterClass
public static void afterAll() {
    CleanStatusBar.disable();
}

You can also use a custom configuration.
For example to show the LTE text and Bluetooth icon:

new CleanStatusBar()
    .setMobileNetworkDataType(MobileDataType.LTE)
    .setBluetoothState(BluetoothState.DISCONNECTED)
    .enable();

With the configuration in the test class it would also be possible to have a different status bar for different screenshots.
That might be useful to change the status bar from transparent to semi-transparent based on different activities so that it matches the actual behaviour of the app.

If we move the configuration to the lane/actions options we have to pass all the configurations to the test via the am instrument command. With 25 configuration options that seems a little ugly in the logs.

@rickclephas rickclephas marked this pull request as ready for review September 11, 2019 18:16
@rickclephas rickclephas changed the title [WIP] [screengrab] automated clean status bar [screengrab] automated clean status bar Sep 11, 2019
@rickclephas
Copy link
Contributor Author

Documentation has been updated.
Let me know if there is anything else that needs to be done.

@janpio janpio requested a review from joshdholtz September 11, 2019 20:17
@janpio janpio changed the title [screengrab] automated clean status bar [screengrab] Let users set clean status bar Sep 11, 2019
@joshdholtz joshdholtz force-pushed the feature/screengrab-clean-status-bar branch from eae9c44 to 3ff92f0 Compare November 13, 2019 01:26
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sooooo 💯 Thanks so much for all the time you spent on this 😊 I rebased from master and fixed it to add support for AndroidX. Really appreciate the contribution ❤️

@joshdholtz joshdholtz merged commit 2cdd049 into fastlane:master Nov 13, 2019
@fastlane-bot
Copy link

Hey @rickclephas 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a week, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀

@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.136.0 🚀

@fastlane fastlane locked and limited conversation to collaborators Jan 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants