Skip to content

Commit

Permalink
[Installer] Fix deleting the cached file when the installation fails
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Jun 4, 2024
1 parent d1b91a4 commit 3b007ce
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.github.muntashirakon.AppManager.apk.behavior.DexOptimizer;
import io.github.muntashirakon.AppManager.compat.PackageManagerCompat;
import io.github.muntashirakon.AppManager.intercept.IntentCompat;
import io.github.muntashirakon.AppManager.logs.Log;
import io.github.muntashirakon.AppManager.main.MainActivity;
import io.github.muntashirakon.AppManager.progress.NotificationProgressHandler;
import io.github.muntashirakon.AppManager.progress.NotificationProgressHandler.NotificationInfo;
Expand All @@ -56,6 +57,8 @@
import io.github.muntashirakon.AppManager.utils.ThreadUtils;

public class PackageInstallerService extends ForegroundService {
public static final String TAG = PackageInstallerService.class.getSimpleName();

public static final String EXTRA_QUEUE_ITEM = "queue_item";
public static final String CHANNEL_ID = BuildConfig.APPLICATION_ID + ".channel.INSTALL";

Expand All @@ -66,7 +69,7 @@ void onFinished(String packageName, int status, @Nullable String blockingPackage
}

public PackageInstallerService() {
super("PackageInstallerService");
super(TAG);
}

@Nullable
Expand Down Expand Up @@ -168,25 +171,21 @@ public void onFinishedInstall(int sessionId, String packageName, int result,
installer.installExisting(packageName, options.getUserId());
} else {
// ApkFile/Uri
ApkFile apkFile;
ApkSource apkSource = apkQueueItem.getApkSource();
if (apkSource != null) {
// ApkFile set
try {
apkFile = apkSource.resolve();
} catch (Throwable th) {
// Could not get ApkFile for some reason, abort
th.printStackTrace();
return;
}
} else {
if (apkSource == null) {
// No apk file, abort
return;
}
installer.install(apkFile, selectedSplitIds, options, mProgressHandler);
// Delete the cached file
if (apkSource instanceof CachedApkSource) {
((CachedApkSource) apkSource).cleanup();
try {
ApkFile apkFile = apkSource.resolve();
installer.install(apkFile, selectedSplitIds, options, mProgressHandler);
} catch (Throwable th) {
Log.w(TAG, "Could not get ApkFile", th);
} finally {
// Delete the cached file
if (apkSource instanceof CachedApkSource) {
((CachedApkSource) apkSource).cleanup();
}
}
}
}
Expand Down

0 comments on commit 3b007ce

Please sign in to comment.