PackageManagerAPI
This adds the PackageGet, PackageList, PackageInstall, and PackageUninstall functions using the PackageManager API on Android
PackageGet - get the information from external storage PackageList - list all system and user installed applications and filter them PackageInstall - install an application from external storage (I know it can be done by termux-open, but having a dedicated APK installer seems good, I guess) PackageUninstall - uninstall an application, doesn't work on system apps
I haven't tested it on Android 10 below and 12 up, I just tested it on my Android 11 phone which works fine I will also add some optimizations if I can because PackageList takes so long to filter out package names
idk if this gets merged or not, but I'll try :)
Hi, nice feature, thanks for the PR! Could you please squash the commits so that just one or a handful remains? The PR at the moment has 42 commits, out of which half says just "test build", which is excessive and makes it harder to review
Thanks for the pull, this is something greatly needed for sure, but PackageManager APIs need to exist in the main termux-app and not in a plugin app. Users shouldn't have install a plugin to get info on packages or install them.
The termux-app already provides the ActivityManager APIs with a TermuxAmSocketServer in the master branch, which will be available in the stable v0.119.0 release. It ports the Android's own ActivityManagerShellCommand that is available with the /system/bin/am command, with features that are possible for an app to execute.
https://github.com/termux/termux-app/blob/062c9771a9ca2efa23e8de109f880c10b93d3fe3/termux-shared/src/main/java/com/termux/shared/termux/shell/am/TermuxAmSocketServer.java
https://github.com/termux/termux-app/blob/062c9771a9ca2efa23e8de109f880c10b93d3fe3/termux-shared/src/main/java/com/termux/shared/shell/am/AmSocketServer.java
https://github.com/termux/termux-am-library/blob/main/termux-am-library/src/main/java/com/termux/am/Am.java
https://github.com/termux/termux-am-socket
https://github.com/termux/termux-packages/blob/master/packages/termux-am-socket/build.sh
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/am/ActivityManagerShellCommand.java
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/cmds/am/am.sh
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/cmds/am/src/com/android/commands/am/Am.java
A similar implementation needs to provided for PackageManager APIs in a separate server (maybe even joined with am server depending on resources and throughput for running 2 servers) based on Android's own PackageManagerShellCommand that is available with the /system/bin/pm command. I have been meaning to ask @tareksander if he has the time to port it ;) otherwise I would have done it myself in future. Many features from it would need to be removed, and additional features will need to be added to it as well, like for getting package info details, including the version name of apps, which is often needed. Another reason why it needs to be part of the termux-app is that it will likely need to be used for TAPM design soon to be implemented, for installing packages provided as app APKs.
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/cmds/pm/pm.sh
Hello, sorry for my late reply. This PackageManagerAPI will just add a small pm command alternative which is parsable because it's JSON, this might be useful for making some sort of "launchers" inside the Termux app, and it's more user-friendly (I guess). maybe I'll work on the TermuxPmSocketServer if I have much knowledge in Android APIs and free time. Thanks for your replies:)
No apologies necessary for late replies.
The TermuxPmServer will also add support for providing full package info in json format, etc. The pm command in android doesn't provide all the required info, that's why I said we need to add additional features. But the whole thing needs to exist in termux-app and not termux-api-app as a single implementation, instead of us having to maintain 2, and one requiring a plugin app. Parts of your pull can be added to that implementation. The pm install command also supports additional flags than this pull.
Generally before implementing new features, it's best to open an issue first and ask the devs how they want it implemented, so you don't waste time going in a different direction.