| 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.sync.internal_api.pub; |
| 6 | |
| 7 | import android.os.Parcel; |
| 8 | import android.os.Parcelable; |
| 9 | |
| 10 | /** |
| 11 | * This enum describes the type of passphrase required, if any, to decrypt synced data. |
| 12 | * |
| 13 | * It implements the Android {@link Parcelable} interface so it is easy to pass around in intents. |
| 14 | * |
| 15 | * It maps the native enum syncer::PassphraseType, but has the additional values INVALID and NONE. |
| 16 | */ |
| 17 | public enum SyncDecryptionPassphraseType implements Parcelable { |
| 18 | INVALID(-2), // Used as default value and is not a valid decryption type. |
| 19 | NONE(-1), // No encryption (deprecated). |
| 20 | IMPLICIT_PASSPHRASE(0), // GAIA-based passphrase (deprecated). |
| 21 | KEYSTORE_PASSPHRASE(1), // Keystore passphrase. |
| 22 | FROZEN_IMPLICIT_PASSPHRASE(2), // Frozen GAIA passphrase. |
| 23 | CUSTOM_PASSPHRASE(3); // User-provided passphrase. |
| 24 | |
| 25 | public static Parcelable.Creator CREATOR = |
| 26 | new Parcelable.Creator<SyncDecryptionPassphraseType>() { |
| 27 | @Override |
| 28 | public SyncDecryptionPassphraseType createFromParcel(Parcel parcel) { |
| 29 | return fromInternalValue(parcel.readInt()); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public SyncDecryptionPassphraseType[] newArray(int size) { |
| 34 | return new SyncDecryptionPassphraseType[size]; |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | public static SyncDecryptionPassphraseType fromInternalValue(int value) { |
| 39 | for (SyncDecryptionPassphraseType type : values()) { |
| 40 | if (type.internalValue() == value) { |
| 41 | return type; |
| 42 | } |
| 43 | } |
| 44 | // Falling back to INVALID. Should not happen if |value| was retrieved from native. |
| 45 | return INVALID; |
| 46 | } |
| 47 | |
| 48 | private final int mNativeValue; |
| 49 | |
| 50 | private SyncDecryptionPassphraseType(int nativeValue) { |
| 51 | mNativeValue = nativeValue; |
| 52 | } |
| 53 | |
| 54 | public int internalValue() { |
| 55 | // Since the values in this enums are constant and very small, this cast is safe. |
| 56 | return mNativeValue; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public int describeContents() { |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void writeToParcel(Parcel dest, int flags) { |
| 66 | dest.writeInt(mNativeValue); |
| 67 | } |
| 68 | } |