Skip to content
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

Restore from prior backup loses settings after an app is reinstalled #1407

Open
issuex opened this issue Apr 30, 2024 · 3 comments
Open

Restore from prior backup loses settings after an app is reinstalled #1407

issuex opened this issue Apr 30, 2024 · 3 comments

Comments

@issuex
Copy link

issuex commented Apr 30, 2024

In v0.5.5h backup & restore still broken i lost all config after restore, stil not understand why you rely on uid.
i just test the app by

Backup > remove some app and reinstall it > Restore

uid of the app was change, seem like it make restore rule to wrong app, some config lost.

  • domain rule per lost
  • ip rule per app lost
  • firewall rule for this app lost

if you use it in real life, and one day you change mobile, you will know why Backup&Restore so importance.

@ignoramous
Copy link
Collaborator

Thanks, we will take a look.

why you rely on uid.

Rethink doesn't rely on "uid" anymore for restores.

@ignoramous ignoramous changed the title Backup Restore still broken, make it impossible to use in real life. Restore from prior backup loses settings after an app is reinstalled Apr 30, 2024
@issuex
Copy link
Author

issuex commented May 1, 2024

  • why i still see uid link to domain rule and ip rule in backup file.
  • the backup after restore the previous backup, in db file CustomDomain table was gone, CustomIp table was gone.
  • i have some app in work profile , can cause restore fail ? in AppInfo tables packageName not equal to previous backup. after restore, package name no_package_999xxxxx was gone (for example facebook uid is 10755 , facebook in work profile will show as 99910755 ) ( seem like now the app use same config for work profile ? )

@ignoramous
Copy link
Collaborator

why i still see uid link to domain rule and ip rule in backup file.

Those are not prescriptive. If you're technical enough, review:

suspend fun process(a: Action) {
try {
val action = a.action
val uid = a.uid // may be -1
Logger.d(LOG_TAG_APP_DB, "Initiated refresh application info $a")
if (action == ACTION_INSERT_NEW_APP) {
// ignore invalid uid (app source could not be determined)
// ignore missing uid (protocol unknown or connectivity mgr missing)
if (Utilities.isMissingOrInvalidUid(uid)) return
maybeInsertApp(uid)
return
}
val current = SystemClock.elapsedRealtime()
// do not auto-refresh and the last refresh was within AUTO_REFRESH_INTERVAL
if (
latestRefreshTime > 0 &&
current - latestRefreshTime < FULL_REFRESH_INTERVAL &&
(action == ACTION_REFRESH_AUTO || action == ACTION_REFRESH_INTERACTIVE)
) {
Logger.i(LOG_TAG_APP_DB, "no-op auto refresh")
return
}
latestRefreshTime = current
val pm = ctx.packageManager ?: return
val fm = FirewallManager.load()
val ipm = IpRulesManager.load()
val dm = DomainRulesManager.load()
val pxm = ProxyManager.load()
val wgm = WireguardManager.load()
val tcpm = TcpProxyHelper.load()
Logger.i(
LOG_TAG_APP_DB,
"reload: fm: ${fm}; ip: ${ipm}; dom: ${dm}; px: ${pxm}; wg: ${wgm}; t: ${tcpm}"
)
val trackedApps = FirewallManager.getAllApps()
// installedPackages includes apps which are disabled by the user
val installedPackages: List<PackageInfo> =
if (isAtleastT()) {
pm.getInstalledPackages(
PackageManager.PackageInfoFlags.of(PackageManager.GET_META_DATA.toLong())
)
} else {
pm.getInstalledPackages(PackageManager.GET_META_DATA)
}
val installedApps =
installedPackages
.map { FirewallManager.AppInfoTuple(it.applicationInfo.uid, it.packageName) }
.toSet()
val packagesToAdd =
findPackagesToAdd(trackedApps, installedApps, action == ACTION_REFRESH_RESTORE)
val packagesToDelete =
findPackagesToDelete(trackedApps, installedApps, action == ACTION_REFRESH_RESTORE)
val packagesToUpdate =
findPackagesToUpdate(trackedApps, installedApps, action == ACTION_REFRESH_RESTORE)
printAll(packagesToAdd, "packagesToAdd")
printAll(packagesToDelete, "packagesToDelete")
printAll(packagesToUpdate, "packagesToUpdate")
Logger.i(
LOG_TAG_APP_DB,
"sizes: rmv: ${packagesToDelete.size}; add: ${packagesToAdd.size}; update: ${packagesToUpdate.size}"
)
deletePackages(packagesToDelete)
addMissingPackages(packagesToAdd)
updateExistingPackagesIfNeeded(packagesToUpdate) // updated only for restore
removeWireGuardProfilesIfNeeded(action == ACTION_REFRESH_RESTORE)
refreshNonApps(trackedApps, installedApps)
// for proxy mapping, restore is a special case, where we clear all proxy->app mappings
// and so, packagesToUpdate, even if not empty, is ignored. proxy mappings cannot be
// updated during restore.
refreshProxyMapping(trackedApps, action == ACTION_REFRESH_RESTORE)
// must be called after updateExistingPackagesIfNeeded
refreshIPRules(packagesToUpdate)
// must be called after updateExistingPackagesIfNeeded
refreshDomainRules(packagesToUpdate)
} catch (e: RuntimeException) {
Logger.e(LOG_TAG_APP_DB, e.message ?: "refresh err", e)
throw e
} finally {
notifyEmptyFirewallRulesIfNeeded()
a.cb()
}
}

the backup after restore the previous backup, in db file CustomDomain table was gone, CustomIp table was gone.

Sounds like it was a botched migration (this is something we don't control and is implemented by "Room", a library by Google). Does retrying restoring from the same backup work?

have some app in work profile , can cause restore fail ?

May be. We don't test Rethink with Work Profiles, and so, are unaware of what bugs lurk (though, we do encourage bug reports on Rethink + Work Profile): #150

Are the Work Profile apps the only ones that did not restore? If you're comfortable, can you email the backup file to me: mz at celzero dot com (no pressure)?

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

No branches or pull requests

2 participants