Loading core/java/android/view/textclassifier/TextClassification.java +25 −2 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public final class TextClassification { @NonNull private final EntityConfidence<String> mEntityConfidence; @NonNull private final List<String> mEntities; private int mLogType; @NonNull private final String mVersionInfo; private TextClassification( @Nullable String text, Loading @@ -56,7 +57,8 @@ public final class TextClassification { @Nullable Intent intent, @Nullable OnClickListener onClickListener, @NonNull EntityConfidence<String> entityConfidence, int logType) { int logType, @NonNull String versionInfo) { mText = text; mIcon = icon; mLabel = label; Loading @@ -65,6 +67,7 @@ public final class TextClassification { mEntityConfidence = new EntityConfidence<>(entityConfidence); mEntities = mEntityConfidence.getEntities(); mLogType = logType; mVersionInfo = versionInfo; } /** Loading Loading @@ -145,6 +148,15 @@ public final class TextClassification { return mLogType; } /** * Returns information about the classifier model used to generate this TextClassification. * @hide */ @NonNull public String getVersionInfo() { return mVersionInfo; } @Override public String toString() { return String.format("TextClassification {" Loading Loading @@ -179,6 +191,7 @@ public final class TextClassification { @NonNull private final EntityConfidence<String> mEntityConfidence = new EntityConfidence<>(); private int mLogType; @NonNull private String mVersionInfo = ""; /** * Sets the classified text. Loading Loading @@ -243,12 +256,22 @@ public final class TextClassification { return this; } /** * Sets information about the classifier model used to generate this TextClassification. * @hide */ Builder setVersionInfo(@NonNull String versionInfo) { mVersionInfo = Preconditions.checkNotNull(mVersionInfo); return this; } /** * Builds and returns a {@link TextClassification} object. */ public TextClassification build() { return new TextClassification( mText, mIcon, mLabel, mIntent, mOnClickListener, mEntityConfidence, mLogType); mText, mIcon, mLabel, mIntent, mOnClickListener, mEntityConfidence, mLogType, mVersionInfo); } } } core/java/android/view/textclassifier/TextClassifier.java +6 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,11 @@ import java.lang.annotation.RetentionPolicy; */ public interface TextClassifier { /** @hide */ String DEFAULT_LOG_TAG = "TextClassifierImpl"; /** @hide */ String TYPE_UNKNOWN = ""; // TODO: Make this public API. String TYPE_OTHER = "other"; String TYPE_EMAIL = "email"; String TYPE_PHONE = "phone"; Loading @@ -43,7 +48,7 @@ public interface TextClassifier { /** @hide */ @Retention(RetentionPolicy.SOURCE) @StringDef({ TYPE_OTHER, TYPE_EMAIL, TYPE_PHONE, TYPE_ADDRESS, TYPE_URL TYPE_UNKNOWN, TYPE_OTHER, TYPE_EMAIL, TYPE_PHONE, TYPE_ADDRESS, TYPE_URL }) @interface EntityType {} Loading core/java/android/view/textclassifier/TextClassifierImpl.java +21 −5 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ import java.util.regex.Pattern; */ final class TextClassifierImpl implements TextClassifier { private static final String LOG_TAG = "TextClassifierImpl"; private static final String LOG_TAG = DEFAULT_LOG_TAG; private static final String MODEL_DIR = "/etc/textclassifier/"; private static final String MODEL_FILE_REGEX = "textclassifier\\.smartselection\\.(.*)\\.model"; private static final String UPDATED_MODEL_FILE_PATH = Loading @@ -86,6 +86,8 @@ final class TextClassifierImpl implements TextClassifier { @GuardedBy("mSmartSelectionLock") // Do not access outside this lock. private Locale mLocale; @GuardedBy("mSmartSelectionLock") // Do not access outside this lock. private int mVersion; @GuardedBy("mSmartSelectionLock") // Do not access outside this lock. private SmartSelection mSmartSelection; TextClassifierImpl(Context context) { Loading @@ -108,8 +110,7 @@ final class TextClassifierImpl implements TextClassifier { if (start <= end && start >= 0 && end <= string.length() && start <= selectionStartIndex && end >= selectionEndIndex) { final TextSelection.Builder tsBuilder = new TextSelection.Builder(start, end) .setLogSource(LOG_TAG); final TextSelection.Builder tsBuilder = new TextSelection.Builder(start, end); final SmartSelection.ClassificationResult[] results = smartSelection.classifyText( string, start, end, Loading @@ -118,7 +119,10 @@ final class TextClassifierImpl implements TextClassifier { for (int i = 0; i < size; i++) { tsBuilder.setEntityType(results[i].mCollection, results[i].mScore); } return tsBuilder.build(); return tsBuilder .setLogSource(LOG_TAG) .setVersionInfo(getVersionInfo()) .build(); } else { // We can not trust the result. Log the issue and ignore the result. Log.d(LOG_TAG, "Got bad indices for input text. Ignoring result."); Loading Loading @@ -202,6 +206,16 @@ final class TextClassifierImpl implements TextClassifier { } } @NonNull private String getVersionInfo() { synchronized (mSmartSelectionLock) { if (mLocale != null) { return String.format("%s_v%d", mLocale.toLanguageTag(), mVersion); } return ""; } } @GuardedBy("mSmartSelectionLock") // Do not call outside this lock. private ParcelFileDescriptor getFdLocked(Locale locale) throws FileNotFoundException { ParcelFileDescriptor updateFd; Loading Loading @@ -256,9 +270,11 @@ final class TextClassifierImpl implements TextClassifier { final int factoryVersion = SmartSelection.getVersion(factoryFd.getFd()); if (updateVersion > factoryVersion) { closeAndLogError(factoryFd); mVersion = updateVersion; return updateFd; } else { closeAndLogError(updateFd); mVersion = factoryVersion; return factoryFd; } } Loading Loading @@ -374,7 +390,7 @@ final class TextClassifierImpl implements TextClassifier { builder.setLabel(label != null ? label.toString() : null); } } return builder.build(); return builder.setVersionInfo(getVersionInfo()).build(); } private static int getHintFlags(CharSequence text, int start, int end) { Loading core/java/android/view/textclassifier/TextSelection.java +25 −2 Original line number Diff line number Diff line Loading @@ -35,15 +35,17 @@ public final class TextSelection { @NonNull private final EntityConfidence<String> mEntityConfidence; @NonNull private final List<String> mEntities; @NonNull private final String mLogSource; @NonNull private final String mVersionInfo; private TextSelection( int startIndex, int endIndex, @NonNull EntityConfidence<String> entityConfidence, @NonNull String logSource) { @NonNull String logSource, @NonNull String versionInfo) { mStartIndex = startIndex; mEndIndex = endIndex; mEntityConfidence = new EntityConfidence<>(entityConfidence); mEntities = mEntityConfidence.getEntities(); mLogSource = logSource; mVersionInfo = versionInfo; } /** Loading Loading @@ -94,10 +96,20 @@ public final class TextSelection { * Returns a tag for the source classifier used to generate this result. * @hide */ @NonNull public String getSourceClassifier() { return mLogSource; } /** * Returns information about the classifier model used to generate this TextSelection. * @hide */ @NonNull public String getVersionInfo() { return mVersionInfo; } @Override public String toString() { return String.format("TextSelection {%d, %d, %s}", Loading @@ -114,6 +126,7 @@ public final class TextSelection { @NonNull private final EntityConfidence<String> mEntityConfidence = new EntityConfidence<>(); @NonNull private String mLogSource = ""; @NonNull private String mVersionInfo = ""; /** * Creates a builder used to build {@link TextSelection} objects. Loading Loading @@ -151,11 +164,21 @@ public final class TextSelection { return this; } /** * Sets information about the classifier model used to generate this TextSelection. * @hide */ Builder setVersionInfo(@NonNull String versionInfo) { mVersionInfo = Preconditions.checkNotNull(mVersionInfo); return this; } /** * Builds and returns {@link TextSelection} object. */ public TextSelection build() { return new TextSelection(mStartIndex, mEndIndex, mEntityConfidence, mLogSource); return new TextSelection( mStartIndex, mEndIndex, mEntityConfidence, mLogSource, mVersionInfo); } } } core/java/android/view/textclassifier/logging/SmartSelectionEventTracker.java 0 → 100644 +560 −0 File added.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/view/textclassifier/TextClassification.java +25 −2 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public final class TextClassification { @NonNull private final EntityConfidence<String> mEntityConfidence; @NonNull private final List<String> mEntities; private int mLogType; @NonNull private final String mVersionInfo; private TextClassification( @Nullable String text, Loading @@ -56,7 +57,8 @@ public final class TextClassification { @Nullable Intent intent, @Nullable OnClickListener onClickListener, @NonNull EntityConfidence<String> entityConfidence, int logType) { int logType, @NonNull String versionInfo) { mText = text; mIcon = icon; mLabel = label; Loading @@ -65,6 +67,7 @@ public final class TextClassification { mEntityConfidence = new EntityConfidence<>(entityConfidence); mEntities = mEntityConfidence.getEntities(); mLogType = logType; mVersionInfo = versionInfo; } /** Loading Loading @@ -145,6 +148,15 @@ public final class TextClassification { return mLogType; } /** * Returns information about the classifier model used to generate this TextClassification. * @hide */ @NonNull public String getVersionInfo() { return mVersionInfo; } @Override public String toString() { return String.format("TextClassification {" Loading Loading @@ -179,6 +191,7 @@ public final class TextClassification { @NonNull private final EntityConfidence<String> mEntityConfidence = new EntityConfidence<>(); private int mLogType; @NonNull private String mVersionInfo = ""; /** * Sets the classified text. Loading Loading @@ -243,12 +256,22 @@ public final class TextClassification { return this; } /** * Sets information about the classifier model used to generate this TextClassification. * @hide */ Builder setVersionInfo(@NonNull String versionInfo) { mVersionInfo = Preconditions.checkNotNull(mVersionInfo); return this; } /** * Builds and returns a {@link TextClassification} object. */ public TextClassification build() { return new TextClassification( mText, mIcon, mLabel, mIntent, mOnClickListener, mEntityConfidence, mLogType); mText, mIcon, mLabel, mIntent, mOnClickListener, mEntityConfidence, mLogType, mVersionInfo); } } }
core/java/android/view/textclassifier/TextClassifier.java +6 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,11 @@ import java.lang.annotation.RetentionPolicy; */ public interface TextClassifier { /** @hide */ String DEFAULT_LOG_TAG = "TextClassifierImpl"; /** @hide */ String TYPE_UNKNOWN = ""; // TODO: Make this public API. String TYPE_OTHER = "other"; String TYPE_EMAIL = "email"; String TYPE_PHONE = "phone"; Loading @@ -43,7 +48,7 @@ public interface TextClassifier { /** @hide */ @Retention(RetentionPolicy.SOURCE) @StringDef({ TYPE_OTHER, TYPE_EMAIL, TYPE_PHONE, TYPE_ADDRESS, TYPE_URL TYPE_UNKNOWN, TYPE_OTHER, TYPE_EMAIL, TYPE_PHONE, TYPE_ADDRESS, TYPE_URL }) @interface EntityType {} Loading
core/java/android/view/textclassifier/TextClassifierImpl.java +21 −5 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ import java.util.regex.Pattern; */ final class TextClassifierImpl implements TextClassifier { private static final String LOG_TAG = "TextClassifierImpl"; private static final String LOG_TAG = DEFAULT_LOG_TAG; private static final String MODEL_DIR = "/etc/textclassifier/"; private static final String MODEL_FILE_REGEX = "textclassifier\\.smartselection\\.(.*)\\.model"; private static final String UPDATED_MODEL_FILE_PATH = Loading @@ -86,6 +86,8 @@ final class TextClassifierImpl implements TextClassifier { @GuardedBy("mSmartSelectionLock") // Do not access outside this lock. private Locale mLocale; @GuardedBy("mSmartSelectionLock") // Do not access outside this lock. private int mVersion; @GuardedBy("mSmartSelectionLock") // Do not access outside this lock. private SmartSelection mSmartSelection; TextClassifierImpl(Context context) { Loading @@ -108,8 +110,7 @@ final class TextClassifierImpl implements TextClassifier { if (start <= end && start >= 0 && end <= string.length() && start <= selectionStartIndex && end >= selectionEndIndex) { final TextSelection.Builder tsBuilder = new TextSelection.Builder(start, end) .setLogSource(LOG_TAG); final TextSelection.Builder tsBuilder = new TextSelection.Builder(start, end); final SmartSelection.ClassificationResult[] results = smartSelection.classifyText( string, start, end, Loading @@ -118,7 +119,10 @@ final class TextClassifierImpl implements TextClassifier { for (int i = 0; i < size; i++) { tsBuilder.setEntityType(results[i].mCollection, results[i].mScore); } return tsBuilder.build(); return tsBuilder .setLogSource(LOG_TAG) .setVersionInfo(getVersionInfo()) .build(); } else { // We can not trust the result. Log the issue and ignore the result. Log.d(LOG_TAG, "Got bad indices for input text. Ignoring result."); Loading Loading @@ -202,6 +206,16 @@ final class TextClassifierImpl implements TextClassifier { } } @NonNull private String getVersionInfo() { synchronized (mSmartSelectionLock) { if (mLocale != null) { return String.format("%s_v%d", mLocale.toLanguageTag(), mVersion); } return ""; } } @GuardedBy("mSmartSelectionLock") // Do not call outside this lock. private ParcelFileDescriptor getFdLocked(Locale locale) throws FileNotFoundException { ParcelFileDescriptor updateFd; Loading Loading @@ -256,9 +270,11 @@ final class TextClassifierImpl implements TextClassifier { final int factoryVersion = SmartSelection.getVersion(factoryFd.getFd()); if (updateVersion > factoryVersion) { closeAndLogError(factoryFd); mVersion = updateVersion; return updateFd; } else { closeAndLogError(updateFd); mVersion = factoryVersion; return factoryFd; } } Loading Loading @@ -374,7 +390,7 @@ final class TextClassifierImpl implements TextClassifier { builder.setLabel(label != null ? label.toString() : null); } } return builder.build(); return builder.setVersionInfo(getVersionInfo()).build(); } private static int getHintFlags(CharSequence text, int start, int end) { Loading
core/java/android/view/textclassifier/TextSelection.java +25 −2 Original line number Diff line number Diff line Loading @@ -35,15 +35,17 @@ public final class TextSelection { @NonNull private final EntityConfidence<String> mEntityConfidence; @NonNull private final List<String> mEntities; @NonNull private final String mLogSource; @NonNull private final String mVersionInfo; private TextSelection( int startIndex, int endIndex, @NonNull EntityConfidence<String> entityConfidence, @NonNull String logSource) { @NonNull String logSource, @NonNull String versionInfo) { mStartIndex = startIndex; mEndIndex = endIndex; mEntityConfidence = new EntityConfidence<>(entityConfidence); mEntities = mEntityConfidence.getEntities(); mLogSource = logSource; mVersionInfo = versionInfo; } /** Loading Loading @@ -94,10 +96,20 @@ public final class TextSelection { * Returns a tag for the source classifier used to generate this result. * @hide */ @NonNull public String getSourceClassifier() { return mLogSource; } /** * Returns information about the classifier model used to generate this TextSelection. * @hide */ @NonNull public String getVersionInfo() { return mVersionInfo; } @Override public String toString() { return String.format("TextSelection {%d, %d, %s}", Loading @@ -114,6 +126,7 @@ public final class TextSelection { @NonNull private final EntityConfidence<String> mEntityConfidence = new EntityConfidence<>(); @NonNull private String mLogSource = ""; @NonNull private String mVersionInfo = ""; /** * Creates a builder used to build {@link TextSelection} objects. Loading Loading @@ -151,11 +164,21 @@ public final class TextSelection { return this; } /** * Sets information about the classifier model used to generate this TextSelection. * @hide */ Builder setVersionInfo(@NonNull String versionInfo) { mVersionInfo = Preconditions.checkNotNull(mVersionInfo); return this; } /** * Builds and returns {@link TextSelection} object. */ public TextSelection build() { return new TextSelection(mStartIndex, mEndIndex, mEntityConfidence, mLogSource); return new TextSelection( mStartIndex, mEndIndex, mEntityConfidence, mLogSource, mVersionInfo); } } }
core/java/android/view/textclassifier/logging/SmartSelectionEventTracker.java 0 → 100644 +560 −0 File added.Preview size limit exceeded, changes collapsed. Show changes