{"record":{"id":"03b9d07fb1c8f5ae","repo":"MuntashirAkon/AppManager","slug":"failed-to-backup-adb-data","errorCode":null,"errorMessage":"Failed to backup ADB data.","messagePattern":"Failed to backup ADB data\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java","lineNumber":391,"sourceCode":"        } catch (Throwable th) {\n            throw new BackupException(\"Failed to backup data directory at \" + dir, th);\n        }\n    }\n\n    @NonNull\n    private Path[] backupAdb(int index) throws BackupException {\n        try {\n            String filePrefix = BackupUtils.getDataFilePrefix(index, \".ab\");\n            Path abFile = mBackupItem.getUnencryptedBackupPath().createNewFile(filePrefix, null);\n            try (OutputStream os = abFile.openOutputStream()) {\n                ParcelFileDescriptor fd = ParcelFileDescriptorUtil.pipeTo(os);\n                BackupCompat.adbBackup(mUserId, fd, false, false, false,\n                        false, false, false, false, true,\n                        new String[]{mPackageName});\n            }\n            return new Path[]{abFile};\n        } catch (Throwable th) {\n            throw new BackupException(\"Failed to backup ADB data.\", th);\n        }\n    }\n\n    private void backupKeyStore() throws BackupException {  // Called only when the app has an keystore item\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {\n            // keystore v2 is not supported.\n            Log.w(TAG, \"Ignoring KeyStore backups for %s\", mPackageName);\n            return;\n        }\n        Path keyStorePath = KeyStoreUtils.getKeyStorePath(mUserId);\n        try {\n            Path masterKeyFile = KeyStoreUtils.getMasterKey(mUserId);\n            // Master key exists, so take its checksum to verify it during the restore\n            mChecksum.add(MASTER_KEY, DigestUtils.getHexDigest(mMetadata.info.checksumAlgo,\n                    masterKeyFile.getContentAsString().getBytes()));\n        } catch (FileNotFoundException ignore) {\n        }\n        // Store the KeyStore files","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java#L373-L409","documentation":"backupAdb() performs an adb-style backup via BackupCompat.adbBackup and wraps any failure in this BackupException. It means the ADB-based backup stream could not be produced or written to the .ab file. The underlying Throwable is attached as cause.","triggerScenarios":"BackupCompat.adbBackup(...) throws (backup agent unavailable, device refuses ADB backup, fd/IO errors) or writing the resulting abFile fails inside backupAdb().","commonSituations":"Target app sets allowBackup=false; Android 12+ deprecating adb backup; device policy blocking backup; user not confirming backup on device.","solutions":["Check the chained cause for adbBackup failure details","Verify the target app allows backup (android:allowBackup) and is not blocked by device policy","Fall back to root-based data backup instead of ADB backup when available","On Android 12+ consider that adb backup is deprecated and may fail for many apps"],"exampleFix":"// before\nPath[] files = backupAdb(index); // throws \"Failed to backup ADB data.\"\n// after\ntry {\n    Path[] files = backupAdb(index);\n} catch (BackupException e) {\n    if (!mBackupFlags.isAdBackup()) throw e; // ADB was optional\n    // surface cause to user or retry with root method\n}","handlingStrategy":"try-catch","validationCode":"ApplicationInfo info = pm.getApplicationInfo(pkg, 0);\nboolean adbAllowed = (info.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0;\nif (mBackupFlags.isAdBackup() && !adbAllowed) throw new IllegalStateException(\"App disallows ADB backup\");","typeGuard":null,"tryCatchPattern":"try {\n    Path[] files = backupAdb(index);\n} catch (BackupException e) {\n    Log.e(TAG, \"adb backup failed\", e.getCause());\n    if (!flagsBackupCacheOnly) rethrow;\n}","preventionTips":["Check android:allowBackup before choosing ADB mode","Remember adb backup is deprecated on Android 12+","Have a root-mode fallback path","Capture the cause for device-side policy hints"],"tags":["backup","adb","android"],"backgroundTag":"api-request-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}