xref: /aosp_15_r20/external/libtextclassifier/native/utils/intents/intent-config.fbs (revision 993b0882672172b81d12fad7a7ac0c3e5c824a12)
1//
2// Copyright (C) 2018 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
17include "utils/zlib/buffer.fbs";
18
19// The type of variable to fetch.
20namespace libtextclassifier3;
21enum AndroidSimpleIntentGeneratorVariableType : int {
22  INVALID_VARIABLE = 0,
23
24  // The raw text that was classified.
25  RAW_TEXT = 1,
26
27  // Text as a URL with explicit protocol. If no protocol was specified, http
28  // is prepended.
29  URL_TEXT = 2,
30
31  // The raw text, but URL encoded.
32  URL_ENCODED_TEXT = 3,
33
34  // For dates/times: the instant of the event in UTC millis.
35  EVENT_TIME_MS_UTC = 4,
36
37  // For dates/times: the start of the event in UTC millis.
38  EVENT_START_MS_UTC = 5,
39
40  // For dates/times: the end of the event in UTC millis.
41  EVENT_END_MS_UTC = 6,
42
43  // Name of the package that's running the classifier.
44  PACKAGE_NAME = 7,
45}
46
47// Enumerates the possible extra types for the simple intent generator.
48namespace libtextclassifier3;
49enum AndroidSimpleIntentGeneratorExtraType : int {
50  INVALID_EXTRA_TYPE = 0,
51  STRING = 1,
52  // Use string_ field.
53
54  BOOL = 2,
55  // Use bool_ field.
56
57  VARIABLE_AS_LONG = 3,
58  // Use int32_ field for the variable index.
59}
60
61// Enumerates the possible condition types for the simple intent generator.
62namespace libtextclassifier3;
63enum AndroidSimpleIntentGeneratorConditionType : int {
64  INVALID_CONDITION_TYPE = 0,
65
66  // Queries the UserManager for the given boolean restriction. The condition
67  // passes if the result is of getBoolean is false. The name of the
68  // restriction to check is in the string_ field.
69  USER_RESTRICTION_NOT_SET = 1,
70
71  // Checks that the parsed event start time is at least a give number of
72  // milliseconds in the future. (Only valid if there is a parsed event
73  // time) The offset is stored in the int64_ field.
74  EVENT_START_IN_FUTURE_MS = 2,
75}
76
77// Describes how intents for the various entity types should be generated on
78// Android. This is distributed through the model, but not used by
79// libtextclassifier yet - rather, it's passed to the calling Java code, which
80// implements the Intent generation logic.
81namespace libtextclassifier3;
82table AndroidIntentFactoryOptions {
83  entity:[AndroidIntentFactoryEntityOptions];
84}
85
86// Describes how intents should be generated for a particular entity type.
87namespace libtextclassifier3;
88table AndroidIntentFactoryEntityOptions {
89  // The entity type as defined by one of the TextClassifier ENTITY_TYPE
90  // constants. (e.g. "address", "phone", etc.)
91  entity_type:string (shared);
92
93  // List of generators for all the different types of intents that should
94  // be made available for the entity type.
95  generator:[AndroidIntentGeneratorOptions];
96}
97
98// Configures a single Android Intent generator.
99namespace libtextclassifier3;
100table AndroidIntentGeneratorOptions {
101  // Strings for UI elements.
102  strings:[AndroidIntentGeneratorStrings];
103
104  // Generator specific configuration.
105  simple:AndroidSimpleIntentGeneratorOptions;
106}
107
108// Language dependent configuration for an Android Intent generator.
109namespace libtextclassifier3;
110table AndroidIntentGeneratorStrings {
111  // BCP 47 tag for the supported locale. Note that because of API level
112  // restrictions, this must /not/ use wildcards. To e.g. match all English
113  // locales, use only "en" and not "en_*". Reference the java.util.Locale
114  // constructor for details.
115  language_tag:string (shared);
116
117  // Title shown for the action (see RemoteAction.getTitle).
118  title:string (shared);
119
120  // Description shown for the action (see
121  // RemoteAction.getContentDescription).
122  description:string (shared);
123}
124
125// An extra to set on a simple intent generator Intent.
126namespace libtextclassifier3;
127table AndroidSimpleIntentGeneratorExtra {
128  // The name of the extra to set.
129  name:string (shared);
130
131  // The type of the extra to set.
132  type:AndroidSimpleIntentGeneratorExtraType;
133
134  string_:string (shared);
135  bool_:bool;
136  int32_:int;
137}
138
139// A condition that needs to be fulfilled for an Intent to get generated.
140namespace libtextclassifier3;
141table AndroidSimpleIntentGeneratorCondition {
142  type:AndroidSimpleIntentGeneratorConditionType;
143  string_:string (shared);
144  int32_:int;
145  int64_:long;
146}
147
148// Configures an intent generator where the logic is simple to be expressed with
149// basic rules - which covers the vast majority of use cases and is analogous
150// to Android Actions.
151// Most strings (action, data, type, ...) may contain variable references. To
152// use them, the generator must first declare all the variables it wishes to use
153// in the variables field. The values then become available as numbered
154// arguments (using the normal java.util.Formatter syntax) in the order they
155// were specified.
156namespace libtextclassifier3;
157table AndroidSimpleIntentGeneratorOptions {
158  // The action to set on the Intent (see Intent.setAction). Supports variables.
159  action:string (shared);
160
161  // The data to set on the Intent (see Intent.setData). Supports variables.
162  data:string (shared);
163
164  // The type to set on the Intent (see Intent.setType). Supports variables.
165  type:string (shared);
166
167  // The list of all the extras to add to the Intent.
168  extra:[AndroidSimpleIntentGeneratorExtra];
169
170  // The list of all the variables that become available for substitution in
171  // the action, data, type and extra strings. To e.g. set a field to the value
172  // of the first variable, use "%0$s".
173  variable:[AndroidSimpleIntentGeneratorVariableType];
174
175  // The list of all conditions that need to be fulfilled for Intent generation.
176  condition:[AndroidSimpleIntentGeneratorCondition];
177}
178
179// Describes how intents should be generated for a particular entity type.
180namespace libtextclassifier3.IntentFactoryModel_;
181table IntentGenerator {
182  // The type of the intent generator, e.g. the entity type as defined by
183  // on the TextClassifier ENTITY_TYPE constants e.g. "address", "phone", etc.
184  type:string (shared);
185
186  // The template generator lua code, either as text source or precompiled
187  // bytecode.
188  lua_template_generator:[ubyte];
189
190  compressed_lua_template_generator:CompressedBuffer;
191}
192
193// Describes how intents for the various entity types should be generated.
194namespace libtextclassifier3;
195table IntentFactoryModel {
196  generator:[IntentFactoryModel_.IntentGenerator];
197
198  // Whether to precompile the generators when loading.
199  precompile_generators:bool = false;
200}
201
202