blob: f830301a3da03987a5c849617d3fab4e7c331506 [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 Goyalb2d46ce2015-03-26 11:32:11 -070036import android.content.pm.PackageManager.NameNotFoundException;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070037import android.content.pm.ProviderInfo;
Adam Cohen228da5a2011-07-27 22:23:47 -070038import android.content.res.Resources;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.database.Cursor;
Sunny Goyalc5939392018-12-07 11:43:47 -080040import android.database.DatabaseUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.database.SQLException;
Adam Cohen228da5a2011-07-27 22:23:47 -070042import android.database.sqlite.SQLiteDatabase;
Adam Cohen228da5a2011-07-27 22:23:47 -070043import android.database.sqlite.SQLiteQueryBuilder;
Sunny Goyal0b037782015-04-02 10:27:03 -070044import android.database.sqlite.SQLiteStatement;
Adam Cohen228da5a2011-07-27 22:23:47 -070045import android.net.Uri;
Sunny Goyal7779d622015-06-11 16:18:39 -070046import android.os.Binder;
Sunny Goyal22ca9ec2017-05-18 15:03:13 -070047import android.os.Build;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070048import android.os.Bundle;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070049import android.os.Handler;
50import android.os.Message;
Sunny Goyal7779d622015-06-11 16:18:39 -070051import android.os.Process;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080052import android.os.UserHandle;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -070053import android.os.UserManager;
Sunny Goyalc5939392018-12-07 11:43:47 -080054import android.provider.BaseColumns;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070055import android.provider.Settings;
Adam Cohen228da5a2011-07-27 22:23:47 -070056import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.util.Log;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070058import android.util.Xml;
Adam Cohen228da5a2011-07-27 22:23:47 -070059
Sunny Goyal0fe505b2014-08-06 09:55:36 -070060import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
61import com.android.launcher3.LauncherSettings.Favorites;
Kenny Guyed131872014-04-30 03:02:21 +010062import com.android.launcher3.compat.UserManagerCompat;
Sunny Goyala9e2f5a2016-06-10 12:22:04 -070063import com.android.launcher3.config.FeatureFlags;
Sunny Goyalfdbef272017-02-01 12:52:54 -080064import com.android.launcher3.logging.FileLog;
Sunny Goyal05f30882017-05-03 12:42:18 -070065import com.android.launcher3.model.DbDowngradeHelper;
Sunny Goyala9e2f5a2016-06-10 12:22:04 -070066import com.android.launcher3.provider.LauncherDbUtils;
Sunny Goyaldbfc9012017-04-17 16:58:36 -070067import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
Sunny Goyale8f7d5a2016-05-24 11:30:14 -070068import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070069import com.android.launcher3.util.IOUtils;
Sunny Goyalefb7e842018-10-04 15:11:00 -070070import com.android.launcher3.util.IntArray;
71import com.android.launcher3.util.IntSet;
Sunny Goyal19026b22018-03-09 14:37:37 -080072import com.android.launcher3.util.NoLocaleSQLiteHelper;
Sunny Goyalb5b55c82016-05-10 12:28:59 -070073import com.android.launcher3.util.Preconditions;
Adam Cohen091440a2015-03-18 14:16:05 -070074import com.android.launcher3.util.Thunk;
Michael Jurka8b805b12012-04-18 14:23:14 -070075
Sunny Goyalc0f03d92019-03-22 14:13:36 -070076import org.xmlpull.v1.XmlPullParser;
77
Sunny Goyal05f30882017-05-03 12:42:18 -070078import java.io.File;
Hyunyoung Song6aa37292017-02-06 10:46:24 -080079import java.io.FileDescriptor;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070080import java.io.IOException;
81import java.io.InputStream;
Hyunyoung Song6aa37292017-02-06 10:46:24 -080082import java.io.PrintWriter;
Sunny Goyalc0f03d92019-03-22 14:13:36 -070083import java.io.StringReader;
Mike Cleronb87bd162009-10-30 16:36:56 -070084import java.net.URISyntaxException;
Adam Cohen228da5a2011-07-27 22:23:47 -070085import java.util.ArrayList;
Sunny Goyalefb7e842018-10-04 15:11:00 -070086import java.util.Arrays;
Sunny Goyalc5939392018-12-07 11:43:47 -080087import java.util.Locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089public class LauncherProvider extends ContentProvider {
Sunny Goyalc74e4192015-09-08 14:01:03 -070090 private static final String TAG = "LauncherProvider";
Joe Onoratoa30ce8e2009-11-11 08:16:49 -080091 private static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092
Sunny Goyal05f30882017-05-03 12:42:18 -070093 private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json";
94
Sunny Goyal3c7d55b2017-04-13 12:01:47 -070095 /**
96 * Represents the schema of the database. Changes in scheme need not be backwards compatible.
Sunny Goyalc5939392018-12-07 11:43:47 -080097 * When increasing the scheme version, ensure that downgrade_schema.json is updated
Sunny Goyal3c7d55b2017-04-13 12:01:47 -070098 */
Sunny Goyalc5939392018-12-07 11:43:47 -080099 public static final int SCHEMA_VERSION = 28;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800100
Sunny Goyal4276e7b2018-11-26 23:44:41 -0800101 public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings";
Winson Chung3d503fb2011-07-13 17:25:49 -0700102
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800103 static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800104
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700105 private final ChangeListenerWrapper mListenerWrapper = new ChangeListenerWrapper();
106 private Handler mListenerHandler;
107
Sunny Goyalf076eae2016-01-11 12:25:10 -0800108 protected DatabaseHelper mOpenHelper;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109
Hyunyoung Song6aa37292017-02-06 10:46:24 -0800110 /**
111 * $ adb shell dumpsys activity provider com.android.launcher3
112 */
113 @Override
114 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
115 LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
116 if (appState == null || !appState.getModel().isModelLoaded()) {
117 return;
118 }
119 appState.getModel().dumpState("", fd, writer, args);
120 }
121
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 @Override
123 public boolean onCreate() {
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800124 if (FeatureFlags.IS_DOGFOOD_BUILD) {
Sunny Goyale26d1002016-06-20 14:52:14 -0700125 Log.d(TAG, "Launcher process started");
126 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700127 mListenerHandler = new Handler(mListenerWrapper);
128
Sunny Goyalfdbef272017-02-01 12:52:54 -0800129 // The content provider exists for the entire duration of the launcher main process and
Sunny Goyal66f2b352018-02-09 10:57:12 -0800130 // is the first component to get created.
131 MainProcessInitializer.initialize(getContext().getApplicationContext());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 return true;
133 }
134
Sunny Goyald3849d12015-10-29 10:28:32 -0700135 /**
136 * Sets a provider listener.
137 */
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700138 public void setLauncherProviderChangeListener(LauncherProviderChangeListener listener) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700139 Preconditions.assertUIThread();
140 mListenerWrapper.mListener = listener;
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700141 }
142
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143 @Override
144 public String getType(Uri uri) {
145 SqlArguments args = new SqlArguments(uri, null, null);
146 if (TextUtils.isEmpty(args.where)) {
147 return "vnd.android.cursor.dir/" + args.table;
148 } else {
149 return "vnd.android.cursor.item/" + args.table;
150 }
151 }
152
Sunny Goyalf076eae2016-01-11 12:25:10 -0800153 /**
154 * Overridden in tests
155 */
156 protected synchronized void createDbIfNotExists() {
Sunny Goyald3849d12015-10-29 10:28:32 -0700157 if (mOpenHelper == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700158 mOpenHelper = new DatabaseHelper(getContext(), mListenerHandler);
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700159
160 if (RestoreDbTask.isPending(getContext())) {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800161 if (!RestoreDbTask.performRestore(mOpenHelper, new BackupManager(getContext()))) {
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700162 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
163 }
164 // Set is pending to false irrespective of the result, so that it doesn't get
165 // executed again.
166 RestoreDbTask.setPending(getContext(), false);
167 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700168 }
169 }
170
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 @Override
172 public Cursor query(Uri uri, String[] projection, String selection,
173 String[] selectionArgs, String sortOrder) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700174 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175
176 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
177 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
178 qb.setTables(args.table);
179
Romain Guy73b979d2009-06-09 12:57:21 -0700180 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder);
182 result.setNotificationUri(getContext().getContentResolver(), uri);
183
184 return result;
185 }
186
Sunny Goyalefb7e842018-10-04 15:11:00 -0700187 @Thunk static int dbInsertAndCheck(DatabaseHelper helper,
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700188 SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
Dan Sandlerd5024042014-01-09 15:01:33 -0500189 if (values == null) {
190 throw new RuntimeException("Error: attempting to insert null values");
191 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800192 if (!values.containsKey(LauncherSettings.Favorites._ID)) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700193 throw new RuntimeException("Error: attempting to add item without specifying an id");
194 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800195 helper.checkId(values);
Sunny Goyalefb7e842018-10-04 15:11:00 -0700196 return (int) db.insert(table, nullColumnHack, values);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700197 }
198
Sunny Goyald1064182015-08-13 12:08:30 -0700199 private void reloadLauncherIfExternal() {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800200 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyald1064182015-08-13 12:08:30 -0700201 LauncherAppState app = LauncherAppState.getInstanceNoCreate();
202 if (app != null) {
Sunny Goyaldd96a5e2017-02-17 11:22:34 -0800203 app.getModel().forceReload();
Sunny Goyald1064182015-08-13 12:08:30 -0700204 }
205 }
206 }
207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 @Override
209 public Uri insert(Uri uri, ContentValues initialValues) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700210 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211 SqlArguments args = new SqlArguments(uri);
212
Sunny Goyald1064182015-08-13 12:08:30 -0700213 // In very limited cases, we support system|signature permission apps to modify the db.
214 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700215 if (!initializeExternalAdd(initialValues)) {
Adam Cohena043fa82014-07-23 14:49:38 -0700216 return null;
217 }
218 }
219
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Chris Wren1ada10d2013-09-13 18:01:38 -0400221 addModifiedTime(initialValues);
Sunny Goyalefb7e842018-10-04 15:11:00 -0700222 final int rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
Sunny Goyale72f3d52015-03-02 14:24:21 -0800223 if (rowId < 0) return null;
Sunny Goyal161a2142018-10-29 14:02:20 -0700224 mOpenHelper.onAddOrDeleteOp(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225
226 uri = ContentUris.withAppendedId(uri, rowId);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700227 notifyListeners();
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800228 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 return uri;
230 }
231
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700232 private boolean initializeExternalAdd(ContentValues values) {
233 // 1. Ensure that externally added items have a valid item id
Sunny Goyalefb7e842018-10-04 15:11:00 -0700234 int id = mOpenHelper.generateNewItemId();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700235 values.put(LauncherSettings.Favorites._ID, id);
236
237 // 2. In the case of an app widget, and if no app widget id is specified, we
238 // attempt allocate and bind the widget.
239 Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
240 if (itemType != null &&
241 itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET &&
242 !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {
243
244 final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
245 ComponentName cn = ComponentName.unflattenFromString(
246 values.getAsString(Favorites.APPWIDGET_PROVIDER));
247
248 if (cn != null) {
249 try {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700250 AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
251 int appWidgetId = widgetHost.allocateAppWidgetId();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700252 values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
253 if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700254 widgetHost.deleteAppWidgetId(appWidgetId);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700255 return false;
256 }
257 } catch (RuntimeException e) {
258 Log.e(TAG, "Failed to initialize external widget", e);
259 return false;
260 }
261 } else {
262 return false;
263 }
264 }
265
Sunny Goyalc5939392018-12-07 11:43:47 -0800266 return true;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700267 }
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 @Override
270 public int bulkInsert(Uri uri, ContentValues[] values) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700271 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 SqlArguments args = new SqlArguments(uri);
273
274 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700275 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 int numValues = values.length;
277 for (int i = 0; i < numValues; i++) {
Chris Wren1ada10d2013-09-13 18:01:38 -0400278 addModifiedTime(values[i]);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700279 if (dbInsertAndCheck(mOpenHelper, db, args.table, null, values[i]) < 0) {
280 return 0;
281 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700283 mOpenHelper.onAddOrDeleteOp(db);
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700284 t.commit();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285 }
286
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700287 notifyListeners();
Sunny Goyald1064182015-08-13 12:08:30 -0700288 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 return values.length;
290 }
291
Sunny Goyal161a2142018-10-29 14:02:20 -0700292 @TargetApi(Build.VERSION_CODES.M)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 @Override
Yura085c8532014-02-11 15:15:29 +0000294 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
295 throws OperationApplicationException {
Sunny Goyald3849d12015-10-29 10:28:32 -0700296 createDbIfNotExists();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700297 try (SQLiteTransaction t = new SQLiteTransaction(mOpenHelper.getWritableDatabase())) {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800298 boolean isAddOrDelete = false;
Sunny Goyal161a2142018-10-29 14:02:20 -0700299
300 final int numOperations = operations.size();
301 final ContentProviderResult[] results = new ContentProviderResult[numOperations];
302 for (int i = 0; i < numOperations; i++) {
303 ContentProviderOperation op = operations.get(i);
304 results[i] = op.apply(this, results, i);
305
306 isAddOrDelete |= (op.isInsert() || op.isDelete()) &&
307 results[i].count != null && results[i].count > 0;
308 }
309 if (isAddOrDelete) {
310 mOpenHelper.onAddOrDeleteOp(t.getDb());
311 }
312
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700313 t.commit();
Sunny Goyald1064182015-08-13 12:08:30 -0700314 reloadLauncherIfExternal();
Sunny Goyal161a2142018-10-29 14:02:20 -0700315 return results;
Yura085c8532014-02-11 15:15:29 +0000316 }
317 }
318
319 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800320 public int delete(Uri uri, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700321 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800322 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
323
324 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800325
Louis Begina9c21c62016-08-15 15:18:41 -0700326 if (Binder.getCallingPid() != Process.myPid()
327 && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700328 mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
Louis Begina9c21c62016-08-15 15:18:41 -0700329 }
330 int count = db.delete(args.table, args.where, args.args);
331 if (count > 0) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700332 mOpenHelper.onAddOrDeleteOp(db);
Louis Begina9c21c62016-08-15 15:18:41 -0700333 notifyListeners();
334 reloadLauncherIfExternal();
335 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800336 return count;
337 }
338
339 @Override
340 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700341 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800342 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
343
Chris Wren1ada10d2013-09-13 18:01:38 -0400344 addModifiedTime(values);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
346 int count = db.update(args.table, values, args.where, args.args);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700347 if (count > 0) notifyListeners();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800348
Sunny Goyald1064182015-08-13 12:08:30 -0700349 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350 return count;
351 }
352
Sunny Goyal7779d622015-06-11 16:18:39 -0700353 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700354 public Bundle call(String method, final String arg, final Bundle extras) {
Sunny Goyal7779d622015-06-11 16:18:39 -0700355 if (Binder.getCallingUid() != Process.myUid()) {
356 return null;
357 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700358 createDbIfNotExists();
Sunny Goyal7779d622015-06-11 16:18:39 -0700359
360 switch (method) {
Sunny Goyald2497482015-09-22 18:24:19 -0700361 case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
362 clearFlagEmptyDbCreated();
363 return null;
364 }
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700365 case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : {
366 Bundle result = new Bundle();
367 result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
368 Utilities.getPrefs(getContext()).getBoolean(EMPTY_DATABASE_CREATED, false));
369 return result;
370 }
Sunny Goyald2497482015-09-22 18:24:19 -0700371 case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
372 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700373 result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders()
374 .toArray());
Sunny Goyald2497482015-09-22 18:24:19 -0700375 return result;
376 }
377 case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
378 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700379 result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId());
Sunny Goyald2497482015-09-22 18:24:19 -0700380 return result;
381 }
382 case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
383 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700384 result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId());
Sunny Goyald2497482015-09-22 18:24:19 -0700385 return result;
386 }
387 case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
Sunny Goyale05b08f2017-02-23 18:30:22 -0800388 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyald2497482015-09-22 18:24:19 -0700389 return null;
390 }
391 case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
392 loadDefaultFavoritesIfNecessary();
393 return null;
394 }
Sunny Goyal55fddc82017-04-06 15:02:52 -0700395 case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: {
396 mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
397 return null;
398 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700399 case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: {
400 Bundle result = new Bundle();
401 result.putBinder(LauncherSettings.Settings.EXTRA_VALUE,
402 new SQLiteTransaction(mOpenHelper.getWritableDatabase()));
403 return result;
404 }
405 case LauncherSettings.Settings.METHOD_REFRESH_BACKUP_TABLE: {
406 mOpenHelper.mBackupTableExists =
407 tableExists(mOpenHelper.getReadableDatabase(), Favorites.BACKUP_TABLE_NAME);
408 return null;
409 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700410 }
411 return null;
412 }
413
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700414 /**
415 * Deletes any empty folder from the DB.
416 * @return Ids of deleted folders.
417 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700418 private IntArray deleteEmptyFolders() {
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700419 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700420 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700421 // Select folders whose id do not match any container value.
422 String selection = LauncherSettings.Favorites.ITEM_TYPE + " = "
423 + LauncherSettings.Favorites.ITEM_TYPE_FOLDER + " AND "
424 + LauncherSettings.Favorites._ID + " NOT IN (SELECT " +
425 LauncherSettings.Favorites.CONTAINER + " FROM "
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700426 + Favorites.TABLE_NAME + ")";
Sunny Goyalc5939392018-12-07 11:43:47 -0800427
428 IntArray folderIds = LauncherDbUtils.queryIntArray(db, Favorites.TABLE_NAME,
429 Favorites._ID, selection, null, null);
Sunny Goyald2497482015-09-22 18:24:19 -0700430 if (!folderIds.isEmpty()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700431 db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery(
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700432 LauncherSettings.Favorites._ID, folderIds), null);
433 }
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700434 t.commit();
Sunny Goyalc5939392018-12-07 11:43:47 -0800435 return folderIds;
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700436 } catch (SQLException ex) {
437 Log.e(TAG, ex.getMessage(), ex);
Sunny Goyalc5939392018-12-07 11:43:47 -0800438 return new IntArray();
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700439 }
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700440 }
441
Sunny Goyalf076eae2016-01-11 12:25:10 -0800442 /**
443 * Overridden in tests
444 */
445 protected void notifyListeners() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700446 mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_LAUNCHER_PROVIDER_CHANGED);
Chris Wren1ada10d2013-09-13 18:01:38 -0400447 }
448
Adam Cohen091440a2015-03-18 14:16:05 -0700449 @Thunk static void addModifiedTime(ContentValues values) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800450 values.put(LauncherSettings.Favorites.MODIFIED, System.currentTimeMillis());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451 }
452
Sunny Goyald2497482015-09-22 18:24:19 -0700453 private void clearFlagEmptyDbCreated() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700454 Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
Sunny Goyal33d44382014-10-16 09:24:19 -0700455 }
456
Sunny Goyal42de82f2014-09-26 22:09:29 -0700457 /**
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700458 * Loads the default workspace based on the following priority scheme:
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700459 * 1) From the app restrictions
460 * 2) From a package provided by play store
461 * 3) From a partner configuration APK, already in the system image
462 * 4) The default configuration for the particular device
Brian Muramatsu5524b492012-10-02 16:55:54 -0700463 */
Sunny Goyald2497482015-09-22 18:24:19 -0700464 synchronized private void loadDefaultFavoritesIfNecessary() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700465 SharedPreferences sp = Utilities.getPrefs(getContext());
Adam Cohene25af792013-06-06 23:08:25 -0700466
Winson Chungc763c4e2013-07-19 13:49:06 -0700467 if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Chris Wren5dee7af2013-12-20 17:22:11 -0500468 Log.d(TAG, "loading default workspace");
Michael Jurka45355c42012-10-08 13:21:35 +0200469
Sunny Goyal55fddc82017-04-06 15:02:52 -0700470 AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700471 AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction(widgetHost);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700472 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700473 loader = AutoInstallsLayout.get(getContext(),widgetHost, mOpenHelper);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700474 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700475 if (loader == null) {
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700476 final Partner partner = Partner.get(getContext().getPackageManager());
477 if (partner != null && partner.hasDefaultLayout()) {
478 final Resources partnerRes = partner.getResources();
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700479 int workspaceResId = partnerRes.getIdentifier(Partner.RES_DEFAULT_LAYOUT,
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700480 "xml", partner.getPackageName());
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700481 if (workspaceResId != 0) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700482 loader = new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal3a5a9d12014-10-01 15:33:41 -0700483 mOpenHelper, partnerRes, workspaceResId);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700484 }
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700485 }
486 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700487
Sunny Goyal9d219682014-10-23 14:21:02 -0700488 final boolean usingExternallyProvidedLayout = loader != null;
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700489 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700490 loader = getDefaultLayoutParser(widgetHost);
Brian Muramatsu5524b492012-10-02 16:55:54 -0700491 }
Sunny Goyalc6c8fef2015-03-04 09:51:18 -0800492
493 // There might be some partially restored DB items, due to buggy restore logic in
494 // previous versions of launcher.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800495 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Michael Jurkab85f8a42012-04-25 15:48:32 -0700496 // Populate favorites table with initial favorites
Sunny Goyal9d219682014-10-23 14:21:02 -0700497 if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0)
498 && usingExternallyProvidedLayout) {
499 // Unable to load external layout. Cleanup and load the internal layout.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800500 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyal9d219682014-10-23 14:21:02 -0700501 mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(),
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700502 getDefaultLayoutParser(widgetHost));
Sunny Goyal9d219682014-10-23 14:21:02 -0700503 }
Sunny Goyal33d44382014-10-16 09:24:19 -0700504 clearFlagEmptyDbCreated();
Michael Jurkab85f8a42012-04-25 15:48:32 -0700505 }
506 }
507
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700508 /**
509 * Creates workspace loader from an XML resource listed in the app restrictions.
510 *
511 * @return the loader if the restrictions are set and the resource exists; null otherwise.
512 */
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700513 private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700514 Context ctx = getContext();
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700515 InvariantDeviceProfile grid = LauncherAppState.getIDP(ctx);
516
517 String authority = Settings.Secure.getString(ctx.getContentResolver(),
518 "launcher3.layout.provider");
519 if (TextUtils.isEmpty(authority)) {
Sunny Goyal35ca8732015-04-06 10:45:31 -0700520 return null;
521 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700522
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700523 ProviderInfo pi = ctx.getPackageManager().resolveContentProvider(authority, 0);
524 if (pi == null) {
525 Log.e(TAG, "No provider found for authority " + authority);
526 return null;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700527 }
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700528 Uri uri = new Uri.Builder().scheme("content").authority(authority).path("launcher_layout")
529 .appendQueryParameter("version", "1")
530 .appendQueryParameter("gridWidth", Integer.toString(grid.numColumns))
531 .appendQueryParameter("gridHeight", Integer.toString(grid.numRows))
532 .appendQueryParameter("hotseatSize", Integer.toString(grid.numHotseatIcons))
533 .build();
534
535 try (InputStream in = ctx.getContentResolver().openInputStream(uri)) {
536 // Read the full xml so that we fail early in case of any IO error.
537 String layout = new String(IOUtils.toByteArray(in));
538 XmlPullParser parser = Xml.newPullParser();
539 parser.setInput(new StringReader(layout));
540
541 Log.d(TAG, "Loading layout from " + authority);
542 return new AutoInstallsLayout(ctx, widgetHost, mOpenHelper,
543 ctx.getPackageManager().getResourcesForApplication(pi.applicationInfo),
544 () -> parser, AutoInstallsLayout.TAG_WORKSPACE);
545 } catch (Exception e) {
546 Log.e(TAG, "Error getting layout stream from: " + authority , e);
547 return null;
548 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700549 }
550
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700551 private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) {
Adam Cohen27824492017-09-22 17:10:55 -0700552 InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext());
553 int defaultLayout = idp.defaultLayoutId;
554
555 UserManagerCompat um = UserManagerCompat.getInstance(getContext());
556 if (um.isDemoUser() && idp.demoModeLayoutId != 0) {
557 defaultLayout = idp.demoModeLayoutId;
558 }
559
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700560 return new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal9d219682014-10-23 14:21:02 -0700561 mOpenHelper, getContext().getResources(), defaultLayout);
562 }
563
Sunny Goyald3849d12015-10-29 10:28:32 -0700564 /**
Sunny Goyalf076eae2016-01-11 12:25:10 -0800565 * The class is subclassed in tests to create an in-memory db.
566 */
Sunny Goyal19026b22018-03-09 14:37:37 -0800567 public static class DatabaseHelper extends NoLocaleSQLiteHelper implements LayoutParserCallback {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800568 private final BackupManager mBackupManager;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700569 private final Handler mWidgetHostResetHandler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800570 private final Context mContext;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700571 private int mMaxItemId = -1;
572 private int mMaxScreenId = -1;
Sunny Goyal161a2142018-10-29 14:02:20 -0700573 private boolean mBackupTableExists;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800574
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700575 DatabaseHelper(Context context, Handler widgetHostResetHandler) {
576 this(context, widgetHostResetHandler, LauncherFiles.LAUNCHER_DB);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700577 // Table creation sometimes fails silently, which leads to a crash loop.
578 // This way, we will try to create a table every time after crash, so the device
579 // would eventually be able to recover.
Sunny Goyal161a2142018-10-29 14:02:20 -0700580 if (!tableExists(getReadableDatabase(), Favorites.TABLE_NAME)) {
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700581 Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
582 // This operation is a no-op if the table already exists.
583 addFavoritesTable(getWritableDatabase(), true);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700584 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700585 mBackupTableExists = tableExists(getReadableDatabase(), Favorites.BACKUP_TABLE_NAME);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700586
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700587 initIds();
588 }
589
590 /**
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700591 * Constructor used in tests and for restore.
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700592 */
593 public DatabaseHelper(
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700594 Context context, Handler widgetHostResetHandler, String tableName) {
Sunny Goyal19026b22018-03-09 14:37:37 -0800595 super(context, tableName, SCHEMA_VERSION);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700596 mContext = context;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700597 mWidgetHostResetHandler = widgetHostResetHandler;
Jon Miranda2bc6b932019-03-07 15:24:46 -0800598 mBackupManager = new BackupManager(mContext);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700599 }
600
601 protected void initIds() {
Winson Chung3d503fb2011-07-13 17:25:49 -0700602 // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
603 // the DB here
Adam Cohendcd297f2013-06-18 13:13:40 -0700604 if (mMaxItemId == -1) {
605 mMaxItemId = initializeMaxItemId(getWritableDatabase());
606 }
607 if (mMaxScreenId == -1) {
608 mMaxScreenId = initializeMaxScreenId(getWritableDatabase());
Winson Chung3d503fb2011-07-13 17:25:49 -0700609 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800610 }
611
612 @Override
613 public void onCreate(SQLiteDatabase db) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800614 if (LOGD) Log.d(TAG, "creating new launcher database");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700615
Adam Cohendcd297f2013-06-18 13:13:40 -0700616 mMaxItemId = 1;
617 mMaxScreenId = 0;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700618
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700619 addFavoritesTable(db, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800620
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800621 // Fresh and clean launcher DB.
622 mMaxItemId = initializeMaxItemId(db);
Sunny Goyalf076eae2016-01-11 12:25:10 -0800623 onEmptyDbCreated();
624 }
625
Sunny Goyal161a2142018-10-29 14:02:20 -0700626 protected void onAddOrDeleteOp(SQLiteDatabase db) {
627 if (mBackupTableExists) {
628 dropTable(db, Favorites.BACKUP_TABLE_NAME);
629 mBackupTableExists = false;
630 }
631 }
632
Sunny Goyalf076eae2016-01-11 12:25:10 -0800633 /**
634 * Overriden in tests.
635 */
636 protected void onEmptyDbCreated() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700637 // Database was just created, so wipe any previous widgets
638 if (mWidgetHostResetHandler != null) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700639 newLauncherWidgetHost().deleteHost();
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700640 mWidgetHostResetHandler.sendEmptyMessage(
Sunny Goyal72db9af2016-11-29 07:25:49 +0530641 ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700642 }
643
Sunny Goyalf076eae2016-01-11 12:25:10 -0800644 // Set the flag for empty DB
645 Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
Sunny Goyalf076eae2016-01-11 12:25:10 -0800646 }
647
Jon Miranda2bc6b932019-03-07 15:24:46 -0800648 public long getSerialNumberForUser(UserHandle user) {
649 return UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user);
650 }
651
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700652 public long getDefaultUserSerial() {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800653 return getSerialNumberForUser(Process.myUserHandle());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800654 }
655
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700656 private void addFavoritesTable(SQLiteDatabase db, boolean optional) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700657 Favorites.addTableToDb(db, getDefaultUserSerial(), optional);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700658 }
659
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660 @Override
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700661 public void onOpen(SQLiteDatabase db) {
662 super.onOpen(db);
Sunny Goyal05f30882017-05-03 12:42:18 -0700663
664 File schemaFile = mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE);
665 if (!schemaFile.exists()) {
666 handleOneTimeDataUpgrade(db);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700667 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800668 DbDowngradeHelper.updateSchemaFile(schemaFile, SCHEMA_VERSION, mContext);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700669 }
670
671 /**
Sunny Goyal05f30882017-05-03 12:42:18 -0700672 * One-time data updated before support of onDowngrade was added. This update is backwards
673 * compatible and can safely be run multiple times.
674 * Note: No new logic should be added here after release, as the new logic might not get
675 * executed on an existing device.
676 * TODO: Move this to db upgrade path, once the downgrade path is released.
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700677 */
Sunny Goyal05f30882017-05-03 12:42:18 -0700678 protected void handleOneTimeDataUpgrade(SQLiteDatabase db) {
679 // Remove "profile extra"
680 UserManagerCompat um = UserManagerCompat.getInstance(mContext);
681 for (UserHandle user : um.getUserProfiles()) {
682 long serial = um.getSerialNumberForUser(user);
683 String sql = "update favorites set intent = replace(intent, "
684 + "';l.profile=" + serial + ";', ';') where itemType = 0;";
685 db.execSQL(sql);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700686 }
687 }
688
689 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Winson Chungc763c4e2013-07-19 13:49:06 -0700691 if (LOGD) Log.d(TAG, "onUpgrade triggered: " + oldVersion);
Sunny Goyala2cc6242015-01-14 14:23:02 -0800692 switch (oldVersion) {
693 // The version cannot be lower that 12, as Launcher3 never supported a lower
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800694 // version of the DB.
Sunny Goyalc5939392018-12-07 11:43:47 -0800695 case 12:
696 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800697 case 13: {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700698 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800699 // Insert new column for holding widget provider name
700 db.execSQL("ALTER TABLE favorites " +
701 "ADD COLUMN appWidgetProvider TEXT;");
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700702 t.commit();
Sunny Goyala2cc6242015-01-14 14:23:02 -0800703 } catch (SQLException ex) {
704 Log.e(TAG, ex.getMessage(), ex);
705 // Old version remains, which means we wipe old data
706 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800707 }
708 }
709 case 14: {
Sunny Goyalc5939392018-12-07 11:43:47 -0800710 if (!addIntegerColumn(db, Favorites.MODIFIED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800711 // Old version remains, which means we wipe old data
712 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800713 }
714 }
715 case 15: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700716 if (!addIntegerColumn(db, Favorites.RESTORED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800717 // Old version remains, which means we wipe old data
718 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800719 }
720 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800721 case 16:
Sunny Goyal10629b02016-09-01 12:50:11 -0700722 // No-op
Sunny Goyalc5939392018-12-07 11:43:47 -0800723 case 17:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800724 // No-op
Sunny Goyalc5939392018-12-07 11:43:47 -0800725 case 18:
726 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800727 case 19: {
728 // Add userId column
Sunny Goyalc5939392018-12-07 11:43:47 -0800729 if (!addIntegerColumn(db, Favorites.PROFILE_ID, getDefaultUserSerial())) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800730 // Old version remains, which means we wipe old data
731 break;
732 }
733 }
734 case 20:
735 if (!updateFolderItemsRank(db, true)) {
736 break;
737 }
Sunny Goyald2f38192015-02-25 10:46:34 -0800738 case 21:
Sunny Goyalc5939392018-12-07 11:43:47 -0800739 // No-op
Sunny Goyald2f38192015-02-25 10:46:34 -0800740 case 22: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700741 if (!addIntegerColumn(db, Favorites.OPTIONS, 0)) {
742 // Old version remains, which means we wipe old data
743 break;
744 }
745 }
Sunny Goyal0b037782015-04-02 10:27:03 -0700746 case 23:
Sunny Goyal5c97f512015-05-19 16:03:28 -0700747 // No-op
Sunny Goyale2fba6c2015-05-12 10:39:59 -0700748 case 24:
Tony Mak1b6826c2018-02-27 15:06:12 +0000749 // No-op
Sunny Goyal5c97f512015-05-19 16:03:28 -0700750 case 25:
751 convertShortcutsToLauncherActivities(db);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700752 case 26:
753 // QSB was moved to the grid. Clear the first row on screen 0.
Jon Miranda7143ba62019-03-15 09:00:05 -0700754 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyal8ad02b82016-12-29 13:31:43 -0800755 !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700756 break;
757 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800758 case 27: {
759 // Update the favorites table so that the screen ids are ordered based on
760 // workspace page rank.
761 IntArray finalScreens = LauncherDbUtils.queryIntArray(db, "workspaceScreens",
762 BaseColumns._ID, null, null, "screenRank");
763 int[] original = finalScreens.toArray();
764 Arrays.sort(original);
765 String updatemap = "";
766 for (int i = 0; i < original.length; i++) {
767 if (finalScreens.get(i) != original[i]) {
768 updatemap += String.format(Locale.ENGLISH, " WHEN %1$s=%2$d THEN %3$d",
769 Favorites.SCREEN, finalScreens.get(i), original[i]);
770 }
771 }
772 if (!TextUtils.isEmpty(updatemap)) {
773 String query = String.format(Locale.ENGLISH,
774 "UPDATE %1$s SET %2$s=CASE %3$s ELSE %2$s END WHERE %4$s = %5$d",
775 Favorites.TABLE_NAME, Favorites.SCREEN, updatemap,
776 Favorites.CONTAINER, Favorites.CONTAINER_DESKTOP);
777 db.execSQL(query);
778 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700779 dropTable(db, "workspaceScreens");
Sunny Goyalc5939392018-12-07 11:43:47 -0800780 }
781 case 28:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800782 // DB Upgraded successfully
783 return;
Chris Wrend5e66bf2013-09-16 14:02:29 -0400784 }
785
Sunny Goyala2cc6242015-01-14 14:23:02 -0800786 // DB was not upgraded
787 Log.w(TAG, "Destroying all old data.");
788 createEmptyDB(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800789 }
Romain Guy7eb9e5e2009-12-02 20:10:07 -0800790
Adam Cohen9b1d0622014-05-21 19:01:57 -0700791 @Override
792 public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Sunny Goyal05f30882017-05-03 12:42:18 -0700793 try {
794 DbDowngradeHelper.parse(mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE))
795 .onDowngrade(db, oldVersion, newVersion);
796 } catch (Exception e) {
797 Log.d(TAG, "Unable to downgrade from: " + oldVersion + " to " + newVersion +
798 ". Wiping databse.", e);
799 createEmptyDB(db);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700800 }
Sunny Goyal42de82f2014-09-26 22:09:29 -0700801 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700802
Sunny Goyal42de82f2014-09-26 22:09:29 -0700803 /**
804 * Clears all the data for a fresh start.
805 */
806 public void createEmptyDB(SQLiteDatabase db) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700807 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700808 dropTable(db, Favorites.TABLE_NAME);
809 dropTable(db, "workspaceScreens");
Sunny Goyale05b08f2017-02-23 18:30:22 -0800810 onCreate(db);
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700811 t.commit();
Sunny Goyale05b08f2017-02-23 18:30:22 -0800812 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700813 }
814
Sunny Goyald2f38192015-02-25 10:46:34 -0800815 /**
Sunny Goyal55fddc82017-04-06 15:02:52 -0700816 * Removes widgets which are registered to the Launcher's host, but are not present
817 * in our model.
818 */
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700819 @TargetApi(Build.VERSION_CODES.O)
Sunny Goyal55fddc82017-04-06 15:02:52 -0700820 public void removeGhostWidgets(SQLiteDatabase db) {
821 // Get all existing widget ids.
822 final AppWidgetHost host = newLauncherWidgetHost();
823 final int[] allWidgets;
824 try {
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700825 // Although the method was defined in O, it has existed since the beginning of time,
826 // so it might work on older platforms as well.
827 allWidgets = host.getAppWidgetIds();
828 } catch (IncompatibleClassChangeError e) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700829 Log.e(TAG, "getAppWidgetIds not supported", e);
830 return;
831 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800832 final IntSet validWidgets = IntSet.wrap(LauncherDbUtils.queryIntArray(db,
833 Favorites.TABLE_NAME, Favorites.APPWIDGET_ID,
834 "itemType=" + Favorites.ITEM_TYPE_APPWIDGET, null, null));
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700835 for (int widgetId : allWidgets) {
836 if (!validWidgets.contains(widgetId)) {
837 try {
838 FileLog.d(TAG, "Deleting invalid widget " + widgetId);
839 host.deleteAppWidgetId(widgetId);
840 } catch (RuntimeException e) {
841 // Ignore
842 }
843 }
Sunny Goyal55fddc82017-04-06 15:02:52 -0700844 }
845 }
846
847 /**
Sunny Goyal0b037782015-04-02 10:27:03 -0700848 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
849 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
850 */
Sunny Goyal316490e2015-06-02 09:38:28 -0700851 @Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700852 try (SQLiteTransaction t = new SQLiteTransaction(db);
853 // Only consider the primary user as other users can't have a shortcut.
854 Cursor c = db.query(Favorites.TABLE_NAME,
855 new String[] { Favorites._ID, Favorites.INTENT},
856 "itemType=" + Favorites.ITEM_TYPE_SHORTCUT +
857 " AND profileId=" + getDefaultUserSerial(),
858 null, null, null, null);
859 SQLiteStatement updateStmt = db.compileStatement("UPDATE favorites SET itemType="
860 + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?")
861 ) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700862 final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
863 final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);
864
865 while (c.moveToNext()) {
866 String intentDescription = c.getString(intentIndex);
867 Intent intent;
868 try {
869 intent = Intent.parseUri(intentDescription, 0);
870 } catch (URISyntaxException e) {
871 Log.e(TAG, "Unable to parse intent", e);
872 continue;
873 }
874
Sunny Goyal4e5cc642015-06-25 16:37:44 -0700875 if (!Utilities.isLauncherAppTarget(intent)) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700876 continue;
877 }
878
Sunny Goyalefb7e842018-10-04 15:11:00 -0700879 int id = c.getInt(idIndex);
Sunny Goyal0b037782015-04-02 10:27:03 -0700880 updateStmt.bindLong(1, id);
Sunny Goyalc22841b2015-07-13 19:59:50 -0700881 updateStmt.executeUpdateDelete();
Sunny Goyal0b037782015-04-02 10:27:03 -0700882 }
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700883 t.commit();
Sunny Goyal0b037782015-04-02 10:27:03 -0700884 } catch (SQLException ex) {
885 Log.w(TAG, "Error deduping shortcuts", ex);
Sunny Goyal0b037782015-04-02 10:27:03 -0700886 }
887 }
888
Adam Cohen091440a2015-03-18 14:16:05 -0700889 @Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700890 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal08f72612015-01-05 13:41:43 -0800891 if (addRankColumn) {
892 // Insert new column for holding rank
893 db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
894 }
895
896 // Get a map for folder ID to folder width
897 Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
898 + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
899 + " GROUP BY container;",
900 new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
901
902 while (c.moveToNext()) {
Sunny Goyalc87775d2015-02-10 19:52:36 -0800903 db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
904 + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
Sunny Goyal08f72612015-01-05 13:41:43 -0800905 new Object[] {c.getLong(1) + 1, c.getLong(0)});
906 }
907
908 c.close();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700909 t.commit();
Sunny Goyal08f72612015-01-05 13:41:43 -0800910 } catch (SQLException ex) {
911 // Old version remains, which means we wipe old data
912 Log.e(TAG, ex.getMessage(), ex);
913 return false;
Sunny Goyal08f72612015-01-05 13:41:43 -0800914 }
915 return true;
916 }
917
Sunny Goyal5d85c442015-03-10 13:14:47 -0700918 private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700919 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700920 db.execSQL("ALTER TABLE favorites ADD COLUMN "
921 + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700922 t.commit();
Kenny Guyed131872014-04-30 03:02:21 +0100923 } catch (SQLException ex) {
Kenny Guyed131872014-04-30 03:02:21 +0100924 Log.e(TAG, ex.getMessage(), ex);
925 return false;
Kenny Guyed131872014-04-30 03:02:21 +0100926 }
927 return true;
928 }
929
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700930 // Generates a new ID to use for an object in your database. This method should be only
931 // called from the main UI thread. As an exception, we do call it when we call the
932 // constructor from the worker thread; however, this doesn't extend until after the
933 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
934 // after that point
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700935 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -0700936 public int generateNewItemId() {
Adam Cohendcd297f2013-06-18 13:13:40 -0700937 if (mMaxItemId < 0) {
938 throw new RuntimeException("Error: max item id was not initialized");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700939 }
Adam Cohendcd297f2013-06-18 13:13:40 -0700940 mMaxItemId += 1;
941 return mMaxItemId;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700942 }
943
Sunny Goyal55fddc82017-04-06 15:02:52 -0700944 public AppWidgetHost newLauncherWidgetHost() {
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700945 return new LauncherAppWidgetHost(mContext);
Sunny Goyal55fddc82017-04-06 15:02:52 -0700946 }
947
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700948 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -0700949 public int insertAndCheck(SQLiteDatabase db, ContentValues values) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700950 return dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, values);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700951 }
952
Sunny Goyalc5939392018-12-07 11:43:47 -0800953 public void checkId(ContentValues values) {
954 int id = values.getAsInteger(Favorites._ID);
955 mMaxItemId = Math.max(id, mMaxItemId);
956
957 Integer screen = values.getAsInteger(Favorites.SCREEN);
958 Integer container = values.getAsInteger(Favorites.CONTAINER);
959 if (screen != null && container != null
960 && container.intValue() == Favorites.CONTAINER_DESKTOP) {
961 mMaxScreenId = Math.max(screen, mMaxScreenId);
Chris Wren5dee7af2013-12-20 17:22:11 -0500962 }
963 }
964
Sunny Goyalefb7e842018-10-04 15:11:00 -0700965 private int initializeMaxItemId(SQLiteDatabase db) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800966 return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s", Favorites._ID, Favorites.TABLE_NAME);
Adam Cohendcd297f2013-06-18 13:13:40 -0700967 }
968
969 // Generates a new ID to use for an workspace screen in your database. This method
970 // should be only called from the main UI thread. As an exception, we do call it when we
971 // call the constructor from the worker thread; however, this doesn't extend until after the
972 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
973 // after that point
Sunny Goyalefb7e842018-10-04 15:11:00 -0700974 public int generateNewScreenId() {
Adam Cohendcd297f2013-06-18 13:13:40 -0700975 if (mMaxScreenId < 0) {
976 throw new RuntimeException("Error: max screen id was not initialized");
977 }
978 mMaxScreenId += 1;
979 return mMaxScreenId;
980 }
981
Sunny Goyalefb7e842018-10-04 15:11:00 -0700982 private int initializeMaxScreenId(SQLiteDatabase db) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800983 return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s WHERE %3$s = %4$d",
984 Favorites.SCREEN, Favorites.TABLE_NAME, Favorites.CONTAINER,
985 Favorites.CONTAINER_DESKTOP);
Adam Cohen7ec3bbf2014-07-31 00:09:45 -0700986 }
987
Adam Cohen091440a2015-03-18 14:16:05 -0700988 @Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700989 // TODO: Use multiple loaders with fall-back and transaction.
Sunny Goyalc5939392018-12-07 11:43:47 -0800990 int count = loader.loadLayout(db, new IntArray());
Adam Cohen71483f42014-05-15 14:04:01 -0700991
992 // Ensure that the max ids are initialized
993 mMaxItemId = initializeMaxItemId(db);
994 mMaxScreenId = initializeMaxScreenId(db);
995 return count;
996 }
Mike Cleronb87bd162009-10-30 16:36:56 -0700997 }
Daniel Lehmannc3a80402012-04-23 21:35:11 -0700998
Sunny Goyalfe4e4b92015-03-04 10:43:45 -0800999 /**
1000 * @return the max _id in the provided table.
1001 */
Sunny Goyalc5939392018-12-07 11:43:47 -08001002 @Thunk static int getMaxId(SQLiteDatabase db, String query, Object... args) {
1003 int max = (int) DatabaseUtils.longForQuery(db,
1004 String.format(Locale.ENGLISH, query, args),
1005 null);
1006 if (max < 0) {
1007 throw new RuntimeException("Error: could not query max id");
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001008 }
Sunny Goyalc5939392018-12-07 11:43:47 -08001009 return max;
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001010 }
1011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 static class SqlArguments {
1013 public final String table;
1014 public final String where;
1015 public final String[] args;
1016
1017 SqlArguments(Uri url, String where, String[] args) {
1018 if (url.getPathSegments().size() == 1) {
1019 this.table = url.getPathSegments().get(0);
1020 this.where = where;
1021 this.args = args;
1022 } else if (url.getPathSegments().size() != 2) {
1023 throw new IllegalArgumentException("Invalid URI: " + url);
1024 } else if (!TextUtils.isEmpty(where)) {
1025 throw new UnsupportedOperationException("WHERE clause not supported: " + url);
1026 } else {
1027 this.table = url.getPathSegments().get(0);
Daniel Lehmannc3a80402012-04-23 21:35:11 -07001028 this.where = "_id=" + ContentUris.parseId(url);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 this.args = null;
1030 }
1031 }
1032
1033 SqlArguments(Uri url) {
1034 if (url.getPathSegments().size() == 1) {
1035 table = url.getPathSegments().get(0);
1036 where = null;
1037 args = null;
1038 } else {
1039 throw new IllegalArgumentException("Invalid URI: " + url);
1040 }
1041 }
1042 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001043
1044 private static class ChangeListenerWrapper implements Handler.Callback {
1045
1046 private static final int MSG_LAUNCHER_PROVIDER_CHANGED = 1;
Sunny Goyalf2dd4212017-09-28 11:31:39 -07001047 private static final int MSG_APP_WIDGET_HOST_RESET = 2;
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001048
1049 private LauncherProviderChangeListener mListener;
1050
1051 @Override
1052 public boolean handleMessage(Message msg) {
1053 if (mListener != null) {
1054 switch (msg.what) {
1055 case MSG_LAUNCHER_PROVIDER_CHANGED:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001056 mListener.onLauncherProviderChanged();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001057 break;
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001058 case MSG_APP_WIDGET_HOST_RESET:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001059 mListener.onAppWidgetHostReset();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001060 break;
1061 }
1062 }
1063 return true;
1064 }
1065 }
Adam Cohen72960972014-01-15 18:13:55 -08001066}