Stabilize Android VPN upgrade restart
This commit is contained in:
@@ -30,8 +30,8 @@ android {
|
||||
applicationId "su.cin.rapvpn"
|
||||
minSdk 26
|
||||
targetSdk 35
|
||||
versionCode 205
|
||||
versionName "0.2.205"
|
||||
versionCode 206
|
||||
versionName "0.2.206"
|
||||
buildConfigField "String", "DEFAULT_BACKEND_URL", "\"${normalizeGradleString(defaultBackendUrl)}\""
|
||||
buildConfigField "String", "DEFAULT_CLUSTER_ID", "\"${normalizeGradleString(defaultClusterId)}\""
|
||||
buildConfigField "String", "DEFAULT_ORGANIZATION_ID", "\"${normalizeGradleString(defaultOrganizationId)}\""
|
||||
|
||||
@@ -30,6 +30,11 @@ public final class RapAutostartReceiver extends BroadcastReceiver {
|
||||
if (prefs.getBoolean(PREF_MANUAL_STOPPED, false)) {
|
||||
return;
|
||||
}
|
||||
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
|
||||
// Diagnostic service owns post-upgrade VPN restart. Starting both services from
|
||||
// MY_PACKAGE_REPLACED can race foreground-service startup and leave diagnostics stale.
|
||||
return;
|
||||
}
|
||||
String profile = prefs.getString(PREF_PROFILE_JSON, "");
|
||||
String backendUrl = prefs.getString(PREF_BACKEND_URL, "");
|
||||
String clusterId = prefs.getString(PREF_CLUSTER_ID, "");
|
||||
|
||||
@@ -247,6 +247,7 @@ public class RapDiagnosticService extends Service {
|
||||
Thread.sleep(3000);
|
||||
continue;
|
||||
}
|
||||
recoverSavedUserId(prefs);
|
||||
releaseStaleBackgroundOperations(System.currentTimeMillis());
|
||||
lastHeartbeatAt = System.currentTimeMillis();
|
||||
serviceState = "online " + new SimpleDateFormat("HH:mm:ss").format(new Date());
|
||||
@@ -775,6 +776,7 @@ public class RapDiagnosticService extends Service {
|
||||
if (APP_VERSION.equals(lastVersion)) {
|
||||
return;
|
||||
}
|
||||
recoverSavedUserId(prefs);
|
||||
String connectionId = prefs.getString(PREF_VPN_CONNECTION_ID, "");
|
||||
String profileJson = prefs.getString(PREF_PROFILE_JSON, "");
|
||||
if (connectionId.isEmpty() || profileJson.isEmpty()) {
|
||||
@@ -804,6 +806,17 @@ public class RapDiagnosticService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void recoverSavedUserId(SharedPreferences prefs) {
|
||||
if (prefs == null || !prefs.getString(PREF_USER_ID, "").trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String savedUserId = savedUserIdForProfileRefresh(prefs);
|
||||
if (savedUserId == null || savedUserId.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
prefs.edit().putString(PREF_USER_ID, savedUserId.trim()).apply();
|
||||
}
|
||||
|
||||
private String refreshProfile() {
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user