Skip to content

fix: Directly save APK to the cache when saving last patched app #2332

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

BenjaminHalko
Copy link
Member

@BenjaminHalko BenjaminHalko commented Nov 30, 2024

This should hopefully solve the issue where it can't write the patched app for some reason

Instead of copying the APK from the temp patcher directory after patching is complete, the patcher will just save the APK to the directory to begin with.

This should hopefully solve the issue where it can't write the patched app for some reason
@BenjaminHalko BenjaminHalko marked this pull request as draft November 30, 2024 21:55
@BenjaminHalko
Copy link
Member Author

This needs to be tested before merging. I can't get the original issue to appear.

@oSumAtrIX
Copy link
Member

@BenjaminHalko BenjaminHalko changed the title fix: Use cache directory for the last patched app fix: Directly save APK to the cache when saving last patched app Nov 30, 2024
@BenjaminHalko BenjaminHalko marked this pull request as ready for review November 30, 2024 22:21
@KobeW50
Copy link
Contributor

KobeW50 commented Dec 6, 2024

This needs to be tested before merging. I can't get the original issue to appear.

Does this fix #2224? If yes, you can send me an APK with the changes and I'll test it

@ILoveOpenSourceApplications

@validcube, This PR was marked as ready for review yet there's no review. Maybe you can look into this?

@kitadai31
Copy link
Contributor

kitadai31 commented Apr 20, 2025

I tested this PR and found two issues

  1. "Installation cancelled" is fixed, but instead, the patched app is not saved to the last patched app section sometimes.
  2. When the above issue (1.) occurs, the tmp-XXXXXX.apk file (last patched app) is left in the app data and become an orphan file.
    Since the file names are randomized, it will never be overwritten.
    There is no way to remove it other than clearing the app data.

I think randomization doesn't really solve the problem.

I found another simple solution, so please check a PR that I will open.

EDITED: I finally found a real cause of this issue. I said "once every two times" at first, but this was wrong. Edited.

Comment on lines +185 to +193
if (_managerAPI.isLastPatchedAppEnabled()) {
// Get a random name from temp dir
// This is to avoid overwriting the last patched app
final String randomName = workDir.path.split('/')[workDir.path.split('/').length - 1];
final Directory cacheDir = await getApplicationSupportDirectory();
outFile = File('${cacheDir.path}/$randomName.apk');
} else {
outFile = File('${workDir.path}/out.apk');
}
Copy link
Member

Choose a reason for hiding this comment

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

This change may be reverted according to the comment in #2490. The change above can be kept.

final Directory appCache = await getApplicationSupportDirectory();
app.patchedFilePath =
outFile.copySync('${appCache.path}/lastPatchedApp.apk').path;
app.patchedFilePath = outFile.path;
Copy link
Member

Choose a reason for hiding this comment

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

But outfile is a temporary file that is eventually deleted no?

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.

5 participants