| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.view.contentcapture; |
| 17 |
|
| 18 |
import static android.view.contentcapture.ContentCaptureManager.DEVICE_CONFIG_PROPERTY_LOGGING_LEVEL; |
| 19 |
import static android.view.contentcapture.ContentCaptureManager.LOGGING_LEVEL_DEBUG; |
| 20 |
import static android.view.contentcapture.ContentCaptureManager.LOGGING_LEVEL_OFF; |
| 21 |
import static android.view.contentcapture.ContentCaptureManager.LOGGING_LEVEL_VERBOSE; |
| 22 |
|
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.os.Build; |
| 25 |
import android.provider.DeviceConfig; |
| 26 |
import android.util.ArraySet; |
| 27 |
import android.util.Log; |
| 28 |
import android.view.contentcapture.ContentCaptureManager.LoggingLevel; |
| 29 |
|
| 30 |
import java.util.ArrayList; |
| 31 |
import java.util.List; |
| 32 |
import java.util.Set; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public final class ContentCaptureHelper { |
| 40 |
|
| 41 |
private static final String TAG = ContentCaptureHelper.class.getSimpleName(); |
| 42 |
|
| 43 |
public static boolean sVerbose = false; |
| 44 |
public static boolean sDebug = true; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
@Nullable |
| 50 |
public static String getSanitizedString(@Nullable CharSequence text) { |
| 51 |
return text == null ? null : text.length() + "_chars"; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@LoggingLevel |
| 58 |
public static int getDefaultLoggingLevel() { |
| 59 |
return Build.IS_DEBUGGABLE ? LOGGING_LEVEL_DEBUG : LOGGING_LEVEL_OFF; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public static void setLoggingLevel() { |
| 66 |
final int defaultLevel = getDefaultLoggingLevel(); |
| 67 |
final int level = DeviceConfig.getInt(DeviceConfig.NAMESPACE_CONTENT_CAPTURE, |
| 68 |
DEVICE_CONFIG_PROPERTY_LOGGING_LEVEL, defaultLevel); |
| 69 |
setLoggingLevel(level); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static void setLoggingLevel(@LoggingLevel int level) { |
| 76 |
Log.i(TAG, "Setting logging level to " + getLoggingLevelAsString(level)); |
| 77 |
sVerbose = sDebug = false; |
| 78 |
switch (level) { |
| 79 |
case LOGGING_LEVEL_VERBOSE: |
| 80 |
sVerbose = true; |
| 81 |
|
| 82 |
case LOGGING_LEVEL_DEBUG: |
| 83 |
sDebug = true; |
| 84 |
return; |
| 85 |
case LOGGING_LEVEL_OFF: |
| 86 |
|
| 87 |
return; |
| 88 |
default: |
| 89 |
Log.w(TAG, "setLoggingLevel(): invalud level: " + level); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public static String getLoggingLevelAsString(@LoggingLevel int level) { |
| 97 |
switch (level) { |
| 98 |
case LOGGING_LEVEL_OFF: |
| 99 |
return "OFF"; |
| 100 |
case LOGGING_LEVEL_DEBUG: |
| 101 |
return "DEBUG"; |
| 102 |
case LOGGING_LEVEL_VERBOSE: |
| 103 |
return "VERBOSE"; |
| 104 |
default: |
| 105 |
return "UNKNOWN-" + level; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
@Nullable |
| 113 |
public static <T> ArrayList<T> toList(@Nullable Set<T> set) { |
| 114 |
return set == null ? null : new ArrayList<T>(set); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
@Nullable |
| 121 |
public static <T> ArraySet<T> toSet(@Nullable List<T> list) { |
| 122 |
return list == null ? null : new ArraySet<T>(list); |
| 123 |
} |
| 124 |
|
| 125 |
private ContentCaptureHelper() { |
| 126 |
throw new UnsupportedOperationException("contains only static methods"); |
| 127 |
} |
| 128 |
} |