blob: e7d896eb3f23e97dcb03a482a6a03cf8d25cfd9e [file] [log] [blame]
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +00001/*
2 * Copyright (C) 2017 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
Abodunrinwa Tokif1d93992018-03-02 13:53:21 +000017package android.view.textclassifier;
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000018
Jan Althaus5a030942018-04-04 19:40:38 +020019import android.annotation.Nullable;
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000020
21import com.android.internal.annotations.VisibleForTesting;
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000022
23/**
Jan Althaus5a030942018-04-04 19:40:38 +020024 * A helper for logging selection session events.
Tony Mak293bdf32020-02-18 11:33:43 +000025 *
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000026 * @hide
27 */
Jan Althaus5a030942018-04-04 19:40:38 +020028public final class SelectionSessionLogger {
Tony Mak293bdf32020-02-18 11:33:43 +000029 // Keep this in sync with the ResultIdUtils in libtextclassifier.
30 private static final String CLASSIFIER_ID = "androidtc";
Jan Althaus92c6dec2018-02-02 09:20:14 +010031
Abodunrinwa Toki6c564672019-05-09 02:03:40 +010032 static boolean isPlatformLocalTextClassifierSmartSelection(String signature) {
33 return SelectionSessionLogger.CLASSIFIER_ID.equals(
34 SelectionSessionLogger.SignatureParser.getClassifierId(signature));
35 }
36
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000037 /**
Abodunrinwa Toki080c8542018-03-27 00:04:06 +010038 * Helper for creating and parsing string ids for
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000039 * {@link android.view.textclassifier.TextClassifierImpl}.
40 */
41 @VisibleForTesting
42 public static final class SignatureParser {
43
Jan Althaus5a030942018-04-04 19:40:38 +020044 static String getClassifierId(@Nullable String signature) {
45 if (signature == null) {
46 return "";
47 }
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000048 final int end = signature.indexOf("|");
49 if (end >= 0) {
50 return signature.substring(0, end);
51 }
52 return "";
53 }
Abodunrinwa Toki3bb44362017-12-05 07:33:41 +000054 }
55}