OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.sync; | 5 package org.chromium.components.sync; |
6 | 6 |
7 import android.os.Parcel; | 7 import android.os.Parcel; |
8 import android.os.Parcelable; | 8 import android.os.Parcelable; |
9 | 9 |
10 import java.util.HashSet; | 10 import java.util.HashSet; |
11 import java.util.Set; | 11 import java.util.Set; |
12 | 12 |
13 /** | 13 /** |
14 * This enum describes the type of passphrase required, if any, to decrypt synce
d data. | 14 * This enum describes the type of passphrase required, if any, to decrypt synce
d data. |
15 * | 15 * |
16 * It implements the Android {@link Parcelable} interface so it is easy to pass
around in intents. | 16 * It implements the Android {@link Parcelable} interface so it is easy to pass
around in intents. |
17 * | 17 * |
18 * It maps the native enum syncer::PassphraseType. | 18 * It maps the native enum syncer::PassphraseType. |
19 */ | 19 */ |
20 public enum PassphraseType implements Parcelable { | 20 public enum PassphraseType implements Parcelable { |
21 IMPLICIT_PASSPHRASE(0), // GAIA-based passphrase (deprecated). | 21 IMPLICIT_PASSPHRASE(0), // GAIA-based passphrase (deprecated). |
22 KEYSTORE_PASSPHRASE(1), // Keystore passphrase. | 22 KEYSTORE_PASSPHRASE(1), // Keystore passphrase. |
23 FROZEN_IMPLICIT_PASSPHRASE(2), // Frozen GAIA passphrase. | 23 FROZEN_IMPLICIT_PASSPHRASE(2), // Frozen GAIA passphrase. |
24 CUSTOM_PASSPHRASE(3); // User-provided passphrase. | 24 CUSTOM_PASSPHRASE(3); // User-provided passphrase. |
25 | 25 |
26 public static Parcelable.Creator CREATOR = | 26 public static Parcelable.Creator CREATOR = new Parcelable.Creator<Passphrase
Type>() { |
27 new Parcelable.Creator<PassphraseType>() { | 27 @Override |
28 @Override | 28 public PassphraseType createFromParcel(Parcel parcel) { |
29 public PassphraseType createFromParcel(Parcel parcel) { | 29 return fromInternalValue(parcel.readInt()); |
30 return fromInternalValue(parcel.readInt()); | 30 } |
31 } | |
32 | 31 |
33 @Override | 32 @Override |
34 public PassphraseType[] newArray(int size) { | 33 public PassphraseType[] newArray(int size) { |
35 return new PassphraseType[size]; | 34 return new PassphraseType[size]; |
36 } | 35 } |
37 }; | 36 }; |
38 | 37 |
39 public static PassphraseType fromInternalValue(int value) { | 38 public static PassphraseType fromInternalValue(int value) { |
40 for (PassphraseType type : values()) { | 39 for (PassphraseType type : values()) { |
41 if (type.internalValue() == value) { | 40 if (type.internalValue() == value) { |
42 return type; | 41 return type; |
43 } | 42 } |
44 } | 43 } |
45 throw new IllegalArgumentException("No value for " + value + " found."); | 44 throw new IllegalArgumentException("No value for " + value + " found."); |
46 } | 45 } |
47 | 46 |
48 private final int mNativeValue; | 47 private final int mNativeValue; |
49 | 48 |
50 private PassphraseType(int nativeValue) { | 49 private PassphraseType(int nativeValue) { |
51 mNativeValue = nativeValue; | 50 mNativeValue = nativeValue; |
52 } | 51 } |
53 | 52 |
54 public Set<PassphraseType> getVisibleTypes() { | 53 public Set<PassphraseType> getVisibleTypes() { |
55 Set<PassphraseType> visibleTypes = new HashSet<>(); | 54 Set<PassphraseType> visibleTypes = new HashSet<>(); |
56 switch (this) { | 55 switch (this) { |
57 case IMPLICIT_PASSPHRASE: // Intentional fall through. | 56 case IMPLICIT_PASSPHRASE: // Intentional fall through. |
58 case KEYSTORE_PASSPHRASE: | 57 case KEYSTORE_PASSPHRASE: |
59 visibleTypes.add(this); | 58 visibleTypes.add(this); |
60 visibleTypes.add(CUSTOM_PASSPHRASE); | 59 visibleTypes.add(CUSTOM_PASSPHRASE); |
61 break; | 60 break; |
62 case FROZEN_IMPLICIT_PASSPHRASE: | 61 case FROZEN_IMPLICIT_PASSPHRASE: |
63 visibleTypes.add(KEYSTORE_PASSPHRASE); | 62 visibleTypes.add(KEYSTORE_PASSPHRASE); |
64 visibleTypes.add(FROZEN_IMPLICIT_PASSPHRASE); | 63 visibleTypes.add(FROZEN_IMPLICIT_PASSPHRASE); |
65 break; | 64 break; |
66 case CUSTOM_PASSPHRASE: | 65 case CUSTOM_PASSPHRASE: |
67 visibleTypes.add(KEYSTORE_PASSPHRASE); | 66 visibleTypes.add(KEYSTORE_PASSPHRASE); |
68 visibleTypes.add(CUSTOM_PASSPHRASE); | 67 visibleTypes.add(CUSTOM_PASSPHRASE); |
69 break; | 68 break; |
70 } | 69 } |
71 return visibleTypes; | 70 return visibleTypes; |
72 } | 71 } |
73 | 72 |
74 /** | 73 /** |
75 * Get the types that are allowed to be enabled from the current type. | 74 * Get the types that are allowed to be enabled from the current type. |
76 * | 75 * |
77 * @param isEncryptEverythingAllowed Whether encrypting all data is allowed. | 76 * @param isEncryptEverythingAllowed Whether encrypting all data is allowed. |
78 */ | 77 */ |
79 public Set<PassphraseType> getAllowedTypes(boolean isEncryptEverythingAllowe
d) { | 78 public Set<PassphraseType> getAllowedTypes(boolean isEncryptEverythingAllowe
d) { |
80 Set<PassphraseType> allowedTypes = new HashSet<>(); | 79 Set<PassphraseType> allowedTypes = new HashSet<>(); |
81 switch (this) { | 80 switch (this) { |
82 case IMPLICIT_PASSPHRASE: // Intentional fall through. | 81 case IMPLICIT_PASSPHRASE: // Intentional fall through. |
83 case KEYSTORE_PASSPHRASE: | 82 case KEYSTORE_PASSPHRASE: |
84 allowedTypes.add(this); | 83 allowedTypes.add(this); |
85 if (isEncryptEverythingAllowed) { | 84 if (isEncryptEverythingAllowed) { |
86 allowedTypes.add(CUSTOM_PASSPHRASE); | 85 allowedTypes.add(CUSTOM_PASSPHRASE); |
87 } | 86 } |
88 break; | 87 break; |
89 case FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through. | 88 case FROZEN_IMPLICIT_PASSPHRASE: // Intentional fall through. |
90 case CUSTOM_PASSPHRASE: // Intentional fall through. | 89 case CUSTOM_PASSPHRASE: // Intentional fall through. |
91 default: | 90 default: |
92 break; | 91 break; |
93 } | 92 } |
94 return allowedTypes; | 93 return allowedTypes; |
95 } | 94 } |
96 | 95 |
97 public int internalValue() { | 96 public int internalValue() { |
98 // Since the values in this enums are constant and very small, this cast
is safe. | 97 // Since the values in this enums are constant and very small, this cast
is safe. |
99 return mNativeValue; | 98 return mNativeValue; |
100 } | 99 } |
101 | 100 |
102 @Override | 101 @Override |
103 public int describeContents() { | 102 public int describeContents() { |
104 return 0; | 103 return 0; |
105 } | 104 } |
106 | 105 |
107 @Override | 106 @Override |
108 public void writeToParcel(Parcel dest, int flags) { | 107 public void writeToParcel(Parcel dest, int flags) { |
109 dest.writeInt(mNativeValue); | 108 dest.writeInt(mNativeValue); |
110 } | 109 } |
111 } | 110 } |
OLD | NEW |