-
Notifications
You must be signed in to change notification settings - Fork 104
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
refactor(ADB): improve internal API #757
base: main
Are you sure you want to change the base?
Conversation
Here's the code health analysis summary for commits Analysis Summary
|
Also make `get_device_brand` more honest
Also merge some `use`s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, there's only one or two good changes here (e.g. explicit serial, deduping android_sdk >= 21
). Most of the other ones are subjective, so they may not be beneficial to others. It is my opinion that changes for the sake of changes should not be done.
I am not a fan of shortening variable names, as none of them were long enough that they needed abbreviation in the first place. For example, command => cmd, packages => packs, shell => sh is wholly unnecessary and adds noise to this PR. It's also not done consistently, as sometimes we see the full word being used (packages), and in other places two different short-forms. (e.g. packs and pack)
Even the renaming of Phone
to Device
was not necessary, especially when considering it's unrelated to this PR, and that some variables are named device
, some dev
, and some remain as phone
.
Forgive the bluntness, but please revert any such subjective changes. We can discuss the specifics on Discord.
Typing in natural language form is more efficient for the developer. When we think of typing "command", we expect to start typing it and have autocomplete suggest it as-is. It will not surface "cmd", so we'd need to remember to type abbreviations everywhere, only to realise that abbreviations are not consistently used. This extra step is at odds with the basic methodology of good, clean code for everyone.
@@ -137,7 +138,7 @@ impl Settings { | |||
None => { | |||
self.device = DeviceSettings { | |||
device_id: phone.adb_id.clone(), | |||
multi_user_mode: phone.android_sdk > 21, | |||
multi_user_mode: supports_multi_user(phone), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential bug: the function checks >=
; while the previous code was simply >
. The official Android API to check for this was added in API 24; however, before this it was manufacturer-dependent. IIRC multiple users were possible even before API 21, via ADB (pm create-user
). Not sure if it was exposed in a user-facing way.
See https://source.android.com/docs/devices/admin/multi-user#applying_the_overlay:
The multi-user feature is disabled by default. To enable the feature, device manufacturers must define […]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I noticed some inconsistencies, so I tried to find docs about which API level should be checked, and I defaulted to Android 5.0
src/core/sync.rs
Outdated
pub async fn perform_adb_commands( | ||
/// Runs a shell command on the device. | ||
/// See [`adb_cmd`] for details. | ||
pub async fn adb_sh_cmd<S: AsRef<str>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of shortening this, and other definitions. It does not help readability; in fact, it makes it more ambiguous at times.
For example, while we obviously know sh => shell and cmd => command, others may assume /bin/sh
or Windows CMD, leading to confusion: does this function only work over sh
and cmd
, or is it a generic platform-agnostic abstraction?
src/core/sync.rs
Outdated
|
||
/// `pm list packages` flag/state/type | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum PmLsPackFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enums are for our benefit, so we should use full, descriptive names here. Please change to:
- IncludeUninstalled
- OnlyEnabled
- OnlyDisabled
For completeness, we could also add entries for all other possible flags (f, d, s, 3, i) (docs). Unused code should be stripped out of the final release binary anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use full, descriptive names
I agree. Single-letter is bad. And it even looks ugly because of the relative length asymmetry with the enum
name.
I tried to mirror the ADB CLI, but I've already deviated from it when I renamed list_users
to ls_users
, so I guess it doesn't hurt to improve the flag names.
For completeness, we could also add entries for all other possible flags (f, d, s, 3, i) (docs).
3
and s
should probably be on a distinct enum
, as they are a different kind of filter. Same for i
and f
.
About completeness, what about #[non_exhaustive]
👀 ? That way, we can easily add the other flags if we need them
I agree with the sentiment, as major refactors could introduce bugs. I tried my best to document all possible places where I could've created one.
yeah 😅, I'll revert that.
I'll revert the rename and defer that to its own PR. I did too much "opportunistic refactoring" (mostly just "opportunistic renaming", which is not very valuable)
Ok 😅 🙁, I'll try to revert all out-of-scope changes. I can't do it today. I'll have more time on the weekend.
Agreed. One of the motivations I had in mind for this PR is to make the code-base more accessible to newcomers (#731), but the strongly context-bound names might go against that goal |
This week, I've been busier than I expected, so I couldn't work on this |
sync
): removeset_var
in favor ofadb_id
#653sync
): removeset_var
in favor ofadb_id
#653 (comment)The goal is to make ADB commands:
stdout
I am sorry to whoever is going to review this 😅. I didn't want the diff to be so big 💀