blob: 63027446990ffcbaa751f867225c07aca5adf5c8 [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
The Android Open Source Project7376fae2009-03-11 12:11:58 -070019import android.appwidget.AppWidgetHost;
Mike Cleronb87bd162009-10-30 16:36:56 -070020import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.content.ComponentName;
Adam Cohen228da5a2011-07-27 22:23:47 -070022import android.content.ContentProvider;
Yura085c8532014-02-11 15:15:29 +000023import android.content.ContentProviderOperation;
24import android.content.ContentProviderResult;
Adam Cohen228da5a2011-07-27 22:23:47 -070025import android.content.ContentUris;
26import android.content.ContentValues;
27import android.content.Context;
28import android.content.Intent;
Yura085c8532014-02-11 15:15:29 +000029import android.content.OperationApplicationException;
Michael Jurkab85f8a42012-04-25 15:48:32 -070030import android.content.SharedPreferences;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070031import android.content.pm.PackageManager.NameNotFoundException;
Adam Cohen228da5a2011-07-27 22:23:47 -070032import android.content.res.Resources;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033import android.database.Cursor;
34import android.database.SQLException;
Adam Cohen228da5a2011-07-27 22:23:47 -070035import android.database.sqlite.SQLiteDatabase;
36import android.database.sqlite.SQLiteOpenHelper;
37import android.database.sqlite.SQLiteQueryBuilder;
Sunny Goyal0b037782015-04-02 10:27:03 -070038import android.database.sqlite.SQLiteStatement;
Adam Cohen228da5a2011-07-27 22:23:47 -070039import android.net.Uri;
Sunny Goyal7779d622015-06-11 16:18:39 -070040import android.os.Binder;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070041import android.os.Bundle;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070042import android.os.Handler;
43import android.os.Message;
Sunny Goyal7779d622015-06-11 16:18:39 -070044import android.os.Process;
Sunny Goyale26d1002016-06-20 14:52:14 -070045import android.os.Trace;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080046import android.os.UserHandle;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070047import android.os.UserManager;
Adam Cohen228da5a2011-07-27 22:23:47 -070048import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.util.Log;
Hyunyoung Songe295aca2017-02-06 10:46:24 -080050import android.view.ViewGroup;
Adam Cohen228da5a2011-07-27 22:23:47 -070051
Sunny Goyal0fe505b2014-08-06 09:55:36 -070052import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
53import com.android.launcher3.LauncherSettings.Favorites;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070054import com.android.launcher3.LauncherSettings.WorkspaceScreens;
Kenny Guyed131872014-04-30 03:02:21 +010055import com.android.launcher3.compat.UserManagerCompat;
Sunny Goyala9e2f5a2016-06-10 12:22:04 -070056import com.android.launcher3.config.FeatureFlags;
Chris Wrene523e702013-10-09 10:36:55 -040057import com.android.launcher3.config.ProviderConfig;
Tony Wickham827cef22016-03-17 15:39:39 -070058import com.android.launcher3.dynamicui.ExtractionUtils;
Sunny Goyalca187462017-03-31 20:09:34 -070059import com.android.launcher3.graphics.IconShapeOverride;
Sunny Goyalfdbef272017-02-01 12:52:54 -080060import com.android.launcher3.logging.FileLog;
Sunny Goyala9e2f5a2016-06-10 12:22:04 -070061import com.android.launcher3.provider.LauncherDbUtils;
Sunny Goyale8f7d5a2016-05-24 11:30:14 -070062import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyale2fba6c2015-05-12 10:39:59 -070063import com.android.launcher3.util.ManagedProfileHeuristic;
Sunny Goyalbf67f3b2016-03-15 15:30:11 -070064import com.android.launcher3.util.NoLocaleSqliteContext;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070065import com.android.launcher3.util.Preconditions;
Adam Cohen091440a2015-03-18 14:16:05 -070066import com.android.launcher3.util.Thunk;
Michael Jurka8b805b12012-04-18 14:23:14 -070067
Hyunyoung Songe295aca2017-02-06 10:46:24 -080068import java.io.FileDescriptor;
69import java.io.PrintWriter;
Mike Cleronb87bd162009-10-30 16:36:56 -070070import java.net.URISyntaxException;
Adam Cohen228da5a2011-07-27 22:23:47 -070071import java.util.ArrayList;
Adam Cohen71483f42014-05-15 14:04:01 -070072import java.util.Collections;
Louis Begina9c21c62016-08-15 15:18:41 -070073import java.util.Locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075public class LauncherProvider extends ContentProvider {
Sunny Goyalc74e4192015-09-08 14:01:03 -070076 private static final String TAG = "LauncherProvider";
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080077 private static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078
Sunny Goyal3c7d55b2017-04-13 12:01:47 -070079 /**
80 * Represents the schema of the database. Changes in scheme need not be backwards compatible.
81 */
82 private static final int SCHEMA_VERSION = 27;
83 /**
84 * Represents the actual data. It could include additional validations and normalizations added
85 * overtime. These must be backwards compatible, else we risk breaking old devices during
86 * restore or binary version downgrade.
87 */
88 private static final int DATA_VERSION = 2;
89
90 private static final String PREF_KEY_DATA_VERISON = "provider_data_version";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091
Sunny Goyale5bb7052015-07-27 14:36:07 -070092 public static final String AUTHORITY = ProviderConfig.AUTHORITY;
Winson Chung3d503fb2011-07-13 17:25:49 -070093
Sunny Goyale87e6ab2014-11-21 22:42:53 -080094 static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070096 private static final String RESTRICTION_PACKAGE_NAME = "workspace.configuration.package.name";
97
Sunny Goyalb5b55c82016-05-10 12:28:59 -070098 private final ChangeListenerWrapper mListenerWrapper = new ChangeListenerWrapper();
99 private Handler mListenerHandler;
100
Sunny Goyalf076eae2016-01-11 12:25:10 -0800101 protected DatabaseHelper mOpenHelper;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800102
Hyunyoung Songe295aca2017-02-06 10:46:24 -0800103 /**
104 * $ adb shell dumpsys activity provider com.android.launcher3
105 */
106 @Override
107 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
108 LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
109 if (appState == null || !appState.getModel().isModelLoaded()) {
110 return;
111 }
112 appState.getModel().dumpState("", fd, writer, args);
113 }
114
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115 @Override
116 public boolean onCreate() {
Sunny Goyale26d1002016-06-20 14:52:14 -0700117 if (ProviderConfig.IS_DOGFOOD_BUILD) {
118 Log.d(TAG, "Launcher process started");
119 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700120 mListenerHandler = new Handler(mListenerWrapper);
121
Sunny Goyalfdbef272017-02-01 12:52:54 -0800122 // The content provider exists for the entire duration of the launcher main process and
123 // is the first component to get created. Initializing FileLog here ensures that it's
124 // always available in the main process.
125 FileLog.setDir(getContext().getApplicationContext().getFilesDir());
Sunny Goyalca187462017-03-31 20:09:34 -0700126 IconShapeOverride.apply(getContext());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 return true;
128 }
129
Sunny Goyald3849d12015-10-29 10:28:32 -0700130 /**
131 * Sets a provider listener.
132 */
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700133 public void setLauncherProviderChangeListener(LauncherProviderChangeListener listener) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700134 Preconditions.assertUIThread();
135 mListenerWrapper.mListener = listener;
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700136 }
137
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138 @Override
139 public String getType(Uri uri) {
140 SqlArguments args = new SqlArguments(uri, null, null);
141 if (TextUtils.isEmpty(args.where)) {
142 return "vnd.android.cursor.dir/" + args.table;
143 } else {
144 return "vnd.android.cursor.item/" + args.table;
145 }
146 }
147
Sunny Goyalf076eae2016-01-11 12:25:10 -0800148 /**
149 * Overridden in tests
150 */
151 protected synchronized void createDbIfNotExists() {
Sunny Goyald3849d12015-10-29 10:28:32 -0700152 if (mOpenHelper == null) {
Sunny Goyale26d1002016-06-20 14:52:14 -0700153 if (LauncherAppState.PROFILE_STARTUP) {
154 Trace.beginSection("Opening workspace DB");
155 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700156 mOpenHelper = new DatabaseHelper(getContext(), mListenerHandler);
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700157
158 if (RestoreDbTask.isPending(getContext())) {
159 if (!RestoreDbTask.performRestore(mOpenHelper)) {
160 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
161 }
162 // Set is pending to false irrespective of the result, so that it doesn't get
163 // executed again.
164 RestoreDbTask.setPending(getContext(), false);
165 }
Sunny Goyale26d1002016-06-20 14:52:14 -0700166
167 if (LauncherAppState.PROFILE_STARTUP) {
168 Trace.endSection();
169 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700170 }
171 }
172
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 @Override
174 public Cursor query(Uri uri, String[] projection, String selection,
175 String[] selectionArgs, String sortOrder) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700176 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
178 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
179 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
180 qb.setTables(args.table);
181
Romain Guy73b979d2009-06-09 12:57:21 -0700182 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder);
184 result.setNotificationUri(getContext().getContentResolver(), uri);
185
186 return result;
187 }
188
Adam Cohen091440a2015-03-18 14:16:05 -0700189 @Thunk static long dbInsertAndCheck(DatabaseHelper helper,
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700190 SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
Dan Sandlerd5024042014-01-09 15:01:33 -0500191 if (values == null) {
192 throw new RuntimeException("Error: attempting to insert null values");
193 }
Adam Cohen71483f42014-05-15 14:04:01 -0700194 if (!values.containsKey(LauncherSettings.ChangeLogColumns._ID)) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700195 throw new RuntimeException("Error: attempting to add item without specifying an id");
196 }
Chris Wren5dee7af2013-12-20 17:22:11 -0500197 helper.checkId(table, values);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700198 return db.insert(table, nullColumnHack, values);
199 }
200
Sunny Goyald1064182015-08-13 12:08:30 -0700201 private void reloadLauncherIfExternal() {
Sunny Goyalc74e4192015-09-08 14:01:03 -0700202 if (Utilities.ATLEAST_MARSHMALLOW && Binder.getCallingPid() != Process.myPid()) {
Sunny Goyald1064182015-08-13 12:08:30 -0700203 LauncherAppState app = LauncherAppState.getInstanceNoCreate();
204 if (app != null) {
Sunny Goyaldd96a5e2017-02-17 11:22:34 -0800205 app.getModel().forceReload();
Sunny Goyald1064182015-08-13 12:08:30 -0700206 }
207 }
208 }
209
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210 @Override
211 public Uri insert(Uri uri, ContentValues initialValues) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700212 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 SqlArguments args = new SqlArguments(uri);
214
Sunny Goyald1064182015-08-13 12:08:30 -0700215 // In very limited cases, we support system|signature permission apps to modify the db.
216 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700217 if (!initializeExternalAdd(initialValues)) {
Adam Cohena043fa82014-07-23 14:49:38 -0700218 return null;
219 }
220 }
221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Chris Wren1ada10d2013-09-13 18:01:38 -0400223 addModifiedTime(initialValues);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700224 final long rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
Sunny Goyale72f3d52015-03-02 14:24:21 -0800225 if (rowId < 0) return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226
227 uri = ContentUris.withAppendedId(uri, rowId);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700228 notifyListeners();
229
Sunny Goyalc74e4192015-09-08 14:01:03 -0700230 if (Utilities.ATLEAST_MARSHMALLOW) {
231 reloadLauncherIfExternal();
232 } else {
233 // Deprecated behavior to support legacy devices which rely on provider callbacks.
234 LauncherAppState app = LauncherAppState.getInstanceNoCreate();
235 if (app != null && "true".equals(uri.getQueryParameter("isExternalAdd"))) {
Sunny Goyaldd96a5e2017-02-17 11:22:34 -0800236 app.getModel().forceReload();
Sunny Goyalc74e4192015-09-08 14:01:03 -0700237 }
238
239 String notify = uri.getQueryParameter("notify");
240 if (notify == null || "true".equals(notify)) {
241 getContext().getContentResolver().notifyChange(uri, null);
242 }
243 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 return uri;
245 }
246
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700247 private boolean initializeExternalAdd(ContentValues values) {
248 // 1. Ensure that externally added items have a valid item id
249 long id = mOpenHelper.generateNewItemId();
250 values.put(LauncherSettings.Favorites._ID, id);
251
252 // 2. In the case of an app widget, and if no app widget id is specified, we
253 // attempt allocate and bind the widget.
254 Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
255 if (itemType != null &&
256 itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET &&
257 !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {
258
259 final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
260 ComponentName cn = ComponentName.unflattenFromString(
261 values.getAsString(Favorites.APPWIDGET_PROVIDER));
262
263 if (cn != null) {
264 try {
265 int appWidgetId = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID)
266 .allocateAppWidgetId();
267 values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
268 if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {
269 return false;
270 }
271 } catch (RuntimeException e) {
272 Log.e(TAG, "Failed to initialize external widget", e);
273 return false;
274 }
275 } else {
276 return false;
277 }
278 }
279
280 // Add screen id if not present
281 long screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
282 SQLiteStatement stmp = null;
283 try {
284 stmp = mOpenHelper.getWritableDatabase().compileStatement(
285 "INSERT OR IGNORE INTO workspaceScreens (_id, screenRank) " +
286 "select ?, (ifnull(MAX(screenRank), -1)+1) from workspaceScreens");
287 stmp.bindLong(1, screenId);
288
289 ContentValues valuesInserted = new ContentValues();
290 valuesInserted.put(LauncherSettings.BaseLauncherColumns._ID, stmp.executeInsert());
291 mOpenHelper.checkId(WorkspaceScreens.TABLE_NAME, valuesInserted);
292 return true;
293 } catch (Exception e) {
294 return false;
295 } finally {
296 Utilities.closeSilently(stmp);
297 }
298 }
299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 @Override
301 public int bulkInsert(Uri uri, ContentValues[] values) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700302 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800303 SqlArguments args = new SqlArguments(uri);
304
305 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
306 db.beginTransaction();
307 try {
308 int numValues = values.length;
309 for (int i = 0; i < numValues; i++) {
Chris Wren1ada10d2013-09-13 18:01:38 -0400310 addModifiedTime(values[i]);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700311 if (dbInsertAndCheck(mOpenHelper, db, args.table, null, values[i]) < 0) {
312 return 0;
313 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314 }
315 db.setTransactionSuccessful();
316 } finally {
317 db.endTransaction();
318 }
319
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700320 notifyListeners();
Sunny Goyald1064182015-08-13 12:08:30 -0700321 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800322 return values.length;
323 }
324
325 @Override
Yura085c8532014-02-11 15:15:29 +0000326 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
327 throws OperationApplicationException {
Sunny Goyald3849d12015-10-29 10:28:32 -0700328 createDbIfNotExists();
Yura085c8532014-02-11 15:15:29 +0000329 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
330 db.beginTransaction();
331 try {
332 ContentProviderResult[] result = super.applyBatch(operations);
333 db.setTransactionSuccessful();
Sunny Goyald1064182015-08-13 12:08:30 -0700334 reloadLauncherIfExternal();
Yura085c8532014-02-11 15:15:29 +0000335 return result;
336 } finally {
337 db.endTransaction();
338 }
339 }
340
341 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800342 public int delete(Uri uri, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700343 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
345
346 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347
Louis Begina9c21c62016-08-15 15:18:41 -0700348 if (Binder.getCallingPid() != Process.myPid()
349 && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
350 String widgetSelection = TextUtils.isEmpty(args.where) ? "1=1" : args.where;
351 widgetSelection = String.format(Locale.ENGLISH, "%1$s = %2$d AND ( %3$s )",
352 Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET, widgetSelection);
353 try (Cursor c = db.query(Favorites.TABLE_NAME, new String[] { Favorites.APPWIDGET_ID },
354 widgetSelection, args.args, null, null, null)) {
355 AppWidgetHost host = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID);
356 while (c.moveToNext()) {
357 int widgetId = c.getInt(0);
358 if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
359 try {
360 host.deleteAppWidgetId(widgetId);
361 } catch (RuntimeException e) {
362 Log.e(TAG, "Error deleting widget id " + widgetId, e);
363 }
364 }
365 }
366 }
367 }
368 int count = db.delete(args.table, args.where, args.args);
369 if (count > 0) {
370 notifyListeners();
371 reloadLauncherIfExternal();
372 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373 return count;
374 }
375
376 @Override
377 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700378 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
380
Chris Wren1ada10d2013-09-13 18:01:38 -0400381 addModifiedTime(values);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
383 int count = db.update(args.table, values, args.where, args.args);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700384 if (count > 0) notifyListeners();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385
Sunny Goyald1064182015-08-13 12:08:30 -0700386 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800387 return count;
388 }
389
Sunny Goyal7779d622015-06-11 16:18:39 -0700390 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700391 public Bundle call(String method, final String arg, final Bundle extras) {
Sunny Goyal7779d622015-06-11 16:18:39 -0700392 if (Binder.getCallingUid() != Process.myUid()) {
393 return null;
394 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700395 createDbIfNotExists();
Sunny Goyal7779d622015-06-11 16:18:39 -0700396
397 switch (method) {
Tony Wickham827cef22016-03-17 15:39:39 -0700398 case LauncherSettings.Settings.METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID: {
399 String extractedColors = extras.getString(
400 LauncherSettings.Settings.EXTRA_EXTRACTED_COLORS);
401 int wallpaperId = extras.getInt(LauncherSettings.Settings.EXTRA_WALLPAPER_ID);
402 Utilities.getPrefs(getContext()).edit()
403 .putString(ExtractionUtils.EXTRACTED_COLORS_PREFERENCE_KEY, extractedColors)
404 .putInt(ExtractionUtils.WALLPAPER_ID_PREFERENCE_KEY, wallpaperId)
405 .apply();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700406 mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_EXTRACTED_COLORS_CHANGED);
Tony Wickham827cef22016-03-17 15:39:39 -0700407 Bundle result = new Bundle();
408 result.putString(LauncherSettings.Settings.EXTRA_VALUE, extractedColors);
409 return result;
410 }
Sunny Goyald2497482015-09-22 18:24:19 -0700411 case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
412 clearFlagEmptyDbCreated();
413 return null;
414 }
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700415 case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : {
416 Bundle result = new Bundle();
417 result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
418 Utilities.getPrefs(getContext()).getBoolean(EMPTY_DATABASE_CREATED, false));
419 return result;
420 }
Sunny Goyald2497482015-09-22 18:24:19 -0700421 case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
422 Bundle result = new Bundle();
423 result.putSerializable(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders());
424 return result;
425 }
426 case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
427 Bundle result = new Bundle();
428 result.putLong(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId());
429 return result;
430 }
431 case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
432 Bundle result = new Bundle();
433 result.putLong(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId());
434 return result;
435 }
436 case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
Sunny Goyale05b08f2017-02-23 18:30:22 -0800437 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyald2497482015-09-22 18:24:19 -0700438 return null;
439 }
440 case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
441 loadDefaultFavoritesIfNecessary();
442 return null;
443 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700444 }
445 return null;
446 }
447
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700448 /**
449 * Deletes any empty folder from the DB.
450 * @return Ids of deleted folders.
451 */
Sunny Goyald2497482015-09-22 18:24:19 -0700452 private ArrayList<Long> deleteEmptyFolders() {
453 ArrayList<Long> folderIds = new ArrayList<>();
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700454 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
455 db.beginTransaction();
456 try {
457 // Select folders whose id do not match any container value.
458 String selection = LauncherSettings.Favorites.ITEM_TYPE + " = "
459 + LauncherSettings.Favorites.ITEM_TYPE_FOLDER + " AND "
460 + LauncherSettings.Favorites._ID + " NOT IN (SELECT " +
461 LauncherSettings.Favorites.CONTAINER + " FROM "
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700462 + Favorites.TABLE_NAME + ")";
463 Cursor c = db.query(Favorites.TABLE_NAME,
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700464 new String[] {LauncherSettings.Favorites._ID},
465 selection, null, null, null, null);
466 while (c.moveToNext()) {
467 folderIds.add(c.getLong(0));
468 }
469 c.close();
Sunny Goyald2497482015-09-22 18:24:19 -0700470 if (!folderIds.isEmpty()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700471 db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery(
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700472 LauncherSettings.Favorites._ID, folderIds), null);
473 }
474 db.setTransactionSuccessful();
475 } catch (SQLException ex) {
476 Log.e(TAG, ex.getMessage(), ex);
477 folderIds.clear();
478 } finally {
479 db.endTransaction();
480 }
481 return folderIds;
482 }
483
Sunny Goyalf076eae2016-01-11 12:25:10 -0800484 /**
485 * Overridden in tests
486 */
487 protected void notifyListeners() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700488 mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_LAUNCHER_PROVIDER_CHANGED);
Chris Wren1ada10d2013-09-13 18:01:38 -0400489 }
490
Adam Cohen091440a2015-03-18 14:16:05 -0700491 @Thunk static void addModifiedTime(ContentValues values) {
Chris Wren1ada10d2013-09-13 18:01:38 -0400492 values.put(LauncherSettings.ChangeLogColumns.MODIFIED, System.currentTimeMillis());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800493 }
494
Sunny Goyald2497482015-09-22 18:24:19 -0700495 private void clearFlagEmptyDbCreated() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700496 Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
Sunny Goyal33d44382014-10-16 09:24:19 -0700497 }
498
Sunny Goyal42de82f2014-09-26 22:09:29 -0700499 /**
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700500 * Loads the default workspace based on the following priority scheme:
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700501 * 1) From the app restrictions
502 * 2) From a package provided by play store
503 * 3) From a partner configuration APK, already in the system image
504 * 4) The default configuration for the particular device
Brian Muramatsu5524b492012-10-02 16:55:54 -0700505 */
Sunny Goyald2497482015-09-22 18:24:19 -0700506 synchronized private void loadDefaultFavoritesIfNecessary() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700507 SharedPreferences sp = Utilities.getPrefs(getContext());
Adam Cohene25af792013-06-06 23:08:25 -0700508
Winson Chungc763c4e2013-07-19 13:49:06 -0700509 if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Chris Wren5dee7af2013-12-20 17:22:11 -0500510 Log.d(TAG, "loading default workspace");
Michael Jurka45355c42012-10-08 13:21:35 +0200511
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700512 AppWidgetHost widgetHost = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID);
513 AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction(widgetHost);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700514 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700515 loader = AutoInstallsLayout.get(getContext(),widgetHost, mOpenHelper);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700516 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700517 if (loader == null) {
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700518 final Partner partner = Partner.get(getContext().getPackageManager());
519 if (partner != null && partner.hasDefaultLayout()) {
520 final Resources partnerRes = partner.getResources();
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700521 int workspaceResId = partnerRes.getIdentifier(Partner.RES_DEFAULT_LAYOUT,
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700522 "xml", partner.getPackageName());
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700523 if (workspaceResId != 0) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700524 loader = new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal3a5a9d12014-10-01 15:33:41 -0700525 mOpenHelper, partnerRes, workspaceResId);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700526 }
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700527 }
528 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700529
Sunny Goyal9d219682014-10-23 14:21:02 -0700530 final boolean usingExternallyProvidedLayout = loader != null;
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700531 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700532 loader = getDefaultLayoutParser(widgetHost);
Brian Muramatsu5524b492012-10-02 16:55:54 -0700533 }
Sunny Goyalc6c8fef2015-03-04 09:51:18 -0800534
535 // There might be some partially restored DB items, due to buggy restore logic in
536 // previous versions of launcher.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800537 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Michael Jurkab85f8a42012-04-25 15:48:32 -0700538 // Populate favorites table with initial favorites
Sunny Goyal9d219682014-10-23 14:21:02 -0700539 if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0)
540 && usingExternallyProvidedLayout) {
541 // Unable to load external layout. Cleanup and load the internal layout.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800542 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyal9d219682014-10-23 14:21:02 -0700543 mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(),
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700544 getDefaultLayoutParser(widgetHost));
Sunny Goyal9d219682014-10-23 14:21:02 -0700545 }
Sunny Goyal33d44382014-10-16 09:24:19 -0700546 clearFlagEmptyDbCreated();
Michael Jurkab85f8a42012-04-25 15:48:32 -0700547 }
548 }
549
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700550 /**
551 * Creates workspace loader from an XML resource listed in the app restrictions.
552 *
553 * @return the loader if the restrictions are set and the resource exists; null otherwise.
554 */
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700555 private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700556 Context ctx = getContext();
557 UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
558 Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
Sunny Goyal35ca8732015-04-06 10:45:31 -0700559 if (bundle == null) {
560 return null;
561 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700562
Sunny Goyal35ca8732015-04-06 10:45:31 -0700563 String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700564 if (packageName != null) {
565 try {
566 Resources targetResources = ctx.getPackageManager()
567 .getResourcesForApplication(packageName);
568 return AutoInstallsLayout.get(ctx, packageName, targetResources,
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700569 widgetHost, mOpenHelper);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700570 } catch (NameNotFoundException e) {
571 Log.e(TAG, "Target package for restricted profile not found", e);
572 return null;
573 }
574 }
575 return null;
576 }
577
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700578 private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) {
Sunny Goyal87f784c2017-01-11 10:48:34 -0800579 int defaultLayout = LauncherAppState.getIDP(getContext()).defaultLayoutId;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700580 return new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal9d219682014-10-23 14:21:02 -0700581 mOpenHelper, getContext().getResources(), defaultLayout);
582 }
583
Sunny Goyald3849d12015-10-29 10:28:32 -0700584 /**
Sunny Goyalf076eae2016-01-11 12:25:10 -0800585 * The class is subclassed in tests to create an in-memory db.
586 */
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700587 public static class DatabaseHelper extends SQLiteOpenHelper implements LayoutParserCallback {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700588 private final Handler mWidgetHostResetHandler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589 private final Context mContext;
Adam Cohendcd297f2013-06-18 13:13:40 -0700590 private long mMaxItemId = -1;
591 private long mMaxScreenId = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700593 DatabaseHelper(Context context, Handler widgetHostResetHandler) {
594 this(context, widgetHostResetHandler, LauncherFiles.LAUNCHER_DB);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700595 // Table creation sometimes fails silently, which leads to a crash loop.
596 // This way, we will try to create a table every time after crash, so the device
597 // would eventually be able to recover.
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700598 if (!tableExists(Favorites.TABLE_NAME) || !tableExists(WorkspaceScreens.TABLE_NAME)) {
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700599 Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
600 // This operation is a no-op if the table already exists.
601 addFavoritesTable(getWritableDatabase(), true);
602 addWorkspacesTable(getWritableDatabase(), true);
603 }
604
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700605 initIds();
606 }
607
608 /**
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700609 * Constructor used in tests and for restore.
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700610 */
611 public DatabaseHelper(
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700612 Context context, Handler widgetHostResetHandler, String tableName) {
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700613 super(new NoLocaleSqliteContext(context), tableName, null, SCHEMA_VERSION);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700614 mContext = context;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700615 mWidgetHostResetHandler = widgetHostResetHandler;
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700616 }
617
618 protected void initIds() {
Winson Chung3d503fb2011-07-13 17:25:49 -0700619 // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
620 // the DB here
Adam Cohendcd297f2013-06-18 13:13:40 -0700621 if (mMaxItemId == -1) {
622 mMaxItemId = initializeMaxItemId(getWritableDatabase());
623 }
624 if (mMaxScreenId == -1) {
625 mMaxScreenId = initializeMaxScreenId(getWritableDatabase());
Winson Chung3d503fb2011-07-13 17:25:49 -0700626 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800627 }
628
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700629 private boolean tableExists(String tableName) {
630 Cursor c = getReadableDatabase().query(
631 true, "sqlite_master", new String[] {"tbl_name"},
632 "tbl_name = ?", new String[] {tableName},
633 null, null, null, null, null);
634 try {
635 return c.getCount() > 0;
636 } finally {
637 c.close();
638 }
639 }
640
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800641 @Override
642 public void onCreate(SQLiteDatabase db) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800643 if (LOGD) Log.d(TAG, "creating new launcher database");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700644
Adam Cohendcd297f2013-06-18 13:13:40 -0700645 mMaxItemId = 1;
646 mMaxScreenId = 0;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700647
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700648 addFavoritesTable(db, false);
649 addWorkspacesTable(db, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800650
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800651 // Fresh and clean launcher DB.
652 mMaxItemId = initializeMaxItemId(db);
Sunny Goyalf076eae2016-01-11 12:25:10 -0800653 onEmptyDbCreated();
654 }
655
656 /**
657 * Overriden in tests.
658 */
659 protected void onEmptyDbCreated() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700660 // Database was just created, so wipe any previous widgets
661 if (mWidgetHostResetHandler != null) {
662 new AppWidgetHost(mContext, Launcher.APPWIDGET_HOST_ID).deleteHost();
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700663 mWidgetHostResetHandler.sendEmptyMessage(
Sunny Goyal72db9af2016-11-29 07:25:49 +0530664 ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700665 }
666
Sunny Goyalf076eae2016-01-11 12:25:10 -0800667 // Set the flag for empty DB
668 Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
Sunny Goyale2fba6c2015-05-12 10:39:59 -0700669
670 // When a new DB is created, remove all previously stored managed profile information.
Sunny Goyal7c74e4a2016-12-15 15:53:17 -0800671 ManagedProfileHeuristic.processAllUsers(Collections.<UserHandle>emptyList(),
Sunny Goyalf076eae2016-01-11 12:25:10 -0800672 mContext);
673 }
674
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700675 public long getDefaultUserSerial() {
Sunny Goyalf076eae2016-01-11 12:25:10 -0800676 return UserManagerCompat.getInstance(mContext).getSerialNumberForUser(
Sunny Goyal7c74e4a2016-12-15 15:53:17 -0800677 Process.myUserHandle());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 }
679
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700680 private void addFavoritesTable(SQLiteDatabase db, boolean optional) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700681 Favorites.addTableToDb(db, getDefaultUserSerial(), optional);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700682 }
683
684 private void addWorkspacesTable(SQLiteDatabase db, boolean optional) {
685 String ifNotExists = optional ? " IF NOT EXISTS " : "";
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700686 db.execSQL("CREATE TABLE " + ifNotExists + WorkspaceScreens.TABLE_NAME + " (" +
Sunny Goyald2f38192015-02-25 10:46:34 -0800687 LauncherSettings.WorkspaceScreens._ID + " INTEGER PRIMARY KEY," +
Chris Wren1ada10d2013-09-13 18:01:38 -0400688 LauncherSettings.WorkspaceScreens.SCREEN_RANK + " INTEGER," +
689 LauncherSettings.ChangeLogColumns.MODIFIED + " INTEGER NOT NULL DEFAULT 0" +
Adam Cohendcd297f2013-06-18 13:13:40 -0700690 ");");
691 }
692
Adam Cohen119285e2014-04-02 16:59:08 -0700693 private void removeOrphanedItems(SQLiteDatabase db) {
Adam Cohenf9c14de2014-04-17 18:20:45 -0700694 // Delete items directly on the workspace who's screen id doesn't exist
695 // "DELETE FROM favorites WHERE screen NOT IN (SELECT _id FROM workspaceScreens)
696 // AND container = -100"
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700697 String removeOrphanedDesktopItems = "DELETE FROM " + Favorites.TABLE_NAME +
Adam Cohenf9c14de2014-04-17 18:20:45 -0700698 " WHERE " +
Adam Cohen119285e2014-04-02 16:59:08 -0700699 LauncherSettings.Favorites.SCREEN + " NOT IN (SELECT " +
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700700 LauncherSettings.WorkspaceScreens._ID + " FROM " + WorkspaceScreens.TABLE_NAME + ")" +
Adam Cohenf9c14de2014-04-17 18:20:45 -0700701 " AND " +
702 LauncherSettings.Favorites.CONTAINER + " = " +
703 LauncherSettings.Favorites.CONTAINER_DESKTOP;
704 db.execSQL(removeOrphanedDesktopItems);
705
706 // Delete items contained in folders which no longer exist (after above statement)
707 // "DELETE FROM favorites WHERE container <> -100 AND container <> -101 AND container
708 // NOT IN (SELECT _id FROM favorites WHERE itemType = 2)"
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700709 String removeOrphanedFolderItems = "DELETE FROM " + Favorites.TABLE_NAME +
Adam Cohenf9c14de2014-04-17 18:20:45 -0700710 " WHERE " +
711 LauncherSettings.Favorites.CONTAINER + " <> " +
712 LauncherSettings.Favorites.CONTAINER_DESKTOP +
713 " AND "
714 + LauncherSettings.Favorites.CONTAINER + " <> " +
715 LauncherSettings.Favorites.CONTAINER_HOTSEAT +
716 " AND "
717 + LauncherSettings.Favorites.CONTAINER + " NOT IN (SELECT " +
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700718 LauncherSettings.Favorites._ID + " FROM " + Favorites.TABLE_NAME +
Adam Cohenf9c14de2014-04-17 18:20:45 -0700719 " WHERE " + LauncherSettings.Favorites.ITEM_TYPE + " = " +
720 LauncherSettings.Favorites.ITEM_TYPE_FOLDER + ")";
721 db.execSQL(removeOrphanedFolderItems);
Adam Cohen119285e2014-04-02 16:59:08 -0700722 }
723
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800724 @Override
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700725 public void onOpen(SQLiteDatabase db) {
726 super.onOpen(db);
727 SharedPreferences prefs = mContext
728 .getSharedPreferences(LauncherFiles.DEVICE_PREFERENCES_KEY, 0);
729 int oldVersion = prefs.getInt(PREF_KEY_DATA_VERISON, 0);
730 if (oldVersion != DATA_VERSION) {
731 // Only run the data upgrade path for an existing db.
732 if (!Utilities.getPrefs(mContext).getBoolean(EMPTY_DATABASE_CREATED, false)) {
733 db.beginTransaction();
734 try {
735 onDataUpgrade(db, oldVersion);
736 db.setTransactionSuccessful();
737 } catch (Exception e) {
738 Log.d(TAG, "Error updating data version, ignoring", e);
739 return;
740 } finally {
741 db.endTransaction();
742 }
743 }
744 prefs.edit().putInt(PREF_KEY_DATA_VERISON, DATA_VERSION).apply();
745 }
746 }
747
748 /**
749 * Called when the data is updated as part of app update. It can be called multiple times
750 * with old version, even though it had been run before. The changes made here must be
751 * backwards compatible, else we risk breaking old devices during restore or binary
752 * version downgrade.
753 */
754 protected void onDataUpgrade(SQLiteDatabase db, int oldVersion) {
755 switch (oldVersion) {
756 case 0:
757 case 1: {
758 // Remove "profile extra"
759 UserManagerCompat um = UserManagerCompat.getInstance(mContext);
760 for (UserHandle user : um.getUserProfiles()) {
761 long serial = um.getSerialNumberForUser(user);
762 String sql = "update favorites set intent = replace(intent, "
763 + "';l.profile=" + serial + ";', ';') where itemType = 0;";
764 db.execSQL(sql);
765 }
766 }
767 case 2:
768 // data updated
769 return;
770 }
771 }
772
773 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800774 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Winson Chungc763c4e2013-07-19 13:49:06 -0700775 if (LOGD) Log.d(TAG, "onUpgrade triggered: " + oldVersion);
Sunny Goyala2cc6242015-01-14 14:23:02 -0800776 switch (oldVersion) {
777 // The version cannot be lower that 12, as Launcher3 never supported a lower
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800778 // version of the DB.
Sunny Goyala2cc6242015-01-14 14:23:02 -0800779 case 12: {
780 // With the new shrink-wrapped and re-orderable workspaces, it makes sense
781 // to persist workspace screens and their relative order.
782 mMaxScreenId = 0;
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700783 addWorkspacesTable(db, false);
Sunny Goyala2cc6242015-01-14 14:23:02 -0800784 }
785 case 13: {
786 db.beginTransaction();
787 try {
788 // Insert new column for holding widget provider name
789 db.execSQL("ALTER TABLE favorites " +
790 "ADD COLUMN appWidgetProvider TEXT;");
791 db.setTransactionSuccessful();
792 } catch (SQLException ex) {
793 Log.e(TAG, ex.getMessage(), ex);
794 // Old version remains, which means we wipe old data
795 break;
796 } finally {
797 db.endTransaction();
798 }
799 }
800 case 14: {
801 db.beginTransaction();
802 try {
803 // Insert new column for holding update timestamp
804 db.execSQL("ALTER TABLE favorites " +
805 "ADD COLUMN modified INTEGER NOT NULL DEFAULT 0;");
806 db.execSQL("ALTER TABLE workspaceScreens " +
807 "ADD COLUMN modified INTEGER NOT NULL DEFAULT 0;");
808 db.setTransactionSuccessful();
809 } catch (SQLException ex) {
810 Log.e(TAG, ex.getMessage(), ex);
811 // Old version remains, which means we wipe old data
812 break;
813 } finally {
814 db.endTransaction();
815 }
816 }
817 case 15: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700818 if (!addIntegerColumn(db, Favorites.RESTORED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800819 // Old version remains, which means we wipe old data
820 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800821 }
822 }
823 case 16: {
Sunny Goyal10629b02016-09-01 12:50:11 -0700824 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800825 }
826 case 17: {
827 // No-op
828 }
829 case 18: {
830 // Due to a data loss bug, some users may have items associated with screen ids
831 // which no longer exist. Since this can cause other problems, and since the user
832 // will never see these items anyway, we use database upgrade as an opportunity to
833 // clean things up.
834 removeOrphanedItems(db);
835 }
836 case 19: {
837 // Add userId column
838 if (!addProfileColumn(db)) {
839 // Old version remains, which means we wipe old data
840 break;
841 }
842 }
843 case 20:
844 if (!updateFolderItemsRank(db, true)) {
845 break;
846 }
Sunny Goyald2f38192015-02-25 10:46:34 -0800847 case 21:
848 // Recreate workspace table with screen id a primary key
849 if (!recreateWorkspaceTable(db)) {
850 break;
851 }
852 case 22: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700853 if (!addIntegerColumn(db, Favorites.OPTIONS, 0)) {
854 // Old version remains, which means we wipe old data
855 break;
856 }
857 }
Sunny Goyal0b037782015-04-02 10:27:03 -0700858 case 23:
Sunny Goyal5c97f512015-05-19 16:03:28 -0700859 // No-op
Sunny Goyale2fba6c2015-05-12 10:39:59 -0700860 case 24:
861 ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mContext);
Sunny Goyal5c97f512015-05-19 16:03:28 -0700862 case 25:
863 convertShortcutsToLauncherActivities(db);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700864 case 26:
865 // QSB was moved to the grid. Clear the first row on screen 0.
866 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyal8ad02b82016-12-29 13:31:43 -0800867 !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700868 break;
869 }
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700870 case 27:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800871 // DB Upgraded successfully
872 return;
Chris Wrend5e66bf2013-09-16 14:02:29 -0400873 }
874
Sunny Goyala2cc6242015-01-14 14:23:02 -0800875 // DB was not upgraded
876 Log.w(TAG, "Destroying all old data.");
877 createEmptyDB(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800878 }
Romain Guy7eb9e5e2009-12-02 20:10:07 -0800879
Adam Cohen9b1d0622014-05-21 19:01:57 -0700880 @Override
881 public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700882 if (oldVersion == 28 && newVersion == 27) {
883 // TODO: remove this check. This is only applicable for internal development/testing
884 // and for any released version of Launcher.
885 return;
886 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700887 // This shouldn't happen -- throw our hands up in the air and start over.
888 Log.w(TAG, "Database version downgrade from: " + oldVersion + " to " + newVersion +
889 ". Wiping databse.");
Sunny Goyal42de82f2014-09-26 22:09:29 -0700890 createEmptyDB(db);
891 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700892
Sunny Goyal42de82f2014-09-26 22:09:29 -0700893 /**
894 * Clears all the data for a fresh start.
895 */
896 public void createEmptyDB(SQLiteDatabase db) {
Sunny Goyale05b08f2017-02-23 18:30:22 -0800897 db.beginTransaction();
898 try {
899 db.execSQL("DROP TABLE IF EXISTS " + Favorites.TABLE_NAME);
900 db.execSQL("DROP TABLE IF EXISTS " + WorkspaceScreens.TABLE_NAME);
901 onCreate(db);
902 db.setTransactionSuccessful();
903 } finally {
904 db.endTransaction();
905 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700906 }
907
Sunny Goyald2f38192015-02-25 10:46:34 -0800908 /**
Sunny Goyal0b037782015-04-02 10:27:03 -0700909 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
910 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
911 */
Sunny Goyal316490e2015-06-02 09:38:28 -0700912 @Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700913 db.beginTransaction();
914 Cursor c = null;
915 SQLiteStatement updateStmt = null;
916
917 try {
918 // Only consider the primary user as other users can't have a shortcut.
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700919 long userSerial = getDefaultUserSerial();
920 c = db.query(Favorites.TABLE_NAME, new String[] {
Sunny Goyal0b037782015-04-02 10:27:03 -0700921 Favorites._ID,
922 Favorites.INTENT,
923 }, "itemType=" + Favorites.ITEM_TYPE_SHORTCUT + " AND profileId=" + userSerial,
924 null, null, null, null);
925
926 updateStmt = db.compileStatement("UPDATE favorites SET itemType="
927 + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?");
928
929 final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
930 final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);
931
932 while (c.moveToNext()) {
933 String intentDescription = c.getString(intentIndex);
934 Intent intent;
935 try {
936 intent = Intent.parseUri(intentDescription, 0);
937 } catch (URISyntaxException e) {
938 Log.e(TAG, "Unable to parse intent", e);
939 continue;
940 }
941
Sunny Goyal4e5cc642015-06-25 16:37:44 -0700942 if (!Utilities.isLauncherAppTarget(intent)) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700943 continue;
944 }
945
946 long id = c.getLong(idIndex);
947 updateStmt.bindLong(1, id);
Sunny Goyalc22841b2015-07-13 19:59:50 -0700948 updateStmt.executeUpdateDelete();
Sunny Goyal0b037782015-04-02 10:27:03 -0700949 }
950 db.setTransactionSuccessful();
951 } catch (SQLException ex) {
952 Log.w(TAG, "Error deduping shortcuts", ex);
953 } finally {
954 db.endTransaction();
955 if (c != null) {
956 c.close();
957 }
958 if (updateStmt != null) {
959 updateStmt.close();
960 }
961 }
962 }
963
964 /**
Sunny Goyald2f38192015-02-25 10:46:34 -0800965 * Recreates workspace table and migrates data to the new table.
966 */
967 public boolean recreateWorkspaceTable(SQLiteDatabase db) {
968 db.beginTransaction();
969 try {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700970 Cursor c = db.query(WorkspaceScreens.TABLE_NAME,
Sunny Goyald2f38192015-02-25 10:46:34 -0800971 new String[] {LauncherSettings.WorkspaceScreens._ID},
972 null, null, null, null,
973 LauncherSettings.WorkspaceScreens.SCREEN_RANK);
974 ArrayList<Long> sortedIDs = new ArrayList<Long>();
975 long maxId = 0;
976 try {
977 while (c.moveToNext()) {
978 Long id = c.getLong(0);
979 if (!sortedIDs.contains(id)) {
980 sortedIDs.add(id);
981 maxId = Math.max(maxId, id);
982 }
983 }
984 } finally {
985 c.close();
986 }
987
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700988 db.execSQL("DROP TABLE IF EXISTS " + WorkspaceScreens.TABLE_NAME);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700989 addWorkspacesTable(db, false);
Sunny Goyald2f38192015-02-25 10:46:34 -0800990
991 // Add all screen ids back
992 int total = sortedIDs.size();
993 for (int i = 0; i < total; i++) {
994 ContentValues values = new ContentValues();
995 values.put(LauncherSettings.WorkspaceScreens._ID, sortedIDs.get(i));
996 values.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
997 addModifiedTime(values);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700998 db.insertOrThrow(WorkspaceScreens.TABLE_NAME, null, values);
Sunny Goyald2f38192015-02-25 10:46:34 -0800999 }
1000 db.setTransactionSuccessful();
1001 mMaxScreenId = maxId;
1002 } catch (SQLException ex) {
1003 // Old version remains, which means we wipe old data
1004 Log.e(TAG, ex.getMessage(), ex);
1005 return false;
1006 } finally {
1007 db.endTransaction();
1008 }
1009 return true;
1010 }
1011
Adam Cohen091440a2015-03-18 14:16:05 -07001012 @Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
Sunny Goyal08f72612015-01-05 13:41:43 -08001013 db.beginTransaction();
1014 try {
1015 if (addRankColumn) {
1016 // Insert new column for holding rank
1017 db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
1018 }
1019
1020 // Get a map for folder ID to folder width
1021 Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
1022 + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
1023 + " GROUP BY container;",
1024 new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
1025
1026 while (c.moveToNext()) {
Sunny Goyalc87775d2015-02-10 19:52:36 -08001027 db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
1028 + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
Sunny Goyal08f72612015-01-05 13:41:43 -08001029 new Object[] {c.getLong(1) + 1, c.getLong(0)});
1030 }
1031
1032 c.close();
1033 db.setTransactionSuccessful();
1034 } catch (SQLException ex) {
1035 // Old version remains, which means we wipe old data
1036 Log.e(TAG, ex.getMessage(), ex);
1037 return false;
1038 } finally {
1039 db.endTransaction();
1040 }
1041 return true;
1042 }
1043
Kenny Guyed131872014-04-30 03:02:21 +01001044 private boolean addProfileColumn(SQLiteDatabase db) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001045 return addIntegerColumn(db, Favorites.PROFILE_ID, getDefaultUserSerial());
Sunny Goyal5d85c442015-03-10 13:14:47 -07001046 }
1047
1048 private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
Kenny Guyed131872014-04-30 03:02:21 +01001049 db.beginTransaction();
1050 try {
Sunny Goyal5d85c442015-03-10 13:14:47 -07001051 db.execSQL("ALTER TABLE favorites ADD COLUMN "
1052 + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
Kenny Guyed131872014-04-30 03:02:21 +01001053 db.setTransactionSuccessful();
1054 } catch (SQLException ex) {
Kenny Guyed131872014-04-30 03:02:21 +01001055 Log.e(TAG, ex.getMessage(), ex);
1056 return false;
1057 } finally {
1058 db.endTransaction();
1059 }
1060 return true;
1061 }
1062
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001063 // Generates a new ID to use for an object in your database. This method should be only
1064 // called from the main UI thread. As an exception, we do call it when we call the
1065 // constructor from the worker thread; however, this doesn't extend until after the
1066 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
1067 // after that point
Sunny Goyal0fe505b2014-08-06 09:55:36 -07001068 @Override
Adam Cohendcd297f2013-06-18 13:13:40 -07001069 public long generateNewItemId() {
1070 if (mMaxItemId < 0) {
1071 throw new RuntimeException("Error: max item id was not initialized");
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001072 }
Adam Cohendcd297f2013-06-18 13:13:40 -07001073 mMaxItemId += 1;
1074 return mMaxItemId;
Michael Jurkaa8c760d2011-04-28 14:59:33 -07001075 }
1076
Sunny Goyal0fe505b2014-08-06 09:55:36 -07001077 @Override
1078 public long insertAndCheck(SQLiteDatabase db, ContentValues values) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001079 return dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, values);
Sunny Goyal0fe505b2014-08-06 09:55:36 -07001080 }
1081
Chris Wren5dee7af2013-12-20 17:22:11 -05001082 public void checkId(String table, ContentValues values) {
1083 long id = values.getAsLong(LauncherSettings.BaseLauncherColumns._ID);
Sunny Goyal8e0e1d72016-10-10 10:41:41 -07001084 if (WorkspaceScreens.TABLE_NAME.equals(table)) {
Chris Wren5dee7af2013-12-20 17:22:11 -05001085 mMaxScreenId = Math.max(id, mMaxScreenId);
1086 } else {
1087 mMaxItemId = Math.max(id, mMaxItemId);
1088 }
1089 }
1090
Adam Cohendcd297f2013-06-18 13:13:40 -07001091 private long initializeMaxItemId(SQLiteDatabase db) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001092 return getMaxId(db, Favorites.TABLE_NAME);
Adam Cohendcd297f2013-06-18 13:13:40 -07001093 }
1094
1095 // Generates a new ID to use for an workspace screen in your database. This method
1096 // should be only called from the main UI thread. As an exception, we do call it when we
1097 // call the constructor from the worker thread; however, this doesn't extend until after the
1098 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
1099 // after that point
1100 public long generateNewScreenId() {
1101 if (mMaxScreenId < 0) {
1102 throw new RuntimeException("Error: max screen id was not initialized");
1103 }
1104 mMaxScreenId += 1;
1105 return mMaxScreenId;
1106 }
1107
Adam Cohendcd297f2013-06-18 13:13:40 -07001108 private long initializeMaxScreenId(SQLiteDatabase db) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001109 return getMaxId(db, WorkspaceScreens.TABLE_NAME);
Adam Cohen7ec3bbf2014-07-31 00:09:45 -07001110 }
1111
Adam Cohen091440a2015-03-18 14:16:05 -07001112 @Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
Adam Cohen71483f42014-05-15 14:04:01 -07001113 ArrayList<Long> screenIds = new ArrayList<Long>();
Sunny Goyal0fe505b2014-08-06 09:55:36 -07001114 // TODO: Use multiple loaders with fall-back and transaction.
1115 int count = loader.loadLayout(db, screenIds);
Adam Cohen71483f42014-05-15 14:04:01 -07001116
1117 // Add the screens specified by the items above
1118 Collections.sort(screenIds);
1119 int rank = 0;
1120 ContentValues values = new ContentValues();
1121 for (Long id : screenIds) {
1122 values.clear();
1123 values.put(LauncherSettings.WorkspaceScreens._ID, id);
1124 values.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, rank);
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001125 if (dbInsertAndCheck(this, db, WorkspaceScreens.TABLE_NAME, null, values) < 0) {
Adam Cohen71483f42014-05-15 14:04:01 -07001126 throw new RuntimeException("Failed initialize screen table"
1127 + "from default layout");
1128 }
1129 rank++;
1130 }
1131
1132 // Ensure that the max ids are initialized
1133 mMaxItemId = initializeMaxItemId(db);
1134 mMaxScreenId = initializeMaxScreenId(db);
Adam Cohen7ec3bbf2014-07-31 00:09:45 -07001135
Adam Cohen71483f42014-05-15 14:04:01 -07001136 return count;
1137 }
Mike Cleronb87bd162009-10-30 16:36:56 -07001138 }
Daniel Lehmannc3a80402012-04-23 21:35:11 -07001139
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001140 /**
1141 * @return the max _id in the provided table.
1142 */
Adam Cohen091440a2015-03-18 14:16:05 -07001143 @Thunk static long getMaxId(SQLiteDatabase db, String table) {
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001144 Cursor c = db.rawQuery("SELECT MAX(_id) FROM " + table, null);
1145 // get the result
1146 long id = -1;
1147 if (c != null && c.moveToNext()) {
1148 id = c.getLong(0);
1149 }
1150 if (c != null) {
1151 c.close();
1152 }
1153
1154 if (id == -1) {
1155 throw new RuntimeException("Error: could not query max id in " + table);
1156 }
1157
1158 return id;
1159 }
1160
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 static class SqlArguments {
1162 public final String table;
1163 public final String where;
1164 public final String[] args;
1165
1166 SqlArguments(Uri url, String where, String[] args) {
1167 if (url.getPathSegments().size() == 1) {
1168 this.table = url.getPathSegments().get(0);
1169 this.where = where;
1170 this.args = args;
1171 } else if (url.getPathSegments().size() != 2) {
1172 throw new IllegalArgumentException("Invalid URI: " + url);
1173 } else if (!TextUtils.isEmpty(where)) {
1174 throw new UnsupportedOperationException("WHERE clause not supported: " + url);
1175 } else {
1176 this.table = url.getPathSegments().get(0);
Daniel Lehmannc3a80402012-04-23 21:35:11 -07001177 this.where = "_id=" + ContentUris.parseId(url);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178 this.args = null;
1179 }
1180 }
1181
1182 SqlArguments(Uri url) {
1183 if (url.getPathSegments().size() == 1) {
1184 table = url.getPathSegments().get(0);
1185 where = null;
1186 args = null;
1187 } else {
1188 throw new IllegalArgumentException("Invalid URI: " + url);
1189 }
1190 }
1191 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001192
1193 private static class ChangeListenerWrapper implements Handler.Callback {
1194
1195 private static final int MSG_LAUNCHER_PROVIDER_CHANGED = 1;
1196 private static final int MSG_EXTRACTED_COLORS_CHANGED = 2;
1197 private static final int MSG_APP_WIDGET_HOST_RESET = 3;
1198
1199 private LauncherProviderChangeListener mListener;
1200
1201 @Override
1202 public boolean handleMessage(Message msg) {
1203 if (mListener != null) {
1204 switch (msg.what) {
1205 case MSG_LAUNCHER_PROVIDER_CHANGED:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001206 mListener.onLauncherProviderChanged();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001207 break;
1208 case MSG_EXTRACTED_COLORS_CHANGED:
1209 mListener.onExtractedColorsChanged();
1210 break;
1211 case MSG_APP_WIDGET_HOST_RESET:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001212 mListener.onAppWidgetHostReset();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001213 break;
1214 }
1215 }
1216 return true;
1217 }
1218 }
Adam Cohen72960972014-01-15 18:13:55 -08001219}