• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.launcher3;
18 
19 import android.content.ContentResolver;
20 import android.database.sqlite.SQLiteDatabase;
21 import android.net.Uri;
22 import android.os.Bundle;
23 import android.provider.BaseColumns;
24 
25 import com.android.launcher3.model.data.ItemInfo;
26 
27 /**
28  * Settings related utilities.
29  */
30 public class LauncherSettings {
31 
32     /**
33      * Favorites.
34      */
35     public static final class Favorites implements BaseColumns {
36         /**
37          * The time of the last update to this row.
38          * <P>Type: INTEGER</P>
39          */
40         public static final String MODIFIED = "modified";
41 
42         /**
43          * Descriptive name of the gesture that can be displayed to the user.
44          * <P>Type: TEXT</P>
45          */
46         public static final String TITLE = "title";
47 
48         /**
49          * The Intent URL of the gesture, describing what it points to. This
50          * value is given to {@link android.content.Intent#parseUri(String, int)} to create
51          * an Intent that can be launched.
52          * <P>Type: TEXT</P>
53          */
54         public static final String INTENT = "intent";
55 
56         /**
57          * The type of the gesture
58          *
59          * <P>Type: INTEGER</P>
60          */
61         public static final String ITEM_TYPE = "itemType";
62 
63         /**
64          * The gesture is a package
65          */
66         public static final int ITEM_TYPE_NON_ACTIONABLE = -1;
67         /**
68          * The gesture is an application
69          */
70         public static final int ITEM_TYPE_APPLICATION = 0;
71 
72         /**
73          * The gesture is an application created shortcut
74          */
75         public static final int ITEM_TYPE_SHORTCUT = 1;
76 
77         /**
78          * The favorite is a user created folder
79          */
80         public static final int ITEM_TYPE_FOLDER = 2;
81 
82         /**
83          * The favorite is a widget
84          */
85         public static final int ITEM_TYPE_APPWIDGET = 4;
86 
87         /**
88          * The favorite is a custom widget provided by the launcher
89          */
90         public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
91 
92         /**
93          * The gesture is an application created deep shortcut
94          */
95         public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
96 
97         /**
98          * Type of the item is recents task.
99          * TODO(hyunyoungs): move constants not related to Favorites DB to a better location.
100          */
101         public static final int ITEM_TYPE_TASK = 7;
102 
103         /**
104          * The item is QSB
105          */
106         public static final int ITEM_TYPE_QSB = 8;
107 
108         /**
109          * The icon package name in Intent.ShortcutIconResource
110          * <P>Type: TEXT</P>
111          */
112         public static final String ICON_PACKAGE = "iconPackage";
113 
114         /**
115          * The icon resource name in Intent.ShortcutIconResource
116          * <P>Type: TEXT</P>
117          */
118         public static final String ICON_RESOURCE = "iconResource";
119 
120         /**
121          * The custom icon bitmap.
122          * <P>Type: BLOB</P>
123          */
124         public static final String ICON = "icon";
125 
126         public static final String TABLE_NAME = "favorites";
127 
128         /**
129          * Backup table created when the favorites table is modified during grid migration
130          */
131         public static final String BACKUP_TABLE_NAME = "favorites_bakup";
132 
133         /**
134          * Backup table created when user hotseat is moved to workspace for hybrid hotseat
135          */
136         public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
137 
138         /**
139          * Temporary table used specifically for grid migrations during wallpaper preview
140          */
141         public static final String PREVIEW_TABLE_NAME = "favorites_preview";
142 
143         /**
144          * Temporary table used specifically for multi-db grid migrations
145          */
146         public static final String TMP_TABLE = "favorites_tmp";
147 
148         /**
149          * The content:// style URL for "favorites" table
150          */
151         public static final Uri CONTENT_URI = Uri.parse("content://"
152                 + LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
153 
154         /**
155          * The content:// style URL for "favorites_bakup" table
156          */
157         public static final Uri BACKUP_CONTENT_URI = Uri.parse("content://"
158                 + LauncherProvider.AUTHORITY + "/" + BACKUP_TABLE_NAME);
159 
160         /**
161          * The content:// style URL for "favorites_preview" table
162          */
163         public static final Uri PREVIEW_CONTENT_URI = Uri.parse("content://"
164                 + LauncherProvider.AUTHORITY + "/" + PREVIEW_TABLE_NAME);
165 
166         /**
167          * The content:// style URL for "favorites_tmp" table
168          */
169         public static final Uri TMP_CONTENT_URI = Uri.parse("content://"
170                 + LauncherProvider.AUTHORITY + "/" + TMP_TABLE);
171 
172         /**
173          * The content:// style URL for a given row, identified by its id.
174          *
175          * @param id The row id.
176          *
177          * @return The unique content URL for the specified row.
178          */
getContentUri(int id)179         public static Uri getContentUri(int id) {
180             return Uri.parse("content://" + LauncherProvider.AUTHORITY
181                     + "/" + TABLE_NAME + "/" + id);
182         }
183 
184         /**
185          * The container holding the favorite
186          * <P>Type: INTEGER</P>
187          */
188         public static final String CONTAINER = "container";
189 
190         /**
191          * The icon is a resource identified by a package name and an integer id.
192          */
193         public static final int CONTAINER_DESKTOP = -100;
194         public static final int CONTAINER_HOTSEAT = -101;
195         public static final int CONTAINER_PREDICTION = -102;
196         public static final int CONTAINER_WIDGETS_PREDICTION = -111;
197         public static final int CONTAINER_HOTSEAT_PREDICTION = -103;
198         public static final int CONTAINER_ALL_APPS = -104;
199         public static final int CONTAINER_WIDGETS_TRAY = -105;
200         public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112;
201         public static final int CONTAINER_PIN_WIDGETS = -113;
202         // Represents search results view.
203         public static final int CONTAINER_SEARCH_RESULTS = -106;
204         public static final int CONTAINER_SHORTCUTS = -107;
205         public static final int CONTAINER_SETTINGS = -108;
206         public static final int CONTAINER_TASKSWITCHER = -109;
207         public static final int CONTAINER_QSB = -110;
208 
209         // Represents any of the extended containers implemented in non-AOSP variants.
210         public static final int EXTENDED_CONTAINERS = -200;
211 
212         public static final int CONTAINER_UNKNOWN = -1;
213 
containerToString(int container)214         public static final String containerToString(int container) {
215             switch (container) {
216                 case CONTAINER_DESKTOP: return "desktop";
217                 case CONTAINER_HOTSEAT: return "hotseat";
218                 case CONTAINER_PREDICTION: return "prediction";
219                 case CONTAINER_ALL_APPS: return "all_apps";
220                 case CONTAINER_WIDGETS_TRAY: return "widgets_tray";
221                 case CONTAINER_SEARCH_RESULTS: return "search_result";
222                 case CONTAINER_SHORTCUTS: return "shortcuts";
223                 default: return String.valueOf(container);
224             }
225         }
226 
itemTypeToString(int type)227         public static final String itemTypeToString(int type) {
228             switch(type) {
229                 case ITEM_TYPE_APPLICATION: return "APP";
230                 case ITEM_TYPE_SHORTCUT: return "SHORTCUT";
231                 case ITEM_TYPE_FOLDER: return "FOLDER";
232                 case ITEM_TYPE_APPWIDGET: return "WIDGET";
233                 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
234                 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
235                 case ITEM_TYPE_TASK: return "TASK";
236                 case ITEM_TYPE_QSB: return "QSB";
237                 default: return String.valueOf(type);
238             }
239         }
240 
241         /**
242          * The screen holding the favorite (if container is CONTAINER_DESKTOP)
243          * <P>Type: INTEGER</P>
244          */
245         public static final String SCREEN = "screen";
246 
247         /**
248          * The X coordinate of the cell holding the favorite
249          * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
250          * <P>Type: INTEGER</P>
251          */
252         public static final String CELLX = "cellX";
253 
254         /**
255          * The Y coordinate of the cell holding the favorite
256          * (if container is CONTAINER_DESKTOP)
257          * <P>Type: INTEGER</P>
258          */
259         public static final String CELLY = "cellY";
260 
261         /**
262          * The X span of the cell holding the favorite
263          * <P>Type: INTEGER</P>
264          */
265         public static final String SPANX = "spanX";
266 
267         /**
268          * The Y span of the cell holding the favorite
269          * <P>Type: INTEGER</P>
270          */
271         public static final String SPANY = "spanY";
272 
273         /**
274          * The profile id of the item in the cell.
275          * <P>
276          * Type: INTEGER
277          * </P>
278          */
279         public static final String PROFILE_ID = "profileId";
280 
281         /**
282          * The appWidgetId of the widget
283          *
284          * <P>Type: INTEGER</P>
285          */
286         public static final String APPWIDGET_ID = "appWidgetId";
287 
288         /**
289          * The ComponentName of the widget provider
290          *
291          * <P>Type: STRING</P>
292          */
293         public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
294 
295         /**
296          * Boolean indicating that his item was restored and not yet successfully bound.
297          * <P>Type: INTEGER</P>
298          */
299         public static final String RESTORED = "restored";
300 
301         /**
302          * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
303          * <p>Type: INTEGER</p>
304          */
305         public static final String RANK = "rank";
306 
307         /**
308          * Stores general flag based options for {@link ItemInfo}s.
309          * <p>Type: INTEGER</p>
310          */
311         public static final String OPTIONS = "options";
312 
313         /**
314          * Stores the source container that the widget was added from.
315          * <p>Type: INTEGER</p>
316          */
317         public static final String APPWIDGET_SOURCE = "appWidgetSource";
318 
addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional)319         public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
320             addTableToDb(db, myProfileId, optional, TABLE_NAME);
321         }
322 
addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional, String tableName)323         public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
324                 String tableName) {
325             String ifNotExists = optional ? " IF NOT EXISTS " : "";
326             db.execSQL("CREATE TABLE " + ifNotExists + tableName + " (" +
327                     "_id INTEGER PRIMARY KEY," +
328                     "title TEXT," +
329                     "intent TEXT," +
330                     "container INTEGER," +
331                     "screen INTEGER," +
332                     "cellX INTEGER," +
333                     "cellY INTEGER," +
334                     "spanX INTEGER," +
335                     "spanY INTEGER," +
336                     "itemType INTEGER," +
337                     "appWidgetId INTEGER NOT NULL DEFAULT -1," +
338                     "iconPackage TEXT," +
339                     "iconResource TEXT," +
340                     "icon BLOB," +
341                     "appWidgetProvider TEXT," +
342                     "modified INTEGER NOT NULL DEFAULT 0," +
343                     "restored INTEGER NOT NULL DEFAULT 0," +
344                     "profileId INTEGER DEFAULT " + myProfileId + "," +
345                     "rank INTEGER NOT NULL DEFAULT 0," +
346                     "options INTEGER NOT NULL DEFAULT 0," +
347                     APPWIDGET_SOURCE + " INTEGER NOT NULL DEFAULT " + CONTAINER_UNKNOWN +
348                     ");");
349         }
350     }
351 
352     /**
353      * Launcher settings
354      */
355     public static final class Settings {
356 
357         public static final Uri CONTENT_URI = Uri.parse("content://" +
358                 LauncherProvider.AUTHORITY + "/settings");
359 
360         public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
361         public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
362 
363         public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
364 
365         public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
366         public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
367 
368         public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
369 
370         public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
371 
372         public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
373 
374         public static final String METHOD_NEW_TRANSACTION = "new_db_transaction";
375 
376         public static final String METHOD_REFRESH_BACKUP_TABLE = "refresh_backup_table";
377 
378         public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table";
379 
380         public static final String METHOD_RESTORE_BACKUP_TABLE = "restore_backup_table";
381 
382         public static final String METHOD_UPDATE_CURRENT_OPEN_HELPER = "update_current_open_helper";
383 
384         public static final String METHOD_PREP_FOR_PREVIEW = "prep_for_preview";
385 
386         public static final String METHOD_SWITCH_DATABASE = "switch_database";
387 
388         public static final String EXTRA_VALUE = "value";
389 
390         public static final String EXTRA_DB_NAME = "db_name";
391 
call(ContentResolver cr, String method)392         public static Bundle call(ContentResolver cr, String method) {
393             return call(cr, method, null /* arg */);
394         }
395 
call(ContentResolver cr, String method, String arg)396         public static Bundle call(ContentResolver cr, String method, String arg) {
397             return call(cr, method, arg, null /* extras */);
398         }
399 
call(ContentResolver cr, String method, String arg, Bundle extras)400         public static Bundle call(ContentResolver cr, String method, String arg, Bundle extras) {
401             return cr.call(CONTENT_URI, method, arg, extras);
402         }
403     }
404 }
405