这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@2096779623
Copy link
Member

No description provided.

@2096779623 2096779623 requested review from Grimler91 and sylirre May 18, 2023 05:33
@sylirre
Copy link
Member

sylirre commented May 18, 2023

pm list packages doesn't work on Android 13

@2096779623
Copy link
Member Author

2096779623 commented May 18, 2023

pm list packages doesn't work on Android 13

~ $ pm list packages|grep com.termux.
package:com.termux.api
package:com.termux.styling
~ $ termux-info
Termux Variables:
TERMUX_API_APP__VERSION_NAME=0.50.1+2c6674f
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP__AM_SOCKET_SERVER_ENABLED=true
TERMUX_APP__APK_PATH=/data/app/~~0NZTxnn8gRJzq6TrrRHsLQ==/com.termux-WFA1nFFqsCUVMO37JW8RqQ==/base.apk
TERMUX_APP__APK_RELEASE=GITHUB
TERMUX_APP__FILES_DIR=/data/user/0/com.termux/files
TERMUX_APP__IS_DEBUGGABLE_BUILD=true
TERMUX_APP__IS_INSTALLED_ON_EXTERNAL_STORAGE=false
TERMUX_APP__PACKAGE_MANAGER=apt
TERMUX_APP__PACKAGE_NAME=com.termux
TERMUX_APP__PACKAGE_VARIANT=apt-android-7
TERMUX_APP__PID=15239
TERMUX_APP__SE_FILE_CONTEXT=u:object_r:app_data_file:s0:c185,c256,c512,c768
TERMUX_APP__SE_INFO=default:targetSdkVersion=28:complete
TERMUX_APP__SE_PROCESS_CONTEXT=u:r:untrusted_app_27:s0:c185,c256,c512,c768
TERMUX_APP__TARGET_SDK=28
TERMUX_APP__UID=10185
TERMUX_APP__USER_ID=0
TERMUX_APP__VERSION_CODE=118
TERMUX_APP__VERSION_NAME=0.118.0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirrors.ustc.edu.cn/termux/apt/termux-main stable main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
# x11-repo (sources.list.d/x11.list)
deb https://mirrors.ustc.edu.cn/termux/apt/termux-x11 x11 main
Updatable packages:
clang/stable 16.0.4 aarch64 [upgradable from: 16.0.3]
curl/stable 8.1.0 aarch64 [upgradable from: 8.0.1]
fribidi/stable 1.0.13 aarch64 [upgradable from: 1.0.12]
libcompiler-rt/stable 16.0.4 aarch64 [upgradable from: 16.0.3]
libcurl/stable 8.1.0 aarch64 [upgradable from: 8.0.1]
libllvm/stable 16.0.4 aarch64 [upgradable from: 16.0.3]
lld/stable 16.0.4 aarch64 [upgradable from: 16.0.3]
llvm/stable 16.0.4 aarch64 [upgradable from: 16.0.3]
termux-tools version:
1.38.1
Android version:
13
Kernel build information:
Linux localhost 4.14.299-Perf #4 SMP PREEMPT Sun Dec 4 15:42:55 CST 2022 aarch64 Android
Device manufacturer:
LGE
Device model:
LM-G820N
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api
com.termux.styling
~ $

Work fine on my Android 13 🤔 .

@sylirre
Copy link
Member

sylirre commented May 18, 2023

Do you have special permissions granted through ADB?

This happens on both F-Droid and GitHub builds:
Screenshot

Nothing is shown in logcat regarding pm failure.

@2096779623
Copy link
Member Author

2096779623 commented May 18, 2023

Do you have special permissions granted through ADB?

No.

@sylirre
Copy link
Member

sylirre commented May 18, 2023

Then perhaps it depends on manufacturer (ROM configuration) and can't be considered as stable way to retrieve list of the applications.

I propose something like this:

TERMUX_PLUGINS=$(pm list packages | grep -v '^cmd:' | grep com.termux.)

if [ -n "$TERMUX_PLUGINS" ]; then
  printf "Installed plugins:\n%s\n" "$TERMUX_PLUGINS"
fi

@agnostic-apollo
Copy link
Member

Nothing is shown in logcat regarding pm failure

It's an selinux restriction that can be bypassed as mentioned in my comment above by using a sub shell and redirecting stdin to /dev/null and stderr to stout.

@agnostic-apollo
Copy link
Member

Also do not hardcode com.termux in grep.

@2096779623 2096779623 force-pushed the master branch 2 times, most recently from 53a58d6 to c6689c4 Compare May 19, 2023 08:30
@2096779623
Copy link
Member Author

Then perhaps it depends on manufacturer (ROM configuration) and can't be considered as stable way to retrieve list of the applications.

Please check if it works fine.

@2096779623 2096779623 force-pushed the master branch 2 times, most recently from 748539b to b872711 Compare May 19, 2023 12:36
@2096779623 2096779623 requested a review from sylirre May 19, 2023 12:37
@agnostic-apollo
Copy link
Member

The regex will match other package names as well. Wait for full response.

@2096779623
Copy link
Member Author

The regex will match other package names as well. Wait for full response.

For example?

@agnostic-apollo

This comment was marked as resolved.

@agnostic-apollo

This comment was marked as resolved.

@agnostic-apollo

This comment was marked as resolved.

@2096779623
Copy link
Member Author

p.s The --show-versioncode option was added in Android 8 but wasn't shown in help output till android 10, can be added if needed by checking ro.build.sdk.version against >= 26.

escaped_package_name="$(echo -n "@TERMUX_APP_PACKAGE@" | sed -zE -e 's/[][\.|$(){}?+*^]/\\&/g')"
if [ "$(getprop ro.build.version.sdk)" -ge "26" ]; then
    SHOW_VERSION_CODE="--show-versioncode"
fi
TERMUX_PLUGINS="$(pm list packages --user "${TERMUX__USER_ID:-0}" $SHOW_VERSION_CODE 2>&1 </dev/null | grep -E "^package:$escaped_package_name\.[a-zA-Z]" | cut -d ":" -f 2- | grep -vE "^$escaped_package_name\.tapm\.[a-zA-Z]")"

@agnostic-apollo
Copy link
Member

agnostic-apollo commented May 20, 2023

Yeah, that would work, but check output of getprop to ensure its an integer before -ge, otherwise will trigger the integer expression expected error if value is invalid or unset. Also should unset show_version_code in case already set, local can't be used since code is not in a function.

show_version_code=""
sdk_version="$(getprop ro.build.version.sdk || :)"
if [[ "$sdk_version" =~ ^[0-9]+$ ]] && [ "$sdk_version" -ge "26" ]; then
  show_version_code="--show-versioncode"
fi

@agnostic-apollo
Copy link
Member

Updated...

Signed-off-by: Kevin Williams <admin@utermux.dev>
Co-authored-by: Leonid Pliushch <leonid.pliushch@gmail.com>
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com>
@2096779623 2096779623 merged commit cfd45f2 into termux:master May 20, 2023
@agnostic-apollo
Copy link
Member

Looks good, thanks!

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.

3 participants