blob: 216c221dc61ab591448a81119616d924bbb688de [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
25/**
26 * Settings related utilities.
27 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070028public class LauncherSettings {
Sunny Goyalc5939392018-12-07 11:43:47 -080029
30 /**
31 * Favorites.
32 */
33 public static final class Favorites implements BaseColumns {
Chris Wren1ada10d2013-09-13 18:01:38 -040034 /**
35 * The time of the last update to this row.
36 * <P>Type: INTEGER</P>
37 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070038 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040039
Romain Guy73b979d2009-06-09 12:57:21 -070040 /**
41 * Descriptive name of the gesture that can be displayed to the user.
42 * <P>Type: TEXT</P>
43 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070044 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070045
46 /**
47 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070048 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070049 * an Intent that can be launched.
50 * <P>Type: TEXT</P>
51 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070052 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070053
54 /**
55 * The type of the gesture
56 *
57 * <P>Type: INTEGER</P>
58 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070059 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070060
61 /**
Samuel Fufad3720c22019-09-06 11:25:08 -070062 * The gesture is a package
63 */
64 public static final int ITEM_TYPE_NON_ACTIONABLE = -1;
65 /**
Romain Guy73b979d2009-06-09 12:57:21 -070066 * The gesture is an application
67 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070068 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070069
70 /**
71 * The gesture is an application created shortcut
72 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070073 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070074
75 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070076 * The icon package name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070077 * <P>Type: TEXT</P>
78 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070079 public static final String ICON_PACKAGE = "iconPackage";
Romain Guy73b979d2009-06-09 12:57:21 -070080
81 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070082 * The icon resource name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070083 * <P>Type: TEXT</P>
84 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070085 public static final String ICON_RESOURCE = "iconResource";
Romain Guy73b979d2009-06-09 12:57:21 -070086
87 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070088 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -070089 * <P>Type: BLOB</P>
90 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070091 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -070092
93 public static final String TABLE_NAME = "favorites";
94
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095 /**
Tracy Zhoube13d102020-01-12 01:07:59 -080096 * Backup table created when the favorites table is modified during grid migration
Sunny Goyal161a2142018-10-29 14:02:20 -070097 */
98 public static final String BACKUP_TABLE_NAME = "favorites_bakup";
99
100 /**
Tracy Zhoube13d102020-01-12 01:07:59 -0800101 * Temporary table used specifically for grid migrations during wallpaper preview
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800102 */
Tracy Zhoube13d102020-01-12 01:07:59 -0800103 public static final String PREVIEW_TABLE_NAME = "favorites_preview";
104
105 /**
106 * The content:// style URL for "favorites" table
107 */
108 public static final Uri CONTENT_URI = Uri.parse("content://"
109 + LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
110
111 /**
112 * The content:// style URL for "favorites_preview" table
113 */
114 public static final Uri PREVIEW_CONTENT_URI = Uri.parse("content://"
115 + LauncherProvider.AUTHORITY + "/" + PREVIEW_TABLE_NAME);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
117 /**
118 * The content:// style URL for a given row, identified by its id.
119 *
120 * @param id The row id.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 *
122 * @return The unique content URL for the specified row.
123 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700124 public static Uri getContentUri(int id) {
Tracy Zhoube13d102020-01-12 01:07:59 -0800125 return Uri.parse("content://" + LauncherProvider.AUTHORITY
126 + "/" + TABLE_NAME + "/" + id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 }
128
129 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 * The container holding the favorite
131 * <P>Type: INTEGER</P>
132 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700133 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134
135 /**
136 * The icon is a resource identified by a package name and an integer id.
137 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700138 public static final int CONTAINER_DESKTOP = -100;
139 public static final int CONTAINER_HOTSEAT = -101;
Samuel Fufa866ff002019-08-09 16:16:06 -0700140 public static final int CONTAINER_PREDICTION = -102;
Samuel Fufa225ac272019-10-21 02:02:40 -0700141 public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500143 static final String containerToString(int container) {
144 switch (container) {
145 case CONTAINER_DESKTOP: return "desktop";
146 case CONTAINER_HOTSEAT: return "hotseat";
Samuel Fufa866ff002019-08-09 16:16:06 -0700147 case CONTAINER_PREDICTION: return "prediction";
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500148 default: return String.valueOf(container);
149 }
150 }
151
Hyunyoung Song86160f52017-02-06 10:46:24 -0800152 static final String itemTypeToString(int type) {
153 switch(type) {
154 case ITEM_TYPE_APPLICATION: return "APP";
155 case ITEM_TYPE_SHORTCUT: return "SHORTCUT";
156 case ITEM_TYPE_FOLDER: return "FOLDER";
157 case ITEM_TYPE_APPWIDGET: return "WIDGET";
158 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
159 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
160 default: return String.valueOf(type);
161 }
162 }
163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 /**
165 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
166 * <P>Type: INTEGER</P>
167 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700168 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169
170 /**
171 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700172 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 * <P>Type: INTEGER</P>
174 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700175 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
177 /**
178 * The Y coordinate of the cell holding the favorite
179 * (if container is CONTAINER_DESKTOP)
180 * <P>Type: INTEGER</P>
181 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700182 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
184 /**
185 * The X span of the cell holding the favorite
186 * <P>Type: INTEGER</P>
187 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700188 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189
190 /**
191 * The Y span of the cell holding the favorite
192 * <P>Type: INTEGER</P>
193 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700194 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195
196 /**
Kenny Guyed131872014-04-30 03:02:21 +0100197 * The profile id of the item in the cell.
198 * <P>
199 * Type: INTEGER
200 * </P>
201 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700202 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100203
204 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 * The favorite is a user created folder
206 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700207 public static final int ITEM_TYPE_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208
209 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700210 * The favorite is a widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700212 public static final int ITEM_TYPE_APPWIDGET = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213
214 /**
Adam Cohen59400422014-03-05 18:07:04 -0800215 * The favorite is a custom widget provided by the launcher
216 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700217 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
Adam Cohen59400422014-03-05 18:07:04 -0800218
219 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700220 * The gesture is an application created deep shortcut
221 */
222 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
223
224 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700225 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226 *
227 * <P>Type: INTEGER</P>
228 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700229 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400230
231 /**
232 * The ComponentName of the widget provider
233 *
234 * <P>Type: STRING</P>
235 */
236 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500237
238 /**
239 * Boolean indicating that his item was restored and not yet successfully bound.
240 * <P>Type: INTEGER</P>
241 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700242 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800243
244 /**
245 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
246 * <p>Type: INTEGER</p>
247 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700248 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700249
250 /**
251 * Stores general flag based options for {@link ItemInfo}s.
252 * <p>Type: INTEGER</p>
253 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700254 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700255
256 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700257 addTableToDb(db, myProfileId, optional, TABLE_NAME);
258 }
259
260 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
261 String tableName) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700262 String ifNotExists = optional ? " IF NOT EXISTS " : "";
Sunny Goyal161a2142018-10-29 14:02:20 -0700263 db.execSQL("CREATE TABLE " + ifNotExists + tableName + " (" +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700264 "_id INTEGER PRIMARY KEY," +
265 "title TEXT," +
266 "intent TEXT," +
267 "container INTEGER," +
268 "screen INTEGER," +
269 "cellX INTEGER," +
270 "cellY INTEGER," +
271 "spanX INTEGER," +
272 "spanY INTEGER," +
273 "itemType INTEGER," +
274 "appWidgetId INTEGER NOT NULL DEFAULT -1," +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700275 "iconPackage TEXT," +
276 "iconResource TEXT," +
277 "icon BLOB," +
278 "appWidgetProvider TEXT," +
279 "modified INTEGER NOT NULL DEFAULT 0," +
280 "restored INTEGER NOT NULL DEFAULT 0," +
281 "profileId INTEGER DEFAULT " + myProfileId + "," +
282 "rank INTEGER NOT NULL DEFAULT 0," +
283 "options INTEGER NOT NULL DEFAULT 0" +
284 ");");
285 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700287
288 /**
289 * Launcher settings
290 */
291 public static final class Settings {
292
293 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800294 LauncherProvider.AUTHORITY + "/settings");
Sunny Goyal7779d622015-06-11 16:18:39 -0700295
Sunny Goyald2497482015-09-22 18:24:19 -0700296 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700297 public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
Sunny Goyald2497482015-09-22 18:24:19 -0700298
299 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
Sunny Goyald2497482015-09-22 18:24:19 -0700300
301 public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
302 public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
303
304 public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
Sunny Goyald2497482015-09-22 18:24:19 -0700305
306 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
Sunny Goyal7779d622015-06-11 16:18:39 -0700307
Sunny Goyal55fddc82017-04-06 15:02:52 -0700308 public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
309
Sunny Goyal161a2142018-10-29 14:02:20 -0700310 public static final String METHOD_NEW_TRANSACTION = "new_db_transaction";
311
312 public static final String METHOD_REFRESH_BACKUP_TABLE = "refresh_backup_table";
313
Pinyao Tingba9c5572019-09-24 14:25:46 -0700314 public static final String METHOD_RESTORE_BACKUP_TABLE = "restore_backup_table";
315
Tracy Zhou7df93d22020-01-27 13:44:06 -0800316 public static final String METHOD_UPDATE_CURRENT_OPEN_HELPER = "update_current_open_helper";
317
Sunny Goyal7779d622015-06-11 16:18:39 -0700318 public static final String EXTRA_VALUE = "value";
Sunny Goyald2497482015-09-22 18:24:19 -0700319
320 public static Bundle call(ContentResolver cr, String method) {
321 return cr.call(CONTENT_URI, method, null, null);
322 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700323 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800324}