Commit 2b31555e authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Propagate sync TRUSTED_VAULT_PASSPHRASE to Java

The new enum was introduced in
https://chromium-review.googlesource.com/c/chromium/src/+/1714585 but
the Java enum has remained outdated since.

This patch adds the new value also in Java by auto-generating the Java
enum via GENERATED_JAVA_ENUM_PACKAGE, which prevents similar future
issues.

Wherever there is passphrase-type-specific logic, the new
TRUSTED_VAULT_PASSPHRASE is treated similarly as the keystore case.

Bug: 1019687
Change-Id: Ib7339e8f60a0f7905626d5821fc6673659173b07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1932904
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719289}
parent c8d35c34
...@@ -20,7 +20,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; ...@@ -20,7 +20,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.tabmodel.TabSelectionType; import org.chromium.chrome.browser.tabmodel.TabSelectionType;
import org.chromium.chrome.browser.util.UrlConstants; import org.chromium.chrome.browser.util.UrlConstants;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
...@@ -217,7 +217,8 @@ public class ContextReporter { ...@@ -217,7 +217,8 @@ public class ContextReporter {
reportStatus(STATUS_SYNC_NOT_INITIALIZED); reportStatus(STATUS_SYNC_NOT_INITIALIZED);
} else if (!syncService.getActiveDataTypes().contains(ModelType.TYPED_URLS)) { } else if (!syncService.getActiveDataTypes().contains(ModelType.TYPED_URLS)) {
reportStatus(STATUS_SYNC_NOT_SYNCING_URLS); reportStatus(STATUS_SYNC_NOT_SYNCING_URLS);
} else if (syncService.getPassphraseType() != Passphrase.Type.KEYSTORE) { } else if (syncService.getPassphraseType() != PassphraseType.KEYSTORE_PASSPHRASE
&& syncService.getPassphraseType() != PassphraseType.TRUSTED_VAULT_PASSPHRASE) {
reportStatus(STATUS_SYNC_NOT_KEYSTORE_PASSPHRASE); reportStatus(STATUS_SYNC_NOT_KEYSTORE_PASSPHRASE);
} else { } else {
reportStatus(STATUS_SYNC_OTHER); reportStatus(STATUS_SYNC_OTHER);
......
...@@ -38,7 +38,7 @@ import org.chromium.chrome.browser.sync.ui.PassphraseDialogFragment; ...@@ -38,7 +38,7 @@ import org.chromium.chrome.browser.sync.ui.PassphraseDialogFragment;
import org.chromium.chrome.browser.sync.ui.PassphraseTypeDialogFragment; import org.chromium.chrome.browser.sync.ui.PassphraseTypeDialogFragment;
import org.chromium.components.signin.ChromeSigninController; import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
import java.util.HashSet; import java.util.HashSet;
...@@ -372,7 +372,7 @@ public class ManageSyncPreferences extends PreferenceFragmentCompat ...@@ -372,7 +372,7 @@ public class ManageSyncPreferences extends PreferenceFragmentCompat
/** Callback for PassphraseTypeDialogFragment.Listener */ /** Callback for PassphraseTypeDialogFragment.Listener */
@Override @Override
public void onPassphraseTypeSelected(@Passphrase.Type int type) { public void onPassphraseTypeSelected(@PassphraseType int type) {
if (!mProfileSyncService.isEngineInitialized()) { if (!mProfileSyncService.isEngineInitialized()) {
// If the engine was shut down since the dialog was opened, do nothing. // If the engine was shut down since the dialog was opened, do nothing.
return; return;
......
...@@ -40,34 +40,6 @@ public class SyncPreferenceUtils { ...@@ -40,34 +40,6 @@ public class SyncPreferenceUtils {
private static final String DASHBOARD_URL = "https://www.google.com/settings/chrome/sync"; private static final String DASHBOARD_URL = "https://www.google.com/settings/chrome/sync";
private static final String MY_ACCOUNT_URL = "https://myaccount.google.com/smartlink/home"; private static final String MY_ACCOUNT_URL = "https://myaccount.google.com/smartlink/home";
/**
* Checks if sync error icon should be shown. Show sync error icon if sync is off because
* of error, passphrase required or disabled in Android.
*/
public static boolean showSyncErrorIcon(Context context) {
if (!AndroidSyncSettings.get().isMasterSyncEnabled()) {
return true;
}
ProfileSyncService profileSyncService = ProfileSyncService.get();
if (profileSyncService != null) {
if (profileSyncService.hasUnrecoverableError()) {
return true;
}
if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
return true;
}
if (profileSyncService.isSyncActive()
&& profileSyncService.isPassphraseRequiredForPreferredDataTypes()) {
return true;
}
}
return false;
}
/** /**
* Return a short summary of the current sync status. * Return a short summary of the current sync status.
*/ */
......
...@@ -16,7 +16,7 @@ import org.chromium.base.annotations.NativeMethods; ...@@ -16,7 +16,7 @@ import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.SyncFirstSetupCompleteSource; import org.chromium.chrome.browser.SyncFirstSetupCompleteSource;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -379,11 +379,11 @@ public class ProfileSyncService { ...@@ -379,11 +379,11 @@ public class ProfileSyncService {
* This method should only be used if you want to know the raw value. For checking whether * This method should only be used if you want to know the raw value. For checking whether
* we should ask the user for a passphrase, use isPassphraseRequiredForPreferredDataTypes(). * we should ask the user for a passphrase, use isPassphraseRequiredForPreferredDataTypes().
*/ */
public @Passphrase.Type int getPassphraseType() { public @PassphraseType int getPassphraseType() {
assert isEngineInitialized(); assert isEngineInitialized();
int passphraseType = ProfileSyncServiceJni.get().getPassphraseType( int passphraseType = ProfileSyncServiceJni.get().getPassphraseType(
mNativeProfileSyncServiceAndroid, ProfileSyncService.this); mNativeProfileSyncServiceAndroid, ProfileSyncService.this);
if (passphraseType < 0 || passphraseType >= Passphrase.Type.NUM_ENTRIES) { if (passphraseType < 0 || passphraseType > PassphraseType.MAX_VALUE) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
return passphraseType; return passphraseType;
......
...@@ -26,7 +26,7 @@ import org.chromium.chrome.browser.signin.SigninManager; ...@@ -26,7 +26,7 @@ import org.chromium.chrome.browser.signin.SigninManager;
import org.chromium.components.signin.ChromeSigninController; import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.sync.AndroidSyncSettings; import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
import org.chromium.components.sync.StopSource; import org.chromium.components.sync.StopSource;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
...@@ -206,7 +206,9 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen ...@@ -206,7 +206,9 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
public boolean isSyncingUrlsWithKeystorePassphrase() { public boolean isSyncingUrlsWithKeystorePassphrase() {
return mProfileSyncService.isEngineInitialized() return mProfileSyncService.isEngineInitialized()
&& mProfileSyncService.getPreferredDataTypes().contains(ModelType.TYPED_URLS) && mProfileSyncService.getPreferredDataTypes().contains(ModelType.TYPED_URLS)
&& mProfileSyncService.getPassphraseType() == Passphrase.Type.KEYSTORE; && (mProfileSyncService.getPassphraseType() == PassphraseType.KEYSTORE_PASSPHRASE
|| mProfileSyncService.getPassphraseType()
== PassphraseType.TRUSTED_VAULT_PASSPHRASE);
} }
/** /**
......
...@@ -27,7 +27,7 @@ import org.chromium.chrome.browser.preferences.sync.SyncAndServicesPreferences; ...@@ -27,7 +27,7 @@ import org.chromium.chrome.browser.preferences.sync.SyncAndServicesPreferences;
import org.chromium.chrome.browser.sync.GoogleServiceAuthError.State; import org.chromium.chrome.browser.sync.GoogleServiceAuthError.State;
import org.chromium.chrome.browser.sync.ui.PassphraseActivity; import org.chromium.chrome.browser.sync.ui.PassphraseActivity;
import org.chromium.components.sync.AndroidSyncSettings; import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
/** /**
* {@link SyncNotificationController} provides functionality for displaying Android notifications * {@link SyncNotificationController} provides functionality for displaying Android notifications
...@@ -67,12 +67,12 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC ...@@ -67,12 +67,12 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC
return; return;
} }
switch (mProfileSyncService.getPassphraseType()) { switch (mProfileSyncService.getPassphraseType()) {
case Passphrase.Type.IMPLICIT: // Falling through intentionally. case PassphraseType.IMPLICIT_PASSPHRASE: // Falling through intentionally.
case Passphrase.Type.FROZEN_IMPLICIT: // Falling through intentionally. case PassphraseType.FROZEN_IMPLICIT_PASSPHRASE: // Falling through intentionally.
case Passphrase.Type.CUSTOM: case PassphraseType.CUSTOM_PASSPHRASE:
showSyncNotification(R.string.sync_need_passphrase, createPasswordIntent()); showSyncNotification(R.string.sync_need_passphrase, createPasswordIntent());
break; break;
case Passphrase.Type.KEYSTORE: // Falling through intentionally. case PassphraseType.KEYSTORE_PASSPHRASE: // Falling through intentionally.
default: default:
mNotificationManager.cancel(NotificationConstants.NOTIFICATION_ID_SYNC); mNotificationManager.cancel(NotificationConstants.NOTIFICATION_ID_SYNC);
return; return;
......
...@@ -28,6 +28,8 @@ import android.widget.EditText; ...@@ -28,6 +28,8 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener; import android.widget.TextView.OnEditorActionListener;
import androidx.browser.customtabs.CustomTabsIntent;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -38,12 +40,10 @@ import org.chromium.chrome.browser.help.HelpAndFeedback; ...@@ -38,12 +40,10 @@ import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.sync.ProfileSyncService; import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.util.IntentUtils; import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
import org.chromium.ui.text.SpanApplier; import org.chromium.ui.text.SpanApplier;
import org.chromium.ui.text.SpanApplier.SpanInfo; import org.chromium.ui.text.SpanApplier.SpanInfo;
import androidx.browser.customtabs.CustomTabsIntent;
/** /**
* Dialog to ask to user to enter their sync passphrase. * Dialog to ask to user to enter their sync passphrase.
*/ */
...@@ -191,22 +191,23 @@ public class PassphraseDialogFragment extends DialogFragment implements OnClickL ...@@ -191,22 +191,23 @@ public class PassphraseDialogFragment extends DialogFragment implements OnClickL
private SpannableString getPromptText() { private SpannableString getPromptText() {
ProfileSyncService pss = ProfileSyncService.get(); ProfileSyncService pss = ProfileSyncService.get();
String accountName = pss.getCurrentSignedInAccountText() + "\n\n"; String accountName = pss.getCurrentSignedInAccountText() + "\n\n";
@Passphrase.Type @PassphraseType
int passphraseType = pss.getPassphraseType(); int passphraseType = pss.getPassphraseType();
if (pss.hasExplicitPassphraseTime()) { if (pss.hasExplicitPassphraseTime()) {
String syncPassphraseHelpContext = String syncPassphraseHelpContext =
getString(R.string.help_context_change_sync_passphrase); getString(R.string.help_context_change_sync_passphrase);
switch (passphraseType) { switch (passphraseType) {
case Passphrase.Type.FROZEN_IMPLICIT: case PassphraseType.FROZEN_IMPLICIT_PASSPHRASE:
return applyInProductHelpSpan( return applyInProductHelpSpan(
accountName + pss.getSyncEnterGooglePassphraseBodyWithDateText(), accountName + pss.getSyncEnterGooglePassphraseBodyWithDateText(),
syncPassphraseHelpContext); syncPassphraseHelpContext);
case Passphrase.Type.CUSTOM: case PassphraseType.CUSTOM_PASSPHRASE:
return applyInProductHelpSpan( return applyInProductHelpSpan(
accountName + pss.getSyncEnterCustomPassphraseBodyWithDateText(), accountName + pss.getSyncEnterCustomPassphraseBodyWithDateText(),
syncPassphraseHelpContext); syncPassphraseHelpContext);
case Passphrase.Type.IMPLICIT: // Falling through intentionally. case PassphraseType.IMPLICIT_PASSPHRASE: // Falling through intentionally.
case Passphrase.Type.KEYSTORE: // Falling through intentionally. case PassphraseType.KEYSTORE_PASSPHRASE: // Falling through intentionally.
case PassphraseType.TRUSTED_VAULT_PASSPHRASE: // Falling through intentionally.
default: default:
Log.w(TAG, "Found incorrect passphrase type " + passphraseType Log.w(TAG, "Found incorrect passphrase type " + passphraseType
+ ". Falling back to default string."); + ". Falling back to default string.");
......
...@@ -32,6 +32,7 @@ import org.chromium.chrome.R; ...@@ -32,6 +32,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeStringConstants; import org.chromium.chrome.browser.ChromeStringConstants;
import org.chromium.chrome.browser.util.IntentUtils; import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.Passphrase;
import org.chromium.components.sync.PassphraseType;
import org.chromium.ui.text.SpanApplier; import org.chromium.ui.text.SpanApplier;
import org.chromium.ui.text.SpanApplier.SpanInfo; import org.chromium.ui.text.SpanApplier.SpanInfo;
import org.chromium.ui.widget.TextViewWithClickableSpans; import org.chromium.ui.widget.TextViewWithClickableSpans;
...@@ -47,9 +48,9 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -47,9 +48,9 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
DialogInterface.OnClickListener, OnItemClickListener { DialogInterface.OnClickListener, OnItemClickListener {
private static final String TAG = "PassphraseTypeDialogFragment"; private static final String TAG = "PassphraseTypeDialogFragment";
public interface Listener { void onPassphraseTypeSelected(@Passphrase.Type int type); } public interface Listener { void onPassphraseTypeSelected(@PassphraseType int type); }
private String[] getDisplayNames(List<Integer /* @Passphrase.Type */> passphraseTypes) { private String[] getDisplayNames(List<Integer /* @PassphraseType */> passphraseTypes) {
String[] displayNames = new String[passphraseTypes.size()]; String[] displayNames = new String[passphraseTypes.size()];
for (int i = 0; i < displayNames.length; i++) { for (int i = 0; i < displayNames.length; i++) {
displayNames[i] = textForPassphraseType(passphraseTypes.get(i)); displayNames[i] = textForPassphraseType(passphraseTypes.get(i));
...@@ -57,24 +58,25 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -57,24 +58,25 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
return displayNames; return displayNames;
} }
private String textForPassphraseType(@Passphrase.Type int type) { private String textForPassphraseType(@PassphraseType int type) {
switch (type) { switch (type) {
case Passphrase.Type.IMPLICIT: // Intentional fall through. case PassphraseType.IMPLICIT_PASSPHRASE: // Intentional fall through.
case Passphrase.Type.KEYSTORE: case PassphraseType.KEYSTORE_PASSPHRASE:
case PassphraseType.TRUSTED_VAULT_PASSPHRASE:
return getString(R.string.sync_passphrase_type_keystore); return getString(R.string.sync_passphrase_type_keystore);
case Passphrase.Type.FROZEN_IMPLICIT: case PassphraseType.FROZEN_IMPLICIT_PASSPHRASE:
String passphraseDate = getPassphraseDateStringFromArguments(); String passphraseDate = getPassphraseDateStringFromArguments();
String frozenPassphraseString = getString(R.string.sync_passphrase_type_frozen); String frozenPassphraseString = getString(R.string.sync_passphrase_type_frozen);
return String.format(frozenPassphraseString, passphraseDate); return String.format(frozenPassphraseString, passphraseDate);
case Passphrase.Type.CUSTOM: case PassphraseType.CUSTOM_PASSPHRASE:
return getString(R.string.sync_passphrase_type_custom); return getString(R.string.sync_passphrase_type_custom);
default: default:
return ""; return "";
} }
} }
private Adapter createAdapter(@Passphrase.Type int currentType) { private Adapter createAdapter(@PassphraseType int currentType) {
List<Integer /* @Passphrase.Type */> passphraseTypes = List<Integer /* @PassphraseType */> passphraseTypes =
Passphrase.getVisibleTypes(currentType); Passphrase.getVisibleTypes(currentType);
return new Adapter(passphraseTypes, getDisplayNames(passphraseTypes)); return new Adapter(passphraseTypes, getDisplayNames(passphraseTypes));
} }
...@@ -91,7 +93,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -91,7 +93,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
* {@link PassphraseTypeDialogFragment#createAdapter}. * {@link PassphraseTypeDialogFragment#createAdapter}.
*/ */
private Adapter( private Adapter(
List<Integer /* @Passphrase.Type */> passphraseTypes, String[] displayStrings) { List<Integer /* @PassphraseType */> passphraseTypes, String[] displayStrings) {
super(getActivity(), R.layout.passphrase_type_item, displayStrings); super(getActivity(), R.layout.passphrase_type_item, displayStrings);
mPassphraseTypes = passphraseTypes; mPassphraseTypes = passphraseTypes;
} }
...@@ -106,22 +108,22 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -106,22 +108,22 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
return getType(position); return getType(position);
} }
public @Passphrase.Type int getType(int position) { public @PassphraseType int getType(int position) {
return mPassphraseTypes.get(position); return mPassphraseTypes.get(position);
} }
public int getPositionForType(@Passphrase.Type int type) { public int getPositionForType(@PassphraseType int type) {
return mPassphraseTypes.indexOf(type); return mPassphraseTypes.indexOf(type);
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
CheckedTextView view = (CheckedTextView) super.getView(position, convertView, parent); CheckedTextView view = (CheckedTextView) super.getView(position, convertView, parent);
@Passphrase.Type @PassphraseType
int positionType = getType(position); int positionType = getType(position);
@Passphrase.Type @PassphraseType
int currentType = getCurrentTypeFromArguments(); int currentType = getCurrentTypeFromArguments();
List<Integer /* @Passphrase.Type */> allowedTypes = Passphrase.getAllowedTypes( List<Integer /* @PassphraseType */> allowedTypes = Passphrase.getAllowedTypes(
currentType, getIsEncryptEverythingAllowedFromArguments()); currentType, getIsEncryptEverythingAllowedFromArguments());
// Set the item to checked it if it is the currently selected encryption type. // Set the item to checked it if it is the currently selected encryption type.
...@@ -133,7 +135,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -133,7 +135,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
} }
/** /**
* This argument should contain a single value of type {@link Passphrase.Type}. * This argument should contain a single value of type {@link PassphraseType}.
*/ */
private static final String ARG_CURRENT_TYPE = "arg_current_type"; private static final String ARG_CURRENT_TYPE = "arg_current_type";
...@@ -142,7 +144,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -142,7 +144,7 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
private static final String ARG_IS_ENCRYPT_EVERYTHING_ALLOWED = private static final String ARG_IS_ENCRYPT_EVERYTHING_ALLOWED =
"arg_is_encrypt_everything_allowed"; "arg_is_encrypt_everything_allowed";
public static PassphraseTypeDialogFragment create(@Passphrase.Type int currentType, public static PassphraseTypeDialogFragment create(@PassphraseType int currentType,
long passphraseTime, boolean isEncryptEverythingAllowed) { long passphraseTime, boolean isEncryptEverythingAllowed) {
PassphraseTypeDialogFragment dialog = new PassphraseTypeDialogFragment(); PassphraseTypeDialogFragment dialog = new PassphraseTypeDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
...@@ -161,12 +163,12 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -161,12 +163,12 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
// Configure the passphrase type list // Configure the passphrase type list
ListView list = (ListView) v.findViewById(R.id.passphrase_types); ListView list = (ListView) v.findViewById(R.id.passphrase_types);
@Passphrase.Type @PassphraseType
int currentType = getCurrentTypeFromArguments(); int currentType = getCurrentTypeFromArguments();
// Configure the hint to reset the passphrase settings // Configure the hint to reset the passphrase settings
// Only show this hint if encryption has been set to use sync passphrase // Only show this hint if encryption has been set to use sync passphrase
if (currentType == Passphrase.Type.CUSTOM) { if (currentType == PassphraseType.CUSTOM_PASSPHRASE) {
TextViewWithClickableSpans instructionsView = TextViewWithClickableSpans instructionsView =
new TextViewWithClickableSpans(getActivity()); new TextViewWithClickableSpans(getActivity());
instructionsView.setPadding(0, instructionsView.setPadding(0,
...@@ -219,11 +221,11 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -219,11 +221,11 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long typeId) { public void onItemClick(AdapterView<?> parent, View view, int position, long typeId) {
@Passphrase.Type @PassphraseType
int currentType = getCurrentTypeFromArguments(); int currentType = getCurrentTypeFromArguments();
// We know that typeId conversion from long to int is safe, because it represents very // We know that typeId conversion from long to int is safe, because it represents very
// small enum values. // small enum values.
@Passphrase.Type @PassphraseType
int type = (int) typeId; int type = (int) typeId;
boolean isEncryptEverythingAllowed = getIsEncryptEverythingAllowedFromArguments(); boolean isEncryptEverythingAllowed = getIsEncryptEverythingAllowedFromArguments();
if (Passphrase.getAllowedTypes(currentType, isEncryptEverythingAllowed).contains(type)) { if (Passphrase.getAllowedTypes(currentType, isEncryptEverythingAllowed).contains(type)) {
...@@ -236,10 +238,10 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements ...@@ -236,10 +238,10 @@ public class PassphraseTypeDialogFragment extends DialogFragment implements
} }
@VisibleForTesting @VisibleForTesting
public @Passphrase.Type int getCurrentTypeFromArguments() { public @PassphraseType int getCurrentTypeFromArguments() {
// NUM_ENTRIES is used to find when value doesn't exist. // MAX_VALUE is used to find when value doesn't exist.
int currentType = getArguments().getInt(ARG_CURRENT_TYPE, Passphrase.Type.NUM_ENTRIES); int currentType = getArguments().getInt(ARG_CURRENT_TYPE, 1 + PassphraseType.MAX_VALUE);
if (currentType == Passphrase.Type.NUM_ENTRIES) { if (currentType > PassphraseType.MAX_VALUE) {
throw new IllegalStateException("Unable to find argument with current type."); throw new IllegalStateException("Unable to find argument with current type.");
} }
return currentType; return currentType;
......
...@@ -38,7 +38,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -38,7 +38,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils; import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.util.Collection; import java.util.Collection;
...@@ -310,8 +310,9 @@ public class ManageSyncPreferencesTest { ...@@ -310,8 +310,9 @@ public class ManageSyncPreferencesTest {
final PassphraseTypeDialogFragment typeFragment = getPassphraseTypeDialogFragment(); final PassphraseTypeDialogFragment typeFragment = getPassphraseTypeDialogFragment();
mSyncTestRule.stopSync(); mSyncTestRule.stopSync();
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(() -> {
() -> { typeFragment.onItemClick(null, null, 0, Passphrase.Type.CUSTOM); }); typeFragment.onItemClick(null, null, 0, PassphraseType.CUSTOM_PASSPHRASE);
});
// No crash means we passed. // No crash means we passed.
} }
...@@ -374,7 +375,7 @@ public class ManageSyncPreferencesTest { ...@@ -374,7 +375,7 @@ public class ManageSyncPreferencesTest {
SyncTestUtil.waitForSyncActive(); SyncTestUtil.waitForSyncActive();
final ManageSyncPreferences fragment = startManageSyncPreferences(); final ManageSyncPreferences fragment = startManageSyncPreferences();
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> fragment.onPassphraseTypeSelected(Passphrase.Type.CUSTOM)); () -> fragment.onPassphraseTypeSelected(PassphraseType.CUSTOM_PASSPHRASE));
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
PassphraseCreationDialogFragment pcdf = getPassphraseCreationDialogFragment(); PassphraseCreationDialogFragment pcdf = getPassphraseCreationDialogFragment();
AlertDialog dialog = (AlertDialog) pcdf.getDialog(); AlertDialog dialog = (AlertDialog) pcdf.getDialog();
......
...@@ -22,7 +22,7 @@ import org.chromium.chrome.R; ...@@ -22,7 +22,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.sync.SyncTestRule; import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.sync.Passphrase; import org.chromium.components.sync.PassphraseType;
/** /**
* Tests to make sure that PassphraseTypeDialogFragment presents the correct options. * Tests to make sure that PassphraseTypeDialogFragment presents the correct options.
...@@ -41,10 +41,10 @@ public class PassphraseTypeDialogFragmentTest { ...@@ -41,10 +41,10 @@ public class PassphraseTypeDialogFragmentTest {
private static final boolean UNCHECKED = false; private static final boolean UNCHECKED = false;
private static class TypeOptions { private static class TypeOptions {
public final @Passphrase.Type int type; public final @PassphraseType int type;
public final boolean isEnabled; public final boolean isEnabled;
public final boolean isChecked; public final boolean isChecked;
public TypeOptions(@Passphrase.Type int type, boolean isEnabled, boolean isChecked) { public TypeOptions(@PassphraseType int type, boolean isEnabled, boolean isChecked) {
this.type = type; this.type = type;
this.isEnabled = isEnabled; this.isEnabled = isEnabled;
this.isChecked = isChecked; this.isChecked = isChecked;
...@@ -57,20 +57,20 @@ public class PassphraseTypeDialogFragmentTest { ...@@ -57,20 +57,20 @@ public class PassphraseTypeDialogFragmentTest {
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testKeystoreEncryptionOptions() { public void testKeystoreEncryptionOptions() {
createFragment(Passphrase.Type.KEYSTORE, true); createFragment(PassphraseType.KEYSTORE_PASSPHRASE, true);
assertPassphraseTypeOptions(false, assertPassphraseTypeOptions(false,
new TypeOptions(Passphrase.Type.CUSTOM, ENABLED, UNCHECKED), new TypeOptions(PassphraseType.CUSTOM_PASSPHRASE, ENABLED, UNCHECKED),
new TypeOptions(Passphrase.Type.KEYSTORE, ENABLED, CHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, ENABLED, CHECKED));
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testCustomEncryptionOptions() { public void testCustomEncryptionOptions() {
createFragment(Passphrase.Type.CUSTOM, true); createFragment(PassphraseType.CUSTOM_PASSPHRASE, true);
assertPassphraseTypeOptions(true, assertPassphraseTypeOptions(true,
new TypeOptions(Passphrase.Type.CUSTOM, DISABLED, CHECKED), new TypeOptions(PassphraseType.CUSTOM_PASSPHRASE, DISABLED, CHECKED),
new TypeOptions(Passphrase.Type.KEYSTORE, DISABLED, UNCHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, DISABLED, UNCHECKED));
} }
/* /*
...@@ -80,43 +80,43 @@ public class PassphraseTypeDialogFragmentTest { ...@@ -80,43 +80,43 @@ public class PassphraseTypeDialogFragmentTest {
@Test @Test
@FlakyTest(message = "crbug.com/588050") @FlakyTest(message = "crbug.com/588050")
public void testFrozenImplicitEncryptionOptions() { public void testFrozenImplicitEncryptionOptions() {
createFragment(Passphrase.Type.FROZEN_IMPLICIT, true); createFragment(PassphraseType.FROZEN_IMPLICIT_PASSPHRASE, true);
assertPassphraseTypeOptions(true, assertPassphraseTypeOptions(true,
new TypeOptions(Passphrase.Type.FROZEN_IMPLICIT, DISABLED, CHECKED), new TypeOptions(PassphraseType.FROZEN_IMPLICIT_PASSPHRASE, DISABLED, CHECKED),
new TypeOptions(Passphrase.Type.KEYSTORE, DISABLED, UNCHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, DISABLED, UNCHECKED));
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testImplicitEncryptionOptions() { public void testImplicitEncryptionOptions() {
createFragment(Passphrase.Type.IMPLICIT, true); createFragment(PassphraseType.IMPLICIT_PASSPHRASE, true);
assertPassphraseTypeOptions(false, assertPassphraseTypeOptions(false,
new TypeOptions(Passphrase.Type.CUSTOM, ENABLED, UNCHECKED), new TypeOptions(PassphraseType.CUSTOM_PASSPHRASE, ENABLED, UNCHECKED),
new TypeOptions(Passphrase.Type.IMPLICIT, ENABLED, CHECKED)); new TypeOptions(PassphraseType.IMPLICIT_PASSPHRASE, ENABLED, CHECKED));
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testKeystoreEncryptionOptionsEncryptEverythingDisallowed() { public void testKeystoreEncryptionOptionsEncryptEverythingDisallowed() {
createFragment(Passphrase.Type.KEYSTORE, false); createFragment(PassphraseType.KEYSTORE_PASSPHRASE, false);
assertPassphraseTypeOptions(false, assertPassphraseTypeOptions(false,
new TypeOptions(Passphrase.Type.CUSTOM, DISABLED, UNCHECKED), new TypeOptions(PassphraseType.CUSTOM_PASSPHRASE, DISABLED, UNCHECKED),
new TypeOptions(Passphrase.Type.KEYSTORE, ENABLED, CHECKED)); new TypeOptions(PassphraseType.KEYSTORE_PASSPHRASE, ENABLED, CHECKED));
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Sync"}) @Feature({"Sync"})
public void testImplicitEncryptionOptionsEncryptEverythingDisallowed() { public void testImplicitEncryptionOptionsEncryptEverythingDisallowed() {
createFragment(Passphrase.Type.IMPLICIT, false); createFragment(PassphraseType.IMPLICIT_PASSPHRASE, false);
assertPassphraseTypeOptions(false, assertPassphraseTypeOptions(false,
new TypeOptions(Passphrase.Type.CUSTOM, DISABLED, UNCHECKED), new TypeOptions(PassphraseType.CUSTOM_PASSPHRASE, DISABLED, UNCHECKED),
new TypeOptions(Passphrase.Type.IMPLICIT, ENABLED, CHECKED)); new TypeOptions(PassphraseType.IMPLICIT_PASSPHRASE, ENABLED, CHECKED));
} }
public void createFragment(@Passphrase.Type int type, boolean isEncryptEverythingAllowed) { public void createFragment(@PassphraseType int type, boolean isEncryptEverythingAllowed) {
mTypeFragment = PassphraseTypeDialogFragment.create(type, 0, isEncryptEverythingAllowed); mTypeFragment = PassphraseTypeDialogFragment.create(type, 0, isEncryptEverythingAllowed);
mTypeFragment.show(mSyncTestRule.getActivity().getSupportFragmentManager(), TAG); mTypeFragment.show(mSyncTestRule.getActivity().getSupportFragmentManager(), TAG);
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
......
...@@ -59,6 +59,7 @@ android_library("sync_javatests") { ...@@ -59,6 +59,7 @@ android_library("sync_javatests") {
java_cpp_enum("java_enums") { java_cpp_enum("java_enums") {
sources = [ sources = [
"//components/sync/base/model_type.h", "//components/sync/base/model_type.h",
"//components/sync/base/passphrase_enums.h",
"//components/sync/base/stop_source.h", "//components/sync/base/stop_source.h",
"//components/sync/driver/sync_service_utils.h", "//components/sync/driver/sync_service_utils.h",
] ]
......
...@@ -4,47 +4,42 @@ ...@@ -4,47 +4,42 @@
package org.chromium.components.sync; package org.chromium.components.sync;
import androidx.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* This class describes the type of passphrase required, if any, to decrypt synced data. * This class provides some utility functions to deal with sync passphrases.
* It maps the native enum PassphraseType.
*/ */
public class Passphrase { public class Passphrase {
@IntDef({Type.IMPLICIT, Type.KEYSTORE, Type.FROZEN_IMPLICIT, Type.CUSTOM}) /**
@Retention(RetentionPolicy.SOURCE) * Returns whether a passphrase type represents a "secondary" passphrase, which usually means
public @interface Type { * a custom passphrase, but also includes the legacy equivalent, a frozen implicit passphrase.
// Update {@link ProfileSyncService#getPassphraseType()} after changing lowest value. */
int IMPLICIT = 0; // GAIA-based passphrase (deprecated). private static boolean isSecondaryPassphraseType(@PassphraseType int type) {
int KEYSTORE = 1; // Keystore passphrase. switch (type) {
int FROZEN_IMPLICIT = 2; // Frozen GAIA passphrase. case PassphraseType.IMPLICIT_PASSPHRASE: // Intentional fall through.
int CUSTOM = 3; // User-provided passphrase. case PassphraseType.TRUSTED_VAULT_PASSPHRASE: // Intentional fall through.
int NUM_ENTRIES = 4; case PassphraseType.KEYSTORE_PASSPHRASE:
return false;
case PassphraseType.FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through.
case PassphraseType.CUSTOM_PASSPHRASE:
return true;
}
return false;
} }
/** /**
* Get the types that are displayed for the current type. * Get the types that are displayed for the current type.
*/ */
public static List<Integer /* @Type */> getVisibleTypes(@Type int type) { public static List<Integer /* @Type */> getVisibleTypes(@PassphraseType int type) {
List<Integer /* @Type */> visibleTypes = new ArrayList<>(); List<Integer /* @Type */> visibleTypes = new ArrayList<>();
switch (type) { if (isSecondaryPassphraseType(type)) {
case Type.IMPLICIT: // Intentional fall through. visibleTypes.add(type);
case Type.KEYSTORE: visibleTypes.add(PassphraseType.KEYSTORE_PASSPHRASE);
visibleTypes.add(Type.CUSTOM); } else {
visibleTypes.add(type); visibleTypes.add(PassphraseType.CUSTOM_PASSPHRASE);
break; visibleTypes.add(type);
case Type.FROZEN_IMPLICIT: // Intentional fall through.
case Type.CUSTOM:
visibleTypes.add(type);
visibleTypes.add(Type.KEYSTORE);
break;
default:
assert false;
} }
return visibleTypes; return visibleTypes;
} }
...@@ -54,12 +49,12 @@ public class Passphrase { ...@@ -54,12 +49,12 @@ public class Passphrase {
* @param isEncryptEverythingAllowed Whether encrypting all data is allowed. * @param isEncryptEverythingAllowed Whether encrypting all data is allowed.
*/ */
public static List<Integer /* @Type */> getAllowedTypes( public static List<Integer /* @Type */> getAllowedTypes(
@Type int type, boolean isEncryptEverythingAllowed) { @PassphraseType int type, boolean isEncryptEverythingAllowed) {
List<Integer /* @Type */> allowedTypes = new ArrayList<>(); List<Integer /* @Type */> allowedTypes = new ArrayList<>();
if (type == Type.IMPLICIT || type == Type.KEYSTORE) { if (!isSecondaryPassphraseType(type)) {
allowedTypes.add(type); allowedTypes.add(type);
if (isEncryptEverythingAllowed) allowedTypes.add(Type.CUSTOM); if (isEncryptEverythingAllowed) allowedTypes.add(PassphraseType.CUSTOM_PASSPHRASE);
} }
return allowedTypes; return allowedTypes;
} }
} }
\ No newline at end of file
...@@ -14,6 +14,7 @@ namespace syncer { ...@@ -14,6 +14,7 @@ namespace syncer {
// the user should be prompted for a decryption passphrase. // the user should be prompted for a decryption passphrase.
// Do not re-order or delete these entries; they are used in a UMA histogram. // Do not re-order or delete these entries; they are used in a UMA histogram.
// Please edit SyncPassphraseType in enums.xml if a value is added. // Please edit SyncPassphraseType in enums.xml if a value is added.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.sync
enum class PassphraseType { enum class PassphraseType {
// GAIA-based passphrase (deprecated). // GAIA-based passphrase (deprecated).
kImplicitPassphrase = 0, kImplicitPassphrase = 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment