|
@@ -47,6 +47,7 @@ import android.support.annotation.LayoutRes;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.v4.content.res.ResourcesCompat;
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.app.AppCompatDelegate;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuInflater;
|
|
@@ -60,6 +61,7 @@ import com.owncloud.android.BuildConfig;
|
|
|
import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.authentication.AccountUtils;
|
|
|
+import com.owncloud.android.authentication.PassCodeManager;
|
|
|
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
|
|
import com.owncloud.android.datamodel.ExternalLinksProvider;
|
|
|
import com.owncloud.android.datastorage.DataStorageProvider;
|
|
@@ -71,6 +73,7 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
import com.owncloud.android.utils.DeviceCredentialUtils;
|
|
|
import com.owncloud.android.utils.DisplayUtils;
|
|
|
+import com.owncloud.android.utils.EncryptionUtils;
|
|
|
import com.owncloud.android.utils.MimeTypeUtil;
|
|
|
import com.owncloud.android.utils.ThemeUtils;
|
|
|
|
|
@@ -119,6 +122,9 @@ public class Preferences extends PreferenceActivity
|
|
|
private String mStoragePath;
|
|
|
private String pendingLock;
|
|
|
|
|
|
+ private Account mAccount;
|
|
|
+ private ArbitraryDataProvider mArbitraryDataProvider;
|
|
|
+
|
|
|
public static class PreferenceKeys {
|
|
|
public static final String STORAGE_PATH = "storage_path";
|
|
|
public static final String INSTANT_UPLOAD_PATH = "instant_upload_path";
|
|
@@ -150,6 +156,9 @@ public class Preferences extends PreferenceActivity
|
|
|
String appVersion = getAppVersion();
|
|
|
PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen");
|
|
|
|
|
|
+ mAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
|
|
|
+ mArbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
|
|
+
|
|
|
// General
|
|
|
setupGeneralCategory(accentColor);
|
|
|
|
|
@@ -307,6 +316,8 @@ public class Preferences extends PreferenceActivity
|
|
|
|
|
|
setupContactsBackupPreference(preferenceCategoryMore);
|
|
|
|
|
|
+ setupE2EMnemonicPreference(preferenceCategoryMore);
|
|
|
+
|
|
|
setupHelpPreference(preferenceCategoryMore);
|
|
|
|
|
|
setupRecommendPreference(preferenceCategoryMore);
|
|
@@ -437,6 +448,34 @@ public class Preferences extends PreferenceActivity
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void setupE2EMnemonicPreference(PreferenceCategory preferenceCategoryMore) {
|
|
|
+ String mnemonic = mArbitraryDataProvider.getValue(mAccount.name, EncryptionUtils.MNEMONIC);
|
|
|
+
|
|
|
+ Preference pMnemonic = findPreference("mnemonic");
|
|
|
+ if (pMnemonic != null) {
|
|
|
+ if (!mnemonic.isEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ if (DeviceCredentialUtils.areCredentialsAvailable(this)) {
|
|
|
+ pMnemonic.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onPreferenceClick(Preference preference) {
|
|
|
+
|
|
|
+ Intent i = new Intent(MainApp.getAppContext(), RequestCredentialsActivity.class);
|
|
|
+ i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
|
+ Preferences.this.startActivityForResult(i, PassCodeManager.PASSCODE_ACTIVITY);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ pMnemonic.setEnabled(false);
|
|
|
+ pMnemonic.setSummary(R.string.prefs_e2e_no_device_credentials);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ preferenceCategoryMore.removePreference(pMnemonic);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void setupHelpPreference(PreferenceCategory preferenceCategoryMore) {
|
|
|
boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
|
|
|
Preference pHelp = findPreference("help");
|
|
@@ -645,16 +684,15 @@ public class Preferences extends PreferenceActivity
|
|
|
} else {
|
|
|
// Upload on WiFi
|
|
|
final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
|
|
- final Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
|
|
|
|
|
|
final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference("synced_folder_on_wifi");
|
|
|
pUploadOnWifiCheckbox.setChecked(
|
|
|
- arbitraryDataProvider.getBooleanValue(account, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
|
|
|
+ arbitraryDataProvider.getBooleanValue(mAccount, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
|
|
|
|
|
|
pUploadOnWifiCheckbox.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
|
@Override
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
- arbitraryDataProvider.storeOrUpdateKeyValue(account.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
|
|
|
+ arbitraryDataProvider.storeOrUpdateKeyValue(mAccount.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
|
|
|
String.valueOf(pUploadOnWifiCheckbox.isChecked()));
|
|
|
|
|
|
return true;
|
|
@@ -800,8 +838,6 @@ public class Preferences extends PreferenceActivity
|
|
|
}
|
|
|
|
|
|
private void launchDavDroidLogin() {
|
|
|
- Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
|
|
|
-
|
|
|
Intent davDroidLoginIntent = new Intent();
|
|
|
davDroidLoginIntent.setClassName("at.bitfire.davdroid", "at.bitfire.davdroid.ui.setup.LoginActivity");
|
|
|
if (getPackageManager().resolveActivity(davDroidLoginIntent, 0) != null) {
|
|
@@ -809,7 +845,7 @@ public class Preferences extends PreferenceActivity
|
|
|
if (mUri != null) {
|
|
|
davDroidLoginIntent.putExtra("url", mUri.toString() + DAV_PATH);
|
|
|
}
|
|
|
- davDroidLoginIntent.putExtra("username", AccountUtils.getAccountUsername(account.name));
|
|
|
+ davDroidLoginIntent.putExtra("username", AccountUtils.getAccountUsername(mAccount.name));
|
|
|
//loginIntent.putExtra("password", "...");
|
|
|
startActivityForResult(davDroidLoginIntent, ACTION_REQUEST_CODE_DAVDROID_SETUP);
|
|
|
} else {
|
|
@@ -835,8 +871,7 @@ public class Preferences extends PreferenceActivity
|
|
|
Thread t = new Thread(new Runnable() {
|
|
|
public void run() {
|
|
|
try {
|
|
|
- Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
|
|
|
- OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
|
|
|
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext());
|
|
|
mUri = OwnCloudClientManagerFactory.getDefaultSingleton().
|
|
|
getClientFor(ocAccount, getApplicationContext()).getBaseUri();
|
|
|
} catch (Throwable t) {
|
|
@@ -888,7 +923,7 @@ public class Preferences extends PreferenceActivity
|
|
|
} else if (requestCode == ACTION_CONFIRM_DEVICE_CREDENTIALS && resultCode == RESULT_OK &&
|
|
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
|
|
data.getIntExtra(RequestCredentialsActivity.KEY_CHECK_RESULT,
|
|
|
- RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) ==
|
|
|
+ RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) ==
|
|
|
RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {
|
|
|
mLock.setValue(LOCK_NONE);
|
|
|
mLock.setSummary(mLock.getEntry());
|
|
@@ -896,6 +931,22 @@ public class Preferences extends PreferenceActivity
|
|
|
if (!pendingLock.equals(LOCK_NONE)) {
|
|
|
enableLock(pendingLock);
|
|
|
}
|
|
|
+ } else if (requestCode == PassCodeManager.PASSCODE_ACTIVITY && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
|
|
+ data.getIntExtra(RequestCredentialsActivity.KEY_CHECK_RESULT,
|
|
|
+ RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) ==
|
|
|
+ RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {
|
|
|
+
|
|
|
+ ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
|
|
+ String mnemonic = arbitraryDataProvider.getValue(mAccount.name, EncryptionUtils.MNEMONIC);
|
|
|
+
|
|
|
+ int accentColor = ThemeUtils.primaryAccentColor(this);
|
|
|
+
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.FallbackTheming_Dialog);
|
|
|
+ builder.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_e2e_mnemonic), accentColor));
|
|
|
+ builder.setMessage(mnemonic);
|
|
|
+ builder.setPositiveButton(ThemeUtils.getColoredTitle(getString(R.string.common_ok), accentColor),
|
|
|
+ (dialog, which) -> dialog.dismiss());
|
|
|
+ builder.show();
|
|
|
}
|
|
|
}
|
|
|
|