• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.contentprotection;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.view.contentcapture.ContentCaptureEvent;
22 import android.view.contentcapture.ViewNode;
23 
24 /**
25  * Utilities for reading data from {@link ContentCaptureEvent} and {@link ViewNode}.
26  *
27  * @hide
28  */
29 public final class ContentProtectionUtils {
30 
31     /** Returns the lowercase text extracted from the {@link ContentCaptureEvent}, if set. */
32     @Nullable
getEventTextLower(@onNull ContentCaptureEvent event)33     public static String getEventTextLower(@NonNull ContentCaptureEvent event) {
34         CharSequence text = event.getText();
35         if (text == null) {
36             return null;
37         }
38         return text.toString().toLowerCase();
39     }
40 
41     /** Returns the lowercase text extracted from the {@link ViewNode}, if set. */
42     @Nullable
getViewNodeTextLower(@ullable ViewNode viewNode)43     public static String getViewNodeTextLower(@Nullable ViewNode viewNode) {
44         if (viewNode == null) {
45             return null;
46         }
47         CharSequence text = viewNode.getText();
48         if (text == null) {
49             return null;
50         }
51         return text.toString().toLowerCase();
52     }
53 
54     /** Returns the lowercase hint text extracted from the {@link ViewNode}, if set. */
55     @Nullable
getHintTextLower(@ullable ViewNode viewNode)56     public static String getHintTextLower(@Nullable ViewNode viewNode) {
57         if (viewNode == null) {
58             return null;
59         }
60         String text = viewNode.getHint();
61         if (text == null) {
62             return null;
63         }
64         return text.toLowerCase();
65     }
66 }
67