Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

[WIP] Add a way to select Android User to let Flipper working on devices with Work Profile #4606

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

sbatezat
Copy link

Summary

Add a way to select Android User to let Flipper working on devices with Work Profile.
Fix #953 & #4605

Changelog

Add a setting on settings sheet to select the Android User to use.
Useful to select the work profile on devices with two users (personal / work profile)

Comments

I don't know React. It works but help would be appreciate to improve code quality/tests. Please feel free to fix things that are not well written before merging this PR.

Known limitations

  • In order to correctly switch from one android user to another, you have to change the setting on the settings sheet and RESTART flipper ("apply and restart").
  • You can't save a profile per device. If you select a work profile available on device A, and you wan't to use a personal profile on device B, you have to change manually settings each time you switch devices (and restart flipper, see above).

@facebook-github-bot
Copy link
Contributor

Hi @sbatezat!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 16, 2023
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

1 similar comment
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@sbatezat
Copy link
Author

Hi there,
Any chance someone (@passy ?) review it and merge it on the main branch?
I'm sure a lot of people will enjoy this new feature :)

Copy link
Contributor

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this and submitting a PR! Left a few questions. Could you also record some screenshots or recording as test plan?

Thanks!

const activeDevice: BaseDevice = useSelector(getActiveDevice);
const [users, setUsers] = useState([] as {id: string; name: string}[]);

activeDevice
Copy link
Contributor

Choose a reason for hiding this comment

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

Best run shell commands in an effect, with the current setup the command is fired on every render

Copy link
Author

Choose a reason for hiding this comment

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

As said on comments, I don't know React. Please feel free to edit that part, as I don't have knowledge about these "useEffect" things. Just a warn: when you say "the command is fired on every render", it may be fine. Best would be to run this command each time selected device change (and user is opening settings sheet) or you could have bad users ids shown.

});
setUsers(users || []);
})
.catch((error) => console.error(error));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some more details to the error message? Also let's start with .warn, as this is typically a local setup issue

Copy link
Author

@sbatezat sbatezat Mar 22, 2023

Choose a reason for hiding this comment

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

This command should not fail. If this command fails there is chances that every shell command will. If I have a look on Flipper source code where executeShell is called, errors are not even managed. For example, on plugins/public/cpi/index.tsx

const chipname = await executeShell('getprop ro.chipname');

There is no try/catch.
The only reason why I've got a catch it's because I don't know how to await in a React context so linters are compelling me to consume the promise in the good old way (.then/.catch) with a compelled catch block (as per linters rules).

With these informations in mind, what do you think about changes I should work on this? Just a warn instead of an error?


const logTag = 'AndroidCertificateProvider';

export default class AndroidCertificateProvider extends CertificateProvider {
name = 'AndroidCertificateProvider';
medium = 'FS_ACCESS' as const;

constructor(private adb: Client) {
constructor(private flipperServer: FlipperServerImpl, private adb: Client) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we pass in less here than the entire flipperServer? For example just the settings object?

Copy link
Author

Choose a reason for hiding this comment

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

I can do that yes 👍
What's your though about the more suitable thing to pass in?
You are suggesting the settings object, but the minimal one would be the userId. Indeed, the only reason why flipperServer is pass in is to read "this.flipperServer.config.settings.androidUserId"

@coveralls
Copy link

coveralls commented Mar 22, 2023

Pull Request Test Coverage Report for Build 4477312510

  • 5 of 33 (15.15%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.07%) to 50.941%

Changes Missing Coverage Covered Lines Changed/Added Lines %
desktop/flipper-ui-core/src/chrome/SettingsSheet.tsx 4 16 25.0%
desktop/flipper-ui-core/src/chrome/settings/configFields.tsx 1 17 5.88%
Files with Coverage Reduction New Missed Lines %
desktop/test-utils/src/pathUtils.tsx 2 57.14%
Totals Coverage Status
Change from base Build 4450172237: -0.07%
Covered Lines: 8180
Relevant Lines: 14651

💛 - Coveralls

@sbatezat
Copy link
Author

Hi @mweststrate , thanks for reviewing my PR 👍

I've answered with some questions, could you please double check them?
Please also find bellow some screenshot, as requested:

MicrosoftTeams-image (3)

MicrosoftTeams-image (1)

MicrosoftTeams-image (2)

MicrosoftTeams-image

@sbatezat
Copy link
Author

sbatezat commented Mar 30, 2023

Hi @mweststrate, could you please have a look on my questions above?
Thanks!

@sbatezat
Copy link
Author

Hi @mweststrate, just a quick reminder on this topic :)
Could you please answer my questions above?

@mweststrate
Copy link
Contributor

mweststrate commented Apr 13, 2023 via email

@daniel-robertson
Copy link

@sbatezat Great effort! Adding work profile support is an excellent feature. @mweststrate Could you please revisit for a review when you get the chance? Thanks.

@sbatezat
Copy link
Author

I've juste resolved conflicts and merged every changes you made
@mweststrate could you please have a look on this? My teams are waiting for this for a long time now

@sbatezat
Copy link
Author

Again some conflicts resolved to merge latest updates of the main branch.
@mweststrate if you don't have time to review these changes, is it possible to ask to someone else in the team?

@sbatezat
Copy link
Author

One year later....
@mweststrate are you alone on that dead project?

@sbatezat
Copy link
Author

@passy any help on this?

@albertoastiazaran-qz
Copy link

I would love it if this change got merged!
Thanks for working on this, @sbatezat, I'm hoping you're able to get it approved.

@albertoastiazaran-qz
Copy link

I'd still like to see this merged. @antonk52 (since I see you've contributed multiple times in the past month), do you think you can help us move this along? Not sure who would be the best person to review at this time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to load app in a work profile in Android
6 participants