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

Replace 'pm list packages' with 'dumpsys package' #130

Merged
merged 4 commits into from Jan 6, 2021
Merged

Replace 'pm list packages' with 'dumpsys package' #130

merged 4 commits into from Jan 6, 2021

Conversation

A-YATTA
Copy link
Collaborator

@A-YATTA A-YATTA commented Dec 24, 2020

In some cases, the command 'pm list packages' will not list all enabled third party packages (same for -e and -s).
https://stackoverflow.com/questions/63416599/adb-shell-pm-list-packages-missing-some-packages

cmd = 'dumpsys package'
grep_cmd = 'grep -Po "Package \[\K[^\]]+"'
apps_list = execute_adb_shell_command(cmd, piped_into_cmd=grep_cmd)
# packages = _get_all_packages(cmd)
Copy link

Choose a reason for hiding this comment

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

Remove this commented out code.

lambda p : p not in runtime_granted_permissions and
p not in runtime_denied_permissions and
p not in install_time_granted_permissions and
p not in install_time_denied_permissions, requested_permissions))
Copy link

Choose a reason for hiding this comment

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

Continuation line unaligned for hanging indent

_ASYNCIO_AVAILABLE = True
except ImportError:
except ImportError :
Copy link

Choose a reason for hiding this comment

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

Whitespace before ':'

Copy link
Owner

Choose a reason for hiding this comment

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

Please revert

# This is to deal with python versions below 3.5
_ASYNCIO_AVAILABLE = False
else:
else :
Copy link

Choose a reason for hiding this comment

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

Whitespace before ':'

Copy link
Owner

Choose a reason for hiding this comment

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

Please revert

_ASYNCIO_AVAILABLE = False

try:
try :
Copy link

Choose a reason for hiding this comment

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

Whitespace before ':'

if activity_name.startswith('.'):
activity_name = '%s%s' %(app_name, activity_name)
return app_name, activity_name
if line.startswith('mFocusedApp'):
Copy link
Owner

Choose a reason for hiding this comment

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

Is this change intentional? I think this is the exact code that I removed in 69bb243

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, I forked the master branch.

Copy link
Owner

Choose a reason for hiding this comment

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

Just do a git pull origin master in that case. Your branch has become stale. I changed this code <24 hours ago.

cmd = 'pm list packages'
packages = _get_all_packages(cmd)
print('\n'.join(packages))
# The command "pm list packages -e" does not return all installed and enabled Apps, the alternative is to use
Copy link
Owner

Choose a reason for hiding this comment

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

So what exactly does pm list packages -e miss? Disabled apps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pm list packages -e for some unknown reason does not list some enabled apps.
-e should show all enabled Apps including system Apps which is not the case as discussed in the thread: https://stackoverflow.com/questions/63416599/adb-shell-pm-list-packages-missing-some-packages

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks. It is fine if we don't know the underlying cause. Add this StackOverflow thread in the code comments as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I saw that the regex is reported as an anomaly by DeepSource Python, Can we replace it by this one dumpsys package | grep "Package \[" | cut -d "\[" -f2 | cut -d "\]" -f1.

Copy link
Owner

Choose a reason for hiding this comment

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

The new code is fine. Just confirm that cut command's arguments are the same on both Linux and Mac.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should be the same (https://superuser.com/questions/179368/how-does-macs-command-line-compare-to-linux), unfortunately I do not have a Mac to test. Can someone else confirm that please ?

Copy link
Owner

Choose a reason for hiding this comment

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

I got cut: bad delimiter as an error on Mac OS. How about we do this parsing in Python instead? That's much more portable as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes sure, I will update it.

@@ -1562,43 +1579,3 @@ def switch_screen(switch_type):
"screen control operation. Error: %s" % e)

return o

Copy link
Owner

Choose a reason for hiding this comment

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

Please rebase your code to avoid reverting this addition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. Sorry for that!

Copy link
Owner

Choose a reason for hiding this comment

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

No worries.

adbe/adb_enhanced.py Outdated Show resolved Hide resolved
Copy link
Owner

@ashishb ashishb 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 your contribution.

@A-YATTA
Copy link
Collaborator Author

A-YATTA commented Dec 24, 2020

Command output:

$ adbe apps list all
com.android.cts.priv.ctsshim
com.android.internal.display.cutout.emulation.corner
com.android.internal.display.cutout.emulation.double
com.android.providers.telephony
com.android.dynsystem
com.android.providers.calendar
com.android.providers.media
com.android.theme.icon.square
com.android.internal.systemui.navbar.gestural_wide_back
....

Copy link
Owner

@ashishb ashishb left a comment

Choose a reason for hiding this comment

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

Approved pending the addition of StackOverflow thread as a comment for future reference.

@A-YATTA A-YATTA closed this Dec 24, 2020
@A-YATTA A-YATTA reopened this Dec 24, 2020
@codeclimate
Copy link

codeclimate bot commented Jan 5, 2021

Code Climate has analyzed commit 4115230 and detected 5 issues on this pull request.

Here's the issue category breakdown:

Category Count
Security 5

View more on Code Climate.

@ashishb
Copy link
Owner

ashishb commented Jan 6, 2021

So, I checked dumpsys package | grep "Package \[" today. It includes some duplicates but even after removing all duplicates I saw 420 packages as opposed to 403 packages from adb shell pm list packages, I do see some weird and interesting services listed. So, yeah, let's merge this after de-duplicating the list.

@ashishb ashishb merged commit ac04b83 into ashishb:master Jan 6, 2021
return_code, result, _ = execute_adb_shell_command2(cmd)
if return_code != 0:
print_error_and_exit('Command "%s" failed, something is wrong' % cmd)
all_apps = re.findall(pattern_packages, result)
Copy link
Owner

Choose a reason for hiding this comment

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

This is not printing the results. I will fix that in #135

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

Successfully merging this pull request may close these issues.

None yet

2 participants