blob: 6ad5c3684ce7ade63a2167b9bc696f616ee8c65c [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 Mirandac7206ca2019-05-13 14:57:50 -0700161 if (!RestoreDbTask.performRestore(getContext(), mOpenHelper,
162 new BackupManager(getContext()))) {
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700163 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
164 }
165 // Set is pending to false irrespective of the result, so that it doesn't get
166 // executed again.
167 RestoreDbTask.setPending(getContext(), false);
168 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700169 }
170 }
171
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 @Override
173 public Cursor query(Uri uri, String[] projection, String selection,
174 String[] selectionArgs, String sortOrder) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700175 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
177 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
178 SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
179 qb.setTables(args.table);
180
Romain Guy73b979d2009-06-09 12:57:21 -0700181 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder);
183 result.setNotificationUri(getContext().getContentResolver(), uri);
184
185 return result;
186 }
187
Sunny Goyalefb7e842018-10-04 15:11:00 -0700188 @Thunk static int dbInsertAndCheck(DatabaseHelper helper,
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700189 SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
Dan Sandlerd5024042014-01-09 15:01:33 -0500190 if (values == null) {
191 throw new RuntimeException("Error: attempting to insert null values");
192 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800193 if (!values.containsKey(LauncherSettings.Favorites._ID)) {
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700194 throw new RuntimeException("Error: attempting to add item without specifying an id");
195 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800196 helper.checkId(values);
Sunny Goyalefb7e842018-10-04 15:11:00 -0700197 return (int) db.insert(table, nullColumnHack, values);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700198 }
199
Sunny Goyald1064182015-08-13 12:08:30 -0700200 private void reloadLauncherIfExternal() {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800201 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyald1064182015-08-13 12:08:30 -0700202 LauncherAppState app = LauncherAppState.getInstanceNoCreate();
203 if (app != null) {
Sunny Goyaldd96a5e2017-02-17 11:22:34 -0800204 app.getModel().forceReload();
Sunny Goyald1064182015-08-13 12:08:30 -0700205 }
206 }
207 }
208
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 @Override
210 public Uri insert(Uri uri, ContentValues initialValues) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700211 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 SqlArguments args = new SqlArguments(uri);
213
Sunny Goyald1064182015-08-13 12:08:30 -0700214 // In very limited cases, we support system|signature permission apps to modify the db.
215 if (Binder.getCallingPid() != Process.myPid()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700216 if (!initializeExternalAdd(initialValues)) {
Adam Cohena043fa82014-07-23 14:49:38 -0700217 return null;
218 }
219 }
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Chris Wren1ada10d2013-09-13 18:01:38 -0400222 addModifiedTime(initialValues);
Sunny Goyalefb7e842018-10-04 15:11:00 -0700223 final int rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
Sunny Goyale72f3d52015-03-02 14:24:21 -0800224 if (rowId < 0) return null;
Sunny Goyal161a2142018-10-29 14:02:20 -0700225 mOpenHelper.onAddOrDeleteOp(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226
227 uri = ContentUris.withAppendedId(uri, rowId);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700228 notifyListeners();
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800229 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230 return uri;
231 }
232
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700233 private boolean initializeExternalAdd(ContentValues values) {
234 // 1. Ensure that externally added items have a valid item id
Sunny Goyalefb7e842018-10-04 15:11:00 -0700235 int id = mOpenHelper.generateNewItemId();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700236 values.put(LauncherSettings.Favorites._ID, id);
237
238 // 2. In the case of an app widget, and if no app widget id is specified, we
239 // attempt allocate and bind the widget.
240 Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
241 if (itemType != null &&
242 itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET &&
243 !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {
244
245 final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
246 ComponentName cn = ComponentName.unflattenFromString(
247 values.getAsString(Favorites.APPWIDGET_PROVIDER));
248
249 if (cn != null) {
250 try {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700251 AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
252 int appWidgetId = widgetHost.allocateAppWidgetId();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700253 values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
254 if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700255 widgetHost.deleteAppWidgetId(appWidgetId);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700256 return false;
257 }
258 } catch (RuntimeException e) {
259 Log.e(TAG, "Failed to initialize external widget", e);
260 return false;
261 }
262 } else {
263 return false;
264 }
265 }
266
Sunny Goyalc5939392018-12-07 11:43:47 -0800267 return true;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700268 }
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 @Override
271 public int bulkInsert(Uri uri, ContentValues[] values) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700272 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 SqlArguments args = new SqlArguments(uri);
274
275 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700276 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 int numValues = values.length;
278 for (int i = 0; i < numValues; i++) {
Chris Wren1ada10d2013-09-13 18:01:38 -0400279 addModifiedTime(values[i]);
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700280 if (dbInsertAndCheck(mOpenHelper, db, args.table, null, values[i]) < 0) {
281 return 0;
282 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700284 mOpenHelper.onAddOrDeleteOp(db);
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700285 t.commit();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 }
287
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700288 notifyListeners();
Sunny Goyald1064182015-08-13 12:08:30 -0700289 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290 return values.length;
291 }
292
Sunny Goyal161a2142018-10-29 14:02:20 -0700293 @TargetApi(Build.VERSION_CODES.M)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 @Override
Yura085c8532014-02-11 15:15:29 +0000295 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
296 throws OperationApplicationException {
Sunny Goyald3849d12015-10-29 10:28:32 -0700297 createDbIfNotExists();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700298 try (SQLiteTransaction t = new SQLiteTransaction(mOpenHelper.getWritableDatabase())) {
Sunny Goyal8c48d8b2019-01-25 15:10:18 -0800299 boolean isAddOrDelete = false;
Sunny Goyal161a2142018-10-29 14:02:20 -0700300
301 final int numOperations = operations.size();
302 final ContentProviderResult[] results = new ContentProviderResult[numOperations];
303 for (int i = 0; i < numOperations; i++) {
304 ContentProviderOperation op = operations.get(i);
305 results[i] = op.apply(this, results, i);
306
307 isAddOrDelete |= (op.isInsert() || op.isDelete()) &&
308 results[i].count != null && results[i].count > 0;
309 }
310 if (isAddOrDelete) {
311 mOpenHelper.onAddOrDeleteOp(t.getDb());
312 }
313
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700314 t.commit();
Sunny Goyald1064182015-08-13 12:08:30 -0700315 reloadLauncherIfExternal();
Sunny Goyal161a2142018-10-29 14:02:20 -0700316 return results;
Yura085c8532014-02-11 15:15:29 +0000317 }
318 }
319
320 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 public int delete(Uri uri, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700322 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800323 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
324
325 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800326
Louis Begina9c21c62016-08-15 15:18:41 -0700327 if (Binder.getCallingPid() != Process.myPid()
328 && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700329 mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
Louis Begina9c21c62016-08-15 15:18:41 -0700330 }
331 int count = db.delete(args.table, args.where, args.args);
332 if (count > 0) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700333 mOpenHelper.onAddOrDeleteOp(db);
Louis Begina9c21c62016-08-15 15:18:41 -0700334 notifyListeners();
335 reloadLauncherIfExternal();
336 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800337 return count;
338 }
339
340 @Override
341 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Sunny Goyald3849d12015-10-29 10:28:32 -0700342 createDbIfNotExists();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
344
Chris Wren1ada10d2013-09-13 18:01:38 -0400345 addModifiedTime(values);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800346 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
347 int count = db.update(args.table, values, args.where, args.args);
Sunny Goyal1d4a2df2015-03-30 11:11:46 -0700348 if (count > 0) notifyListeners();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800349
Sunny Goyald1064182015-08-13 12:08:30 -0700350 reloadLauncherIfExternal();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351 return count;
352 }
353
Sunny Goyal7779d622015-06-11 16:18:39 -0700354 @Override
Tony Wickham827cef22016-03-17 15:39:39 -0700355 public Bundle call(String method, final String arg, final Bundle extras) {
Sunny Goyal7779d622015-06-11 16:18:39 -0700356 if (Binder.getCallingUid() != Process.myUid()) {
357 return null;
358 }
Sunny Goyald3849d12015-10-29 10:28:32 -0700359 createDbIfNotExists();
Sunny Goyal7779d622015-06-11 16:18:39 -0700360
361 switch (method) {
Sunny Goyald2497482015-09-22 18:24:19 -0700362 case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
363 clearFlagEmptyDbCreated();
364 return null;
365 }
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700366 case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : {
367 Bundle result = new Bundle();
368 result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
369 Utilities.getPrefs(getContext()).getBoolean(EMPTY_DATABASE_CREATED, false));
370 return result;
371 }
Sunny Goyald2497482015-09-22 18:24:19 -0700372 case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
373 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700374 result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders()
375 .toArray());
Sunny Goyald2497482015-09-22 18:24:19 -0700376 return result;
377 }
378 case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
379 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700380 result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId());
Sunny Goyald2497482015-09-22 18:24:19 -0700381 return result;
382 }
383 case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
384 Bundle result = new Bundle();
Sunny Goyalefb7e842018-10-04 15:11:00 -0700385 result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId());
Sunny Goyald2497482015-09-22 18:24:19 -0700386 return result;
387 }
388 case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
Sunny Goyale05b08f2017-02-23 18:30:22 -0800389 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyald2497482015-09-22 18:24:19 -0700390 return null;
391 }
392 case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
393 loadDefaultFavoritesIfNecessary();
394 return null;
395 }
Sunny Goyal55fddc82017-04-06 15:02:52 -0700396 case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: {
397 mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
398 return null;
399 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700400 case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: {
401 Bundle result = new Bundle();
402 result.putBinder(LauncherSettings.Settings.EXTRA_VALUE,
403 new SQLiteTransaction(mOpenHelper.getWritableDatabase()));
404 return result;
405 }
406 case LauncherSettings.Settings.METHOD_REFRESH_BACKUP_TABLE: {
407 mOpenHelper.mBackupTableExists =
408 tableExists(mOpenHelper.getReadableDatabase(), Favorites.BACKUP_TABLE_NAME);
409 return null;
410 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700411 }
412 return null;
413 }
414
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700415 /**
416 * Deletes any empty folder from the DB.
417 * @return Ids of deleted folders.
418 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700419 private IntArray deleteEmptyFolders() {
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700420 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700421 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700422 // Select folders whose id do not match any container value.
423 String selection = LauncherSettings.Favorites.ITEM_TYPE + " = "
424 + LauncherSettings.Favorites.ITEM_TYPE_FOLDER + " AND "
425 + LauncherSettings.Favorites._ID + " NOT IN (SELECT " +
426 LauncherSettings.Favorites.CONTAINER + " FROM "
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700427 + Favorites.TABLE_NAME + ")";
Sunny Goyalc5939392018-12-07 11:43:47 -0800428
429 IntArray folderIds = LauncherDbUtils.queryIntArray(db, Favorites.TABLE_NAME,
430 Favorites._ID, selection, null, null);
Sunny Goyald2497482015-09-22 18:24:19 -0700431 if (!folderIds.isEmpty()) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700432 db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery(
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700433 LauncherSettings.Favorites._ID, folderIds), null);
434 }
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700435 t.commit();
Sunny Goyalc5939392018-12-07 11:43:47 -0800436 return folderIds;
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700437 } catch (SQLException ex) {
438 Log.e(TAG, ex.getMessage(), ex);
Sunny Goyalc5939392018-12-07 11:43:47 -0800439 return new IntArray();
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700440 }
Sunny Goyalb1622cc2015-06-10 16:00:42 -0700441 }
442
Sunny Goyalf076eae2016-01-11 12:25:10 -0800443 /**
444 * Overridden in tests
445 */
446 protected void notifyListeners() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700447 mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_LAUNCHER_PROVIDER_CHANGED);
Chris Wren1ada10d2013-09-13 18:01:38 -0400448 }
449
Adam Cohen091440a2015-03-18 14:16:05 -0700450 @Thunk static void addModifiedTime(ContentValues values) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800451 values.put(LauncherSettings.Favorites.MODIFIED, System.currentTimeMillis());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 }
453
Sunny Goyald2497482015-09-22 18:24:19 -0700454 private void clearFlagEmptyDbCreated() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700455 Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
Sunny Goyal33d44382014-10-16 09:24:19 -0700456 }
457
Sunny Goyal42de82f2014-09-26 22:09:29 -0700458 /**
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700459 * Loads the default workspace based on the following priority scheme:
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700460 * 1) From the app restrictions
461 * 2) From a package provided by play store
462 * 3) From a partner configuration APK, already in the system image
463 * 4) The default configuration for the particular device
Brian Muramatsu5524b492012-10-02 16:55:54 -0700464 */
Sunny Goyald2497482015-09-22 18:24:19 -0700465 synchronized private void loadDefaultFavoritesIfNecessary() {
Sunny Goyalf7258242015-10-19 16:59:07 -0700466 SharedPreferences sp = Utilities.getPrefs(getContext());
Adam Cohene25af792013-06-06 23:08:25 -0700467
Winson Chungc763c4e2013-07-19 13:49:06 -0700468 if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Chris Wren5dee7af2013-12-20 17:22:11 -0500469 Log.d(TAG, "loading default workspace");
Michael Jurka45355c42012-10-08 13:21:35 +0200470
Sunny Goyal55fddc82017-04-06 15:02:52 -0700471 AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700472 AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction(widgetHost);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700473 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700474 loader = AutoInstallsLayout.get(getContext(),widgetHost, mOpenHelper);
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700475 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700476 if (loader == null) {
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700477 final Partner partner = Partner.get(getContext().getPackageManager());
478 if (partner != null && partner.hasDefaultLayout()) {
479 final Resources partnerRes = partner.getResources();
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700480 int workspaceResId = partnerRes.getIdentifier(Partner.RES_DEFAULT_LAYOUT,
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700481 "xml", partner.getPackageName());
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700482 if (workspaceResId != 0) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700483 loader = new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal3a5a9d12014-10-01 15:33:41 -0700484 mOpenHelper, partnerRes, workspaceResId);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700485 }
Adam Cohen9b8f51f2014-05-30 15:34:09 -0700486 }
487 }
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700488
Sunny Goyal9d219682014-10-23 14:21:02 -0700489 final boolean usingExternallyProvidedLayout = loader != null;
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700490 if (loader == null) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700491 loader = getDefaultLayoutParser(widgetHost);
Brian Muramatsu5524b492012-10-02 16:55:54 -0700492 }
Sunny Goyalc6c8fef2015-03-04 09:51:18 -0800493
494 // There might be some partially restored DB items, due to buggy restore logic in
495 // previous versions of launcher.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800496 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Michael Jurkab85f8a42012-04-25 15:48:32 -0700497 // Populate favorites table with initial favorites
Sunny Goyal9d219682014-10-23 14:21:02 -0700498 if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0)
499 && usingExternallyProvidedLayout) {
500 // Unable to load external layout. Cleanup and load the internal layout.
Sunny Goyale05b08f2017-02-23 18:30:22 -0800501 mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
Sunny Goyal9d219682014-10-23 14:21:02 -0700502 mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(),
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700503 getDefaultLayoutParser(widgetHost));
Sunny Goyal9d219682014-10-23 14:21:02 -0700504 }
Sunny Goyal33d44382014-10-16 09:24:19 -0700505 clearFlagEmptyDbCreated();
Michael Jurkab85f8a42012-04-25 15:48:32 -0700506 }
507 }
508
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700509 /**
510 * Creates workspace loader from an XML resource listed in the app restrictions.
511 *
512 * @return the loader if the restrictions are set and the resource exists; null otherwise.
513 */
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700514 private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700515 Context ctx = getContext();
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700516 InvariantDeviceProfile grid = LauncherAppState.getIDP(ctx);
517
518 String authority = Settings.Secure.getString(ctx.getContentResolver(),
519 "launcher3.layout.provider");
520 if (TextUtils.isEmpty(authority)) {
Sunny Goyal35ca8732015-04-06 10:45:31 -0700521 return null;
522 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700523
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700524 ProviderInfo pi = ctx.getPackageManager().resolveContentProvider(authority, 0);
525 if (pi == null) {
526 Log.e(TAG, "No provider found for authority " + authority);
527 return null;
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700528 }
Sunny Goyalc0f03d92019-03-22 14:13:36 -0700529 Uri uri = new Uri.Builder().scheme("content").authority(authority).path("launcher_layout")
530 .appendQueryParameter("version", "1")
531 .appendQueryParameter("gridWidth", Integer.toString(grid.numColumns))
532 .appendQueryParameter("gridHeight", Integer.toString(grid.numRows))
533 .appendQueryParameter("hotseatSize", Integer.toString(grid.numHotseatIcons))
534 .build();
535
536 try (InputStream in = ctx.getContentResolver().openInputStream(uri)) {
537 // Read the full xml so that we fail early in case of any IO error.
538 String layout = new String(IOUtils.toByteArray(in));
539 XmlPullParser parser = Xml.newPullParser();
540 parser.setInput(new StringReader(layout));
541
542 Log.d(TAG, "Loading layout from " + authority);
543 return new AutoInstallsLayout(ctx, widgetHost, mOpenHelper,
544 ctx.getPackageManager().getResourcesForApplication(pi.applicationInfo),
545 () -> parser, AutoInstallsLayout.TAG_WORKSPACE);
546 } catch (Exception e) {
547 Log.e(TAG, "Error getting layout stream from: " + authority , e);
548 return null;
549 }
Sunny Goyalb2d46ce2015-03-26 11:32:11 -0700550 }
551
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700552 private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) {
Adam Cohen27824492017-09-22 17:10:55 -0700553 InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext());
554 int defaultLayout = idp.defaultLayoutId;
555
556 UserManagerCompat um = UserManagerCompat.getInstance(getContext());
557 if (um.isDemoUser() && idp.demoModeLayoutId != 0) {
558 defaultLayout = idp.demoModeLayoutId;
559 }
560
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700561 return new DefaultLayoutParser(getContext(), widgetHost,
Sunny Goyal9d219682014-10-23 14:21:02 -0700562 mOpenHelper, getContext().getResources(), defaultLayout);
563 }
564
Sunny Goyald3849d12015-10-29 10:28:32 -0700565 /**
Sunny Goyalf076eae2016-01-11 12:25:10 -0800566 * The class is subclassed in tests to create an in-memory db.
567 */
Sunny Goyal19026b22018-03-09 14:37:37 -0800568 public static class DatabaseHelper extends NoLocaleSQLiteHelper implements LayoutParserCallback {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800569 private final BackupManager mBackupManager;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700570 private final Handler mWidgetHostResetHandler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 private final Context mContext;
Sunny Goyalefb7e842018-10-04 15:11:00 -0700572 private int mMaxItemId = -1;
573 private int mMaxScreenId = -1;
Sunny Goyal161a2142018-10-29 14:02:20 -0700574 private boolean mBackupTableExists;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700576 DatabaseHelper(Context context, Handler widgetHostResetHandler) {
577 this(context, widgetHostResetHandler, LauncherFiles.LAUNCHER_DB);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700578 // Table creation sometimes fails silently, which leads to a crash loop.
579 // This way, we will try to create a table every time after crash, so the device
580 // would eventually be able to recover.
Sunny Goyal161a2142018-10-29 14:02:20 -0700581 if (!tableExists(getReadableDatabase(), Favorites.TABLE_NAME)) {
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700582 Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
583 // This operation is a no-op if the table already exists.
584 addFavoritesTable(getWritableDatabase(), true);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700585 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700586 mBackupTableExists = tableExists(getReadableDatabase(), Favorites.BACKUP_TABLE_NAME);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700587
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700588 initIds();
589 }
590
591 /**
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700592 * Constructor used in tests and for restore.
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700593 */
594 public DatabaseHelper(
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700595 Context context, Handler widgetHostResetHandler, String tableName) {
Sunny Goyal19026b22018-03-09 14:37:37 -0800596 super(context, tableName, SCHEMA_VERSION);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700597 mContext = context;
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700598 mWidgetHostResetHandler = widgetHostResetHandler;
Jon Miranda2bc6b932019-03-07 15:24:46 -0800599 mBackupManager = new BackupManager(mContext);
Sunny Goyal7eab3cc2016-03-18 17:42:55 -0700600 }
601
602 protected void initIds() {
Winson Chung3d503fb2011-07-13 17:25:49 -0700603 // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
604 // the DB here
Adam Cohendcd297f2013-06-18 13:13:40 -0700605 if (mMaxItemId == -1) {
606 mMaxItemId = initializeMaxItemId(getWritableDatabase());
607 }
608 if (mMaxScreenId == -1) {
609 mMaxScreenId = initializeMaxScreenId(getWritableDatabase());
Winson Chung3d503fb2011-07-13 17:25:49 -0700610 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800611 }
612
613 @Override
614 public void onCreate(SQLiteDatabase db) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800615 if (LOGD) Log.d(TAG, "creating new launcher database");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700616
Adam Cohendcd297f2013-06-18 13:13:40 -0700617 mMaxItemId = 1;
618 mMaxScreenId = 0;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700619
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700620 addFavoritesTable(db, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800621
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800622 // Fresh and clean launcher DB.
623 mMaxItemId = initializeMaxItemId(db);
Sunny Goyalf076eae2016-01-11 12:25:10 -0800624 onEmptyDbCreated();
625 }
626
Sunny Goyal161a2142018-10-29 14:02:20 -0700627 protected void onAddOrDeleteOp(SQLiteDatabase db) {
628 if (mBackupTableExists) {
629 dropTable(db, Favorites.BACKUP_TABLE_NAME);
630 mBackupTableExists = false;
631 }
632 }
633
Sunny Goyalf076eae2016-01-11 12:25:10 -0800634 /**
635 * Overriden in tests.
636 */
637 protected void onEmptyDbCreated() {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700638 // Database was just created, so wipe any previous widgets
639 if (mWidgetHostResetHandler != null) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700640 newLauncherWidgetHost().deleteHost();
Sunny Goyal2e013ea2016-10-07 16:17:19 -0700641 mWidgetHostResetHandler.sendEmptyMessage(
Sunny Goyal72db9af2016-11-29 07:25:49 +0530642 ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET);
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700643 }
644
Sunny Goyalf076eae2016-01-11 12:25:10 -0800645 // Set the flag for empty DB
646 Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
Sunny Goyalf076eae2016-01-11 12:25:10 -0800647 }
648
Jon Miranda2bc6b932019-03-07 15:24:46 -0800649 public long getSerialNumberForUser(UserHandle user) {
650 return UserManagerCompat.getInstance(mContext).getSerialNumberForUser(user);
651 }
652
Sunny Goyale8f7d5a2016-05-24 11:30:14 -0700653 public long getDefaultUserSerial() {
Jon Miranda2bc6b932019-03-07 15:24:46 -0800654 return getSerialNumberForUser(Process.myUserHandle());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 }
656
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700657 private void addFavoritesTable(SQLiteDatabase db, boolean optional) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700658 Favorites.addTableToDb(db, getDefaultUserSerial(), optional);
Sunny Goyal6fb929e2015-09-23 11:40:53 -0700659 }
660
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 @Override
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700662 public void onOpen(SQLiteDatabase db) {
663 super.onOpen(db);
Sunny Goyal05f30882017-05-03 12:42:18 -0700664
665 File schemaFile = mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE);
666 if (!schemaFile.exists()) {
667 handleOneTimeDataUpgrade(db);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700668 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800669 DbDowngradeHelper.updateSchemaFile(schemaFile, SCHEMA_VERSION, mContext);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700670 }
671
672 /**
Sunny Goyal05f30882017-05-03 12:42:18 -0700673 * One-time data updated before support of onDowngrade was added. This update is backwards
674 * compatible and can safely be run multiple times.
675 * Note: No new logic should be added here after release, as the new logic might not get
676 * executed on an existing device.
677 * TODO: Move this to db upgrade path, once the downgrade path is released.
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700678 */
Sunny Goyal05f30882017-05-03 12:42:18 -0700679 protected void handleOneTimeDataUpgrade(SQLiteDatabase db) {
680 // Remove "profile extra"
681 UserManagerCompat um = UserManagerCompat.getInstance(mContext);
682 for (UserHandle user : um.getUserProfiles()) {
683 long serial = um.getSerialNumberForUser(user);
684 String sql = "update favorites set intent = replace(intent, "
685 + "';l.profile=" + serial + ";', ';') where itemType = 0;";
686 db.execSQL(sql);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700687 }
688 }
689
690 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800691 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Winson Chungc763c4e2013-07-19 13:49:06 -0700692 if (LOGD) Log.d(TAG, "onUpgrade triggered: " + oldVersion);
Sunny Goyala2cc6242015-01-14 14:23:02 -0800693 switch (oldVersion) {
694 // The version cannot be lower that 12, as Launcher3 never supported a lower
Sunny Goyale87e6ab2014-11-21 22:42:53 -0800695 // version of the DB.
Sunny Goyalc5939392018-12-07 11:43:47 -0800696 case 12:
697 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800698 case 13: {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700699 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800700 // Insert new column for holding widget provider name
701 db.execSQL("ALTER TABLE favorites " +
702 "ADD COLUMN appWidgetProvider TEXT;");
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700703 t.commit();
Sunny Goyala2cc6242015-01-14 14:23:02 -0800704 } catch (SQLException ex) {
705 Log.e(TAG, ex.getMessage(), ex);
706 // Old version remains, which means we wipe old data
707 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800708 }
709 }
710 case 14: {
Sunny Goyalc5939392018-12-07 11:43:47 -0800711 if (!addIntegerColumn(db, Favorites.MODIFIED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800712 // Old version remains, which means we wipe old data
713 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800714 }
715 }
716 case 15: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700717 if (!addIntegerColumn(db, Favorites.RESTORED, 0)) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800718 // Old version remains, which means we wipe old data
719 break;
Sunny Goyala2cc6242015-01-14 14:23:02 -0800720 }
721 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800722 case 16:
Sunny Goyal10629b02016-09-01 12:50:11 -0700723 // No-op
Sunny Goyalc5939392018-12-07 11:43:47 -0800724 case 17:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800725 // No-op
Sunny Goyalc5939392018-12-07 11:43:47 -0800726 case 18:
727 // No-op
Sunny Goyala2cc6242015-01-14 14:23:02 -0800728 case 19: {
729 // Add userId column
Sunny Goyalc5939392018-12-07 11:43:47 -0800730 if (!addIntegerColumn(db, Favorites.PROFILE_ID, getDefaultUserSerial())) {
Sunny Goyala2cc6242015-01-14 14:23:02 -0800731 // Old version remains, which means we wipe old data
732 break;
733 }
734 }
735 case 20:
736 if (!updateFolderItemsRank(db, true)) {
737 break;
738 }
Sunny Goyald2f38192015-02-25 10:46:34 -0800739 case 21:
Sunny Goyalc5939392018-12-07 11:43:47 -0800740 // No-op
Sunny Goyald2f38192015-02-25 10:46:34 -0800741 case 22: {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700742 if (!addIntegerColumn(db, Favorites.OPTIONS, 0)) {
743 // Old version remains, which means we wipe old data
744 break;
745 }
746 }
Sunny Goyal0b037782015-04-02 10:27:03 -0700747 case 23:
Sunny Goyal5c97f512015-05-19 16:03:28 -0700748 // No-op
Sunny Goyale2fba6c2015-05-12 10:39:59 -0700749 case 24:
Tony Mak1b6826c2018-02-27 15:06:12 +0000750 // No-op
Sunny Goyal5c97f512015-05-19 16:03:28 -0700751 case 25:
752 convertShortcutsToLauncherActivities(db);
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700753 case 26:
754 // QSB was moved to the grid. Clear the first row on screen 0.
Jon Miranda7143ba62019-03-15 09:00:05 -0700755 if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
Sunny Goyal8ad02b82016-12-29 13:31:43 -0800756 !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) {
Sunny Goyala9e2f5a2016-06-10 12:22:04 -0700757 break;
758 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800759 case 27: {
760 // Update the favorites table so that the screen ids are ordered based on
761 // workspace page rank.
762 IntArray finalScreens = LauncherDbUtils.queryIntArray(db, "workspaceScreens",
763 BaseColumns._ID, null, null, "screenRank");
764 int[] original = finalScreens.toArray();
765 Arrays.sort(original);
766 String updatemap = "";
767 for (int i = 0; i < original.length; i++) {
768 if (finalScreens.get(i) != original[i]) {
769 updatemap += String.format(Locale.ENGLISH, " WHEN %1$s=%2$d THEN %3$d",
770 Favorites.SCREEN, finalScreens.get(i), original[i]);
771 }
772 }
773 if (!TextUtils.isEmpty(updatemap)) {
774 String query = String.format(Locale.ENGLISH,
775 "UPDATE %1$s SET %2$s=CASE %3$s ELSE %2$s END WHERE %4$s = %5$d",
776 Favorites.TABLE_NAME, Favorites.SCREEN, updatemap,
777 Favorites.CONTAINER, Favorites.CONTAINER_DESKTOP);
778 db.execSQL(query);
779 }
Sunny Goyal161a2142018-10-29 14:02:20 -0700780 dropTable(db, "workspaceScreens");
Sunny Goyalc5939392018-12-07 11:43:47 -0800781 }
782 case 28:
Sunny Goyala2cc6242015-01-14 14:23:02 -0800783 // DB Upgraded successfully
784 return;
Chris Wrend5e66bf2013-09-16 14:02:29 -0400785 }
786
Sunny Goyala2cc6242015-01-14 14:23:02 -0800787 // DB was not upgraded
788 Log.w(TAG, "Destroying all old data.");
789 createEmptyDB(db);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800790 }
Romain Guy7eb9e5e2009-12-02 20:10:07 -0800791
Adam Cohen9b1d0622014-05-21 19:01:57 -0700792 @Override
793 public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Sunny Goyal05f30882017-05-03 12:42:18 -0700794 try {
795 DbDowngradeHelper.parse(mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE))
796 .onDowngrade(db, oldVersion, newVersion);
797 } catch (Exception e) {
798 Log.d(TAG, "Unable to downgrade from: " + oldVersion + " to " + newVersion +
799 ". Wiping databse.", e);
800 createEmptyDB(db);
Sunny Goyal3c7d55b2017-04-13 12:01:47 -0700801 }
Sunny Goyal42de82f2014-09-26 22:09:29 -0700802 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700803
Sunny Goyal42de82f2014-09-26 22:09:29 -0700804 /**
805 * Clears all the data for a fresh start.
806 */
807 public void createEmptyDB(SQLiteDatabase db) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700808 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700809 dropTable(db, Favorites.TABLE_NAME);
810 dropTable(db, "workspaceScreens");
Sunny Goyale05b08f2017-02-23 18:30:22 -0800811 onCreate(db);
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700812 t.commit();
Sunny Goyale05b08f2017-02-23 18:30:22 -0800813 }
Adam Cohen9b1d0622014-05-21 19:01:57 -0700814 }
815
Sunny Goyald2f38192015-02-25 10:46:34 -0800816 /**
Sunny Goyal55fddc82017-04-06 15:02:52 -0700817 * Removes widgets which are registered to the Launcher's host, but are not present
818 * in our model.
819 */
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700820 @TargetApi(Build.VERSION_CODES.O)
Sunny Goyal55fddc82017-04-06 15:02:52 -0700821 public void removeGhostWidgets(SQLiteDatabase db) {
822 // Get all existing widget ids.
823 final AppWidgetHost host = newLauncherWidgetHost();
824 final int[] allWidgets;
825 try {
Sunny Goyal22ca9ec2017-05-18 15:03:13 -0700826 // Although the method was defined in O, it has existed since the beginning of time,
827 // so it might work on older platforms as well.
828 allWidgets = host.getAppWidgetIds();
829 } catch (IncompatibleClassChangeError e) {
Sunny Goyal55fddc82017-04-06 15:02:52 -0700830 Log.e(TAG, "getAppWidgetIds not supported", e);
831 return;
832 }
Sunny Goyalc5939392018-12-07 11:43:47 -0800833 final IntSet validWidgets = IntSet.wrap(LauncherDbUtils.queryIntArray(db,
834 Favorites.TABLE_NAME, Favorites.APPWIDGET_ID,
835 "itemType=" + Favorites.ITEM_TYPE_APPWIDGET, null, null));
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700836 for (int widgetId : allWidgets) {
837 if (!validWidgets.contains(widgetId)) {
838 try {
839 FileLog.d(TAG, "Deleting invalid widget " + widgetId);
840 host.deleteAppWidgetId(widgetId);
841 } catch (RuntimeException e) {
842 // Ignore
843 }
844 }
Sunny Goyal55fddc82017-04-06 15:02:52 -0700845 }
846 }
847
848 /**
Sunny Goyal0b037782015-04-02 10:27:03 -0700849 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
850 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
851 */
Sunny Goyal316490e2015-06-02 09:38:28 -0700852 @Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700853 try (SQLiteTransaction t = new SQLiteTransaction(db);
854 // Only consider the primary user as other users can't have a shortcut.
855 Cursor c = db.query(Favorites.TABLE_NAME,
856 new String[] { Favorites._ID, Favorites.INTENT},
857 "itemType=" + Favorites.ITEM_TYPE_SHORTCUT +
858 " AND profileId=" + getDefaultUserSerial(),
859 null, null, null, null);
860 SQLiteStatement updateStmt = db.compileStatement("UPDATE favorites SET itemType="
861 + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?")
862 ) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700863 final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
864 final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);
865
866 while (c.moveToNext()) {
867 String intentDescription = c.getString(intentIndex);
868 Intent intent;
869 try {
870 intent = Intent.parseUri(intentDescription, 0);
871 } catch (URISyntaxException e) {
872 Log.e(TAG, "Unable to parse intent", e);
873 continue;
874 }
875
Sunny Goyal4e5cc642015-06-25 16:37:44 -0700876 if (!Utilities.isLauncherAppTarget(intent)) {
Sunny Goyal0b037782015-04-02 10:27:03 -0700877 continue;
878 }
879
Sunny Goyalefb7e842018-10-04 15:11:00 -0700880 int id = c.getInt(idIndex);
Sunny Goyal0b037782015-04-02 10:27:03 -0700881 updateStmt.bindLong(1, id);
Sunny Goyalc22841b2015-07-13 19:59:50 -0700882 updateStmt.executeUpdateDelete();
Sunny Goyal0b037782015-04-02 10:27:03 -0700883 }
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700884 t.commit();
Sunny Goyal0b037782015-04-02 10:27:03 -0700885 } catch (SQLException ex) {
886 Log.w(TAG, "Error deduping shortcuts", ex);
Sunny Goyal0b037782015-04-02 10:27:03 -0700887 }
888 }
889
Adam Cohen091440a2015-03-18 14:16:05 -0700890 @Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700891 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal08f72612015-01-05 13:41:43 -0800892 if (addRankColumn) {
893 // Insert new column for holding rank
894 db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
895 }
896
897 // Get a map for folder ID to folder width
898 Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
899 + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
900 + " GROUP BY container;",
901 new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
902
903 while (c.moveToNext()) {
Sunny Goyalc87775d2015-02-10 19:52:36 -0800904 db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
905 + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
Sunny Goyal08f72612015-01-05 13:41:43 -0800906 new Object[] {c.getLong(1) + 1, c.getLong(0)});
907 }
908
909 c.close();
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700910 t.commit();
Sunny Goyal08f72612015-01-05 13:41:43 -0800911 } catch (SQLException ex) {
912 // Old version remains, which means we wipe old data
913 Log.e(TAG, ex.getMessage(), ex);
914 return false;
Sunny Goyal08f72612015-01-05 13:41:43 -0800915 }
916 return true;
917 }
918
Sunny Goyal5d85c442015-03-10 13:14:47 -0700919 private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700920 try (SQLiteTransaction t = new SQLiteTransaction(db)) {
Sunny Goyal5d85c442015-03-10 13:14:47 -0700921 db.execSQL("ALTER TABLE favorites ADD COLUMN "
922 + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
Sunny Goyaldbfc9012017-04-17 16:58:36 -0700923 t.commit();
Kenny Guyed131872014-04-30 03:02:21 +0100924 } catch (SQLException ex) {
Kenny Guyed131872014-04-30 03:02:21 +0100925 Log.e(TAG, ex.getMessage(), ex);
926 return false;
Kenny Guyed131872014-04-30 03:02:21 +0100927 }
928 return true;
929 }
930
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700931 // Generates a new ID to use for an object in your database. This method should be only
932 // called from the main UI thread. As an exception, we do call it when we call the
933 // constructor from the worker thread; however, this doesn't extend until after the
934 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
935 // after that point
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700936 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -0700937 public int generateNewItemId() {
Adam Cohendcd297f2013-06-18 13:13:40 -0700938 if (mMaxItemId < 0) {
939 throw new RuntimeException("Error: max item id was not initialized");
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700940 }
Adam Cohendcd297f2013-06-18 13:13:40 -0700941 mMaxItemId += 1;
942 return mMaxItemId;
Michael Jurkaa8c760d2011-04-28 14:59:33 -0700943 }
944
Sunny Goyal55fddc82017-04-06 15:02:52 -0700945 public AppWidgetHost newLauncherWidgetHost() {
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700946 return new LauncherAppWidgetHost(mContext);
Sunny Goyal55fddc82017-04-06 15:02:52 -0700947 }
948
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700949 @Override
Sunny Goyalefb7e842018-10-04 15:11:00 -0700950 public int insertAndCheck(SQLiteDatabase db, ContentValues values) {
Sunny Goyalb5b55c82016-05-10 12:28:59 -0700951 return dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, values);
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700952 }
953
Sunny Goyalc5939392018-12-07 11:43:47 -0800954 public void checkId(ContentValues values) {
955 int id = values.getAsInteger(Favorites._ID);
956 mMaxItemId = Math.max(id, mMaxItemId);
957
958 Integer screen = values.getAsInteger(Favorites.SCREEN);
959 Integer container = values.getAsInteger(Favorites.CONTAINER);
960 if (screen != null && container != null
961 && container.intValue() == Favorites.CONTAINER_DESKTOP) {
962 mMaxScreenId = Math.max(screen, mMaxScreenId);
Chris Wren5dee7af2013-12-20 17:22:11 -0500963 }
964 }
965
Sunny Goyalefb7e842018-10-04 15:11:00 -0700966 private int initializeMaxItemId(SQLiteDatabase db) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800967 return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s", Favorites._ID, Favorites.TABLE_NAME);
Adam Cohendcd297f2013-06-18 13:13:40 -0700968 }
969
970 // Generates a new ID to use for an workspace screen in your database. This method
971 // should be only called from the main UI thread. As an exception, we do call it when we
972 // call the constructor from the worker thread; however, this doesn't extend until after the
973 // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
974 // after that point
Sunny Goyalefb7e842018-10-04 15:11:00 -0700975 public int generateNewScreenId() {
Adam Cohendcd297f2013-06-18 13:13:40 -0700976 if (mMaxScreenId < 0) {
977 throw new RuntimeException("Error: max screen id was not initialized");
978 }
979 mMaxScreenId += 1;
980 return mMaxScreenId;
981 }
982
Sunny Goyalefb7e842018-10-04 15:11:00 -0700983 private int initializeMaxScreenId(SQLiteDatabase db) {
Sunny Goyalc5939392018-12-07 11:43:47 -0800984 return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s WHERE %3$s = %4$d",
985 Favorites.SCREEN, Favorites.TABLE_NAME, Favorites.CONTAINER,
986 Favorites.CONTAINER_DESKTOP);
Adam Cohen7ec3bbf2014-07-31 00:09:45 -0700987 }
988
Adam Cohen091440a2015-03-18 14:16:05 -0700989 @Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
Sunny Goyal0fe505b2014-08-06 09:55:36 -0700990 // TODO: Use multiple loaders with fall-back and transaction.
Sunny Goyalc5939392018-12-07 11:43:47 -0800991 int count = loader.loadLayout(db, new IntArray());
Adam Cohen71483f42014-05-15 14:04:01 -0700992
993 // Ensure that the max ids are initialized
994 mMaxItemId = initializeMaxItemId(db);
995 mMaxScreenId = initializeMaxScreenId(db);
996 return count;
997 }
Mike Cleronb87bd162009-10-30 16:36:56 -0700998 }
Daniel Lehmannc3a80402012-04-23 21:35:11 -0700999
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001000 /**
1001 * @return the max _id in the provided table.
1002 */
Sunny Goyalc5939392018-12-07 11:43:47 -08001003 @Thunk static int getMaxId(SQLiteDatabase db, String query, Object... args) {
1004 int max = (int) DatabaseUtils.longForQuery(db,
1005 String.format(Locale.ENGLISH, query, args),
1006 null);
1007 if (max < 0) {
1008 throw new RuntimeException("Error: could not query max id");
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001009 }
Sunny Goyalc5939392018-12-07 11:43:47 -08001010 return max;
Sunny Goyalfe4e4b92015-03-04 10:43:45 -08001011 }
1012
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001013 static class SqlArguments {
1014 public final String table;
1015 public final String where;
1016 public final String[] args;
1017
1018 SqlArguments(Uri url, String where, String[] args) {
1019 if (url.getPathSegments().size() == 1) {
1020 this.table = url.getPathSegments().get(0);
1021 this.where = where;
1022 this.args = args;
1023 } else if (url.getPathSegments().size() != 2) {
1024 throw new IllegalArgumentException("Invalid URI: " + url);
1025 } else if (!TextUtils.isEmpty(where)) {
1026 throw new UnsupportedOperationException("WHERE clause not supported: " + url);
1027 } else {
1028 this.table = url.getPathSegments().get(0);
Daniel Lehmannc3a80402012-04-23 21:35:11 -07001029 this.where = "_id=" + ContentUris.parseId(url);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 this.args = null;
1031 }
1032 }
1033
1034 SqlArguments(Uri url) {
1035 if (url.getPathSegments().size() == 1) {
1036 table = url.getPathSegments().get(0);
1037 where = null;
1038 args = null;
1039 } else {
1040 throw new IllegalArgumentException("Invalid URI: " + url);
1041 }
1042 }
1043 }
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001044
1045 private static class ChangeListenerWrapper implements Handler.Callback {
1046
1047 private static final int MSG_LAUNCHER_PROVIDER_CHANGED = 1;
Sunny Goyalf2dd4212017-09-28 11:31:39 -07001048 private static final int MSG_APP_WIDGET_HOST_RESET = 2;
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001049
1050 private LauncherProviderChangeListener mListener;
1051
1052 @Override
1053 public boolean handleMessage(Message msg) {
1054 if (mListener != null) {
1055 switch (msg.what) {
1056 case MSG_LAUNCHER_PROVIDER_CHANGED:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001057 mListener.onLauncherProviderChanged();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001058 break;
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001059 case MSG_APP_WIDGET_HOST_RESET:
Sunny Goyal2e013ea2016-10-07 16:17:19 -07001060 mListener.onAppWidgetHostReset();
Sunny Goyalb5b55c82016-05-10 12:28:59 -07001061 break;
1062 }
1063 }
1064 return true;
1065 }
1066 }
Adam Cohen72960972014-01-15 18:13:55 -08001067}