blob: 2397429346b426c0d6ab62bbc67b91901b8d2344 [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 Goyald2497482015-09-22 18:24:19 -070019import android.content.ContentResolver;
Sunny Goyalc190dbf2016-05-05 14:37:05 -070020import android.database.sqlite.SQLiteDatabase;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.net.Uri;
Sunny Goyald2497482015-09-22 18:24:19 -070022import android.os.Bundle;
Adam Cohendf2cc412011-04-27 16:56:57 -070023import android.provider.BaseColumns;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024
Sunny Goyale396abf2020-04-06 15:11:17 -070025import com.android.launcher3.model.data.ItemInfo;
26
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027/**
28 * Settings related utilities.
29 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070030public class LauncherSettings {
Sunny Goyalc5939392018-12-07 11:43:47 -080031
32 /**
Luca Zuccarini20983812023-01-03 14:19:48 +000033 * Types of animations.
34 */
35 public static final class Animation {
36 /**
37 * The default animation for a given view/item info type.
38 */
39 public static final int DEFAULT = 0;
40 /**
41 * An animation using the view's background.
42 */
43 public static final int VIEW_BACKGROUND = 1;
Hyunyoung Songa38aab92023-03-14 07:56:59 +000044 /**
45 * The default animation for a given view/item info type, but without the splash icon.
46 */
47 public static final int DEFAULT_NO_ICON = 2;
Luca Zuccarini20983812023-01-03 14:19:48 +000048 }
49
50 /**
Sunny Goyalc5939392018-12-07 11:43:47 -080051 * Favorites.
52 */
53 public static final class Favorites implements BaseColumns {
Chris Wren1ada10d2013-09-13 18:01:38 -040054 /**
55 * The time of the last update to this row.
56 * <P>Type: INTEGER</P>
57 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070058 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040059
Romain Guy73b979d2009-06-09 12:57:21 -070060 /**
61 * Descriptive name of the gesture that can be displayed to the user.
62 * <P>Type: TEXT</P>
63 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070064 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070065
66 /**
67 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070068 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070069 * an Intent that can be launched.
70 * <P>Type: TEXT</P>
71 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070072 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070073
74 /**
75 * The type of the gesture
76 *
77 * <P>Type: INTEGER</P>
78 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070079 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070080
81 /**
Samuel Fufad3720c22019-09-06 11:25:08 -070082 * The gesture is a package
83 */
84 public static final int ITEM_TYPE_NON_ACTIONABLE = -1;
85 /**
Romain Guy73b979d2009-06-09 12:57:21 -070086 * The gesture is an application
87 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070088 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070089
90 /**
91 * The gesture is an application created shortcut
Sunny Goyale274d972023-05-01 16:55:59 -070092 * @deprecated This is no longer supported. Use {@link #ITEM_TYPE_DEEP_SHORTCUT} instead
Romain Guy73b979d2009-06-09 12:57:21 -070093 */
Sunny Goyale274d972023-05-01 16:55:59 -070094 @Deprecated
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070095 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070096
97 /**
Andy Wickham19ab1772021-02-10 21:36:51 -080098 * The favorite is a user created folder
99 */
100 public static final int ITEM_TYPE_FOLDER = 2;
101
102 /**
103 * The favorite is a widget
104 */
105 public static final int ITEM_TYPE_APPWIDGET = 4;
106
107 /**
108 * The favorite is a custom widget provided by the launcher
109 */
110 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
111
112 /**
113 * The gesture is an application created deep shortcut
114 */
115 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
116
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700117 /**
118 * The favorite is an app pair for launching split screen
119 */
120 public static final int ITEM_TYPE_APP_PAIR = 10;
sfufa@google.comca76de02021-09-24 08:55:48 -0700121
Andy Wickham93456812022-10-05 17:58:45 -0700122 // *** Below enum values are used for metrics purpose but not used in Favorites DB ***
sfufa@google.comca76de02021-09-24 08:55:48 -0700123
124 /**
Andy Wickham19ab1772021-02-10 21:36:51 -0800125 * Type of the item is recents task.
Andy Wickham19ab1772021-02-10 21:36:51 -0800126 */
127 public static final int ITEM_TYPE_TASK = 7;
128
129 /**
130 * The item is QSB
131 */
132 public static final int ITEM_TYPE_QSB = 8;
133
134 /**
Andy Wickham93456812022-10-05 17:58:45 -0700135 * The favorite is a search action
136 */
137 public static final int ITEM_TYPE_SEARCH_ACTION = 9;
138
139 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -0700140 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -0700141 * <P>Type: BLOB</P>
142 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700143 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -0700144
145 public static final String TABLE_NAME = "favorites";
146
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 /**
Samuel Fufaf667a132020-05-29 14:47:42 -0700148 * Backup table created when user hotseat is moved to workspace for hybrid hotseat
149 */
150 public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
151
152 /**
Tracy Zhouf6018722020-02-06 16:37:16 -0800153 * Temporary table used specifically for multi-db grid migrations
154 */
155 public static final String TMP_TABLE = "favorites_tmp";
156
157 /**
Tracy Zhoube13d102020-01-12 01:07:59 -0800158 * The content:// style URL for "favorites" table
159 */
160 public static final Uri CONTENT_URI = Uri.parse("content://"
161 + LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
162
163 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 * The content:// style URL for a given row, identified by its id.
165 *
166 * @param id The row id.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 *
168 * @return The unique content URL for the specified row.
169 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700170 public static Uri getContentUri(int id) {
Tracy Zhoube13d102020-01-12 01:07:59 -0800171 return Uri.parse("content://" + LauncherProvider.AUTHORITY
172 + "/" + TABLE_NAME + "/" + id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 }
174
175 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 * The container holding the favorite
177 * <P>Type: INTEGER</P>
178 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700179 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
181 /**
182 * The icon is a resource identified by a package name and an integer id.
183 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700184 public static final int CONTAINER_DESKTOP = -100;
185 public static final int CONTAINER_HOTSEAT = -101;
Samuel Fufa866ff002019-08-09 16:16:06 -0700186 public static final int CONTAINER_PREDICTION = -102;
Steven Ng3a835322021-03-02 21:26:00 +0000187 public static final int CONTAINER_WIDGETS_PREDICTION = -111;
Samuel Fufa225ac272019-10-21 02:02:40 -0700188 public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
thiruram261c3a62020-04-29 16:23:15 -0700189 public static final int CONTAINER_ALL_APPS = -104;
thiruram6bf68482020-05-06 22:19:43 -0700190 public static final int CONTAINER_WIDGETS_TRAY = -105;
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100191 public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112;
192 public static final int CONTAINER_PIN_WIDGETS = -113;
Brian Isganitisf0ca4ae2021-09-02 16:08:29 -0400193 public static final int CONTAINER_WALLPAPERS = -114;
thiruram63bf8ee2020-06-01 12:03:19 -0700194 public static final int CONTAINER_SHORTCUTS = -107;
Hyunyoung Songf26c7932020-06-06 14:44:27 -0700195 public static final int CONTAINER_SETTINGS = -108;
Hyunyoung Song13c2bc72020-06-10 00:35:35 -0700196 public static final int CONTAINER_TASKSWITCHER = -109;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
thiruram73821a92021-02-05 17:50:37 -0800198 // Represents any of the extended containers implemented in non-AOSP variants.
199 public static final int EXTENDED_CONTAINERS = -200;
200
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100201 public static final int CONTAINER_UNKNOWN = -1;
202
Sunny Goyale396abf2020-04-06 15:11:17 -0700203 public static final String containerToString(int container) {
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500204 switch (container) {
205 case CONTAINER_DESKTOP: return "desktop";
206 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700207 case CONTAINER_PREDICTION: return "prediction";
thiruram6bf68482020-05-06 22:19:43 -0700208 case CONTAINER_ALL_APPS: return "all_apps";
209 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
thiruram63bf8ee2020-06-01 12:03:19 -0700210 case CONTAINER_SHORTCUTS: return "shortcuts";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500211 default: return String.valueOf(container);
212 }
213 }
214
Sunny Goyale396abf2020-04-06 15:11:17 -0700215 public static final String itemTypeToString(int type) {
Hyunyoung Song86160f52017-02-06 10:46:24 -0800216 switch(type) {
217 case ITEM_TYPE_APPLICATION: return "APP";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800218 case ITEM_TYPE_FOLDER: return "FOLDER";
219 case ITEM_TYPE_APPWIDGET: return "WIDGET";
220 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
221 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
Andy Wickham19ab1772021-02-10 21:36:51 -0800222 case ITEM_TYPE_TASK: return "TASK";
223 case ITEM_TYPE_QSB: return "QSB";
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700224 case ITEM_TYPE_APP_PAIR: return "APP_PAIR";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800225 default: return String.valueOf(type);
226 }
227 }
228
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 /**
230 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
231 * <P>Type: INTEGER</P>
232 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700233 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234
235 /**
236 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700237 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238 * <P>Type: INTEGER</P>
239 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700240 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241
242 /**
243 * The Y coordinate of the cell holding the favorite
244 * (if container is CONTAINER_DESKTOP)
245 * <P>Type: INTEGER</P>
246 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700247 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248
249 /**
250 * The X span of the cell holding the favorite
251 * <P>Type: INTEGER</P>
252 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700253 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254
255 /**
256 * The Y span of the cell holding the favorite
257 * <P>Type: INTEGER</P>
258 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700259 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260
261 /**
Kenny Guyed131872014-04-30 03:02:21 +0100262 * The profile id of the item in the cell.
263 * <P>
264 * Type: INTEGER
265 * </P>
266 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700267 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100268
269 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700270 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 *
272 * <P>Type: INTEGER</P>
273 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700274 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400275
276 /**
277 * The ComponentName of the widget provider
278 *
279 * <P>Type: STRING</P>
280 */
281 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500282
283 /**
284 * Boolean indicating that his item was restored and not yet successfully bound.
285 * <P>Type: INTEGER</P>
286 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700287 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800288
289 /**
290 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
291 * <p>Type: INTEGER</p>
292 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700293 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700294
295 /**
296 * Stores general flag based options for {@link ItemInfo}s.
297 * <p>Type: INTEGER</p>
298 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700299 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700300
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100301 /**
302 * Stores the source container that the widget was added from.
303 * <p>Type: INTEGER</p>
304 */
305 public static final String APPWIDGET_SOURCE = "appWidgetSource";
306
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700307 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700308 addTableToDb(db, myProfileId, optional, TABLE_NAME);
309 }
310
311 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
312 String tableName) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700313 String ifNotExists = optional ? " IF NOT EXISTS " : "";
Sunny Goyal161a2142018-10-29 14:02:20 -0700314 db.execSQL("CREATE TABLE " + ifNotExists + tableName + " (" +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700315 "_id INTEGER PRIMARY KEY," +
316 "title TEXT," +
317 "intent TEXT," +
318 "container INTEGER," +
319 "screen INTEGER," +
320 "cellX INTEGER," +
321 "cellY INTEGER," +
322 "spanX INTEGER," +
323 "spanY INTEGER," +
324 "itemType INTEGER," +
325 "appWidgetId INTEGER NOT NULL DEFAULT -1," +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700326 "icon BLOB," +
327 "appWidgetProvider TEXT," +
328 "modified INTEGER NOT NULL DEFAULT 0," +
329 "restored INTEGER NOT NULL DEFAULT 0," +
330 "profileId INTEGER DEFAULT " + myProfileId + "," +
331 "rank INTEGER NOT NULL DEFAULT 0," +
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100332 "options INTEGER NOT NULL DEFAULT 0," +
333 APPWIDGET_SOURCE + " INTEGER NOT NULL DEFAULT " + CONTAINER_UNKNOWN +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700334 ");");
335 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800336 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700337
338 /**
339 * Launcher settings
340 */
341 public static final class Settings {
342
343 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800344 LauncherProvider.AUTHORITY + "/settings");
Sunny Goyal7779d622015-06-11 16:18:39 -0700345
Sunny Goyald2497482015-09-22 18:24:19 -0700346 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
347
348 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
Sunny Goyald2497482015-09-22 18:24:19 -0700349
350 public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
351 public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
352
353 public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
Sunny Goyald2497482015-09-22 18:24:19 -0700354
355 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
Sunny Goyal7779d622015-06-11 16:18:39 -0700356
Sunny Goyal55fddc82017-04-06 15:02:52 -0700357 public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
358
Sunny Goyal161a2142018-10-29 14:02:20 -0700359 public static final String METHOD_NEW_TRANSACTION = "new_db_transaction";
360
Samuel Fufaf667a132020-05-29 14:47:42 -0700361 public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table";
362
Sunny Goyal7779d622015-06-11 16:18:39 -0700363 public static final String EXTRA_VALUE = "value";
Sunny Goyald2497482015-09-22 18:24:19 -0700364
Pinyao Ting702ed272020-10-14 11:17:04 -0700365 public static final String EXTRA_DB_NAME = "db_name";
366
Sunny Goyalab2f8082023-04-11 11:35:43 -0700367 public static final String LAYOUT_DIGEST_KEY = "launcher3.layout.provider.blob";
368 public static final String LAYOUT_DIGEST_LABEL = "launcher-layout";
369 public static final String LAYOUT_DIGEST_TAG = "ignore";
370
Sunny Goyald2497482015-09-22 18:24:19 -0700371 public static Bundle call(ContentResolver cr, String method) {
Pinyao Ting96186af2020-07-20 11:03:39 -0700372 return call(cr, method, null /* arg */);
Tracy Zhouc0000452020-03-17 18:28:38 -0700373 }
374
375 public static Bundle call(ContentResolver cr, String method, String arg) {
Sunny Goyal7bc6cde2023-05-12 23:07:25 +0000376 return cr.call(CONTENT_URI, method, arg, null);
Pinyao Ting96186af2020-07-20 11:03:39 -0700377 }
378
Sunny Goyal7779d622015-06-11 16:18:39 -0700379 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380}