blob: 34ebaf2539c3b926f03e680b9c589c52d83ecd5c [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 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -0700142 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -0700143 * <P>Type: BLOB</P>
144 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700145 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -0700146
147 public static final String TABLE_NAME = "favorites";
148
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 /**
Samuel Fufaf667a132020-05-29 14:47:42 -0700150 * Backup table created when user hotseat is moved to workspace for hybrid hotseat
151 */
152 public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
153
154 /**
Tracy Zhouf6018722020-02-06 16:37:16 -0800155 * Temporary table used specifically for multi-db grid migrations
156 */
157 public static final String TMP_TABLE = "favorites_tmp";
158
159 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160 * The container holding the favorite
161 * <P>Type: INTEGER</P>
162 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700163 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164
165 /**
166 * The icon is a resource identified by a package name and an integer id.
167 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700168 public static final int CONTAINER_DESKTOP = -100;
169 public static final int CONTAINER_HOTSEAT = -101;
Samuel Fufa866ff002019-08-09 16:16:06 -0700170 public static final int CONTAINER_PREDICTION = -102;
Steven Ng3a835322021-03-02 21:26:00 +0000171 public static final int CONTAINER_WIDGETS_PREDICTION = -111;
Samuel Fufa225ac272019-10-21 02:02:40 -0700172 public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
thiruram261c3a62020-04-29 16:23:15 -0700173 public static final int CONTAINER_ALL_APPS = -104;
thiruram6bf68482020-05-06 22:19:43 -0700174 public static final int CONTAINER_WIDGETS_TRAY = -105;
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100175 public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112;
176 public static final int CONTAINER_PIN_WIDGETS = -113;
Brian Isganitisf0ca4ae2021-09-02 16:08:29 -0400177 public static final int CONTAINER_WALLPAPERS = -114;
thiruram63bf8ee2020-06-01 12:03:19 -0700178 public static final int CONTAINER_SHORTCUTS = -107;
Hyunyoung Songf26c7932020-06-06 14:44:27 -0700179 public static final int CONTAINER_SETTINGS = -108;
Hyunyoung Song13c2bc72020-06-10 00:35:35 -0700180 public static final int CONTAINER_TASKSWITCHER = -109;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181
thiruram73821a92021-02-05 17:50:37 -0800182 // Represents any of the extended containers implemented in non-AOSP variants.
183 public static final int EXTENDED_CONTAINERS = -200;
184
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100185 public static final int CONTAINER_UNKNOWN = -1;
186
Sunny Goyale396abf2020-04-06 15:11:17 -0700187 public static final String containerToString(int container) {
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500188 switch (container) {
189 case CONTAINER_DESKTOP: return "desktop";
190 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700191 case CONTAINER_PREDICTION: return "prediction";
thiruram6bf68482020-05-06 22:19:43 -0700192 case CONTAINER_ALL_APPS: return "all_apps";
193 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
thiruram63bf8ee2020-06-01 12:03:19 -0700194 case CONTAINER_SHORTCUTS: return "shortcuts";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500195 default: return String.valueOf(container);
196 }
197 }
198
Sunny Goyale396abf2020-04-06 15:11:17 -0700199 public static final String itemTypeToString(int type) {
Hyunyoung Song86160f52017-02-06 10:46:24 -0800200 switch(type) {
201 case ITEM_TYPE_APPLICATION: return "APP";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800202 case ITEM_TYPE_FOLDER: return "FOLDER";
203 case ITEM_TYPE_APPWIDGET: return "WIDGET";
204 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
205 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
Andy Wickham19ab1772021-02-10 21:36:51 -0800206 case ITEM_TYPE_TASK: return "TASK";
207 case ITEM_TYPE_QSB: return "QSB";
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700208 case ITEM_TYPE_APP_PAIR: return "APP_PAIR";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800209 default: return String.valueOf(type);
210 }
211 }
212
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 /**
214 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
215 * <P>Type: INTEGER</P>
216 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700217 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
219 /**
220 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700221 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 * <P>Type: INTEGER</P>
223 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700224 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225
226 /**
227 * The Y coordinate of the cell holding the favorite
228 * (if container is CONTAINER_DESKTOP)
229 * <P>Type: INTEGER</P>
230 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700231 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232
233 /**
234 * The X span of the cell holding the favorite
235 * <P>Type: INTEGER</P>
236 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700237 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238
239 /**
240 * The Y span of the cell holding the favorite
241 * <P>Type: INTEGER</P>
242 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700243 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244
245 /**
Kenny Guyed131872014-04-30 03:02:21 +0100246 * The profile id of the item in the cell.
247 * <P>
248 * Type: INTEGER
249 * </P>
250 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700251 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100252
253 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700254 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 *
256 * <P>Type: INTEGER</P>
257 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700258 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400259
260 /**
261 * The ComponentName of the widget provider
262 *
263 * <P>Type: STRING</P>
264 */
265 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500266
267 /**
268 * Boolean indicating that his item was restored and not yet successfully bound.
269 * <P>Type: INTEGER</P>
270 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700271 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800272
273 /**
274 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
275 * <p>Type: INTEGER</p>
276 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700277 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700278
279 /**
280 * Stores general flag based options for {@link ItemInfo}s.
281 * <p>Type: INTEGER</p>
282 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700283 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700284
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100285 /**
286 * Stores the source container that the widget was added from.
287 * <p>Type: INTEGER</p>
288 */
289 public static final String APPWIDGET_SOURCE = "appWidgetSource";
290
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700291 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700292 addTableToDb(db, myProfileId, optional, TABLE_NAME);
293 }
294
295 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
296 String tableName) {
Stefan Andoniane8b86db2023-10-27 21:38:16 +0000297 db.execSQL("CREATE TABLE " + (optional ? " IF NOT EXISTS " : "") + tableName + " ("
298 + getJoinedColumnsToTypes(myProfileId) + ");");
299 }
300
301 // LinkedHashMap maintains Order of Insertion
302 @NonNull
303 private static LinkedHashMap<String, String> getColumnsToTypes(long profileId) {
304 final LinkedHashMap<String, String> columnsToTypes = new LinkedHashMap<>();
305 columnsToTypes.put(_ID, "INTEGER PRIMARY KEY");
306 columnsToTypes.put(TITLE, "TEXT");
307 columnsToTypes.put(INTENT, "TEXT");
308 columnsToTypes.put(CONTAINER, "INTEGER");
309 columnsToTypes.put(SCREEN, "INTEGER");
310 columnsToTypes.put(CELLX, "INTEGER");
311 columnsToTypes.put(CELLY, "INTEGER");
312 columnsToTypes.put(SPANX, "INTEGER");
313 columnsToTypes.put(SPANY, "INTEGER");
314 columnsToTypes.put(ITEM_TYPE, "INTEGER");
315 columnsToTypes.put(APPWIDGET_ID, "INTEGER NOT NULL DEFAULT -1");
316 columnsToTypes.put(ICON, "BLOB");
317 columnsToTypes.put(APPWIDGET_PROVIDER, "TEXT");
318 columnsToTypes.put(MODIFIED, "INTEGER NOT NULL DEFAULT 0");
319 columnsToTypes.put(RESTORED, "INTEGER NOT NULL DEFAULT 0");
320 columnsToTypes.put(PROFILE_ID, "INTEGER DEFAULT " + profileId);
321 columnsToTypes.put(RANK, "INTEGER NOT NULL DEFAULT 0");
322 columnsToTypes.put(OPTIONS, "INTEGER NOT NULL DEFAULT 0");
323 columnsToTypes.put(APPWIDGET_SOURCE, "INTEGER NOT NULL DEFAULT -1");
324 return columnsToTypes;
325 }
326
327 private static String getJoinedColumnsToTypes(long profileId) {
328 return getColumnsToTypes(profileId)
329 .entrySet()
330 .stream()
331 .map(it -> it.getKey() + " " + it.getValue())
332 .collect(Collectors.joining(", "));
333 }
334
335 /**
336 * Returns an ordered list of columns in the Favorites table as one string, ready to use in
337 * an SQL statement.
338 */
339 @NonNull
340 public static String getColumns(long profileId) {
341 return String.join(", ", getColumnsToTypes(profileId).keySet());
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700342 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700344
345 /**
346 * Launcher settings
347 */
348 public static final class Settings {
Sunny Goyalab2f8082023-04-11 11:35:43 -0700349 public static final String LAYOUT_DIGEST_KEY = "launcher3.layout.provider.blob";
350 public static final String LAYOUT_DIGEST_LABEL = "launcher-layout";
351 public static final String LAYOUT_DIGEST_TAG = "ignore";
Sunny Goyal7779d622015-06-11 16:18:39 -0700352 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353}