nwrkbiz / android-xserver

Maintaining the original project to make it work again with new Android versions.
MIT License
179 stars 21 forks source link

Problems with APKs produced by gradle build #18

Closed nwrkbiz closed 3 years ago

nwrkbiz commented 3 years ago

Leads to failing execution of FLWM. There are also problems with notifications. Maybe because of the split between xserver and xdemo.

nwrkbiz commented 3 years ago

@IriaSomobu Can you help me out with this problem? Fixing this would also fix the APKs provided by F-Droid.

IriaSomobu commented 3 years ago

Yep, I'll see what's gone wrong tomorrow.

Please, can you provide a bit more info? Detailed description on how to reproduce the bugs will help a lot

IriaSomobu commented 3 years ago

By the way, it is gRAdle build system, not gARdle.

nwrkbiz commented 3 years ago

I have added a window manager (FLWM) to the project. (Located in /demo/src/main/assets/) This can be toggled on/off via an menu entry in xdemo: https://github.com/nwrkbiz/android-xserver/blob/b7fcf6cbe4e6579c4a10a0e44b91d9dfeb15c76f/demo/src/main/java/au/com/darkside/xdemo/XServerActivity.java#L302

With APKs produced by gradle this fails with "permission denied". I think this happens, because two os users are created on install time. One for au.com.darkside.xdemo and the other for au.com.darkside.xserver. It seems to me like, while the executables are unpacked and owned by xdemo, they are beeing tried to execute by xserver.

