1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.autofill; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import java.util.Collection; 23 24 /** @hide */ 25 public final class Helper { 26 27 // Debug-level flags are defined when service is bound. 28 public static boolean sDebug = false; 29 public static boolean sVerbose = false; 30 31 /** 32 * Appends {@code value} to the {@code builder} redacting its contents. 33 */ appendRedacted(@onNull StringBuilder builder, @Nullable CharSequence value)34 public static void appendRedacted(@NonNull StringBuilder builder, 35 @Nullable CharSequence value) { 36 builder.append(getRedacted(value)); 37 } 38 39 /** 40 * Gets the redacted version of a value. 41 */ 42 @NonNull getRedacted(@ullable CharSequence value)43 public static String getRedacted(@Nullable CharSequence value) { 44 return (value == null) ? "null" : value.length() + "_chars"; 45 } 46 47 /** 48 * Appends {@code values} to the {@code builder} redacting its contents. 49 */ appendRedacted(@onNull StringBuilder builder, @Nullable String[] values)50 public static void appendRedacted(@NonNull StringBuilder builder, @Nullable String[] values) { 51 if (values == null) { 52 builder.append("N/A"); 53 return; 54 } 55 builder.append("["); 56 for (String value : values) { 57 builder.append(" '"); 58 appendRedacted(builder, value); 59 builder.append("'"); 60 } 61 builder.append(" ]"); 62 } 63 64 /** 65 * Convers a collaction of {@link AutofillId AutofillIds} to an array. 66 * @param collection The collection. 67 * @return The array. 68 */ toArray(Collection<AutofillId> collection)69 public static @NonNull AutofillId[] toArray(Collection<AutofillId> collection) { 70 if (collection == null) { 71 return new AutofillId[0]; 72 } 73 final AutofillId[] array = new AutofillId[collection.size()]; 74 collection.toArray(array); 75 return array; 76 } 77 Helper()78 private Helper() { 79 throw new UnsupportedOperationException("contains static members only"); 80 } 81 } 82