The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.provider.LauncherDbUtils.dropTable; |
| 20 | import static com.android.launcher3.provider.LauncherDbUtils.tableExists; |
| 21 | |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 22 | import android.annotation.TargetApi; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 23 | import android.appwidget.AppWidgetHost; |
Mike Cleron | b87bd16 | 2009-10-30 16:36:56 -0700 | [diff] [blame] | 24 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.content.ComponentName; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 26 | import android.content.ContentProvider; |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 27 | import android.content.ContentProviderOperation; |
| 28 | import android.content.ContentProviderResult; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 29 | import android.content.ContentUris; |
| 30 | import android.content.ContentValues; |
| 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 33 | import android.content.OperationApplicationException; |
Michael Jurka | b85f8a4 | 2012-04-25 15:48:32 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager.NameNotFoundException; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 36 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.database.Cursor; |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 38 | import android.database.DatabaseUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | import android.database.SQLException; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 40 | import android.database.sqlite.SQLiteDatabase; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 41 | import android.database.sqlite.SQLiteQueryBuilder; |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 42 | import android.database.sqlite.SQLiteStatement; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 43 | import android.net.Uri; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 44 | import android.os.Binder; |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 45 | import android.os.Build; |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 46 | import android.os.Bundle; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 47 | import android.os.Handler; |
| 48 | import android.os.Message; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 49 | import android.os.Process; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 50 | import android.os.UserHandle; |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 51 | import android.os.UserManager; |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 52 | import android.provider.BaseColumns; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 53 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | import android.util.Log; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 55 | |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 56 | import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback; |
| 57 | import com.android.launcher3.LauncherSettings.Favorites; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 58 | import com.android.launcher3.compat.UserManagerCompat; |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 59 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 60 | import com.android.launcher3.logging.FileLog; |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 61 | import com.android.launcher3.model.DbDowngradeHelper; |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 62 | import com.android.launcher3.provider.LauncherDbUtils; |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 63 | import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction; |
Sunny Goyal | e8f7d5a | 2016-05-24 11:30:14 -0700 | [diff] [blame] | 64 | import com.android.launcher3.provider.RestoreDbTask; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 65 | import com.android.launcher3.util.IntArray; |
| 66 | import com.android.launcher3.util.IntSet; |
Sunny Goyal | 19026b2 | 2018-03-09 14:37:37 -0800 | [diff] [blame] | 67 | import com.android.launcher3.util.NoLocaleSQLiteHelper; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 68 | import com.android.launcher3.util.Preconditions; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 69 | import com.android.launcher3.util.Thunk; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 70 | |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 71 | import java.io.File; |
Hyunyoung Song | 6aa3729 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 72 | import java.io.FileDescriptor; |
| 73 | import java.io.PrintWriter; |
Mike Cleron | b87bd16 | 2009-10-30 16:36:56 -0700 | [diff] [blame] | 74 | import java.net.URISyntaxException; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 75 | import java.util.ArrayList; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 76 | import java.util.Arrays; |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 77 | import java.util.Locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | public class LauncherProvider extends ContentProvider { |
Sunny Goyal | c74e419 | 2015-09-08 14:01:03 -0700 | [diff] [blame] | 80 | private static final String TAG = "LauncherProvider"; |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 81 | private static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 82 | |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 83 | private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json"; |
| 84 | |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Represents the schema of the database. Changes in scheme need not be backwards compatible. |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 87 | * When increasing the scheme version, ensure that downgrade_schema.json is updated |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 88 | */ |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 89 | public static final int SCHEMA_VERSION = 28; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | |
Sunny Goyal | 4276e7b | 2018-11-26 23:44:41 -0800 | [diff] [blame] | 91 | public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings"; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 92 | |
Sunny Goyal | e87e6ab | 2014-11-21 22:42:53 -0800 | [diff] [blame] | 93 | static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 95 | private static final String RESTRICTION_PACKAGE_NAME = "workspace.configuration.package.name"; |
| 96 | |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 97 | private final ChangeListenerWrapper mListenerWrapper = new ChangeListenerWrapper(); |
| 98 | private Handler mListenerHandler; |
| 99 | |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 100 | protected DatabaseHelper mOpenHelper; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 101 | |
Hyunyoung Song | 6aa3729 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 102 | /** |
| 103 | * $ adb shell dumpsys activity provider com.android.launcher3 |
| 104 | */ |
| 105 | @Override |
| 106 | public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 107 | LauncherAppState appState = LauncherAppState.getInstanceNoCreate(); |
| 108 | if (appState == null || !appState.getModel().isModelLoaded()) { |
| 109 | return; |
| 110 | } |
| 111 | appState.getModel().dumpState("", fd, writer, args); |
| 112 | } |
| 113 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 114 | @Override |
| 115 | public boolean onCreate() { |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 116 | if (FeatureFlags.IS_DOGFOOD_BUILD) { |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 117 | Log.d(TAG, "Launcher process started"); |
| 118 | } |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 119 | mListenerHandler = new Handler(mListenerWrapper); |
| 120 | |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 121 | // The content provider exists for the entire duration of the launcher main process and |
Sunny Goyal | 66f2b35 | 2018-02-09 10:57:12 -0800 | [diff] [blame] | 122 | // is the first component to get created. |
| 123 | MainProcessInitializer.initialize(getContext().getApplicationContext()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | return true; |
| 125 | } |
| 126 | |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Sets a provider listener. |
| 129 | */ |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 130 | public void setLauncherProviderChangeListener(LauncherProviderChangeListener listener) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 131 | Preconditions.assertUIThread(); |
| 132 | mListenerWrapper.mListener = listener; |
Anjali Koppal | 67e7cae | 2014-03-13 12:14:12 -0700 | [diff] [blame] | 133 | } |
| 134 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | @Override |
| 136 | public String getType(Uri uri) { |
| 137 | SqlArguments args = new SqlArguments(uri, null, null); |
| 138 | if (TextUtils.isEmpty(args.where)) { |
| 139 | return "vnd.android.cursor.dir/" + args.table; |
| 140 | } else { |
| 141 | return "vnd.android.cursor.item/" + args.table; |
| 142 | } |
| 143 | } |
| 144 | |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 145 | /** |
| 146 | * Overridden in tests |
| 147 | */ |
| 148 | protected synchronized void createDbIfNotExists() { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 149 | if (mOpenHelper == null) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 150 | mOpenHelper = new DatabaseHelper(getContext(), mListenerHandler); |
Sunny Goyal | e8f7d5a | 2016-05-24 11:30:14 -0700 | [diff] [blame] | 151 | |
| 152 | if (RestoreDbTask.isPending(getContext())) { |
| 153 | if (!RestoreDbTask.performRestore(mOpenHelper)) { |
| 154 | mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase()); |
| 155 | } |
| 156 | // Set is pending to false irrespective of the result, so that it doesn't get |
| 157 | // executed again. |
| 158 | RestoreDbTask.setPending(getContext(), false); |
| 159 | } |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 163 | @Override |
| 164 | public Cursor query(Uri uri, String[] projection, String selection, |
| 165 | String[] selectionArgs, String sortOrder) { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 166 | createDbIfNotExists(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 167 | |
| 168 | SqlArguments args = new SqlArguments(uri, selection, selectionArgs); |
| 169 | SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); |
| 170 | qb.setTables(args.table); |
| 171 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 172 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 173 | Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder); |
| 174 | result.setNotificationUri(getContext().getContentResolver(), uri); |
| 175 | |
| 176 | return result; |
| 177 | } |
| 178 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 179 | @Thunk static int dbInsertAndCheck(DatabaseHelper helper, |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 180 | SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) { |
Dan Sandler | d502404 | 2014-01-09 15:01:33 -0500 | [diff] [blame] | 181 | if (values == null) { |
| 182 | throw new RuntimeException("Error: attempting to insert null values"); |
| 183 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 184 | if (!values.containsKey(LauncherSettings.Favorites._ID)) { |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 185 | throw new RuntimeException("Error: attempting to add item without specifying an id"); |
| 186 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 187 | helper.checkId(values); |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 188 | return (int) db.insert(table, nullColumnHack, values); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 191 | private void reloadLauncherIfExternal() { |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame^] | 192 | if (Binder.getCallingPid() != Process.myPid()) { |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 193 | LauncherAppState app = LauncherAppState.getInstanceNoCreate(); |
| 194 | if (app != null) { |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 195 | app.getModel().forceReload(); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 200 | @Override |
| 201 | public Uri insert(Uri uri, ContentValues initialValues) { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 202 | createDbIfNotExists(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 203 | SqlArguments args = new SqlArguments(uri); |
| 204 | |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 205 | // In very limited cases, we support system|signature permission apps to modify the db. |
| 206 | if (Binder.getCallingPid() != Process.myPid()) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 207 | if (!initializeExternalAdd(initialValues)) { |
Adam Cohen | a043fa8 | 2014-07-23 14:49:38 -0700 | [diff] [blame] | 208 | return null; |
| 209 | } |
| 210 | } |
| 211 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 212 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 213 | addModifiedTime(initialValues); |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 214 | final int rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues); |
Sunny Goyal | e72f3d5 | 2015-03-02 14:24:21 -0800 | [diff] [blame] | 215 | if (rowId < 0) return null; |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 216 | mOpenHelper.onAddOrDeleteOp(db); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 217 | |
| 218 | uri = ContentUris.withAppendedId(uri, rowId); |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 219 | notifyListeners(); |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame^] | 220 | reloadLauncherIfExternal(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 221 | return uri; |
| 222 | } |
| 223 | |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 224 | private boolean initializeExternalAdd(ContentValues values) { |
| 225 | // 1. Ensure that externally added items have a valid item id |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 226 | int id = mOpenHelper.generateNewItemId(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 227 | values.put(LauncherSettings.Favorites._ID, id); |
| 228 | |
| 229 | // 2. In the case of an app widget, and if no app widget id is specified, we |
| 230 | // attempt allocate and bind the widget. |
| 231 | Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE); |
| 232 | if (itemType != null && |
| 233 | itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && |
| 234 | !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) { |
| 235 | |
| 236 | final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext()); |
| 237 | ComponentName cn = ComponentName.unflattenFromString( |
| 238 | values.getAsString(Favorites.APPWIDGET_PROVIDER)); |
| 239 | |
| 240 | if (cn != null) { |
| 241 | try { |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 242 | AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost(); |
| 243 | int appWidgetId = widgetHost.allocateAppWidgetId(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 244 | values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId); |
| 245 | if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) { |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 246 | widgetHost.deleteAppWidgetId(appWidgetId); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 247 | return false; |
| 248 | } |
| 249 | } catch (RuntimeException e) { |
| 250 | Log.e(TAG, "Failed to initialize external widget", e); |
| 251 | return false; |
| 252 | } |
| 253 | } else { |
| 254 | return false; |
| 255 | } |
| 256 | } |
| 257 | |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 258 | return true; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 259 | } |
| 260 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 261 | @Override |
| 262 | public int bulkInsert(Uri uri, ContentValues[] values) { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 263 | createDbIfNotExists(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 264 | SqlArguments args = new SqlArguments(uri); |
| 265 | |
| 266 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 267 | try (SQLiteTransaction t = new SQLiteTransaction(db)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 268 | int numValues = values.length; |
| 269 | for (int i = 0; i < numValues; i++) { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 270 | addModifiedTime(values[i]); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 271 | if (dbInsertAndCheck(mOpenHelper, db, args.table, null, values[i]) < 0) { |
| 272 | return 0; |
| 273 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 274 | } |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 275 | mOpenHelper.onAddOrDeleteOp(db); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 276 | t.commit(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 279 | notifyListeners(); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 280 | reloadLauncherIfExternal(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 281 | return values.length; |
| 282 | } |
| 283 | |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 284 | @TargetApi(Build.VERSION_CODES.M) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 285 | @Override |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 286 | public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) |
| 287 | throws OperationApplicationException { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 288 | createDbIfNotExists(); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 289 | try (SQLiteTransaction t = new SQLiteTransaction(mOpenHelper.getWritableDatabase())) { |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame^] | 290 | boolean isAddOrDelete = false; |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 291 | |
| 292 | final int numOperations = operations.size(); |
| 293 | final ContentProviderResult[] results = new ContentProviderResult[numOperations]; |
| 294 | for (int i = 0; i < numOperations; i++) { |
| 295 | ContentProviderOperation op = operations.get(i); |
| 296 | results[i] = op.apply(this, results, i); |
| 297 | |
| 298 | isAddOrDelete |= (op.isInsert() || op.isDelete()) && |
| 299 | results[i].count != null && results[i].count > 0; |
| 300 | } |
| 301 | if (isAddOrDelete) { |
| 302 | mOpenHelper.onAddOrDeleteOp(t.getDb()); |
| 303 | } |
| 304 | |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 305 | t.commit(); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 306 | reloadLauncherIfExternal(); |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 307 | return results; |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 312 | public int delete(Uri uri, String selection, String[] selectionArgs) { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 313 | createDbIfNotExists(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 314 | SqlArguments args = new SqlArguments(uri, selection, selectionArgs); |
| 315 | |
| 316 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 317 | |
Louis Begin | a9c21c6 | 2016-08-15 15:18:41 -0700 | [diff] [blame] | 318 | if (Binder.getCallingPid() != Process.myPid() |
| 319 | && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) { |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 320 | mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase()); |
Louis Begin | a9c21c6 | 2016-08-15 15:18:41 -0700 | [diff] [blame] | 321 | } |
| 322 | int count = db.delete(args.table, args.where, args.args); |
| 323 | if (count > 0) { |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 324 | mOpenHelper.onAddOrDeleteOp(db); |
Louis Begin | a9c21c6 | 2016-08-15 15:18:41 -0700 | [diff] [blame] | 325 | notifyListeners(); |
| 326 | reloadLauncherIfExternal(); |
| 327 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 328 | return count; |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 333 | createDbIfNotExists(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 334 | SqlArguments args = new SqlArguments(uri, selection, selectionArgs); |
| 335 | |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 336 | addModifiedTime(values); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 337 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
| 338 | int count = db.update(args.table, values, args.where, args.args); |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 339 | if (count > 0) notifyListeners(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 340 | |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 341 | reloadLauncherIfExternal(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 342 | return count; |
| 343 | } |
| 344 | |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 345 | @Override |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 346 | public Bundle call(String method, final String arg, final Bundle extras) { |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 347 | if (Binder.getCallingUid() != Process.myUid()) { |
| 348 | return null; |
| 349 | } |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 350 | createDbIfNotExists(); |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 351 | |
| 352 | switch (method) { |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 353 | case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: { |
| 354 | clearFlagEmptyDbCreated(); |
| 355 | return null; |
| 356 | } |
Sunny Goyal | a5c8a9e | 2016-07-08 08:32:44 -0700 | [diff] [blame] | 357 | case LauncherSettings.Settings.METHOD_WAS_EMPTY_DB_CREATED : { |
| 358 | Bundle result = new Bundle(); |
| 359 | result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, |
| 360 | Utilities.getPrefs(getContext()).getBoolean(EMPTY_DATABASE_CREATED, false)); |
| 361 | return result; |
| 362 | } |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 363 | case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: { |
| 364 | Bundle result = new Bundle(); |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 365 | result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders() |
| 366 | .toArray()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 367 | return result; |
| 368 | } |
| 369 | case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: { |
| 370 | Bundle result = new Bundle(); |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 371 | result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 372 | return result; |
| 373 | } |
| 374 | case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: { |
| 375 | Bundle result = new Bundle(); |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 376 | result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 377 | return result; |
| 378 | } |
| 379 | case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: { |
Sunny Goyal | e05b08f | 2017-02-23 18:30:22 -0800 | [diff] [blame] | 380 | mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 381 | return null; |
| 382 | } |
| 383 | case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: { |
| 384 | loadDefaultFavoritesIfNecessary(); |
| 385 | return null; |
| 386 | } |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 387 | case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: { |
| 388 | mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase()); |
| 389 | return null; |
| 390 | } |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 391 | case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: { |
| 392 | Bundle result = new Bundle(); |
| 393 | result.putBinder(LauncherSettings.Settings.EXTRA_VALUE, |
| 394 | new SQLiteTransaction(mOpenHelper.getWritableDatabase())); |
| 395 | return result; |
| 396 | } |
| 397 | case LauncherSettings.Settings.METHOD_REFRESH_BACKUP_TABLE: { |
| 398 | mOpenHelper.mBackupTableExists = |
| 399 | tableExists(mOpenHelper.getReadableDatabase(), Favorites.BACKUP_TABLE_NAME); |
| 400 | return null; |
| 401 | } |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 402 | } |
| 403 | return null; |
| 404 | } |
| 405 | |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 406 | /** |
| 407 | * Deletes any empty folder from the DB. |
| 408 | * @return Ids of deleted folders. |
| 409 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 410 | private IntArray deleteEmptyFolders() { |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 411 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 412 | try (SQLiteTransaction t = new SQLiteTransaction(db)) { |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 413 | // Select folders whose id do not match any container value. |
| 414 | String selection = LauncherSettings.Favorites.ITEM_TYPE + " = " |
| 415 | + LauncherSettings.Favorites.ITEM_TYPE_FOLDER + " AND " |
| 416 | + LauncherSettings.Favorites._ID + " NOT IN (SELECT " + |
| 417 | LauncherSettings.Favorites.CONTAINER + " FROM " |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 418 | + Favorites.TABLE_NAME + ")"; |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 419 | |
| 420 | IntArray folderIds = LauncherDbUtils.queryIntArray(db, Favorites.TABLE_NAME, |
| 421 | Favorites._ID, selection, null, null); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 422 | if (!folderIds.isEmpty()) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 423 | db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery( |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 424 | LauncherSettings.Favorites._ID, folderIds), null); |
| 425 | } |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 426 | t.commit(); |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 427 | return folderIds; |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 428 | } catch (SQLException ex) { |
| 429 | Log.e(TAG, ex.getMessage(), ex); |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 430 | return new IntArray(); |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 431 | } |
Sunny Goyal | b1622cc | 2015-06-10 16:00:42 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 434 | /** |
| 435 | * Overridden in tests |
| 436 | */ |
| 437 | protected void notifyListeners() { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 438 | mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_LAUNCHER_PROVIDER_CHANGED); |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 441 | @Thunk static void addModifiedTime(ContentValues values) { |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 442 | values.put(LauncherSettings.Favorites.MODIFIED, System.currentTimeMillis()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 445 | private void clearFlagEmptyDbCreated() { |
Sunny Goyal | f725824 | 2015-10-19 16:59:07 -0700 | [diff] [blame] | 446 | Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit(); |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Sunny Goyal | 42de82f | 2014-09-26 22:09:29 -0700 | [diff] [blame] | 449 | /** |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 450 | * Loads the default workspace based on the following priority scheme: |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 451 | * 1) From the app restrictions |
| 452 | * 2) From a package provided by play store |
| 453 | * 3) From a partner configuration APK, already in the system image |
| 454 | * 4) The default configuration for the particular device |
Brian Muramatsu | 5524b49 | 2012-10-02 16:55:54 -0700 | [diff] [blame] | 455 | */ |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 456 | synchronized private void loadDefaultFavoritesIfNecessary() { |
Sunny Goyal | f725824 | 2015-10-19 16:59:07 -0700 | [diff] [blame] | 457 | SharedPreferences sp = Utilities.getPrefs(getContext()); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 458 | |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 459 | if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) { |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 460 | Log.d(TAG, "loading default workspace"); |
Michael Jurka | 45355c4 | 2012-10-08 13:21:35 +0200 | [diff] [blame] | 461 | |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 462 | AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 463 | AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction(widgetHost); |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 464 | if (loader == null) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 465 | loader = AutoInstallsLayout.get(getContext(),widgetHost, mOpenHelper); |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 466 | } |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 467 | if (loader == null) { |
Adam Cohen | 9b8f51f | 2014-05-30 15:34:09 -0700 | [diff] [blame] | 468 | final Partner partner = Partner.get(getContext().getPackageManager()); |
| 469 | if (partner != null && partner.hasDefaultLayout()) { |
| 470 | final Resources partnerRes = partner.getResources(); |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 471 | int workspaceResId = partnerRes.getIdentifier(Partner.RES_DEFAULT_LAYOUT, |
Adam Cohen | 9b8f51f | 2014-05-30 15:34:09 -0700 | [diff] [blame] | 472 | "xml", partner.getPackageName()); |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 473 | if (workspaceResId != 0) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 474 | loader = new DefaultLayoutParser(getContext(), widgetHost, |
Sunny Goyal | 3a5a9d1 | 2014-10-01 15:33:41 -0700 | [diff] [blame] | 475 | mOpenHelper, partnerRes, workspaceResId); |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 476 | } |
Adam Cohen | 9b8f51f | 2014-05-30 15:34:09 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 479 | |
Sunny Goyal | 9d21968 | 2014-10-23 14:21:02 -0700 | [diff] [blame] | 480 | final boolean usingExternallyProvidedLayout = loader != null; |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 481 | if (loader == null) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 482 | loader = getDefaultLayoutParser(widgetHost); |
Brian Muramatsu | 5524b49 | 2012-10-02 16:55:54 -0700 | [diff] [blame] | 483 | } |
Sunny Goyal | c6c8fef | 2015-03-04 09:51:18 -0800 | [diff] [blame] | 484 | |
| 485 | // There might be some partially restored DB items, due to buggy restore logic in |
| 486 | // previous versions of launcher. |
Sunny Goyal | e05b08f | 2017-02-23 18:30:22 -0800 | [diff] [blame] | 487 | mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase()); |
Michael Jurka | b85f8a4 | 2012-04-25 15:48:32 -0700 | [diff] [blame] | 488 | // Populate favorites table with initial favorites |
Sunny Goyal | 9d21968 | 2014-10-23 14:21:02 -0700 | [diff] [blame] | 489 | if ((mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), loader) <= 0) |
| 490 | && usingExternallyProvidedLayout) { |
| 491 | // Unable to load external layout. Cleanup and load the internal layout. |
Sunny Goyal | e05b08f | 2017-02-23 18:30:22 -0800 | [diff] [blame] | 492 | mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase()); |
Sunny Goyal | 9d21968 | 2014-10-23 14:21:02 -0700 | [diff] [blame] | 493 | mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 494 | getDefaultLayoutParser(widgetHost)); |
Sunny Goyal | 9d21968 | 2014-10-23 14:21:02 -0700 | [diff] [blame] | 495 | } |
Sunny Goyal | 33d4438 | 2014-10-16 09:24:19 -0700 | [diff] [blame] | 496 | clearFlagEmptyDbCreated(); |
Michael Jurka | b85f8a4 | 2012-04-25 15:48:32 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 500 | /** |
| 501 | * Creates workspace loader from an XML resource listed in the app restrictions. |
| 502 | * |
| 503 | * @return the loader if the restrictions are set and the resource exists; null otherwise. |
| 504 | */ |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 505 | private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) { |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 506 | Context ctx = getContext(); |
| 507 | UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE); |
| 508 | Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName()); |
Sunny Goyal | 35ca873 | 2015-04-06 10:45:31 -0700 | [diff] [blame] | 509 | if (bundle == null) { |
| 510 | return null; |
| 511 | } |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 512 | |
Sunny Goyal | 35ca873 | 2015-04-06 10:45:31 -0700 | [diff] [blame] | 513 | String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME); |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 514 | if (packageName != null) { |
| 515 | try { |
| 516 | Resources targetResources = ctx.getPackageManager() |
| 517 | .getResourcesForApplication(packageName); |
| 518 | return AutoInstallsLayout.get(ctx, packageName, targetResources, |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 519 | widgetHost, mOpenHelper); |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 520 | } catch (NameNotFoundException e) { |
| 521 | Log.e(TAG, "Target package for restricted profile not found", e); |
| 522 | return null; |
| 523 | } |
| 524 | } |
| 525 | return null; |
| 526 | } |
| 527 | |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 528 | private DefaultLayoutParser getDefaultLayoutParser(AppWidgetHost widgetHost) { |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 529 | InvariantDeviceProfile idp = LauncherAppState.getIDP(getContext()); |
| 530 | int defaultLayout = idp.defaultLayoutId; |
| 531 | |
| 532 | UserManagerCompat um = UserManagerCompat.getInstance(getContext()); |
| 533 | if (um.isDemoUser() && idp.demoModeLayoutId != 0) { |
| 534 | defaultLayout = idp.demoModeLayoutId; |
| 535 | } |
| 536 | |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 537 | return new DefaultLayoutParser(getContext(), widgetHost, |
Sunny Goyal | 9d21968 | 2014-10-23 14:21:02 -0700 | [diff] [blame] | 538 | mOpenHelper, getContext().getResources(), defaultLayout); |
| 539 | } |
| 540 | |
Sunny Goyal | d3849d1 | 2015-10-29 10:28:32 -0700 | [diff] [blame] | 541 | /** |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 542 | * The class is subclassed in tests to create an in-memory db. |
| 543 | */ |
Sunny Goyal | 19026b2 | 2018-03-09 14:37:37 -0800 | [diff] [blame] | 544 | public static class DatabaseHelper extends NoLocaleSQLiteHelper implements LayoutParserCallback { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 545 | private final Handler mWidgetHostResetHandler; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 546 | private final Context mContext; |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 547 | private int mMaxItemId = -1; |
| 548 | private int mMaxScreenId = -1; |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 549 | private boolean mBackupTableExists; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 550 | |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 551 | DatabaseHelper(Context context, Handler widgetHostResetHandler) { |
| 552 | this(context, widgetHostResetHandler, LauncherFiles.LAUNCHER_DB); |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 553 | // Table creation sometimes fails silently, which leads to a crash loop. |
| 554 | // This way, we will try to create a table every time after crash, so the device |
| 555 | // would eventually be able to recover. |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 556 | if (!tableExists(getReadableDatabase(), Favorites.TABLE_NAME)) { |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 557 | Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate"); |
| 558 | // This operation is a no-op if the table already exists. |
| 559 | addFavoritesTable(getWritableDatabase(), true); |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 560 | } |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 561 | mBackupTableExists = tableExists(getReadableDatabase(), Favorites.BACKUP_TABLE_NAME); |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 562 | |
Sunny Goyal | 7eab3cc | 2016-03-18 17:42:55 -0700 | [diff] [blame] | 563 | initIds(); |
| 564 | } |
| 565 | |
| 566 | /** |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 567 | * Constructor used in tests and for restore. |
Sunny Goyal | 7eab3cc | 2016-03-18 17:42:55 -0700 | [diff] [blame] | 568 | */ |
| 569 | public DatabaseHelper( |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 570 | Context context, Handler widgetHostResetHandler, String tableName) { |
Sunny Goyal | 19026b2 | 2018-03-09 14:37:37 -0800 | [diff] [blame] | 571 | super(context, tableName, SCHEMA_VERSION); |
Sunny Goyal | 7eab3cc | 2016-03-18 17:42:55 -0700 | [diff] [blame] | 572 | mContext = context; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 573 | mWidgetHostResetHandler = widgetHostResetHandler; |
Sunny Goyal | 7eab3cc | 2016-03-18 17:42:55 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | protected void initIds() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 577 | // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from |
| 578 | // the DB here |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 579 | if (mMaxItemId == -1) { |
| 580 | mMaxItemId = initializeMaxItemId(getWritableDatabase()); |
| 581 | } |
| 582 | if (mMaxScreenId == -1) { |
| 583 | mMaxScreenId = initializeMaxScreenId(getWritableDatabase()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 584 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | @Override |
| 588 | public void onCreate(SQLiteDatabase db) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 589 | if (LOGD) Log.d(TAG, "creating new launcher database"); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 590 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 591 | mMaxItemId = 1; |
| 592 | mMaxScreenId = 0; |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 593 | |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 594 | addFavoritesTable(db, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 595 | |
Sunny Goyal | e87e6ab | 2014-11-21 22:42:53 -0800 | [diff] [blame] | 596 | // Fresh and clean launcher DB. |
| 597 | mMaxItemId = initializeMaxItemId(db); |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 598 | onEmptyDbCreated(); |
| 599 | } |
| 600 | |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 601 | protected void onAddOrDeleteOp(SQLiteDatabase db) { |
| 602 | if (mBackupTableExists) { |
| 603 | dropTable(db, Favorites.BACKUP_TABLE_NAME); |
| 604 | mBackupTableExists = false; |
| 605 | } |
| 606 | } |
| 607 | |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 608 | /** |
| 609 | * Overriden in tests. |
| 610 | */ |
| 611 | protected void onEmptyDbCreated() { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 612 | // Database was just created, so wipe any previous widgets |
| 613 | if (mWidgetHostResetHandler != null) { |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 614 | newLauncherWidgetHost().deleteHost(); |
Sunny Goyal | 2e013ea | 2016-10-07 16:17:19 -0700 | [diff] [blame] | 615 | mWidgetHostResetHandler.sendEmptyMessage( |
Sunny Goyal | 72db9af | 2016-11-29 07:25:49 +0530 | [diff] [blame] | 616 | ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 619 | // Set the flag for empty DB |
| 620 | Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit(); |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 621 | } |
| 622 | |
Sunny Goyal | e8f7d5a | 2016-05-24 11:30:14 -0700 | [diff] [blame] | 623 | public long getDefaultUserSerial() { |
Sunny Goyal | f076eae | 2016-01-11 12:25:10 -0800 | [diff] [blame] | 624 | return UserManagerCompat.getInstance(mContext).getSerialNumberForUser( |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 625 | Process.myUserHandle()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 628 | private void addFavoritesTable(SQLiteDatabase db, boolean optional) { |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 629 | Favorites.addTableToDb(db, getDefaultUserSerial(), optional); |
Sunny Goyal | 6fb929e | 2015-09-23 11:40:53 -0700 | [diff] [blame] | 630 | } |
| 631 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 632 | @Override |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 633 | public void onOpen(SQLiteDatabase db) { |
| 634 | super.onOpen(db); |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 635 | |
| 636 | File schemaFile = mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE); |
| 637 | if (!schemaFile.exists()) { |
| 638 | handleOneTimeDataUpgrade(db); |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 639 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 640 | DbDowngradeHelper.updateSchemaFile(schemaFile, SCHEMA_VERSION, mContext); |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /** |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 644 | * One-time data updated before support of onDowngrade was added. This update is backwards |
| 645 | * compatible and can safely be run multiple times. |
| 646 | * Note: No new logic should be added here after release, as the new logic might not get |
| 647 | * executed on an existing device. |
| 648 | * TODO: Move this to db upgrade path, once the downgrade path is released. |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 649 | */ |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 650 | protected void handleOneTimeDataUpgrade(SQLiteDatabase db) { |
| 651 | // Remove "profile extra" |
| 652 | UserManagerCompat um = UserManagerCompat.getInstance(mContext); |
| 653 | for (UserHandle user : um.getUserProfiles()) { |
| 654 | long serial = um.getSerialNumberForUser(user); |
| 655 | String sql = "update favorites set intent = replace(intent, " |
| 656 | + "';l.profile=" + serial + ";', ';') where itemType = 0;"; |
| 657 | db.execSQL(sql); |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| 661 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 662 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
Winson Chung | c763c4e | 2013-07-19 13:49:06 -0700 | [diff] [blame] | 663 | if (LOGD) Log.d(TAG, "onUpgrade triggered: " + oldVersion); |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 664 | switch (oldVersion) { |
| 665 | // The version cannot be lower that 12, as Launcher3 never supported a lower |
Sunny Goyal | e87e6ab | 2014-11-21 22:42:53 -0800 | [diff] [blame] | 666 | // version of the DB. |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 667 | case 12: |
| 668 | // No-op |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 669 | case 13: { |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 670 | try (SQLiteTransaction t = new SQLiteTransaction(db)) { |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 671 | // Insert new column for holding widget provider name |
| 672 | db.execSQL("ALTER TABLE favorites " + |
| 673 | "ADD COLUMN appWidgetProvider TEXT;"); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 674 | t.commit(); |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 675 | } catch (SQLException ex) { |
| 676 | Log.e(TAG, ex.getMessage(), ex); |
| 677 | // Old version remains, which means we wipe old data |
| 678 | break; |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | case 14: { |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 682 | if (!addIntegerColumn(db, Favorites.MODIFIED, 0)) { |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 683 | // Old version remains, which means we wipe old data |
| 684 | break; |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | case 15: { |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 688 | if (!addIntegerColumn(db, Favorites.RESTORED, 0)) { |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 689 | // Old version remains, which means we wipe old data |
| 690 | break; |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 693 | case 16: |
Sunny Goyal | 10629b0 | 2016-09-01 12:50:11 -0700 | [diff] [blame] | 694 | // No-op |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 695 | case 17: |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 696 | // No-op |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 697 | case 18: |
| 698 | // No-op |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 699 | case 19: { |
| 700 | // Add userId column |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 701 | if (!addIntegerColumn(db, Favorites.PROFILE_ID, getDefaultUserSerial())) { |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 702 | // Old version remains, which means we wipe old data |
| 703 | break; |
| 704 | } |
| 705 | } |
| 706 | case 20: |
| 707 | if (!updateFolderItemsRank(db, true)) { |
| 708 | break; |
| 709 | } |
Sunny Goyal | d2f3819 | 2015-02-25 10:46:34 -0800 | [diff] [blame] | 710 | case 21: |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 711 | // No-op |
Sunny Goyal | d2f3819 | 2015-02-25 10:46:34 -0800 | [diff] [blame] | 712 | case 22: { |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 713 | if (!addIntegerColumn(db, Favorites.OPTIONS, 0)) { |
| 714 | // Old version remains, which means we wipe old data |
| 715 | break; |
| 716 | } |
| 717 | } |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 718 | case 23: |
Sunny Goyal | 5c97f51 | 2015-05-19 16:03:28 -0700 | [diff] [blame] | 719 | // No-op |
Sunny Goyal | e2fba6c | 2015-05-12 10:39:59 -0700 | [diff] [blame] | 720 | case 24: |
Tony Mak | 1b6826c | 2018-02-27 15:06:12 +0000 | [diff] [blame] | 721 | // No-op |
Sunny Goyal | 5c97f51 | 2015-05-19 16:03:28 -0700 | [diff] [blame] | 722 | case 25: |
| 723 | convertShortcutsToLauncherActivities(db); |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 724 | case 26: |
| 725 | // QSB was moved to the grid. Clear the first row on screen 0. |
Ryan Lothian | fa530cd | 2018-10-12 14:14:16 -0400 | [diff] [blame] | 726 | if (FeatureFlags.QSB_ON_FIRST_SCREEN.get() && |
Sunny Goyal | 8ad02b8 | 2016-12-29 13:31:43 -0800 | [diff] [blame] | 727 | !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) { |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 728 | break; |
| 729 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 730 | case 27: { |
| 731 | // Update the favorites table so that the screen ids are ordered based on |
| 732 | // workspace page rank. |
| 733 | IntArray finalScreens = LauncherDbUtils.queryIntArray(db, "workspaceScreens", |
| 734 | BaseColumns._ID, null, null, "screenRank"); |
| 735 | int[] original = finalScreens.toArray(); |
| 736 | Arrays.sort(original); |
| 737 | String updatemap = ""; |
| 738 | for (int i = 0; i < original.length; i++) { |
| 739 | if (finalScreens.get(i) != original[i]) { |
| 740 | updatemap += String.format(Locale.ENGLISH, " WHEN %1$s=%2$d THEN %3$d", |
| 741 | Favorites.SCREEN, finalScreens.get(i), original[i]); |
| 742 | } |
| 743 | } |
| 744 | if (!TextUtils.isEmpty(updatemap)) { |
| 745 | String query = String.format(Locale.ENGLISH, |
| 746 | "UPDATE %1$s SET %2$s=CASE %3$s ELSE %2$s END WHERE %4$s = %5$d", |
| 747 | Favorites.TABLE_NAME, Favorites.SCREEN, updatemap, |
| 748 | Favorites.CONTAINER, Favorites.CONTAINER_DESKTOP); |
| 749 | db.execSQL(query); |
| 750 | } |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 751 | dropTable(db, "workspaceScreens"); |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 752 | } |
| 753 | case 28: |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 754 | // DB Upgraded successfully |
| 755 | return; |
Chris Wren | d5e66bf | 2013-09-16 14:02:29 -0400 | [diff] [blame] | 756 | } |
| 757 | |
Sunny Goyal | a2cc624 | 2015-01-14 14:23:02 -0800 | [diff] [blame] | 758 | // DB was not upgraded |
| 759 | Log.w(TAG, "Destroying all old data."); |
| 760 | createEmptyDB(db); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 761 | } |
Romain Guy | 7eb9e5e | 2009-12-02 20:10:07 -0800 | [diff] [blame] | 762 | |
Adam Cohen | 9b1d062 | 2014-05-21 19:01:57 -0700 | [diff] [blame] | 763 | @Override |
| 764 | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
Sunny Goyal | 05f3088 | 2017-05-03 12:42:18 -0700 | [diff] [blame] | 765 | try { |
| 766 | DbDowngradeHelper.parse(mContext.getFileStreamPath(DOWNGRADE_SCHEMA_FILE)) |
| 767 | .onDowngrade(db, oldVersion, newVersion); |
| 768 | } catch (Exception e) { |
| 769 | Log.d(TAG, "Unable to downgrade from: " + oldVersion + " to " + newVersion + |
| 770 | ". Wiping databse.", e); |
| 771 | createEmptyDB(db); |
Sunny Goyal | 3c7d55b | 2017-04-13 12:01:47 -0700 | [diff] [blame] | 772 | } |
Sunny Goyal | 42de82f | 2014-09-26 22:09:29 -0700 | [diff] [blame] | 773 | } |
Adam Cohen | 9b1d062 | 2014-05-21 19:01:57 -0700 | [diff] [blame] | 774 | |
Sunny Goyal | 42de82f | 2014-09-26 22:09:29 -0700 | [diff] [blame] | 775 | /** |
| 776 | * Clears all the data for a fresh start. |
| 777 | */ |
| 778 | public void createEmptyDB(SQLiteDatabase db) { |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 779 | try (SQLiteTransaction t = new SQLiteTransaction(db)) { |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 780 | dropTable(db, Favorites.TABLE_NAME); |
| 781 | dropTable(db, "workspaceScreens"); |
Sunny Goyal | e05b08f | 2017-02-23 18:30:22 -0800 | [diff] [blame] | 782 | onCreate(db); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 783 | t.commit(); |
Sunny Goyal | e05b08f | 2017-02-23 18:30:22 -0800 | [diff] [blame] | 784 | } |
Adam Cohen | 9b1d062 | 2014-05-21 19:01:57 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Sunny Goyal | d2f3819 | 2015-02-25 10:46:34 -0800 | [diff] [blame] | 787 | /** |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 788 | * Removes widgets which are registered to the Launcher's host, but are not present |
| 789 | * in our model. |
| 790 | */ |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 791 | @TargetApi(Build.VERSION_CODES.O) |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 792 | public void removeGhostWidgets(SQLiteDatabase db) { |
| 793 | // Get all existing widget ids. |
| 794 | final AppWidgetHost host = newLauncherWidgetHost(); |
| 795 | final int[] allWidgets; |
| 796 | try { |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 797 | // Although the method was defined in O, it has existed since the beginning of time, |
| 798 | // so it might work on older platforms as well. |
| 799 | allWidgets = host.getAppWidgetIds(); |
| 800 | } catch (IncompatibleClassChangeError e) { |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 801 | Log.e(TAG, "getAppWidgetIds not supported", e); |
| 802 | return; |
| 803 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 804 | final IntSet validWidgets = IntSet.wrap(LauncherDbUtils.queryIntArray(db, |
| 805 | Favorites.TABLE_NAME, Favorites.APPWIDGET_ID, |
| 806 | "itemType=" + Favorites.ITEM_TYPE_APPWIDGET, null, null)); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 807 | for (int widgetId : allWidgets) { |
| 808 | if (!validWidgets.contains(widgetId)) { |
| 809 | try { |
| 810 | FileLog.d(TAG, "Deleting invalid widget " + widgetId); |
| 811 | host.deleteAppWidgetId(widgetId); |
| 812 | } catch (RuntimeException e) { |
| 813 | // Ignore |
| 814 | } |
| 815 | } |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
| 819 | /** |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 820 | * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid |
| 821 | * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}. |
| 822 | */ |
Sunny Goyal | 316490e | 2015-06-02 09:38:28 -0700 | [diff] [blame] | 823 | @Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) { |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 824 | try (SQLiteTransaction t = new SQLiteTransaction(db); |
| 825 | // Only consider the primary user as other users can't have a shortcut. |
| 826 | Cursor c = db.query(Favorites.TABLE_NAME, |
| 827 | new String[] { Favorites._ID, Favorites.INTENT}, |
| 828 | "itemType=" + Favorites.ITEM_TYPE_SHORTCUT + |
| 829 | " AND profileId=" + getDefaultUserSerial(), |
| 830 | null, null, null, null); |
| 831 | SQLiteStatement updateStmt = db.compileStatement("UPDATE favorites SET itemType=" |
| 832 | + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?") |
| 833 | ) { |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 834 | final int idIndex = c.getColumnIndexOrThrow(Favorites._ID); |
| 835 | final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT); |
| 836 | |
| 837 | while (c.moveToNext()) { |
| 838 | String intentDescription = c.getString(intentIndex); |
| 839 | Intent intent; |
| 840 | try { |
| 841 | intent = Intent.parseUri(intentDescription, 0); |
| 842 | } catch (URISyntaxException e) { |
| 843 | Log.e(TAG, "Unable to parse intent", e); |
| 844 | continue; |
| 845 | } |
| 846 | |
Sunny Goyal | 4e5cc64 | 2015-06-25 16:37:44 -0700 | [diff] [blame] | 847 | if (!Utilities.isLauncherAppTarget(intent)) { |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 848 | continue; |
| 849 | } |
| 850 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 851 | int id = c.getInt(idIndex); |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 852 | updateStmt.bindLong(1, id); |
Sunny Goyal | c22841b | 2015-07-13 19:59:50 -0700 | [diff] [blame] | 853 | updateStmt.executeUpdateDelete(); |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 854 | } |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 855 | t.commit(); |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 856 | } catch (SQLException ex) { |
| 857 | Log.w(TAG, "Error deduping shortcuts", ex); |
Sunny Goyal | 0b03778 | 2015-04-02 10:27:03 -0700 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 861 | @Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) { |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 862 | try (SQLiteTransaction t = new SQLiteTransaction(db)) { |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 863 | if (addRankColumn) { |
| 864 | // Insert new column for holding rank |
| 865 | db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;"); |
| 866 | } |
| 867 | |
| 868 | // Get a map for folder ID to folder width |
| 869 | Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites" |
| 870 | + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)" |
| 871 | + " GROUP BY container;", |
| 872 | new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)}); |
| 873 | |
| 874 | while (c.moveToNext()) { |
Sunny Goyal | c87775d | 2015-02-10 19:52:36 -0800 | [diff] [blame] | 875 | db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE " |
| 876 | + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;", |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 877 | new Object[] {c.getLong(1) + 1, c.getLong(0)}); |
| 878 | } |
| 879 | |
| 880 | c.close(); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 881 | t.commit(); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 882 | } catch (SQLException ex) { |
| 883 | // Old version remains, which means we wipe old data |
| 884 | Log.e(TAG, ex.getMessage(), ex); |
| 885 | return false; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 886 | } |
| 887 | return true; |
| 888 | } |
| 889 | |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 890 | private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) { |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 891 | try (SQLiteTransaction t = new SQLiteTransaction(db)) { |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 892 | db.execSQL("ALTER TABLE favorites ADD COLUMN " |
| 893 | + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";"); |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 894 | t.commit(); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 895 | } catch (SQLException ex) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 896 | Log.e(TAG, ex.getMessage(), ex); |
| 897 | return false; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 898 | } |
| 899 | return true; |
| 900 | } |
| 901 | |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 902 | // Generates a new ID to use for an object in your database. This method should be only |
| 903 | // called from the main UI thread. As an exception, we do call it when we call the |
| 904 | // constructor from the worker thread; however, this doesn't extend until after the |
| 905 | // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp |
| 906 | // after that point |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 907 | @Override |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 908 | public int generateNewItemId() { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 909 | if (mMaxItemId < 0) { |
| 910 | throw new RuntimeException("Error: max item id was not initialized"); |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 911 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 912 | mMaxItemId += 1; |
| 913 | return mMaxItemId; |
Michael Jurka | a8c760d | 2011-04-28 14:59:33 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 916 | public AppWidgetHost newLauncherWidgetHost() { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 917 | return new LauncherAppWidgetHost(mContext); |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 920 | @Override |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 921 | public int insertAndCheck(SQLiteDatabase db, ContentValues values) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 922 | return dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, values); |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 925 | public void checkId(ContentValues values) { |
| 926 | int id = values.getAsInteger(Favorites._ID); |
| 927 | mMaxItemId = Math.max(id, mMaxItemId); |
| 928 | |
| 929 | Integer screen = values.getAsInteger(Favorites.SCREEN); |
| 930 | Integer container = values.getAsInteger(Favorites.CONTAINER); |
| 931 | if (screen != null && container != null |
| 932 | && container.intValue() == Favorites.CONTAINER_DESKTOP) { |
| 933 | mMaxScreenId = Math.max(screen, mMaxScreenId); |
Chris Wren | 5dee7af | 2013-12-20 17:22:11 -0500 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 937 | private int initializeMaxItemId(SQLiteDatabase db) { |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 938 | return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s", Favorites._ID, Favorites.TABLE_NAME); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | // Generates a new ID to use for an workspace screen in your database. This method |
| 942 | // should be only called from the main UI thread. As an exception, we do call it when we |
| 943 | // call the constructor from the worker thread; however, this doesn't extend until after the |
| 944 | // constructor is called, and we only pass a reference to LauncherProvider to LauncherApp |
| 945 | // after that point |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 946 | public int generateNewScreenId() { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 947 | if (mMaxScreenId < 0) { |
| 948 | throw new RuntimeException("Error: max screen id was not initialized"); |
| 949 | } |
| 950 | mMaxScreenId += 1; |
| 951 | return mMaxScreenId; |
| 952 | } |
| 953 | |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 954 | private int initializeMaxScreenId(SQLiteDatabase db) { |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 955 | return getMaxId(db, "SELECT MAX(%1$s) FROM %2$s WHERE %3$s = %4$d", |
| 956 | Favorites.SCREEN, Favorites.TABLE_NAME, Favorites.CONTAINER, |
| 957 | Favorites.CONTAINER_DESKTOP); |
Adam Cohen | 7ec3bbf | 2014-07-31 00:09:45 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 960 | @Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) { |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 961 | // TODO: Use multiple loaders with fall-back and transaction. |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 962 | int count = loader.loadLayout(db, new IntArray()); |
Adam Cohen | 71483f4 | 2014-05-15 14:04:01 -0700 | [diff] [blame] | 963 | |
| 964 | // Ensure that the max ids are initialized |
| 965 | mMaxItemId = initializeMaxItemId(db); |
| 966 | mMaxScreenId = initializeMaxScreenId(db); |
| 967 | return count; |
| 968 | } |
Mike Cleron | b87bd16 | 2009-10-30 16:36:56 -0700 | [diff] [blame] | 969 | } |
Daniel Lehmann | c3a8040 | 2012-04-23 21:35:11 -0700 | [diff] [blame] | 970 | |
Sunny Goyal | fe4e4b9 | 2015-03-04 10:43:45 -0800 | [diff] [blame] | 971 | /** |
| 972 | * @return the max _id in the provided table. |
| 973 | */ |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 974 | @Thunk static int getMaxId(SQLiteDatabase db, String query, Object... args) { |
| 975 | int max = (int) DatabaseUtils.longForQuery(db, |
| 976 | String.format(Locale.ENGLISH, query, args), |
| 977 | null); |
| 978 | if (max < 0) { |
| 979 | throw new RuntimeException("Error: could not query max id"); |
Sunny Goyal | fe4e4b9 | 2015-03-04 10:43:45 -0800 | [diff] [blame] | 980 | } |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 981 | return max; |
Sunny Goyal | fe4e4b9 | 2015-03-04 10:43:45 -0800 | [diff] [blame] | 982 | } |
| 983 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 984 | static class SqlArguments { |
| 985 | public final String table; |
| 986 | public final String where; |
| 987 | public final String[] args; |
| 988 | |
| 989 | SqlArguments(Uri url, String where, String[] args) { |
| 990 | if (url.getPathSegments().size() == 1) { |
| 991 | this.table = url.getPathSegments().get(0); |
| 992 | this.where = where; |
| 993 | this.args = args; |
| 994 | } else if (url.getPathSegments().size() != 2) { |
| 995 | throw new IllegalArgumentException("Invalid URI: " + url); |
| 996 | } else if (!TextUtils.isEmpty(where)) { |
| 997 | throw new UnsupportedOperationException("WHERE clause not supported: " + url); |
| 998 | } else { |
| 999 | this.table = url.getPathSegments().get(0); |
Daniel Lehmann | c3a8040 | 2012-04-23 21:35:11 -0700 | [diff] [blame] | 1000 | this.where = "_id=" + ContentUris.parseId(url); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1001 | this.args = null; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | SqlArguments(Uri url) { |
| 1006 | if (url.getPathSegments().size() == 1) { |
| 1007 | table = url.getPathSegments().get(0); |
| 1008 | where = null; |
| 1009 | args = null; |
| 1010 | } else { |
| 1011 | throw new IllegalArgumentException("Invalid URI: " + url); |
| 1012 | } |
| 1013 | } |
| 1014 | } |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 1015 | |
| 1016 | private static class ChangeListenerWrapper implements Handler.Callback { |
| 1017 | |
| 1018 | private static final int MSG_LAUNCHER_PROVIDER_CHANGED = 1; |
Sunny Goyal | f2dd421 | 2017-09-28 11:31:39 -0700 | [diff] [blame] | 1019 | private static final int MSG_APP_WIDGET_HOST_RESET = 2; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 1020 | |
| 1021 | private LauncherProviderChangeListener mListener; |
| 1022 | |
| 1023 | @Override |
| 1024 | public boolean handleMessage(Message msg) { |
| 1025 | if (mListener != null) { |
| 1026 | switch (msg.what) { |
| 1027 | case MSG_LAUNCHER_PROVIDER_CHANGED: |
Sunny Goyal | 2e013ea | 2016-10-07 16:17:19 -0700 | [diff] [blame] | 1028 | mListener.onLauncherProviderChanged(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 1029 | break; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 1030 | case MSG_APP_WIDGET_HOST_RESET: |
Sunny Goyal | 2e013ea | 2016-10-07 16:17:19 -0700 | [diff] [blame] | 1031 | mListener.onAppWidgetHostReset(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | return true; |
| 1036 | } |
| 1037 | } |
Adam Cohen | 7296097 | 2014-01-15 18:13:55 -0800 | [diff] [blame] | 1038 | } |