I implemented a "Running in background" notification to be shown when "minimizing" the xserver app. This does not seem to work with the gradle apk. (See: https://github.com/nwrkbiz/android-xserver/commit/0b77516140116c6b4d32b9b9e06763427ff621e9)

IriaSomobu commented 3 years ago

Built from commit b7fcf6c (latest on master): unable to reproduce problems on Android 7.1.2

When window manager toggled on Notification on background No notification on foreground
Screenshot_20210102-175723 Screenshot_20210102-175802 Screenshot_20210102-175814

You are 100% wrong at this part:

two os users are created on install time. One for au.com.darkside.xdemo and the other for au.com.darkside.xserver.

Android creates one user per application. For our demo.apk it is au.com.darkside.xdemo user as is stated in line 7 of build.gradle. Code of library project is compiled and copied into demo project just as regular compiled code -- you can find it in apk's classes.dex file.

Also:

It seems to me like, while the executables are unpacked and owned by xdemo, they are beeing tried to execute by xserver.

Just in case -- files located in au.com.darkside.xserver package related to library project only, which should stay WM- and executables-agnostic. Library is pure XServer without any code related to window managers, executable management, etc.

IriaSomobu commented 3 years ago

As for notifications, in Android 8 Google forced us to use Notification channels. I'll PR with notification fix soon.

nwrkbiz commented 3 years ago

Hmm thats strange. Did you also try the APK provided by f-droid?

Or this (local build of mine, changed "/data/data/" to getApplicationInfo().dataDir + "/" + executable in XServerActivity.java): demo-debug.apk.zip

When installing and running demo-debug.apk two folders with different ownership are created in /data/data/ (thats where my assumption came from -> uid u0_a173 tries to execute wm.aarch64 which fails with permission denied): image

And big thanks for your help, I feel a little bit lost on this one.

IriaSomobu commented 3 years ago

Did you also try the APK provided by f-droid?

Yep. Both F-Droid's apk and debug apk works in a same way as manually compiled one. Also I do not have ...xserver folder on my device, only ...xdemo.

two folders with different ownership are created

I assume that folder au.com.darkside.xserver was created by old XServer version that was built before demo-library separation, because only there app's package name is set to au.com.darkside.XServer.

nwrkbiz commented 3 years ago

Ok, I just tried it on an Android 6 device, and everything works fine there aswell. My main device is Android 10 so it is defenitly related to the android versions. (Something I should have tried in the first place)

Hmm, ... maybe targeting API level 23 via "compileSdkVersion" in build.gardle can resolve this?

I assume that folder au.com.darkside.xserver was created by old XServer version that was built before demo-library separation, because only there app's package name is set to au.com.darkside.XServer.

I manually deleted the folder and uninstalled all other versions to verify that this is not the case.

nwrkbiz commented 3 years ago

Jup.

Setting compileSdkVersion 23 and targetSdkVersion 23 within the build.gradle forces the old API and everything seems to work there.

IriaSomobu commented 3 years ago

compileSdkVersion 23 tells gradle that we want to use old build tools (SDK). I think you can safely revert this line and nothing will change.

targetSdkVersion 23 tells android that our app is designed for elder android version and should be run in backward compatibility mode. Also GooglePlay refuses to publish apps this so low targetSdkVersion. I think this line "fixes" the bug.

By the way, can you record log via logcat?

nwrkbiz commented 3 years ago

targetSdkVersion 23 tells android that our app is designed for elder android version and should be run in backward compatibility mode. Also GooglePlay refuses to publish apps this so low targetSdkVersion. I think this line "fixes" the bug.

Yeah GooglePlay requires minimum sdk to be 29.

By the way, can you record log via logcat?

Yes I can, what do you want me to record?

IriaSomobu commented 3 years ago

Yes I can, what do you want me to record?

Everything at the moment of crash and some log lines before and after that moment. Start an app, then adb logcat on your PC (redirecting output to a file), and then trigger app to a crash and stop recording. After you got logcat file, make sure there are no sensitive information and then put log file here.

nwrkbiz commented 3 years ago

Ok I think I found a solution. With the new API level, execution permissions are only granted to getApplicationInfo().nativeLibraryDir.

For these folder to be generated, we will need to add /jniLibs/<<cpu-arch>> folders to our xdemo subproject and set android:extractNativeLibs="true" in AndroidManifest.

nwrkbiz commented 3 years ago

adb logcat stacktrace of F-Droid build on android 10 device:

01-02 18:58:57.952 30322 30322 D AndroidRuntime: Shutting down VM
01-02 18:58:57.953 30322 30322 E AndroidRuntime: FATAL EXCEPTION: main
01-02 18:58:57.953 30322 30322 E AndroidRuntime: Process: au.com.darkside.xdemo, PID: 30322
01-02 18:58:57.953 30322 30322 E AndroidRuntime: java.lang.RuntimeException: java.io.IOException: Cannot run program "/data/data/au.com.darkside.xdemo/wm.aarch64" (in directory "/data/data/au.com.darkside.xdemo"): error=13, Permission denied
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at au.com.darkside.xdemo.XServerActivity.onOptionsItemSelected(Unknown Source:281)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.app.Activity.onMenuItemSelected(Activity.java:4156)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.policy.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1255)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:787)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:151)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:934)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:924)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.view.menu.MenuPopup.onItemClick(MenuPopup.java:128)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.widget.AdapterView.performItemClick(AdapterView.java:330)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.widget.AbsListView.performItemClick(AbsListView.java:1215)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.widget.AbsListView$PerformClick.run(AbsListView.java:3223)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:883)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:100)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:214)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7397)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:920)
01-02 18:58:57.953 30322 30322 E AndroidRuntime: Caused by: java.io.IOException: Cannot run program "/data/data/au.com.darkside.xdemo/wm.aarch64" (in directory "/data/data/au.com.darkside.xdemo"): error=13, Permission denied
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at au.com.darkside.xdemo.XServerActivity.onOptionsItemSelected(Unknown Source:263)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        ... 17 more
01-02 18:58:57.953 30322 30322 E AndroidRuntime: Caused by: java.io.IOException: error=13, Permission denied
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at java.lang.UNIXProcess.forkAndExec(Native Method)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at java.lang.ProcessImpl.start(ProcessImpl.java:141)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
01-02 18:58:57.953 30322 30322 E AndroidRuntime:        ... 18 more
nwrkbiz commented 3 years ago

Further info: https://www.reddit.com/r/androiddev/comments/b2inbu/psa_android_q_blocks_executing_binaries_in_your/

I tried the suggested solution and it worked fine for me, I'll pr to your notification branch.