| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.autofill; |
| 18 |
|
| 19 |
import static android.view.autofill.Helper.sDebug; |
| 20 |
|
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
import android.util.Log; |
| 25 |
|
| 26 |
import com.android.internal.util.Preconditions; |
| 27 |
|
| 28 |
import java.util.Arrays; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
final class OptionalValidators extends InternalValidator { |
| 39 |
|
| 40 |
private static final String TAG = "OptionalValidators"; |
| 41 |
|
| 42 |
@NonNull private final InternalValidator[] mValidators; |
| 43 |
|
| 44 |
OptionalValidators(@NonNull InternalValidator[] validators) { |
| 45 |
mValidators = Preconditions.checkArrayElementsNotNull(validators, "validators"); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public boolean isValid(@NonNull ValueFinder finder) { |
| 50 |
for (InternalValidator validator : mValidators) { |
| 51 |
final boolean valid = validator.isValid(finder); |
| 52 |
if (sDebug) Log.d(TAG, "isValid(" + validator + "): " + valid); |
| 53 |
if (valid) return true; |
| 54 |
} |
| 55 |
|
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
@Override |
| 63 |
public String toString() { |
| 64 |
if (!sDebug) return super.toString(); |
| 65 |
|
| 66 |
return new StringBuilder("OptionalValidators: [validators=") |
| 67 |
.append(Arrays.toString(mValidators)) |
| 68 |
.append("]") |
| 69 |
.toString(); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@Override |
| 76 |
public int describeContents() { |
| 77 |
return 0; |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public void writeToParcel(Parcel dest, int flags) { |
| 82 |
dest.writeParcelableArray(mValidators, flags); |
| 83 |
} |
| 84 |
|
| 85 |
public static final @android.annotation.NonNull Parcelable.Creator<OptionalValidators> CREATOR = |
| 86 |
new Parcelable.Creator<OptionalValidators>() { |
| 87 |
@Override |
| 88 |
public OptionalValidators createFromParcel(Parcel parcel) { |
| 89 |
return new OptionalValidators(parcel |
| 90 |
.readParcelableArray(null, InternalValidator.class)); |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public OptionalValidators[] newArray(int size) { |
| 95 |
return new OptionalValidators[size]; |
| 96 |
} |
| 97 |
}; |
| 98 |
} |