blob: 1fb9032c9af5e5ead22e49bc23b5d6e9183ee953 [file] [log] [blame]
Felipe Leme284ad1c2018-11-15 18:16:12 -08001/*
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 */
Felipe Leme749b8892018-12-03 16:30:30 -080016package android.service.autofill.augmented;
Felipe Leme284ad1c2018-11-15 18:16:12 -080017
18import android.annotation.IntDef;
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
Felipe Leme2cab38c2019-01-11 10:39:14 -080022import android.annotation.TestApi;
Felipe Leme284ad1c2018-11-15 18:16:12 -080023import android.graphics.Rect;
Felipe Leme749b8892018-12-03 16:30:30 -080024import android.service.autofill.augmented.AugmentedAutofillService.AutofillProxy;
Felipe Leme284ad1c2018-11-15 18:16:12 -080025import android.util.DebugUtils;
26import android.view.View;
27
28import java.io.PrintWriter;
29import java.lang.annotation.Retention;
30import java.lang.annotation.RetentionPolicy;
31
32/**
33 * Abstraction of a "Smart Suggestion" component responsible to embed the autofill UI provided by
34 * the intelligence service.
35 *
36 * <p>The Smart Suggestion can embed the autofill UI in 3 distinct places:
37 *
38 * <ul>
39 * <li>A small area associated with suggestions (like a small strip in the top of the IME),
40 * returned by {@link #getSuggestionArea()}
41 * <li>The full area (like the full IME window), returned by {@link #getFullArea()}
42 * <li>A subset of the aforementioned areas, returned by {@link Area#getSubArea(Rect)}
43 * </ul>
44 *
45 * <p>The Smart Suggestion is represented by a {@link Area} object that contains the
46 * dimensions the smart suggestion window, so the service can use it to calculate the size of the
47 * view that will be passed to {@link FillWindow#update(Area, View, long)}.
48 *
49 * @hide
50 */
51@SystemApi
Felipe Leme2cab38c2019-01-11 10:39:14 -080052@TestApi
53//TODO(b/122654591): @TestApi is needed because CtsAutoFillServiceTestCases hosts the service
54//in the same package as the test, and that module is compiled with SDK=test_current
Felipe Leme284ad1c2018-11-15 18:16:12 -080055public abstract class PresentationParams {
56
57 /**
58 * Flag indicating the Smart Suggestion is hosted in the top of its container.
59 */
60 public static final int FLAG_HINT_GRAVITY_TOP = 0x1;
61
62 /**
63 * Flag indicating the Smart Suggestion is hosted in the bottom of its container.
64 */
65 public static final int FLAG_HINT_GRAVITY_BOTTOM = 0x2;
66
67 /**
68 * Flag indicating the Smart Suggestion is hosted in the left of its container.
69 */
70 public static final int FLAG_HINT_GRAVITY_LEFT = 0x4;
71
72 /**
73 * Flag indicating the Smart Suggestion is hosted in the right of its container.
74 */
75 public static final int FLAG_HINT_GRAVITY_RIGHT = 0x8;
76
77 /**
78 * Flag indicating the Smart Suggestion is hosted by the IME.
79 */
80 public static final int FLAG_HOST_IME = 0x10;
81
82 /**
83 * Flag indicating the Smart Suggestion is hosted by the Android System as a floating popup
84 * window.
85 */
86 public static final int FLAG_HOST_SYSTEM = 0x20;
87
88 /** @hide */
89 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
90 FLAG_HINT_GRAVITY_TOP,
91 FLAG_HINT_GRAVITY_BOTTOM,
92 FLAG_HINT_GRAVITY_LEFT,
93 FLAG_HINT_GRAVITY_RIGHT,
94 FLAG_HOST_IME,
95 FLAG_HOST_SYSTEM
96 })
97 @Retention(RetentionPolicy.SOURCE)
98 @interface Flags {}
99
100
101 // /** @hide */
102 PresentationParams() {}
103
104 /**
105 * Gets the area of the suggestion strip for the given {@code metadata}
106 *
107 * @return strip dimensions, or {@code null} if the Smart Suggestion provider does not support
108 * suggestions strip.
109 */
110 @Nullable
111 public Area getSuggestionArea() {
112 return null;
113 }
114
115 /**
116 * Gets the full area for the of the Smart Suggestion provider.
117 *
118 * @return full dimensions, or {@code null} if the Smart Suggestion provider does not support
119 * embeding the UI on its full area.
120 */
121 @Nullable
122 public Area getFullArea() {
123 return null;
124 }
125
126 /**
127 * Gets flags associated with the Smart Suggestion.
128 *
129 * @return any combination of {@link #FLAG_HINT_GRAVITY_TOP},
130 * {@link #FLAG_HINT_GRAVITY_BOTTOM}, {@link #FLAG_HINT_GRAVITY_LEFT},
131 * {@link #FLAG_HINT_GRAVITY_RIGHT}, {@link #FLAG_HOST_IME}, or
132 * {@link #FLAG_HOST_SYSTEM},
133 */
134 public @Flags int getFlags() {
135 return 0;
136 }
137
138 /** @hide */
139 void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
140 final int flags = getFlags();
141 if (flags > 0) {
142 pw.print(prefix); pw.print("flags: "); pw.println(flagsToString(flags));
143 }
144 }
145
146 private static String flagsToString(int flags) {
147 return DebugUtils.flagsToString(PresentationParams.class, "FLAG_", flags);
148 }
149
150 /**
151 * Area associated with a {@link PresentationParams Smart Suggestions} provider.
152 *
153 * @hide
Felipe Leme2cab38c2019-01-11 10:39:14 -0800154 */
Felipe Leme284ad1c2018-11-15 18:16:12 -0800155 @SystemApi
Felipe Leme2cab38c2019-01-11 10:39:14 -0800156 @TestApi
157 //TODO(b/122654591): @TestApi is needed because CtsAutoFillServiceTestCases hosts the service
158 //in the same package as the test, and that module is compiled with SDK=test_current
Felipe Leme284ad1c2018-11-15 18:16:12 -0800159 public abstract static class Area {
160
161 /** @hide */
162 public final AutofillProxy proxy;
163
164 private final Rect mBounds;
165
166 private Area(@NonNull AutofillProxy proxy, @NonNull Rect bounds) {
167 this.proxy = proxy;
168 mBounds = bounds;
169 }
170
171 /**
172 * Gets the area boundaries.
173 */
174 @NonNull
175 public Rect getBounds() {
176 return mBounds;
177 }
178
179 /**
180 * Gets a subarea limited by given boundaries.
181 *
182 * @param bounds boundaries relative to this Area.
183 *
Felipe Leme284ad1c2018-11-15 18:16:12 -0800184 * @return new subarea, or {@code null} if the Smart Suggestion host does not support such
185 * subaarea.
Felipe Leme749b8892018-12-03 16:30:30 -0800186 *
187 * @throws IllegalArgumentException if the {@code bounds} is not fully-contained inside this
188 * full Area.
189 *
Felipe Leme284ad1c2018-11-15 18:16:12 -0800190 */
191 @Nullable
192 public Area getSubArea(@NonNull Rect bounds) {
Felipe Leme559e21d2019-01-18 17:57:21 -0800193 // TODO(b/123100712): implement / check boundaries / throw IAE / add unit test
Felipe Leme284ad1c2018-11-15 18:16:12 -0800194 return null;
195 }
196
197 @Override
198 public String toString() {
199 return mBounds.toString();
200 }
201 }
202
203 /**
204 * System-provided poup window anchored to a view.
205 *
206 * <p>Used just for debugging purposes.
207 *
208 * @hide
209 */
210 public static final class SystemPopupPresentationParams extends PresentationParams {
211 private final Area mSuggestionArea;
212
213 public SystemPopupPresentationParams(@NonNull AutofillProxy proxy, @NonNull Rect rect) {
214 mSuggestionArea = new Area(proxy, rect) {};
215 }
216
217 @Override
218 public Area getSuggestionArea() {
219 return mSuggestionArea;
220 }
221
222 @Override
223 public int getFlags() {
224 return FLAG_HOST_SYSTEM | FLAG_HINT_GRAVITY_BOTTOM;
225 }
226
227 @Override
228 void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
229 super.dump(prefix, pw);
230 pw.print(prefix); pw.print("area: "); pw.println(mSuggestionArea);
231 }
232 }
233}