blob: 2a5ee001d52c3527200b298018121d8b891f0e59 [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 /**
33 * Favorites.
34 */
35 public static final class Favorites implements BaseColumns {
Chris Wren1ada10d2013-09-13 18:01:38 -040036 /**
37 * The time of the last update to this row.
38 * <P>Type: INTEGER</P>
39 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070040 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040041
Romain Guy73b979d2009-06-09 12:57:21 -070042 /**
43 * Descriptive name of the gesture that can be displayed to the user.
44 * <P>Type: TEXT</P>
45 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070046 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070047
48 /**
49 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070050 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070051 * an Intent that can be launched.
52 * <P>Type: TEXT</P>
53 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070054 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070055
56 /**
57 * The type of the gesture
58 *
59 * <P>Type: INTEGER</P>
60 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070061 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070062
63 /**
Samuel Fufad3720c22019-09-06 11:25:08 -070064 * The gesture is a package
65 */
66 public static final int ITEM_TYPE_NON_ACTIONABLE = -1;
67 /**
Romain Guy73b979d2009-06-09 12:57:21 -070068 * The gesture is an application
69 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070070 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070071
72 /**
73 * The gesture is an application created shortcut
74 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070075 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070076
77 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070078 * The icon package name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070079 * <P>Type: TEXT</P>
80 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070081 public static final String ICON_PACKAGE = "iconPackage";
Romain Guy73b979d2009-06-09 12:57:21 -070082
83 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070084 * The icon resource name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070085 * <P>Type: TEXT</P>
86 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070087 public static final String ICON_RESOURCE = "iconResource";
Romain Guy73b979d2009-06-09 12:57:21 -070088
89 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070090 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -070091 * <P>Type: BLOB</P>
92 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070093 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -070094
95 public static final String TABLE_NAME = "favorites";
96
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097 /**
Tracy Zhoube13d102020-01-12 01:07:59 -080098 * Backup table created when the favorites table is modified during grid migration
Sunny Goyal161a2142018-10-29 14:02:20 -070099 */
100 public static final String BACKUP_TABLE_NAME = "favorites_bakup";
101
102 /**
Samuel Fufaf667a132020-05-29 14:47:42 -0700103 * Backup table created when user hotseat is moved to workspace for hybrid hotseat
104 */
105 public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
106
107 /**
Tracy Zhoube13d102020-01-12 01:07:59 -0800108 * Temporary table used specifically for grid migrations during wallpaper preview
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109 */
Tracy Zhoube13d102020-01-12 01:07:59 -0800110 public static final String PREVIEW_TABLE_NAME = "favorites_preview";
111
112 /**
Tracy Zhouf6018722020-02-06 16:37:16 -0800113 * Temporary table used specifically for multi-db grid migrations
114 */
115 public static final String TMP_TABLE = "favorites_tmp";
116
117 /**
Tracy Zhoube13d102020-01-12 01:07:59 -0800118 * The content:// style URL for "favorites" table
119 */
120 public static final Uri CONTENT_URI = Uri.parse("content://"
121 + LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
122
123 /**
124 * The content:// style URL for "favorites_preview" table
125 */
126 public static final Uri PREVIEW_CONTENT_URI = Uri.parse("content://"
127 + LauncherProvider.AUTHORITY + "/" + PREVIEW_TABLE_NAME);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128
129 /**
Tracy Zhouf6018722020-02-06 16:37:16 -0800130 * The content:// style URL for "favorites_tmp" table
131 */
132 public static final Uri TMP_CONTENT_URI = Uri.parse("content://"
133 + LauncherProvider.AUTHORITY + "/" + TMP_TABLE);
134
135 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136 * The content:// style URL for a given row, identified by its id.
137 *
138 * @param id The row id.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 *
140 * @return The unique content URL for the specified row.
141 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700142 public static Uri getContentUri(int id) {
Tracy Zhoube13d102020-01-12 01:07:59 -0800143 return Uri.parse("content://" + LauncherProvider.AUTHORITY
144 + "/" + TABLE_NAME + "/" + id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145 }
146
147 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 * The container holding the favorite
149 * <P>Type: INTEGER</P>
150 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700151 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
153 /**
154 * The icon is a resource identified by a package name and an integer id.
155 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700156 public static final int CONTAINER_DESKTOP = -100;
157 public static final int CONTAINER_HOTSEAT = -101;
Samuel Fufa866ff002019-08-09 16:16:06 -0700158 public static final int CONTAINER_PREDICTION = -102;
Samuel Fufa225ac272019-10-21 02:02:40 -0700159 public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
thiruram261c3a62020-04-29 16:23:15 -0700160 public static final int CONTAINER_ALL_APPS = -104;
thiruram6bf68482020-05-06 22:19:43 -0700161 public static final int CONTAINER_WIDGETS_TRAY = -105;
thiruram62c7b5c2020-05-19 09:31:38 -0700162 // Represents search results view.
163 public static final int CONTAINER_SEARCH_RESULTS = -106;
thiruram63bf8ee2020-06-01 12:03:19 -0700164 public static final int CONTAINER_SHORTCUTS = -107;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165
Sunny Goyale396abf2020-04-06 15:11:17 -0700166 public static final String containerToString(int container) {
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500167 switch (container) {
168 case CONTAINER_DESKTOP: return "desktop";
169 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700170 case CONTAINER_PREDICTION: return "prediction";
thiruram6bf68482020-05-06 22:19:43 -0700171 case CONTAINER_ALL_APPS: return "all_apps";
172 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
thiruram62c7b5c2020-05-19 09:31:38 -0700173 case CONTAINER_SEARCH_RESULTS: return "search_result";
thiruram63bf8ee2020-06-01 12:03:19 -0700174 case CONTAINER_SHORTCUTS: return "shortcuts";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500175 default: return String.valueOf(container);
176 }
177 }
178
Sunny Goyale396abf2020-04-06 15:11:17 -0700179 public static final String itemTypeToString(int type) {
Hyunyoung Song86160f52017-02-06 10:46:24 -0800180 switch(type) {
181 case ITEM_TYPE_APPLICATION: return "APP";
182 case ITEM_TYPE_SHORTCUT: return "SHORTCUT";
183 case ITEM_TYPE_FOLDER: return "FOLDER";
184 case ITEM_TYPE_APPWIDGET: return "WIDGET";
185 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
186 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
187 default: return String.valueOf(type);
188 }
189 }
190
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 /**
192 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
193 * <P>Type: INTEGER</P>
194 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700195 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196
197 /**
198 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700199 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800200 * <P>Type: INTEGER</P>
201 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700202 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800203
204 /**
205 * The Y coordinate of the cell holding the favorite
206 * (if container is CONTAINER_DESKTOP)
207 * <P>Type: INTEGER</P>
208 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700209 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
211 /**
212 * The X span of the cell holding the favorite
213 * <P>Type: INTEGER</P>
214 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700215 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
217 /**
218 * The Y span of the cell holding the favorite
219 * <P>Type: INTEGER</P>
220 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700221 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222
223 /**
Kenny Guyed131872014-04-30 03:02:21 +0100224 * The profile id of the item in the cell.
225 * <P>
226 * Type: INTEGER
227 * </P>
228 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700229 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100230
231 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232 * The favorite is a user created folder
233 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700234 public static final int ITEM_TYPE_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235
236 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700237 * The favorite is a widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700239 public static final int ITEM_TYPE_APPWIDGET = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800240
241 /**
Adam Cohen59400422014-03-05 18:07:04 -0800242 * The favorite is a custom widget provided by the launcher
243 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700244 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
Adam Cohen59400422014-03-05 18:07:04 -0800245
246 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700247 * The gesture is an application created deep shortcut
248 */
249 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
250
251 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700252 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 *
254 * <P>Type: INTEGER</P>
255 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700256 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400257
258 /**
259 * The ComponentName of the widget provider
260 *
261 * <P>Type: STRING</P>
262 */
263 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500264
265 /**
266 * Boolean indicating that his item was restored and not yet successfully bound.
267 * <P>Type: INTEGER</P>
268 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700269 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800270
271 /**
272 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
273 * <p>Type: INTEGER</p>
274 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700275 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700276
277 /**
278 * Stores general flag based options for {@link ItemInfo}s.
279 * <p>Type: INTEGER</p>
280 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700281 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700282
283 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700284 addTableToDb(db, myProfileId, optional, TABLE_NAME);
285 }
286
287 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
288 String tableName) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700289 String ifNotExists = optional ? " IF NOT EXISTS " : "";
Sunny Goyal161a2142018-10-29 14:02:20 -0700290 db.execSQL("CREATE TABLE " + ifNotExists + tableName + " (" +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700291 "_id INTEGER PRIMARY KEY," +
292 "title TEXT," +
293 "intent TEXT," +
294 "container INTEGER," +
295 "screen INTEGER," +
296 "cellX INTEGER," +
297 "cellY INTEGER," +
298 "spanX INTEGER," +
299 "spanY INTEGER," +
300 "itemType INTEGER," +
301 "appWidgetId INTEGER NOT NULL DEFAULT -1," +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700302 "iconPackage TEXT," +
303 "iconResource TEXT," +
304 "icon BLOB," +
305 "appWidgetProvider TEXT," +
306 "modified INTEGER NOT NULL DEFAULT 0," +
307 "restored INTEGER NOT NULL DEFAULT 0," +
308 "profileId INTEGER DEFAULT " + myProfileId + "," +
309 "rank INTEGER NOT NULL DEFAULT 0," +
310 "options INTEGER NOT NULL DEFAULT 0" +
311 ");");
312 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800313 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700314
315 /**
316 * Launcher settings
317 */
318 public static final class Settings {
319
320 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800321 LauncherProvider.AUTHORITY + "/settings");
Sunny Goyal7779d622015-06-11 16:18:39 -0700322
Sunny Goyald2497482015-09-22 18:24:19 -0700323 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700324 public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
Sunny Goyald2497482015-09-22 18:24:19 -0700325
326 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
Sunny Goyald2497482015-09-22 18:24:19 -0700327
328 public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
329 public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
330
331 public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
Sunny Goyald2497482015-09-22 18:24:19 -0700332
333 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
Sunny Goyal7779d622015-06-11 16:18:39 -0700334
Sunny Goyal55fddc82017-04-06 15:02:52 -0700335 public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
336
Sunny Goyal161a2142018-10-29 14:02:20 -0700337 public static final String METHOD_NEW_TRANSACTION = "new_db_transaction";
338
339 public static final String METHOD_REFRESH_BACKUP_TABLE = "refresh_backup_table";
340
Samuel Fufaf667a132020-05-29 14:47:42 -0700341 public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table";
342
Pinyao Tingba9c5572019-09-24 14:25:46 -0700343 public static final String METHOD_RESTORE_BACKUP_TABLE = "restore_backup_table";
344
Tracy Zhou7df93d22020-01-27 13:44:06 -0800345 public static final String METHOD_UPDATE_CURRENT_OPEN_HELPER = "update_current_open_helper";
346
Tracy Zhouc0000452020-03-17 18:28:38 -0700347 public static final String METHOD_PREP_FOR_PREVIEW = "prep_for_preview";
348
Sunny Goyal7779d622015-06-11 16:18:39 -0700349 public static final String EXTRA_VALUE = "value";
Sunny Goyald2497482015-09-22 18:24:19 -0700350
351 public static Bundle call(ContentResolver cr, String method) {
Tracy Zhouc0000452020-03-17 18:28:38 -0700352 return call(cr, method, null);
353 }
354
355 public static Bundle call(ContentResolver cr, String method, String arg) {
356 return cr.call(CONTENT_URI, method, arg, null);
Sunny Goyald2497482015-09-22 18:24:19 -0700357 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700358 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359}