preference migration

This commit is contained in:
arrase 2016-11-17 22:10:46 +01:00
parent c6054bb256
commit 356d7235b4
1 changed files with 24 additions and 0 deletions

View File

@ -152,6 +152,28 @@ public class OrbotMainActivity extends AppCompatActivity
return super.onCreateView(parent, name, context, attrs); return super.onCreateView(parent, name, context, attrs);
return null; 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. */ /** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -159,6 +181,8 @@ public class OrbotMainActivity extends AppCompatActivity
mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
migratePreferences(); // Migrate old preferences
/* Create the widgets before registering for broadcasts to guarantee /* Create the widgets before registering for broadcasts to guarantee
* that the widgets exist when the status updates try to update them */ * that the widgets exist when the status updates try to update them */
doLayout(); doLayout();