blob: 6081300ced8cc1256f3dd4a93fae3a2260929eef [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 Goyal161a2142018-10-29 14:02:20 -070019import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
20import static com.android.launcher3.provider.LauncherDbUtils.tableExists;
21
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070022import android.annotation.TargetApi;
Jon Miranda2bc6b932019-03-07 15:24:46 -080023import android.app.backup.BackupManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -070024import android.appwidget.AppWidgetHost;
Mike Cleronb87bd162009-10-30 16:36:56 -070025import android.appwidget.AppWidgetManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026import android.content.ComponentName;
Adam Cohen228da5a2011-07-27 22:23:47 -070027import android.content.ContentProvider;
Yura085c8532014-02-11 15:15:29 +000028import android.content.ContentProviderOperation;
29import android.content.ContentProviderResult;
Adam Cohen228da5a2011-07-27 22:23:47 -070030import android.content.ContentUris;
31import android.content.ContentValues;
32import android.content.Context;
33import android.content.Intent;
Yura085c8532014-02-11 15:15:29 +000034import android.content.OperationApplicationException;
Michael Jurkab85f8a42012-04-25 15:48:32 -070035import android.content.SharedPreferences;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070036import android.content.pm.ProviderInfo;
Adam Cohen228da5a2011-07-27 22:23:47 -070037import android.content.res.Resources;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038import android.database.Cursor;
Sunny Goyalc5939392018-12-07 11:43:47 -080039import android.database.DatabaseUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.database.SQLException;
Adam Cohen228da5a2011-07-27 22:23:47 -070041import android.database.sqlite.SQLiteDatabase;
Adam Cohen228da5a2011-07-27 22:23:47 -070042import android.database.sqlite.SQLiteQueryBuilder;
Sunny Goyal0b037782015-04-02 10:27:03 -070043import android.database.sqlite.SQLiteStatement;
Adam Cohen228da5a2011-07-27 22:23:47 -070044import android.net.Uri;
Sunny Goyal7779d622015-06-11 16:18:39 -070045import android.os.Binder;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070046import android.os.Build;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070047import android.os.Bundle;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070048import android.os.Handler;
49import android.os.Message;
Sunny Goyal7779d622015-06-11 16:18:39 -070050import android.os.Process;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080051import android.os.UserHandle;
Sunny Goyalc5939392018-12-07 11:43:47 -080052import android.provider.BaseColumns;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070053import android.provider.Settings;
Adam Cohen228da5a2011-07-27 22:23:47 -070054import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.util.Log;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070056import android.util.Xml;
Adam Cohen228da5a2011-07-27 22:23:47 -070057
Sunny Goyal0fe505b2014-08-06 09:55:36 -070058import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
59import com.android.launcher3.LauncherSettings.Favorites;
Kenny Guyed131872014-04-30 03:02:21 +010060import com.android.launcher3.compat.UserManagerCompat;
Sunny Goyala9e2f5a2016-06-10 12:22:04 -070061import com.android.launcher3.config.FeatureFlags;
Sunny Goyalfdbef272017-02-01 12:52:54 -080062import com.android.launcher3.logging.FileLog;
Sunny Goyal05f30882017-05-03 12:42:18 -070063import com.android.launcher3.model.DbDowngradeHelper;
Sunny Goyala9e2f5a2016-06-10 12:22:04 -070064import com.android.launcher3.provider.LauncherDbUtils;
Sunny Goyaldbfc9012017-04-17 16:58:36 -070065import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
Sunny Goyale8f7d5a2016-05-24 11:30:14 -070066import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070067import com.android.launcher3.util.IOUtils;
Sunny Goyalefb7e842018-10-04 15:11:00 -070068import com.android.launcher3.util.IntArray;
69import com.android.launcher3.util.IntSet;
Sunny Goyal19026b22018-03-09 14:37:37 -080070import com.android.launcher3.util.NoLocaleSQLiteHelper;
Sunny Goyal9dbb27c2019-07-17 15:12:56 -070071import com.android.launcher3.util.PackageManagerHelper;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070072import com.android.launcher3.util.Preconditions;
Adam Cohen091440a2015-03-18 14:16:05 -070073import com.android.launcher3.util.Thunk;
Michael Jurka8b805b12012-04-18 14:23:14 -070074
Sunny Goyalc0f03d92019-03-22 14:13:36 -070075import org.xmlpull.v1.XmlPullParser;
76
Sunny Goyal05f30882017-05-03 12:42:18 -070077import java.io.File;
Hyunyoung Song6aa37292017-02-06 10:46:24 -080078import java.io.FileDescriptor;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070079import java.io.InputStream;
Hyunyoung Song6aa37292017-02-06 10:46:24 -080080import java.io.PrintWriter;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070081import java.io.StringReader;
Mike Cleronb87bd162009-10-30 16:36:56 -070082import java.net.URISyntaxException;
Adam Cohen228da5a2011-07-27 22:23:47 -070083import java.util.ArrayList;
Sunny Goyalefb7e842018-10-04 15:11:00 -070084import java.util.Arrays;
Sunny Goyalc5939392018-12-07 11:43:47 -080085import java.util.Locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080086
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087public class LauncherProvider extends ContentProvider {
Sunny Goyalc74e4192015-09-08 14:01:03 -070088 private static final String TAG = "LauncherProvider";
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080089 private static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090
Sunny Goyal05f30882017-05-03 12:42:18 -070091 private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json";
92
Sunny Goyal3c7d55b2017-04-13 12:01:47 -070093 /**
94 * Represents the schema of the database. Changes in scheme need not be backwards compatible.
Sunny Goyalc5939392018-12-07 11:43:47 -080095 * When increasing the scheme version, ensure that downgrade_schema.json is updated
Sunny Goyal3c7d55b2017-04-13 12:01:47 -070096 */
Sunny Goyalc5939392018-12-07 11:43:47 -080097 public static final int SCHEMA_VERSION = 28;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098
Sunny Goyal4276e7b2018-11-26 23:44:41 -080099 public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings";
Winson Chung3d503fb2011-07-13 17:25:49 -0700100
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800101 static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800102
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700103 private final ChangeListenerWrapper mListenerWrapper = new ChangeListenerWrapper();
104 private Handler mListenerHandler;
105
Sunny Goyalf076eae2016-01-11 12:25:10 -0800106 protected DatabaseHelper mOpenHelper;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107
Hyunyoung Song6aa37292017-02-06 10:46:24 -0800108 /**
109 * $ adb shell dumpsys activity provider com.android.launcher3
110 */
111 @Override
112 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
113 LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
114 if (appState == null || !appState.getModel().isModelLoaded()) {
115 return;
116 }
117 appState.getModel().dumpState("", fd, writer, args);
118 }
119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120 @Override
121 public boolean onCreate() {
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800122 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyale26d1002016-06-20 14:52:14 -0700123 Log.d(TAG, "Launcher process started");
124 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700125 mListenerHandler = new Handler(mListenerWrapper);
126
Sunny Goyalfdbef272017-02-01 12:52:54 -0800127 // The content provider exists for the entire duration of the launcher main process and
Sunny Goyal66f2b352018-02-09 10:57:12 -0800128 // is the first component to get created.
129 MainProcessInitializer.initialize(getContext().getApplicationContext());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 return true;
131 }
132
Sunny Goyald3849d12015-10-29 10:28:32 -0700133 /**
134 * Sets a provider listener.
135 */
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700136 public void setLauncherProviderChangeListener(LauncherProviderChangeListener listener) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700137 Preconditions.assertUIThread();
138 mListenerWrapper.mListener = listener;
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700139 }
140
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 @Override
142 public String getType(Uri uri) {
143 SqlArguments args = new SqlArguments(uri, null, null);
144 if (TextUtils.isEmpty(args.where)) {
145 return "vnd.android.cursor.dir/" + args.table;
146 } else {
147 return "vnd.android.cursor.item/" + args.table;
148 }
149 }
150
Sunny Goyalf076eae2016-01-11 12:25:10 -0800151 /**
152 * Overridden in tests
153 */
154 protected synchronized void createDbIfNotExists() {
Sunny Goyald3849d12015-10-29 10:28:32 -0700155 if (mOpenHelper == null) {
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())) {
Jon Mirandac7206ca2019-05-13 14:57:50 -0700159 if (!RestoreDbTask.performRestore(getContext(), mOpenHelper,
160 new BackupManager(getContext()))) {
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700161 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
162 }
163 // Set is pending to false irrespective of the result, so that it doesn't get
164 // executed again.
165 RestoreDbTask.setPending(getContext(), false);
166 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700167 }
168 }
169
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 @Override
171 public Cursor query(Uri uri, String[] projection, String selection,
172 String[] selectionArgs, String sortOrder) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700173 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
175 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
176 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
177 qb.setTables(args.table);
178
Romain Guy73b979d2009-06-09 12:57:21 -0700179 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder);
181 result.setNotificationUri(getContext().getContentResolver(), uri);
182
183 return result;
184 }
185
Sunny Goyalefb7e842018-10-04 15:11:00 -0700186 @Thunk static int dbInsertAndCheck(DatabaseHelper helper,
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700187 SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
Dan Sandlerd5024042014-01-09 15:01:33 -0500188 if (values == null) {
189 throw new RuntimeException("Error: attempting to insert null values");
190 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800191 if (!values.containsKey(LauncherSettings.Favorites._ID)) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700192 throw new RuntimeException("Error: attempting to add item without specifying an id");
193 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800194 helper.checkId(values);
Sunny Goyalefb7e842018-10-04 15:11:00 -0700195 return (int) db.insert(table, nullColumnHack, values);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700196 }
197
Sunny Goyald1064182015-08-13 12:08:30 -0700198 private void reloadLauncherIfExternal() {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800199 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyald1064182015-08-13 12:08:30 -0700200 LauncherAppState app = LauncherAppState.getInstanceNoCreate();
201 if (app != null) {
Sunny Goyaldd96a5e2017-02-17 11:22:34 -0800202 app.getModel().forceReload();
Sunny Goyald1064182015-08-13 12:08:30 -0700203 }
204 }
205 }
206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 @Override
208 public Uri insert(Uri uri, ContentValues initialValues) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700209 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210 SqlArguments args = new SqlArguments(uri);
211
Sunny Goyald1064182015-08-13 12:08:30 -0700212 // In very limited cases, we support system|signature permission apps to modify the db.
213 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700214 if (!initializeExternalAdd(initialValues)) {
Adam Cohena043fa82014-07-23 14:49:38 -0700215 return null;
216 }
217 }
218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Chris Wren1ada10d2013-09-13 18:01:38 -0400220 addModifiedTime(initialValues);
Sunny Goyalefb7e842018-10-04 15:11:00 -0700221 final int rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
Sunny Goyale72f3d52015-03-02 14:24:21 -0800222 if (rowId < 0) return null;
Sunny Goyal161a2142018-10-29 14:02:20 -0700223 mOpenHelper.onAddOrDeleteOp(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224
225 uri = ContentUris.withAppendedId(uri, rowId);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700226 notifyListeners();
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800227 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 return uri;
229 }
230
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700231 private boolean initializeExternalAdd(ContentValues values) {
232 // 1. Ensure that externally added items have a valid item id
Sunny Goyalefb7e842018-10-04 15:11:00 -0700233 int id = mOpenHelper.generateNewItemId();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700234 values.put(LauncherSettings.Favorites._ID, id);
235
236 // 2. In the case of an app widget, and if no app widget id is specified, we
237 // attempt allocate and bind the widget.
238 Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
239 if (itemType != null &&
240 itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET &&
241 !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {
242
243 final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
244 ComponentName cn = ComponentName.unflattenFromString(
245 values.getAsString(Favorites.APPWIDGET_PROVIDER));
246
247 if (cn != null) {
248 try {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700249 AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
250 int appWidgetId = widgetHost.allocateAppWidgetId();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700251 values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
252 if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700253 widgetHost.deleteAppWidgetId(appWidgetId);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700254 return false;
255 }
256 } catch (RuntimeException e) {
257 Log.e(TAG, "Failed to initialize external widget", e);
258 return false;
259 }
260 } else {
261 return false;
262 }
263 }
264
Sunny Goyalc5939392018-12-07 11:43:47 -0800265 return true;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700266 }
267
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 @Override
269 public int bulkInsert(Uri uri, ContentValues[] values) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700270 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 SqlArguments args = new SqlArguments(uri);
272
273 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700274 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 int numValues = values.length;
276 for (int i = 0; i < numValues; i++) {
Chris Wren1ada10d2013-09-13 18:01:38 -0400277 addModifiedTime(values[i]);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700278 if (dbInsertAndCheck(mOpenHelper, db, args.table, null, values[i]) < 0) {
279 return 0;
280 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700282 mOpenHelper.onAddOrDeleteOp(db);
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700283 t.commit();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284 }
285
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700286 notifyListeners();
Sunny Goyald1064182015-08-13 12:08:30 -0700287 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288 return values.length;
289 }
290
Sunny Goyal161a2142018-10-29 14:02:20 -0700291 @TargetApi(Build.VERSION_CODES.M)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 @Override
Yura085c8532014-02-11 15:15:29 +0000293 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
294 throws OperationApplicationException {
Sunny Goyald3849d12015-10-29 10:28:32 -0700295 createDbIfNotExists();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700296 try (SQLiteTransaction t = new SQLiteTransaction(mOpenHelper.getWritableDatabase())) {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800297 boolean isAddOrDelete = false;
Sunny Goyal161a2142018-10-29 14:02:20 -0700298
299 final int numOperations = operations.size();
300 final ContentProviderResult[] results = new ContentProviderResult[numOperations];
301 for (int i = 0; i < numOperations; i++) {
302 ContentProviderOperation op = operations.get(i);
303 results[i] = op.apply(this, results, i);
304
305 isAddOrDelete |= (op.isInsert() || op.isDelete()) &&
306 results[i].count != null && results[i].count > 0;
307 }
308 if (isAddOrDelete) {
309 mOpenHelper.onAddOrDeleteOp(t.getDb());
310 }
311
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700312 t.commit();
Sunny Goyald1064182015-08-13 12:08:30 -0700313 reloadLauncherIfExternal();
Sunny Goyal161a2142018-10-29 14:02:20 -0700314 return results;
Yura085c8532014-02-11 15:15:29 +0000315 }
316 }
317
318 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800319 public int delete(Uri uri, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700320 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
322
323 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800324
Louis Begina9c21c62016-08-15 15:18:41 -0700325 if (Binder.getCallingPid() != Process.myPid()
326 && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700327 mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
Louis Begina9c21c62016-08-15 15:18:41 -0700328 }
329 int count = db.delete(args.table, args.where, args.args);
330 if (count > 0) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700331 mOpenHelper.onAddOrDeleteOp(db);
Louis Begina9c21c62016-08-15 15:18:41 -0700332 notifyListeners();
333 reloadLauncherIfExternal();
334 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800335 return count;
336 }
337
338 @Override
339 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700340 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
342
Chris Wren1ada10d2013-09-13 18:01:38 -0400343 addModifiedTime(values);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
345 int count = db.update(args.table, values, args.where, args.args);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700346 if (count > 0) notifyListeners();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347
Sunny Goyald1064182015-08-13 12:08:30 -0700348 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800349 return count;
350 }
351
Sunny Goyal7779d622015-06-11 16:18:39 -0700352 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700353 public Bundle call(String method, final String arg, final Bundle extras) {
Sunny Goyal7779d622015-06-11 16:18:39 -0700354 if (Binder.getCallingUid() != Process.myUid()) {
355 return null;
356 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700357 createDbIfNotExists();
Sunny Goyal7779d622015-06-11 16:18:39 -0700358
359 switch (method) {
Sunny Goyald2497482015-09-22 18:24:19 -0700360 case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
361 clearFlagEmptyDbCreated();
362 return null;
363 }
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700364 case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : {
365 Bundle result = new Bundle();
366 result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
367 Utilities.getPrefs(getContext()).getBoolean(EMPTY_DATABASE_CREATED, false));
368 return result;
369 }
Sunny Goyald2497482015-09-22 18:24:19 -0700370 case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
371 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700372 result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders()
373 .toArray());
Sunny Goyald2497482015-09-22 18:24:19 -0700374 return result;
375 }
376 case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
377 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700378 result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId());
Sunny Goyald2497482015-09-22 18:24:19 -0700379 return result;
380 }
381 case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
382 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700383 result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId());
Sunny Goyald2497482015-09-22 18:24:19 -0700384 return result;
385 }
386 case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
Sunny Goyale05b08f2017-02-23 18:30:22 -0800387 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyald2497482015-09-22 18:24:19 -0700388 return null;
389 }
390 case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
391 loadDefaultFavoritesIfNecessary();
392 return null;
393 }
Sunny Goyal55fddc82017-04-06 15:02:52 -0700394 case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: {
395 mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
396 return null;
397 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700398 case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: {
399 Bundle result = new Bundle();
400 result.putBinder(LauncherSettings.Settings.EXTRA_VALUE,
401 new SQLiteTransaction(mOpenHelper.getWritableDatabase()));
402 return result;
403 }
404 case LauncherSettings.Settings.METHOD_REFRESH_BACKUP_TABLE: {
405 mOpenHelper.mBackupTableExists =
406 tableExists(mOpenHelper.getReadableDatabase(), Favorites.BACKUP_TABLE_NAME);
407 return null;
408 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700409 }
410 return null;
411 }
412
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700413 /**
414 * Deletes any empty folder from the DB.
415 * @return Ids of deleted folders.
416 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700417 private IntArray deleteEmptyFolders() {
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700418 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700419 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700420 // Select folders whose id do not match any container value.
421 String selection = LauncherSettings.Favorites.ITEM_TYPE + " = "
422 + LauncherSettings.Favorites.ITEM_TYPE_FOLDER + " AND "
423 + LauncherSettings.Favorites._ID + " NOT IN (SELECT " +
424 LauncherSettings.Favorites.CONTAINER + " FROM "
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700425 + Favorites.TABLE_NAME + ")";
Sunny Goyalc5939392018-12-07 11:43:47 -0800426
427 IntArray folderIds = LauncherDbUtils.queryIntArray(db, Favorites.TABLE_NAME,
428 Favorites._ID, selection, null, null);
Sunny Goyald2497482015-09-22 18:24:19 -0700429 if (!folderIds.isEmpty()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700430 db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery(
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700431 LauncherSettings.Favorites._ID, folderIds), null);
432 }
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700433 t.commit();
Sunny Goyalc5939392018-12-07 11:43:47 -0800434 return folderIds;
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700435 } catch (SQLException ex) {
436 Log.e(TAG, ex.getMessage(), ex);
Sunny Goyalc5939392018-12-07 11:43:47 -0800437 return new IntArray();
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700438 }
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700439 }
440
Sunny Goyalf076eae2016-01-11 12:25:10 -0800441 /**
442 * Overridden in tests
443 */
444 protected void notifyListeners() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700445 mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_LAUNCHER_PROVIDER_CHANGED);
Chris Wren1ada10d2013-09-13 18:01:38 -0400446 }
447
Adam Cohen091440a2015-03-18 14:16:05 -0700448 @Thunk static void addModifiedTime(ContentValues values) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800449 values.put(LauncherSettings.Favorites.MODIFIED, System.currentTimeMillis());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 }
451
Sunny Goyald2497482015-09-22 18:24:19 -0700452 private void clearFlagEmptyDbCreated() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700453 Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
Sunny Goyal33d44382014-10-16 09:24:19 -0700454 }
455
Sunny Goyal42de82f2014-09-26 22:09:29 -0700456 /**
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700457 * Loads the default workspace based on the following priority scheme:
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700458 * 1) From the app restrictions
459 * 2) From a package provided by play store
460 * 3) From a partner configuration APK, already in the system image
461 * 4) The default configuration for the particular device
Brian Muramatsu5524b492012-10-02 16:55:54 -0700462 */
Sunny Goyald2497482015-09-22 18:24:19 -0700463 synchronized private void loadDefaultFavoritesIfNecessary() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700464 SharedPreferences sp = Utilities.getPrefs(getContext());
Adam Cohene25af792013-06-06 23:08:25 -0700465
Winson Chungc763c4e2013-07-19 13:49:06 -0700466 if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Chris Wren5dee7af2013-12-20 17:22:11 -0500467 Log.d(TAG, "loading default workspace");
Michael Jurka45355c42012-10-08 13:21:35 +0200468
Sunny Goyal55fddc82017-04-06 15:02:52 -0700469 AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700470 AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction(widgetHost);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700471 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700472 loader = AutoInstallsLayout.get(getContext(),widgetHost, mOpenHelper);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700473 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700474 if (loader == null) {
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700475 final Partner partner = Partner.get(getContext().getPackageManager());
476 if (partner != null && partner.hasDefaultLayout()) {
477 final Resources partnerRes = partner.getResources();
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700478 int workspaceResId = partnerRes.getIdentifier(Partner.RES_DEFAULT_LAYOUT,
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700479 "xml", partner.getPackageName());
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700480 if (workspaceResId != 0) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700481 loader = new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal3a5a9d12014-10-01 15:33:41 -0700482 mOpenHelper, partnerRes, workspaceResId);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700483 }
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700484 }
485 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700486
Sunny Goyal9d219682014-10-23 14:21:02 -0700487 final boolean usingExternallyProvidedLayout = loader != null;
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700488 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700489 loader = getDefaultLayoutParser(widgetHost);
Brian Muramatsu5524b492012-10-02 16:55:54 -0700490 }
Sunny Goyalc6c8fef2015-03-04 09:51:18 -0800491
492 // There might be some partially restored DB items, due to buggy restore logic in
493 // previous versions of launcher.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800494 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Michael Jurkab85f8a42012-04-25 15:48:32 -0700495 // Populate favorites table with initial favorites
Sunny Goyal9d219682014-10-23 14:21:02 -0700496 if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0)
497 && usingExternallyProvidedLayout) {
498 // Unable to load external layout. Cleanup and load the internal layout.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800499 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyal9d219682014-10-23 14:21:02 -0700500 mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(),
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700501 getDefaultLayoutParser(widgetHost));
Sunny Goyal9d219682014-10-23 14:21:02 -0700502 }
Sunny Goyal33d44382014-10-16 09:24:19 -0700503 clearFlagEmptyDbCreated();
Michael Jurkab85f8a42012-04-25 15:48:32 -0700504 }
505 }
506
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700507 /**
508 * Creates workspace loader from an XML resource listed in the app restrictions.
509 *
510 * @return the loader if the restrictions are set and the resource exists; null otherwise.
511 */
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700512 private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700513 Context ctx = getContext();
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700514 InvariantDeviceProfile grid = LauncherAppState.getIDP(ctx);
515
516 String authority = Settings.Secure.getString(ctx.getContentResolver(),
517 "launcher3.layout.provider");
518 if (TextUtils.isEmpty(authority)) {
Sunny Goyal35ca8732015-04-06 10:45:31 -0700519 return null;
520 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700521
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700522 ProviderInfo pi = ctx.getPackageManager().resolveContentProvider(authority, 0);
523 if (pi == null) {
524 Log.e(TAG, "No provider found for authority " + authority);
525 return null;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700526 }
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700527 Uri uri = new Uri.Builder().scheme("content").authority(authority).path("launcher_layout")
528 .appendQueryParameter("version", "1")
529 .appendQueryParameter("gridWidth", Integer.toString(grid.numColumns))
530 .appendQueryParameter("gridHeight", Integer.toString(grid.numRows))
531 .appendQueryParameter("hotseatSize", Integer.toString(grid.numHotseatIcons))
532 .build();
533
534 try (InputStream in = ctx.getContentResolver().openInputStream(uri)) {
535 // Read the full xml so that we fail early in case of any IO error.
536 String layout = new String(IOUtils.toByteArray(in));
537 XmlPullParser parser = Xml.newPullParser();
538 parser.setInput(new StringReader(layout));
539
540 Log.d(TAG, "Loading layout from " + authority);
541 return new AutoInstallsLayout(ctx, widgetHost, mOpenHelper,
542 ctx.getPackageManager().getResourcesForApplication(pi.applicationInfo),
543 () -> parser, AutoInstallsLayout.TAG_WORKSPACE);
544 } catch (Exception e) {
545 Log.e(TAG, "Error getting layout stream from: " + authority , e);
546 return null;
547 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700548 }
549
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700550 private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) {
Adam Cohen27824492017-09-22 17:10:55 -0700551 InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext());
552 int defaultLayout = idp.defaultLayoutId;
553
554 UserManagerCompat um = UserManagerCompat.getInstance(getContext());
555 if (um.isDemoUser() && idp.demoModeLayoutId != 0) {
556 defaultLayout = idp.demoModeLayoutId;
557 }
558
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700559 return new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal9d219682014-10-23 14:21:02 -0700560 mOpenHelper, getContext().getResources(), defaultLayout);
561 }
562
Sunny Goyald3849d12015-10-29 10:28:32 -0700563 /**
Sunny Goyalf076eae2016-01-11 12:25:10 -0800564 * The class is subclassed in tests to create an in-memory db.
565 */
Sunny Goyal19026b22018-03-09 14:37:37 -0800566 public static class DatabaseHelper extends NoLocaleSQLiteHelper implements LayoutParserCallback {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800567 private final BackupManager mBackupManager;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700568 private final Handler mWidgetHostResetHandler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 private final Context mContext;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700570 private int mMaxItemId = -1;
571 private int mMaxScreenId = -1;
Sunny Goyal161a2142018-10-29 14:02:20 -0700572 private boolean mBackupTableExists;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700574 DatabaseHelper(Context context, Handler widgetHostResetHandler) {
575 this(context, widgetHostResetHandler, LauncherFiles.LAUNCHER_DB);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700576 // Table creation sometimes fails silently, which leads to a crash loop.
577 // This way, we will try to create a table every time after crash, so the device
578 // would eventually be able to recover.
Sunny Goyal161a2142018-10-29 14:02:20 -0700579 if (!tableExists(getReadableDatabase(), Favorites.TABLE_NAME)) {
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700580 Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
581 // This operation is a no-op if the table already exists.
582 addFavoritesTable(getWritableDatabase(), true);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700583 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700584 mBackupTableExists = tableExists(getReadableDatabase(), Favorites.BACKUP_TABLE_NAME);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700585
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700586 initIds();
587 }
588
589 /**
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700590 * Constructor used in tests and for restore.
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700591 */
592 public DatabaseHelper(
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700593 Context context, Handler widgetHostResetHandler, String tableName) {
Sunny Goyal19026b22018-03-09 14:37:37 -0800594 super(context, tableName, SCHEMA_VERSION);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700595 mContext = context;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700596 mWidgetHostResetHandler = widgetHostResetHandler;
Jon Miranda2bc6b932019-03-07 15:24:46 -0800597 mBackupManager = new BackupManager(mContext);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700598 }
599
600 protected void initIds() {
Winson Chung3d503fb2011-07-13 17:25:49 -0700601 // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
602 // the DB here
Adam Cohendcd297f2013-06-18 13:13:40 -0700603 if (mMaxItemId == -1) {
604 mMaxItemId = initializeMaxItemId(getWritableDatabase());
605 }
606 if (mMaxScreenId == -1) {
607 mMaxScreenId = initializeMaxScreenId(getWritableDatabase());
Winson Chung3d503fb2011-07-13 17:25:49 -0700608 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609 }
610
611 @Override
612 public void onCreate(SQLiteDatabase db) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800613 if (LOGD) Log.d(TAG, "creating new launcher database");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700614
Adam Cohendcd297f2013-06-18 13:13:40 -0700615 mMaxItemId = 1;
616 mMaxScreenId = 0;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700617
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700618 addFavoritesTable(db, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800619
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800620 // Fresh and clean launcher DB.
621 mMaxItemId = initializeMaxItemId(db);
Sunny Goyalf076eae2016-01-11 12:25:10 -0800622 onEmptyDbCreated();
623 }
624
Sunny Goyal161a2142018-10-29 14:02:20 -0700625 protected void onAddOrDeleteOp(SQLiteDatabase db) {
626 if (mBackupTableExists) {
627 dropTable(db, Favorites.BACKUP_TABLE_NAME);
628 mBackupTableExists = false;
629 }
630 }
631
Sunny Goyalf076eae2016-01-11 12:25:10 -0800632 /**
633 * Overriden in tests.
634 */
635 protected void onEmptyDbCreated() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700636 // Database was just created, so wipe any previous widgets
637 if (mWidgetHostResetHandler != null) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700638 newLauncherWidgetHost().deleteHost();
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700639 mWidgetHostResetHandler.sendEmptyMessage(
Sunny Goyal72db9af2016-11-29 07:25:49 +0530640 ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700641 }
642
Sunny Goyalf076eae2016-01-11 12:25:10 -0800643 // Set the flag for empty DB
644 Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
Sunny Goyalf076eae2016-01-11 12:25:10 -0800645 }
646
Jon Miranda2bc6b932019-03-07 15:24:46 -0800647 public long getSerialNumberForUser(UserHandle user) {
648 return UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user);
649 }
650
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700651 public long getDefaultUserSerial() {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800652 return getSerialNumberForUser(Process.myUserHandle());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800653 }
654
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700655 private void addFavoritesTable(SQLiteDatabase db, boolean optional) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700656 Favorites.addTableToDb(db, getDefaultUserSerial(), optional);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700657 }
658
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 @Override
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700660 public void onOpen(SQLiteDatabase db) {
661 super.onOpen(db);
Sunny Goyal05f30882017-05-03 12:42:18 -0700662
663 File schemaFile = mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE);
664 if (!schemaFile.exists()) {
665 handleOneTimeDataUpgrade(db);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700666 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800667 DbDowngradeHelper.updateSchemaFile(schemaFile, SCHEMA_VERSION, mContext);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700668 }
669
670 /**
Sunny Goyal05f30882017-05-03 12:42:18 -0700671 * One-time data updated before support of onDowngrade was added. This update is backwards
672 * compatible and can safely be run multiple times.
673 * Note: No new logic should be added here after release, as the new logic might not get
674 * executed on an existing device.
675 * TODO: Move this to db upgrade path, once the downgrade path is released.
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700676 */
Sunny Goyal05f30882017-05-03 12:42:18 -0700677 protected void handleOneTimeDataUpgrade(SQLiteDatabase db) {
678 // Remove "profile extra"
679 UserManagerCompat um = UserManagerCompat.getInstance(mContext);
680 for (UserHandle user : um.getUserProfiles()) {
681 long serial = um.getSerialNumberForUser(user);
682 String sql = "update favorites set intent = replace(intent, "
683 + "';l.profile=" + serial + ";', ';') where itemType = 0;";
684 db.execSQL(sql);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700685 }
686 }
687
688 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Winson Chungc763c4e2013-07-19 13:49:06 -0700690 if (LOGD) Log.d(TAG, "onUpgrade triggered: " + oldVersion);
Sunny Goyala2cc6242015-01-14 14:23:02 -0800691 switch (oldVersion) {
692 // The version cannot be lower that 12, as Launcher3 never supported a lower
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800693 // version of the DB.
Sunny Goyalc5939392018-12-07 11:43:47 -0800694 case 12:
695 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800696 case 13: {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700697 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800698 // Insert new column for holding widget provider name
699 db.execSQL("ALTER TABLE favorites " +
700 "ADD COLUMN appWidgetProvider TEXT;");
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700701 t.commit();
Sunny Goyala2cc6242015-01-14 14:23:02 -0800702 } catch (SQLException ex) {
703 Log.e(TAG, ex.getMessage(), ex);
704 // Old version remains, which means we wipe old data
705 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800706 }
707 }
708 case 14: {
Sunny Goyalc5939392018-12-07 11:43:47 -0800709 if (!addIntegerColumn(db, Favorites.MODIFIED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800710 // Old version remains, which means we wipe old data
711 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800712 }
713 }
714 case 15: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700715 if (!addIntegerColumn(db, Favorites.RESTORED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800716 // Old version remains, which means we wipe old data
717 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800718 }
719 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800720 case 16:
Sunny Goyal10629b02016-09-01 12:50:11 -0700721 // No-op
Sunny Goyalc5939392018-12-07 11:43:47 -0800722 case 17:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800723 // No-op
Sunny Goyalc5939392018-12-07 11:43:47 -0800724 case 18:
725 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800726 case 19: {
727 // Add userId column
Sunny Goyalc5939392018-12-07 11:43:47 -0800728 if (!addIntegerColumn(db, Favorites.PROFILE_ID, getDefaultUserSerial())) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800729 // Old version remains, which means we wipe old data
730 break;
731 }
732 }
733 case 20:
734 if (!updateFolderItemsRank(db, true)) {
735 break;
736 }
Sunny Goyald2f38192015-02-25 10:46:34 -0800737 case 21:
Sunny Goyalc5939392018-12-07 11:43:47 -0800738 // No-op
Sunny Goyald2f38192015-02-25 10:46:34 -0800739 case 22: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700740 if (!addIntegerColumn(db, Favorites.OPTIONS, 0)) {
741 // Old version remains, which means we wipe old data
742 break;
743 }
744 }
Sunny Goyal0b037782015-04-02 10:27:03 -0700745 case 23:
Sunny Goyal5c97f512015-05-19 16:03:28 -0700746 // No-op
Sunny Goyale2fba6c2015-05-12 10:39:59 -0700747 case 24:
Tony Mak1b6826c2018-02-27 15:06:12 +0000748 // No-op
Sunny Goyal5c97f512015-05-19 16:03:28 -0700749 case 25:
750 convertShortcutsToLauncherActivities(db);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700751 case 26:
752 // QSB was moved to the grid. Clear the first row on screen 0.
Jon Miranda7143ba62019-03-15 09:00:05 -0700753 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyal8ad02b82016-12-29 13:31:43 -0800754 !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700755 break;
756 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800757 case 27: {
758 // Update the favorites table so that the screen ids are ordered based on
759 // workspace page rank.
760 IntArray finalScreens = LauncherDbUtils.queryIntArray(db, "workspaceScreens",
761 BaseColumns._ID, null, null, "screenRank");
762 int[] original = finalScreens.toArray();
763 Arrays.sort(original);
764 String updatemap = "";
765 for (int i = 0; i < original.length; i++) {
766 if (finalScreens.get(i) != original[i]) {
767 updatemap += String.format(Locale.ENGLISH, " WHEN %1$s=%2$d THEN %3$d",
768 Favorites.SCREEN, finalScreens.get(i), original[i]);
769 }
770 }
771 if (!TextUtils.isEmpty(updatemap)) {
772 String query = String.format(Locale.ENGLISH,
773 "UPDATE %1$s SET %2$s=CASE %3$s ELSE %2$s END WHERE %4$s = %5$d",
774 Favorites.TABLE_NAME, Favorites.SCREEN, updatemap,
775 Favorites.CONTAINER, Favorites.CONTAINER_DESKTOP);
776 db.execSQL(query);
777 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700778 dropTable(db, "workspaceScreens");
Sunny Goyalc5939392018-12-07 11:43:47 -0800779 }
780 case 28:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800781 // DB Upgraded successfully
782 return;
Chris Wrend5e66bf2013-09-16 14:02:29 -0400783 }
784
Sunny Goyala2cc6242015-01-14 14:23:02 -0800785 // DB was not upgraded
786 Log.w(TAG, "Destroying all old data.");
787 createEmptyDB(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800788 }
Romain Guy7eb9e5e2009-12-02 20:10:07 -0800789
Adam Cohen9b1d0622014-05-21 19:01:57 -0700790 @Override
791 public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Sunny Goyal05f30882017-05-03 12:42:18 -0700792 try {
793 DbDowngradeHelper.parse(mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE))
794 .onDowngrade(db, oldVersion, newVersion);
795 } catch (Exception e) {
796 Log.d(TAG, "Unable to downgrade from: " + oldVersion + " to " + newVersion +
797 ". Wiping databse.", e);
798 createEmptyDB(db);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700799 }
Sunny Goyal42de82f2014-09-26 22:09:29 -0700800 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700801
Sunny Goyal42de82f2014-09-26 22:09:29 -0700802 /**
803 * Clears all the data for a fresh start.
804 */
805 public void createEmptyDB(SQLiteDatabase db) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700806 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700807 dropTable(db, Favorites.TABLE_NAME);
808 dropTable(db, "workspaceScreens");
Sunny Goyale05b08f2017-02-23 18:30:22 -0800809 onCreate(db);
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700810 t.commit();
Sunny Goyale05b08f2017-02-23 18:30:22 -0800811 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700812 }
813
Sunny Goyald2f38192015-02-25 10:46:34 -0800814 /**
Sunny Goyal55fddc82017-04-06 15:02:52 -0700815 * Removes widgets which are registered to the Launcher's host, but are not present
816 * in our model.
817 */
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700818 @TargetApi(Build.VERSION_CODES.O)
Sunny Goyal55fddc82017-04-06 15:02:52 -0700819 public void removeGhostWidgets(SQLiteDatabase db) {
820 // Get all existing widget ids.
821 final AppWidgetHost host = newLauncherWidgetHost();
822 final int[] allWidgets;
823 try {
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700824 // Although the method was defined in O, it has existed since the beginning of time,
825 // so it might work on older platforms as well.
826 allWidgets = host.getAppWidgetIds();
827 } catch (IncompatibleClassChangeError e) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700828 Log.e(TAG, "getAppWidgetIds not supported", e);
829 return;
830 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800831 final IntSet validWidgets = IntSet.wrap(LauncherDbUtils.queryIntArray(db,
832 Favorites.TABLE_NAME, Favorites.APPWIDGET_ID,
833 "itemType=" + Favorites.ITEM_TYPE_APPWIDGET, null, null));
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700834 for (int widgetId : allWidgets) {
835 if (!validWidgets.contains(widgetId)) {
836 try {
837 FileLog.d(TAG, "Deleting invalid widget " + widgetId);
838 host.deleteAppWidgetId(widgetId);
839 } catch (RuntimeException e) {
840 // Ignore
841 }
842 }
Sunny Goyal55fddc82017-04-06 15:02:52 -0700843 }
844 }
845
846 /**
Sunny Goyal0b037782015-04-02 10:27:03 -0700847 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
848 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
849 */
Sunny Goyal316490e2015-06-02 09:38:28 -0700850 @Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700851 try (SQLiteTransaction t = new SQLiteTransaction(db);
852 // Only consider the primary user as other users can't have a shortcut.
853 Cursor c = db.query(Favorites.TABLE_NAME,
854 new String[] { Favorites._ID, Favorites.INTENT},
855 "itemType=" + Favorites.ITEM_TYPE_SHORTCUT +
856 " AND profileId=" + getDefaultUserSerial(),
857 null, null, null, null);
858 SQLiteStatement updateStmt = db.compileStatement("UPDATE favorites SET itemType="
859 + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?")
860 ) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700861 final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
862 final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);
863
864 while (c.moveToNext()) {
865 String intentDescription = c.getString(intentIndex);
866 Intent intent;
867 try {
868 intent = Intent.parseUri(intentDescription, 0);
869 } catch (URISyntaxException e) {
870 Log.e(TAG, "Unable to parse intent", e);
871 continue;
872 }
873
Sunny Goyal9dbb27c2019-07-17 15:12:56 -0700874 if (!PackageManagerHelper.isLauncherAppTarget(intent)) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700875 continue;
876 }
877
Sunny Goyalefb7e842018-10-04 15:11:00 -0700878 int id = c.getInt(idIndex);
Sunny Goyal0b037782015-04-02 10:27:03 -0700879 updateStmt.bindLong(1, id);
Sunny Goyalc22841b2015-07-13 19:59:50 -0700880 updateStmt.executeUpdateDelete();
Sunny Goyal0b037782015-04-02 10:27:03 -0700881 }
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700882 t.commit();
Sunny Goyal0b037782015-04-02 10:27:03 -0700883 } catch (SQLException ex) {
884 Log.w(TAG, "Error deduping shortcuts", ex);
Sunny Goyal0b037782015-04-02 10:27:03 -0700885 }
886 }
887
Adam Cohen091440a2015-03-18 14:16:05 -0700888 @Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700889 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal08f72612015-01-05 13:41:43 -0800890 if (addRankColumn) {
891 // Insert new column for holding rank
892 db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
893 }
894
895 // Get a map for folder ID to folder width
896 Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
897 + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
898 + " GROUP BY container;",
899 new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
900
901 while (c.moveToNext()) {
Sunny Goyalc87775d2015-02-10 19:52:36 -0800902 db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
903 + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
Sunny Goyal08f72612015-01-05 13:41:43 -0800904 new Object[] {c.getLong(1) + 1, c.getLong(0)});
905 }
906
907 c.close();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700908 t.commit();
Sunny Goyal08f72612015-01-05 13:41:43 -0800909 } catch (SQLException ex) {
910 // Old version remains, which means we wipe old data
911 Log.e(TAG, ex.getMessage(), ex);
912 return false;
Sunny Goyal08f72612015-01-05 13:41:43 -0800913 }
914 return true;
915 }
916
Sunny Goyal5d85c442015-03-10 13:14:47 -0700917 private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700918 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700919 db.execSQL("ALTER TABLE favorites ADD COLUMN "
920 + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700921 t.commit();
Kenny Guyed131872014-04-30 03:02:21 +0100922 } catch (SQLException ex) {
Kenny Guyed131872014-04-30 03:02:21 +0100923 Log.e(TAG, ex.getMessage(), ex);
924 return false;
Kenny Guyed131872014-04-30 03:02:21 +0100925 }
926 return true;
927 }
928
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700929 // Generates a new ID to use for an object in your database. This method should be only
930 // called from the main UI thread. As an exception, we do call it when we call the
931 // constructor from the worker thread; however, this doesn't extend until after the
932 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
933 // after that point
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700934 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -0700935 public int generateNewItemId() {
Adam Cohendcd297f2013-06-18 13:13:40 -0700936 if (mMaxItemId < 0) {
937 throw new RuntimeException("Error: max item id was not initialized");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700938 }
Adam Cohendcd297f2013-06-18 13:13:40 -0700939 mMaxItemId += 1;
940 return mMaxItemId;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700941 }
942
Sunny Goyal55fddc82017-04-06 15:02:52 -0700943 public AppWidgetHost newLauncherWidgetHost() {
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700944 return new LauncherAppWidgetHost(mContext);
Sunny Goyal55fddc82017-04-06 15:02:52 -0700945 }
946
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700947 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -0700948 public int insertAndCheck(SQLiteDatabase db, ContentValues values) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700949 return dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, values);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700950 }
951
Sunny Goyalc5939392018-12-07 11:43:47 -0800952 public void checkId(ContentValues values) {
953 int id = values.getAsInteger(Favorites._ID);
954 mMaxItemId = Math.max(id, mMaxItemId);
955
956 Integer screen = values.getAsInteger(Favorites.SCREEN);
957 Integer container = values.getAsInteger(Favorites.CONTAINER);
958 if (screen != null && container != null
959 && container.intValue() == Favorites.CONTAINER_DESKTOP) {
960 mMaxScreenId = Math.max(screen, mMaxScreenId);
Chris Wren5dee7af2013-12-20 17:22:11 -0500961 }
962 }
963
Sunny Goyalefb7e842018-10-04 15:11:00 -0700964 private int initializeMaxItemId(SQLiteDatabase db) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800965 return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s", Favorites._ID, Favorites.TABLE_NAME);
Adam Cohendcd297f2013-06-18 13:13:40 -0700966 }
967
968 // Generates a new ID to use for an workspace screen in your database. This method
969 // should be only called from the main UI thread. As an exception, we do call it when we
970 // call the constructor from the worker thread; however, this doesn't extend until after the
971 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
972 // after that point
Sunny Goyalefb7e842018-10-04 15:11:00 -0700973 public int generateNewScreenId() {
Adam Cohendcd297f2013-06-18 13:13:40 -0700974 if (mMaxScreenId < 0) {
975 throw new RuntimeException("Error: max screen id was not initialized");
976 }
977 mMaxScreenId += 1;
978 return mMaxScreenId;
979 }
980
Sunny Goyalefb7e842018-10-04 15:11:00 -0700981 private int initializeMaxScreenId(SQLiteDatabase db) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800982 return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s WHERE %3$s = %4$d",
983 Favorites.SCREEN, Favorites.TABLE_NAME, Favorites.CONTAINER,
984 Favorites.CONTAINER_DESKTOP);
Adam Cohen7ec3bbf2014-07-31 00:09:45 -0700985 }
986
Adam Cohen091440a2015-03-18 14:16:05 -0700987 @Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700988 // TODO: Use multiple loaders with fall-back and transaction.
Sunny Goyalc5939392018-12-07 11:43:47 -0800989 int count = loader.loadLayout(db, new IntArray());
Adam Cohen71483f42014-05-15 14:04:01 -0700990
991 // Ensure that the max ids are initialized
992 mMaxItemId = initializeMaxItemId(db);
993 mMaxScreenId = initializeMaxScreenId(db);
994 return count;
995 }
Mike Cleronb87bd162009-10-30 16:36:56 -0700996 }
Daniel Lehmannc3a80402012-04-23 21:35:11 -0700997
Sunny Goyalfe4e4b92015-03-04 10:43:45 -0800998 /**
999 * @return the max _id in the provided table.
1000 */
Sunny Goyalc5939392018-12-07 11:43:47 -08001001 @Thunk static int getMaxId(SQLiteDatabase db, String query, Object... args) {
1002 int max = (int) DatabaseUtils.longForQuery(db,
1003 String.format(Locale.ENGLISH, query, args),
1004 null);
1005 if (max < 0) {
1006 throw new RuntimeException("Error: could not query max id");
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001007 }
Sunny Goyalc5939392018-12-07 11:43:47 -08001008 return max;
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001009 }
1010
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001011 static class SqlArguments {
1012 public final String table;
1013 public final String where;
1014 public final String[] args;
1015
1016 SqlArguments(Uri url, String where, String[] args) {
1017 if (url.getPathSegments().size() == 1) {
1018 this.table = url.getPathSegments().get(0);
1019 this.where = where;
1020 this.args = args;
1021 } else if (url.getPathSegments().size() != 2) {
1022 throw new IllegalArgumentException("Invalid URI: " + url);
1023 } else if (!TextUtils.isEmpty(where)) {
1024 throw new UnsupportedOperationException("WHERE clause not supported: " + url);
1025 } else {
1026 this.table = url.getPathSegments().get(0);
Daniel Lehmannc3a80402012-04-23 21:35:11 -07001027 this.where = "_id=" + ContentUris.parseId(url);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 this.args = null;
1029 }
1030 }
1031
1032 SqlArguments(Uri url) {
1033 if (url.getPathSegments().size() == 1) {
1034 table = url.getPathSegments().get(0);
1035 where = null;
1036 args = null;
1037 } else {
1038 throw new IllegalArgumentException("Invalid URI: " + url);
1039 }
1040 }
1041 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001042
1043 private static class ChangeListenerWrapper implements Handler.Callback {
1044
1045 private static final int MSG_LAUNCHER_PROVIDER_CHANGED = 1;
Sunny Goyalf2dd4212017-09-28 11:31:39 -07001046 private static final int MSG_APP_WIDGET_HOST_RESET = 2;
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001047
1048 private LauncherProviderChangeListener mListener;
1049
1050 @Override
1051 public boolean handleMessage(Message msg) {
1052 if (mListener != null) {
1053 switch (msg.what) {
1054 case MSG_LAUNCHER_PROVIDER_CHANGED:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001055 mListener.onLauncherProviderChanged();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001056 break;
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001057 case MSG_APP_WIDGET_HOST_RESET:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001058 mListener.onAppWidgetHostReset();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001059 break;
1060 }
1061 }
1062 return true;
1063 }
1064 }
Adam Cohen72960972014-01-15 18:13:55 -08001065}