blob: 1d2d1611de93f2b3980c6258aae76391fa84f1b4 [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 Goyal95045ce2024-09-27 13:56:45 -070019import static android.util.Base64.NO_PADDING;
20import static android.util.Base64.NO_WRAP;
21
Sunny Goyalc190dbf2016-05-05 14:37:05 -070022import android.database.sqlite.SQLiteDatabase;
Adam Cohendf2cc412011-04-27 16:56:57 -070023import android.provider.BaseColumns;
Sunny Goyal95045ce2024-09-27 13:56:45 -070024import android.util.Base64;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025
Stefan Andoniane8b86db2023-10-27 21:38:16 +000026import androidx.annotation.NonNull;
27
Sunny Goyale396abf2020-04-06 15:11:17 -070028import com.android.launcher3.model.data.ItemInfo;
29
Stefan Andoniane8b86db2023-10-27 21:38:16 +000030import java.util.LinkedHashMap;
31import java.util.stream.Collectors;
32
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033/**
34 * Settings related utilities.
35 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070036public class LauncherSettings {
Sunny Goyalc5939392018-12-07 11:43:47 -080037
38 /**
Luca Zuccarini20983812023-01-03 14:19:48 +000039 * Types of animations.
40 */
41 public static final class Animation {
42 /**
43 * The default animation for a given view/item info type.
44 */
45 public static final int DEFAULT = 0;
46 /**
47 * An animation using the view's background.
48 */
49 public static final int VIEW_BACKGROUND = 1;
Hyunyoung Songa38aab92023-03-14 07:56:59 +000050 /**
51 * The default animation for a given view/item info type, but without the splash icon.
52 */
53 public static final int DEFAULT_NO_ICON = 2;
Luca Zuccarini20983812023-01-03 14:19:48 +000054 }
55
56 /**
Sunny Goyalc5939392018-12-07 11:43:47 -080057 * Favorites.
58 */
59 public static final class Favorites implements BaseColumns {
Chris Wren1ada10d2013-09-13 18:01:38 -040060 /**
61 * The time of the last update to this row.
62 * <P>Type: INTEGER</P>
63 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070064 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040065
Romain Guy73b979d2009-06-09 12:57:21 -070066 /**
67 * Descriptive name of the gesture that can be displayed to the user.
68 * <P>Type: TEXT</P>
69 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070070 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070071
72 /**
73 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070074 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070075 * an Intent that can be launched.
76 * <P>Type: TEXT</P>
77 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070078 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070079
80 /**
81 * The type of the gesture
82 *
83 * <P>Type: INTEGER</P>
84 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070085 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070086
87 /**
Samuel Fufad3720c22019-09-06 11:25:08 -070088 * The gesture is a package
89 */
90 public static final int ITEM_TYPE_NON_ACTIONABLE = -1;
91 /**
Romain Guy73b979d2009-06-09 12:57:21 -070092 * The gesture is an application
93 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070094 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070095
96 /**
97 * The gesture is an application created shortcut
Sunny Goyale274d972023-05-01 16:55:59 -070098 * @deprecated This is no longer supported. Use {@link #ITEM_TYPE_DEEP_SHORTCUT} instead
Romain Guy73b979d2009-06-09 12:57:21 -070099 */
Sunny Goyale274d972023-05-01 16:55:59 -0700100 @Deprecated
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700101 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -0700102
103 /**
Andy Wickham19ab1772021-02-10 21:36:51 -0800104 * The favorite is a user created folder
105 */
106 public static final int ITEM_TYPE_FOLDER = 2;
107
108 /**
109 * The favorite is a widget
110 */
111 public static final int ITEM_TYPE_APPWIDGET = 4;
112
113 /**
114 * The favorite is a custom widget provided by the launcher
115 */
116 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
117
118 /**
119 * The gesture is an application created deep shortcut
120 */
121 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
122
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700123 /**
124 * The favorite is an app pair for launching split screen
125 */
126 public static final int ITEM_TYPE_APP_PAIR = 10;
sfufa@google.comca76de02021-09-24 08:55:48 -0700127
Andy Wickham93456812022-10-05 17:58:45 -0700128 // *** Below enum values are used for metrics purpose but not used in Favorites DB ***
sfufa@google.comca76de02021-09-24 08:55:48 -0700129
130 /**
Andy Wickham19ab1772021-02-10 21:36:51 -0800131 * Type of the item is recents task.
Andy Wickham19ab1772021-02-10 21:36:51 -0800132 */
133 public static final int ITEM_TYPE_TASK = 7;
134
135 /**
136 * The item is QSB
137 */
138 public static final int ITEM_TYPE_QSB = 8;
139
140 /**
Andy Wickham93456812022-10-05 17:58:45 -0700141 * The favorite is a search action
142 */
143 public static final int ITEM_TYPE_SEARCH_ACTION = 9;
144
145 /**
Holly Sun20c30c92024-03-05 17:07:56 -0800146 * Private space install app button.
147 */
148 public static final int ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON = 11;
149
150 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -0700151 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -0700152 * <P>Type: BLOB</P>
153 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700154 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -0700155
156 public static final String TABLE_NAME = "favorites";
157
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 /**
Samuel Fufaf667a132020-05-29 14:47:42 -0700159 * Backup table created when user hotseat is moved to workspace for hybrid hotseat
160 */
161 public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
162
163 /**
Tracy Zhouf6018722020-02-06 16:37:16 -0800164 * Temporary table used specifically for multi-db grid migrations
165 */
166 public static final String TMP_TABLE = "favorites_tmp";
167
168 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 * The container holding the favorite
170 * <P>Type: INTEGER</P>
171 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700172 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
174 /**
175 * The icon is a resource identified by a package name and an integer id.
176 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700177 public static final int CONTAINER_DESKTOP = -100;
178 public static final int CONTAINER_HOTSEAT = -101;
Samuel Fufa866ff002019-08-09 16:16:06 -0700179 public static final int CONTAINER_PREDICTION = -102;
Steven Ng3a835322021-03-02 21:26:00 +0000180 public static final int CONTAINER_WIDGETS_PREDICTION = -111;
Samuel Fufa225ac272019-10-21 02:02:40 -0700181 public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
thiruram261c3a62020-04-29 16:23:15 -0700182 public static final int CONTAINER_ALL_APPS = -104;
thiruram6bf68482020-05-06 22:19:43 -0700183 public static final int CONTAINER_WIDGETS_TRAY = -105;
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100184 public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112;
185 public static final int CONTAINER_PIN_WIDGETS = -113;
Brian Isganitisf0ca4ae2021-09-02 16:08:29 -0400186 public static final int CONTAINER_WALLPAPERS = -114;
thiruram63bf8ee2020-06-01 12:03:19 -0700187 public static final int CONTAINER_SHORTCUTS = -107;
Hyunyoung Songf26c7932020-06-06 14:44:27 -0700188 public static final int CONTAINER_SETTINGS = -108;
Hyunyoung Song13c2bc72020-06-10 00:35:35 -0700189 public static final int CONTAINER_TASKSWITCHER = -109;
Brandon Dayauon120838b2024-04-08 13:04:54 -0700190 public static final int CONTAINER_PRIVATESPACE = -110;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
thiruram73821a92021-02-05 17:50:37 -0800192 // Represents any of the extended containers implemented in non-AOSP variants.
193 public static final int EXTENDED_CONTAINERS = -200;
194
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100195 public static final int CONTAINER_UNKNOWN = -1;
196
Sunny Goyale396abf2020-04-06 15:11:17 -0700197 public static final String containerToString(int container) {
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500198 switch (container) {
199 case CONTAINER_DESKTOP: return "desktop";
200 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700201 case CONTAINER_PREDICTION: return "prediction";
thiruram6bf68482020-05-06 22:19:43 -0700202 case CONTAINER_ALL_APPS: return "all_apps";
203 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
thiruram63bf8ee2020-06-01 12:03:19 -0700204 case CONTAINER_SHORTCUTS: return "shortcuts";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500205 default: return String.valueOf(container);
206 }
207 }
208
Sunny Goyale396abf2020-04-06 15:11:17 -0700209 public static final String itemTypeToString(int type) {
Hyunyoung Song86160f52017-02-06 10:46:24 -0800210 switch(type) {
211 case ITEM_TYPE_APPLICATION: return "APP";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800212 case ITEM_TYPE_FOLDER: return "FOLDER";
213 case ITEM_TYPE_APPWIDGET: return "WIDGET";
214 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
215 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
Andy Wickham19ab1772021-02-10 21:36:51 -0800216 case ITEM_TYPE_TASK: return "TASK";
217 case ITEM_TYPE_QSB: return "QSB";
Jeremy Sim7cf0dd92023-03-24 22:39:45 -0700218 case ITEM_TYPE_APP_PAIR: return "APP_PAIR";
Holly Sun20c30c92024-03-05 17:07:56 -0800219 case ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON:
220 return "PRIVATE_SPACE_INSTALL_APP_BUTTON";
Hyunyoung Song86160f52017-02-06 10:46:24 -0800221 default: return String.valueOf(type);
222 }
223 }
224
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225 /**
226 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
227 * <P>Type: INTEGER</P>
228 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700229 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230
231 /**
232 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700233 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 * <P>Type: INTEGER</P>
235 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700236 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237
238 /**
239 * The Y coordinate of the cell holding the favorite
240 * (if container is CONTAINER_DESKTOP)
241 * <P>Type: INTEGER</P>
242 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700243 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244
245 /**
246 * The X span of the cell holding the favorite
247 * <P>Type: INTEGER</P>
248 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700249 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250
251 /**
252 * The Y span of the cell holding the favorite
253 * <P>Type: INTEGER</P>
254 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700255 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256
257 /**
Kenny Guyed131872014-04-30 03:02:21 +0100258 * The profile id of the item in the cell.
259 * <P>
260 * Type: INTEGER
261 * </P>
262 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700263 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100264
265 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700266 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 *
268 * <P>Type: INTEGER</P>
269 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700270 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400271
272 /**
273 * The ComponentName of the widget provider
274 *
275 * <P>Type: STRING</P>
276 */
277 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500278
279 /**
280 * Boolean indicating that his item was restored and not yet successfully bound.
281 * <P>Type: INTEGER</P>
282 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700283 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800284
285 /**
286 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
287 * <p>Type: INTEGER</p>
288 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700289 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700290
291 /**
292 * Stores general flag based options for {@link ItemInfo}s.
293 * <p>Type: INTEGER</p>
294 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700295 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700296
Yogisha Dixit658c5da2021-05-24 23:23:15 +0100297 /**
298 * Stores the source container that the widget was added from.
299 * <p>Type: INTEGER</p>
300 */
301 public static final String APPWIDGET_SOURCE = "appWidgetSource";
302
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700303 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700304 addTableToDb(db, myProfileId, optional, TABLE_NAME);
305 }
306
307 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
308 String tableName) {
Stefan Andoniane8b86db2023-10-27 21:38:16 +0000309 db.execSQL("CREATE TABLE " + (optional ? " IF NOT EXISTS " : "") + tableName + " ("
310 + getJoinedColumnsToTypes(myProfileId) + ");");
311 }
312
313 // LinkedHashMap maintains Order of Insertion
314 @NonNull
315 private static LinkedHashMap<String, String> getColumnsToTypes(long profileId) {
316 final LinkedHashMap<String, String> columnsToTypes = new LinkedHashMap<>();
317 columnsToTypes.put(_ID, "INTEGER PRIMARY KEY");
318 columnsToTypes.put(TITLE, "TEXT");
319 columnsToTypes.put(INTENT, "TEXT");
320 columnsToTypes.put(CONTAINER, "INTEGER");
321 columnsToTypes.put(SCREEN, "INTEGER");
322 columnsToTypes.put(CELLX, "INTEGER");
323 columnsToTypes.put(CELLY, "INTEGER");
324 columnsToTypes.put(SPANX, "INTEGER");
325 columnsToTypes.put(SPANY, "INTEGER");
326 columnsToTypes.put(ITEM_TYPE, "INTEGER");
327 columnsToTypes.put(APPWIDGET_ID, "INTEGER NOT NULL DEFAULT -1");
328 columnsToTypes.put(ICON, "BLOB");
329 columnsToTypes.put(APPWIDGET_PROVIDER, "TEXT");
330 columnsToTypes.put(MODIFIED, "INTEGER NOT NULL DEFAULT 0");
331 columnsToTypes.put(RESTORED, "INTEGER NOT NULL DEFAULT 0");
332 columnsToTypes.put(PROFILE_ID, "INTEGER DEFAULT " + profileId);
333 columnsToTypes.put(RANK, "INTEGER NOT NULL DEFAULT 0");
334 columnsToTypes.put(OPTIONS, "INTEGER NOT NULL DEFAULT 0");
335 columnsToTypes.put(APPWIDGET_SOURCE, "INTEGER NOT NULL DEFAULT -1");
336 return columnsToTypes;
337 }
338
339 private static String getJoinedColumnsToTypes(long profileId) {
340 return getColumnsToTypes(profileId)
341 .entrySet()
342 .stream()
343 .map(it -> it.getKey() + " " + it.getValue())
344 .collect(Collectors.joining(", "));
345 }
346
347 /**
348 * Returns an ordered list of columns in the Favorites table as one string, ready to use in
349 * an SQL statement.
350 */
351 @NonNull
352 public static String getColumns(long profileId) {
353 return String.join(", ", getColumnsToTypes(profileId).keySet());
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700354 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700356
357 /**
358 * Launcher settings
359 */
360 public static final class Settings {
Sunny Goyal95045ce2024-09-27 13:56:45 -0700361 public static final String LAYOUT_PROVIDER_KEY = "launcher3.layout.provider";
Sunny Goyalab2f8082023-04-11 11:35:43 -0700362 public static final String LAYOUT_DIGEST_LABEL = "launcher-layout";
363 public static final String LAYOUT_DIGEST_TAG = "ignore";
Sunny Goyal95045ce2024-09-27 13:56:45 -0700364 public static final String BLOB_KEY_PREFIX = "blob://";
365
366 /**
367 * Creates a key to be used for {@link #LAYOUT_PROVIDER_KEY}
368 * @param digest byte[] representing the message digest for the blob handle
369 */
370 public static String createBlobProviderKey(byte[] digest) {
371 return BLOB_KEY_PREFIX + Base64.encodeToString(digest, NO_WRAP | NO_PADDING);
372 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700373 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374}