LSPatch icon indicating copy to clipboard operation
LSPatch copied to clipboard

Enhance installation and cleanup processes(#29)

Open xihan123 opened this issue 9 months ago • 1 comments

This pull request includes several changes to improve the functionality and stability of the LSPatch application. The most important changes include modifications to the AndroidManifest.xml file, updates to the LSPApplication and Patcher classes, and enhancements to the NewPatchScreen and AppManagePage user interfaces.

Permissions and Providers:

  • Added the REQUEST_INSTALL_PACKAGES permission to the AndroidManifest.xml file.
  • Added a FileProvider to the AndroidManifest.xml to support file sharing.

Application and Patching Logic:

  • Introduced a new targetApkFile property in LSPApplication to handle APK files.
  • Updated the Patcher class to copy the APK to the external cache directory and assign it to targetApkFile.

User Interface Enhancements:

  • Modified NewPatchScreen to include a new InstallDialog2 for handling APK installations with additional uninstall logic.
  • Added functions to Utils.kt to check if an APK is fixed by LSP, install APKs, and uninstall APKs by package name.

Clean-Up and Utility Functions:

  • Added a method to clean the external temporary APK directory in LSPPackageManager.
  • Created a new XML file file_paths.xml to define paths for file sharing.

xihan123 avatar Mar 25 '25 04:03 xihan123

I will begin reviewing when I finish my PhD thesis (soon), please feel free to improve current PR.

JingMatrix avatar May 18 '25 07:05 JingMatrix

For the local mode, i.e., when useManager = False, you choose to embed the loader. I am not sure whether this is a good design, I may thus choose to skip the third commit.

Do you find any advantage of doing so?

JingMatrix avatar Aug 03 '25 08:08 JingMatrix

This can be convenient to a certain extent. If there are no changes for a long time, the user experience will be better. However, many users are now reporting that this causes the program to crash.

According to the log, the crash is caused by the core not being loaded.

xihan123 avatar Aug 03 '25 08:08 xihan123

I see, I'd prefer to see the user bug reports. We can keep it as another possible pull-request in the future. You may keep it in another branch of your repo.

Let us focus on the native installation. Currently, most installed application from play store are using split APK delivery. However, the simple Intent method is no longer sufficient to handle multiple APKs.

It is recommended to use PackageInstaller for split APKs. Could you please improve / check this point? To test it out, you can try patching Spotify installed from Google Play as an example.

JingMatrix avatar Aug 03 '25 09:08 JingMatrix

use PackageInstaller for split APKs?

xihan123 avatar Aug 03 '25 09:08 xihan123

I meant, currently, only PackageInstaller can handle split APKs installation. You need to create a PackageInstaller session and so on.

JingMatrix avatar Aug 03 '25 09:08 JingMatrix

I don't understand

xihan123 avatar Aug 03 '25 09:08 xihan123

Okay, here is what I mean.

Problem in you code

You code cannot handle split APK installation, which thus fails to patch most applications installed from Google Play store, such as Spotify. Note that in this case, LSPatch modfies each split APK, and these modified APKs need to be installed at the same time.

My suggestion to solve this

I suggest you to read the official doc of the PackageInstaller API, since this is the official way to handle monolithic APK and split APKs. After reading its doc or maybe some other resources, you should be able to finally solve this problem.

Futher details of this API

This API has a concept of session, by handling all split APKs during a created session, you will manage to correctly install them into the device.

JingMatrix avatar Aug 03 '25 09:08 JingMatrix

OK, now I understand. I will take a look at it when I have time.

xihan123 avatar Aug 03 '25 09:08 xihan123

Is the code written by AI, and you were talking with it in Chinese?

JingMatrix avatar Aug 07 '25 20:08 JingMatrix

Is the code written by AI, and you were talking with it in Chinese?

The annotations were written by the AI, while the overall logic was completed by myself.

xihan123 avatar Aug 08 '25 00:08 xihan123

AI generated code are really low, you should double check. At least, please log in English, and use the TAG properly. No stupid comments from AI.

JingMatrix avatar Aug 09 '25 05:08 JingMatrix

Recently, I have been in the habit of using AI to generate comments to organize the logic after writing the code. However, when submitting, I forgot to delete them.

xihan123 avatar Aug 09 '25 06:08 xihan123

Please rebase on the master branch, remove the two commits, https://github.com/JingMatrix/LSPatch/pull/33/commits/8dba96296b62747c92c61ad68bc9d168b4d476e5 and https://github.com/JingMatrix/LSPatch/pull/33/commits/feea434ccba46dff037b71a54d8bb20ac0afb963.

You can keep them in another branch of your repo.

JingMatrix avatar Aug 09 '25 06:08 JingMatrix