blob: 84b8ba112630e850cba066dadef81d704a4b3b7a [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyalc190dbf2016-05-05 14:37:05 -070019import android.database.sqlite.SQLiteDatabase;
Adam Cohendf2cc412011-04-27 16:56:57 -070020import android.provider.BaseColumns;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021
Stefan Andoniane8b86db2023-10-27 21:38:16 +000022import androidx.annotation.NonNull;
23
Sunny Goyale396abf2020-04-06 15:11:17 -070024import com.android.launcher3.model.data.ItemInfo;
25
Stefan Andoniane8b86db2023-10-27 21:38:16 +000026import java.util.LinkedHashMap;
27import java.util.stream.Collectors;
28
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029/**
30 * Settings related utilities.
31 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070032public class LauncherSettings {
Sunny Goyalc5939392018-12-07 11:43:47 -080033
34 /**
Luca Zuccarini20983812023-01-03 14:19:48 +000035 * Types of animations.
36 */
37 public static final class Animation {
38 /**
39 * The default animation for a given view/item info type.
40 */
41 public static final int DEFAULT = 0;
42 /**
43 * An animation using the view's background.
44 */
45 public static final int VIEW_BACKGROUND = 1;
Hyunyoung Songa38aab92023-03-14 07:56:59 +000046 /**
47 * The default animation for a given view/item info type, but without the splash icon.
48 */
49 public static final int DEFAULT_NO_ICON = 2;
Luca Zuccarini20983812023-01-03 14:19:48 +000050 }
51
52 /**
Sunny Goyalc5939392018-12-07 11:43:47 -080053 * Favorites.
54 */
55 public static final class Favorites implements BaseColumns {
Chris Wren1ada10d2013-09-13 18:01:38 -040056 /**
57 * The time of the last update to this row.
58 * <P>Type: INTEGER</P>
59 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070060 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040061
Romain Guy73b979d2009-06-09 12:57:21 -070062 /**
63 * Descriptive name of the gesture that can be displayed to the user.
64 * <P>Type: TEXT</P>
65 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070066 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070067
68 /**
69 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070070 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070071 * an Intent that can be launched.
72 * <P>Type: TEXT</P>
73 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070074 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070075
76 /**
77 * The type of the gesture
78 *
79 * <P>Type: INTEGER</P>
80 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070081 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070082
83 /**
Samuel Fufad3720c22019-09-06 11:25:08 -070084 * The gesture is a package
85 */
86 public static final int ITEM_TYPE_NON_ACTIONABLE = -1;
87 /**
Romain Guy73b979d2009-06-09 12:57:21 -070088 * The gesture is an application
89 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070090 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070091
92 /**
93 * The gesture is an application created shortcut
Sunny Goyale274d972023-05-01 16:55:59 -070094 * @deprecated This is no longer supported. Use {@link #ITEM_TYPE_DEEP_SHORTCUT} instead
Romain Guy73b979d2009-06-09 12:57:21 -070095 */
Sunny Goyale274d972023-05-01 16:55:59 -070096 @Deprecated
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070097 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070098
99 /**
Andy Wickham19ab1772021-02-10 21:36:51 -0800100 * The favorite is a user created folder
101 */
102 public static final int ITEM_TYPE_FOLDER = 2;
103
104 /**
105 * The favorite is a widget
106 */
107 public static final int ITEM_TYPE_APPWIDGET = 4;
108
109 /**
110 * The favorite is a custom widget provided by the launcher
111 */
112 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
113
114 /**
115 * The gesture is an application created deep shortcut
116 */
117 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
118
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700119 /**
120 * The favorite is an app pair for launching split screen
121 */
122 public static final int ITEM_TYPE_APP_PAIR = 10;
sfufa@google.comca76de02021-09-24 08:55:48 -0700123
Andy Wickham93456812022-10-05 17:58:45 -0700124 // *** Below enum values are used for metrics purpose but not used in Favorites DB ***
sfufa@google.comca76de02021-09-24 08:55:48 -0700125
126 /**
Andy Wickham19ab1772021-02-10 21:36:51 -0800127 * Type of the item is recents task.
Andy Wickham19ab1772021-02-10 21:36:51 -0800128 */
129 public static final int ITEM_TYPE_TASK = 7;
130
131 /**
132 * The item is QSB
133 */
134 public static final int ITEM_TYPE_QSB = 8;
135
136 /**
Andy Wickham93456812022-10-05 17:58:45 -0700137 * The favorite is a search action
138 */
139 public static final int ITEM_TYPE_SEARCH_ACTION = 9;
140
141 /**
Holly Sun20c30c92024-03-05 17:07:56 -0800142 * Private space install app button.
143 */
144 public static final int ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON = 11;
145
146 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -0700147 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -0700148 * <P>Type: BLOB</P>
149 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700150 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -0700151
152 public static final String TABLE_NAME = "favorites";
153
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 /**
Samuel Fufaf667a132020-05-29 14:47:42 -0700155 * Backup table created when user hotseat is moved to workspace for hybrid hotseat
156 */
157 public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
158
159 /**
Tracy Zhouf6018722020-02-06 16:37:16 -0800160 * Temporary table used specifically for multi-db grid migrations
161 */
162 public static final String TMP_TABLE = "favorites_tmp";
163
164 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 * The container holding the favorite
166 * <P>Type: INTEGER</P>
167 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700168 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169
170 /**
171 * The icon is a resource identified by a package name and an integer id.
172 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700173 public static final int CONTAINER_DESKTOP = -100;
174 public static final int CONTAINER_HOTSEAT = -101;
Samuel Fufa866ff002019-08-09 16:16:06 -0700175 public static final int CONTAINER_PREDICTION = -102;
Steven Ng3a835322021-03-02 21:26:00 +0000176 public static final int CONTAINER_WIDGETS_PREDICTION = -111;
Samuel Fufa225ac272019-10-21 02:02:40 -0700177 public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
thiruram261c3a62020-04-29 16:23:15 -0700178 public static final int CONTAINER_ALL_APPS = -104;
thiruram6bf68482020-05-06 22:19:43 -0700179 public static final int CONTAINER_WIDGETS_TRAY = -105;
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100180 public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112;
181 public static final int CONTAINER_PIN_WIDGETS = -113;
Brian Isganitisf0ca4ae2021-09-02 16:08:29 -0400182 public static final int CONTAINER_WALLPAPERS = -114;
thiruram63bf8ee2020-06-01 12:03:19 -0700183 public static final int CONTAINER_SHORTCUTS = -107;
Hyunyoung Songf26c7932020-06-06 14:44:27 -0700184 public static final int CONTAINER_SETTINGS = -108;
Hyunyoung Song13c2bc72020-06-10 00:35:35 -0700185 public static final int CONTAINER_TASKSWITCHER = -109;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186
thiruram73821a92021-02-05 17:50:37 -0800187 // Represents any of the extended containers implemented in non-AOSP variants.
188 public static final int EXTENDED_CONTAINERS = -200;
189
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100190 public static final int CONTAINER_UNKNOWN = -1;
191
Sunny Goyale396abf2020-04-06 15:11:17 -0700192 public static final String containerToString(int container) {
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500193 switch (container) {
194 case CONTAINER_DESKTOP: return "desktop";
195 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700196 case CONTAINER_PREDICTION: return "prediction";
thiruram6bf68482020-05-06 22:19:43 -0700197 case CONTAINER_ALL_APPS: return "all_apps";
198 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
thiruram63bf8ee2020-06-01 12:03:19 -0700199 case CONTAINER_SHORTCUTS: return "shortcuts";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500200 default: return String.valueOf(container);
201 }
202 }
203
Sunny Goyale396abf2020-04-06 15:11:17 -0700204 public static final String itemTypeToString(int type) {
Hyunyoung Song86160f52017-02-06 10:46:24 -0800205 switch(type) {
206 case ITEM_TYPE_APPLICATION: return "APP";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800207 case ITEM_TYPE_FOLDER: return "FOLDER";
208 case ITEM_TYPE_APPWIDGET: return "WIDGET";
209 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
210 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
Andy Wickham19ab1772021-02-10 21:36:51 -0800211 case ITEM_TYPE_TASK: return "TASK";
212 case ITEM_TYPE_QSB: return "QSB";
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700213 case ITEM_TYPE_APP_PAIR: return "APP_PAIR";
Holly Sun20c30c92024-03-05 17:07:56 -0800214 case ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON:
215 return "PRIVATE_SPACE_INSTALL_APP_BUTTON";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800216 default: return String.valueOf(type);
217 }
218 }
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 /**
221 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
222 * <P>Type: INTEGER</P>
223 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700224 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225
226 /**
227 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700228 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 * <P>Type: INTEGER</P>
230 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700231 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232
233 /**
234 * The Y coordinate of the cell holding the favorite
235 * (if container is CONTAINER_DESKTOP)
236 * <P>Type: INTEGER</P>
237 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700238 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800239
240 /**
241 * The X span of the cell holding the favorite
242 * <P>Type: INTEGER</P>
243 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700244 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245
246 /**
247 * The Y span of the cell holding the favorite
248 * <P>Type: INTEGER</P>
249 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700250 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251
252 /**
Kenny Guyed131872014-04-30 03:02:21 +0100253 * The profile id of the item in the cell.
254 * <P>
255 * Type: INTEGER
256 * </P>
257 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700258 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100259
260 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700261 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262 *
263 * <P>Type: INTEGER</P>
264 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700265 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400266
267 /**
268 * The ComponentName of the widget provider
269 *
270 * <P>Type: STRING</P>
271 */
272 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500273
274 /**
275 * Boolean indicating that his item was restored and not yet successfully bound.
276 * <P>Type: INTEGER</P>
277 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700278 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800279
280 /**
281 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
282 * <p>Type: INTEGER</p>
283 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700284 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700285
286 /**
287 * Stores general flag based options for {@link ItemInfo}s.
288 * <p>Type: INTEGER</p>
289 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700290 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700291
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100292 /**
293 * Stores the source container that the widget was added from.
294 * <p>Type: INTEGER</p>
295 */
296 public static final String APPWIDGET_SOURCE = "appWidgetSource";
297
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700298 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700299 addTableToDb(db, myProfileId, optional, TABLE_NAME);
300 }
301
302 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
303 String tableName) {
Stefan Andoniane8b86db2023-10-27 21:38:16 +0000304 db.execSQL("CREATE TABLE " + (optional ? " IF NOT EXISTS " : "") + tableName + " ("
305 + getJoinedColumnsToTypes(myProfileId) + ");");
306 }
307
308 // LinkedHashMap maintains Order of Insertion
309 @NonNull
310 private static LinkedHashMap<String, String> getColumnsToTypes(long profileId) {
311 final LinkedHashMap<String, String> columnsToTypes = new LinkedHashMap<>();
312 columnsToTypes.put(_ID, "INTEGER PRIMARY KEY");
313 columnsToTypes.put(TITLE, "TEXT");
314 columnsToTypes.put(INTENT, "TEXT");
315 columnsToTypes.put(CONTAINER, "INTEGER");
316 columnsToTypes.put(SCREEN, "INTEGER");
317 columnsToTypes.put(CELLX, "INTEGER");
318 columnsToTypes.put(CELLY, "INTEGER");
319 columnsToTypes.put(SPANX, "INTEGER");
320 columnsToTypes.put(SPANY, "INTEGER");
321 columnsToTypes.put(ITEM_TYPE, "INTEGER");
322 columnsToTypes.put(APPWIDGET_ID, "INTEGER NOT NULL DEFAULT -1");
323 columnsToTypes.put(ICON, "BLOB");
324 columnsToTypes.put(APPWIDGET_PROVIDER, "TEXT");
325 columnsToTypes.put(MODIFIED, "INTEGER NOT NULL DEFAULT 0");
326 columnsToTypes.put(RESTORED, "INTEGER NOT NULL DEFAULT 0");
327 columnsToTypes.put(PROFILE_ID, "INTEGER DEFAULT " + profileId);
328 columnsToTypes.put(RANK, "INTEGER NOT NULL DEFAULT 0");
329 columnsToTypes.put(OPTIONS, "INTEGER NOT NULL DEFAULT 0");
330 columnsToTypes.put(APPWIDGET_SOURCE, "INTEGER NOT NULL DEFAULT -1");
331 return columnsToTypes;
332 }
333
334 private static String getJoinedColumnsToTypes(long profileId) {
335 return getColumnsToTypes(profileId)
336 .entrySet()
337 .stream()
338 .map(it -> it.getKey() + " " + it.getValue())
339 .collect(Collectors.joining(", "));
340 }
341
342 /**
343 * Returns an ordered list of columns in the Favorites table as one string, ready to use in
344 * an SQL statement.
345 */
346 @NonNull
347 public static String getColumns(long profileId) {
348 return String.join(", ", getColumnsToTypes(profileId).keySet());
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700349 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700351
352 /**
353 * Launcher settings
354 */
355 public static final class Settings {
Sunny Goyalab2f8082023-04-11 11:35:43 -0700356 public static final String LAYOUT_DIGEST_KEY = "launcher3.layout.provider.blob";
357 public static final String LAYOUT_DIGEST_LABEL = "launcher-layout";
358 public static final String LAYOUT_DIGEST_TAG = "ignore";
Sunny Goyal7779d622015-06-11 16:18:39 -0700359 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360}