summaryrefslogtreecommitdiff
path: root/main/src/ui/java/de
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2025-02-05 21:59:12 +0100
committerArne Schwabe <arne@rfc2549.org>2025-02-05 21:59:12 +0100
commit5d9c0007bae92d3c5065cf11335eb3eab732e6f7 (patch)
tree326a39c1a414f8b47061b3c781d5d7aca841be7c /main/src/ui/java/de
parentb292f11d47f8779eefbe8538450fbd5ea8a06946 (diff)
Ensure that profiles update are notified/synced to the other process
Diffstat (limited to 'main/src/ui/java/de')
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/activities/VPNPreferences.kt21
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java8
2 files changed, 23 insertions, 6 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/VPNPreferences.kt b/main/src/ui/java/de/blinkt/openvpn/activities/VPNPreferences.kt
index 0dd61748..a60c7567 100644
--- a/main/src/ui/java/de/blinkt/openvpn/activities/VPNPreferences.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/activities/VPNPreferences.kt
@@ -20,6 +20,7 @@ import com.google.android.material.tabs.TabLayoutMediator
import de.blinkt.openvpn.R
import de.blinkt.openvpn.VpnProfile
import de.blinkt.openvpn.core.ProfileManager
+import de.blinkt.openvpn.core.VpnStatus
import de.blinkt.openvpn.fragments.Settings_Allowed_Apps
import de.blinkt.openvpn.fragments.Settings_Authentication
import de.blinkt.openvpn.fragments.Settings_Basic
@@ -32,7 +33,7 @@ import de.blinkt.openvpn.fragments.ShowConfigFragment
import de.blinkt.openvpn.fragments.VPNProfileList
import de.blinkt.openvpn.views.ScreenSlidePagerAdapter
-class VPNPreferences : BaseActivity() {
+class VPNPreferences : BaseActivity(), VpnStatus.ProfileNotifyListener {
private var mProfileUUID: String? = null
private var mProfile: VpnProfile? = null
private lateinit var mPager: ViewPager2
@@ -55,7 +56,6 @@ class VPNPreferences : BaseActivity() {
override fun onResume() {
super.onResume()
- profile
// When a profile is deleted from a category fragment in hadset mod we need to finish
// this activity as well when returning
if (mProfile == null || mProfile!!.profileDeleted) {
@@ -100,6 +100,7 @@ class VPNPreferences : BaseActivity() {
finish()
return
}
+ VpnStatus.addProfileStateListener(this);
title = getString(R.string.edit_profile_title, mProfile!!.name)
@@ -208,4 +209,20 @@ class VPNPreferences : BaseActivity() {
Settings_Allowed_Apps::class.java,
)
}
+
+ override fun notifyProfileVersionChanged(
+ uuid: String?,
+ version: Int,
+ changedInThisProcess: Boolean
+ ) {
+ if (mProfile?.uuidString != uuid)
+ return;
+
+ if ((mProfile?.mVersion?: 0) < version)
+ {
+ /* Profile has changed outside of our process. Most likely from the AIDL service. */
+ Toast.makeText(this, R.string.editor_close_profile_changed, Toast.LENGTH_LONG).show();
+ finish();
+ }
+ }
}
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
index c85fe26e..d60051d3 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/VPNProfileList.java
@@ -22,7 +22,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
-import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
@@ -78,7 +77,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
// Shortcut version is increased to refresh all shortcuts
final static int SHORTCUT_VERSION = 1;
private static final int MENU_ADD_PROFILE = Menu.FIRST;
- private static final int START_VPN_CONFIG = 92;
+ private static final int EDIT_VPN_CONFIG = 92;
private static final int SELECT_PROFILE = 43;
private static final int IMPORT_PROFILE = 231;
private static final int FILE_PICKER_RESULT_KITKAT = 392;
@@ -520,10 +519,11 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
if (resultCode != Activity.RESULT_OK)
return;
- if (requestCode == START_VPN_CONFIG) {
+ if (requestCode == EDIT_VPN_CONFIG) {
String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID);
VpnProfile profile = ProfileManager.get(getActivity(), configuredVPN);
+ profile.addChangeLogEntry("Profile edited by user");
getPM().saveProfile(getActivity(), profile);
// Name could be modified, reset List adapter
setListAdapter();
@@ -557,7 +557,7 @@ public class VPNProfileList extends ListFragment implements OnClickListener, Vpn
Intent vprefintent = new Intent(getActivity(), VPNPreferences.class)
.putExtra(getActivity().getPackageName() + ".profileUUID", profile.getUUID().toString());
- startActivityForResult(vprefintent, START_VPN_CONFIG);
+ startActivityForResult(vprefintent, EDIT_VPN_CONFIG);
}
private void startVPN(VpnProfile profile) {