The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
| 17 | package com.android.providers.settings; |
| 18 | |
Matt Pape | 25c940d | 2019-03-26 12:14:33 -0700 | [diff] [blame] | 19 | import static android.os.Process.INVALID_UID; |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 20 | import static android.os.Process.ROOT_UID; |
| 21 | import static android.os.Process.SHELL_UID; |
| 22 | import static android.os.Process.SYSTEM_UID; |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 23 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY; |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 24 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 25 | import android.Manifest; |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 26 | import android.annotation.NonNull; |
Kweku Adams | b0886f3 | 2017-10-31 15:32:09 -0700 | [diff] [blame] | 27 | import android.annotation.Nullable; |
Christopher Tate | d5fe147 | 2012-09-10 15:48:38 -0700 | [diff] [blame] | 28 | import android.app.ActivityManager; |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 29 | import android.app.AppGlobals; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 30 | import android.app.backup.BackupManager; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 31 | import android.content.BroadcastReceiver; |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 32 | import android.content.ComponentName; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 33 | import android.content.ContentProvider; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | import android.content.ContentValues; |
| 35 | import android.content.Context; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 36 | import android.content.Intent; |
| 37 | import android.content.IntentFilter; |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 38 | import android.content.om.IOverlayManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 39 | import android.content.pm.ApplicationInfo; |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 40 | import android.content.pm.IPackageManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 41 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | import android.content.pm.PackageManager; |
Christopher Tate | 38e7a60 | 2013-09-03 16:57:34 -0700 | [diff] [blame] | 43 | import android.content.pm.UserInfo; |
Chad Brubaker | 20e0dc3 | 2017-04-28 18:24:55 -0700 | [diff] [blame] | 44 | import android.content.res.Resources; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 45 | import android.database.Cursor; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 46 | import android.database.MatrixCursor; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 47 | import android.database.sqlite.SQLiteDatabase; |
| 48 | import android.database.sqlite.SQLiteQueryBuilder; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 49 | import android.hardware.camera2.utils.ArrayUtils; |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 50 | import android.media.AudioManager; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | import android.net.Uri; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 52 | import android.os.Binder; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 53 | import android.os.Build; |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 54 | import android.os.Bundle; |
Amith Yamasani | 5cdf7f5 | 2013-06-27 15:12:01 -0700 | [diff] [blame] | 55 | import android.os.DropBoxManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 56 | import android.os.Environment; |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 57 | import android.os.Handler; |
Svet Ganov | a8f9026 | 2016-05-10 08:44:48 -0700 | [diff] [blame] | 58 | import android.os.HandlerThread; |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
| 60 | import android.os.Message; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 61 | import android.os.ParcelFileDescriptor; |
Christopher Tate | 0da1357 | 2013-10-13 17:34:49 -0700 | [diff] [blame] | 62 | import android.os.Process; |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 63 | import android.os.RemoteException; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 64 | import android.os.SELinux; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 65 | import android.os.ServiceManager; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 66 | import android.os.UserHandle; |
| 67 | import android.os.UserManager; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 68 | import android.os.UserManagerInternal; |
Matt Pape | 1278d1c | 2018-12-11 13:03:49 -0800 | [diff] [blame] | 69 | import android.provider.DeviceConfig; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | import android.provider.Settings; |
Narayan Kamath | 94bcdbc | 2017-07-17 15:32:53 +0100 | [diff] [blame] | 71 | import android.provider.Settings.Global; |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 72 | import android.provider.Settings.Secure; |
Al Sutton | 91f89d0 | 2019-08-16 12:56:57 +0100 | [diff] [blame] | 73 | import android.provider.settings.validators.SystemSettingsValidators; |
Al Sutton | b0067fb | 2019-08-16 10:34:46 +0100 | [diff] [blame] | 74 | import android.provider.settings.validators.Validator; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 75 | import android.text.TextUtils; |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 76 | import android.util.ArrayMap; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 77 | import android.util.ArraySet; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
| 79 | import android.util.SparseArray; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 80 | import android.util.SparseBooleanArray; |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 81 | import android.util.proto.ProtoOutputStream; |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 82 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 83 | import com.android.internal.annotations.GuardedBy; |
| 84 | import com.android.internal.content.PackageMonitor; |
| 85 | import com.android.internal.os.BackgroundThread; |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 86 | import com.android.providers.settings.SettingsState.Setting; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 87 | import com.android.server.LocalServices; |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 88 | import com.android.server.SystemConfig; |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 89 | |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 90 | import com.google.android.collect.Sets; |
| 91 | |
Neil Fuller | 3447fb4 | 2019-04-08 22:03:14 +0100 | [diff] [blame] | 92 | import libcore.util.HexEncoding; |
| 93 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 94 | import java.io.File; |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 95 | import java.io.FileDescriptor; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 96 | import java.io.FileNotFoundException; |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 97 | import java.io.PrintWriter; |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 98 | import java.nio.ByteBuffer; |
| 99 | import java.security.InvalidKeyException; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 100 | import java.security.NoSuchAlgorithmException; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 101 | import java.security.SecureRandom; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 102 | import java.util.ArrayList; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 103 | import java.util.Arrays; |
Robin Lee | 7af9a74 | 2017-02-20 14:47:30 +0000 | [diff] [blame] | 104 | import java.util.Collection; |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 105 | import java.util.HashMap; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 106 | import java.util.HashSet; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 107 | import java.util.List; |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 108 | import java.util.Map; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 109 | import java.util.Set; |
| 110 | import java.util.regex.Pattern; |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 111 | |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 112 | import javax.crypto.Mac; |
| 113 | import javax.crypto.spec.SecretKeySpec; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 114 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 115 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 116 | /** |
| 117 | * <p> |
| 118 | * This class is a content provider that publishes the system settings. |
| 119 | * It can be accessed via the content provider APIs or via custom call |
| 120 | * commands. The latter is a bit faster and is the preferred way to access |
| 121 | * the platform settings. |
| 122 | * </p> |
| 123 | * <p> |
| 124 | * There are three settings types, global (with signature level protection |
| 125 | * and shared across users), secure (with signature permission level |
| 126 | * protection and per user), and system (with dangerous permission level |
| 127 | * protection and per user). Global settings are stored under the device owner. |
| 128 | * Each of these settings is represented by a {@link |
| 129 | * com.android.providers.settings.SettingsState} object mapped to an integer |
| 130 | * key derived from the setting type in the most significant bits and user |
| 131 | * id in the least significant bits. Settings are synchronously loaded on |
| 132 | * instantiation of a SettingsState and asynchronously persisted on mutation. |
| 133 | * Settings are stored in the user specific system directory. |
| 134 | * </p> |
| 135 | * <p> |
| 136 | * Apps targeting APIs Lollipop MR1 and lower can add custom settings entries |
| 137 | * and get a warning. Targeting higher API version prohibits this as the |
| 138 | * system settings are not a place for apps to save their state. When a package |
| 139 | * is removed the settings it added are deleted. Apps cannot delete system |
| 140 | * settings added by the platform. System settings values are validated to |
| 141 | * ensure the clients do not put bad values. Global and secure settings are |
| 142 | * changed only by trusted parties, therefore no validation is performed. Also |
| 143 | * there is a limit on the amount of app specific settings that can be added |
| 144 | * to prevent unlimited growth of the system process memory footprint. |
| 145 | * </p> |
| 146 | */ |
| 147 | @SuppressWarnings("deprecation") |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 148 | public class SettingsProvider extends ContentProvider { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 149 | static final boolean DEBUG = false; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 150 | |
Svetoslav Ganov | 264c7a9 | 2016-08-24 17:31:14 -0700 | [diff] [blame] | 151 | private static final boolean DROP_DATABASE_ON_MIGRATION = true; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 152 | |
| 153 | private static final String LOG_TAG = "SettingsProvider"; |
Christopher Tate | 0da1357 | 2013-10-13 17:34:49 -0700 | [diff] [blame] | 154 | |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 155 | private static final String TABLE_SYSTEM = "system"; |
| 156 | private static final String TABLE_SECURE = "secure"; |
| 157 | private static final String TABLE_GLOBAL = "global"; |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 158 | private static final String TABLE_CONFIG = "config"; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 159 | |
| 160 | // Old tables no longer exist. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | private static final String TABLE_FAVORITES = "favorites"; |
| 162 | private static final String TABLE_OLD_FAVORITES = "old_favorites"; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 163 | private static final String TABLE_BLUETOOTH_DEVICES = "bluetooth_devices"; |
| 164 | private static final String TABLE_BOOKMARKS = "bookmarks"; |
| 165 | private static final String TABLE_ANDROID_METADATA = "android_metadata"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 167 | // The set of removed legacy tables. |
| 168 | private static final Set<String> REMOVED_LEGACY_TABLES = new ArraySet<>(); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 169 | static { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 170 | REMOVED_LEGACY_TABLES.add(TABLE_FAVORITES); |
| 171 | REMOVED_LEGACY_TABLES.add(TABLE_OLD_FAVORITES); |
| 172 | REMOVED_LEGACY_TABLES.add(TABLE_BLUETOOTH_DEVICES); |
| 173 | REMOVED_LEGACY_TABLES.add(TABLE_BOOKMARKS); |
| 174 | REMOVED_LEGACY_TABLES.add(TABLE_ANDROID_METADATA); |
| 175 | } |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 176 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 177 | private static final int MUTATION_OPERATION_INSERT = 1; |
| 178 | private static final int MUTATION_OPERATION_DELETE = 2; |
| 179 | private static final int MUTATION_OPERATION_UPDATE = 3; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 180 | private static final int MUTATION_OPERATION_RESET = 4; |
Julia Reynolds | 5e458dd | 2014-07-07 16:07:01 -0400 | [diff] [blame] | 181 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 182 | private static final String[] ALL_COLUMNS = new String[] { |
| 183 | Settings.NameValueTable._ID, |
| 184 | Settings.NameValueTable.NAME, |
| 185 | Settings.NameValueTable.VALUE |
| 186 | }; |
| 187 | |
Makoto Onuki | 53f0e02 | 2017-11-29 13:51:01 -0800 | [diff] [blame] | 188 | public static final int SETTINGS_TYPE_GLOBAL = SettingsState.SETTINGS_TYPE_GLOBAL; |
| 189 | public static final int SETTINGS_TYPE_SYSTEM = SettingsState.SETTINGS_TYPE_SYSTEM; |
| 190 | public static final int SETTINGS_TYPE_SECURE = SettingsState.SETTINGS_TYPE_SECURE; |
| 191 | public static final int SETTINGS_TYPE_SSAID = SettingsState.SETTINGS_TYPE_SSAID; |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 192 | public static final int SETTINGS_TYPE_CONFIG = SettingsState.SETTINGS_TYPE_CONFIG; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 193 | |
| 194 | private static final Bundle NULL_SETTING_BUNDLE = Bundle.forPair( |
| 195 | Settings.NameValueTable.VALUE, null); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 196 | |
Nicholas Sauer | 3d87d1e | 2018-11-06 08:38:39 -0800 | [diff] [blame] | 197 | public static final String RESULT_ROWS_DELETED = "result_rows_deleted"; |
Nicholas Sauer | 7250053 | 2018-11-21 10:30:58 -0800 | [diff] [blame] | 198 | public static final String RESULT_SETTINGS_LIST = "result_settings_list"; |
Nicholas Sauer | 3d87d1e | 2018-11-06 08:38:39 -0800 | [diff] [blame] | 199 | |
Chad Brubaker | 20e0dc3 | 2017-04-28 18:24:55 -0700 | [diff] [blame] | 200 | // Overlay specified settings whitelisted for Instant Apps |
| 201 | private static final Set<String> OVERLAY_ALLOWED_GLOBAL_INSTANT_APP_SETTINGS = new ArraySet<>(); |
| 202 | private static final Set<String> OVERLAY_ALLOWED_SYSTEM_INSTANT_APP_SETTINGS = new ArraySet<>(); |
| 203 | private static final Set<String> OVERLAY_ALLOWED_SECURE_INSTANT_APP_SETTINGS = new ArraySet<>(); |
| 204 | |
| 205 | static { |
| 206 | for (String name : Resources.getSystem().getStringArray( |
| 207 | com.android.internal.R.array.config_allowedGlobalInstantAppSettings)) { |
| 208 | OVERLAY_ALLOWED_GLOBAL_INSTANT_APP_SETTINGS.add(name); |
| 209 | } |
| 210 | for (String name : Resources.getSystem().getStringArray( |
| 211 | com.android.internal.R.array.config_allowedSystemInstantAppSettings)) { |
| 212 | OVERLAY_ALLOWED_SYSTEM_INSTANT_APP_SETTINGS.add(name); |
| 213 | } |
| 214 | for (String name : Resources.getSystem().getStringArray( |
| 215 | com.android.internal.R.array.config_allowedSecureInstantAppSettings)) { |
| 216 | OVERLAY_ALLOWED_SECURE_INSTANT_APP_SETTINGS.add(name); |
| 217 | } |
| 218 | } |
| 219 | |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 220 | // Changes to these global settings are synchronously persisted |
| 221 | private static final Set<String> CRITICAL_GLOBAL_SETTINGS = new ArraySet<>(); |
| 222 | static { |
| 223 | CRITICAL_GLOBAL_SETTINGS.add(Settings.Global.DEVICE_PROVISIONED); |
| 224 | } |
| 225 | |
| 226 | // Changes to these secure settings are synchronously persisted |
| 227 | private static final Set<String> CRITICAL_SECURE_SETTINGS = new ArraySet<>(); |
| 228 | static { |
| 229 | CRITICAL_SECURE_SETTINGS.add(Settings.Secure.USER_SETUP_COMPLETE); |
| 230 | } |
| 231 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 232 | // Per user secure settings that moved to the for all users global settings. |
| 233 | static final Set<String> sSecureMovedToGlobalSettings = new ArraySet<>(); |
| 234 | static { |
| 235 | Settings.Secure.getMovedToGlobalSettings(sSecureMovedToGlobalSettings); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 238 | // Per user system settings that moved to the for all users global settings. |
| 239 | static final Set<String> sSystemMovedToGlobalSettings = new ArraySet<>(); |
| 240 | static { |
| 241 | Settings.System.getMovedToGlobalSettings(sSystemMovedToGlobalSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 244 | // Per user system settings that moved to the per user secure settings. |
| 245 | static final Set<String> sSystemMovedToSecureSettings = new ArraySet<>(); |
| 246 | static { |
| 247 | Settings.System.getMovedToSecureSettings(sSystemMovedToSecureSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 250 | // Per all users global settings that moved to the per user secure settings. |
| 251 | static final Set<String> sGlobalMovedToSecureSettings = new ArraySet<>(); |
| 252 | static { |
| 253 | Settings.Global.getMovedToSecureSettings(sGlobalMovedToSecureSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 256 | // Per user secure settings that are cloned for the managed profiles of the user. |
| 257 | private static final Set<String> sSecureCloneToManagedSettings = new ArraySet<>(); |
| 258 | static { |
| 259 | Settings.Secure.getCloneToManagedProfileSettings(sSecureCloneToManagedSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 262 | // Per user system settings that are cloned for the managed profiles of the user. |
| 263 | private static final Set<String> sSystemCloneToManagedSettings = new ArraySet<>(); |
| 264 | static { |
| 265 | Settings.System.getCloneToManagedProfileSettings(sSystemCloneToManagedSettings); |
Julia Reynolds | 5e458dd | 2014-07-07 16:07:01 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 268 | // Per user system settings that are cloned from the profile's parent when a dependency |
| 269 | // in {@link Settings.Secure} is set to "1". |
| 270 | public static final Map<String, String> sSystemCloneFromParentOnDependency = new ArrayMap<>(); |
| 271 | static { |
| 272 | Settings.System.getCloneFromParentOnValueSettings(sSystemCloneFromParentOnDependency); |
| 273 | } |
| 274 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 275 | private final Object mLock = new Object(); |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 276 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 277 | @GuardedBy("mLock") |
| 278 | private SettingsRegistry mSettingsRegistry; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 279 | |
Svet Ganov | a8f9026 | 2016-05-10 08:44:48 -0700 | [diff] [blame] | 280 | @GuardedBy("mLock") |
| 281 | private HandlerThread mHandlerThread; |
| 282 | |
Makoto Onuki | 73360ab | 2017-03-17 11:50:13 -0700 | [diff] [blame] | 283 | @GuardedBy("mLock") |
| 284 | private Handler mHandler; |
| 285 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 286 | // We have to call in the user manager with no lock held, |
| 287 | private volatile UserManager mUserManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 288 | |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 289 | private UserManagerInternal mUserManagerInternal; |
| 290 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 291 | // We have to call in the package manager with no lock held, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 292 | private volatile IPackageManager mPackageManager; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 293 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 294 | public static int makeKey(int type, int userId) { |
Makoto Onuki | 53f0e02 | 2017-11-29 13:51:01 -0800 | [diff] [blame] | 295 | return SettingsState.makeKey(type, userId); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | public static int getTypeFromKey(int key) { |
Makoto Onuki | 53f0e02 | 2017-11-29 13:51:01 -0800 | [diff] [blame] | 299 | return SettingsState.getTypeFromKey(key); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | public static int getUserIdFromKey(int key) { |
Makoto Onuki | 53f0e02 | 2017-11-29 13:51:01 -0800 | [diff] [blame] | 303 | return SettingsState.getUserIdFromKey(key); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | public static String settingTypeToString(int type) { |
Makoto Onuki | 53f0e02 | 2017-11-29 13:51:01 -0800 | [diff] [blame] | 307 | return SettingsState.settingTypeToString(type); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | public static String keyToString(int key) { |
Makoto Onuki | 53f0e02 | 2017-11-29 13:51:01 -0800 | [diff] [blame] | 311 | return SettingsState.keyToString(key); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 312 | } |
| 313 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | @Override |
| 315 | public boolean onCreate() { |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 316 | Settings.setInSystemServer(); |
Michal Karpinski | 2c37b08 | 2018-01-18 16:14:27 +0000 | [diff] [blame] | 317 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 318 | synchronized (mLock) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 319 | mUserManager = UserManager.get(getContext()); |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 320 | mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 321 | mPackageManager = AppGlobals.getPackageManager(); |
Svet Ganov | a8f9026 | 2016-05-10 08:44:48 -0700 | [diff] [blame] | 322 | mHandlerThread = new HandlerThread(LOG_TAG, |
| 323 | Process.THREAD_PRIORITY_BACKGROUND); |
| 324 | mHandlerThread.start(); |
Makoto Onuki | 73360ab | 2017-03-17 11:50:13 -0700 | [diff] [blame] | 325 | mHandler = new Handler(mHandlerThread.getLooper()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 326 | mSettingsRegistry = new SettingsRegistry(); |
| 327 | } |
Makoto Onuki | 73360ab | 2017-03-17 11:50:13 -0700 | [diff] [blame] | 328 | mHandler.post(() -> { |
| 329 | registerBroadcastReceivers(); |
| 330 | startWatchingUserRestrictionChanges(); |
| 331 | }); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 332 | ServiceManager.addService("settings", new SettingsService(this)); |
Matt Pape | abb6789 | 2018-12-07 09:13:26 -0800 | [diff] [blame] | 333 | ServiceManager.addService("device_config", new DeviceConfigService(this)); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 334 | return true; |
| 335 | } |
| 336 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 337 | @Override |
| 338 | public Bundle call(String method, String name, Bundle args) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 339 | final int requestingUserId = getRequestingUserId(args); |
| 340 | switch (method) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 341 | case Settings.CALL_METHOD_GET_CONFIG: { |
| 342 | Setting setting = getConfigSetting(name); |
| 343 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
| 344 | } |
| 345 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 346 | case Settings.CALL_METHOD_GET_GLOBAL: { |
| 347 | Setting setting = getGlobalSetting(name); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 348 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 349 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 350 | |
| 351 | case Settings.CALL_METHOD_GET_SECURE: { |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 352 | Setting setting = getSecureSetting(name, requestingUserId, |
| 353 | /*enableOverride=*/ true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 354 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | case Settings.CALL_METHOD_GET_SYSTEM: { |
| 358 | Setting setting = getSystemSetting(name, requestingUserId); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 359 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 362 | case Settings.CALL_METHOD_PUT_CONFIG: { |
| 363 | String value = getSettingValue(args); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 364 | final boolean makeDefault = getSettingMakeDefault(args); |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 365 | insertConfigSetting(name, value, makeDefault); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 366 | break; |
| 367 | } |
| 368 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 369 | case Settings.CALL_METHOD_PUT_GLOBAL: { |
| 370 | String value = getSettingValue(args); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 371 | String tag = getSettingTag(args); |
| 372 | final boolean makeDefault = getSettingMakeDefault(args); |
| 373 | insertGlobalSetting(name, value, tag, makeDefault, requestingUserId, false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 374 | break; |
| 375 | } |
| 376 | |
| 377 | case Settings.CALL_METHOD_PUT_SECURE: { |
| 378 | String value = getSettingValue(args); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 379 | String tag = getSettingTag(args); |
| 380 | final boolean makeDefault = getSettingMakeDefault(args); |
| 381 | insertSecureSetting(name, value, tag, makeDefault, requestingUserId, false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 382 | break; |
| 383 | } |
| 384 | |
| 385 | case Settings.CALL_METHOD_PUT_SYSTEM: { |
| 386 | String value = getSettingValue(args); |
| 387 | insertSystemSetting(name, value, requestingUserId); |
| 388 | break; |
| 389 | } |
| 390 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 391 | case Settings.CALL_METHOD_RESET_CONFIG: { |
| 392 | final int mode = getResetModeEnforcingPermission(args); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 393 | String prefix = getSettingPrefix(args); |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 394 | resetConfigSetting(mode, prefix); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 395 | break; |
| 396 | } |
| 397 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 398 | case Settings.CALL_METHOD_RESET_GLOBAL: { |
| 399 | final int mode = getResetModeEnforcingPermission(args); |
| 400 | String tag = getSettingTag(args); |
| 401 | resetGlobalSetting(requestingUserId, mode, tag); |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | case Settings.CALL_METHOD_RESET_SECURE: { |
| 406 | final int mode = getResetModeEnforcingPermission(args); |
| 407 | String tag = getSettingTag(args); |
| 408 | resetSecureSetting(requestingUserId, mode, tag); |
| 409 | break; |
| 410 | } |
| 411 | |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 412 | case Settings.CALL_METHOD_DELETE_CONFIG: { |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 413 | int rows = deleteConfigSetting(name) ? 1 : 0; |
Nicholas Sauer | 3d87d1e | 2018-11-06 08:38:39 -0800 | [diff] [blame] | 414 | Bundle result = new Bundle(); |
| 415 | result.putInt(RESULT_ROWS_DELETED, rows); |
| 416 | return result; |
| 417 | } |
| 418 | |
| 419 | case Settings.CALL_METHOD_DELETE_GLOBAL: { |
| 420 | int rows = deleteGlobalSetting(name, requestingUserId, false) ? 1 : 0; |
| 421 | Bundle result = new Bundle(); |
| 422 | result.putInt(RESULT_ROWS_DELETED, rows); |
| 423 | return result; |
| 424 | } |
| 425 | |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 426 | case Settings.CALL_METHOD_DELETE_SECURE: { |
| 427 | int rows = deleteSecureSetting(name, requestingUserId, false) ? 1 : 0; |
| 428 | Bundle result = new Bundle(); |
| 429 | result.putInt(RESULT_ROWS_DELETED, rows); |
| 430 | return result; |
| 431 | } |
| 432 | |
| 433 | case Settings.CALL_METHOD_DELETE_SYSTEM: { |
| 434 | int rows = deleteSystemSetting(name, requestingUserId) ? 1 : 0; |
| 435 | Bundle result = new Bundle(); |
| 436 | result.putInt(RESULT_ROWS_DELETED, rows); |
| 437 | return result; |
| 438 | } |
| 439 | |
| 440 | case Settings.CALL_METHOD_LIST_CONFIG: { |
| 441 | String prefix = getSettingPrefix(args); |
Matt Pape | 793b15c | 2019-10-07 13:17:20 -0700 | [diff] [blame] | 442 | return packageValuesForCallResult(getAllConfigFlags(prefix), |
| 443 | isTrackingGeneration(args)); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | case Settings.CALL_METHOD_LIST_GLOBAL: { |
Nicholas Sauer | 7250053 | 2018-11-21 10:30:58 -0800 | [diff] [blame] | 447 | Bundle result = new Bundle(); |
| 448 | result.putStringArrayList(RESULT_SETTINGS_LIST, |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 449 | buildSettingsList(getAllGlobalSettings(null))); |
Nicholas Sauer | 7250053 | 2018-11-21 10:30:58 -0800 | [diff] [blame] | 450 | return result; |
| 451 | } |
| 452 | |
| 453 | case Settings.CALL_METHOD_LIST_SECURE: { |
| 454 | Bundle result = new Bundle(); |
| 455 | result.putStringArrayList(RESULT_SETTINGS_LIST, |
| 456 | buildSettingsList(getAllSecureSettings(requestingUserId, null))); |
| 457 | return result; |
| 458 | } |
| 459 | |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 460 | case Settings.CALL_METHOD_LIST_SYSTEM: { |
Nicholas Sauer | 7250053 | 2018-11-21 10:30:58 -0800 | [diff] [blame] | 461 | Bundle result = new Bundle(); |
| 462 | result.putStringArrayList(RESULT_SETTINGS_LIST, |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 463 | buildSettingsList(getAllSystemSettings(requestingUserId, null))); |
Nicholas Sauer | 7250053 | 2018-11-21 10:30:58 -0800 | [diff] [blame] | 464 | return result; |
| 465 | } |
| 466 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 467 | default: { |
| 468 | Slog.w(LOG_TAG, "call() with invalid method: " + method); |
| 469 | } break; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 470 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 471 | |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 472 | return null; |
| 473 | } |
| 474 | |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 475 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 476 | public String getType(Uri uri) { |
| 477 | Arguments args = new Arguments(uri, null, null, true); |
| 478 | if (TextUtils.isEmpty(args.name)) { |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 479 | return "vnd.android.cursor.dir/" + args.table; |
| 480 | } else { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 481 | return "vnd.android.cursor.item/" + args.table; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
| 485 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 486 | public Cursor query(Uri uri, String[] projection, String where, String[] whereArgs, |
| 487 | String order) { |
| 488 | if (DEBUG) { |
| 489 | Slog.v(LOG_TAG, "query() for user: " + UserHandle.getCallingUserId()); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 492 | Arguments args = new Arguments(uri, where, whereArgs, true); |
| 493 | String[] normalizedProjection = normalizeProjection(projection); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 494 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 495 | // If a legacy table that is gone, done. |
| 496 | if (REMOVED_LEGACY_TABLES.contains(args.table)) { |
| 497 | return new MatrixCursor(normalizedProjection, 0); |
| 498 | } |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 499 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 500 | switch (args.table) { |
| 501 | case TABLE_GLOBAL: { |
| 502 | if (args.name != null) { |
| 503 | Setting setting = getGlobalSetting(args.name); |
| 504 | return packageSettingForQuery(setting, normalizedProjection); |
| 505 | } else { |
| 506 | return getAllGlobalSettings(projection); |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 507 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 508 | } |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 509 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 510 | case TABLE_SECURE: { |
| 511 | final int userId = UserHandle.getCallingUserId(); |
| 512 | if (args.name != null) { |
| 513 | Setting setting = getSecureSetting(args.name, userId); |
| 514 | return packageSettingForQuery(setting, normalizedProjection); |
| 515 | } else { |
| 516 | return getAllSecureSettings(userId, projection); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 517 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 518 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 519 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 520 | case TABLE_SYSTEM: { |
| 521 | final int userId = UserHandle.getCallingUserId(); |
| 522 | if (args.name != null) { |
| 523 | Setting setting = getSystemSetting(args.name, userId); |
| 524 | return packageSettingForQuery(setting, normalizedProjection); |
| 525 | } else { |
| 526 | return getAllSystemSettings(userId, projection); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 527 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 528 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 529 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 530 | default: { |
| 531 | throw new IllegalArgumentException("Invalid Uri path:" + uri); |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Nicholas Sauer | 7250053 | 2018-11-21 10:30:58 -0800 | [diff] [blame] | 536 | private ArrayList<String> buildSettingsList(Cursor cursor) { |
| 537 | final ArrayList<String> lines = new ArrayList<String>(); |
| 538 | try { |
| 539 | while (cursor != null && cursor.moveToNext()) { |
| 540 | lines.add(cursor.getString(1) + "=" + cursor.getString(2)); |
| 541 | } |
| 542 | } finally { |
| 543 | if (cursor != null) { |
| 544 | cursor.close(); |
| 545 | } |
| 546 | } |
| 547 | return lines; |
| 548 | } |
| 549 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 550 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 551 | public Uri insert(Uri uri, ContentValues values) { |
| 552 | if (DEBUG) { |
| 553 | Slog.v(LOG_TAG, "insert() for user: " + UserHandle.getCallingUserId()); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 556 | String table = getValidTableOrThrow(uri); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 557 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 558 | // If a legacy table that is gone, done. |
| 559 | if (REMOVED_LEGACY_TABLES.contains(table)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | return null; |
| 561 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 562 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 563 | String name = values.getAsString(Settings.Secure.NAME); |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 564 | if (!isKeyValid(name)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 565 | return null; |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 568 | String value = values.getAsString(Settings.Secure.VALUE); |
| 569 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 570 | switch (table) { |
| 571 | case TABLE_GLOBAL: { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 572 | if (insertGlobalSetting(name, value, null, false, |
| 573 | UserHandle.getCallingUserId(), false)) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 574 | return Uri.withAppendedPath(Settings.Global.CONTENT_URI, name); |
Christopher Tate | c221d2b | 2012-10-03 18:33:52 -0700 | [diff] [blame] | 575 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 576 | } break; |
| 577 | |
| 578 | case TABLE_SECURE: { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 579 | if (insertSecureSetting(name, value, null, false, |
| 580 | UserHandle.getCallingUserId(), false)) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 581 | return Uri.withAppendedPath(Settings.Secure.CONTENT_URI, name); |
| 582 | } |
| 583 | } break; |
| 584 | |
| 585 | case TABLE_SYSTEM: { |
| 586 | if (insertSystemSetting(name, value, UserHandle.getCallingUserId())) { |
| 587 | return Uri.withAppendedPath(Settings.System.CONTENT_URI, name); |
| 588 | } |
| 589 | } break; |
| 590 | |
| 591 | default: { |
| 592 | throw new IllegalArgumentException("Bad Uri path:" + uri); |
Christopher Tate | c221d2b | 2012-10-03 18:33:52 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 596 | return null; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 600 | public int bulkInsert(Uri uri, ContentValues[] allValues) { |
| 601 | if (DEBUG) { |
| 602 | Slog.v(LOG_TAG, "bulkInsert() for user: " + UserHandle.getCallingUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 604 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 605 | int insertionCount = 0; |
| 606 | final int valuesCount = allValues.length; |
| 607 | for (int i = 0; i < valuesCount; i++) { |
| 608 | ContentValues values = allValues[i]; |
| 609 | if (insert(uri, values) != null) { |
| 610 | insertionCount++; |
| 611 | } |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 612 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 613 | |
| 614 | return insertionCount; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 618 | public int delete(Uri uri, String where, String[] whereArgs) { |
| 619 | if (DEBUG) { |
| 620 | Slog.v(LOG_TAG, "delete() for user: " + UserHandle.getCallingUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 622 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 623 | Arguments args = new Arguments(uri, where, whereArgs, false); |
| 624 | |
| 625 | // If a legacy table that is gone, done. |
| 626 | if (REMOVED_LEGACY_TABLES.contains(args.table)) { |
| 627 | return 0; |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 628 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 629 | |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 630 | if (!isKeyValid(args.name)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 631 | return 0; |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 632 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 633 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 634 | switch (args.table) { |
| 635 | case TABLE_GLOBAL: { |
| 636 | final int userId = UserHandle.getCallingUserId(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 637 | return deleteGlobalSetting(args.name, userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 638 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 639 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 640 | case TABLE_SECURE: { |
| 641 | final int userId = UserHandle.getCallingUserId(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 642 | return deleteSecureSetting(args.name, userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 643 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 644 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 645 | case TABLE_SYSTEM: { |
| 646 | final int userId = UserHandle.getCallingUserId(); |
| 647 | return deleteSystemSetting(args.name, userId) ? 1 : 0; |
| 648 | } |
| 649 | |
| 650 | default: { |
| 651 | throw new IllegalArgumentException("Bad Uri path:" + uri); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 652 | } |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 653 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | @Override |
| 657 | public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { |
| 658 | if (DEBUG) { |
| 659 | Slog.v(LOG_TAG, "update() for user: " + UserHandle.getCallingUserId()); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 660 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 661 | |
| 662 | Arguments args = new Arguments(uri, where, whereArgs, false); |
| 663 | |
| 664 | // If a legacy table that is gone, done. |
| 665 | if (REMOVED_LEGACY_TABLES.contains(args.table)) { |
| 666 | return 0; |
| 667 | } |
| 668 | |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 669 | String name = values.getAsString(Settings.Secure.NAME); |
| 670 | if (!isKeyValid(name)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 671 | return 0; |
| 672 | } |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 673 | String value = values.getAsString(Settings.Secure.VALUE); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 674 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 675 | switch (args.table) { |
| 676 | case TABLE_GLOBAL: { |
| 677 | final int userId = UserHandle.getCallingUserId(); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 678 | return updateGlobalSetting(args.name, value, null, false, |
| 679 | userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 680 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 681 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 682 | case TABLE_SECURE: { |
| 683 | final int userId = UserHandle.getCallingUserId(); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 684 | return updateSecureSetting(args.name, value, null, false, |
| 685 | userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 686 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 687 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 688 | case TABLE_SYSTEM: { |
| 689 | final int userId = UserHandle.getCallingUserId(); |
| 690 | return updateSystemSetting(args.name, value, userId) ? 1 : 0; |
| 691 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 692 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 693 | default: { |
| 694 | throw new IllegalArgumentException("Invalid Uri path:" + uri); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 695 | } |
| 696 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | @Override |
| 700 | public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { |
Robin Lee | 2ab02e2 | 2016-07-28 18:41:23 +0100 | [diff] [blame] | 701 | final int userId = getUserIdFromUri(uri, UserHandle.getCallingUserId()); |
| 702 | if (userId != UserHandle.getCallingUserId()) { |
| 703 | getContext().enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS, |
| 704 | "Access files from the settings of another user"); |
| 705 | } |
| 706 | uri = ContentProvider.getUriWithoutUserId(uri); |
| 707 | |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 708 | final String cacheRingtoneSetting; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 709 | final String cacheName; |
| 710 | if (Settings.System.RINGTONE_CACHE_URI.equals(uri)) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 711 | cacheRingtoneSetting = Settings.System.RINGTONE; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 712 | cacheName = Settings.System.RINGTONE_CACHE; |
| 713 | } else if (Settings.System.NOTIFICATION_SOUND_CACHE_URI.equals(uri)) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 714 | cacheRingtoneSetting = Settings.System.NOTIFICATION_SOUND; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 715 | cacheName = Settings.System.NOTIFICATION_SOUND_CACHE; |
| 716 | } else if (Settings.System.ALARM_ALERT_CACHE_URI.equals(uri)) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 717 | cacheRingtoneSetting = Settings.System.ALARM_ALERT; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 718 | cacheName = Settings.System.ALARM_ALERT_CACHE; |
| 719 | } else { |
| 720 | throw new FileNotFoundException("Direct file access no longer supported; " |
| 721 | + "ringtone playback is available through android.media.Ringtone"); |
| 722 | } |
| 723 | |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 724 | int actualCacheOwner; |
| 725 | // Redirect cache to parent if ringtone setting is owned by profile parent |
| 726 | synchronized (mLock) { |
| 727 | actualCacheOwner = resolveOwningUserIdForSystemSettingLocked(userId, |
| 728 | cacheRingtoneSetting); |
| 729 | } |
| 730 | final File cacheFile = new File(getRingtoneCacheDir(actualCacheOwner), cacheName); |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 731 | return ParcelFileDescriptor.open(cacheFile, ParcelFileDescriptor.parseMode(mode)); |
| 732 | } |
| 733 | |
| 734 | private File getRingtoneCacheDir(int userId) { |
| 735 | final File cacheDir = new File(Environment.getDataSystemDeDirectory(userId), "ringtones"); |
| 736 | cacheDir.mkdir(); |
| 737 | SELinux.restorecon(cacheDir); |
| 738 | return cacheDir; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 739 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 740 | |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 741 | /** |
| 742 | * Dump all settings as a proto buf. |
| 743 | * |
| 744 | * @param fd The file to dump to |
| 745 | */ |
| 746 | void dumpProto(@NonNull FileDescriptor fd) { |
| 747 | ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 748 | |
| 749 | synchronized (mLock) { |
| 750 | SettingsProtoDumpUtil.dumpProtoLocked(mSettingsRegistry, proto); |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | proto.flush(); |
| 754 | } |
| 755 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 756 | public void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) { |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 757 | synchronized (mLock) { |
| 758 | final long identity = Binder.clearCallingIdentity(); |
| 759 | try { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 760 | SparseBooleanArray users = mSettingsRegistry.getKnownUsersLocked(); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 761 | final int userCount = users.size(); |
| 762 | for (int i = 0; i < userCount; i++) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 763 | dumpForUserLocked(users.keyAt(i), pw); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 764 | } |
| 765 | } finally { |
| 766 | Binder.restoreCallingIdentity(identity); |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
Andreas Gampe | b5889307 | 2018-09-05 16:52:31 -0700 | [diff] [blame] | 771 | @GuardedBy("mLock") |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 772 | private void dumpForUserLocked(int userId, PrintWriter pw) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 773 | if (userId == UserHandle.USER_SYSTEM) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 774 | pw.println("CONFIG SETTINGS (user " + userId + ")"); |
| 775 | SettingsState configSettings = mSettingsRegistry.getSettingsLocked( |
| 776 | SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM); |
| 777 | if (configSettings != null) { |
| 778 | dumpSettingsLocked(configSettings, pw); |
| 779 | pw.println(); |
| 780 | configSettings.dumpHistoricalOperations(pw); |
| 781 | } |
| 782 | |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 783 | pw.println("GLOBAL SETTINGS (user " + userId + ")"); |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 784 | SettingsState globalSettings = mSettingsRegistry.getSettingsLocked( |
| 785 | SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 786 | if (globalSettings != null) { |
| 787 | dumpSettingsLocked(globalSettings, pw); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 788 | pw.println(); |
| 789 | globalSettings.dumpHistoricalOperations(pw); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 790 | } |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | pw.println("SECURE SETTINGS (user " + userId + ")"); |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 794 | SettingsState secureSettings = mSettingsRegistry.getSettingsLocked( |
| 795 | SETTINGS_TYPE_SECURE, userId); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 796 | if (secureSettings != null) { |
| 797 | dumpSettingsLocked(secureSettings, pw); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 798 | pw.println(); |
| 799 | secureSettings.dumpHistoricalOperations(pw); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 800 | } |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 801 | |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 802 | pw.println("SYSTEM SETTINGS (user " + userId + ")"); |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 803 | SettingsState systemSettings = mSettingsRegistry.getSettingsLocked( |
| 804 | SETTINGS_TYPE_SYSTEM, userId); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 805 | if (systemSettings != null) { |
| 806 | dumpSettingsLocked(systemSettings, pw); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 807 | pw.println(); |
| 808 | systemSettings.dumpHistoricalOperations(pw); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 809 | } |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 810 | } |
| 811 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 812 | private void dumpSettingsLocked(SettingsState settingsState, PrintWriter pw) { |
| 813 | List<String> names = settingsState.getSettingNamesLocked(); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 814 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 815 | final int nameCount = names.size(); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 816 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 817 | for (int i = 0; i < nameCount; i++) { |
| 818 | String name = names.get(i); |
| 819 | Setting setting = settingsState.getSettingLocked(name); |
| 820 | pw.print("_id:"); pw.print(toDumpString(setting.getId())); |
| 821 | pw.print(" name:"); pw.print(toDumpString(name)); |
| 822 | if (setting.getPackageName() != null) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 823 | pw.print(" pkg:"); pw.print(setting.getPackageName()); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 824 | } |
| 825 | pw.print(" value:"); pw.print(toDumpString(setting.getValue())); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 826 | if (setting.getDefaultValue() != null) { |
| 827 | pw.print(" default:"); pw.print(setting.getDefaultValue()); |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 828 | pw.print(" defaultSystemSet:"); pw.print(setting.isDefaultFromSystem()); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 829 | } |
| 830 | if (setting.getTag() != null) { |
| 831 | pw.print(" tag:"); pw.print(setting.getTag()); |
| 832 | } |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 833 | pw.println(); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 834 | } |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 835 | } |
| 836 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 837 | private static String toDumpString(String s) { |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 838 | if (s != null) { |
| 839 | return s; |
| 840 | } |
| 841 | return "{null}"; |
| 842 | } |
| 843 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 844 | private void registerBroadcastReceivers() { |
| 845 | IntentFilter userFilter = new IntentFilter(); |
| 846 | userFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 847 | userFilter.addAction(Intent.ACTION_USER_STOPPED); |
| 848 | |
| 849 | getContext().registerReceiver(new BroadcastReceiver() { |
| 850 | @Override |
| 851 | public void onReceive(Context context, Intent intent) { |
| 852 | final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 853 | UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 854 | |
| 855 | switch (intent.getAction()) { |
| 856 | case Intent.ACTION_USER_REMOVED: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 857 | synchronized (mLock) { |
| 858 | mSettingsRegistry.removeUserStateLocked(userId, true); |
| 859 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 860 | } break; |
| 861 | |
| 862 | case Intent.ACTION_USER_STOPPED: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 863 | synchronized (mLock) { |
| 864 | mSettingsRegistry.removeUserStateLocked(userId, false); |
| 865 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 866 | } break; |
| 867 | } |
| 868 | } |
| 869 | }, userFilter); |
| 870 | |
| 871 | PackageMonitor monitor = new PackageMonitor() { |
| 872 | @Override |
| 873 | public void onPackageRemoved(String packageName, int uid) { |
| 874 | synchronized (mLock) { |
Zimuzo | c56192c | 2018-07-25 10:40:01 +0100 | [diff] [blame] | 875 | mSettingsRegistry.removeSettingsForPackageLocked(packageName, |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 876 | UserHandle.getUserId(uid)); |
| 877 | } |
| 878 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 879 | |
| 880 | @Override |
| 881 | public void onUidRemoved(int uid) { |
| 882 | synchronized (mLock) { |
| 883 | mSettingsRegistry.onUidRemovedLocked(uid); |
| 884 | } |
| 885 | } |
Zimuzo | c56192c | 2018-07-25 10:40:01 +0100 | [diff] [blame] | 886 | |
| 887 | @Override |
| 888 | public void onPackageDataCleared(String packageName, int uid) { |
| 889 | synchronized (mLock) { |
| 890 | mSettingsRegistry.removeSettingsForPackageLocked(packageName, |
| 891 | UserHandle.getUserId(uid)); |
| 892 | } |
| 893 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 894 | }; |
| 895 | |
| 896 | // package changes |
| 897 | monitor.register(getContext(), BackgroundThread.getHandler().getLooper(), |
| 898 | UserHandle.ALL, true); |
| 899 | } |
| 900 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 901 | private void startWatchingUserRestrictionChanges() { |
| 902 | // TODO: The current design of settings looking different based on user restrictions |
| 903 | // should be reworked to keep them separate and system code should check the setting |
| 904 | // first followed by checking the user restriction before performing an operation. |
| 905 | UserManagerInternal userManager = LocalServices.getService(UserManagerInternal.class); |
| 906 | userManager.addUserRestrictionsListener((int userId, Bundle newRestrictions, |
| 907 | Bundle prevRestrictions) -> { |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 908 | Set<String> changedRestrictions = getRestrictionDiff(prevRestrictions, newRestrictions); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 909 | // We are changing the settings affected by restrictions to their current |
| 910 | // value with a forced update to ensure that all cross profile dependencies |
| 911 | // are taken into account. Also make sure the settings update to.. the same |
| 912 | // value passes the security checks, so clear binder calling id. |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 913 | if (changedRestrictions.contains(UserManager.DISALLOW_SHARE_LOCATION)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 914 | final long identity = Binder.clearCallingIdentity(); |
| 915 | try { |
| 916 | synchronized (mLock) { |
| 917 | Setting setting = getSecureSetting( |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 918 | Settings.Secure.LOCATION_MODE, userId); |
| 919 | updateSecureSetting(Settings.Secure.LOCATION_MODE, |
| 920 | setting != null ? setting.getValue() : null, null, |
| 921 | true, userId, true); |
| 922 | setting = getSecureSetting( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 923 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED, userId); |
| 924 | updateSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 925 | setting != null ? setting.getValue() : null, null, |
| 926 | true, userId, true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 927 | } |
| 928 | } finally { |
| 929 | Binder.restoreCallingIdentity(identity); |
| 930 | } |
| 931 | } |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 932 | if (changedRestrictions.contains(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) |
| 933 | || changedRestrictions.contains( |
Irina Dumitrescu | 4638edd | 2018-09-05 14:08:33 +0100 | [diff] [blame] | 934 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 935 | final long identity = Binder.clearCallingIdentity(); |
| 936 | try { |
| 937 | synchronized (mLock) { |
| 938 | Setting setting = getGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 939 | String value = setting != null ? setting.getValue() : null; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 940 | updateGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 941 | value, null, true, userId, true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 942 | } |
| 943 | } finally { |
| 944 | Binder.restoreCallingIdentity(identity); |
| 945 | } |
| 946 | } |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 947 | if (changedRestrictions.contains(UserManager.DISALLOW_DEBUGGING_FEATURES)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 948 | final long identity = Binder.clearCallingIdentity(); |
| 949 | try { |
| 950 | synchronized (mLock) { |
| 951 | Setting setting = getGlobalSetting(Settings.Global.ADB_ENABLED); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 952 | String value = setting != null ? setting.getValue() : null; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 953 | updateGlobalSetting(Settings.Global.ADB_ENABLED, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 954 | value, null, true, userId, true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 955 | } |
| 956 | } finally { |
| 957 | Binder.restoreCallingIdentity(identity); |
| 958 | } |
| 959 | } |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 960 | if (changedRestrictions.contains(UserManager.ENSURE_VERIFY_APPS)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 961 | final long identity = Binder.clearCallingIdentity(); |
| 962 | try { |
| 963 | synchronized (mLock) { |
| 964 | Setting enable = getGlobalSetting( |
| 965 | Settings.Global.PACKAGE_VERIFIER_ENABLE); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 966 | String enableValue = enable != null ? enable.getValue() : null; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 967 | updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_ENABLE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 968 | enableValue, null, true, userId, true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 969 | Setting include = getGlobalSetting( |
| 970 | Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 971 | String includeValue = include != null ? include.getValue() : null; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 972 | updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 973 | includeValue, null, true, userId, true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 974 | } |
| 975 | } finally { |
| 976 | Binder.restoreCallingIdentity(identity); |
| 977 | } |
| 978 | } |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 979 | if (changedRestrictions.contains(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 980 | final long identity = Binder.clearCallingIdentity(); |
| 981 | try { |
| 982 | synchronized (mLock) { |
| 983 | Setting setting = getGlobalSetting( |
| 984 | Settings.Global.PREFERRED_NETWORK_MODE); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 985 | String value = setting != null ? setting.getValue() : null; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 986 | updateGlobalSetting(Settings.Global.PREFERRED_NETWORK_MODE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 987 | value, null, true, userId, true); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 988 | } |
| 989 | } finally { |
| 990 | Binder.restoreCallingIdentity(identity); |
| 991 | } |
| 992 | } |
| 993 | }); |
| 994 | } |
| 995 | |
Irina Dumitrescu | e369687 | 2019-01-09 16:07:59 +0000 | [diff] [blame] | 996 | private static Set<String> getRestrictionDiff(Bundle prevRestrictions, Bundle newRestrictions) { |
| 997 | Set<String> restrictionNames = Sets.newArraySet(); |
| 998 | restrictionNames.addAll(prevRestrictions.keySet()); |
| 999 | restrictionNames.addAll(newRestrictions.keySet()); |
| 1000 | Set<String> diff = Sets.newArraySet(); |
| 1001 | for (String restrictionName : restrictionNames) { |
| 1002 | if (prevRestrictions.getBoolean(restrictionName) != newRestrictions.getBoolean( |
| 1003 | restrictionName)) { |
| 1004 | diff.add(restrictionName); |
| 1005 | } |
| 1006 | } |
| 1007 | return diff; |
| 1008 | } |
| 1009 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1010 | private Setting getConfigSetting(String name) { |
| 1011 | if (DEBUG) { |
| 1012 | Slog.v(LOG_TAG, "getConfigSetting(" + name + ")"); |
| 1013 | } |
| 1014 | |
Stanislav Zholnin | 5579950 | 2019-03-08 14:54:55 +0000 | [diff] [blame] | 1015 | DeviceConfig.enforceReadPermission(getContext(), /*namespace=*/name.split("/")[0]); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1016 | |
| 1017 | // Get the value. |
| 1018 | synchronized (mLock) { |
| 1019 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_CONFIG, |
| 1020 | UserHandle.USER_SYSTEM, name); |
| 1021 | } |
| 1022 | } |
| 1023 | |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1024 | private boolean insertConfigSetting(String name, String value, boolean makeDefault) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1025 | if (DEBUG) { |
| 1026 | Slog.v(LOG_TAG, "insertConfigSetting(" + name + ", " + value + ", " |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1027 | + makeDefault + ")"); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1028 | } |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1029 | return mutateConfigSetting(name, value, null, makeDefault, |
| 1030 | MUTATION_OPERATION_INSERT, 0); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1033 | private boolean deleteConfigSetting(String name) { |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1034 | if (DEBUG) { |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1035 | Slog.v(LOG_TAG, "deleteConfigSetting(" + name + ")"); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1036 | } |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1037 | return mutateConfigSetting(name, null, null, false, |
| 1038 | MUTATION_OPERATION_DELETE, 0); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1041 | private void resetConfigSetting(int mode, String prefix) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1042 | if (DEBUG) { |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1043 | Slog.v(LOG_TAG, "resetConfigSetting(" + mode + ", " + prefix + ")"); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1044 | } |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1045 | mutateConfigSetting(null, null, prefix, false, |
| 1046 | MUTATION_OPERATION_RESET, mode); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1049 | private boolean mutateConfigSetting(String name, String value, String prefix, |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1050 | boolean makeDefault, int operation, int mode) { |
Stanislav Zholnin | 5a25a84 | 2019-03-13 14:43:26 +0000 | [diff] [blame] | 1051 | enforceWritePermission(Manifest.permission.WRITE_DEVICE_CONFIG); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1052 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1053 | // Perform the mutation. |
| 1054 | synchronized (mLock) { |
| 1055 | switch (operation) { |
| 1056 | case MUTATION_OPERATION_INSERT: { |
| 1057 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_CONFIG, |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1058 | UserHandle.USER_SYSTEM, name, value, null, makeDefault, true, |
Matt Pape | 7b1c6cd | 2019-01-04 08:10:41 -0800 | [diff] [blame] | 1059 | resolveCallingPackage(), false, null); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1062 | case MUTATION_OPERATION_DELETE: { |
| 1063 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_CONFIG, |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 1064 | UserHandle.USER_SYSTEM, name, false, null); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1067 | case MUTATION_OPERATION_RESET: { |
| 1068 | mSettingsRegistry.resetSettingsLocked(SETTINGS_TYPE_CONFIG, |
Matt Pape | 7b1c6cd | 2019-01-04 08:10:41 -0800 | [diff] [blame] | 1069 | UserHandle.USER_SYSTEM, resolveCallingPackage(), mode, null, prefix); |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 1070 | } return true; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | return false; |
| 1075 | } |
| 1076 | |
Matt Pape | 793b15c | 2019-10-07 13:17:20 -0700 | [diff] [blame] | 1077 | private HashMap<String, String> getAllConfigFlags(@Nullable String prefix) { |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1078 | if (DEBUG) { |
| 1079 | Slog.v(LOG_TAG, "getAllConfigFlags() for " + prefix); |
| 1080 | } |
| 1081 | |
| 1082 | synchronized (mLock) { |
| 1083 | // Get the settings. |
| 1084 | SettingsState settingsState = mSettingsRegistry.getSettingsLocked( |
| 1085 | SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1086 | List<String> names = getSettingsNamesLocked(SETTINGS_TYPE_CONFIG, |
| 1087 | UserHandle.USER_SYSTEM); |
| 1088 | |
| 1089 | final int nameCount = names.size(); |
Matt Pape | 793b15c | 2019-10-07 13:17:20 -0700 | [diff] [blame] | 1090 | HashMap<String, String> flagsToValues = new HashMap<>(names.size()); |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 1091 | |
| 1092 | for (int i = 0; i < nameCount; i++) { |
| 1093 | String name = names.get(i); |
| 1094 | Setting setting = settingsState.getSettingLocked(name); |
| 1095 | if (prefix == null || setting.getName().startsWith(prefix)) { |
| 1096 | flagsToValues.put(setting.getName(), setting.getValue()); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | return flagsToValues; |
| 1101 | } |
| 1102 | } |
| 1103 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1104 | private Cursor getAllGlobalSettings(String[] projection) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1105 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1106 | Slog.v(LOG_TAG, "getAllGlobalSettings()"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1109 | synchronized (mLock) { |
| 1110 | // Get the settings. |
| 1111 | SettingsState settingsState = mSettingsRegistry.getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1112 | SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1113 | |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1114 | List<String> names = getSettingsNamesLocked(SETTINGS_TYPE_GLOBAL, |
| 1115 | UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1116 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1117 | final int nameCount = names.size(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1118 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1119 | String[] normalizedProjection = normalizeProjection(projection); |
| 1120 | MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1121 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1122 | // Anyone can get the global settings, so no security checks. |
| 1123 | for (int i = 0; i < nameCount; i++) { |
| 1124 | String name = names.get(i); |
| 1125 | Setting setting = settingsState.getSettingLocked(name); |
| 1126 | appendSettingToCursor(result, setting); |
| 1127 | } |
| 1128 | |
| 1129 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1130 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1131 | } |
| 1132 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1133 | private Setting getGlobalSetting(String name) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1134 | if (DEBUG) { |
| 1135 | Slog.v(LOG_TAG, "getGlobalSetting(" + name + ")"); |
| 1136 | } |
| 1137 | |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1138 | // Ensure the caller can access the setting. |
| 1139 | enforceSettingReadable(name, SETTINGS_TYPE_GLOBAL, UserHandle.getCallingUserId()); |
| 1140 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1141 | // Get the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1142 | synchronized (mLock) { |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1143 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_GLOBAL, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1144 | UserHandle.USER_SYSTEM, name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1145 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1148 | private boolean updateGlobalSetting(String name, String value, String tag, |
| 1149 | boolean makeDefault, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1150 | if (DEBUG) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1151 | Slog.v(LOG_TAG, "updateGlobalSetting(" + name + ", " + value + ", " |
| 1152 | + ", " + tag + ", " + makeDefault + ", " + requestingUserId |
| 1153 | + ", " + forceNotify + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1154 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1155 | return mutateGlobalSetting(name, value, tag, makeDefault, requestingUserId, |
| 1156 | MUTATION_OPERATION_UPDATE, forceNotify, 0); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1159 | private boolean insertGlobalSetting(String name, String value, String tag, |
| 1160 | boolean makeDefault, int requestingUserId, boolean forceNotify) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1161 | if (DEBUG) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1162 | Slog.v(LOG_TAG, "insertGlobalSetting(" + name + ", " + value + ", " |
| 1163 | + ", " + tag + ", " + makeDefault + ", " + requestingUserId |
| 1164 | + ", " + forceNotify + ")"); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1165 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1166 | return mutateGlobalSetting(name, value, tag, makeDefault, requestingUserId, |
| 1167 | MUTATION_OPERATION_INSERT, forceNotify, 0); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1170 | private boolean deleteGlobalSetting(String name, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1171 | if (DEBUG) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1172 | Slog.v(LOG_TAG, "deleteGlobalSetting(" + name + ", " + requestingUserId |
| 1173 | + ", " + forceNotify + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1174 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1175 | return mutateGlobalSetting(name, null, null, false, requestingUserId, |
| 1176 | MUTATION_OPERATION_DELETE, forceNotify, 0); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1179 | private void resetGlobalSetting(int requestingUserId, int mode, String tag) { |
| 1180 | if (DEBUG) { |
| 1181 | Slog.v(LOG_TAG, "resetGlobalSetting(" + requestingUserId + ", " |
| 1182 | + mode + ", " + tag + ")"); |
| 1183 | } |
| 1184 | mutateGlobalSetting(null, null, tag, false, requestingUserId, |
| 1185 | MUTATION_OPERATION_RESET, false, mode); |
| 1186 | } |
| 1187 | |
| 1188 | private boolean mutateGlobalSetting(String name, String value, String tag, |
| 1189 | boolean makeDefault, int requestingUserId, int operation, boolean forceNotify, |
| 1190 | int mode) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1191 | // Make sure the caller can change the settings - treated as secure. |
| 1192 | enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1193 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1194 | // Resolve the userId on whose behalf the call is made. |
| 1195 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 1196 | |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1197 | // If this is a setting that is currently restricted for this user, do not allow |
| 1198 | // unrestricting changes. |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 1199 | if (name != null && mUserManagerInternal.isSettingRestrictedForUser( |
| 1200 | name, callingUserId, value, Binder.getCallingUid())) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
| 1203 | |
| 1204 | // Perform the mutation. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1205 | synchronized (mLock) { |
| 1206 | switch (operation) { |
| 1207 | case MUTATION_OPERATION_INSERT: { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1208 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_GLOBAL, |
| 1209 | UserHandle.USER_SYSTEM, name, value, tag, makeDefault, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1210 | getCallingPackage(), forceNotify, CRITICAL_GLOBAL_SETTINGS); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1211 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1212 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1213 | case MUTATION_OPERATION_DELETE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1214 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_GLOBAL, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1215 | UserHandle.USER_SYSTEM, name, forceNotify, CRITICAL_GLOBAL_SETTINGS); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1216 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1217 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1218 | case MUTATION_OPERATION_UPDATE: { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1219 | return mSettingsRegistry.updateSettingLocked(SETTINGS_TYPE_GLOBAL, |
| 1220 | UserHandle.USER_SYSTEM, name, value, tag, makeDefault, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1221 | getCallingPackage(), forceNotify, CRITICAL_GLOBAL_SETTINGS); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1222 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1223 | |
| 1224 | case MUTATION_OPERATION_RESET: { |
| 1225 | mSettingsRegistry.resetSettingsLocked(SETTINGS_TYPE_GLOBAL, |
| 1226 | UserHandle.USER_SYSTEM, getCallingPackage(), mode, tag); |
| 1227 | } return true; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | return false; |
| 1232 | } |
| 1233 | |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1234 | private PackageInfo getCallingPackageInfo(int userId) { |
| 1235 | try { |
| 1236 | return mPackageManager.getPackageInfo(getCallingPackage(), |
| 1237 | PackageManager.GET_SIGNATURES, userId); |
| 1238 | } catch (RemoteException e) { |
| 1239 | throw new IllegalStateException("Package " + getCallingPackage() + " doesn't exist"); |
| 1240 | } |
| 1241 | } |
| 1242 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1243 | private Cursor getAllSecureSettings(int userId, String[] projection) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1244 | if (DEBUG) { |
| 1245 | Slog.v(LOG_TAG, "getAllSecureSettings(" + userId + ")"); |
| 1246 | } |
| 1247 | |
| 1248 | // Resolve the userId on whose behalf the call is made. |
| 1249 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 1250 | |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1251 | // The relevant "calling package" userId will be the owning userId for some |
| 1252 | // profiles, and we can't do the lookup inside our [lock held] loop, so work out |
| 1253 | // up front who the effective "new SSAID" user ID for that settings name will be. |
| 1254 | final int ssaidUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, |
| 1255 | Settings.Secure.ANDROID_ID); |
| 1256 | final PackageInfo ssaidCallingPkg = getCallingPackageInfo(ssaidUserId); |
| 1257 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1258 | synchronized (mLock) { |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1259 | List<String> names = getSettingsNamesLocked(SETTINGS_TYPE_SECURE, callingUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1260 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1261 | final int nameCount = names.size(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1262 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1263 | String[] normalizedProjection = normalizeProjection(projection); |
| 1264 | MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1265 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1266 | for (int i = 0; i < nameCount; i++) { |
| 1267 | String name = names.get(i); |
| 1268 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1269 | final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, |
| 1270 | name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1271 | |
Alex Klyubin | 1991f57 | 2017-03-03 14:08:36 -0800 | [diff] [blame] | 1272 | if (!isSecureSettingAccessible(name, callingUserId, owningUserId)) { |
| 1273 | // This caller is not permitted to access this setting. Pretend the setting |
| 1274 | // doesn't exist. |
Svetoslav Ganov | 83a1f7f | 2016-04-27 13:50:49 -0700 | [diff] [blame] | 1275 | continue; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1276 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1277 | |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 1278 | // As of Android O, the SSAID is read from an app-specific entry in table |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1279 | // SETTINGS_FILE_SSAID, unless accessed by a system process. |
| 1280 | final Setting setting; |
| 1281 | if (isNewSsaidSetting(name)) { |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1282 | setting = getSsaidSettingLocked(ssaidCallingPkg, owningUserId); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1283 | } else { |
| 1284 | setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, |
| 1285 | name); |
| 1286 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1287 | appendSettingToCursor(result, setting); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1290 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1291 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1292 | } |
| 1293 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1294 | private Setting getSecureSetting(String name, int requestingUserId) { |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 1295 | return getSecureSetting(name, requestingUserId, /*enableOverride=*/ false); |
| 1296 | } |
| 1297 | |
| 1298 | private Setting getSecureSetting(String name, int requestingUserId, boolean enableOverride) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1299 | if (DEBUG) { |
| 1300 | Slog.v(LOG_TAG, "getSecureSetting(" + name + ", " + requestingUserId + ")"); |
| 1301 | } |
| 1302 | |
| 1303 | // Resolve the userId on whose behalf the call is made. |
| 1304 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 1305 | |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1306 | // Ensure the caller can access the setting. |
| 1307 | enforceSettingReadable(name, SETTINGS_TYPE_SECURE, UserHandle.getCallingUserId()); |
| 1308 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1309 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1310 | final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name); |
| 1311 | |
Alex Klyubin | 1991f57 | 2017-03-03 14:08:36 -0800 | [diff] [blame] | 1312 | if (!isSecureSettingAccessible(name, callingUserId, owningUserId)) { |
| 1313 | // This caller is not permitted to access this setting. Pretend the setting doesn't |
| 1314 | // exist. |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 1315 | SettingsState settings = mSettingsRegistry.getSettingsLocked(SETTINGS_TYPE_SECURE, |
| 1316 | owningUserId); |
| 1317 | return settings != null ? settings.getNullSetting() : null; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1318 | } |
| 1319 | |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1320 | // As of Android O, the SSAID is read from an app-specific entry in table |
| 1321 | // SETTINGS_FILE_SSAID, unless accessed by a system process. |
| 1322 | if (isNewSsaidSetting(name)) { |
| 1323 | PackageInfo callingPkg = getCallingPackageInfo(owningUserId); |
| 1324 | synchronized (mLock) { |
| 1325 | return getSsaidSettingLocked(callingPkg, owningUserId); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1326 | } |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1327 | } |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 1328 | if (enableOverride) { |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1329 | if (Secure.LOCATION_MODE.equals(name)) { |
| 1330 | final Setting overridden = getLocationModeSetting(owningUserId); |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 1331 | if (overridden != null) { |
| 1332 | return overridden; |
| 1333 | } |
| 1334 | } |
| 1335 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1336 | |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1337 | // Not the SSAID; do a straight lookup |
| 1338 | synchronized (mLock) { |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1339 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SECURE, |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1340 | owningUserId, name); |
| 1341 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1344 | private boolean isNewSsaidSetting(String name) { |
| 1345 | return Settings.Secure.ANDROID_ID.equals(name) |
| 1346 | && UserHandle.getAppId(Binder.getCallingUid()) >= Process.FIRST_APPLICATION_UID; |
| 1347 | } |
| 1348 | |
Andreas Gampe | b5889307 | 2018-09-05 16:52:31 -0700 | [diff] [blame] | 1349 | @GuardedBy("mLock") |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 1350 | private Setting getSsaidSettingLocked(PackageInfo callingPkg, int owningUserId) { |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1351 | // Get uid of caller (key) used to store ssaid value |
| 1352 | String name = Integer.toString( |
| 1353 | UserHandle.getUid(owningUserId, UserHandle.getAppId(Binder.getCallingUid()))); |
| 1354 | |
| 1355 | if (DEBUG) { |
| 1356 | Slog.v(LOG_TAG, "getSsaidSettingLocked(" + name + "," + owningUserId + ")"); |
| 1357 | } |
| 1358 | |
| 1359 | // Retrieve the ssaid from the table if present. |
| 1360 | final Setting ssaid = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SSAID, owningUserId, |
| 1361 | name); |
Chad Brubaker | 0d277a7 | 2017-04-12 16:56:53 -0700 | [diff] [blame] | 1362 | // If the app is an Instant App use its stored SSAID instead of our own. |
| 1363 | final String instantSsaid; |
| 1364 | final long token = Binder.clearCallingIdentity(); |
| 1365 | try { |
| 1366 | instantSsaid = mPackageManager.getInstantAppAndroidId(callingPkg.packageName, |
| 1367 | owningUserId); |
| 1368 | } catch (RemoteException e) { |
| 1369 | Slog.e(LOG_TAG, "Failed to get Instant App Android ID", e); |
| 1370 | return null; |
| 1371 | } finally { |
| 1372 | Binder.restoreCallingIdentity(token); |
| 1373 | } |
Svet Ganov | 96c9946 | 2017-05-05 14:27:13 -0700 | [diff] [blame] | 1374 | |
| 1375 | final SettingsState ssaidSettings = mSettingsRegistry.getSettingsLocked( |
| 1376 | SETTINGS_TYPE_SSAID, owningUserId); |
| 1377 | |
Chad Brubaker | 0d277a7 | 2017-04-12 16:56:53 -0700 | [diff] [blame] | 1378 | if (instantSsaid != null) { |
| 1379 | // Use the stored value if it is still valid. |
| 1380 | if (ssaid != null && instantSsaid.equals(ssaid.getValue())) { |
Svet Ganov | 96c9946 | 2017-05-05 14:27:13 -0700 | [diff] [blame] | 1381 | return mascaradeSsaidSetting(ssaidSettings, ssaid); |
Chad Brubaker | 0d277a7 | 2017-04-12 16:56:53 -0700 | [diff] [blame] | 1382 | } |
| 1383 | // The value has changed, update the stored value. |
Chad Brubaker | 0d277a7 | 2017-04-12 16:56:53 -0700 | [diff] [blame] | 1384 | final boolean success = ssaidSettings.insertSettingLocked(name, instantSsaid, null, |
| 1385 | true, callingPkg.packageName); |
| 1386 | if (!success) { |
| 1387 | throw new IllegalStateException("Failed to update instant app android id"); |
| 1388 | } |
Svet Ganov | 96c9946 | 2017-05-05 14:27:13 -0700 | [diff] [blame] | 1389 | Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SSAID, |
| 1390 | owningUserId, name); |
| 1391 | return mascaradeSsaidSetting(ssaidSettings, setting); |
Chad Brubaker | 0d277a7 | 2017-04-12 16:56:53 -0700 | [diff] [blame] | 1392 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1393 | |
| 1394 | // Lazy initialize ssaid if not yet present in ssaid table. |
Mark Rathjen | ea61759 | 2017-01-18 23:03:41 -0800 | [diff] [blame] | 1395 | if (ssaid == null || ssaid.isNull() || ssaid.getValue() == null) { |
Svet Ganov | 96c9946 | 2017-05-05 14:27:13 -0700 | [diff] [blame] | 1396 | Setting setting = mSettingsRegistry.generateSsaidLocked(callingPkg, owningUserId); |
| 1397 | return mascaradeSsaidSetting(ssaidSettings, setting); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Svet Ganov | 96c9946 | 2017-05-05 14:27:13 -0700 | [diff] [blame] | 1400 | return mascaradeSsaidSetting(ssaidSettings, ssaid); |
| 1401 | } |
| 1402 | |
| 1403 | private Setting mascaradeSsaidSetting(SettingsState settingsState, Setting ssaidSetting) { |
| 1404 | // SSAID settings are located in a dedicated table for internal bookkeeping |
| 1405 | // but for the world they reside in the secure table, so adjust the key here. |
| 1406 | // We have a special name when looking it up but want the world to see it as |
| 1407 | // "android_id". |
| 1408 | if (ssaidSetting != null) { |
| 1409 | return settingsState.new Setting(ssaidSetting) { |
| 1410 | @Override |
| 1411 | public int getKey() { |
| 1412 | final int userId = getUserIdFromKey(super.getKey()); |
| 1413 | return makeKey(SETTINGS_TYPE_SECURE, userId); |
| 1414 | } |
| 1415 | |
| 1416 | @Override |
| 1417 | public String getName() { |
| 1418 | return Settings.Secure.ANDROID_ID; |
| 1419 | } |
| 1420 | }; |
| 1421 | } |
| 1422 | return null; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1425 | private Setting getLocationModeSetting(int owningUserId) { |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 1426 | synchronized (mLock) { |
| 1427 | final Setting setting = getGlobalSetting( |
| 1428 | Global.LOCATION_GLOBAL_KILL_SWITCH); |
| 1429 | if (!"1".equals(setting.getValue())) { |
| 1430 | return null; |
| 1431 | } |
| 1432 | // Global kill-switch is enabled. Return an empty value. |
| 1433 | final SettingsState settingsState = mSettingsRegistry.getSettingsLocked( |
| 1434 | SETTINGS_TYPE_SECURE, owningUserId); |
| 1435 | return settingsState.new Setting( |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1436 | Secure.LOCATION_MODE, |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 1437 | "", // value |
| 1438 | "", // tag |
| 1439 | "", // default value |
| 1440 | "", // package name |
| 1441 | false, // from system |
| 1442 | "0" // id |
| 1443 | ) { |
| 1444 | @Override |
| 1445 | public boolean update(String value, boolean setDefault, String packageName, |
| 1446 | String tag, boolean forceNonSystemPackage) { |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1447 | Slog.wtf(LOG_TAG, "update shouldn't be called on this instance."); |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 1448 | return false; |
| 1449 | } |
| 1450 | }; |
| 1451 | } |
| 1452 | } |
| 1453 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1454 | private boolean insertSecureSetting(String name, String value, String tag, |
| 1455 | boolean makeDefault, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1456 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1457 | Slog.v(LOG_TAG, "insertSecureSetting(" + name + ", " + value + ", " |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1458 | + ", " + tag + ", " + makeDefault + ", " + requestingUserId |
| 1459 | + ", " + forceNotify + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1460 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1461 | return mutateSecureSetting(name, value, tag, makeDefault, requestingUserId, |
| 1462 | MUTATION_OPERATION_INSERT, forceNotify, 0); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1465 | private boolean deleteSecureSetting(String name, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1466 | if (DEBUG) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1467 | Slog.v(LOG_TAG, "deleteSecureSetting(" + name + ", " + requestingUserId |
| 1468 | + ", " + forceNotify + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1469 | } |
| 1470 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1471 | return mutateSecureSetting(name, null, null, false, requestingUserId, |
| 1472 | MUTATION_OPERATION_DELETE, forceNotify, 0); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1473 | } |
| 1474 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1475 | private boolean updateSecureSetting(String name, String value, String tag, |
| 1476 | boolean makeDefault, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1477 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1478 | Slog.v(LOG_TAG, "updateSecureSetting(" + name + ", " + value + ", " |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1479 | + ", " + tag + ", " + makeDefault + ", " + requestingUserId |
| 1480 | + ", " + forceNotify +")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1481 | } |
| 1482 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1483 | return mutateSecureSetting(name, value, tag, makeDefault, requestingUserId, |
| 1484 | MUTATION_OPERATION_UPDATE, forceNotify, 0); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1485 | } |
| 1486 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1487 | private void resetSecureSetting(int requestingUserId, int mode, String tag) { |
| 1488 | if (DEBUG) { |
| 1489 | Slog.v(LOG_TAG, "resetSecureSetting(" + requestingUserId + ", " |
| 1490 | + mode + ", " + tag + ")"); |
| 1491 | } |
| 1492 | |
| 1493 | mutateSecureSetting(null, null, tag, false, requestingUserId, |
| 1494 | MUTATION_OPERATION_RESET, false, mode); |
| 1495 | } |
| 1496 | |
| 1497 | private boolean mutateSecureSetting(String name, String value, String tag, |
| 1498 | boolean makeDefault, int requestingUserId, int operation, boolean forceNotify, |
| 1499 | int mode) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1500 | // Make sure the caller can change the settings. |
| 1501 | enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1502 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1503 | // Resolve the userId on whose behalf the call is made. |
| 1504 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 1505 | |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1506 | // If this is a setting that is currently restricted for this user, do not allow |
| 1507 | // unrestricting changes. |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 1508 | if (name != null && mUserManagerInternal.isSettingRestrictedForUser( |
| 1509 | name, callingUserId, value, Binder.getCallingUid())) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | |
| 1513 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1514 | final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name); |
| 1515 | |
| 1516 | // Only the owning user can change the setting. |
| 1517 | if (owningUserId != callingUserId) { |
| 1518 | return false; |
| 1519 | } |
| 1520 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1521 | // Mutate the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1522 | synchronized (mLock) { |
Soonil Nagarkar | 10b1960 | 2019-09-10 15:46:32 -0700 | [diff] [blame] | 1523 | // Special cases for location providers (sigh). |
| 1524 | if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) { |
| 1525 | return updateLocationProvidersAllowedLocked(value, tag, owningUserId, makeDefault, |
| 1526 | forceNotify); |
| 1527 | } |
| 1528 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1529 | switch (operation) { |
| 1530 | case MUTATION_OPERATION_INSERT: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1531 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1532 | owningUserId, name, value, tag, makeDefault, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1533 | getCallingPackage(), forceNotify, CRITICAL_SECURE_SETTINGS); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1534 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1535 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1536 | case MUTATION_OPERATION_DELETE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1537 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_SECURE, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1538 | owningUserId, name, forceNotify, CRITICAL_SECURE_SETTINGS); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1539 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1540 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1541 | case MUTATION_OPERATION_UPDATE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1542 | return mSettingsRegistry.updateSettingLocked(SETTINGS_TYPE_SECURE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1543 | owningUserId, name, value, tag, makeDefault, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1544 | getCallingPackage(), forceNotify, CRITICAL_SECURE_SETTINGS); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1545 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1546 | |
| 1547 | case MUTATION_OPERATION_RESET: { |
| 1548 | mSettingsRegistry.resetSettingsLocked(SETTINGS_TYPE_SECURE, |
| 1549 | UserHandle.USER_SYSTEM, getCallingPackage(), mode, tag); |
| 1550 | } return true; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | return false; |
| 1555 | } |
| 1556 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1557 | private Cursor getAllSystemSettings(int userId, String[] projection) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1558 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1559 | Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | // Resolve the userId on whose behalf the call is made. |
| 1563 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 1564 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1565 | synchronized (mLock) { |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1566 | List<String> names = getSettingsNamesLocked(SETTINGS_TYPE_SYSTEM, callingUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1567 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1568 | final int nameCount = names.size(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1569 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1570 | String[] normalizedProjection = normalizeProjection(projection); |
| 1571 | MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1572 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1573 | for (int i = 0; i < nameCount; i++) { |
| 1574 | String name = names.get(i); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1575 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1576 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1577 | final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, |
| 1578 | name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1579 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1580 | Setting setting = mSettingsRegistry.getSettingLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1581 | SETTINGS_TYPE_SYSTEM, owningUserId, name); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1582 | appendSettingToCursor(result, setting); |
| 1583 | } |
| 1584 | |
| 1585 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1586 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1587 | } |
| 1588 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1589 | private Setting getSystemSetting(String name, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1590 | if (DEBUG) { |
| 1591 | Slog.v(LOG_TAG, "getSystemSetting(" + name + ", " + requestingUserId + ")"); |
| 1592 | } |
| 1593 | |
| 1594 | // Resolve the userId on whose behalf the call is made. |
| 1595 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 1596 | |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1597 | // Ensure the caller can access the setting. |
| 1598 | enforceSettingReadable(name, SETTINGS_TYPE_SYSTEM, UserHandle.getCallingUserId()); |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1599 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1600 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1601 | final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name); |
| 1602 | |
| 1603 | // Get the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1604 | synchronized (mLock) { |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1605 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SYSTEM, owningUserId, name); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1606 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1607 | } |
| 1608 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1609 | private boolean insertSystemSetting(String name, String value, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1610 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1611 | Slog.v(LOG_TAG, "insertSystemSetting(" + name + ", " + value + ", " |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1612 | + requestingUserId + ")"); |
| 1613 | } |
| 1614 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1615 | return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1618 | private boolean deleteSystemSetting(String name, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1619 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1620 | Slog.v(LOG_TAG, "deleteSystemSetting(" + name + ", " + requestingUserId + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1623 | return mutateSystemSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1624 | } |
| 1625 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1626 | private boolean updateSystemSetting(String name, String value, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1627 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1628 | Slog.v(LOG_TAG, "updateSystemSetting(" + name + ", " + value + ", " |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1629 | + requestingUserId + ")"); |
| 1630 | } |
| 1631 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1632 | return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1635 | private boolean mutateSystemSetting(String name, String value, int runAsUserId, |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1636 | int operation) { |
Billy Lau | 6ad2d66 | 2015-07-18 00:26:58 +0100 | [diff] [blame] | 1637 | if (!hasWriteSecureSettingsPermission()) { |
| 1638 | // If the caller doesn't hold WRITE_SECURE_SETTINGS, we verify whether this |
| 1639 | // operation is allowed for the calling package through appops. |
| 1640 | if (!Settings.checkAndNoteWriteSettingsOperation(getContext(), |
| 1641 | Binder.getCallingUid(), getCallingPackage(), true)) { |
| 1642 | return false; |
| 1643 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1644 | } |
| 1645 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1646 | // Resolve the userId on whose behalf the call is made. |
| 1647 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(runAsUserId); |
| 1648 | |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 1649 | if (name != null && mUserManagerInternal.isSettingRestrictedForUser( |
| 1650 | name, callingUserId, value, Binder.getCallingUid())) { |
| 1651 | return false; |
| 1652 | } |
| 1653 | |
Svetoslav | d8d25e0 | 2015-11-20 13:09:26 -0800 | [diff] [blame] | 1654 | // Enforce what the calling package can mutate the system settings. |
| 1655 | enforceRestrictedSystemSettingsMutationForCallingPackage(operation, name, callingUserId); |
| 1656 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1657 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1658 | final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name); |
| 1659 | |
| 1660 | // Only the owning user id can change the setting. |
| 1661 | if (owningUserId != callingUserId) { |
| 1662 | return false; |
| 1663 | } |
| 1664 | |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 1665 | // Invalidate any relevant cache files |
| 1666 | String cacheName = null; |
| 1667 | if (Settings.System.RINGTONE.equals(name)) { |
| 1668 | cacheName = Settings.System.RINGTONE_CACHE; |
| 1669 | } else if (Settings.System.NOTIFICATION_SOUND.equals(name)) { |
| 1670 | cacheName = Settings.System.NOTIFICATION_SOUND_CACHE; |
| 1671 | } else if (Settings.System.ALARM_ALERT.equals(name)) { |
| 1672 | cacheName = Settings.System.ALARM_ALERT_CACHE; |
| 1673 | } |
| 1674 | if (cacheName != null) { |
| 1675 | final File cacheFile = new File( |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 1676 | getRingtoneCacheDir(owningUserId), cacheName); |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 1677 | cacheFile.delete(); |
| 1678 | } |
| 1679 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1680 | // Mutate the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1681 | synchronized (mLock) { |
| 1682 | switch (operation) { |
| 1683 | case MUTATION_OPERATION_INSERT: { |
| 1684 | validateSystemSettingValue(name, value); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1685 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SYSTEM, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1686 | owningUserId, name, value, null, false, getCallingPackage(), |
| 1687 | false, null); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | case MUTATION_OPERATION_DELETE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1691 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_SYSTEM, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1692 | owningUserId, name, false, null); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | case MUTATION_OPERATION_UPDATE: { |
| 1696 | validateSystemSettingValue(name, value); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1697 | return mSettingsRegistry.updateSettingLocked(SETTINGS_TYPE_SYSTEM, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 1698 | owningUserId, name, value, null, false, getCallingPackage(), |
| 1699 | false, null); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1700 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1703 | return false; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1704 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1705 | } |
| 1706 | |
Billy Lau | 6ad2d66 | 2015-07-18 00:26:58 +0100 | [diff] [blame] | 1707 | private boolean hasWriteSecureSettingsPermission() { |
Svetoslav | f41334b | 2015-06-23 12:06:03 -0700 | [diff] [blame] | 1708 | // Write secure settings is a more protected permission. If caller has it we are good. |
| 1709 | if (getContext().checkCallingOrSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1710 | == PackageManager.PERMISSION_GRANTED) { |
| 1711 | return true; |
| 1712 | } |
| 1713 | |
Svetoslav | f41334b | 2015-06-23 12:06:03 -0700 | [diff] [blame] | 1714 | return false; |
| 1715 | } |
| 1716 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1717 | private void validateSystemSettingValue(String name, String value) { |
Al Sutton | 91f89d0 | 2019-08-16 12:56:57 +0100 | [diff] [blame] | 1718 | Validator validator = SystemSettingsValidators.VALIDATORS.get(name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1719 | if (validator != null && !validator.validate(value)) { |
| 1720 | throw new IllegalArgumentException("Invalid value: " + value |
| 1721 | + " for setting: " + name); |
| 1722 | } |
| 1723 | } |
| 1724 | |
Alex Klyubin | 1991f57 | 2017-03-03 14:08:36 -0800 | [diff] [blame] | 1725 | /** |
| 1726 | * Returns {@code true} if the specified secure setting should be accessible to the caller. |
| 1727 | */ |
| 1728 | private boolean isSecureSettingAccessible(String name, int callingUserId, |
| 1729 | int owningUserId) { |
| 1730 | // Special case for location (sigh). |
| 1731 | // This check is not inside the name-based checks below because this method performs checks |
| 1732 | // only if the calling user ID is not the same as the owning user ID. |
| 1733 | if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) { |
| 1734 | return false; |
| 1735 | } |
| 1736 | |
| 1737 | switch (name) { |
| 1738 | case "bluetooth_address": |
| 1739 | // BluetoothManagerService for some reason stores the Android's Bluetooth MAC |
| 1740 | // address in this secure setting. Secure settings can normally be read by any app, |
| 1741 | // which thus enables them to bypass the recently introduced restrictions on access |
| 1742 | // to device identifiers. |
| 1743 | // To mitigate this we make this setting available only to callers privileged to see |
| 1744 | // this device's MAC addresses, same as through public API |
| 1745 | // BluetoothAdapter.getAddress() (see BluetoothManagerService for details). |
| 1746 | return getContext().checkCallingOrSelfPermission( |
| 1747 | Manifest.permission.LOCAL_MAC_ADDRESS) == PackageManager.PERMISSION_GRANTED; |
| 1748 | default: |
| 1749 | return true; |
| 1750 | } |
| 1751 | } |
| 1752 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1753 | private boolean isLocationProvidersAllowedRestricted(String name, int callingUserId, |
| 1754 | int owningUserId) { |
| 1755 | // Optimization - location providers are restricted only for managed profiles. |
| 1756 | if (callingUserId == owningUserId) { |
| 1757 | return false; |
| 1758 | } |
| 1759 | if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name) |
| 1760 | && mUserManager.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, |
| 1761 | new UserHandle(callingUserId))) { |
| 1762 | return true; |
| 1763 | } |
| 1764 | return false; |
| 1765 | } |
| 1766 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1767 | private int resolveOwningUserIdForSecureSettingLocked(int userId, String setting) { |
| 1768 | return resolveOwningUserIdLocked(userId, sSecureCloneToManagedSettings, setting); |
| 1769 | } |
| 1770 | |
| 1771 | private int resolveOwningUserIdForSystemSettingLocked(int userId, String setting) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 1772 | final int parentId; |
| 1773 | // Resolves dependency if setting has a dependency and the calling user has a parent |
| 1774 | if (sSystemCloneFromParentOnDependency.containsKey(setting) |
| 1775 | && (parentId = getGroupParentLocked(userId)) != userId) { |
| 1776 | // The setting has a dependency and the profile has a parent |
| 1777 | String dependency = sSystemCloneFromParentOnDependency.get(setting); |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1778 | // Lookup the dependency setting as ourselves, some callers may not have access to it. |
| 1779 | final long token = Binder.clearCallingIdentity(); |
| 1780 | try { |
| 1781 | Setting settingObj = getSecureSetting(dependency, userId); |
| 1782 | if (settingObj != null && settingObj.getValue().equals("1")) { |
| 1783 | return parentId; |
| 1784 | } |
| 1785 | } finally { |
| 1786 | Binder.restoreCallingIdentity(token); |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 1787 | } |
| 1788 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1789 | return resolveOwningUserIdLocked(userId, sSystemCloneToManagedSettings, setting); |
| 1790 | } |
| 1791 | |
| 1792 | private int resolveOwningUserIdLocked(int userId, Set<String> keys, String name) { |
| 1793 | final int parentId = getGroupParentLocked(userId); |
| 1794 | if (parentId != userId && keys.contains(name)) { |
| 1795 | return parentId; |
| 1796 | } |
| 1797 | return userId; |
| 1798 | } |
| 1799 | |
Svetoslav | f41334b | 2015-06-23 12:06:03 -0700 | [diff] [blame] | 1800 | private void enforceRestrictedSystemSettingsMutationForCallingPackage(int operation, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1801 | String name, int userId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1802 | // System/root/shell can mutate whatever secure settings they want. |
| 1803 | final int callingUid = Binder.getCallingUid(); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1804 | final int appId = UserHandle.getAppId(callingUid); |
| 1805 | if (appId == android.os.Process.SYSTEM_UID |
| 1806 | || appId == Process.SHELL_UID |
| 1807 | || appId == Process.ROOT_UID) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1808 | return; |
| 1809 | } |
| 1810 | |
| 1811 | switch (operation) { |
| 1812 | case MUTATION_OPERATION_INSERT: |
| 1813 | // Insert updates. |
| 1814 | case MUTATION_OPERATION_UPDATE: { |
| 1815 | if (Settings.System.PUBLIC_SETTINGS.contains(name)) { |
| 1816 | return; |
| 1817 | } |
| 1818 | |
| 1819 | // The calling package is already verified. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1820 | PackageInfo packageInfo = getCallingPackageInfoOrThrow(userId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1821 | |
| 1822 | // Privileged apps can do whatever they want. |
| 1823 | if ((packageInfo.applicationInfo.privateFlags |
| 1824 | & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) { |
| 1825 | return; |
| 1826 | } |
| 1827 | |
| 1828 | warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk( |
| 1829 | packageInfo.applicationInfo.targetSdkVersion, name); |
| 1830 | } break; |
| 1831 | |
| 1832 | case MUTATION_OPERATION_DELETE: { |
| 1833 | if (Settings.System.PUBLIC_SETTINGS.contains(name) |
| 1834 | || Settings.System.PRIVATE_SETTINGS.contains(name)) { |
| 1835 | throw new IllegalArgumentException("You cannot delete system defined" |
| 1836 | + " secure settings."); |
| 1837 | } |
| 1838 | |
| 1839 | // The calling package is already verified. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1840 | PackageInfo packageInfo = getCallingPackageInfoOrThrow(userId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1841 | |
| 1842 | // Privileged apps can do whatever they want. |
| 1843 | if ((packageInfo.applicationInfo.privateFlags & |
| 1844 | ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) { |
| 1845 | return; |
| 1846 | } |
| 1847 | |
| 1848 | warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk( |
| 1849 | packageInfo.applicationInfo.targetSdkVersion, name); |
| 1850 | } break; |
| 1851 | } |
| 1852 | } |
| 1853 | |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1854 | private Set<String> getInstantAppAccessibleSettings(int settingsType) { |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1855 | switch (settingsType) { |
| 1856 | case SETTINGS_TYPE_GLOBAL: |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1857 | return Settings.Global.INSTANT_APP_SETTINGS; |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1858 | case SETTINGS_TYPE_SECURE: |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1859 | return Settings.Secure.INSTANT_APP_SETTINGS; |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1860 | case SETTINGS_TYPE_SYSTEM: |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1861 | return Settings.System.INSTANT_APP_SETTINGS; |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1862 | default: |
| 1863 | throw new IllegalArgumentException("Invalid settings type: " + settingsType); |
| 1864 | } |
| 1865 | } |
| 1866 | |
Chad Brubaker | 20e0dc3 | 2017-04-28 18:24:55 -0700 | [diff] [blame] | 1867 | private Set<String> getOverlayInstantAppAccessibleSettings(int settingsType) { |
| 1868 | switch (settingsType) { |
| 1869 | case SETTINGS_TYPE_GLOBAL: |
| 1870 | return OVERLAY_ALLOWED_GLOBAL_INSTANT_APP_SETTINGS; |
| 1871 | case SETTINGS_TYPE_SYSTEM: |
| 1872 | return OVERLAY_ALLOWED_SYSTEM_INSTANT_APP_SETTINGS; |
| 1873 | case SETTINGS_TYPE_SECURE: |
| 1874 | return OVERLAY_ALLOWED_SECURE_INSTANT_APP_SETTINGS; |
| 1875 | default: |
| 1876 | throw new IllegalArgumentException("Invalid settings type: " + settingsType); |
| 1877 | } |
| 1878 | } |
| 1879 | |
Andreas Gampe | b5889307 | 2018-09-05 16:52:31 -0700 | [diff] [blame] | 1880 | @GuardedBy("mLock") |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1881 | private List<String> getSettingsNamesLocked(int settingsType, int userId) { |
Chad Brubaker | b6108d6 | 2017-12-23 20:06:44 -0800 | [diff] [blame] | 1882 | // Don't enforce the instant app whitelist for now -- its too prone to unintended breakage |
| 1883 | // in the current form. |
| 1884 | return mSettingsRegistry.getSettingsNamesLocked(settingsType, userId); |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1885 | } |
| 1886 | |
Chad Brubaker | a6830e7 | 2017-04-28 17:34:36 -0700 | [diff] [blame] | 1887 | private void enforceSettingReadable(String settingName, int settingsType, int userId) { |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1888 | if (UserHandle.getAppId(Binder.getCallingUid()) < Process.FIRST_APPLICATION_UID) { |
| 1889 | return; |
| 1890 | } |
Chad Brubaker | f0fa853 | 2017-02-23 10:45:20 -0800 | [diff] [blame] | 1891 | ApplicationInfo ai = getCallingApplicationInfoOrThrow(); |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 1892 | if (!ai.isInstantApp()) { |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1893 | return; |
| 1894 | } |
Chad Brubaker | 20e0dc3 | 2017-04-28 18:24:55 -0700 | [diff] [blame] | 1895 | if (!getInstantAppAccessibleSettings(settingsType).contains(settingName) |
| 1896 | && !getOverlayInstantAppAccessibleSettings(settingsType).contains(settingName)) { |
Chad Brubaker | b6108d6 | 2017-12-23 20:06:44 -0800 | [diff] [blame] | 1897 | // Don't enforce the instant app whitelist for now -- its too prone to unintended |
| 1898 | // breakage in the current form. |
| 1899 | Slog.w(LOG_TAG, "Instant App " + ai.packageName |
| 1900 | + " trying to access unexposed setting, this will be an error in the future."); |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1901 | } |
| 1902 | } |
| 1903 | |
Chad Brubaker | f0fa853 | 2017-02-23 10:45:20 -0800 | [diff] [blame] | 1904 | private ApplicationInfo getCallingApplicationInfoOrThrow() { |
| 1905 | // We always use the callingUid for this lookup. This means that if hypothetically an |
| 1906 | // app was installed in user A with cross user and in user B as an Instant App |
| 1907 | // the app in A would be able to see all the settings in user B. However since cross |
| 1908 | // user is a system permission and the app must be uninstalled in B and then installed as |
| 1909 | // an Instant App that situation is not realistic or supported. |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1910 | ApplicationInfo ai = null; |
| 1911 | try { |
Chad Brubaker | f0fa853 | 2017-02-23 10:45:20 -0800 | [diff] [blame] | 1912 | ai = mPackageManager.getApplicationInfo(getCallingPackage(), 0 |
| 1913 | , UserHandle.getCallingUserId()); |
Chad Brubaker | 97bccee | 2017-01-05 15:51:41 -0800 | [diff] [blame] | 1914 | } catch (RemoteException ignored) { |
| 1915 | } |
| 1916 | if (ai == null) { |
| 1917 | throw new IllegalStateException("Failed to lookup info for package " |
| 1918 | + getCallingPackage()); |
| 1919 | } |
| 1920 | return ai; |
| 1921 | } |
| 1922 | |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1923 | private PackageInfo getCallingPackageInfoOrThrow(int userId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1924 | try { |
Svetoslav Ganov | 67a8d35 | 2016-03-02 13:26:40 -0800 | [diff] [blame] | 1925 | PackageInfo packageInfo = mPackageManager.getPackageInfo( |
| 1926 | getCallingPackage(), 0, userId); |
| 1927 | if (packageInfo != null) { |
| 1928 | return packageInfo; |
| 1929 | } |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1930 | } catch (RemoteException e) { |
Svetoslav Ganov | 67a8d35 | 2016-03-02 13:26:40 -0800 | [diff] [blame] | 1931 | /* ignore */ |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1932 | } |
Svetoslav Ganov | 67a8d35 | 2016-03-02 13:26:40 -0800 | [diff] [blame] | 1933 | throw new IllegalStateException("Calling package doesn't exist"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | private int getGroupParentLocked(int userId) { |
| 1937 | // Most frequent use case. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1938 | if (userId == UserHandle.USER_SYSTEM) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1939 | return userId; |
| 1940 | } |
| 1941 | // We are in the same process with the user manager and the returned |
| 1942 | // user info is a cached instance, so just look up instead of cache. |
| 1943 | final long identity = Binder.clearCallingIdentity(); |
| 1944 | try { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1945 | // Just a lookup and not reentrant, so holding a lock is fine. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1946 | UserInfo userInfo = mUserManager.getProfileParent(userId); |
| 1947 | return (userInfo != null) ? userInfo.id : userId; |
| 1948 | } finally { |
| 1949 | Binder.restoreCallingIdentity(identity); |
| 1950 | } |
| 1951 | } |
| 1952 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1953 | private void enforceWritePermission(String permission) { |
| 1954 | if (getContext().checkCallingOrSelfPermission(permission) |
| 1955 | != PackageManager.PERMISSION_GRANTED) { |
| 1956 | throw new SecurityException("Permission denial: writing to settings requires:" |
| 1957 | + permission); |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | * Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED. |
| 1963 | * This setting contains a list of the currently enabled location providers. |
| 1964 | * But helper functions in android.providers.Settings can enable or disable |
| 1965 | * a single provider by using a "+" or "-" prefix before the provider name. |
| 1966 | * |
yuemingw | 1d13eae | 2018-01-30 17:27:54 +0000 | [diff] [blame] | 1967 | * <p>See also {@link com.android.server.pm.UserRestrictionsUtils#isSettingRestrictedForUser()}. |
| 1968 | * If DISALLOW_SHARE_LOCATION is set, the said method will only allow values with |
| 1969 | * the "-" prefix. |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1970 | * |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1971 | * @returns whether the enabled location providers changed. |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1972 | */ |
Andreas Gampe | b5889307 | 2018-09-05 16:52:31 -0700 | [diff] [blame] | 1973 | @GuardedBy("mLock") |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 1974 | private boolean updateLocationProvidersAllowedLocked(String value, String tag, |
| 1975 | int owningUserId, boolean makeDefault, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1976 | if (TextUtils.isEmpty(value)) { |
| 1977 | return false; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 1978 | } |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 1979 | Setting oldSetting = getSecureSetting( |
| 1980 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED, owningUserId); |
| 1981 | if (oldSetting == null) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1982 | return false; |
| 1983 | } |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 1984 | String oldProviders = oldSetting.getValue(); |
| 1985 | List<String> oldProvidersList = TextUtils.isEmpty(oldProviders) |
| 1986 | ? new ArrayList<>() : new ArrayList<>(Arrays.asList(oldProviders.split(","))); |
| 1987 | Set<String> newProvidersSet = new ArraySet<>(); |
| 1988 | newProvidersSet.addAll(oldProvidersList); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1989 | |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 1990 | String[] providerUpdates = value.split(","); |
| 1991 | boolean inputError = false; |
| 1992 | for (String provider : providerUpdates) { |
| 1993 | // do not update location_providers_allowed when input is invalid |
| 1994 | if (TextUtils.isEmpty(provider)) { |
| 1995 | inputError = true; |
| 1996 | break; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1997 | } |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 1998 | final char prefix = provider.charAt(0); |
| 1999 | // do not update location_providers_allowed when input is invalid |
| 2000 | if (prefix != '+' && prefix != '-') { |
| 2001 | inputError = true; |
| 2002 | break; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2003 | } |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 2004 | // skip prefix |
| 2005 | provider = provider.substring(1); |
| 2006 | if (prefix == '+') { |
| 2007 | newProvidersSet.add(provider); |
| 2008 | } else if (prefix == '-') { |
| 2009 | newProvidersSet.remove(provider); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2010 | } |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 2011 | } |
| 2012 | String newProviders = TextUtils.join(",", newProvidersSet.toArray()); |
| 2013 | if (inputError == true || newProviders.equals(oldProviders)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2014 | // nothing changed, so no need to update the database |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2015 | if (forceNotify) { |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 2016 | mSettingsRegistry.notifyForSettingsChange( |
| 2017 | makeKey(SETTINGS_TYPE_SECURE, owningUserId), |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2018 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED); |
| 2019 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2020 | return false; |
| 2021 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2022 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, |
Maggie | 83e03f5 | 2018-03-16 12:22:20 -0700 | [diff] [blame] | 2023 | owningUserId, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, newProviders, tag, |
| 2024 | makeDefault, getCallingPackage(), forceNotify, CRITICAL_SECURE_SETTINGS); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2025 | } |
| 2026 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2027 | private static void warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk( |
| 2028 | int targetSdkVersion, String name) { |
| 2029 | // If the app targets Lollipop MR1 or older SDK we warn, otherwise crash. |
| 2030 | if (targetSdkVersion <= Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 2031 | if (Settings.System.PRIVATE_SETTINGS.contains(name)) { |
| 2032 | Slog.w(LOG_TAG, "You shouldn't not change private system settings." |
| 2033 | + " This will soon become an error."); |
| 2034 | } else { |
| 2035 | Slog.w(LOG_TAG, "You shouldn't keep your settings in the secure settings." |
| 2036 | + " This will soon become an error."); |
| 2037 | } |
| 2038 | } else { |
| 2039 | if (Settings.System.PRIVATE_SETTINGS.contains(name)) { |
| 2040 | throw new IllegalArgumentException("You cannot change private secure settings."); |
| 2041 | } else { |
| 2042 | throw new IllegalArgumentException("You cannot keep your settings in" |
| 2043 | + " the secure settings."); |
| 2044 | } |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | private static int resolveCallingUserIdEnforcingPermissionsLocked(int requestingUserId) { |
| 2049 | if (requestingUserId == UserHandle.getCallingUserId()) { |
| 2050 | return requestingUserId; |
| 2051 | } |
| 2052 | return ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 2053 | Binder.getCallingUid(), requestingUserId, false, true, |
| 2054 | "get/set setting for user", null); |
| 2055 | } |
| 2056 | |
Matt Pape | 793b15c | 2019-10-07 13:17:20 -0700 | [diff] [blame] | 2057 | private Bundle packageValueForCallResult(Setting setting, boolean trackingGeneration) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2058 | if (!trackingGeneration) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2059 | if (setting == null || setting.isNull()) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2060 | return NULL_SETTING_BUNDLE; |
| 2061 | } |
| 2062 | return Bundle.forPair(Settings.NameValueTable.VALUE, setting.getValue()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2063 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2064 | Bundle result = new Bundle(); |
| 2065 | result.putString(Settings.NameValueTable.VALUE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2066 | !setting.isNull() ? setting.getValue() : null); |
Svet Ganov | 96c9946 | 2017-05-05 14:27:13 -0700 | [diff] [blame] | 2067 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2068 | mSettingsRegistry.mGenerationRegistry.addGenerationData(result, setting.getKey()); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2069 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2070 | } |
| 2071 | |
Matt Pape | 793b15c | 2019-10-07 13:17:20 -0700 | [diff] [blame] | 2072 | private Bundle packageValuesForCallResult(HashMap<String, String> keyValues, |
| 2073 | boolean trackingGeneration) { |
| 2074 | Bundle result = new Bundle(); |
| 2075 | result.putSerializable(Settings.NameValueTable.VALUE, keyValues); |
| 2076 | if (trackingGeneration) { |
| 2077 | synchronized (mLock) { |
| 2078 | mSettingsRegistry.mGenerationRegistry.addGenerationData(result, |
| 2079 | mSettingsRegistry.getSettingsLocked( |
| 2080 | SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM).mKey); |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | return result; |
| 2085 | } |
| 2086 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2087 | private static int getRequestingUserId(Bundle args) { |
| 2088 | final int callingUserId = UserHandle.getCallingUserId(); |
| 2089 | return (args != null) ? args.getInt(Settings.CALL_METHOD_USER_KEY, callingUserId) |
| 2090 | : callingUserId; |
| 2091 | } |
| 2092 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2093 | private boolean isTrackingGeneration(Bundle args) { |
| 2094 | return args != null && args.containsKey(Settings.CALL_METHOD_TRACK_GENERATION_KEY); |
| 2095 | } |
| 2096 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2097 | private static String getSettingValue(Bundle args) { |
| 2098 | return (args != null) ? args.getString(Settings.NameValueTable.VALUE) : null; |
| 2099 | } |
| 2100 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2101 | private static String getSettingTag(Bundle args) { |
| 2102 | return (args != null) ? args.getString(Settings.CALL_METHOD_TAG_KEY) : null; |
| 2103 | } |
| 2104 | |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 2105 | private static String getSettingPrefix(Bundle args) { |
| 2106 | String prefix = (args != null) ? args.getString(Settings.CALL_METHOD_PREFIX_KEY) : null; |
| 2107 | // Append '/' to ensure we only match properties with this exact prefix. |
| 2108 | // i.e. "foo" should match "foo/property" but not "foobar/property" |
| 2109 | return prefix != null ? prefix + "/" : null; |
| 2110 | } |
| 2111 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2112 | private static boolean getSettingMakeDefault(Bundle args) { |
| 2113 | return (args != null) && args.getBoolean(Settings.CALL_METHOD_MAKE_DEFAULT_KEY); |
| 2114 | } |
| 2115 | |
| 2116 | private static int getResetModeEnforcingPermission(Bundle args) { |
| 2117 | final int mode = (args != null) ? args.getInt(Settings.CALL_METHOD_RESET_MODE_KEY) : 0; |
| 2118 | switch (mode) { |
| 2119 | case Settings.RESET_MODE_UNTRUSTED_DEFAULTS: { |
| 2120 | if (!isCallerSystemOrShellOrRootOnDebuggableBuild()) { |
| 2121 | throw new SecurityException("Only system, shell/root on a " |
| 2122 | + "debuggable build can reset to untrusted defaults"); |
| 2123 | } |
| 2124 | return mode; |
| 2125 | } |
| 2126 | case Settings.RESET_MODE_UNTRUSTED_CHANGES: { |
| 2127 | if (!isCallerSystemOrShellOrRootOnDebuggableBuild()) { |
| 2128 | throw new SecurityException("Only system, shell/root on a " |
| 2129 | + "debuggable build can reset untrusted changes"); |
| 2130 | } |
| 2131 | return mode; |
| 2132 | } |
| 2133 | case Settings.RESET_MODE_TRUSTED_DEFAULTS: { |
| 2134 | if (!isCallerSystemOrShellOrRootOnDebuggableBuild()) { |
| 2135 | throw new SecurityException("Only system, shell/root on a " |
| 2136 | + "debuggable build can reset to trusted defaults"); |
| 2137 | } |
| 2138 | return mode; |
| 2139 | } |
| 2140 | case Settings.RESET_MODE_PACKAGE_DEFAULTS: { |
| 2141 | return mode; |
| 2142 | } |
| 2143 | } |
| 2144 | throw new IllegalArgumentException("Invalid reset mode: " + mode); |
| 2145 | } |
| 2146 | |
| 2147 | private static boolean isCallerSystemOrShellOrRootOnDebuggableBuild() { |
| 2148 | final int appId = UserHandle.getAppId(Binder.getCallingUid()); |
| 2149 | return appId == SYSTEM_UID || (Build.IS_DEBUGGABLE |
| 2150 | && (appId == SHELL_UID || appId == ROOT_UID)); |
| 2151 | } |
| 2152 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2153 | private static String getValidTableOrThrow(Uri uri) { |
| 2154 | if (uri.getPathSegments().size() > 0) { |
| 2155 | String table = uri.getPathSegments().get(0); |
| 2156 | if (DatabaseHelper.isValidTable(table)) { |
| 2157 | return table; |
| 2158 | } |
| 2159 | throw new IllegalArgumentException("Bad root path: " + table); |
| 2160 | } |
| 2161 | throw new IllegalArgumentException("Invalid URI:" + uri); |
| 2162 | } |
| 2163 | |
| 2164 | private static MatrixCursor packageSettingForQuery(Setting setting, String[] projection) { |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 2165 | if (setting.isNull()) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2166 | return new MatrixCursor(projection, 0); |
| 2167 | } |
| 2168 | MatrixCursor cursor = new MatrixCursor(projection, 1); |
| 2169 | appendSettingToCursor(cursor, setting); |
| 2170 | return cursor; |
| 2171 | } |
| 2172 | |
| 2173 | private static String[] normalizeProjection(String[] projection) { |
| 2174 | if (projection == null) { |
| 2175 | return ALL_COLUMNS; |
| 2176 | } |
| 2177 | |
| 2178 | final int columnCount = projection.length; |
| 2179 | for (int i = 0; i < columnCount; i++) { |
| 2180 | String column = projection[i]; |
| 2181 | if (!ArrayUtils.contains(ALL_COLUMNS, column)) { |
| 2182 | throw new IllegalArgumentException("Invalid column: " + column); |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2186 | return projection; |
| 2187 | } |
| 2188 | |
| 2189 | private static void appendSettingToCursor(MatrixCursor cursor, Setting setting) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2190 | if (setting == null || setting.isNull()) { |
Suprabh Shukla | c9d064a | 2016-04-12 18:45:34 -0700 | [diff] [blame] | 2191 | return; |
| 2192 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2193 | final int columnCount = cursor.getColumnCount(); |
| 2194 | |
| 2195 | String[] values = new String[columnCount]; |
| 2196 | |
| 2197 | for (int i = 0; i < columnCount; i++) { |
| 2198 | String column = cursor.getColumnName(i); |
| 2199 | |
| 2200 | switch (column) { |
| 2201 | case Settings.NameValueTable._ID: { |
| 2202 | values[i] = setting.getId(); |
| 2203 | } break; |
| 2204 | |
| 2205 | case Settings.NameValueTable.NAME: { |
| 2206 | values[i] = setting.getName(); |
| 2207 | } break; |
| 2208 | |
| 2209 | case Settings.NameValueTable.VALUE: { |
| 2210 | values[i] = setting.getValue(); |
| 2211 | } break; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 2212 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2213 | } |
| 2214 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2215 | cursor.addRow(values); |
| 2216 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2217 | |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 2218 | private static boolean isKeyValid(String key) { |
| 2219 | return !(TextUtils.isEmpty(key) || SettingsState.isBinary(key)); |
| 2220 | } |
| 2221 | |
Matt Pape | 7b1c6cd | 2019-01-04 08:10:41 -0800 | [diff] [blame] | 2222 | private String resolveCallingPackage() { |
| 2223 | switch (Binder.getCallingUid()) { |
| 2224 | case Process.ROOT_UID: { |
| 2225 | return "root"; |
| 2226 | } |
| 2227 | |
| 2228 | case Process.SHELL_UID: { |
| 2229 | return "com.android.shell"; |
| 2230 | } |
| 2231 | |
| 2232 | default: { |
| 2233 | return getCallingPackage(); |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2238 | private static final class Arguments { |
| 2239 | private static final Pattern WHERE_PATTERN_WITH_PARAM_NO_BRACKETS = |
| 2240 | Pattern.compile("[\\s]*name[\\s]*=[\\s]*\\?[\\s]*"); |
| 2241 | |
| 2242 | private static final Pattern WHERE_PATTERN_WITH_PARAM_IN_BRACKETS = |
| 2243 | Pattern.compile("[\\s]*\\([\\s]*name[\\s]*=[\\s]*\\?[\\s]*\\)[\\s]*"); |
| 2244 | |
| 2245 | private static final Pattern WHERE_PATTERN_NO_PARAM_IN_BRACKETS = |
| 2246 | Pattern.compile("[\\s]*\\([\\s]*name[\\s]*=[\\s]*['\"].*['\"][\\s]*\\)[\\s]*"); |
| 2247 | |
| 2248 | private static final Pattern WHERE_PATTERN_NO_PARAM_NO_BRACKETS = |
| 2249 | Pattern.compile("[\\s]*name[\\s]*=[\\s]*['\"].*['\"][\\s]*"); |
| 2250 | |
| 2251 | public final String table; |
| 2252 | public final String name; |
| 2253 | |
| 2254 | public Arguments(Uri uri, String where, String[] whereArgs, boolean supportAll) { |
| 2255 | final int segmentSize = uri.getPathSegments().size(); |
| 2256 | switch (segmentSize) { |
| 2257 | case 1: { |
| 2258 | if (where != null |
| 2259 | && (WHERE_PATTERN_WITH_PARAM_NO_BRACKETS.matcher(where).matches() |
| 2260 | || WHERE_PATTERN_WITH_PARAM_IN_BRACKETS.matcher(where).matches()) |
| 2261 | && whereArgs.length == 1) { |
| 2262 | name = whereArgs[0]; |
| 2263 | table = computeTableForSetting(uri, name); |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 2264 | return; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2265 | } else if (where != null |
| 2266 | && (WHERE_PATTERN_NO_PARAM_NO_BRACKETS.matcher(where).matches() |
| 2267 | || WHERE_PATTERN_NO_PARAM_IN_BRACKETS.matcher(where).matches())) { |
| 2268 | final int startIndex = Math.max(where.indexOf("'"), |
| 2269 | where.indexOf("\"")) + 1; |
| 2270 | final int endIndex = Math.max(where.lastIndexOf("'"), |
| 2271 | where.lastIndexOf("\"")); |
| 2272 | name = where.substring(startIndex, endIndex); |
| 2273 | table = computeTableForSetting(uri, name); |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 2274 | return; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2275 | } else if (supportAll && where == null && whereArgs == null) { |
| 2276 | name = null; |
| 2277 | table = computeTableForSetting(uri, null); |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 2278 | return; |
Brad Fitzpatrick | 342984a | 2010-03-09 16:59:30 -0800 | [diff] [blame] | 2279 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2280 | } break; |
| 2281 | |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 2282 | case 2: { |
| 2283 | if (where == null && whereArgs == null) { |
| 2284 | name = uri.getPathSegments().get(1); |
| 2285 | table = computeTableForSetting(uri, name); |
| 2286 | return; |
| 2287 | } |
| 2288 | } break; |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2289 | } |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 2290 | |
| 2291 | EventLogTags.writeUnsupportedSettingsQuery( |
| 2292 | uri.toSafeString(), where, Arrays.toString(whereArgs)); |
| 2293 | String message = String.format( "Supported SQL:\n" |
| 2294 | + " uri content://some_table/some_property with null where and where args\n" |
| 2295 | + " uri content://some_table with query name=? and single name as arg\n" |
| 2296 | + " uri content://some_table with query name=some_name and null args\n" |
| 2297 | + " but got - uri:%1s, where:%2s whereArgs:%3s", uri, where, |
| 2298 | Arrays.toString(whereArgs)); |
| 2299 | throw new IllegalArgumentException(message); |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2300 | } |
| 2301 | |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 2302 | private static String computeTableForSetting(Uri uri, String name) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2303 | String table = getValidTableOrThrow(uri); |
| 2304 | |
| 2305 | if (name != null) { |
| 2306 | if (sSystemMovedToSecureSettings.contains(name)) { |
| 2307 | table = TABLE_SECURE; |
| 2308 | } |
| 2309 | |
| 2310 | if (sSystemMovedToGlobalSettings.contains(name)) { |
| 2311 | table = TABLE_GLOBAL; |
| 2312 | } |
| 2313 | |
| 2314 | if (sSecureMovedToGlobalSettings.contains(name)) { |
| 2315 | table = TABLE_GLOBAL; |
| 2316 | } |
| 2317 | |
| 2318 | if (sGlobalMovedToSecureSettings.contains(name)) { |
| 2319 | table = TABLE_SECURE; |
| 2320 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2321 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2322 | |
| 2323 | return table; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | final class SettingsRegistry { |
| 2328 | private static final String DROPBOX_TAG_USERLOG = "restricted_profile_ssaid"; |
| 2329 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2330 | private static final String SETTINGS_FILE_GLOBAL = "settings_global.xml"; |
| 2331 | private static final String SETTINGS_FILE_SYSTEM = "settings_system.xml"; |
| 2332 | private static final String SETTINGS_FILE_SECURE = "settings_secure.xml"; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2333 | private static final String SETTINGS_FILE_SSAID = "settings_ssaid.xml"; |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 2334 | private static final String SETTINGS_FILE_CONFIG = "settings_config.xml"; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2335 | |
| 2336 | private static final String SSAID_USER_KEY = "userkey"; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2337 | |
| 2338 | private final SparseArray<SettingsState> mSettingsStates = new SparseArray<>(); |
| 2339 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2340 | private GenerationRegistry mGenerationRegistry; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2341 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 2342 | private final Handler mHandler; |
| 2343 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2344 | private final BackupManager mBackupManager; |
| 2345 | |
Amith Yamasani | 3945202 | 2017-03-21 15:23:47 -0700 | [diff] [blame] | 2346 | private String mSettingsCreationBuildId; |
| 2347 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2348 | public SettingsRegistry() { |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 2349 | mHandler = new MyHandler(getContext().getMainLooper()); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2350 | mGenerationRegistry = new GenerationRegistry(mLock); |
| 2351 | mBackupManager = new BackupManager(getContext()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2352 | migrateAllLegacySettingsIfNeeded(); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2353 | syncSsaidTableOnStart(); |
| 2354 | } |
| 2355 | |
| 2356 | private void generateUserKeyLocked(int userId) { |
| 2357 | // Generate a random key for each user used for creating a new ssaid. |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2358 | final byte[] keyBytes = new byte[32]; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2359 | final SecureRandom rand = new SecureRandom(); |
| 2360 | rand.nextBytes(keyBytes); |
| 2361 | |
| 2362 | // Convert to string for storage in settings table. |
Neil Fuller | 3447fb4 | 2019-04-08 22:03:14 +0100 | [diff] [blame] | 2363 | final String userKey = HexEncoding.encodeToString(keyBytes, true /* upperCase */); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2364 | |
| 2365 | // Store the key in the ssaid table. |
| 2366 | final SettingsState ssaidSettings = getSettingsLocked(SETTINGS_TYPE_SSAID, userId); |
| 2367 | final boolean success = ssaidSettings.insertSettingLocked(SSAID_USER_KEY, userKey, null, |
| 2368 | true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 2369 | |
| 2370 | if (!success) { |
| 2371 | throw new IllegalStateException("Ssaid settings not accessible"); |
| 2372 | } |
| 2373 | } |
| 2374 | |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2375 | private byte[] getLengthPrefix(byte[] data) { |
| 2376 | return ByteBuffer.allocate(4).putInt(data.length).array(); |
| 2377 | } |
| 2378 | |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 2379 | public Setting generateSsaidLocked(PackageInfo callingPkg, int userId) { |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2380 | // Read the user's key from the ssaid table. |
| 2381 | Setting userKeySetting = getSettingLocked(SETTINGS_TYPE_SSAID, userId, SSAID_USER_KEY); |
Mark Rathjen | ea61759 | 2017-01-18 23:03:41 -0800 | [diff] [blame] | 2382 | if (userKeySetting == null || userKeySetting.isNull() |
| 2383 | || userKeySetting.getValue() == null) { |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2384 | // Lazy initialize and store the user key. |
| 2385 | generateUserKeyLocked(userId); |
| 2386 | userKeySetting = getSettingLocked(SETTINGS_TYPE_SSAID, userId, SSAID_USER_KEY); |
Mark Rathjen | ea61759 | 2017-01-18 23:03:41 -0800 | [diff] [blame] | 2387 | if (userKeySetting == null || userKeySetting.isNull() |
| 2388 | || userKeySetting.getValue() == null) { |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2389 | throw new IllegalStateException("User key not accessible"); |
| 2390 | } |
| 2391 | } |
| 2392 | final String userKey = userKeySetting.getValue(); |
Neil Fuller | 3447fb4 | 2019-04-08 22:03:14 +0100 | [diff] [blame] | 2393 | if (userKey == null || userKey.length() % 2 != 0) { |
| 2394 | throw new IllegalStateException("User key invalid"); |
| 2395 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2396 | |
| 2397 | // Convert the user's key back to a byte array. |
Neil Fuller | 3447fb4 | 2019-04-08 22:03:14 +0100 | [diff] [blame] | 2398 | final byte[] keyBytes = HexEncoding.decode(userKey); |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2399 | |
| 2400 | // Validate that the key is of expected length. |
| 2401 | // Keys are currently 32 bytes, but were once 16 bytes during Android O development. |
Neil Fuller | 3447fb4 | 2019-04-08 22:03:14 +0100 | [diff] [blame] | 2402 | if (keyBytes.length != 16 && keyBytes.length != 32) { |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2403 | throw new IllegalStateException("User key invalid"); |
| 2404 | } |
| 2405 | |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2406 | final Mac m; |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2407 | try { |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2408 | m = Mac.getInstance("HmacSHA256"); |
| 2409 | m.init(new SecretKeySpec(keyBytes, m.getAlgorithm())); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2410 | } catch (NoSuchAlgorithmException e) { |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2411 | throw new IllegalStateException("HmacSHA256 is not available", e); |
| 2412 | } catch (InvalidKeyException e) { |
| 2413 | throw new IllegalStateException("Key is corrupted", e); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2414 | } |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2415 | |
Mark Rathjen | f42dd91 | 2017-06-05 19:04:34 -0700 | [diff] [blame] | 2416 | // Mac each of the developer signatures. |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 2417 | for (int i = 0; i < callingPkg.signatures.length; i++) { |
| 2418 | byte[] sig = callingPkg.signatures[i].toByteArray(); |
Mark Rathjen | 7599f13 | 2017-01-23 14:15:54 -0800 | [diff] [blame] | 2419 | m.update(getLengthPrefix(sig), 0, 4); |
| 2420 | m.update(sig); |
| 2421 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2422 | |
| 2423 | // Convert result to a string for storage in settings table. Only want first 64 bits. |
Neil Fuller | 3447fb4 | 2019-04-08 22:03:14 +0100 | [diff] [blame] | 2424 | final String ssaid = HexEncoding.encodeToString(m.doFinal(), false /* upperCase */) |
| 2425 | .substring(0, 16); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2426 | |
| 2427 | // Save the ssaid in the ssaid table. |
Christopher Tate | b218e76 | 2017-04-05 16:34:07 -0700 | [diff] [blame] | 2428 | final String uid = Integer.toString(callingPkg.applicationInfo.uid); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2429 | final SettingsState ssaidSettings = getSettingsLocked(SETTINGS_TYPE_SSAID, userId); |
| 2430 | final boolean success = ssaidSettings.insertSettingLocked(uid, ssaid, null, true, |
Mark Rathjen | f42dd91 | 2017-06-05 19:04:34 -0700 | [diff] [blame] | 2431 | callingPkg.packageName); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2432 | |
| 2433 | if (!success) { |
| 2434 | throw new IllegalStateException("Ssaid settings not accessible"); |
| 2435 | } |
| 2436 | |
| 2437 | return getSettingLocked(SETTINGS_TYPE_SSAID, userId, uid); |
| 2438 | } |
| 2439 | |
| 2440 | public void syncSsaidTableOnStart() { |
| 2441 | synchronized (mLock) { |
| 2442 | // Verify that each user's packages and ssaid's are in sync. |
| 2443 | for (UserInfo user : mUserManager.getUsers(true)) { |
| 2444 | // Get all uids for the user's packages. |
| 2445 | final List<PackageInfo> packages; |
| 2446 | try { |
Tetsutoki Shiozawa | ebe0e5f | 2018-01-17 11:07:09 +0900 | [diff] [blame] | 2447 | packages = mPackageManager.getInstalledPackages( |
| 2448 | PackageManager.MATCH_UNINSTALLED_PACKAGES, |
| 2449 | user.id).getList(); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2450 | } catch (RemoteException e) { |
| 2451 | throw new IllegalStateException("Package manager not available"); |
| 2452 | } |
| 2453 | final Set<String> appUids = new HashSet<>(); |
| 2454 | for (PackageInfo info : packages) { |
| 2455 | appUids.add(Integer.toString(info.applicationInfo.uid)); |
| 2456 | } |
| 2457 | |
| 2458 | // Get all uids currently stored in the user's ssaid table. |
| 2459 | final Set<String> ssaidUids = new HashSet<>( |
| 2460 | getSettingsNamesLocked(SETTINGS_TYPE_SSAID, user.id)); |
| 2461 | ssaidUids.remove(SSAID_USER_KEY); |
| 2462 | |
| 2463 | // Perform a set difference for the appUids and ssaidUids. |
| 2464 | ssaidUids.removeAll(appUids); |
| 2465 | |
| 2466 | // If there are ssaidUids left over they need to be removed from the table. |
| 2467 | final SettingsState ssaidSettings = getSettingsLocked(SETTINGS_TYPE_SSAID, |
| 2468 | user.id); |
| 2469 | for (String uid : ssaidUids) { |
| 2470 | ssaidSettings.deleteSettingLocked(uid); |
| 2471 | } |
| 2472 | } |
| 2473 | } |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2476 | public List<String> getSettingsNamesLocked(int type, int userId) { |
| 2477 | final int key = makeKey(type, userId); |
| 2478 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2479 | if (settingsState == null) { |
| 2480 | return new ArrayList<String>(); |
| 2481 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2482 | return settingsState.getSettingNamesLocked(); |
| 2483 | } |
| 2484 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2485 | public SparseBooleanArray getKnownUsersLocked() { |
| 2486 | SparseBooleanArray users = new SparseBooleanArray(); |
| 2487 | for (int i = mSettingsStates.size()-1; i >= 0; i--) { |
| 2488 | users.put(getUserIdFromKey(mSettingsStates.keyAt(i)), true); |
| 2489 | } |
| 2490 | return users; |
| 2491 | } |
| 2492 | |
Kweku Adams | b0886f3 | 2017-10-31 15:32:09 -0700 | [diff] [blame] | 2493 | @Nullable |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2494 | public SettingsState getSettingsLocked(int type, int userId) { |
| 2495 | final int key = makeKey(type, userId); |
| 2496 | return peekSettingsStateLocked(key); |
| 2497 | } |
| 2498 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2499 | public boolean ensureSettingsForUserLocked(int userId) { |
| 2500 | // First make sure this user actually exists. |
| 2501 | if (mUserManager.getUserInfo(userId) == null) { |
| 2502 | Slog.wtf(LOG_TAG, "Requested user " + userId + " does not exist"); |
| 2503 | return false; |
| 2504 | } |
| 2505 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2506 | // Migrate the setting for this user if needed. |
| 2507 | migrateLegacySettingsForUserIfNeededLocked(userId); |
| 2508 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 2509 | // Ensure config settings loaded if owner. |
| 2510 | if (userId == UserHandle.USER_SYSTEM) { |
| 2511 | final int configKey |
| 2512 | = makeKey(SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM); |
| 2513 | ensureSettingsStateLocked(configKey); |
| 2514 | } |
| 2515 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2516 | // Ensure global settings loaded if owner. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 2517 | if (userId == UserHandle.USER_SYSTEM) { |
| 2518 | final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2519 | ensureSettingsStateLocked(globalKey); |
| 2520 | } |
| 2521 | |
| 2522 | // Ensure secure settings loaded. |
| 2523 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 2524 | ensureSettingsStateLocked(secureKey); |
| 2525 | |
| 2526 | // Make sure the secure settings have an Android id set. |
| 2527 | SettingsState secureSettings = getSettingsLocked(SETTINGS_TYPE_SECURE, userId); |
| 2528 | ensureSecureSettingAndroidIdSetLocked(secureSettings); |
| 2529 | |
| 2530 | // Ensure system settings loaded. |
| 2531 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 2532 | ensureSettingsStateLocked(systemKey); |
| 2533 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2534 | // Ensure secure settings loaded. |
| 2535 | final int ssaidKey = makeKey(SETTINGS_TYPE_SSAID, userId); |
| 2536 | ensureSettingsStateLocked(ssaidKey); |
| 2537 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2538 | // Upgrade the settings to the latest version. |
| 2539 | UpgradeController upgrader = new UpgradeController(userId); |
| 2540 | upgrader.upgradeIfNeededLocked(); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2541 | return true; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | private void ensureSettingsStateLocked(int key) { |
| 2545 | if (mSettingsStates.get(key) == null) { |
| 2546 | final int maxBytesPerPackage = getMaxBytesPerPackageForType(getTypeFromKey(key)); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2547 | SettingsState settingsState = new SettingsState(getContext(), mLock, |
| 2548 | getSettingsFile(key), key, maxBytesPerPackage, mHandlerThread.getLooper()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2549 | mSettingsStates.put(key, settingsState); |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | public void removeUserStateLocked(int userId, boolean permanently) { |
| 2554 | // We always keep the global settings in memory. |
| 2555 | |
| 2556 | // Nuke system settings. |
| 2557 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 2558 | final SettingsState systemSettingsState = mSettingsStates.get(systemKey); |
| 2559 | if (systemSettingsState != null) { |
| 2560 | if (permanently) { |
| 2561 | mSettingsStates.remove(systemKey); |
| 2562 | systemSettingsState.destroyLocked(null); |
Brad Fitzpatrick | 342984a | 2010-03-09 16:59:30 -0800 | [diff] [blame] | 2563 | } else { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2564 | systemSettingsState.destroyLocked(new Runnable() { |
| 2565 | @Override |
| 2566 | public void run() { |
| 2567 | mSettingsStates.remove(systemKey); |
| 2568 | } |
| 2569 | }); |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | // Nuke secure settings. |
| 2574 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 2575 | final SettingsState secureSettingsState = mSettingsStates.get(secureKey); |
| 2576 | if (secureSettingsState != null) { |
| 2577 | if (permanently) { |
| 2578 | mSettingsStates.remove(secureKey); |
| 2579 | secureSettingsState.destroyLocked(null); |
| 2580 | } else { |
| 2581 | secureSettingsState.destroyLocked(new Runnable() { |
| 2582 | @Override |
| 2583 | public void run() { |
| 2584 | mSettingsStates.remove(secureKey); |
| 2585 | } |
| 2586 | }); |
Brad Fitzpatrick | 342984a | 2010-03-09 16:59:30 -0800 | [diff] [blame] | 2587 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2588 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2589 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2590 | // Nuke ssaid settings. |
| 2591 | final int ssaidKey = makeKey(SETTINGS_TYPE_SSAID, userId); |
| 2592 | final SettingsState ssaidSettingsState = mSettingsStates.get(ssaidKey); |
| 2593 | if (ssaidSettingsState != null) { |
| 2594 | if (permanently) { |
| 2595 | mSettingsStates.remove(ssaidKey); |
| 2596 | ssaidSettingsState.destroyLocked(null); |
| 2597 | } else { |
| 2598 | ssaidSettingsState.destroyLocked(new Runnable() { |
| 2599 | @Override |
| 2600 | public void run() { |
| 2601 | mSettingsStates.remove(ssaidKey); |
| 2602 | } |
| 2603 | }); |
| 2604 | } |
| 2605 | } |
| 2606 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2607 | // Nuke generation tracking data |
| 2608 | mGenerationRegistry.onUserRemoved(userId); |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2609 | } |
| 2610 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2611 | public boolean insertSettingLocked(int type, int userId, String name, String value, |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2612 | String tag, boolean makeDefault, String packageName, boolean forceNotify, |
| 2613 | Set<String> criticalSettings) { |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 2614 | return insertSettingLocked(type, userId, name, value, tag, makeDefault, false, |
| 2615 | packageName, forceNotify, criticalSettings); |
| 2616 | } |
| 2617 | |
| 2618 | public boolean insertSettingLocked(int type, int userId, String name, String value, |
| 2619 | String tag, boolean makeDefault, boolean forceNonSystemPackage, String packageName, |
| 2620 | boolean forceNotify, Set<String> criticalSettings) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2621 | final int key = makeKey(type, userId); |
| 2622 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2623 | boolean success = false; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2624 | SettingsState settingsState = peekSettingsStateLocked(key); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2625 | if (settingsState != null) { |
| 2626 | success = settingsState.insertSettingLocked(name, value, |
Matt Pape | c1323dc | 2018-12-11 12:32:42 -0800 | [diff] [blame] | 2627 | tag, makeDefault, forceNonSystemPackage, packageName); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2628 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2629 | |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2630 | if (success && criticalSettings != null && criticalSettings.contains(name)) { |
| 2631 | settingsState.persistSyncLocked(); |
| 2632 | } |
| 2633 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2634 | if (forceNotify || success) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2635 | notifyForSettingsChange(key, name); |
| 2636 | } |
| 2637 | return success; |
| 2638 | } |
| 2639 | |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2640 | public boolean deleteSettingLocked(int type, int userId, String name, boolean forceNotify, |
| 2641 | Set<String> criticalSettings) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2642 | final int key = makeKey(type, userId); |
| 2643 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2644 | boolean success = false; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2645 | SettingsState settingsState = peekSettingsStateLocked(key); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2646 | if (settingsState != null) { |
| 2647 | success = settingsState.deleteSettingLocked(name); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2648 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2649 | |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2650 | if (success && criticalSettings != null && criticalSettings.contains(name)) { |
| 2651 | settingsState.persistSyncLocked(); |
| 2652 | } |
| 2653 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2654 | if (forceNotify || success) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2655 | notifyForSettingsChange(key, name); |
| 2656 | } |
| 2657 | return success; |
| 2658 | } |
| 2659 | |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2660 | public boolean updateSettingLocked(int type, int userId, String name, String value, |
| 2661 | String tag, boolean makeDefault, String packageName, boolean forceNotify, |
| 2662 | Set<String> criticalSettings) { |
| 2663 | final int key = makeKey(type, userId); |
| 2664 | |
| 2665 | boolean success = false; |
| 2666 | SettingsState settingsState = peekSettingsStateLocked(key); |
| 2667 | if (settingsState != null) { |
| 2668 | success = settingsState.updateSettingLocked(name, value, tag, |
| 2669 | makeDefault, packageName); |
| 2670 | } |
| 2671 | |
| 2672 | if (success && criticalSettings != null && criticalSettings.contains(name)) { |
| 2673 | settingsState.persistSyncLocked(); |
| 2674 | } |
| 2675 | |
| 2676 | if (forceNotify || success) { |
| 2677 | notifyForSettingsChange(key, name); |
| 2678 | } |
| 2679 | |
| 2680 | return success; |
| 2681 | } |
| 2682 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2683 | public Setting getSettingLocked(int type, int userId, String name) { |
| 2684 | final int key = makeKey(type, userId); |
| 2685 | |
| 2686 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2687 | if (settingsState == null) { |
Mark Rathjen | ea61759 | 2017-01-18 23:03:41 -0800 | [diff] [blame] | 2688 | return null; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2689 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2690 | |
| 2691 | // getSettingLocked will return non-null result |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2692 | return settingsState.getSettingLocked(name); |
| 2693 | } |
| 2694 | |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2695 | public void resetSettingsLocked(int type, int userId, String packageName, int mode, |
| 2696 | String tag) { |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 2697 | resetSettingsLocked(type, userId, packageName, mode, tag, null); |
| 2698 | } |
| 2699 | |
| 2700 | public void resetSettingsLocked(int type, int userId, String packageName, int mode, |
| 2701 | String tag, @Nullable String prefix) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2702 | final int key = makeKey(type, userId); |
| 2703 | SettingsState settingsState = peekSettingsStateLocked(key); |
| 2704 | if (settingsState == null) { |
| 2705 | return; |
| 2706 | } |
| 2707 | |
| 2708 | switch (mode) { |
| 2709 | case Settings.RESET_MODE_PACKAGE_DEFAULTS: { |
| 2710 | for (String name : settingsState.getSettingNamesLocked()) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2711 | boolean someSettingChanged = false; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2712 | Setting setting = settingsState.getSettingLocked(name); |
| 2713 | if (packageName.equals(setting.getPackageName())) { |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 2714 | if ((tag != null && !tag.equals(setting.getTag())) |
| 2715 | || (prefix != null && !setting.getName().startsWith(prefix))) { |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2716 | continue; |
| 2717 | } |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2718 | if (settingsState.resetSettingLocked(name)) { |
| 2719 | someSettingChanged = true; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2720 | notifyForSettingsChange(key, name); |
| 2721 | } |
| 2722 | } |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2723 | if (someSettingChanged) { |
| 2724 | settingsState.persistSyncLocked(); |
| 2725 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2726 | } |
| 2727 | } break; |
| 2728 | |
| 2729 | case Settings.RESET_MODE_UNTRUSTED_DEFAULTS: { |
| 2730 | for (String name : settingsState.getSettingNamesLocked()) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2731 | boolean someSettingChanged = false; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2732 | Setting setting = settingsState.getSettingLocked(name); |
| 2733 | if (!SettingsState.isSystemPackage(getContext(), |
Matt Pape | 25c940d | 2019-03-26 12:14:33 -0700 | [diff] [blame] | 2734 | setting.getPackageName(), INVALID_UID, userId)) { |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 2735 | if (prefix != null && !setting.getName().startsWith(prefix)) { |
| 2736 | continue; |
| 2737 | } |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2738 | if (settingsState.resetSettingLocked(name)) { |
| 2739 | someSettingChanged = true; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2740 | notifyForSettingsChange(key, name); |
| 2741 | } |
| 2742 | } |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2743 | if (someSettingChanged) { |
| 2744 | settingsState.persistSyncLocked(); |
| 2745 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2746 | } |
| 2747 | } break; |
| 2748 | |
| 2749 | case Settings.RESET_MODE_UNTRUSTED_CHANGES: { |
| 2750 | for (String name : settingsState.getSettingNamesLocked()) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2751 | boolean someSettingChanged = false; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2752 | Setting setting = settingsState.getSettingLocked(name); |
| 2753 | if (!SettingsState.isSystemPackage(getContext(), |
Matt Pape | 25c940d | 2019-03-26 12:14:33 -0700 | [diff] [blame] | 2754 | setting.getPackageName(), INVALID_UID, userId)) { |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 2755 | if (prefix != null && !setting.getName().startsWith(prefix)) { |
| 2756 | continue; |
| 2757 | } |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 2758 | if (setting.isDefaultFromSystem()) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2759 | if (settingsState.resetSettingLocked(name)) { |
| 2760 | someSettingChanged = true; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2761 | notifyForSettingsChange(key, name); |
| 2762 | } |
| 2763 | } else if (settingsState.deleteSettingLocked(name)) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2764 | someSettingChanged = true; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2765 | notifyForSettingsChange(key, name); |
| 2766 | } |
| 2767 | } |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2768 | if (someSettingChanged) { |
| 2769 | settingsState.persistSyncLocked(); |
| 2770 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2771 | } |
| 2772 | } break; |
| 2773 | |
| 2774 | case Settings.RESET_MODE_TRUSTED_DEFAULTS: { |
| 2775 | for (String name : settingsState.getSettingNamesLocked()) { |
| 2776 | Setting setting = settingsState.getSettingLocked(name); |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2777 | boolean someSettingChanged = false; |
Matt Pape | 6bfc62e | 2018-11-28 13:16:03 -0800 | [diff] [blame] | 2778 | if (prefix != null && !setting.getName().startsWith(prefix)) { |
| 2779 | continue; |
| 2780 | } |
Eugene Susla | d72c397 | 2016-12-27 15:49:30 -0800 | [diff] [blame] | 2781 | if (setting.isDefaultFromSystem()) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2782 | if (settingsState.resetSettingLocked(name)) { |
| 2783 | someSettingChanged = true; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2784 | notifyForSettingsChange(key, name); |
| 2785 | } |
| 2786 | } else if (settingsState.deleteSettingLocked(name)) { |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2787 | someSettingChanged = true; |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2788 | notifyForSettingsChange(key, name); |
| 2789 | } |
Svetoslav Ganov | 5fb405b | 2017-01-26 22:43:09 -0800 | [diff] [blame] | 2790 | if (someSettingChanged) { |
| 2791 | settingsState.persistSyncLocked(); |
| 2792 | } |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2793 | } |
| 2794 | } break; |
| 2795 | } |
| 2796 | } |
| 2797 | |
Zimuzo | c56192c | 2018-07-25 10:40:01 +0100 | [diff] [blame] | 2798 | public void removeSettingsForPackageLocked(String packageName, int userId) { |
Svet Ganov | 8de3480 | 2015-04-27 09:33:40 -0700 | [diff] [blame] | 2799 | // Global and secure settings are signature protected. Apps signed |
| 2800 | // by the platform certificate are generally not uninstalled and |
| 2801 | // the main exception is tests. We trust components signed |
| 2802 | // by the platform certificate and do not do a clean up after them. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2803 | |
| 2804 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 2805 | SettingsState systemSettings = mSettingsStates.get(systemKey); |
Svet Ganov | 8de3480 | 2015-04-27 09:33:40 -0700 | [diff] [blame] | 2806 | if (systemSettings != null) { |
Zimuzo | c56192c | 2018-07-25 10:40:01 +0100 | [diff] [blame] | 2807 | systemSettings.removeSettingsForPackageLocked(packageName); |
Svet Ganov | 8de3480 | 2015-04-27 09:33:40 -0700 | [diff] [blame] | 2808 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2809 | } |
| 2810 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2811 | public void onUidRemovedLocked(int uid) { |
| 2812 | final SettingsState ssaidSettings = getSettingsLocked(SETTINGS_TYPE_SSAID, |
| 2813 | UserHandle.getUserId(uid)); |
Tony Mak | 24c6ab4 | 2018-01-08 14:35:34 +0000 | [diff] [blame] | 2814 | if (ssaidSettings != null) { |
| 2815 | ssaidSettings.deleteSettingLocked(Integer.toString(uid)); |
| 2816 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
Kweku Adams | b0886f3 | 2017-10-31 15:32:09 -0700 | [diff] [blame] | 2819 | @Nullable |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2820 | private SettingsState peekSettingsStateLocked(int key) { |
| 2821 | SettingsState settingsState = mSettingsStates.get(key); |
| 2822 | if (settingsState != null) { |
| 2823 | return settingsState; |
| 2824 | } |
| 2825 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame] | 2826 | if (!ensureSettingsForUserLocked(getUserIdFromKey(key))) { |
| 2827 | return null; |
| 2828 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2829 | return mSettingsStates.get(key); |
| 2830 | } |
| 2831 | |
| 2832 | private void migrateAllLegacySettingsIfNeeded() { |
| 2833 | synchronized (mLock) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 2834 | final int key = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2835 | File globalFile = getSettingsFile(key); |
Amith Yamasani | 74bf71b | 2017-07-19 16:49:52 -0700 | [diff] [blame] | 2836 | if (SettingsState.stateFileExists(globalFile)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2837 | return; |
| 2838 | } |
| 2839 | |
Amith Yamasani | 3945202 | 2017-03-21 15:23:47 -0700 | [diff] [blame] | 2840 | mSettingsCreationBuildId = Build.ID; |
| 2841 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2842 | final long identity = Binder.clearCallingIdentity(); |
| 2843 | try { |
| 2844 | List<UserInfo> users = mUserManager.getUsers(true); |
| 2845 | |
| 2846 | final int userCount = users.size(); |
| 2847 | for (int i = 0; i < userCount; i++) { |
| 2848 | final int userId = users.get(i).id; |
| 2849 | |
| 2850 | DatabaseHelper dbHelper = new DatabaseHelper(getContext(), userId); |
| 2851 | SQLiteDatabase database = dbHelper.getWritableDatabase(); |
| 2852 | migrateLegacySettingsForUserLocked(dbHelper, database, userId); |
| 2853 | |
| 2854 | // Upgrade to the latest version. |
| 2855 | UpgradeController upgrader = new UpgradeController(userId); |
| 2856 | upgrader.upgradeIfNeededLocked(); |
| 2857 | |
| 2858 | // Drop from memory if not a running user. |
| 2859 | if (!mUserManager.isUserRunning(new UserHandle(userId))) { |
| 2860 | removeUserStateLocked(userId, false); |
| 2861 | } |
| 2862 | } |
| 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(identity); |
| 2865 | } |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | private void migrateLegacySettingsForUserIfNeededLocked(int userId) { |
| 2870 | // Every user has secure settings and if no file we need to migrate. |
| 2871 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 2872 | File secureFile = getSettingsFile(secureKey); |
Amith Yamasani | 74bf71b | 2017-07-19 16:49:52 -0700 | [diff] [blame] | 2873 | if (SettingsState.stateFileExists(secureFile)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2874 | return; |
| 2875 | } |
| 2876 | |
| 2877 | DatabaseHelper dbHelper = new DatabaseHelper(getContext(), userId); |
| 2878 | SQLiteDatabase database = dbHelper.getWritableDatabase(); |
| 2879 | |
| 2880 | migrateLegacySettingsForUserLocked(dbHelper, database, userId); |
| 2881 | } |
| 2882 | |
| 2883 | private void migrateLegacySettingsForUserLocked(DatabaseHelper dbHelper, |
| 2884 | SQLiteDatabase database, int userId) { |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 2885 | // Move over the system settings. |
| 2886 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 2887 | ensureSettingsStateLocked(systemKey); |
| 2888 | SettingsState systemSettings = mSettingsStates.get(systemKey); |
| 2889 | migrateLegacySettingsLocked(systemSettings, database, TABLE_SYSTEM); |
| 2890 | systemSettings.persistSyncLocked(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2891 | |
| 2892 | // Move over the secure settings. |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 2893 | // Do this after System settings, since this is the first thing we check when deciding |
| 2894 | // to skip over migration from db to xml for a secondary user. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2895 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 2896 | ensureSettingsStateLocked(secureKey); |
| 2897 | SettingsState secureSettings = mSettingsStates.get(secureKey); |
| 2898 | migrateLegacySettingsLocked(secureSettings, database, TABLE_SECURE); |
| 2899 | ensureSecureSettingAndroidIdSetLocked(secureSettings); |
| 2900 | secureSettings.persistSyncLocked(); |
| 2901 | |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 2902 | // Move over the global settings if owner. |
| 2903 | // Do this last, since this is the first thing we check when deciding |
| 2904 | // to skip over migration from db to xml for owner user. |
| 2905 | if (userId == UserHandle.USER_SYSTEM) { |
| 2906 | final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, userId); |
| 2907 | ensureSettingsStateLocked(globalKey); |
| 2908 | SettingsState globalSettings = mSettingsStates.get(globalKey); |
| 2909 | migrateLegacySettingsLocked(globalSettings, database, TABLE_GLOBAL); |
Amith Yamasani | 3945202 | 2017-03-21 15:23:47 -0700 | [diff] [blame] | 2910 | // If this was just created |
| 2911 | if (mSettingsCreationBuildId != null) { |
| 2912 | globalSettings.insertSettingLocked(Settings.Global.DATABASE_CREATION_BUILDID, |
| 2913 | mSettingsCreationBuildId, null, true, |
| 2914 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2915 | } |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 2916 | globalSettings.persistSyncLocked(); |
| 2917 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2918 | |
| 2919 | // Drop the database as now all is moved and persisted. |
| 2920 | if (DROP_DATABASE_ON_MIGRATION) { |
| 2921 | dbHelper.dropDatabase(); |
| 2922 | } else { |
| 2923 | dbHelper.backupDatabase(); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | private void migrateLegacySettingsLocked(SettingsState settingsState, |
| 2928 | SQLiteDatabase database, String table) { |
| 2929 | SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); |
| 2930 | queryBuilder.setTables(table); |
| 2931 | |
| 2932 | Cursor cursor = queryBuilder.query(database, ALL_COLUMNS, |
| 2933 | null, null, null, null, null); |
| 2934 | |
| 2935 | if (cursor == null) { |
| 2936 | return; |
| 2937 | } |
| 2938 | |
| 2939 | try { |
| 2940 | if (!cursor.moveToFirst()) { |
| 2941 | return; |
| 2942 | } |
| 2943 | |
| 2944 | final int nameColumnIdx = cursor.getColumnIndex(Settings.NameValueTable.NAME); |
| 2945 | final int valueColumnIdx = cursor.getColumnIndex(Settings.NameValueTable.VALUE); |
| 2946 | |
| 2947 | settingsState.setVersionLocked(database.getVersion()); |
| 2948 | |
| 2949 | while (!cursor.isAfterLast()) { |
| 2950 | String name = cursor.getString(nameColumnIdx); |
| 2951 | String value = cursor.getString(valueColumnIdx); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2952 | settingsState.insertSettingLocked(name, value, null, true, |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2953 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2954 | cursor.moveToNext(); |
| 2955 | } |
| 2956 | } finally { |
| 2957 | cursor.close(); |
| 2958 | } |
| 2959 | } |
| 2960 | |
Andreas Gampe | b5889307 | 2018-09-05 16:52:31 -0700 | [diff] [blame] | 2961 | @GuardedBy("secureSettings.mLock") |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2962 | private void ensureSecureSettingAndroidIdSetLocked(SettingsState secureSettings) { |
| 2963 | Setting value = secureSettings.getSettingLocked(Settings.Secure.ANDROID_ID); |
| 2964 | |
Seigo Nonaka | 6e5b602 | 2016-04-27 16:32:44 +0900 | [diff] [blame] | 2965 | if (!value.isNull()) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2966 | return; |
| 2967 | } |
| 2968 | |
| 2969 | final int userId = getUserIdFromKey(secureSettings.mKey); |
| 2970 | |
| 2971 | final UserInfo user; |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | user = mUserManager.getUserInfo(userId); |
| 2975 | } finally { |
| 2976 | Binder.restoreCallingIdentity(identity); |
| 2977 | } |
| 2978 | if (user == null) { |
| 2979 | // Can happen due to races when deleting users - treat as benign. |
| 2980 | return; |
| 2981 | } |
| 2982 | |
| 2983 | String androidId = Long.toHexString(new SecureRandom().nextLong()); |
| 2984 | secureSettings.insertSettingLocked(Settings.Secure.ANDROID_ID, androidId, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 2985 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2986 | |
| 2987 | Slog.d(LOG_TAG, "Generated and saved new ANDROID_ID [" + androidId |
| 2988 | + "] for user " + userId); |
| 2989 | |
| 2990 | // Write a drop box entry if it's a restricted profile |
| 2991 | if (user.isRestricted()) { |
| 2992 | DropBoxManager dbm = (DropBoxManager) getContext().getSystemService( |
| 2993 | Context.DROPBOX_SERVICE); |
| 2994 | if (dbm != null && dbm.isTagEnabled(DROPBOX_TAG_USERLOG)) { |
| 2995 | dbm.addText(DROPBOX_TAG_USERLOG, System.currentTimeMillis() |
| 2996 | + "," + DROPBOX_TAG_USERLOG + "," + androidId + "\n"); |
| 2997 | } |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | private void notifyForSettingsChange(int key, String name) { |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3002 | // Increment the generation first, so observers always see the new value |
Phil Weaver | 83fec00 | 2016-05-11 10:55:29 -0700 | [diff] [blame] | 3003 | mGenerationRegistry.incrementGeneration(key); |
| 3004 | |
Linus Tufvesson | 93c3855 | 2019-05-30 12:47:39 +0100 | [diff] [blame] | 3005 | if (isGlobalSettingsKey(key) || isConfigSettingsKey(key)) { |
Jeff Sharkey | 308093f | 2018-03-25 22:53:29 -0600 | [diff] [blame] | 3006 | final long token = Binder.clearCallingIdentity(); |
| 3007 | try { |
Linus Tufvesson | 93c3855 | 2019-05-30 12:47:39 +0100 | [diff] [blame] | 3008 | if (Global.LOCATION_GLOBAL_KILL_SWITCH.equals(name) |
| 3009 | && isGlobalSettingsKey(key)) { |
Jeff Sharkey | 308093f | 2018-03-25 22:53:29 -0600 | [diff] [blame] | 3010 | // When the global kill switch is updated, send the |
| 3011 | // change notification for the location setting. |
| 3012 | notifyLocationChangeForRunningUsers(); |
| 3013 | } |
Linus Tufvesson | 93c3855 | 2019-05-30 12:47:39 +0100 | [diff] [blame] | 3014 | notifySettingChangeForRunningUsers(key, name); |
Jeff Sharkey | 308093f | 2018-03-25 22:53:29 -0600 | [diff] [blame] | 3015 | } finally { |
| 3016 | Binder.restoreCallingIdentity(token); |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3017 | } |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3018 | } else { |
| 3019 | final int userId = getUserIdFromKey(key); |
| 3020 | final Uri uri = getNotificationUriFor(key, name); |
| 3021 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, |
| 3022 | userId, 0, uri).sendToTarget(); |
| 3023 | if (isSecureSettingsKey(key)) { |
| 3024 | maybeNotifyProfiles(getTypeFromKey(key), userId, uri, name, |
| 3025 | sSecureCloneToManagedSettings); |
| 3026 | maybeNotifyProfiles(SETTINGS_TYPE_SYSTEM, userId, uri, name, |
| 3027 | sSystemCloneFromParentOnDependency.values()); |
| 3028 | } else if (isSystemSettingsKey(key)) { |
| 3029 | maybeNotifyProfiles(getTypeFromKey(key), userId, uri, name, |
| 3030 | sSystemCloneToManagedSettings); |
| 3031 | } |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 3032 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 3033 | |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3034 | // Always notify that our data changed |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 3035 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget(); |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 3038 | private void maybeNotifyProfiles(int type, int userId, Uri uri, String name, |
Robin Lee | 7af9a74 | 2017-02-20 14:47:30 +0000 | [diff] [blame] | 3039 | Collection<String> keysCloned) { |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 3040 | if (keysCloned.contains(name)) { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3041 | for (int profileId : mUserManager.getProfileIdsWithDisabled(userId)) { |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 3042 | // the notification for userId has already been sent. |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3043 | if (profileId != userId) { |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3044 | final int key = makeKey(type, profileId); |
| 3045 | // Increment the generation first, so observers always see the new value |
| 3046 | mGenerationRegistry.incrementGeneration(key); |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 3047 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 3048 | profileId, 0, uri).sendToTarget(); |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3052 | } |
| 3053 | |
Linus Tufvesson | 93c3855 | 2019-05-30 12:47:39 +0100 | [diff] [blame] | 3054 | private void notifySettingChangeForRunningUsers(int key, String name) { |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3055 | // Important: No need to update generation for each user as there |
| 3056 | // is a singleton generation entry for the global settings which |
| 3057 | // is already incremented be the caller. |
| 3058 | final Uri uri = getNotificationUriFor(key, name); |
| 3059 | final List<UserInfo> users = mUserManager.getUsers(/*excludeDying*/ true); |
| 3060 | for (int i = 0; i < users.size(); i++) { |
| 3061 | final int userId = users.get(i).id; |
| 3062 | if (mUserManager.isUserRunning(UserHandle.of(userId))) { |
| 3063 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, |
| 3064 | userId, 0, uri).sendToTarget(); |
| 3065 | } |
| 3066 | } |
| 3067 | } |
| 3068 | |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 3069 | private void notifyLocationChangeForRunningUsers() { |
| 3070 | final List<UserInfo> users = mUserManager.getUsers(/*excludeDying=*/ true); |
| 3071 | |
| 3072 | for (int i = 0; i < users.size(); i++) { |
| 3073 | final int userId = users.get(i).id; |
| 3074 | |
| 3075 | if (!mUserManager.isUserRunning(UserHandle.of(userId))) { |
| 3076 | continue; |
| 3077 | } |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 3078 | |
Svet Ganov | 945864c | 2018-03-22 21:49:10 -0700 | [diff] [blame] | 3079 | // Increment the generation first, so observers always see the new value |
| 3080 | final int key = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 3081 | mGenerationRegistry.incrementGeneration(key); |
| 3082 | |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 3083 | final Uri uri = getNotificationUriFor(key, Secure.LOCATION_MODE); |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 3084 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, |
| 3085 | userId, 0, uri).sendToTarget(); |
| 3086 | } |
| 3087 | } |
| 3088 | |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 3089 | private boolean isConfigSettingsKey(int key) { |
| 3090 | return getTypeFromKey(key) == SETTINGS_TYPE_CONFIG; |
| 3091 | } |
| 3092 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3093 | private boolean isGlobalSettingsKey(int key) { |
| 3094 | return getTypeFromKey(key) == SETTINGS_TYPE_GLOBAL; |
| 3095 | } |
| 3096 | |
| 3097 | private boolean isSystemSettingsKey(int key) { |
| 3098 | return getTypeFromKey(key) == SETTINGS_TYPE_SYSTEM; |
| 3099 | } |
| 3100 | |
| 3101 | private boolean isSecureSettingsKey(int key) { |
| 3102 | return getTypeFromKey(key) == SETTINGS_TYPE_SECURE; |
| 3103 | } |
| 3104 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3105 | private boolean isSsaidSettingsKey(int key) { |
| 3106 | return getTypeFromKey(key) == SETTINGS_TYPE_SSAID; |
| 3107 | } |
| 3108 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3109 | private File getSettingsFile(int key) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 3110 | if (isConfigSettingsKey(key)) { |
| 3111 | final int userId = getUserIdFromKey(key); |
| 3112 | return new File(Environment.getUserSystemDirectory(userId), |
| 3113 | SETTINGS_FILE_CONFIG); |
| 3114 | } else if (isGlobalSettingsKey(key)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3115 | final int userId = getUserIdFromKey(key); |
| 3116 | return new File(Environment.getUserSystemDirectory(userId), |
| 3117 | SETTINGS_FILE_GLOBAL); |
| 3118 | } else if (isSystemSettingsKey(key)) { |
| 3119 | final int userId = getUserIdFromKey(key); |
| 3120 | return new File(Environment.getUserSystemDirectory(userId), |
| 3121 | SETTINGS_FILE_SYSTEM); |
| 3122 | } else if (isSecureSettingsKey(key)) { |
| 3123 | final int userId = getUserIdFromKey(key); |
| 3124 | return new File(Environment.getUserSystemDirectory(userId), |
| 3125 | SETTINGS_FILE_SECURE); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3126 | } else if (isSsaidSettingsKey(key)) { |
| 3127 | final int userId = getUserIdFromKey(key); |
| 3128 | return new File(Environment.getUserSystemDirectory(userId), |
| 3129 | SETTINGS_FILE_SSAID); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3130 | } else { |
| 3131 | throw new IllegalArgumentException("Invalid settings key:" + key); |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | private Uri getNotificationUriFor(int key, String name) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 3136 | if (isConfigSettingsKey(key)) { |
Matt Pape | 1278d1c | 2018-12-11 13:03:49 -0800 | [diff] [blame] | 3137 | return (name != null) ? Uri.withAppendedPath(DeviceConfig.CONTENT_URI, name) |
| 3138 | : DeviceConfig.CONTENT_URI; |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 3139 | } else if (isGlobalSettingsKey(key)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3140 | return (name != null) ? Uri.withAppendedPath(Settings.Global.CONTENT_URI, name) |
| 3141 | : Settings.Global.CONTENT_URI; |
| 3142 | } else if (isSecureSettingsKey(key)) { |
| 3143 | return (name != null) ? Uri.withAppendedPath(Settings.Secure.CONTENT_URI, name) |
| 3144 | : Settings.Secure.CONTENT_URI; |
| 3145 | } else if (isSystemSettingsKey(key)) { |
| 3146 | return (name != null) ? Uri.withAppendedPath(Settings.System.CONTENT_URI, name) |
| 3147 | : Settings.System.CONTENT_URI; |
| 3148 | } else { |
| 3149 | throw new IllegalArgumentException("Invalid settings key:" + key); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | private int getMaxBytesPerPackageForType(int type) { |
| 3154 | switch (type) { |
Matt Pape | 1b31a33 | 2018-10-17 09:58:28 -0700 | [diff] [blame] | 3155 | case SETTINGS_TYPE_CONFIG: |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3156 | case SETTINGS_TYPE_GLOBAL: |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3157 | case SETTINGS_TYPE_SECURE: |
| 3158 | case SETTINGS_TYPE_SSAID: { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3159 | return SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED; |
| 3160 | } |
| 3161 | |
| 3162 | default: { |
| 3163 | return SettingsState.MAX_BYTES_PER_APP_PACKAGE_LIMITED; |
| 3164 | } |
| 3165 | } |
| 3166 | } |
| 3167 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 3168 | private final class MyHandler extends Handler { |
| 3169 | private static final int MSG_NOTIFY_URI_CHANGED = 1; |
| 3170 | private static final int MSG_NOTIFY_DATA_CHANGED = 2; |
| 3171 | |
| 3172 | public MyHandler(Looper looper) { |
| 3173 | super(looper); |
| 3174 | } |
| 3175 | |
| 3176 | @Override |
| 3177 | public void handleMessage(Message msg) { |
| 3178 | switch (msg.what) { |
| 3179 | case MSG_NOTIFY_URI_CHANGED: { |
| 3180 | final int userId = msg.arg1; |
| 3181 | Uri uri = (Uri) msg.obj; |
Jeff Sharkey | 88f9d0b | 2017-08-11 15:29:40 -0600 | [diff] [blame] | 3182 | try { |
| 3183 | getContext().getContentResolver().notifyChange(uri, null, true, userId); |
| 3184 | } catch (SecurityException e) { |
| 3185 | Slog.w(LOG_TAG, "Failed to notify for " + userId + ": " + uri, e); |
| 3186 | } |
Makoto Onuki | 0000d32 | 2017-11-28 16:31:47 -0800 | [diff] [blame] | 3187 | if (DEBUG || true) { |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 3188 | Slog.v(LOG_TAG, "Notifying for " + userId + ": " + uri); |
| 3189 | } |
| 3190 | } break; |
| 3191 | |
| 3192 | case MSG_NOTIFY_DATA_CHANGED: { |
| 3193 | mBackupManager.dataChanged(); |
| 3194 | } break; |
| 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3199 | private final class UpgradeController { |
Lyn Han | af1997e | 2019-07-15 16:03:19 -0700 | [diff] [blame] | 3200 | private static final int SETTINGS_VERSION = 183; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3201 | |
| 3202 | private final int mUserId; |
| 3203 | |
| 3204 | public UpgradeController(int userId) { |
| 3205 | mUserId = userId; |
| 3206 | } |
| 3207 | |
| 3208 | public void upgradeIfNeededLocked() { |
| 3209 | // The version of all settings for a user is the same (all users have secure). |
| 3210 | SettingsState secureSettings = getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 3211 | SETTINGS_TYPE_SECURE, mUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3212 | |
| 3213 | // Try an update from the current state. |
| 3214 | final int oldVersion = secureSettings.getVersionLocked(); |
| 3215 | final int newVersion = SETTINGS_VERSION; |
| 3216 | |
Svet Ganov | c9755bc | 2015-03-28 13:21:22 -0700 | [diff] [blame] | 3217 | // If up do date - done. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3218 | if (oldVersion == newVersion) { |
| 3219 | return; |
| 3220 | } |
| 3221 | |
| 3222 | // Try to upgrade. |
| 3223 | final int curVersion = onUpgradeLocked(mUserId, oldVersion, newVersion); |
| 3224 | |
| 3225 | // If upgrade failed start from scratch and upgrade. |
| 3226 | if (curVersion != newVersion) { |
| 3227 | // Drop state we have for this user. |
| 3228 | removeUserStateLocked(mUserId, true); |
| 3229 | |
| 3230 | // Recreate the database. |
| 3231 | DatabaseHelper dbHelper = new DatabaseHelper(getContext(), mUserId); |
| 3232 | SQLiteDatabase database = dbHelper.getWritableDatabase(); |
| 3233 | dbHelper.recreateDatabase(database, newVersion, curVersion, oldVersion); |
| 3234 | |
| 3235 | // Migrate the settings for this user. |
| 3236 | migrateLegacySettingsForUserLocked(dbHelper, database, mUserId); |
| 3237 | |
| 3238 | // Now upgrade should work fine. |
| 3239 | onUpgradeLocked(mUserId, oldVersion, newVersion); |
Svetoslav Ganov | 264c7a9 | 2016-08-24 17:31:14 -0700 | [diff] [blame] | 3240 | |
| 3241 | // Make a note what happened, so we don't wonder why data was lost |
| 3242 | String reason = "Settings rebuilt! Current version: " |
| 3243 | + curVersion + " while expected: " + newVersion; |
| 3244 | getGlobalSettingsLocked().insertSettingLocked( |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3245 | Settings.Global.DATABASE_DOWNGRADE_REASON, |
| 3246 | reason, null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | // Set the global settings version if owner. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 3250 | if (mUserId == UserHandle.USER_SYSTEM) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3251 | SettingsState globalSettings = getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 3252 | SETTINGS_TYPE_GLOBAL, mUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3253 | globalSettings.setVersionLocked(newVersion); |
| 3254 | } |
| 3255 | |
| 3256 | // Set the secure settings version. |
| 3257 | secureSettings.setVersionLocked(newVersion); |
| 3258 | |
| 3259 | // Set the system settings version. |
| 3260 | SettingsState systemSettings = getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 3261 | SETTINGS_TYPE_SYSTEM, mUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3262 | systemSettings.setVersionLocked(newVersion); |
| 3263 | } |
| 3264 | |
| 3265 | private SettingsState getGlobalSettingsLocked() { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 3266 | return getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | private SettingsState getSecureSettingsLocked(int userId) { |
| 3270 | return getSettingsLocked(SETTINGS_TYPE_SECURE, userId); |
| 3271 | } |
| 3272 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3273 | private SettingsState getSsaidSettingsLocked(int userId) { |
| 3274 | return getSettingsLocked(SETTINGS_TYPE_SSAID, userId); |
| 3275 | } |
| 3276 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3277 | private SettingsState getSystemSettingsLocked(int userId) { |
| 3278 | return getSettingsLocked(SETTINGS_TYPE_SYSTEM, userId); |
| 3279 | } |
| 3280 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 3281 | /** |
| 3282 | * You must perform all necessary mutations to bring the settings |
| 3283 | * for this user from the old to the new version. When you add a new |
| 3284 | * upgrade step you *must* update SETTINGS_VERSION. |
| 3285 | * |
| 3286 | * This is an example of moving a setting from secure to global. |
| 3287 | * |
| 3288 | * // v119: Example settings changes. |
| 3289 | * if (currentVersion == 118) { |
| 3290 | * if (userId == UserHandle.USER_OWNER) { |
| 3291 | * // Remove from the secure settings. |
| 3292 | * SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3293 | * String name = "example_setting_to_move"; |
| 3294 | * String value = secureSettings.getSetting(name); |
| 3295 | * secureSettings.deleteSetting(name); |
| 3296 | * |
| 3297 | * // Add to the global settings. |
| 3298 | * SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3299 | * globalSettings.insertSetting(name, value, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3300 | * } |
| 3301 | * |
| 3302 | * // Update the current version. |
| 3303 | * currentVersion = 119; |
| 3304 | * } |
| 3305 | */ |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3306 | private int onUpgradeLocked(int userId, int oldVersion, int newVersion) { |
| 3307 | if (DEBUG) { |
| 3308 | Slog.w(LOG_TAG, "Upgrading settings for user: " + userId + " from version: " |
| 3309 | + oldVersion + " to version: " + newVersion); |
| 3310 | } |
| 3311 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 3312 | int currentVersion = oldVersion; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 3313 | |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 3314 | // v119: Reset zen + ringer mode. |
| 3315 | if (currentVersion == 118) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 3316 | if (userId == UserHandle.USER_SYSTEM) { |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 3317 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3318 | globalSettings.updateSettingLocked(Settings.Global.ZEN_MODE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3319 | Integer.toString(Settings.Global.ZEN_MODE_OFF), null, |
| 3320 | true, SettingsState.SYSTEM_PACKAGE_NAME); |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 3321 | globalSettings.updateSettingLocked(Settings.Global.MODE_RINGER, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3322 | Integer.toString(AudioManager.RINGER_MODE_NORMAL), null, |
| 3323 | true, SettingsState.SYSTEM_PACKAGE_NAME); |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 3324 | } |
| 3325 | currentVersion = 119; |
| 3326 | } |
| 3327 | |
Jason Monk | 27bbb2d | 2015-03-31 16:46:39 -0400 | [diff] [blame] | 3328 | // v120: Add double tap to wake setting. |
| 3329 | if (currentVersion == 119) { |
| 3330 | SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3331 | secureSettings.insertSettingLocked(Settings.Secure.DOUBLE_TAP_TO_WAKE, |
| 3332 | getContext().getResources().getBoolean( |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3333 | R.bool.def_double_tap_to_wake) ? "1" : "0", null, true, |
Jason Monk | 27bbb2d | 2015-03-31 16:46:39 -0400 | [diff] [blame] | 3334 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 3335 | |
| 3336 | currentVersion = 120; |
| 3337 | } |
| 3338 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 3339 | if (currentVersion == 120) { |
| 3340 | // Before 121, we used a different string encoding logic. We just bump the |
| 3341 | // version here; SettingsState knows how to handle pre-version 120 files. |
| 3342 | currentVersion = 121; |
| 3343 | } |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 3344 | |
Martijn Coenen | 7ab4b7f | 2015-07-27 15:58:32 +0200 | [diff] [blame] | 3345 | if (currentVersion == 121) { |
| 3346 | // Version 122: allow OEMs to set a default payment component in resources. |
| 3347 | // Note that we only write the default if no default has been set; |
| 3348 | // if there is, we just leave the default at whatever it currently is. |
| 3349 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3350 | String defaultComponent = (getContext().getResources().getString( |
| 3351 | R.string.def_nfc_payment_component)); |
| 3352 | Setting currentSetting = secureSettings.getSettingLocked( |
| 3353 | Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT); |
| 3354 | if (defaultComponent != null && !defaultComponent.isEmpty() && |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 3355 | currentSetting.isNull()) { |
Martijn Coenen | 7ab4b7f | 2015-07-27 15:58:32 +0200 | [diff] [blame] | 3356 | secureSettings.insertSettingLocked( |
| 3357 | Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3358 | defaultComponent, null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Martijn Coenen | 7ab4b7f | 2015-07-27 15:58:32 +0200 | [diff] [blame] | 3359 | } |
| 3360 | currentVersion = 122; |
| 3361 | } |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 3362 | |
| 3363 | if (currentVersion == 122) { |
| 3364 | // Version 123: Adding a default value for the ability to add a user from |
| 3365 | // the lock screen. |
| 3366 | if (userId == UserHandle.USER_SYSTEM) { |
| 3367 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3368 | Setting currentSetting = globalSettings.getSettingLocked( |
| 3369 | Settings.Global.ADD_USERS_WHEN_LOCKED); |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 3370 | if (currentSetting.isNull()) { |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 3371 | globalSettings.insertSettingLocked( |
| 3372 | Settings.Global.ADD_USERS_WHEN_LOCKED, |
| 3373 | getContext().getResources().getBoolean( |
| 3374 | R.bool.def_add_users_from_lockscreen) ? "1" : "0", |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3375 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | currentVersion = 123; |
| 3379 | } |
Bryce Lee | bd17928 | 2015-12-17 19:01:37 -0800 | [diff] [blame] | 3380 | |
| 3381 | if (currentVersion == 123) { |
Bryce Lee | ec85f34 | 2015-12-16 13:32:28 -0800 | [diff] [blame] | 3382 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3383 | String defaultDisabledProfiles = (getContext().getResources().getString( |
| 3384 | R.string.def_bluetooth_disabled_profiles)); |
| 3385 | globalSettings.insertSettingLocked(Settings.Global.BLUETOOTH_DISABLED_PROFILES, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3386 | defaultDisabledProfiles, null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Bryce Lee | bd17928 | 2015-12-17 19:01:37 -0800 | [diff] [blame] | 3387 | currentVersion = 124; |
Bryce Lee | ec85f34 | 2015-12-16 13:32:28 -0800 | [diff] [blame] | 3388 | } |
| 3389 | |
Prathmesh Prabhu | de16b86 | 2016-03-04 15:22:24 -0800 | [diff] [blame] | 3390 | if (currentVersion == 124) { |
| 3391 | // Version 124: allow OEMs to set a default value for whether IME should be |
| 3392 | // shown when a physical keyboard is connected. |
| 3393 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3394 | Setting currentSetting = secureSettings.getSettingLocked( |
| 3395 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 3396 | if (currentSetting.isNull()) { |
Prathmesh Prabhu | de16b86 | 2016-03-04 15:22:24 -0800 | [diff] [blame] | 3397 | secureSettings.insertSettingLocked( |
| 3398 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, |
| 3399 | getContext().getResources().getBoolean( |
| 3400 | R.bool.def_show_ime_with_hard_keyboard) ? "1" : "0", |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3401 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Prathmesh Prabhu | de16b86 | 2016-03-04 15:22:24 -0800 | [diff] [blame] | 3402 | } |
| 3403 | currentVersion = 125; |
| 3404 | } |
| 3405 | |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 3406 | if (currentVersion == 125) { |
| 3407 | // Version 125: Allow OEMs to set the default VR service. |
| 3408 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3409 | |
| 3410 | Setting currentSetting = secureSettings.getSettingLocked( |
| 3411 | Settings.Secure.ENABLED_VR_LISTENERS); |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 3412 | if (currentSetting.isNull()) { |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 3413 | ArraySet<ComponentName> l = |
| 3414 | SystemConfig.getInstance().getDefaultVrComponents(); |
| 3415 | |
| 3416 | if (l != null && !l.isEmpty()) { |
| 3417 | StringBuilder b = new StringBuilder(); |
| 3418 | boolean start = true; |
| 3419 | for (ComponentName c : l) { |
| 3420 | if (!start) { |
| 3421 | b.append(':'); |
| 3422 | } |
| 3423 | b.append(c.flattenToString()); |
| 3424 | start = false; |
| 3425 | } |
| 3426 | secureSettings.insertSettingLocked( |
| 3427 | Settings.Secure.ENABLED_VR_LISTENERS, b.toString(), |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3428 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | } |
| 3432 | currentVersion = 126; |
| 3433 | } |
| 3434 | |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 3435 | if (currentVersion == 126) { |
| 3436 | // Version 126: copy the primary values of LOCK_SCREEN_SHOW_NOTIFICATIONS and |
| 3437 | // LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS into managed profile. |
| 3438 | if (mUserManager.isManagedProfile(userId)) { |
| 3439 | final SettingsState systemSecureSettings = |
| 3440 | getSecureSettingsLocked(UserHandle.USER_SYSTEM); |
| 3441 | |
| 3442 | final Setting showNotifications = systemSecureSettings.getSettingLocked( |
| 3443 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); |
Seigo Nonaka | 6e5b602 | 2016-04-27 16:32:44 +0900 | [diff] [blame] | 3444 | if (!showNotifications.isNull()) { |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 3445 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3446 | secureSettings.insertSettingLocked( |
| 3447 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3448 | showNotifications.getValue(), null, true, |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 3449 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 3450 | } |
| 3451 | |
| 3452 | final Setting allowPrivate = systemSecureSettings.getSettingLocked( |
| 3453 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); |
Seigo Nonaka | 6e5b602 | 2016-04-27 16:32:44 +0900 | [diff] [blame] | 3454 | if (!allowPrivate.isNull()) { |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 3455 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3456 | secureSettings.insertSettingLocked( |
| 3457 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3458 | allowPrivate.getValue(), null, true, |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 3459 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 3460 | } |
| 3461 | } |
| 3462 | currentVersion = 127; |
| 3463 | } |
| 3464 | |
Steven Ng | dc20ba6 | 2016-04-26 18:19:04 +0100 | [diff] [blame] | 3465 | if (currentVersion == 127) { |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 3466 | // version 127 is no longer used. |
Steven Ng | dc20ba6 | 2016-04-26 18:19:04 +0100 | [diff] [blame] | 3467 | currentVersion = 128; |
| 3468 | } |
| 3469 | |
Julia Reynolds | 1f721e1 | 2016-07-11 08:50:58 -0400 | [diff] [blame] | 3470 | if (currentVersion == 128) { |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 3471 | // Version 128: Removed |
Julia Reynolds | 1f721e1 | 2016-07-11 08:50:58 -0400 | [diff] [blame] | 3472 | currentVersion = 129; |
| 3473 | } |
| 3474 | |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 3475 | if (currentVersion == 129) { |
| 3476 | // default longpress timeout changed from 500 to 400. If unchanged from the old |
| 3477 | // default, update to the new default. |
| 3478 | final SettingsState systemSecureSettings = |
| 3479 | getSecureSettingsLocked(userId); |
| 3480 | final String oldValue = systemSecureSettings.getSettingLocked( |
| 3481 | Settings.Secure.LONG_PRESS_TIMEOUT).getValue(); |
| 3482 | if (TextUtils.equals("500", oldValue)) { |
| 3483 | systemSecureSettings.insertSettingLocked( |
| 3484 | Settings.Secure.LONG_PRESS_TIMEOUT, |
| 3485 | String.valueOf(getContext().getResources().getInteger( |
| 3486 | R.integer.def_long_press_timeout_millis)), |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3487 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 3488 | } |
| 3489 | currentVersion = 130; |
| 3490 | } |
| 3491 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 3492 | if (currentVersion == 130) { |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3493 | // Split Ambient settings |
| 3494 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3495 | boolean dozeExplicitlyDisabled = "0".equals(secureSettings. |
| 3496 | getSettingLocked(Settings.Secure.DOZE_ENABLED).getValue()); |
| 3497 | |
| 3498 | if (dozeExplicitlyDisabled) { |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 3499 | secureSettings.insertSettingLocked(Settings.Secure.DOZE_PICK_UP_GESTURE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3500 | "0", null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 3501 | secureSettings.insertSettingLocked(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3502 | "0", null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3503 | } |
| 3504 | currentVersion = 131; |
| 3505 | } |
| 3506 | |
| 3507 | if (currentVersion == 131) { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 3508 | // Initialize new multi-press timeout to default value |
| 3509 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 3510 | final String oldValue = systemSecureSettings.getSettingLocked( |
| 3511 | Settings.Secure.MULTI_PRESS_TIMEOUT).getValue(); |
| 3512 | if (TextUtils.equals(null, oldValue)) { |
| 3513 | systemSecureSettings.insertSettingLocked( |
| 3514 | Settings.Secure.MULTI_PRESS_TIMEOUT, |
| 3515 | String.valueOf(getContext().getResources().getInteger( |
| 3516 | R.integer.def_multi_press_timeout_millis)), |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3517 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3520 | currentVersion = 132; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3523 | if (currentVersion == 132) { |
| 3524 | // Version 132: Allow managed profile to optionally use the parent's ringtones |
Andre Lago | ea35e07 | 2016-08-04 13:41:13 +0100 | [diff] [blame] | 3525 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 3526 | String defaultSyncParentSounds = (getContext().getResources() |
| 3527 | .getBoolean(R.bool.def_sync_parent_sounds) ? "1" : "0"); |
| 3528 | systemSecureSettings.insertSettingLocked( |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3529 | Settings.Secure.SYNC_PARENT_SOUNDS, defaultSyncParentSounds, |
| 3530 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3531 | currentVersion = 133; |
Andre Lago | ea35e07 | 2016-08-04 13:41:13 +0100 | [diff] [blame] | 3532 | } |
| 3533 | |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3534 | if (currentVersion == 133) { |
| 3535 | // Version 133: Add default end button behavior |
Keun-young Park | ec7a118 | 2016-10-18 11:52:38 -0700 | [diff] [blame] | 3536 | final SettingsState systemSettings = getSystemSettingsLocked(userId); |
davidln | edb31e1 | 2018-09-25 10:21:20 -0700 | [diff] [blame] | 3537 | if (systemSettings.getSettingLocked(Settings.System.END_BUTTON_BEHAVIOR) |
| 3538 | .isNull()) { |
Keun-young Park | ec7a118 | 2016-10-18 11:52:38 -0700 | [diff] [blame] | 3539 | String defaultEndButtonBehavior = Integer.toString(getContext() |
| 3540 | .getResources().getInteger(R.integer.def_end_button_behavior)); |
| 3541 | systemSettings.insertSettingLocked(Settings.System.END_BUTTON_BEHAVIOR, |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 3542 | defaultEndButtonBehavior, null, true, |
| 3543 | SettingsState.SYSTEM_PACKAGE_NAME); |
Keun-young Park | ec7a118 | 2016-10-18 11:52:38 -0700 | [diff] [blame] | 3544 | } |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 3545 | currentVersion = 134; |
Keun-young Park | ec7a118 | 2016-10-18 11:52:38 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
Phil Weaver | 89e3ffc | 2016-09-19 13:51:10 -0700 | [diff] [blame] | 3548 | if (currentVersion == 134) { |
| 3549 | // Remove setting that specifies if magnification values should be preserved. |
| 3550 | // This setting defaulted to true and never has a UI. |
| 3551 | getSecureSettingsLocked(userId).deleteSettingLocked( |
| 3552 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE); |
| 3553 | currentVersion = 135; |
| 3554 | } |
| 3555 | |
Jeremy Joslin | 8bdad34 | 2016-12-14 11:46:47 -0800 | [diff] [blame] | 3556 | if (currentVersion == 135) { |
Jeremy Joslin | c9eb3c4 | 2017-02-08 10:45:30 -0800 | [diff] [blame] | 3557 | // Version 135 no longer used. |
Jeremy Joslin | 8bdad34 | 2016-12-14 11:46:47 -0800 | [diff] [blame] | 3558 | currentVersion = 136; |
| 3559 | } |
| 3560 | |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3561 | if (currentVersion == 136) { |
| 3562 | // Version 136: Store legacy SSAID for all apps currently installed on the |
| 3563 | // device as first step in migrating SSAID to be unique per application. |
| 3564 | |
| 3565 | final boolean isUpgrade; |
| 3566 | try { |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 3567 | isUpgrade = mPackageManager.isDeviceUpgrading(); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3568 | } catch (RemoteException e) { |
| 3569 | throw new IllegalStateException("Package manager not available"); |
| 3570 | } |
| 3571 | // Only retain legacy ssaid if the device is performing an OTA. After wiping |
| 3572 | // user data or first boot on a new device should use new ssaid generation. |
| 3573 | if (isUpgrade) { |
| 3574 | // Retrieve the legacy ssaid from the secure settings table. |
Mark Rathjen | ea61759 | 2017-01-18 23:03:41 -0800 | [diff] [blame] | 3575 | final Setting legacySsaidSetting = getSettingLocked(SETTINGS_TYPE_SECURE, |
| 3576 | userId, Settings.Secure.ANDROID_ID); |
| 3577 | if (legacySsaidSetting == null || legacySsaidSetting.isNull() |
| 3578 | || legacySsaidSetting.getValue() == null) { |
| 3579 | throw new IllegalStateException("Legacy ssaid not accessible"); |
| 3580 | } |
| 3581 | final String legacySsaid = legacySsaidSetting.getValue(); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3582 | |
| 3583 | // Fill each uid with the legacy ssaid to be backwards compatible. |
| 3584 | final List<PackageInfo> packages; |
| 3585 | try { |
Tetsutoki Shiozawa | ebe0e5f | 2018-01-17 11:07:09 +0900 | [diff] [blame] | 3586 | packages = mPackageManager.getInstalledPackages( |
| 3587 | PackageManager.MATCH_UNINSTALLED_PACKAGES, |
| 3588 | userId).getList(); |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3589 | } catch (RemoteException e) { |
| 3590 | throw new IllegalStateException("Package manager not available"); |
| 3591 | } |
| 3592 | |
| 3593 | final SettingsState ssaidSettings = getSsaidSettingsLocked(userId); |
| 3594 | for (PackageInfo info : packages) { |
| 3595 | // Check if the UID already has an entry in the table. |
| 3596 | final String uid = Integer.toString(info.applicationInfo.uid); |
| 3597 | final Setting ssaid = ssaidSettings.getSettingLocked(uid); |
| 3598 | |
| 3599 | if (ssaid.isNull() || ssaid.getValue() == null) { |
| 3600 | // Android Id doesn't exist for this package so create it. |
| 3601 | ssaidSettings.insertSettingLocked(uid, legacySsaid, null, true, |
| 3602 | info.packageName); |
Tetsutoki Shiozawa | ebe0e5f | 2018-01-17 11:07:09 +0900 | [diff] [blame] | 3603 | if (DEBUG) { |
| 3604 | Slog.d(LOG_TAG, "Keep the legacy ssaid for uid=" + uid); |
| 3605 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | } |
| 3609 | |
| 3610 | currentVersion = 137; |
| 3611 | } |
Suprabh Shukla | e3745ee | 2017-02-02 20:01:11 -0800 | [diff] [blame] | 3612 | if (currentVersion == 137) { |
| 3613 | // Version 138: Settings.Secure#INSTALL_NON_MARKET_APPS is deprecated and its |
| 3614 | // default value set to 1. The user can no longer change the value of this |
| 3615 | // setting through the UI. |
| 3616 | final SettingsState secureSetting = getSecureSettingsLocked(userId); |
| 3617 | if (!mUserManager.hasUserRestriction( |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 3618 | UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserHandle.of(userId)) |
| 3619 | && secureSetting.getSettingLocked( |
| 3620 | Settings.Secure.INSTALL_NON_MARKET_APPS).getValue().equals("0")) { |
| 3621 | |
Suprabh Shukla | e3745ee | 2017-02-02 20:01:11 -0800 | [diff] [blame] | 3622 | secureSetting.insertSettingLocked(Settings.Secure.INSTALL_NON_MARKET_APPS, |
| 3623 | "1", null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
Suprabh Shukla | 0b1356f | 2017-02-21 14:33:50 -0800 | [diff] [blame] | 3624 | // For managed profiles with profile owners, DevicePolicyManagerService |
| 3625 | // may want to set the user restriction in this case |
| 3626 | secureSetting.insertSettingLocked( |
| 3627 | Settings.Secure.UNKNOWN_SOURCES_DEFAULT_REVERSED, "1", null, true, |
| 3628 | SettingsState.SYSTEM_PACKAGE_NAME); |
Suprabh Shukla | e3745ee | 2017-02-02 20:01:11 -0800 | [diff] [blame] | 3629 | } |
| 3630 | currentVersion = 138; |
| 3631 | } |
Mark Rathjen | d891f01 | 2017-01-19 04:10:37 +0000 | [diff] [blame] | 3632 | |
Jeremy Joslin | c9eb3c4 | 2017-02-08 10:45:30 -0800 | [diff] [blame] | 3633 | if (currentVersion == 138) { |
Jeremy Joslin | 27d14c4 | 2017-02-15 12:02:03 -0800 | [diff] [blame] | 3634 | // Version 139: Removed. |
Jeremy Joslin | c9eb3c4 | 2017-02-08 10:45:30 -0800 | [diff] [blame] | 3635 | currentVersion = 139; |
| 3636 | } |
| 3637 | |
Phil Weaver | 385912e | 2017-02-10 10:06:56 -0800 | [diff] [blame] | 3638 | if (currentVersion == 139) { |
| 3639 | // Version 140: Settings.Secure#ACCESSIBILITY_SPEAK_PASSWORD is deprecated and |
| 3640 | // the user can no longer change the value of this setting through the UI. |
| 3641 | // Force to true. |
| 3642 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3643 | secureSettings.updateSettingLocked(Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, |
| 3644 | "1", null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3645 | currentVersion = 140; |
| 3646 | } |
| 3647 | |
Julia Reynolds | ad0d9e0 | 2017-02-15 08:41:48 -0500 | [diff] [blame] | 3648 | if (currentVersion == 140) { |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 3649 | // Version 141: Removed |
Julia Reynolds | ad0d9e0 | 2017-02-15 08:41:48 -0500 | [diff] [blame] | 3650 | currentVersion = 141; |
| 3651 | } |
| 3652 | |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 3653 | if (currentVersion == 141) { |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 3654 | // This implementation was incorrectly setting the current value of |
| 3655 | // settings changed by non-system packages as the default which default |
| 3656 | // is set by the system. We add a new upgrade step at the end to properly |
| 3657 | // handle this case which would also fix incorrect changes made by the |
| 3658 | // old implementation of this step. |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 3659 | currentVersion = 142; |
| 3660 | } |
| 3661 | |
Stephen Chen | 5d0922f | 2017-03-27 10:28:04 -0700 | [diff] [blame] | 3662 | if (currentVersion == 142) { |
Felipe Leme | ff35509 | 2017-04-03 12:55:02 -0700 | [diff] [blame] | 3663 | // Version 143: Set a default value for Wi-Fi wakeup feature. |
Stephen Chen | 5d0922f | 2017-03-27 10:28:04 -0700 | [diff] [blame] | 3664 | if (userId == UserHandle.USER_SYSTEM) { |
| 3665 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3666 | Setting currentSetting = globalSettings.getSettingLocked( |
| 3667 | Settings.Global.WIFI_WAKEUP_ENABLED); |
| 3668 | if (currentSetting.isNull()) { |
| 3669 | globalSettings.insertSettingLocked( |
| 3670 | Settings.Global.WIFI_WAKEUP_ENABLED, |
| 3671 | getContext().getResources().getBoolean( |
| 3672 | R.bool.def_wifi_wakeup_enabled) ? "1" : "0", |
| 3673 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | currentVersion = 143; |
| 3678 | } |
| 3679 | |
Felipe Leme | ff35509 | 2017-04-03 12:55:02 -0700 | [diff] [blame] | 3680 | if (currentVersion == 143) { |
| 3681 | // Version 144: Set a default value for Autofill service. |
| 3682 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3683 | final Setting currentSetting = secureSettings |
| 3684 | .getSettingLocked(Settings.Secure.AUTOFILL_SERVICE); |
| 3685 | if (currentSetting.isNull()) { |
| 3686 | final String defaultValue = getContext().getResources().getString( |
| 3687 | com.android.internal.R.string.config_defaultAutofillService); |
| 3688 | if (defaultValue != null) { |
| 3689 | Slog.d(LOG_TAG, "Setting [" + defaultValue + "] as Autofill Service " |
| 3690 | + "for user " + userId); |
| 3691 | secureSettings.insertSettingLocked(Settings.Secure.AUTOFILL_SERVICE, |
| 3692 | defaultValue, null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | currentVersion = 144; |
| 3697 | } |
| 3698 | |
Jeremy Joslin | 45caa25 | 2017-05-04 11:22:46 -0700 | [diff] [blame] | 3699 | if (currentVersion == 144) { |
Amin Shaikh | 8636796 | 2017-06-07 08:58:22 -0700 | [diff] [blame] | 3700 | // Version 145: Removed |
| 3701 | currentVersion = 145; |
| 3702 | } |
| 3703 | |
| 3704 | if (currentVersion == 145) { |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 3705 | // Version 146: In step 142 we had a bug where incorrectly |
| 3706 | // some settings were considered system set and as a result |
| 3707 | // made the default and marked as the default being set by |
| 3708 | // the system. Here reevaluate the default and default system |
| 3709 | // set flags. This would both fix corruption by the old impl |
| 3710 | // of step 142 and also properly handle devices which never |
| 3711 | // run 142. |
Jeremy Joslin | 45caa25 | 2017-05-04 11:22:46 -0700 | [diff] [blame] | 3712 | if (userId == UserHandle.USER_SYSTEM) { |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 3713 | SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3714 | ensureLegacyDefaultValueAndSystemSetUpdatedLocked(globalSettings, userId); |
| 3715 | globalSettings.persistSyncLocked(); |
Jeremy Joslin | 45caa25 | 2017-05-04 11:22:46 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 3718 | SettingsState secureSettings = getSecureSettingsLocked(mUserId); |
| 3719 | ensureLegacyDefaultValueAndSystemSetUpdatedLocked(secureSettings, userId); |
| 3720 | secureSettings.persistSyncLocked(); |
| 3721 | |
| 3722 | SettingsState systemSettings = getSystemSettingsLocked(mUserId); |
| 3723 | ensureLegacyDefaultValueAndSystemSetUpdatedLocked(systemSettings, userId); |
| 3724 | systemSettings.persistSyncLocked(); |
| 3725 | |
Amin Shaikh | 8636796 | 2017-06-07 08:58:22 -0700 | [diff] [blame] | 3726 | currentVersion = 146; |
Jeremy Joslin | 45caa25 | 2017-05-04 11:22:46 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
Narayan Kamath | 94bcdbc | 2017-07-17 15:32:53 +0100 | [diff] [blame] | 3729 | if (currentVersion == 146) { |
Joe LaPenna | 250d784 | 2018-01-25 10:19:42 -0800 | [diff] [blame] | 3730 | // Version 147: Removed. (This version previously allowed showing the |
| 3731 | // "wifi_wakeup_available" setting). |
| 3732 | // The setting that was added here is deleted in 153. |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 3733 | currentVersion = 147; |
| 3734 | } |
| 3735 | |
| 3736 | if (currentVersion == 147) { |
| 3737 | // Version 148: Set the default value for DEFAULT_RESTRICT_BACKGROUND_DATA. |
Narayan Kamath | 94bcdbc | 2017-07-17 15:32:53 +0100 | [diff] [blame] | 3738 | if (userId == UserHandle.USER_SYSTEM) { |
| 3739 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3740 | final Setting currentSetting = globalSettings.getSettingLocked( |
| 3741 | Global.DEFAULT_RESTRICT_BACKGROUND_DATA); |
| 3742 | if (currentSetting.isNull()) { |
| 3743 | globalSettings.insertSettingLocked( |
| 3744 | Global.DEFAULT_RESTRICT_BACKGROUND_DATA, |
| 3745 | getContext().getResources().getBoolean( |
| 3746 | R.bool.def_restrict_background_data) ? "1" : "0", |
| 3747 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3748 | } |
| 3749 | } |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 3750 | currentVersion = 148; |
Narayan Kamath | 94bcdbc | 2017-07-17 15:32:53 +0100 | [diff] [blame] | 3751 | } |
| 3752 | |
Tim Zheng | cc1e76a | 2017-08-30 17:46:19 -0700 | [diff] [blame] | 3753 | if (currentVersion == 148) { |
| 3754 | // Version 149: Set the default value for BACKUP_MANAGER_CONSTANTS. |
| 3755 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 3756 | final String oldValue = systemSecureSettings.getSettingLocked( |
| 3757 | Settings.Secure.BACKUP_MANAGER_CONSTANTS).getValue(); |
| 3758 | if (TextUtils.equals(null, oldValue)) { |
| 3759 | final String defaultValue = getContext().getResources().getString( |
| 3760 | R.string.def_backup_manager_constants); |
| 3761 | if (!TextUtils.isEmpty(defaultValue)) { |
| 3762 | systemSecureSettings.insertSettingLocked( |
| 3763 | Settings.Secure.BACKUP_MANAGER_CONSTANTS, defaultValue, null, |
| 3764 | true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3765 | } |
| 3766 | } |
Tim Zheng | cc1e76a | 2017-08-30 17:46:19 -0700 | [diff] [blame] | 3767 | currentVersion = 149; |
| 3768 | } |
Jacky Cheung | 7076a31 | 2017-10-02 10:40:48 -0700 | [diff] [blame] | 3769 | |
| 3770 | if (currentVersion == 149) { |
| 3771 | // Version 150: Set a default value for mobile data always on |
| 3772 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3773 | final Setting currentSetting = globalSettings.getSettingLocked( |
| 3774 | Settings.Global.MOBILE_DATA_ALWAYS_ON); |
| 3775 | if (currentSetting.isNull()) { |
| 3776 | globalSettings.insertSettingLocked( |
| 3777 | Settings.Global.MOBILE_DATA_ALWAYS_ON, |
| 3778 | getContext().getResources().getBoolean( |
| 3779 | R.bool.def_mobile_data_always_on) ? "1" : "0", |
| 3780 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3781 | } |
| 3782 | |
| 3783 | currentVersion = 150; |
| 3784 | } |
| 3785 | |
Mike Digman | 4af4a6f | 2018-01-16 14:49:38 -0800 | [diff] [blame] | 3786 | if (currentVersion == 150) { |
Mike Digman | 32e0331 | 2018-05-16 16:43:23 -0700 | [diff] [blame] | 3787 | // Version 151: Removed. |
Mike Digman | 4af4a6f | 2018-01-16 14:49:38 -0800 | [diff] [blame] | 3788 | currentVersion = 151; |
| 3789 | } |
| 3790 | |
Joe LaPenna | 4f50ed4 | 2018-01-22 14:54:45 -0800 | [diff] [blame] | 3791 | if (currentVersion == 151) { |
Joe LaPenna | 250d784 | 2018-01-25 10:19:42 -0800 | [diff] [blame] | 3792 | // Version 152: Removed. (This version made the setting for wifi_wakeup enabled |
| 3793 | // by default but it is now no longer configurable). |
| 3794 | // The setting updated here is deleted in 153. |
Joe LaPenna | 4f50ed4 | 2018-01-22 14:54:45 -0800 | [diff] [blame] | 3795 | currentVersion = 152; |
| 3796 | } |
| 3797 | |
Joe LaPenna | 250d784 | 2018-01-25 10:19:42 -0800 | [diff] [blame] | 3798 | if (currentVersion == 152) { |
| 3799 | getGlobalSettingsLocked().deleteSettingLocked("wifi_wakeup_available"); |
| 3800 | currentVersion = 153; |
| 3801 | } |
| 3802 | |
Ben Lin | b4df8bc | 2018-01-29 11:48:20 -0800 | [diff] [blame] | 3803 | if (currentVersion == 153) { |
| 3804 | // Version 154: Read notification badge configuration from config. |
| 3805 | // If user has already set the value, don't do anything. |
| 3806 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 3807 | final Setting showNotificationBadges = systemSecureSettings.getSettingLocked( |
| 3808 | Settings.Secure.NOTIFICATION_BADGING); |
| 3809 | if (showNotificationBadges.isNull()) { |
| 3810 | final boolean defaultValue = getContext().getResources().getBoolean( |
| 3811 | com.android.internal.R.bool.config_notificationBadging); |
| 3812 | systemSecureSettings.insertSettingLocked( |
| 3813 | Secure.NOTIFICATION_BADGING, |
| 3814 | defaultValue ? "1" : "0", |
| 3815 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3816 | } |
| 3817 | currentVersion = 154; |
| 3818 | } |
| 3819 | |
Bernardo Rufino | eaa78b9 | 2018-01-26 11:25:37 +0000 | [diff] [blame] | 3820 | if (currentVersion == 154) { |
| 3821 | // Version 155: Set the default value for BACKUP_LOCAL_TRANSPORT_PARAMETERS. |
| 3822 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 3823 | final String oldValue = systemSecureSettings.getSettingLocked( |
| 3824 | Settings.Secure.BACKUP_LOCAL_TRANSPORT_PARAMETERS).getValue(); |
| 3825 | if (TextUtils.equals(null, oldValue)) { |
| 3826 | final String defaultValue = getContext().getResources().getString( |
| 3827 | R.string.def_backup_local_transport_parameters); |
| 3828 | if (!TextUtils.isEmpty(defaultValue)) { |
| 3829 | systemSecureSettings.insertSettingLocked( |
| 3830 | Settings.Secure.BACKUP_LOCAL_TRANSPORT_PARAMETERS, defaultValue, |
| 3831 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3832 | } |
| 3833 | |
| 3834 | } |
| 3835 | currentVersion = 155; |
| 3836 | } |
| 3837 | |
Beverly | da90481 | 2018-03-02 09:55:30 -0500 | [diff] [blame] | 3838 | if (currentVersion == 155) { |
Annie Meng | d069a88 | 2018-03-13 15:31:40 +0000 | [diff] [blame] | 3839 | // Version 156: Set the default value for CHARGING_STARTED_SOUND. |
Beverly | da90481 | 2018-03-02 09:55:30 -0500 | [diff] [blame] | 3840 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3841 | final String oldValue = globalSettings.getSettingLocked( |
| 3842 | Global.CHARGING_STARTED_SOUND).getValue(); |
| 3843 | final String oldDefault = getContext().getResources().getString( |
| 3844 | R.string.def_wireless_charging_started_sound); |
| 3845 | if (TextUtils.equals(null, oldValue) |
| 3846 | || TextUtils.equals(oldValue, oldDefault)) { |
| 3847 | final String defaultValue = getContext().getResources().getString( |
| 3848 | R.string.def_charging_started_sound); |
| 3849 | if (!TextUtils.isEmpty(defaultValue)) { |
| 3850 | globalSettings.insertSettingLocked( |
| 3851 | Settings.Global.CHARGING_STARTED_SOUND, defaultValue, |
| 3852 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3853 | } |
| 3854 | |
| 3855 | } |
| 3856 | currentVersion = 156; |
| 3857 | } |
| 3858 | |
Beverly | 09da25f | 2018-02-26 09:17:07 -0500 | [diff] [blame] | 3859 | if (currentVersion == 156) { |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 3860 | // Version 157: Set a default value for zen duration, |
| 3861 | // in version 169, zen duration is moved to secure settings |
Beverly | 09da25f | 2018-02-26 09:17:07 -0500 | [diff] [blame] | 3862 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3863 | final Setting currentSetting = globalSettings.getSettingLocked( |
| 3864 | Global.ZEN_DURATION); |
| 3865 | if (currentSetting.isNull()) { |
| 3866 | String defaultZenDuration = Integer.toString(getContext() |
| 3867 | .getResources().getInteger(R.integer.def_zen_duration)); |
| 3868 | globalSettings.insertSettingLocked( |
| 3869 | Global.ZEN_DURATION, defaultZenDuration, |
| 3870 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3871 | } |
Beverly | 09da25f | 2018-02-26 09:17:07 -0500 | [diff] [blame] | 3872 | currentVersion = 157; |
| 3873 | } |
Annie Meng | d069a88 | 2018-03-13 15:31:40 +0000 | [diff] [blame] | 3874 | |
| 3875 | if (currentVersion == 157) { |
| 3876 | // Version 158: Set default value for BACKUP_AGENT_TIMEOUT_PARAMETERS. |
| 3877 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3878 | final String oldValue = globalSettings.getSettingLocked( |
| 3879 | Settings.Global.BACKUP_AGENT_TIMEOUT_PARAMETERS).getValue(); |
| 3880 | if (TextUtils.equals(null, oldValue)) { |
| 3881 | final String defaultValue = getContext().getResources().getString( |
| 3882 | R.string.def_backup_agent_timeout_parameters); |
| 3883 | if (!TextUtils.isEmpty(defaultValue)) { |
| 3884 | globalSettings.insertSettingLocked( |
| 3885 | Settings.Global.BACKUP_AGENT_TIMEOUT_PARAMETERS, defaultValue, |
| 3886 | null, true, |
| 3887 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 3888 | } |
| 3889 | } |
| 3890 | currentVersion = 158; |
| 3891 | } |
Roshan Pius | 9c39667 | 2018-03-02 14:54:13 -0800 | [diff] [blame] | 3892 | |
| 3893 | if (currentVersion == 158) { |
| 3894 | // Remove setting that specifies wifi bgscan throttling params |
| 3895 | getGlobalSettingsLocked().deleteSettingLocked( |
| 3896 | "wifi_scan_background_throttle_interval_ms"); |
| 3897 | getGlobalSettingsLocked().deleteSettingLocked( |
| 3898 | "wifi_scan_background_throttle_package_whitelist"); |
| 3899 | currentVersion = 159; |
| 3900 | } |
| 3901 | |
Pavel Grafov | c5c9730 | 2018-03-19 13:37:15 +0000 | [diff] [blame] | 3902 | if (currentVersion == 159) { |
| 3903 | // Version 160: Hiding notifications from the lockscreen is only available as |
| 3904 | // primary user option, profiles can only make them redacted. If a profile was |
| 3905 | // configured to not show lockscreen notifications, ensure that at the very |
| 3906 | // least these will be come hidden. |
| 3907 | if (mUserManager.isManagedProfile(userId)) { |
| 3908 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3909 | Setting showNotifications = secureSettings.getSettingLocked( |
| 3910 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); |
| 3911 | // The default value is "1", check if user has turned it off. |
| 3912 | if ("0".equals(showNotifications.getValue())) { |
| 3913 | secureSettings.insertSettingLocked( |
| 3914 | Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, "0", |
| 3915 | null /* tag */, false /* makeDefault */, |
| 3916 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 3917 | } |
| 3918 | // The setting is no longer valid for managed profiles, it should be |
| 3919 | // treated as if it was set to "1". |
| 3920 | secureSettings.deleteSettingLocked(Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); |
| 3921 | } |
| 3922 | currentVersion = 160; |
| 3923 | } |
Philip P. Moltmann | 18e3eb8 | 2018-03-09 16:55:55 -0800 | [diff] [blame] | 3924 | |
| 3925 | if (currentVersion == 160) { |
| 3926 | // Version 161: Set the default value for |
Philip P. Moltmann | 7e25b3d | 2018-03-09 20:22:58 -0800 | [diff] [blame] | 3927 | // MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY and |
Philip P. Moltmann | 18e3eb8 | 2018-03-09 16:55:55 -0800 | [diff] [blame] | 3928 | // SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT |
| 3929 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 3930 | |
| 3931 | String oldValue = globalSettings.getSettingLocked( |
Philip P. Moltmann | 7e25b3d | 2018-03-09 20:22:58 -0800 | [diff] [blame] | 3932 | Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY).getValue(); |
| 3933 | if (TextUtils.equals(null, oldValue)) { |
| 3934 | globalSettings.insertSettingLocked( |
| 3935 | Settings.Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY, |
| 3936 | Integer.toString(getContext().getResources().getInteger( |
| 3937 | R.integer.def_max_sound_trigger_detection_service_ops_per_day)), |
| 3938 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3939 | } |
| 3940 | |
| 3941 | oldValue = globalSettings.getSettingLocked( |
Philip P. Moltmann | 18e3eb8 | 2018-03-09 16:55:55 -0800 | [diff] [blame] | 3942 | Global.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT).getValue(); |
| 3943 | if (TextUtils.equals(null, oldValue)) { |
| 3944 | globalSettings.insertSettingLocked( |
| 3945 | Settings.Global.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT, |
| 3946 | Integer.toString(getContext().getResources().getInteger( |
| 3947 | R.integer.def_sound_trigger_detection_service_op_timeout)), |
| 3948 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3949 | } |
| 3950 | currentVersion = 161; |
| 3951 | } |
| 3952 | |
Mike Digman | 5527286 | 2018-02-20 14:35:17 -0800 | [diff] [blame] | 3953 | if (currentVersion == 161) { |
| 3954 | // Version 161: Add a gesture for silencing phones |
| 3955 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 3956 | final Setting currentSetting = secureSettings.getSettingLocked( |
| 3957 | Secure.VOLUME_HUSH_GESTURE); |
| 3958 | if (currentSetting.isNull()) { |
| 3959 | secureSettings.insertSettingLocked( |
| 3960 | Secure.VOLUME_HUSH_GESTURE, |
| 3961 | Integer.toString(Secure.VOLUME_HUSH_VIBRATE), |
| 3962 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3963 | } |
| 3964 | |
| 3965 | currentVersion = 162; |
| 3966 | } |
| 3967 | |
Julia Reynolds | c4e5ecf | 2018-04-11 11:33:32 -0400 | [diff] [blame] | 3968 | if (currentVersion == 162) { |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 3969 | // Version 162: REMOVED: Add a gesture for silencing phones |
Julia Reynolds | c4e5ecf | 2018-04-11 11:33:32 -0400 | [diff] [blame] | 3970 | currentVersion = 163; |
| 3971 | } |
| 3972 | |
Philip P. Moltmann | cb58a83 | 2018-04-16 09:19:42 -0700 | [diff] [blame] | 3973 | if (currentVersion == 163) { |
| 3974 | // Version 163: Update default value of |
| 3975 | // MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY from old to new default |
| 3976 | final SettingsState settings = getGlobalSettingsLocked(); |
| 3977 | final Setting currentSetting = settings.getSettingLocked( |
| 3978 | Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY); |
| 3979 | if (currentSetting.isDefaultFromSystem()) { |
| 3980 | settings.insertSettingLocked( |
| 3981 | Settings.Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY, |
| 3982 | Integer.toString(getContext().getResources().getInteger( |
| 3983 | R.integer |
| 3984 | .def_max_sound_trigger_detection_service_ops_per_day)), |
| 3985 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 3986 | } |
| 3987 | |
| 3988 | currentVersion = 164; |
| 3989 | } |
| 3990 | |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 3991 | if (currentVersion == 164) { |
Julia Reynolds | 24836c5 | 2018-06-06 14:36:03 -0400 | [diff] [blame] | 3992 | // Version 164: REMOVED: show zen upgrade notification |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 3993 | currentVersion = 165; |
| 3994 | } |
| 3995 | |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 3996 | if (currentVersion == 165) { |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 3997 | // Version 165: MOVED: Show zen settings suggestion and zen updated settings |
| 3998 | // moved to secure settings and are set in version 169 |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 3999 | currentVersion = 166; |
| 4000 | } |
| 4001 | |
Beverly | 38fcfd0 | 2018-05-18 17:33:40 -0400 | [diff] [blame] | 4002 | if (currentVersion == 166) { |
| 4003 | // Version 166: add default values for hush gesture used and manual ringer |
| 4004 | // toggle |
| 4005 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4006 | Setting currentHushUsedSetting = secureSettings.getSettingLocked( |
| 4007 | Secure.HUSH_GESTURE_USED); |
| 4008 | if (currentHushUsedSetting.isNull()) { |
| 4009 | secureSettings.insertSettingLocked( |
| 4010 | Settings.Secure.HUSH_GESTURE_USED, "0", null, true, |
| 4011 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 4012 | } |
| 4013 | |
| 4014 | Setting currentRingerToggleCountSetting = secureSettings.getSettingLocked( |
| 4015 | Secure.MANUAL_RINGER_TOGGLE_COUNT); |
| 4016 | if (currentRingerToggleCountSetting.isNull()) { |
| 4017 | secureSettings.insertSettingLocked( |
| 4018 | Settings.Secure.MANUAL_RINGER_TOGGLE_COUNT, "0", null, true, |
| 4019 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 4020 | } |
| 4021 | currentVersion = 167; |
| 4022 | } |
| 4023 | |
Beverly | 155c9d2 | 2018-05-23 18:03:23 -0400 | [diff] [blame] | 4024 | if (currentVersion == 167) { |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 4025 | // Version 167: MOVED - Settings.Global.CHARGING_VIBRATION_ENABLED moved to |
| 4026 | // Settings.Secure.CHARGING_VIBRATION_ENABLED, set in version 170 |
Beverly | 155c9d2 | 2018-05-23 18:03:23 -0400 | [diff] [blame] | 4027 | currentVersion = 168; |
| 4028 | } |
| 4029 | |
Michael Wright | 0e9eeee | 2018-05-26 00:31:20 +0100 | [diff] [blame] | 4030 | if (currentVersion == 168) { |
| 4031 | // Version 168: by default, vibrate for phone calls |
| 4032 | final SettingsState systemSettings = getSystemSettingsLocked(userId); |
| 4033 | final Setting currentSetting = systemSettings.getSettingLocked( |
| 4034 | Settings.System.VIBRATE_WHEN_RINGING); |
| 4035 | if (currentSetting.isNull()) { |
| 4036 | systemSettings.insertSettingLocked( |
| 4037 | Settings.System.VIBRATE_WHEN_RINGING, |
| 4038 | getContext().getResources().getBoolean( |
| 4039 | R.bool.def_vibrate_when_ringing) ? "1" : "0", |
| 4040 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4041 | } |
| 4042 | currentVersion = 169; |
| 4043 | } |
| 4044 | |
Nadav Bar | f9f115d | 2018-06-24 10:06:50 +0300 | [diff] [blame] | 4045 | if (currentVersion == 169) { |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 4046 | // Version 169: Set the default value for Secure Settings ZEN_DURATION, |
| 4047 | // SHOW_ZEN_SETTINGS_SUGGESTION, ZEN_SETTINGS_UPDATE and |
| 4048 | // ZEN_SETTINGS_SUGGESTION_VIEWED |
Nadav Bar | f9f115d | 2018-06-24 10:06:50 +0300 | [diff] [blame] | 4049 | |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 4050 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 4051 | final Setting globalZenDuration = globalSettings.getSettingLocked( |
| 4052 | Global.ZEN_DURATION); |
| 4053 | |
| 4054 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4055 | final Setting secureZenDuration = secureSettings.getSettingLocked( |
| 4056 | Secure.ZEN_DURATION); |
| 4057 | |
| 4058 | // ZEN_DURATION |
| 4059 | if (!globalZenDuration.isNull()) { |
| 4060 | secureSettings.insertSettingLocked( |
| 4061 | Secure.ZEN_DURATION, globalZenDuration.getValue(), null, false, |
| 4062 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 4063 | |
| 4064 | // set global zen duration setting to null since it's deprecated |
| 4065 | globalSettings.insertSettingLocked( |
| 4066 | Global.ZEN_DURATION, null, null, true, |
| 4067 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 4068 | } else if (secureZenDuration.isNull()) { |
| 4069 | String defaultZenDuration = Integer.toString(getContext() |
| 4070 | .getResources().getInteger(R.integer.def_zen_duration)); |
| 4071 | secureSettings.insertSettingLocked( |
| 4072 | Secure.ZEN_DURATION, defaultZenDuration, null, true, |
| 4073 | SettingsState.SYSTEM_PACKAGE_NAME); |
Nadav Bar | f9f115d | 2018-06-24 10:06:50 +0300 | [diff] [blame] | 4074 | } |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 4075 | |
| 4076 | // SHOW_ZEN_SETTINGS_SUGGESTION |
| 4077 | final Setting currentShowZenSettingSuggestion = secureSettings.getSettingLocked( |
| 4078 | Secure.SHOW_ZEN_SETTINGS_SUGGESTION); |
| 4079 | if (currentShowZenSettingSuggestion.isNull()) { |
| 4080 | secureSettings.insertSettingLocked( |
| 4081 | Secure.SHOW_ZEN_SETTINGS_SUGGESTION, "1", |
| 4082 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4083 | } |
| 4084 | |
| 4085 | // ZEN_SETTINGS_UPDATED |
| 4086 | final Setting currentUpdatedSetting = secureSettings.getSettingLocked( |
| 4087 | Secure.ZEN_SETTINGS_UPDATED); |
| 4088 | if (currentUpdatedSetting.isNull()) { |
| 4089 | secureSettings.insertSettingLocked( |
| 4090 | Secure.ZEN_SETTINGS_UPDATED, "0", |
| 4091 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4092 | } |
| 4093 | |
| 4094 | // ZEN_SETTINGS_SUGGESTION_VIEWED |
| 4095 | final Setting currentSettingSuggestionViewed = secureSettings.getSettingLocked( |
| 4096 | Secure.ZEN_SETTINGS_SUGGESTION_VIEWED); |
| 4097 | if (currentSettingSuggestionViewed.isNull()) { |
| 4098 | secureSettings.insertSettingLocked( |
| 4099 | Secure.ZEN_SETTINGS_SUGGESTION_VIEWED, "0", |
| 4100 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4101 | } |
| 4102 | |
Nadav Bar | f9f115d | 2018-06-24 10:06:50 +0300 | [diff] [blame] | 4103 | currentVersion = 170; |
| 4104 | } |
| 4105 | |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 4106 | if (currentVersion == 170) { |
| 4107 | // Version 170: Set the default value for Secure Settings: |
| 4108 | // CHARGING_SOUNDS_ENABLED and CHARGING_VIBRATION_ENABLED |
| 4109 | |
| 4110 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 4111 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4112 | |
| 4113 | // CHARGING_SOUNDS_ENABLED |
| 4114 | final Setting globalChargingSoundEnabled = globalSettings.getSettingLocked( |
| 4115 | Global.CHARGING_SOUNDS_ENABLED); |
| 4116 | final Setting secureChargingSoundsEnabled = secureSettings.getSettingLocked( |
| 4117 | Secure.CHARGING_SOUNDS_ENABLED); |
| 4118 | |
| 4119 | if (!globalChargingSoundEnabled.isNull()) { |
Beverly | ff9c587 | 2019-01-02 15:44:00 -0500 | [diff] [blame] | 4120 | if (secureChargingSoundsEnabled.isNull()) { |
| 4121 | secureSettings.insertSettingLocked( |
| 4122 | Secure.CHARGING_SOUNDS_ENABLED, |
| 4123 | globalChargingSoundEnabled.getValue(), null, false, |
| 4124 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 4125 | } |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 4126 | |
| 4127 | // set global charging_sounds_enabled setting to null since it's deprecated |
| 4128 | globalSettings.insertSettingLocked( |
| 4129 | Global.CHARGING_SOUNDS_ENABLED, null, null, true, |
| 4130 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 4131 | } else if (secureChargingSoundsEnabled.isNull()) { |
| 4132 | String defChargingSoundsEnabled = getContext().getResources() |
| 4133 | .getBoolean(R.bool.def_charging_sounds_enabled) ? "1" : "0"; |
| 4134 | secureSettings.insertSettingLocked( |
| 4135 | Secure.CHARGING_SOUNDS_ENABLED, defChargingSoundsEnabled, null, |
| 4136 | true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4137 | } |
| 4138 | |
| 4139 | // CHARGING_VIBRATION_ENABLED |
| 4140 | final Setting secureChargingVibrationEnabled = secureSettings.getSettingLocked( |
| 4141 | Secure.CHARGING_VIBRATION_ENABLED); |
| 4142 | |
| 4143 | if (secureChargingVibrationEnabled.isNull()) { |
| 4144 | String defChargingVibrationEnabled = getContext().getResources() |
| 4145 | .getBoolean(R.bool.def_charging_vibration_enabled) ? "1" : "0"; |
| 4146 | secureSettings.insertSettingLocked( |
| 4147 | Secure.CHARGING_VIBRATION_ENABLED, defChargingVibrationEnabled, |
| 4148 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4149 | } |
| 4150 | |
| 4151 | currentVersion = 171; |
| 4152 | } |
| 4153 | |
Nadav Bar | 8bc8c9e | 2018-09-12 15:41:51 +0300 | [diff] [blame] | 4154 | if (currentVersion == 171) { |
| 4155 | // Version 171: by default, add STREAM_VOICE_CALL to list of streams that can |
| 4156 | // be muted. |
| 4157 | final SettingsState systemSettings = getSystemSettingsLocked(userId); |
| 4158 | final Setting currentSetting = systemSettings.getSettingLocked( |
| 4159 | Settings.System.MUTE_STREAMS_AFFECTED); |
| 4160 | if (!currentSetting.isNull()) { |
| 4161 | try { |
| 4162 | int currentSettingIntegerValue = Integer.parseInt( |
| 4163 | currentSetting.getValue()); |
| 4164 | if ((currentSettingIntegerValue |
| 4165 | & (1 << AudioManager.STREAM_VOICE_CALL)) == 0) { |
| 4166 | systemSettings.insertSettingLocked( |
| 4167 | Settings.System.MUTE_STREAMS_AFFECTED, |
| 4168 | Integer.toString( |
| 4169 | currentSettingIntegerValue |
| 4170 | | (1 << AudioManager.STREAM_VOICE_CALL)), |
| 4171 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4172 | } |
| 4173 | } catch (NumberFormatException e) { |
| 4174 | // remove the setting in case it is not a valid integer |
| 4175 | Slog.w("Failed to parse integer value of MUTE_STREAMS_AFFECTED" |
| 4176 | + "setting, removing setting", e); |
| 4177 | systemSettings.deleteSettingLocked( |
| 4178 | Settings.System.MUTE_STREAMS_AFFECTED); |
| 4179 | } |
| 4180 | |
| 4181 | } |
| 4182 | currentVersion = 172; |
| 4183 | } |
| 4184 | |
Soonil Nagarkar | 42da1b1 | 2019-01-22 11:29:27 -0800 | [diff] [blame] | 4185 | if (currentVersion == 172) { |
| 4186 | // Version 172: Set the default value for Secure Settings: LOCATION_MODE |
| 4187 | |
| 4188 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4189 | |
| 4190 | final Setting locationMode = secureSettings.getSettingLocked( |
| 4191 | Secure.LOCATION_MODE); |
| 4192 | |
| 4193 | if (locationMode.isNull()) { |
| 4194 | final Setting locationProvidersAllowed = secureSettings.getSettingLocked( |
| 4195 | Secure.LOCATION_PROVIDERS_ALLOWED); |
| 4196 | |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 4197 | final int defLocationMode; |
| 4198 | if (locationProvidersAllowed.isNull()) { |
| 4199 | defLocationMode = getContext().getResources().getInteger( |
| 4200 | R.integer.def_location_mode); |
| 4201 | } else { |
| 4202 | defLocationMode = |
| 4203 | !TextUtils.isEmpty(locationProvidersAllowed.getValue()) |
| 4204 | ? Secure.LOCATION_MODE_ON |
| 4205 | : Secure.LOCATION_MODE_OFF; |
| 4206 | } |
Soonil Nagarkar | 42da1b1 | 2019-01-22 11:29:27 -0800 | [diff] [blame] | 4207 | secureSettings.insertSettingLocked( |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 4208 | Secure.LOCATION_MODE, Integer.toString(defLocationMode), |
Soonil Nagarkar | 42da1b1 | 2019-01-22 11:29:27 -0800 | [diff] [blame] | 4209 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4210 | } |
| 4211 | |
| 4212 | currentVersion = 173; |
| 4213 | } |
| 4214 | |
Beverly | 4179f99 | 2019-02-08 11:34:16 -0500 | [diff] [blame] | 4215 | if (currentVersion == 173) { |
| 4216 | // Version 173: Set the default value for Secure Settings: NOTIFICATION_BUBBLES |
Lyn Han | b739fa6 | 2019-06-27 18:41:11 -0700 | [diff] [blame] | 4217 | // Removed. Moved NOTIFICATION_BUBBLES to Global Settings. |
Beverly | 4179f99 | 2019-02-08 11:34:16 -0500 | [diff] [blame] | 4218 | currentVersion = 174; |
| 4219 | } |
| 4220 | |
Yiwen Chen | 0305b57 | 2019-03-05 11:26:59 -0800 | [diff] [blame] | 4221 | if (currentVersion == 174) { |
| 4222 | // Version 174: Set the default value for Global Settings: APPLY_RAMPING_RINGER |
| 4223 | |
| 4224 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 4225 | |
| 4226 | Setting currentRampingRingerSetting = globalSettings.getSettingLocked( |
| 4227 | Settings.Global.APPLY_RAMPING_RINGER); |
| 4228 | if (currentRampingRingerSetting.isNull()) { |
| 4229 | globalSettings.insertSettingLocked( |
| 4230 | Settings.Global.APPLY_RAMPING_RINGER, |
| 4231 | getContext().getResources().getBoolean( |
| 4232 | R.bool.def_apply_ramping_ringer) ? "1" : "0", null, |
| 4233 | true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4234 | } |
| 4235 | |
| 4236 | currentVersion = 175; |
| 4237 | } |
| 4238 | |
wilsonshih | 5d999e2 | 2019-03-20 11:50:42 +0800 | [diff] [blame] | 4239 | if (currentVersion == 175) { |
| 4240 | // Version 175: Set the default value for System Settings: |
| 4241 | // RING_VIBRATION_INTENSITY. If the notification vibration intensity has been |
| 4242 | // set and ring vibration intensity hasn't, the ring vibration intensity should |
| 4243 | // followed notification vibration intensity. |
| 4244 | |
| 4245 | final SettingsState systemSettings = getSystemSettingsLocked(userId); |
| 4246 | |
| 4247 | Setting notificationVibrationIntensity = systemSettings.getSettingLocked( |
| 4248 | Settings.System.NOTIFICATION_VIBRATION_INTENSITY); |
| 4249 | |
| 4250 | Setting ringVibrationIntensity = systemSettings.getSettingLocked( |
| 4251 | Settings.System.RING_VIBRATION_INTENSITY); |
| 4252 | |
| 4253 | if (!notificationVibrationIntensity.isNull() |
| 4254 | && ringVibrationIntensity.isNull()) { |
| 4255 | systemSettings.insertSettingLocked( |
| 4256 | Settings.System.RING_VIBRATION_INTENSITY, |
| 4257 | notificationVibrationIntensity.getValue(), |
| 4258 | null , true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4259 | } |
| 4260 | |
| 4261 | currentVersion = 176; |
| 4262 | } |
| 4263 | |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 4264 | if (currentVersion == 176) { |
| 4265 | // Version 176: Migrate the existing swipe up setting into the resource overlay |
Winson Chung | 3d5d3b3 | 2019-04-24 16:52:47 -0700 | [diff] [blame] | 4266 | // for the navigation bar interaction mode. We do so only if the |
| 4267 | // setting is set. |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 4268 | |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 4269 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4270 | final Setting swipeUpSetting = secureSettings.getSettingLocked( |
Winson Chung | 85e7459 | 2019-03-06 11:49:22 -0800 | [diff] [blame] | 4271 | "swipe_up_to_switch_apps_enabled"); |
Winson Chung | 3d5d3b3 | 2019-04-24 16:52:47 -0700 | [diff] [blame] | 4272 | if (swipeUpSetting != null && !swipeUpSetting.isNull() |
| 4273 | && swipeUpSetting.getValue().equals("1")) { |
| 4274 | final IOverlayManager overlayManager = IOverlayManager.Stub.asInterface( |
| 4275 | ServiceManager.getService(Context.OVERLAY_SERVICE)); |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 4276 | try { |
Winson Chung | 3d5d3b3 | 2019-04-24 16:52:47 -0700 | [diff] [blame] | 4277 | overlayManager.setEnabledExclusiveInCategory( |
| 4278 | NAV_BAR_MODE_2BUTTON_OVERLAY, UserHandle.USER_CURRENT); |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 4279 | } catch (RemoteException e) { |
| 4280 | throw new IllegalStateException( |
| 4281 | "Failed to set nav bar interaction mode overlay"); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | currentVersion = 177; |
| 4286 | } |
| 4287 | |
Edgar Wang | eb8bddb | 2019-04-19 17:29:49 +0800 | [diff] [blame] | 4288 | if (currentVersion == 177) { |
| 4289 | // Version 177: Set the default value for Secure Settings: AWARE_ENABLED |
| 4290 | |
| 4291 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4292 | |
| 4293 | final Setting awareEnabled = secureSettings.getSettingLocked( |
| 4294 | Secure.AWARE_ENABLED); |
| 4295 | |
| 4296 | if (awareEnabled.isNull()) { |
| 4297 | final boolean defAwareEnabled = getContext().getResources().getBoolean( |
| 4298 | R.bool.def_aware_enabled); |
| 4299 | secureSettings.insertSettingLocked( |
| 4300 | Secure.AWARE_ENABLED, defAwareEnabled ? "1" : "0", |
| 4301 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4302 | } |
| 4303 | |
| 4304 | currentVersion = 178; |
| 4305 | } |
| 4306 | |
Edgar Wang | dabc41e | 2019-05-07 18:53:31 +0800 | [diff] [blame] | 4307 | if (currentVersion == 178) { |
| 4308 | // Version 178: Set the default value for Secure Settings: |
| 4309 | // SKIP_GESTURE & SILENCE_GESTURE |
| 4310 | |
| 4311 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4312 | |
| 4313 | final Setting skipGesture = secureSettings.getSettingLocked( |
| 4314 | Secure.SKIP_GESTURE); |
| 4315 | |
| 4316 | if (skipGesture.isNull()) { |
| 4317 | final boolean defSkipGesture = getContext().getResources().getBoolean( |
| 4318 | R.bool.def_skip_gesture); |
| 4319 | secureSettings.insertSettingLocked( |
| 4320 | Secure.SKIP_GESTURE, defSkipGesture ? "1" : "0", |
| 4321 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4322 | } |
| 4323 | |
| 4324 | final Setting silenceGesture = secureSettings.getSettingLocked( |
| 4325 | Secure.SILENCE_GESTURE); |
| 4326 | |
| 4327 | if (silenceGesture.isNull()) { |
| 4328 | final boolean defSilenceGesture = getContext().getResources().getBoolean( |
| 4329 | R.bool.def_silence_gesture); |
| 4330 | secureSettings.insertSettingLocked( |
| 4331 | Secure.SILENCE_GESTURE, defSilenceGesture ? "1" : "0", |
| 4332 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4333 | } |
| 4334 | |
| 4335 | currentVersion = 179; |
| 4336 | } |
| 4337 | |
Mady Mellor | 95e879a | 2019-05-06 08:50:06 -0700 | [diff] [blame] | 4338 | if (currentVersion == 179) { |
| 4339 | // Version 178: Reset the default for Secure Settings: NOTIFICATION_BUBBLES |
| 4340 | // This is originally set in version 173, however, the default value changed |
Lyn Han | b739fa6 | 2019-06-27 18:41:11 -0700 | [diff] [blame] | 4341 | // so this step is to ensure the value is updated to the correct default. |
Mady Mellor | 95e879a | 2019-05-06 08:50:06 -0700 | [diff] [blame] | 4342 | |
Lyn Han | b739fa6 | 2019-06-27 18:41:11 -0700 | [diff] [blame] | 4343 | // Removed. Moved NOTIFICATION_BUBBLES to Global Settings. |
Mady Mellor | 95e879a | 2019-05-06 08:50:06 -0700 | [diff] [blame] | 4344 | currentVersion = 180; |
| 4345 | } |
Winson Chung | d9f2fb3 | 2019-03-05 11:10:12 -0800 | [diff] [blame] | 4346 | |
Edgar Wang | 4870e4b | 2019-05-15 19:14:43 +0800 | [diff] [blame] | 4347 | if (currentVersion == 180) { |
| 4348 | // Version 180: Set the default value for Secure Settings: AWARE_LOCK_ENABLED |
| 4349 | |
| 4350 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 4351 | |
| 4352 | final Setting awareLockEnabled = secureSettings.getSettingLocked( |
| 4353 | Secure.AWARE_LOCK_ENABLED); |
| 4354 | |
| 4355 | if (awareLockEnabled.isNull()) { |
| 4356 | final boolean defAwareLockEnabled = getContext().getResources().getBoolean( |
| 4357 | R.bool.def_aware_lock_enabled); |
| 4358 | secureSettings.insertSettingLocked( |
| 4359 | Secure.AWARE_LOCK_ENABLED, defAwareLockEnabled ? "1" : "0", |
| 4360 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4361 | } |
| 4362 | |
| 4363 | currentVersion = 181; |
| 4364 | } |
| 4365 | |
Eric Laurent | 02153e6 | 2019-06-12 17:20:03 -0700 | [diff] [blame] | 4366 | if (currentVersion == 181) { |
| 4367 | // Version cd : by default, add STREAM_BLUETOOTH_SCO to list of streams that can |
| 4368 | // be muted. |
| 4369 | final SettingsState systemSettings = getSystemSettingsLocked(userId); |
| 4370 | final Setting currentSetting = systemSettings.getSettingLocked( |
| 4371 | Settings.System.MUTE_STREAMS_AFFECTED); |
| 4372 | if (!currentSetting.isNull()) { |
| 4373 | try { |
| 4374 | int currentSettingIntegerValue = Integer.parseInt( |
| 4375 | currentSetting.getValue()); |
| 4376 | if ((currentSettingIntegerValue |
| 4377 | & (1 << AudioManager.STREAM_BLUETOOTH_SCO)) == 0) { |
| 4378 | systemSettings.insertSettingLocked( |
| 4379 | Settings.System.MUTE_STREAMS_AFFECTED, |
| 4380 | Integer.toString( |
| 4381 | currentSettingIntegerValue |
| 4382 | | (1 << AudioManager.STREAM_BLUETOOTH_SCO)), |
| 4383 | null, true, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4384 | } |
| 4385 | } catch (NumberFormatException e) { |
| 4386 | // remove the setting in case it is not a valid integer |
| 4387 | Slog.w("Failed to parse integer value of MUTE_STREAMS_AFFECTED" |
| 4388 | + "setting, removing setting", e); |
| 4389 | systemSettings.deleteSettingLocked( |
| 4390 | Settings.System.MUTE_STREAMS_AFFECTED); |
| 4391 | } |
| 4392 | |
| 4393 | } |
| 4394 | currentVersion = 182; |
| 4395 | } |
| 4396 | |
Lyn Han | b739fa6 | 2019-06-27 18:41:11 -0700 | [diff] [blame] | 4397 | if (currentVersion == 182) { |
| 4398 | // Remove secure bubble settings. |
Mady Mellor | fa9556a | 2019-09-19 11:10:31 -0700 | [diff] [blame] | 4399 | getSecureSettingsLocked(userId).deleteSettingLocked("notification_bubbles"); |
Lyn Han | b739fa6 | 2019-06-27 18:41:11 -0700 | [diff] [blame] | 4400 | |
| 4401 | // Add global bubble settings. |
| 4402 | getGlobalSettingsLocked().insertSettingLocked(Global.NOTIFICATION_BUBBLES, |
| 4403 | getContext().getResources().getBoolean( |
| 4404 | R.bool.def_notification_bubbles) ? "1" : "0", null /* tag */, |
| 4405 | true /* makeDefault */, SettingsState.SYSTEM_PACKAGE_NAME); |
| 4406 | |
| 4407 | currentVersion = 183; |
| 4408 | } |
| 4409 | |
Felipe Leme | ff35509 | 2017-04-03 12:55:02 -0700 | [diff] [blame] | 4410 | // vXXX: Add new settings above this point. |
| 4411 | |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 4412 | if (currentVersion != newVersion) { |
Svetoslav Ganov | 264c7a9 | 2016-08-24 17:31:14 -0700 | [diff] [blame] | 4413 | Slog.wtf("SettingsProvider", "warning: upgrading settings database to version " |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 4414 | + newVersion + " left it at " |
Stephen Chen | 5d0922f | 2017-03-27 10:28:04 -0700 | [diff] [blame] | 4415 | + currentVersion + |
| 4416 | " instead; this is probably a bug. Did you update SETTINGS_VERSION?", |
| 4417 | new Throwable()); |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 4418 | if (DEBUG) { |
| 4419 | throw new RuntimeException("db upgrade error"); |
| 4420 | } |
| 4421 | } |
| 4422 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 4423 | // Return the current version. |
| 4424 | return currentVersion; |
Brad Fitzpatrick | 547a96b | 2010-03-09 17:58:53 -0800 | [diff] [blame] | 4425 | } |
| 4426 | } |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 4427 | |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 4428 | private void ensureLegacyDefaultValueAndSystemSetUpdatedLocked(SettingsState settings, |
| 4429 | int userId) { |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 4430 | List<String> names = settings.getSettingNamesLocked(); |
| 4431 | final int nameCount = names.size(); |
| 4432 | for (int i = 0; i < nameCount; i++) { |
| 4433 | String name = names.get(i); |
| 4434 | Setting setting = settings.getSettingLocked(name); |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 4435 | |
| 4436 | // In the upgrade case we pretend the call is made from the app |
| 4437 | // that made the last change to the setting to properly determine |
| 4438 | // whether the call has been made by a system component. |
| 4439 | int callingUid = -1; |
| 4440 | try { |
| 4441 | callingUid = mPackageManager.getPackageUid(setting.getPackageName(), 0, userId); |
| 4442 | } catch (RemoteException e) { |
| 4443 | /* ignore - handled below */ |
| 4444 | } |
| 4445 | if (callingUid < 0) { |
| 4446 | Slog.e(LOG_TAG, "Unknown package: " + setting.getPackageName()); |
| 4447 | continue; |
| 4448 | } |
| 4449 | try { |
| 4450 | final boolean systemSet = SettingsState.isSystemPackage(getContext(), |
Matt Pape | 25c940d | 2019-03-26 12:14:33 -0700 | [diff] [blame] | 4451 | setting.getPackageName(), callingUid, userId); |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 4452 | if (systemSet) { |
| 4453 | settings.insertSettingLocked(name, setting.getValue(), |
| 4454 | setting.getTag(), true, setting.getPackageName()); |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 4455 | } else if (setting.getDefaultValue() != null && setting.isDefaultFromSystem()) { |
| 4456 | // We had a bug where changes by non-system packages were marked |
| 4457 | // as system made and as a result set as the default. Therefore, if |
| 4458 | // the package changed the setting last is not a system one but the |
| 4459 | // setting is marked as its default coming from the system we clear |
| 4460 | // the default and clear the system set flag. |
| 4461 | settings.resetSettingDefaultValueLocked(name); |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 4462 | } |
Svetoslav Ganov | f7654c5 | 2017-08-16 17:33:22 -0700 | [diff] [blame] | 4463 | } catch (IllegalStateException e) { |
| 4464 | // If the package goes over its quota during the upgrade, don't |
| 4465 | // crash but just log the error as the system does the upgrade. |
| 4466 | Slog.e(LOG_TAG, "Error upgrading setting: " + setting.getName(), e); |
| 4467 | |
Svet Ganov | 1370155 | 2017-02-23 12:45:17 -0800 | [diff] [blame] | 4468 | } |
| 4469 | } |
| 4470 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 4471 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 4472 | } |