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 | 95045ce | 2024-09-27 13:56:45 -0700 | [diff] [blame] | 19 | import static android.util.Base64.NO_PADDING; |
| 20 | import static android.util.Base64.NO_WRAP; |
| 21 | |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 22 | import android.database.sqlite.SQLiteDatabase; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 23 | import android.provider.BaseColumns; |
Sunny Goyal | 95045ce | 2024-09-27 13:56:45 -0700 | [diff] [blame] | 24 | import android.util.Base64; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | |
Stefan Andonian | e8b86db | 2023-10-27 21:38:16 +0000 | [diff] [blame] | 26 | import androidx.annotation.NonNull; |
| 27 | |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 28 | import com.android.launcher3.model.data.ItemInfo; |
| 29 | |
Stefan Andonian | e8b86db | 2023-10-27 21:38:16 +0000 | [diff] [blame] | 30 | import java.util.LinkedHashMap; |
| 31 | import java.util.stream.Collectors; |
| 32 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | /** |
| 34 | * Settings related utilities. |
| 35 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 36 | public class LauncherSettings { |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
Luca Zuccarini | 2098381 | 2023-01-03 14:19:48 +0000 | [diff] [blame] | 39 | * Types of animations. |
| 40 | */ |
| 41 | public static final class Animation { |
| 42 | /** |
| 43 | * The default animation for a given view/item info type. |
| 44 | */ |
| 45 | public static final int DEFAULT = 0; |
| 46 | /** |
| 47 | * An animation using the view's background. |
| 48 | */ |
| 49 | public static final int VIEW_BACKGROUND = 1; |
Hyunyoung Song | a38aab9 | 2023-03-14 07:56:59 +0000 | [diff] [blame] | 50 | /** |
| 51 | * The default animation for a given view/item info type, but without the splash icon. |
| 52 | */ |
| 53 | public static final int DEFAULT_NO_ICON = 2; |
Luca Zuccarini | 2098381 | 2023-01-03 14:19:48 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 57 | * Favorites. |
| 58 | */ |
| 59 | public static final class Favorites implements BaseColumns { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 60 | /** |
| 61 | * The time of the last update to this row. |
| 62 | * <P>Type: INTEGER</P> |
| 63 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 64 | public static final String MODIFIED = "modified"; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 65 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Descriptive name of the gesture that can be displayed to the user. |
| 68 | * <P>Type: TEXT</P> |
| 69 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 70 | public static final String TITLE = "title"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * The Intent URL of the gesture, describing what it points to. This |
Romain Guy | 1ce1a24 | 2009-06-23 17:34:54 -0700 | [diff] [blame] | 74 | * value is given to {@link android.content.Intent#parseUri(String, int)} to create |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 75 | * an Intent that can be launched. |
| 76 | * <P>Type: TEXT</P> |
| 77 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 78 | public static final String INTENT = "intent"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * The type of the gesture |
| 82 | * |
| 83 | * <P>Type: INTEGER</P> |
| 84 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 85 | public static final String ITEM_TYPE = "itemType"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
Samuel Fufa | d3720c2 | 2019-09-06 11:25:08 -0700 | [diff] [blame] | 88 | * The gesture is a package |
| 89 | */ |
| 90 | public static final int ITEM_TYPE_NON_ACTIONABLE = -1; |
| 91 | /** |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 92 | * The gesture is an application |
| 93 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 94 | public static final int ITEM_TYPE_APPLICATION = 0; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * The gesture is an application created shortcut |
Sunny Goyal | e274d97 | 2023-05-01 16:55:59 -0700 | [diff] [blame] | 98 | * @deprecated This is no longer supported. Use {@link #ITEM_TYPE_DEEP_SHORTCUT} instead |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 99 | */ |
Sunny Goyal | e274d97 | 2023-05-01 16:55:59 -0700 | [diff] [blame] | 100 | @Deprecated |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 101 | public static final int ITEM_TYPE_SHORTCUT = 1; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
Andy Wickham | 19ab177 | 2021-02-10 21:36:51 -0800 | [diff] [blame] | 104 | * The favorite is a user created folder |
| 105 | */ |
| 106 | public static final int ITEM_TYPE_FOLDER = 2; |
| 107 | |
| 108 | /** |
| 109 | * The favorite is a widget |
| 110 | */ |
| 111 | public static final int ITEM_TYPE_APPWIDGET = 4; |
| 112 | |
| 113 | /** |
| 114 | * The favorite is a custom widget provided by the launcher |
| 115 | */ |
| 116 | public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5; |
| 117 | |
| 118 | /** |
| 119 | * The gesture is an application created deep shortcut |
| 120 | */ |
| 121 | public static final int ITEM_TYPE_DEEP_SHORTCUT = 6; |
| 122 | |
Jeremy Sim | 7cf0dd9 | 2023-03-24 22:39:45 -0700 | [diff] [blame] | 123 | /** |
| 124 | * The favorite is an app pair for launching split screen |
| 125 | */ |
| 126 | public static final int ITEM_TYPE_APP_PAIR = 10; |
sfufa@google.com | ca76de0 | 2021-09-24 08:55:48 -0700 | [diff] [blame] | 127 | |
Andy Wickham | 9345681 | 2022-10-05 17:58:45 -0700 | [diff] [blame] | 128 | // *** Below enum values are used for metrics purpose but not used in Favorites DB *** |
sfufa@google.com | ca76de0 | 2021-09-24 08:55:48 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
Andy Wickham | 19ab177 | 2021-02-10 21:36:51 -0800 | [diff] [blame] | 131 | * Type of the item is recents task. |
Andy Wickham | 19ab177 | 2021-02-10 21:36:51 -0800 | [diff] [blame] | 132 | */ |
| 133 | public static final int ITEM_TYPE_TASK = 7; |
| 134 | |
| 135 | /** |
| 136 | * The item is QSB |
| 137 | */ |
| 138 | public static final int ITEM_TYPE_QSB = 8; |
| 139 | |
| 140 | /** |
Andy Wickham | 9345681 | 2022-10-05 17:58:45 -0700 | [diff] [blame] | 141 | * The favorite is a search action |
| 142 | */ |
| 143 | public static final int ITEM_TYPE_SEARCH_ACTION = 9; |
| 144 | |
| 145 | /** |
Holly Sun | 20c30c9 | 2024-03-05 17:07:56 -0800 | [diff] [blame] | 146 | * Private space install app button. |
| 147 | */ |
| 148 | public static final int ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON = 11; |
| 149 | |
| 150 | /** |
Sunny Goyal | eb4b799 | 2016-04-21 14:30:18 -0700 | [diff] [blame] | 151 | * The custom icon bitmap. |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 152 | * <P>Type: BLOB</P> |
| 153 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 154 | public static final String ICON = "icon"; |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 155 | |
| 156 | public static final String TABLE_NAME = "favorites"; |
| 157 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 158 | /** |
Samuel Fufa | f667a13 | 2020-05-29 14:47:42 -0700 | [diff] [blame] | 159 | * Backup table created when user hotseat is moved to workspace for hybrid hotseat |
| 160 | */ |
| 161 | public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup"; |
| 162 | |
| 163 | /** |
Tracy Zhou | f601872 | 2020-02-06 16:37:16 -0800 | [diff] [blame] | 164 | * Temporary table used specifically for multi-db grid migrations |
| 165 | */ |
| 166 | public static final String TMP_TABLE = "favorites_tmp"; |
| 167 | |
| 168 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 169 | * The container holding the favorite |
| 170 | * <P>Type: INTEGER</P> |
| 171 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 172 | public static final String CONTAINER = "container"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * The icon is a resource identified by a package name and an integer id. |
| 176 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 177 | public static final int CONTAINER_DESKTOP = -100; |
| 178 | public static final int CONTAINER_HOTSEAT = -101; |
Samuel Fufa | 866ff00 | 2019-08-09 16:16:06 -0700 | [diff] [blame] | 179 | public static final int CONTAINER_PREDICTION = -102; |
Steven Ng | 3a83532 | 2021-03-02 21:26:00 +0000 | [diff] [blame] | 180 | public static final int CONTAINER_WIDGETS_PREDICTION = -111; |
Samuel Fufa | 225ac27 | 2019-10-21 02:02:40 -0700 | [diff] [blame] | 181 | public static final int CONTAINER_HOTSEAT_PREDICTION = -103; |
thiruram | 261c3a6 | 2020-04-29 16:23:15 -0700 | [diff] [blame] | 182 | public static final int CONTAINER_ALL_APPS = -104; |
thiruram | 6bf6848 | 2020-05-06 22:19:43 -0700 | [diff] [blame] | 183 | public static final int CONTAINER_WIDGETS_TRAY = -105; |
Yogisha Dixit | 658c5da | 2021-05-24 23:23:15 +0100 | [diff] [blame] | 184 | public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112; |
| 185 | public static final int CONTAINER_PIN_WIDGETS = -113; |
Brian Isganitis | f0ca4ae | 2021-09-02 16:08:29 -0400 | [diff] [blame] | 186 | public static final int CONTAINER_WALLPAPERS = -114; |
thiruram | 63bf8ee | 2020-06-01 12:03:19 -0700 | [diff] [blame] | 187 | public static final int CONTAINER_SHORTCUTS = -107; |
Hyunyoung Song | f26c793 | 2020-06-06 14:44:27 -0700 | [diff] [blame] | 188 | public static final int CONTAINER_SETTINGS = -108; |
Hyunyoung Song | 13c2bc7 | 2020-06-10 00:35:35 -0700 | [diff] [blame] | 189 | public static final int CONTAINER_TASKSWITCHER = -109; |
Brandon Dayauon | 120838b | 2024-04-08 13:04:54 -0700 | [diff] [blame] | 190 | public static final int CONTAINER_PRIVATESPACE = -110; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 191 | |
thiruram | 73821a9 | 2021-02-05 17:50:37 -0800 | [diff] [blame] | 192 | // Represents any of the extended containers implemented in non-AOSP variants. |
| 193 | public static final int EXTENDED_CONTAINERS = -200; |
| 194 | |
Yogisha Dixit | 658c5da | 2021-05-24 23:23:15 +0100 | [diff] [blame] | 195 | public static final int CONTAINER_UNKNOWN = -1; |
| 196 | |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 197 | public static final String containerToString(int container) { |
Dan Sandler | ab5fa3a | 2014-03-06 23:48:04 -0500 | [diff] [blame] | 198 | switch (container) { |
| 199 | case CONTAINER_DESKTOP: return "desktop"; |
| 200 | case CONTAINER_HOTSEAT: return "hotseat"; |
Samuel Fufa | 866ff00 | 2019-08-09 16:16:06 -0700 | [diff] [blame] | 201 | case CONTAINER_PREDICTION: return "prediction"; |
thiruram | 6bf6848 | 2020-05-06 22:19:43 -0700 | [diff] [blame] | 202 | case CONTAINER_ALL_APPS: return "all_apps"; |
| 203 | case CONTAINER_WIDGETS_TRAY: return "widgets_tray"; |
thiruram | 63bf8ee | 2020-06-01 12:03:19 -0700 | [diff] [blame] | 204 | case CONTAINER_SHORTCUTS: return "shortcuts"; |
Dan Sandler | ab5fa3a | 2014-03-06 23:48:04 -0500 | [diff] [blame] | 205 | default: return String.valueOf(container); |
| 206 | } |
| 207 | } |
| 208 | |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 209 | public static final String itemTypeToString(int type) { |
Hyunyoung Song | 86160f5 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 210 | switch(type) { |
| 211 | case ITEM_TYPE_APPLICATION: return "APP"; |
Hyunyoung Song | 86160f5 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 212 | case ITEM_TYPE_FOLDER: return "FOLDER"; |
| 213 | case ITEM_TYPE_APPWIDGET: return "WIDGET"; |
| 214 | case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET"; |
| 215 | case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT"; |
Andy Wickham | 19ab177 | 2021-02-10 21:36:51 -0800 | [diff] [blame] | 216 | case ITEM_TYPE_TASK: return "TASK"; |
| 217 | case ITEM_TYPE_QSB: return "QSB"; |
Jeremy Sim | 7cf0dd9 | 2023-03-24 22:39:45 -0700 | [diff] [blame] | 218 | case ITEM_TYPE_APP_PAIR: return "APP_PAIR"; |
Holly Sun | 20c30c9 | 2024-03-05 17:07:56 -0800 | [diff] [blame] | 219 | case ITEM_TYPE_PRIVATE_SPACE_INSTALL_APP_BUTTON: |
| 220 | return "PRIVATE_SPACE_INSTALL_APP_BUTTON"; |
Hyunyoung Song | 86160f5 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 221 | default: return String.valueOf(type); |
| 222 | } |
| 223 | } |
| 224 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 225 | /** |
| 226 | * The screen holding the favorite (if container is CONTAINER_DESKTOP) |
| 227 | * <P>Type: INTEGER</P> |
| 228 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 229 | public static final String SCREEN = "screen"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * The X coordinate of the cell holding the favorite |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 233 | * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 234 | * <P>Type: INTEGER</P> |
| 235 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 236 | public static final String CELLX = "cellX"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * The Y coordinate of the cell holding the favorite |
| 240 | * (if container is CONTAINER_DESKTOP) |
| 241 | * <P>Type: INTEGER</P> |
| 242 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 243 | public static final String CELLY = "cellY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * The X span of the cell holding the favorite |
| 247 | * <P>Type: INTEGER</P> |
| 248 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 249 | public static final String SPANX = "spanX"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 250 | |
| 251 | /** |
| 252 | * The Y span of the cell holding the favorite |
| 253 | * <P>Type: INTEGER</P> |
| 254 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 255 | public static final String SPANY = "spanY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 256 | |
| 257 | /** |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 258 | * The profile id of the item in the cell. |
| 259 | * <P> |
| 260 | * Type: INTEGER |
| 261 | * </P> |
| 262 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 263 | public static final String PROFILE_ID = "profileId"; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 264 | |
| 265 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 266 | * The appWidgetId of the widget |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 267 | * |
| 268 | * <P>Type: INTEGER</P> |
| 269 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 270 | public static final String APPWIDGET_ID = "appWidgetId"; |
Chris Wren | d5e66bf | 2013-09-16 14:02:29 -0400 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * The ComponentName of the widget provider |
| 274 | * |
| 275 | * <P>Type: STRING</P> |
| 276 | */ |
| 277 | public static final String APPWIDGET_PROVIDER = "appWidgetProvider"; |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 278 | |
| 279 | /** |
| 280 | * Boolean indicating that his item was restored and not yet successfully bound. |
| 281 | * <P>Type: INTEGER</P> |
| 282 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 283 | public static final String RESTORED = "restored"; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * Indicates the position of the item inside an auto-arranged view like folder or hotseat. |
| 287 | * <p>Type: INTEGER</p> |
| 288 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 289 | public static final String RANK = "rank"; |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * Stores general flag based options for {@link ItemInfo}s. |
| 293 | * <p>Type: INTEGER</p> |
| 294 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 295 | public static final String OPTIONS = "options"; |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 296 | |
Yogisha Dixit | 658c5da | 2021-05-24 23:23:15 +0100 | [diff] [blame] | 297 | /** |
| 298 | * Stores the source container that the widget was added from. |
| 299 | * <p>Type: INTEGER</p> |
| 300 | */ |
| 301 | public static final String APPWIDGET_SOURCE = "appWidgetSource"; |
| 302 | |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 303 | public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) { |
Sunny Goyal | 161a214 | 2018-10-29 14:02:20 -0700 | [diff] [blame] | 304 | addTableToDb(db, myProfileId, optional, TABLE_NAME); |
| 305 | } |
| 306 | |
| 307 | public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional, |
| 308 | String tableName) { |
Stefan Andonian | e8b86db | 2023-10-27 21:38:16 +0000 | [diff] [blame] | 309 | db.execSQL("CREATE TABLE " + (optional ? " IF NOT EXISTS " : "") + tableName + " (" |
| 310 | + getJoinedColumnsToTypes(myProfileId) + ");"); |
| 311 | } |
| 312 | |
| 313 | // LinkedHashMap maintains Order of Insertion |
| 314 | @NonNull |
| 315 | private static LinkedHashMap<String, String> getColumnsToTypes(long profileId) { |
| 316 | final LinkedHashMap<String, String> columnsToTypes = new LinkedHashMap<>(); |
| 317 | columnsToTypes.put(_ID, "INTEGER PRIMARY KEY"); |
| 318 | columnsToTypes.put(TITLE, "TEXT"); |
| 319 | columnsToTypes.put(INTENT, "TEXT"); |
| 320 | columnsToTypes.put(CONTAINER, "INTEGER"); |
| 321 | columnsToTypes.put(SCREEN, "INTEGER"); |
| 322 | columnsToTypes.put(CELLX, "INTEGER"); |
| 323 | columnsToTypes.put(CELLY, "INTEGER"); |
| 324 | columnsToTypes.put(SPANX, "INTEGER"); |
| 325 | columnsToTypes.put(SPANY, "INTEGER"); |
| 326 | columnsToTypes.put(ITEM_TYPE, "INTEGER"); |
| 327 | columnsToTypes.put(APPWIDGET_ID, "INTEGER NOT NULL DEFAULT -1"); |
| 328 | columnsToTypes.put(ICON, "BLOB"); |
| 329 | columnsToTypes.put(APPWIDGET_PROVIDER, "TEXT"); |
| 330 | columnsToTypes.put(MODIFIED, "INTEGER NOT NULL DEFAULT 0"); |
| 331 | columnsToTypes.put(RESTORED, "INTEGER NOT NULL DEFAULT 0"); |
| 332 | columnsToTypes.put(PROFILE_ID, "INTEGER DEFAULT " + profileId); |
| 333 | columnsToTypes.put(RANK, "INTEGER NOT NULL DEFAULT 0"); |
| 334 | columnsToTypes.put(OPTIONS, "INTEGER NOT NULL DEFAULT 0"); |
| 335 | columnsToTypes.put(APPWIDGET_SOURCE, "INTEGER NOT NULL DEFAULT -1"); |
| 336 | return columnsToTypes; |
| 337 | } |
| 338 | |
| 339 | private static String getJoinedColumnsToTypes(long profileId) { |
| 340 | return getColumnsToTypes(profileId) |
| 341 | .entrySet() |
| 342 | .stream() |
| 343 | .map(it -> it.getKey() + " " + it.getValue()) |
| 344 | .collect(Collectors.joining(", ")); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Returns an ordered list of columns in the Favorites table as one string, ready to use in |
| 349 | * an SQL statement. |
| 350 | */ |
| 351 | @NonNull |
| 352 | public static String getColumns(long profileId) { |
| 353 | return String.join(", ", getColumnsToTypes(profileId).keySet()); |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 354 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 355 | } |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 356 | |
| 357 | /** |
| 358 | * Launcher settings |
| 359 | */ |
| 360 | public static final class Settings { |
Sunny Goyal | 95045ce | 2024-09-27 13:56:45 -0700 | [diff] [blame] | 361 | public static final String LAYOUT_PROVIDER_KEY = "launcher3.layout.provider"; |
Sunny Goyal | ab2f808 | 2023-04-11 11:35:43 -0700 | [diff] [blame] | 362 | public static final String LAYOUT_DIGEST_LABEL = "launcher-layout"; |
| 363 | public static final String LAYOUT_DIGEST_TAG = "ignore"; |
Sunny Goyal | 95045ce | 2024-09-27 13:56:45 -0700 | [diff] [blame] | 364 | public static final String BLOB_KEY_PREFIX = "blob://"; |
| 365 | |
| 366 | /** |
| 367 | * Creates a key to be used for {@link #LAYOUT_PROVIDER_KEY} |
| 368 | * @param digest byte[] representing the message digest for the blob handle |
| 369 | */ |
| 370 | public static String createBlobProviderKey(byte[] digest) { |
| 371 | return BLOB_KEY_PREFIX + Base64.encodeToString(digest, NO_WRAP | NO_PADDING); |
| 372 | } |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 373 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 374 | } |