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 | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 19 | import android.annotation.TargetApi; |
Mike Cleron | b87bd16 | 2009-10-30 16:36:56 -0700 | [diff] [blame] | 20 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.content.ComponentName; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 22 | import android.content.ContentProvider; |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 23 | import android.content.ContentProviderOperation; |
| 24 | import android.content.ContentProviderResult; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 25 | import android.content.ContentUris; |
| 26 | import android.content.ContentValues; |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 27 | import android.content.OperationApplicationException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | import android.database.Cursor; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 29 | import android.database.sqlite.SQLiteQueryBuilder; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 31 | import android.os.Binder; |
Sunny Goyal | 22ca9ec | 2017-05-18 15:03:13 -0700 | [diff] [blame] | 32 | import android.os.Build; |
Sunny Goyal | b2d46ce | 2015-03-26 11:32:11 -0700 | [diff] [blame] | 33 | import android.os.Bundle; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 34 | import android.os.Process; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 35 | import android.text.TextUtils; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.util.Log; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 37 | |
Sunny Goyal | 0fe505b | 2014-08-06 09:55:36 -0700 | [diff] [blame] | 38 | import com.android.launcher3.LauncherSettings.Favorites; |
Sunny Goyal | a9e2f5a | 2016-06-10 12:22:04 -0700 | [diff] [blame] | 39 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 40 | import com.android.launcher3.model.ModelDbController; |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 41 | import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction; |
Sihua Ma | 8bbfcb6 | 2022-11-08 16:46:07 -0800 | [diff] [blame] | 42 | import com.android.launcher3.widget.LauncherWidgetHolder; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 43 | |
Hyunyoung Song | 6aa3729 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 44 | import java.io.FileDescriptor; |
| 45 | import java.io.PrintWriter; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame] | 46 | import java.util.ArrayList; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | public class LauncherProvider extends ContentProvider { |
Sunny Goyal | c74e419 | 2015-09-08 14:01:03 -0700 | [diff] [blame] | 49 | private static final String TAG = "LauncherProvider"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | |
Sunny Goyal | 4276e7b | 2018-11-26 23:44:41 -0800 | [diff] [blame] | 51 | public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings"; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 52 | |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 53 | protected ModelDbController mModelDbController; |
Schneider Victor-tulias | fb252e7 | 2022-02-10 11:10:21 -0800 | [diff] [blame] | 54 | |
Hyunyoung Song | 6aa3729 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 55 | /** |
| 56 | * $ adb shell dumpsys activity provider com.android.launcher3 |
| 57 | */ |
| 58 | @Override |
| 59 | public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 60 | LauncherAppState appState = LauncherAppState.getInstanceNoCreate(); |
| 61 | if (appState == null || !appState.getModel().isModelLoaded()) { |
| 62 | return; |
| 63 | } |
| 64 | appState.getModel().dumpState("", fd, writer, args); |
| 65 | } |
| 66 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | @Override |
| 68 | public boolean onCreate() { |
Zak Cohen | 3eeb41d | 2020-02-14 14:15:13 -0800 | [diff] [blame] | 69 | if (FeatureFlags.IS_STUDIO_BUILD) { |
Sunny Goyal | e26d100 | 2016-06-20 14:52:14 -0700 | [diff] [blame] | 70 | Log.d(TAG, "Launcher process started"); |
| 71 | } |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 72 | mModelDbController = new ModelDbController(getContext()); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 73 | |
Sunny Goyal | fdbef27 | 2017-02-01 12:52:54 -0800 | [diff] [blame] | 74 | // 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] | 75 | // is the first component to get created. |
| 76 | MainProcessInitializer.initialize(getContext().getApplicationContext()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 77 | return true; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String getType(Uri uri) { |
| 82 | SqlArguments args = new SqlArguments(uri, null, null); |
| 83 | if (TextUtils.isEmpty(args.where)) { |
| 84 | return "vnd.android.cursor.dir/" + args.table; |
| 85 | } else { |
| 86 | return "vnd.android.cursor.item/" + args.table; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Cursor query(Uri uri, String[] projection, String selection, |
| 92 | String[] selectionArgs, String sortOrder) { |
| 93 | |
| 94 | SqlArguments args = new SqlArguments(uri, selection, selectionArgs); |
| 95 | SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); |
| 96 | qb.setTables(args.table); |
| 97 | |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 98 | Cursor result = mModelDbController.query( |
| 99 | args.table, projection, args.where, args.args, sortOrder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 100 | result.setNotificationUri(getContext().getContentResolver(), uri); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 101 | return result; |
| 102 | } |
| 103 | |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 104 | private void reloadLauncherIfExternal() { |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame] | 105 | if (Binder.getCallingPid() != Process.myPid()) { |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 106 | LauncherAppState app = LauncherAppState.getInstanceNoCreate(); |
| 107 | if (app != null) { |
Sunny Goyal | dd96a5e | 2017-02-17 11:22:34 -0800 | [diff] [blame] | 108 | app.getModel().forceReload(); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 113 | @Override |
| 114 | public Uri insert(Uri uri, ContentValues initialValues) { |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 115 | // In very limited cases, we support system|signature permission apps to modify the db. |
| 116 | if (Binder.getCallingPid() != Process.myPid()) { |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 117 | if (!initializeExternalAdd(initialValues)) { |
Adam Cohen | a043fa8 | 2014-07-23 14:49:38 -0700 | [diff] [blame] | 118 | return null; |
| 119 | } |
| 120 | } |
| 121 | |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 122 | SqlArguments args = new SqlArguments(uri); |
| 123 | int rowId = mModelDbController.insert(args.table, initialValues); |
Sunny Goyal | e72f3d5 | 2015-03-02 14:24:21 -0800 | [diff] [blame] | 124 | if (rowId < 0) return null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 125 | |
| 126 | uri = ContentUris.withAppendedId(uri, rowId); |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame] | 127 | reloadLauncherIfExternal(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 128 | return uri; |
| 129 | } |
| 130 | |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 131 | private boolean initializeExternalAdd(ContentValues values) { |
| 132 | // 1. Ensure that externally added items have a valid item id |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 133 | int id = mModelDbController.generateNewItemId(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 134 | values.put(LauncherSettings.Favorites._ID, id); |
| 135 | |
| 136 | // 2. In the case of an app widget, and if no app widget id is specified, we |
| 137 | // attempt allocate and bind the widget. |
| 138 | Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE); |
| 139 | if (itemType != null && |
| 140 | itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && |
| 141 | !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) { |
| 142 | |
| 143 | final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext()); |
| 144 | ComponentName cn = ComponentName.unflattenFromString( |
| 145 | values.getAsString(Favorites.APPWIDGET_PROVIDER)); |
| 146 | |
| 147 | if (cn != null) { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 148 | LauncherWidgetHolder widgetHolder = LauncherWidgetHolder.newInstance(getContext()); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 149 | try { |
Sihua Ma | aa2b872 | 2022-10-25 15:17:58 -0700 | [diff] [blame] | 150 | int appWidgetId = widgetHolder.allocateAppWidgetId(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 151 | values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId); |
| 152 | if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) { |
Sihua Ma | aa2b872 | 2022-10-25 15:17:58 -0700 | [diff] [blame] | 153 | widgetHolder.deleteAppWidgetId(appWidgetId); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 154 | return false; |
| 155 | } |
| 156 | } catch (RuntimeException e) { |
| 157 | Log.e(TAG, "Failed to initialize external widget", e); |
| 158 | return false; |
Sihua Ma | aa2b872 | 2022-10-25 15:17:58 -0700 | [diff] [blame] | 159 | } finally { |
| 160 | // Necessary to destroy the holder to free up possible activity context |
| 161 | widgetHolder.destroy(); |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 162 | } |
| 163 | } else { |
| 164 | return false; |
| 165 | } |
| 166 | } |
| 167 | |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 168 | return true; |
Sunny Goyal | b5b55c8 | 2016-05-10 12:28:59 -0700 | [diff] [blame] | 169 | } |
| 170 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 171 | @Override |
| 172 | public int bulkInsert(Uri uri, ContentValues[] values) { |
| 173 | SqlArguments args = new SqlArguments(uri); |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 174 | mModelDbController.bulkInsert(args.table, values); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 175 | reloadLauncherIfExternal(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | return values.length; |
| 177 | } |
| 178 | |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 179 | @TargetApi(Build.VERSION_CODES.M) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | @Override |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 181 | public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) |
| 182 | throws OperationApplicationException { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 183 | try (SQLiteTransaction t = mModelDbController.newTransaction()) { |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 184 | final int numOperations = operations.size(); |
| 185 | final ContentProviderResult[] results = new ContentProviderResult[numOperations]; |
| 186 | for (int i = 0; i < numOperations; i++) { |
| 187 | ContentProviderOperation op = operations.get(i); |
| 188 | results[i] = op.apply(this, results, i); |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 189 | } |
Sunny Goyal | dbfc901 | 2017-04-17 16:58:36 -0700 | [diff] [blame] | 190 | t.commit(); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 191 | reloadLauncherIfExternal(); |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 192 | return results; |
Yura | 085c853 | 2014-02-11 15:15:29 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
| 196 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 197 | public int delete(Uri uri, String selection, String[] selectionArgs) { |
| 198 | SqlArguments args = new SqlArguments(uri, selection, selectionArgs); |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 199 | int count = mModelDbController.delete(args.table, args.where, args.args); |
Louis Begin | a9c21c6 | 2016-08-15 15:18:41 -0700 | [diff] [blame] | 200 | if (count > 0) { |
Louis Begin | a9c21c6 | 2016-08-15 15:18:41 -0700 | [diff] [blame] | 201 | reloadLauncherIfExternal(); |
| 202 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 203 | return count; |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { |
| 208 | SqlArguments args = new SqlArguments(uri, selection, selectionArgs); |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 209 | int count = mModelDbController.update(args.table, values, args.where, args.args); |
Sunny Goyal | d106418 | 2015-08-13 12:08:30 -0700 | [diff] [blame] | 210 | reloadLauncherIfExternal(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 211 | return count; |
| 212 | } |
| 213 | |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 214 | @Override |
Tony Wickham | 827cef2 | 2016-03-17 15:39:39 -0700 | [diff] [blame] | 215 | public Bundle call(String method, final String arg, final Bundle extras) { |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 216 | if (Binder.getCallingUid() != Process.myUid()) { |
| 217 | return null; |
| 218 | } |
| 219 | |
| 220 | switch (method) { |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 221 | case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 222 | mModelDbController.clearEmptyDbFlag(); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 223 | return null; |
| 224 | } |
| 225 | case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: { |
| 226 | Bundle result = new Bundle(); |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 227 | result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, |
| 228 | mModelDbController.deleteEmptyFolders().toArray()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 229 | return result; |
| 230 | } |
| 231 | case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: { |
| 232 | Bundle result = new Bundle(); |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 233 | result.putInt(LauncherSettings.Settings.EXTRA_VALUE, |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 234 | mModelDbController.generateNewItemId()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 235 | return result; |
| 236 | } |
| 237 | case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: { |
| 238 | Bundle result = new Bundle(); |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 239 | result.putInt(LauncherSettings.Settings.EXTRA_VALUE, |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 240 | mModelDbController.getNewScreenId()); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 241 | return result; |
| 242 | } |
| 243 | case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 244 | mModelDbController.createEmptyDB(); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 245 | return null; |
| 246 | } |
| 247 | case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 248 | mModelDbController.loadDefaultFavoritesIfNecessary(); |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 249 | return null; |
| 250 | } |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 251 | case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 252 | mModelDbController.removeGhostWidgets(); |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 253 | return null; |
| 254 | } |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 255 | case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: { |
| 256 | Bundle result = new Bundle(); |
| 257 | result.putBinder(LauncherSettings.Settings.EXTRA_VALUE, |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 258 | mModelDbController.newTransaction()); |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 259 | return result; |
| 260 | } |
Samuel Fufa | f667a13 | 2020-05-29 14:47:42 -0700 | [diff] [blame] | 261 | case LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE: { |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 262 | mModelDbController.refreshHotseatRestoreTable(); |
Samuel Fufa | f667a13 | 2020-05-29 14:47:42 -0700 | [diff] [blame] | 263 | return null; |
| 264 | } |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 265 | case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: { |
Sunny Goyal | 278939f | 2021-07-28 14:35:47 -0700 | [diff] [blame] | 266 | Bundle result = new Bundle(); |
| 267 | result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 268 | mModelDbController.updateCurrentOpenHelper(arg /* dbFile */)); |
Sunny Goyal | 278939f | 2021-07-28 14:35:47 -0700 | [diff] [blame] | 269 | return result; |
Tracy Zhou | c000045 | 2020-03-17 18:28:38 -0700 | [diff] [blame] | 270 | } |
| 271 | case LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW: { |
Sunny Goyal | 278939f | 2021-07-28 14:35:47 -0700 | [diff] [blame] | 272 | Bundle result = new Bundle(); |
| 273 | result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 274 | mModelDbController.prepareForPreview(arg /* dbFile */)); |
Sunny Goyal | 278939f | 2021-07-28 14:35:47 -0700 | [diff] [blame] | 275 | return result; |
Pinyao Ting | 96186af | 2020-07-20 11:03:39 -0700 | [diff] [blame] | 276 | } |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 277 | } |
| 278 | return null; |
| 279 | } |
| 280 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 281 | static class SqlArguments { |
| 282 | public final String table; |
| 283 | public final String where; |
| 284 | public final String[] args; |
| 285 | |
| 286 | SqlArguments(Uri url, String where, String[] args) { |
| 287 | if (url.getPathSegments().size() == 1) { |
| 288 | this.table = url.getPathSegments().get(0); |
| 289 | this.where = where; |
| 290 | this.args = args; |
| 291 | } else if (url.getPathSegments().size() != 2) { |
| 292 | throw new IllegalArgumentException("Invalid URI: " + url); |
| 293 | } else if (!TextUtils.isEmpty(where)) { |
| 294 | throw new UnsupportedOperationException("WHERE clause not supported: " + url); |
| 295 | } else { |
| 296 | this.table = url.getPathSegments().get(0); |
Daniel Lehmann | c3a8040 | 2012-04-23 21:35:11 -0700 | [diff] [blame] | 297 | this.where = "_id=" + ContentUris.parseId(url); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 298 | this.args = null; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | SqlArguments(Uri url) { |
| 303 | if (url.getPathSegments().size() == 1) { |
| 304 | table = url.getPathSegments().get(0); |
| 305 | where = null; |
| 306 | args = null; |
| 307 | } else { |
| 308 | throw new IllegalArgumentException("Invalid URI: " + url); |
| 309 | } |
| 310 | } |
| 311 | } |
Adam Cohen | 7296097 | 2014-01-15 18:13:55 -0800 | [diff] [blame] | 312 | } |