From 071fc8cd4c4dca88aa1b0c29528f3c733f25d474 Mon Sep 17 00:00:00 2001 From: maxbogue Date: Thu, 27 Aug 2015 15:04:51 -0700 Subject: [Sync] Move PassphraseType to org.chromium.sync. There's no reason for it to be off in its own confusing package. BUG=488563 Review URL: https://codereview.chromium.org/1321483004 Cr-Commit-Position: refs/heads/master@{#345997} --- .../java/src/org/chromium/sync/PassphraseType.java | 111 +++++++++++++++++++++ .../sync/internal_api/pub/PassphraseType.java | 111 --------------------- 2 files changed, 111 insertions(+), 111 deletions(-) create mode 100644 sync/android/java/src/org/chromium/sync/PassphraseType.java delete mode 100644 sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java (limited to 'sync') diff --git a/sync/android/java/src/org/chromium/sync/PassphraseType.java b/sync/android/java/src/org/chromium/sync/PassphraseType.java new file mode 100644 index 0000000..8ef3d5a --- /dev/null +++ b/sync/android/java/src/org/chromium/sync/PassphraseType.java @@ -0,0 +1,111 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.sync; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.HashSet; +import java.util.Set; + +/** + * This enum describes the type of passphrase required, if any, to decrypt synced data. + * + * It implements the Android {@link Parcelable} interface so it is easy to pass around in intents. + * + * It maps the native enum syncer::PassphraseType. + */ +public enum PassphraseType implements Parcelable { + IMPLICIT_PASSPHRASE(0), // GAIA-based passphrase (deprecated). + KEYSTORE_PASSPHRASE(1), // Keystore passphrase. + FROZEN_IMPLICIT_PASSPHRASE(2), // Frozen GAIA passphrase. + CUSTOM_PASSPHRASE(3); // User-provided passphrase. + + public static Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public PassphraseType createFromParcel(Parcel parcel) { + return fromInternalValue(parcel.readInt()); + } + + @Override + public PassphraseType[] newArray(int size) { + return new PassphraseType[size]; + } + }; + + public static PassphraseType fromInternalValue(int value) { + for (PassphraseType type : values()) { + if (type.internalValue() == value) { + return type; + } + } + throw new IllegalArgumentException("No value for " + value + " found."); + } + + private final int mNativeValue; + + private PassphraseType(int nativeValue) { + mNativeValue = nativeValue; + } + + public Set getVisibleTypes() { + Set visibleTypes = new HashSet<>(); + switch (this) { + case IMPLICIT_PASSPHRASE: // Intentional fall through. + case KEYSTORE_PASSPHRASE: + visibleTypes.add(this); + visibleTypes.add(CUSTOM_PASSPHRASE); + break; + case FROZEN_IMPLICIT_PASSPHRASE: + visibleTypes.add(KEYSTORE_PASSPHRASE); + visibleTypes.add(FROZEN_IMPLICIT_PASSPHRASE); + break; + case CUSTOM_PASSPHRASE: + visibleTypes.add(KEYSTORE_PASSPHRASE); + visibleTypes.add(CUSTOM_PASSPHRASE); + break; + } + return visibleTypes; + } + + /** + * Get the types that are allowed to be enabled from the current type. + * + * @param encryptEverythingAllowed Whether encrypting all data is allowed. + */ + public Set getAllowedTypes(boolean encryptEverythingAllowed) { + Set allowedTypes = new HashSet<>(); + switch (this) { + case IMPLICIT_PASSPHRASE: // Intentional fall through. + case KEYSTORE_PASSPHRASE: + allowedTypes.add(this); + if (encryptEverythingAllowed) { + allowedTypes.add(CUSTOM_PASSPHRASE); + } + break; + case FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through. + case CUSTOM_PASSPHRASE: // Intentional fall through. + default: + break; + } + return allowedTypes; + } + + public int internalValue() { + // Since the values in this enums are constant and very small, this cast is safe. + return mNativeValue; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mNativeValue); + } +} diff --git a/sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java b/sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java deleted file mode 100644 index 4802881..0000000 --- a/sync/android/java/src/org/chromium/sync/internal_api/pub/PassphraseType.java +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.sync.internal_api.pub; - -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.HashSet; -import java.util.Set; - -/** - * This enum describes the type of passphrase required, if any, to decrypt synced data. - * - * It implements the Android {@link Parcelable} interface so it is easy to pass around in intents. - * - * It maps the native enum syncer::PassphraseType. - */ -public enum PassphraseType implements Parcelable { - IMPLICIT_PASSPHRASE(0), // GAIA-based passphrase (deprecated). - KEYSTORE_PASSPHRASE(1), // Keystore passphrase. - FROZEN_IMPLICIT_PASSPHRASE(2), // Frozen GAIA passphrase. - CUSTOM_PASSPHRASE(3); // User-provided passphrase. - - public static Parcelable.Creator CREATOR = - new Parcelable.Creator() { - @Override - public PassphraseType createFromParcel(Parcel parcel) { - return fromInternalValue(parcel.readInt()); - } - - @Override - public PassphraseType[] newArray(int size) { - return new PassphraseType[size]; - } - }; - - public static PassphraseType fromInternalValue(int value) { - for (PassphraseType type : values()) { - if (type.internalValue() == value) { - return type; - } - } - throw new IllegalArgumentException("No value for " + value + " found."); - } - - private final int mNativeValue; - - private PassphraseType(int nativeValue) { - mNativeValue = nativeValue; - } - - public Set getVisibleTypes() { - Set visibleTypes = new HashSet<>(); - switch (this) { - case IMPLICIT_PASSPHRASE: // Intentional fall through. - case KEYSTORE_PASSPHRASE: - visibleTypes.add(this); - visibleTypes.add(CUSTOM_PASSPHRASE); - break; - case FROZEN_IMPLICIT_PASSPHRASE: - visibleTypes.add(KEYSTORE_PASSPHRASE); - visibleTypes.add(FROZEN_IMPLICIT_PASSPHRASE); - break; - case CUSTOM_PASSPHRASE: - visibleTypes.add(KEYSTORE_PASSPHRASE); - visibleTypes.add(CUSTOM_PASSPHRASE); - break; - } - return visibleTypes; - } - - /** - * Get the types that are allowed to be enabled from the current type. - * - * @param encryptEverythingAllowed Whether encrypting all data is allowed. - */ - public Set getAllowedTypes(boolean encryptEverythingAllowed) { - Set allowedTypes = new HashSet<>(); - switch (this) { - case IMPLICIT_PASSPHRASE: // Intentional fall through. - case KEYSTORE_PASSPHRASE: - allowedTypes.add(this); - if (encryptEverythingAllowed) { - allowedTypes.add(CUSTOM_PASSPHRASE); - } - break; - case FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through. - case CUSTOM_PASSPHRASE: // Intentional fall through. - default: - break; - } - return allowedTypes; - } - - public int internalValue() { - // Since the values in this enums are constant and very small, this cast is safe. - return mNativeValue; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mNativeValue); - } -} -- cgit v1.1