[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] preference migration



commit 356d7235b45cf8128378c8bc8414fb87394490be
Author: arrase <arrase@xxxxxxxxx>
Date:   Thu Nov 17 22:10:46 2016 +0100

    preference migration
---
 .../org/torproject/android/OrbotMainActivity.java  | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index f887291..3a98022 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -152,6 +152,28 @@ public class OrbotMainActivity extends AppCompatActivity
           return super.onCreateView(parent, name, context, attrs);
         return null;
     }
+
+	private void migratePreferences(){
+		String hsPortString = mPrefs.getString("pref_hs_ports", "");
+		if(hsPortString.length() > 0)
+		{
+			StringTokenizer st = new StringTokenizer (hsPortString,",");
+			ContentResolver cr = getContentResolver();
+			while (st.hasMoreTokens())
+			{
+				int hsPort = Integer.parseInt(st.nextToken().split(" ")[0]);
+				ContentValues fields = new ContentValues();
+				fields.put("name", hsPort);
+				fields.put("port", hsPort);
+				fields.put("onion_port", hsPort);
+				cr.insert(HSContentProvider.CONTENT_URI, fields);
+			}
+
+			Editor pEdit = mPrefs.edit();
+			pEdit.remove("pref_hs_ports");
+			pEdit.commit();
+		}
+	}
     
     /** Called when the activity is first created. */
     public void onCreate(Bundle savedInstanceState) {
@@ -159,6 +181,8 @@ public class OrbotMainActivity extends AppCompatActivity
 
         mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
 
+		migratePreferences(); // Migrate old preferences
+
         /* Create the widgets before registering for broadcasts to guarantee
          * that the widgets exist when the status updates try to update them */
     	doLayout();



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits