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