Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 1 | /* |
| 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 Toki | f1d9399 | 2018-03-02 13:53:21 +0000 | [diff] [blame] | 17 | package android.view.textclassifier; |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 18 | |
Jan Althaus | 5a03094 | 2018-04-04 19:40:38 +0200 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 20 | |
| 21 | import com.android.internal.annotations.VisibleForTesting; |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
Jan Althaus | 5a03094 | 2018-04-04 19:40:38 +0200 | [diff] [blame] | 24 | * A helper for logging selection session events. |
Tony Mak | 293bdf3 | 2020-02-18 11:33:43 +0000 | [diff] [blame] | 25 | * |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 26 | * @hide |
| 27 | */ |
Jan Althaus | 5a03094 | 2018-04-04 19:40:38 +0200 | [diff] [blame] | 28 | public final class SelectionSessionLogger { |
Tony Mak | 293bdf3 | 2020-02-18 11:33:43 +0000 | [diff] [blame] | 29 | // Keep this in sync with the ResultIdUtils in libtextclassifier. |
| 30 | private static final String CLASSIFIER_ID = "androidtc"; |
Jan Althaus | 92c6dec | 2018-02-02 09:20:14 +0100 | [diff] [blame] | 31 | |
Abodunrinwa Toki | 6c56467 | 2019-05-09 02:03:40 +0100 | [diff] [blame] | 32 | static boolean isPlatformLocalTextClassifierSmartSelection(String signature) { |
| 33 | return SelectionSessionLogger.CLASSIFIER_ID.equals( |
| 34 | SelectionSessionLogger.SignatureParser.getClassifierId(signature)); |
| 35 | } |
| 36 | |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 37 | /** |
Abodunrinwa Toki | 080c854 | 2018-03-27 00:04:06 +0100 | [diff] [blame] | 38 | * Helper for creating and parsing string ids for |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 39 | * {@link android.view.textclassifier.TextClassifierImpl}. |
| 40 | */ |
| 41 | @VisibleForTesting |
| 42 | public static final class SignatureParser { |
| 43 | |
Jan Althaus | 5a03094 | 2018-04-04 19:40:38 +0200 | [diff] [blame] | 44 | static String getClassifierId(@Nullable String signature) { |
| 45 | if (signature == null) { |
| 46 | return ""; |
| 47 | } |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 48 | final int end = signature.indexOf("|"); |
| 49 | if (end >= 0) { |
| 50 | return signature.substring(0, end); |
| 51 | } |
| 52 | return ""; |
| 53 | } |
Abodunrinwa Toki | 3bb4436 | 2017-12-05 07:33:41 +0000 | [diff] [blame] | 54 | } |
| 55 | } |