|
|
@ -41,6 +41,7 @@ import android.text.TextUtils;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
@ -114,6 +115,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
|
|
|
|
|
|
|
|
private boolean hasAccount;
|
|
|
|
private boolean hasAccount;
|
|
|
|
private String password;
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
private boolean import_accounts;
|
|
|
|
|
|
|
|
private boolean import_answers;
|
|
|
|
|
|
|
|
private boolean import_settings;
|
|
|
|
|
|
|
|
|
|
|
|
private static final int KEY_ITERATIONS = 65536;
|
|
|
|
private static final int KEY_ITERATIONS = 65536;
|
|
|
|
private static final int KEY_LENGTH = 256;
|
|
|
|
private static final int KEY_LENGTH = 256;
|
|
|
@ -309,6 +313,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("fair:toggle"));
|
|
|
|
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("fair:toggle"));
|
|
|
|
password = savedInstanceState.getString("fair:password");
|
|
|
|
password = savedInstanceState.getString("fair:password");
|
|
|
|
|
|
|
|
import_accounts = savedInstanceState.getBoolean("fair:import_accounts");
|
|
|
|
|
|
|
|
import_answers = savedInstanceState.getBoolean("fair:import_answers");
|
|
|
|
|
|
|
|
import_settings = savedInstanceState.getBoolean("fair:import_settings");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(this);
|
|
|
|
DB db = DB.getInstance(this);
|
|
|
@ -325,6 +332,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
outState.putBoolean("fair:toggle", drawerToggle.isDrawerIndicatorEnabled());
|
|
|
|
outState.putBoolean("fair:toggle", drawerToggle.isDrawerIndicatorEnabled());
|
|
|
|
outState.putString("fair:password", password);
|
|
|
|
outState.putString("fair:password", password);
|
|
|
|
|
|
|
|
outState.putBoolean("fair:import_accounts", import_accounts);
|
|
|
|
|
|
|
|
outState.putBoolean("fair:import_answers", import_answers);
|
|
|
|
|
|
|
|
outState.putBoolean("fair:import_settings", import_settings);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -415,11 +425,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
switch (requestCode) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_EXPORT:
|
|
|
|
case REQUEST_EXPORT:
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
handleExport(data, this.password);
|
|
|
|
handleExport(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REQUEST_IMPORT:
|
|
|
|
case REQUEST_IMPORT:
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
handleImport(data, this.password);
|
|
|
|
handleImport(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REQUEST_IMPORT_CERTIFICATE:
|
|
|
|
case REQUEST_IMPORT_CERTIFICATE:
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
@ -538,10 +548,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void handleExport(Intent data, String password) {
|
|
|
|
private void handleExport(Intent data) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putString("password", password);
|
|
|
|
args.putString("password", this.password);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -730,10 +740,13 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
}.execute(this, args, "setup:export");
|
|
|
|
}.execute(this, args, "setup:export");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void handleImport(Intent data, String password) {
|
|
|
|
private void handleImport(Intent data) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putString("password", password);
|
|
|
|
args.putString("password", this.password);
|
|
|
|
|
|
|
|
args.putBoolean("import_accounts", this.import_accounts);
|
|
|
|
|
|
|
|
args.putBoolean("import_answers", this.import_answers);
|
|
|
|
|
|
|
|
args.putBoolean("import_settings", this.import_settings);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -745,6 +758,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
Uri uri = args.getParcelable("uri");
|
|
|
|
Uri uri = args.getParcelable("uri");
|
|
|
|
String password = args.getString("password");
|
|
|
|
String password = args.getString("password");
|
|
|
|
|
|
|
|
boolean import_accounts = args.getBoolean("import_accounts");
|
|
|
|
|
|
|
|
boolean import_answers = args.getBoolean("import_answers");
|
|
|
|
|
|
|
|
boolean import_settings = args.getBoolean("import_settings");
|
|
|
|
|
|
|
|
|
|
|
|
if (!"content".equals(uri.getScheme()) &&
|
|
|
|
if (!"content".equals(uri.getScheme()) &&
|
|
|
|
!Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
|
|
!Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
|
@ -801,286 +817,295 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
Map<Long, Long> xFolder = new HashMap<>();
|
|
|
|
Map<Long, Long> xFolder = new HashMap<>();
|
|
|
|
List<EntityRule> rules = new ArrayList<>();
|
|
|
|
List<EntityRule> rules = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
// Answers
|
|
|
|
if (import_answers) {
|
|
|
|
JSONArray janswers = jimport.getJSONArray("answers");
|
|
|
|
// Answers
|
|
|
|
for (int a = 0; a < janswers.length(); a++) {
|
|
|
|
JSONArray janswers = jimport.getJSONArray("answers");
|
|
|
|
JSONObject janswer = (JSONObject) janswers.get(a);
|
|
|
|
for (int a = 0; a < janswers.length(); a++) {
|
|
|
|
EntityAnswer answer = EntityAnswer.fromJSON(janswer);
|
|
|
|
JSONObject janswer = (JSONObject) janswers.get(a);
|
|
|
|
long id = answer.id;
|
|
|
|
EntityAnswer answer = EntityAnswer.fromJSON(janswer);
|
|
|
|
answer.id = null;
|
|
|
|
long id = answer.id;
|
|
|
|
|
|
|
|
answer.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
answer.id = db.answer().insertAnswer(answer);
|
|
|
|
answer.id = db.answer().insertAnswer(answer);
|
|
|
|
xAnswer.put(id, answer.id);
|
|
|
|
xAnswer.put(id, answer.id);
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported answer=" + answer.name + " id=" + answer.id + " (" + id + ")");
|
|
|
|
Log.i("Imported answer=" + answer.name + " id=" + answer.id + " (" + id + ")");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EntityAccount primary = db.account().getPrimaryAccount();
|
|
|
|
if (import_accounts) {
|
|
|
|
|
|
|
|
EntityAccount primary = db.account().getPrimaryAccount();
|
|
|
|
|
|
|
|
|
|
|
|
// Accounts
|
|
|
|
// Accounts
|
|
|
|
JSONArray jaccounts = jimport.getJSONArray("accounts");
|
|
|
|
JSONArray jaccounts = jimport.getJSONArray("accounts");
|
|
|
|
for (int a = 0; a < jaccounts.length(); a++) {
|
|
|
|
for (int a = 0; a < jaccounts.length(); a++) {
|
|
|
|
JSONObject jaccount = (JSONObject) jaccounts.get(a);
|
|
|
|
JSONObject jaccount = (JSONObject) jaccounts.get(a);
|
|
|
|
EntityAccount account = EntityAccount.fromJSON(jaccount);
|
|
|
|
EntityAccount account = EntityAccount.fromJSON(jaccount);
|
|
|
|
|
|
|
|
|
|
|
|
if (account.auth_type == AUTH_TYPE_GMAIL) {
|
|
|
|
if (account.auth_type == AUTH_TYPE_GMAIL) {
|
|
|
|
if (GmailState.getAccount(context, account.user) == null) {
|
|
|
|
if (GmailState.getAccount(context, account.user) == null) {
|
|
|
|
Log.i("Google account not found user=" + account.user);
|
|
|
|
Log.i("Google account not found user=" + account.user);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Long aid = account.id;
|
|
|
|
|
|
|
|
account.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (primary != null)
|
|
|
|
|
|
|
|
account.primary = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forward referenced
|
|
|
|
|
|
|
|
Long swipe_left = account.swipe_left;
|
|
|
|
|
|
|
|
Long swipe_right = account.swipe_right;
|
|
|
|
|
|
|
|
Long move_to = account.move_to;
|
|
|
|
|
|
|
|
if (account.swipe_left != null && account.swipe_left > 0)
|
|
|
|
|
|
|
|
account.swipe_left = null;
|
|
|
|
|
|
|
|
if (account.swipe_right != null && account.swipe_right > 0)
|
|
|
|
|
|
|
|
account.swipe_right = null;
|
|
|
|
|
|
|
|
account.move_to = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
account.created = new Date().getTime();
|
|
|
|
|
|
|
|
account.id = db.account().insertAccount(account);
|
|
|
|
|
|
|
|
Log.i("Imported account=" + account.name + " id=" + account.id + " (" + aid + ")");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
Long aid = account.id;
|
|
|
|
account.deleteNotificationChannel(context);
|
|
|
|
account.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (account.notify)
|
|
|
|
if (primary != null)
|
|
|
|
if (jaccount.has("channel")) {
|
|
|
|
account.primary = false;
|
|
|
|
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
|
|
|
|
|
|
|
|
nm.createNotificationChannelGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jchannel = (JSONObject) jaccount.get("channel");
|
|
|
|
// Forward referenced
|
|
|
|
jchannel.put("id", EntityAccount.getNotificationChannelId(account.id));
|
|
|
|
Long swipe_left = account.swipe_left;
|
|
|
|
jchannel.put("group", group.getId());
|
|
|
|
Long swipe_right = account.swipe_right;
|
|
|
|
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
|
|
|
Long move_to = account.move_to;
|
|
|
|
|
|
|
|
if (account.swipe_left != null && account.swipe_left > 0)
|
|
|
|
|
|
|
|
account.swipe_left = null;
|
|
|
|
|
|
|
|
if (account.swipe_right != null && account.swipe_right > 0)
|
|
|
|
|
|
|
|
account.swipe_right = null;
|
|
|
|
|
|
|
|
account.move_to = null;
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported account channel=" + jchannel);
|
|
|
|
account.created = new Date().getTime();
|
|
|
|
} else
|
|
|
|
account.id = db.account().insertAccount(account);
|
|
|
|
account.createNotificationChannel(context);
|
|
|
|
Log.i("Imported account=" + account.name + " id=" + account.id + " (" + aid + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray jidentities = (JSONArray) jaccount.get("identities");
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
for (int i = 0; i < jidentities.length(); i++) {
|
|
|
|
account.deleteNotificationChannel(context);
|
|
|
|
JSONObject jidentity = (JSONObject) jidentities.get(i);
|
|
|
|
|
|
|
|
EntityIdentity identity = EntityIdentity.fromJSON(jidentity);
|
|
|
|
|
|
|
|
long id = identity.id;
|
|
|
|
|
|
|
|
identity.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
identity.account = account.id;
|
|
|
|
if (account.notify)
|
|
|
|
identity.id = db.identity().insertIdentity(identity);
|
|
|
|
if (jaccount.has("channel")) {
|
|
|
|
xIdentity.put(id, identity.id);
|
|
|
|
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
|
|
|
|
|
|
|
|
nm.createNotificationChannelGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported identity=" + identity.email + " id=" + identity + id + " (" + id + ")");
|
|
|
|
JSONObject jchannel = (JSONObject) jaccount.get("channel");
|
|
|
|
}
|
|
|
|
jchannel.put("id", EntityAccount.getNotificationChannelId(account.id));
|
|
|
|
|
|
|
|
jchannel.put("group", group.getId());
|
|
|
|
|
|
|
|
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray jfolders = (JSONArray) jaccount.get("folders");
|
|
|
|
Log.i("Imported account channel=" + jchannel);
|
|
|
|
for (int f = 0; f < jfolders.length(); f++) {
|
|
|
|
} else
|
|
|
|
JSONObject jfolder = (JSONObject) jfolders.get(f);
|
|
|
|
account.createNotificationChannel(context);
|
|
|
|
EntityFolder folder = EntityFolder.fromJSON(jfolder);
|
|
|
|
}
|
|
|
|
long id = folder.id;
|
|
|
|
|
|
|
|
folder.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
folder.account = account.id;
|
|
|
|
JSONArray jidentities = (JSONArray) jaccount.get("identities");
|
|
|
|
folder.id = db.folder().insertFolder(folder);
|
|
|
|
for (int i = 0; i < jidentities.length(); i++) {
|
|
|
|
xFolder.put(id, folder.id);
|
|
|
|
JSONObject jidentity = (JSONObject) jidentities.get(i);
|
|
|
|
|
|
|
|
EntityIdentity identity = EntityIdentity.fromJSON(jidentity);
|
|
|
|
|
|
|
|
long id = identity.id;
|
|
|
|
|
|
|
|
identity.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(swipe_left, id))
|
|
|
|
identity.account = account.id;
|
|
|
|
account.swipe_left = folder.id;
|
|
|
|
identity.id = db.identity().insertIdentity(identity);
|
|
|
|
if (Objects.equals(swipe_right, id))
|
|
|
|
xIdentity.put(id, identity.id);
|
|
|
|
account.swipe_right = folder.id;
|
|
|
|
|
|
|
|
if (Objects.equals(move_to, id))
|
|
|
|
|
|
|
|
account.move_to = folder.id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
Log.i("Imported identity=" + identity.email + " id=" + identity + id + " (" + id + ")");
|
|
|
|
String channelId = EntityFolder.getNotificationChannelId(folder.id);
|
|
|
|
}
|
|
|
|
nm.deleteNotificationChannel(channelId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (jfolder.has("channel")) {
|
|
|
|
|
|
|
|
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
|
|
|
|
|
|
|
|
nm.createNotificationChannelGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jchannel = (JSONObject) jfolder.get("channel");
|
|
|
|
JSONArray jfolders = (JSONArray) jaccount.get("folders");
|
|
|
|
jchannel.put("id", channelId);
|
|
|
|
for (int f = 0; f < jfolders.length(); f++) {
|
|
|
|
jchannel.put("group", group.getId());
|
|
|
|
JSONObject jfolder = (JSONObject) jfolders.get(f);
|
|
|
|
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
|
|
|
EntityFolder folder = EntityFolder.fromJSON(jfolder);
|
|
|
|
|
|
|
|
long id = folder.id;
|
|
|
|
|
|
|
|
folder.id = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
folder.account = account.id;
|
|
|
|
|
|
|
|
folder.id = db.folder().insertFolder(folder);
|
|
|
|
|
|
|
|
xFolder.put(id, folder.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(swipe_left, id))
|
|
|
|
|
|
|
|
account.swipe_left = folder.id;
|
|
|
|
|
|
|
|
if (Objects.equals(swipe_right, id))
|
|
|
|
|
|
|
|
account.swipe_right = folder.id;
|
|
|
|
|
|
|
|
if (Objects.equals(move_to, id))
|
|
|
|
|
|
|
|
account.move_to = folder.id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
|
|
|
String channelId = EntityFolder.getNotificationChannelId(folder.id);
|
|
|
|
|
|
|
|
nm.deleteNotificationChannel(channelId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (jfolder.has("channel")) {
|
|
|
|
|
|
|
|
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
|
|
|
|
|
|
|
|
nm.createNotificationChannelGroup(group);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jchannel = (JSONObject) jfolder.get("channel");
|
|
|
|
|
|
|
|
jchannel.put("id", channelId);
|
|
|
|
|
|
|
|
jchannel.put("group", group.getId());
|
|
|
|
|
|
|
|
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported folder channel=" + jchannel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported folder channel=" + jchannel);
|
|
|
|
if (jfolder.has("rules")) {
|
|
|
|
|
|
|
|
JSONArray jrules = jfolder.getJSONArray("rules");
|
|
|
|
|
|
|
|
for (int r = 0; r < jrules.length(); r++) {
|
|
|
|
|
|
|
|
JSONObject jrule = (JSONObject) jrules.get(r);
|
|
|
|
|
|
|
|
EntityRule rule = EntityRule.fromJSON(jrule);
|
|
|
|
|
|
|
|
rule.folder = folder.id;
|
|
|
|
|
|
|
|
rules.add(rule);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.i("Imported folder=" + folder.name + " id=" + folder.id + " (" + id + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (jfolder.has("rules")) {
|
|
|
|
// Contacts
|
|
|
|
JSONArray jrules = jfolder.getJSONArray("rules");
|
|
|
|
if (jaccount.has("contacts")) {
|
|
|
|
for (int r = 0; r < jrules.length(); r++) {
|
|
|
|
JSONArray jcontacts = jaccount.getJSONArray("contacts");
|
|
|
|
JSONObject jrule = (JSONObject) jrules.get(r);
|
|
|
|
for (int c = 0; c < jcontacts.length(); c++) {
|
|
|
|
EntityRule rule = EntityRule.fromJSON(jrule);
|
|
|
|
JSONObject jcontact = (JSONObject) jcontacts.get(c);
|
|
|
|
rule.folder = folder.id;
|
|
|
|
EntityContact contact = EntityContact.fromJSON(jcontact);
|
|
|
|
rules.add(rule);
|
|
|
|
contact.account = account.id;
|
|
|
|
|
|
|
|
if (db.contact().getContact(contact.account, contact.type, contact.email) == null)
|
|
|
|
|
|
|
|
contact.id = db.contact().insertContact(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.i("Imported contacts=" + jcontacts.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.i("Imported folder=" + folder.name + " id=" + folder.id + " (" + id + ")");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Contacts
|
|
|
|
// Update swipe left/right
|
|
|
|
if (jaccount.has("contacts")) {
|
|
|
|
db.account().updateAccount(account);
|
|
|
|
JSONArray jcontacts = jaccount.getJSONArray("contacts");
|
|
|
|
|
|
|
|
for (int c = 0; c < jcontacts.length(); c++) {
|
|
|
|
|
|
|
|
JSONObject jcontact = (JSONObject) jcontacts.get(c);
|
|
|
|
|
|
|
|
EntityContact contact = EntityContact.fromJSON(jcontact);
|
|
|
|
|
|
|
|
contact.account = account.id;
|
|
|
|
|
|
|
|
if (db.contact().getContact(contact.account, contact.type, contact.email) == null)
|
|
|
|
|
|
|
|
contact.id = db.contact().insertContact(contact);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.i("Imported contacts=" + jcontacts.length());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update swipe left/right
|
|
|
|
for (EntityRule rule : rules) {
|
|
|
|
db.account().updateAccount(account);
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
JSONObject jaction = new JSONObject(rule.action);
|
|
|
|
|
|
|
|
|
|
|
|
for (EntityRule rule : rules) {
|
|
|
|
int type = jaction.getInt("type");
|
|
|
|
try {
|
|
|
|
switch (type) {
|
|
|
|
JSONObject jaction = new JSONObject(rule.action);
|
|
|
|
case EntityRule.TYPE_MOVE:
|
|
|
|
|
|
|
|
case EntityRule.TYPE_COPY:
|
|
|
|
|
|
|
|
long target = jaction.getLong("target");
|
|
|
|
|
|
|
|
Log.i("XLAT target " + target + " > " + xFolder.get(target));
|
|
|
|
|
|
|
|
jaction.put("target", xFolder.get(target));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EntityRule.TYPE_ANSWER:
|
|
|
|
|
|
|
|
long identity = jaction.getLong("identity");
|
|
|
|
|
|
|
|
long answer = jaction.getLong("answer");
|
|
|
|
|
|
|
|
Log.i("XLAT identity " + identity + " > " + xIdentity.get(identity));
|
|
|
|
|
|
|
|
Log.i("XLAT answer " + answer + " > " + xAnswer.get(answer));
|
|
|
|
|
|
|
|
jaction.put("identity", xIdentity.get(identity));
|
|
|
|
|
|
|
|
jaction.put("answer", xAnswer.get(answer));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int type = jaction.getInt("type");
|
|
|
|
rule.action = jaction.toString();
|
|
|
|
switch (type) {
|
|
|
|
} catch (JSONException ex) {
|
|
|
|
case EntityRule.TYPE_MOVE:
|
|
|
|
Log.e(ex);
|
|
|
|
case EntityRule.TYPE_COPY:
|
|
|
|
|
|
|
|
long target = jaction.getLong("target");
|
|
|
|
|
|
|
|
Log.i("XLAT target " + target + " > " + xFolder.get(target));
|
|
|
|
|
|
|
|
jaction.put("target", xFolder.get(target));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EntityRule.TYPE_ANSWER:
|
|
|
|
|
|
|
|
long identity = jaction.getLong("identity");
|
|
|
|
|
|
|
|
long answer = jaction.getLong("answer");
|
|
|
|
|
|
|
|
Log.i("XLAT identity " + identity + " > " + xIdentity.get(identity));
|
|
|
|
|
|
|
|
Log.i("XLAT answer " + answer + " > " + xAnswer.get(answer));
|
|
|
|
|
|
|
|
jaction.put("identity", xIdentity.get(identity));
|
|
|
|
|
|
|
|
jaction.put("answer", xAnswer.get(answer));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rule.action = jaction.toString();
|
|
|
|
db.rule().insertRule(rule);
|
|
|
|
} catch (JSONException ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.rule().insertRule(rule);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (jimport.has("certificates")) {
|
|
|
|
if (import_settings) {
|
|
|
|
JSONArray jcertificates = jimport.getJSONArray("certificates");
|
|
|
|
// Certificates
|
|
|
|
for (int c = 0; c < jcertificates.length(); c++) {
|
|
|
|
if (jimport.has("certificates")) {
|
|
|
|
JSONObject jcertificate = (JSONObject) jcertificates.get(c);
|
|
|
|
JSONArray jcertificates = jimport.getJSONArray("certificates");
|
|
|
|
EntityCertificate certificate = EntityCertificate.fromJSON(jcertificate);
|
|
|
|
for (int c = 0; c < jcertificates.length(); c++) {
|
|
|
|
EntityCertificate record = db.certificate().getCertificate(certificate.fingerprint, certificate.email);
|
|
|
|
JSONObject jcertificate = (JSONObject) jcertificates.get(c);
|
|
|
|
if (record == null) {
|
|
|
|
EntityCertificate certificate = EntityCertificate.fromJSON(jcertificate);
|
|
|
|
db.certificate().insertCertificate(certificate);
|
|
|
|
EntityCertificate record = db.certificate().getCertificate(certificate.fingerprint, certificate.email);
|
|
|
|
Log.i("Imported certificate=" + certificate.email);
|
|
|
|
if (record == null) {
|
|
|
|
|
|
|
|
db.certificate().insertCertificate(certificate);
|
|
|
|
|
|
|
|
Log.i("Imported certificate=" + certificate.email);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
// Settings
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
JSONArray jsettings = jimport.getJSONArray("settings");
|
|
|
|
JSONArray jsettings = jimport.getJSONArray("settings");
|
|
|
|
for (int s = 0; s < jsettings.length(); s++) {
|
|
|
|
for (int s = 0; s < jsettings.length(); s++) {
|
|
|
|
JSONObject jsetting = (JSONObject) jsettings.get(s);
|
|
|
|
JSONObject jsetting = (JSONObject) jsettings.get(s);
|
|
|
|
String key = jsetting.getString("key");
|
|
|
|
String key = jsetting.getString("key");
|
|
|
|
|
|
|
|
|
|
|
|
if ("pro".equals(key) && !BuildConfig.DEBUG)
|
|
|
|
if ("pro".equals(key) && !BuildConfig.DEBUG)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if ("biometrics".equals(key) || "pin".equals(key))
|
|
|
|
if ("biometrics".equals(key) || "pin".equals(key))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if ("alert_once".equals(key) && !Helper.isXiaomi())
|
|
|
|
if ("alert_once".equals(key) && !Helper.isXiaomi())
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if ("background_service".equals(key) &&
|
|
|
|
if ("background_service".equals(key) &&
|
|
|
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Prevent restart
|
|
|
|
// Prevent restart
|
|
|
|
if ("secure".equals(key) ||
|
|
|
|
if ("secure".equals(key) ||
|
|
|
|
"shortcuts".equals(key) ||
|
|
|
|
"shortcuts".equals(key) ||
|
|
|
|
"language".equals(key) ||
|
|
|
|
"language".equals(key) ||
|
|
|
|
"query_threads".equals(key) ||
|
|
|
|
"query_threads".equals(key) ||
|
|
|
|
"wal".equals(key))
|
|
|
|
"wal".equals(key))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (key != null && key.startsWith("widget."))
|
|
|
|
if (key != null && key.startsWith("widget."))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if ("external_search".equals(key)) {
|
|
|
|
if ("external_search".equals(key)) {
|
|
|
|
boolean external_search = jsetting.getBoolean("value");
|
|
|
|
boolean external_search = jsetting.getBoolean("value");
|
|
|
|
Helper.enableComponent(context, ActivitySearch.class, external_search);
|
|
|
|
Helper.enableComponent(context, ActivitySearch.class, external_search);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object value = jsetting.get("value");
|
|
|
|
Object value = jsetting.get("value");
|
|
|
|
String type = jsetting.optString("type");
|
|
|
|
String type = jsetting.optString("type");
|
|
|
|
Log.i("Setting name=" + key + " value=" + value + " type=" + type);
|
|
|
|
Log.i("Setting name=" + key + " value=" + value + " type=" + type);
|
|
|
|
switch (type) {
|
|
|
|
switch (type) {
|
|
|
|
case "bool":
|
|
|
|
case "bool":
|
|
|
|
editor.putBoolean(key, (Boolean) value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "int":
|
|
|
|
|
|
|
|
editor.putInt(key, (Integer) value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "long":
|
|
|
|
|
|
|
|
if (value instanceof Integer)
|
|
|
|
|
|
|
|
editor.putLong(key, Long.valueOf((Integer) value));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
editor.putLong(key, (Long) value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "string":
|
|
|
|
|
|
|
|
editor.putString(key, (String) value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
Log.w("Inferring type of value=" + value);
|
|
|
|
|
|
|
|
if (value instanceof Boolean)
|
|
|
|
|
|
|
|
editor.putBoolean(key, (Boolean) value);
|
|
|
|
editor.putBoolean(key, (Boolean) value);
|
|
|
|
else if (value instanceof Integer) {
|
|
|
|
break;
|
|
|
|
Integer i = (Integer) value;
|
|
|
|
case "int":
|
|
|
|
if (key.endsWith(".account"))
|
|
|
|
editor.putInt(key, (Integer) value);
|
|
|
|
editor.putLong(key, Long.valueOf(i));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "long":
|
|
|
|
|
|
|
|
if (value instanceof Integer)
|
|
|
|
|
|
|
|
editor.putLong(key, Long.valueOf((Integer) value));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
editor.putInt(key, i);
|
|
|
|
editor.putLong(key, (Long) value);
|
|
|
|
} else if (value instanceof Long)
|
|
|
|
break;
|
|
|
|
editor.putLong(key, (Long) value);
|
|
|
|
case "string":
|
|
|
|
else if (value instanceof String)
|
|
|
|
|
|
|
|
editor.putString(key, (String) value);
|
|
|
|
editor.putString(key, (String) value);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
throw new IllegalArgumentException("Unknown settings type key=" + key);
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
Log.w("Inferring type of value=" + value);
|
|
|
|
|
|
|
|
if (value instanceof Boolean)
|
|
|
|
|
|
|
|
editor.putBoolean(key, (Boolean) value);
|
|
|
|
|
|
|
|
else if (value instanceof Integer) {
|
|
|
|
|
|
|
|
Integer i = (Integer) value;
|
|
|
|
|
|
|
|
if (key.endsWith(".account"))
|
|
|
|
|
|
|
|
editor.putLong(key, Long.valueOf(i));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
editor.putInt(key, i);
|
|
|
|
|
|
|
|
} else if (value instanceof Long)
|
|
|
|
|
|
|
|
editor.putLong(key, (Long) value);
|
|
|
|
|
|
|
|
else if (value instanceof String)
|
|
|
|
|
|
|
|
editor.putString(key, (String) value);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("Unknown settings type key=" + key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported setting=" + key);
|
|
|
|
Log.i("Imported setting=" + key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
editor.apply();
|
|
|
|
|
|
|
|
ApplicationEx.upgrade(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.apply();
|
|
|
|
|
|
|
|
ApplicationEx.upgrade(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
if (import_accounts) {
|
|
|
|
if (jimport.has("channels")) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
JSONArray jchannels = jimport.getJSONArray("channels");
|
|
|
|
if (jimport.has("channels")) {
|
|
|
|
for (int i = 0; i < jchannels.length(); i++) {
|
|
|
|
JSONArray jchannels = jimport.getJSONArray("channels");
|
|
|
|
JSONObject jchannel = (JSONObject) jchannels.get(i);
|
|
|
|
for (int i = 0; i < jchannels.length(); i++) {
|
|
|
|
|
|
|
|
JSONObject jchannel = (JSONObject) jchannels.get(i);
|
|
|
|
|
|
|
|
|
|
|
|
String channelId = jchannel.getString("id");
|
|
|
|
String channelId = jchannel.getString("id");
|
|
|
|
nm.deleteNotificationChannel(channelId);
|
|
|
|
nm.deleteNotificationChannel(channelId);
|
|
|
|
|
|
|
|
|
|
|
|
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
|
|
|
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported contact channel=" + jchannel);
|
|
|
|
Log.i("Imported contact channel=" + jchannel);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1376,6 +1401,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
Context context = getContext();
|
|
|
|
Context context = getContext();
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_import, null);
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_import, null);
|
|
|
|
etPassword1 = dview.findViewById(R.id.tilPassword1);
|
|
|
|
etPassword1 = dview.findViewById(R.id.tilPassword1);
|
|
|
|
|
|
|
|
CheckBox cbAccounts = dview.findViewById(R.id.cbAccounts);
|
|
|
|
|
|
|
|
CheckBox cbAnswers = dview.findViewById(R.id.cbAnswers);
|
|
|
|
|
|
|
|
CheckBox cbSettings = dview.findViewById(R.id.cbSettings);
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
etPassword1.getEditText().setText(savedInstanceState.getString("fair:password1"));
|
|
|
|
etPassword1.getEditText().setText(savedInstanceState.getString("fair:password1"));
|
|
|
@ -1390,7 +1418,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
if (TextUtils.isEmpty(password1) && !BuildConfig.DEBUG)
|
|
|
|
if (TextUtils.isEmpty(password1) && !BuildConfig.DEBUG)
|
|
|
|
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
|
|
|
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
((ActivitySetup) getActivity()).password = password1;
|
|
|
|
ActivitySetup activity = (ActivitySetup) getActivity();
|
|
|
|
|
|
|
|
activity.password = password1;
|
|
|
|
|
|
|
|
activity.import_accounts = cbAccounts.isChecked();
|
|
|
|
|
|
|
|
activity.import_answers = cbAnswers.isChecked();
|
|
|
|
|
|
|
|
activity.import_settings = cbSettings.isChecked();
|
|
|
|
getActivity().startActivityForResult(
|
|
|
|
getActivity().startActivityForResult(
|
|
|
|
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
|
|
|
|
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|