blob: 87ac1933971f1f8f339f09c056b6c767541368d8 [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;
Brandon Dayauon120838b2024-04-08 13:04:54 -0700186 public static final int CONTAINER_PRIVATESPACE = -110;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
thiruram73821a92021-02-05 17:50:37 -0800188 // Represents any of the extended containers implemented in non-AOSP variants.
189 public static final int EXTENDED_CONTAINERS = -200;
190
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100191 public static final int CONTAINER_UNKNOWN = -1;
192
Sunny Goyale396abf2020-04-06 15:11:17 -0700193 public static final String containerToString(int container) {
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500194 switch (container) {
195 case CONTAINER_DESKTOP: return "desktop";
196 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700197 case CONTAINER_PREDICTION: return "prediction";
thiruram6bf68482020-05-06 22:19:43 -0700198 case CONTAINER_ALL_APPS: return "all_apps";
199 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
thiruram63bf8ee2020-06-01 12:03:19 -0700200 case CONTAINER_SHORTCUTS: return "shortcuts";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500201 default: return String.valueOf(container);
202 }
203 }
204
Sunny Goyale396abf2020-04-06 15:11:17 -0700205 public static final String itemTypeToString(int type) {
Hyunyoung Song86160f52017-02-06 10:46:24 -0800206 switch(type) {
207 case ITEM_TYPE_APPLICATION: return "APP";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800208 case ITEM_TYPE_FOLDER: return "FOLDER";
209 case ITEM_TYPE_APPWIDGET: return "WIDGET";
210 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
211 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
Andy Wickham19ab1772021-02-10 21:36:51 -0800212 case ITEM_TYPE_TASK: return "TASK";
213 case ITEM_TYPE_QSB: return "QSB";
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700214 case ITEM_TYPE_APP_PAIR: return "APP_PAIR";
Holly Sun20c30c92024-03-05 17:07:56 -0800215 case ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON:
216 return "PRIVATE_SPACE_INSTALL_APP_BUTTON";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800217 default: return String.valueOf(type);
218 }
219 }
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 /**
222 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
223 * <P>Type: INTEGER</P>
224 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700225 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226
227 /**
228 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700229 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230 * <P>Type: INTEGER</P>
231 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700232 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233
234 /**
235 * The Y coordinate of the cell holding the favorite
236 * (if container is CONTAINER_DESKTOP)
237 * <P>Type: INTEGER</P>
238 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700239 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800240
241 /**
242 * The X span of the cell holding the favorite
243 * <P>Type: INTEGER</P>
244 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700245 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246
247 /**
248 * The Y span of the cell holding the favorite
249 * <P>Type: INTEGER</P>
250 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700251 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252
253 /**
Kenny Guyed131872014-04-30 03:02:21 +0100254 * The profile id of the item in the cell.
255 * <P>
256 * Type: INTEGER
257 * </P>
258 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700259 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100260
261 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700262 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263 *
264 * <P>Type: INTEGER</P>
265 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700266 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400267
268 /**
269 * The ComponentName of the widget provider
270 *
271 * <P>Type: STRING</P>
272 */
273 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500274
275 /**
276 * Boolean indicating that his item was restored and not yet successfully bound.
277 * <P>Type: INTEGER</P>
278 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700279 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800280
281 /**
282 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
283 * <p>Type: INTEGER</p>
284 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700285 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700286
287 /**
288 * Stores general flag based options for {@link ItemInfo}s.
289 * <p>Type: INTEGER</p>
290 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700291 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700292
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100293 /**
294 * Stores the source container that the widget was added from.
295 * <p>Type: INTEGER</p>
296 */
297 public static final String APPWIDGET_SOURCE = "appWidgetSource";
298
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700299 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700300 addTableToDb(db, myProfileId, optional, TABLE_NAME);
301 }
302
303 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
304 String tableName) {
Stefan Andoniane8b86db2023-10-27 21:38:16 +0000305 db.execSQL("CREATE TABLE " + (optional ? " IF NOT EXISTS " : "") + tableName + " ("
306 + getJoinedColumnsToTypes(myProfileId) + ");");
307 }
308
309 // LinkedHashMap maintains Order of Insertion
310 @NonNull
311 private static LinkedHashMap<String, String> getColumnsToTypes(long profileId) {
312 final LinkedHashMap<String, String> columnsToTypes = new LinkedHashMap<>();
313 columnsToTypes.put(_ID, "INTEGER PRIMARY KEY");
314 columnsToTypes.put(TITLE, "TEXT");
315 columnsToTypes.put(INTENT, "TEXT");
316 columnsToTypes.put(CONTAINER, "INTEGER");
317 columnsToTypes.put(SCREEN, "INTEGER");
318 columnsToTypes.put(CELLX, "INTEGER");
319 columnsToTypes.put(CELLY, "INTEGER");
320 columnsToTypes.put(SPANX, "INTEGER");
321 columnsToTypes.put(SPANY, "INTEGER");
322 columnsToTypes.put(ITEM_TYPE, "INTEGER");
323 columnsToTypes.put(APPWIDGET_ID, "INTEGER NOT NULL DEFAULT -1");
324 columnsToTypes.put(ICON, "BLOB");
325 columnsToTypes.put(APPWIDGET_PROVIDER, "TEXT");
326 columnsToTypes.put(MODIFIED, "INTEGER NOT NULL DEFAULT 0");
327 columnsToTypes.put(RESTORED, "INTEGER NOT NULL DEFAULT 0");
328 columnsToTypes.put(PROFILE_ID, "INTEGER DEFAULT " + profileId);
329 columnsToTypes.put(RANK, "INTEGER NOT NULL DEFAULT 0");
330 columnsToTypes.put(OPTIONS, "INTEGER NOT NULL DEFAULT 0");
331 columnsToTypes.put(APPWIDGET_SOURCE, "INTEGER NOT NULL DEFAULT -1");
332 return columnsToTypes;
333 }
334
335 private static String getJoinedColumnsToTypes(long profileId) {
336 return getColumnsToTypes(profileId)
337 .entrySet()
338 .stream()
339 .map(it -> it.getKey() + " " + it.getValue())
340 .collect(Collectors.joining(", "));
341 }
342
343 /**
344 * Returns an ordered list of columns in the Favorites table as one string, ready to use in
345 * an SQL statement.
346 */
347 @NonNull
348 public static String getColumns(long profileId) {
349 return String.join(", ", getColumnsToTypes(profileId).keySet());
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700350 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700352
353 /**
354 * Launcher settings
355 */
356 public static final class Settings {
Sunny Goyalab2f8082023-04-11 11:35:43 -0700357 public static final String LAYOUT_DIGEST_KEY = "launcher3.layout.provider.blob";
358 public static final String LAYOUT_DIGEST_LABEL = "launcher-layout";
359 public static final String LAYOUT_DIGEST_TAG = "ignore";
Sunny Goyal7779d622015-06-11 16:18:39 -0700360 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361}