Skip to content

Commit

Permalink
[Backup] Include the reason for a failed APK installation during restore
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Dec 5, 2024
1 parent a3e6d25 commit 4a7d3f9
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;

import io.github.muntashirakon.AppManager.apk.ApkFile;
import io.github.muntashirakon.AppManager.apk.installer.InstallerOptions;
Expand Down Expand Up @@ -348,6 +349,7 @@ private void restoreApkFiles() throws BackupException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
options.setInstallScenario(PackageManager.INSTALL_SCENARIO_BULK);
}
AtomicReference<String> status = new AtomicReference<>();
PackageInstallerCompat packageInstaller = PackageInstallerCompat.getNewInstance();
packageInstaller.setOnInstallListener(new PackageInstallerCompat.OnInstallListener() {
@Override
Expand All @@ -363,11 +365,22 @@ public void onAnotherAttemptInMiui(@Nullable ApkFile apkFile) {

@Override
public void onFinishedInstall(int sessionId, String packageName, int result, @Nullable String blockingPackage, @Nullable String statusMessage) {
status.set(statusMessage);
}
});
try {
if (!packageInstaller.install(allApks, mPackageName, options)) {
throw new BackupException("A (re)install was necessary but couldn't perform it.");
String statusMessage;
if (!isVerified) {
// Previously installed app was uninstalled.
statusMessage = "Couldn't perform a re-installation";
} else {
statusMessage = "Couldn't perform an installation";
}
if (status.get() != null) {
statusMessage += ": " + status.get();
} else statusMessage += ".";
throw new BackupException(statusMessage);
}
} finally {
deleteFiles(allApks); // Clean up apk files
Expand Down

0 comments on commit 4a7d3f9

Please sign in to comment.