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 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 19 | import android.Manifest; |
Christopher Tate | d5fe147 | 2012-09-10 15:48:38 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 21 | import android.app.AppGlobals; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 22 | import android.app.backup.BackupManager; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 25 | import android.content.ContentProvider; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | import android.content.ContentValues; |
| 27 | import android.content.Context; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
| 29 | import android.content.IntentFilter; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 31 | import android.content.pm.IPackageManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Christopher Tate | 38e7a60 | 2013-09-03 16:57:34 -0700 | [diff] [blame] | 34 | import android.content.pm.UserInfo; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 35 | import android.database.Cursor; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 36 | import android.database.MatrixCursor; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | import android.database.sqlite.SQLiteDatabase; |
| 38 | import android.database.sqlite.SQLiteQueryBuilder; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 39 | import android.hardware.camera2.utils.ArrayUtils; |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 40 | import android.media.AudioManager; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 41 | import android.net.Uri; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 42 | import android.os.Binder; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 43 | import android.os.Build; |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 44 | import android.os.Bundle; |
Amith Yamasani | 5cdf7f5 | 2013-06-27 15:12:01 -0700 | [diff] [blame] | 45 | import android.os.DropBoxManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 46 | import android.os.Environment; |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 47 | import android.os.Handler; |
Svet Ganov | a8f9026 | 2016-05-10 08:44:48 -0700 | [diff] [blame] | 48 | import android.os.HandlerThread; |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 49 | import android.os.Looper; |
| 50 | import android.os.Message; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; |
Christopher Tate | 0da1357 | 2013-10-13 17:34:49 -0700 | [diff] [blame] | 52 | import android.os.Process; |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 53 | import android.os.RemoteException; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 54 | import android.os.SELinux; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 55 | import android.os.ServiceManager; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
| 57 | import android.os.UserManager; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 58 | import android.os.UserManagerInternal; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 59 | import android.provider.Settings; |
| 60 | import android.text.TextUtils; |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 61 | import android.util.ArrayMap; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 62 | import android.util.ArraySet; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 63 | import android.util.Slog; |
| 64 | import android.util.SparseArray; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 65 | import android.util.SparseBooleanArray; |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 66 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 67 | import com.android.internal.annotations.GuardedBy; |
| 68 | import com.android.internal.content.PackageMonitor; |
| 69 | import com.android.internal.os.BackgroundThread; |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 70 | import com.android.providers.settings.SettingsState.Setting; |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 71 | import com.android.server.LocalServices; |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 72 | import com.android.server.SystemConfig; |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 73 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 74 | import java.io.File; |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 75 | import java.io.FileDescriptor; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 76 | import java.io.FileNotFoundException; |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 77 | import java.io.PrintWriter; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 78 | import java.security.SecureRandom; |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 79 | import java.util.ArrayList; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 80 | import java.util.Arrays; |
| 81 | import java.util.List; |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 82 | import java.util.Map; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 83 | import java.util.Set; |
| 84 | import java.util.regex.Pattern; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 85 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 86 | /** |
| 87 | * <p> |
| 88 | * This class is a content provider that publishes the system settings. |
| 89 | * It can be accessed via the content provider APIs or via custom call |
| 90 | * commands. The latter is a bit faster and is the preferred way to access |
| 91 | * the platform settings. |
| 92 | * </p> |
| 93 | * <p> |
| 94 | * There are three settings types, global (with signature level protection |
| 95 | * and shared across users), secure (with signature permission level |
| 96 | * protection and per user), and system (with dangerous permission level |
| 97 | * protection and per user). Global settings are stored under the device owner. |
| 98 | * Each of these settings is represented by a {@link |
| 99 | * com.android.providers.settings.SettingsState} object mapped to an integer |
| 100 | * key derived from the setting type in the most significant bits and user |
| 101 | * id in the least significant bits. Settings are synchronously loaded on |
| 102 | * instantiation of a SettingsState and asynchronously persisted on mutation. |
| 103 | * Settings are stored in the user specific system directory. |
| 104 | * </p> |
| 105 | * <p> |
| 106 | * Apps targeting APIs Lollipop MR1 and lower can add custom settings entries |
| 107 | * and get a warning. Targeting higher API version prohibits this as the |
| 108 | * system settings are not a place for apps to save their state. When a package |
| 109 | * is removed the settings it added are deleted. Apps cannot delete system |
| 110 | * settings added by the platform. System settings values are validated to |
| 111 | * ensure the clients do not put bad values. Global and secure settings are |
| 112 | * changed only by trusted parties, therefore no validation is performed. Also |
| 113 | * there is a limit on the amount of app specific settings that can be added |
| 114 | * to prevent unlimited growth of the system process memory footprint. |
| 115 | * </p> |
| 116 | */ |
| 117 | @SuppressWarnings("deprecation") |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | public class SettingsProvider extends ContentProvider { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 119 | static final boolean DEBUG = false; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 120 | |
Svetoslav Ganov | 264c7a9 | 2016-08-24 17:31:14 -0700 | [diff] [blame] | 121 | private static final boolean DROP_DATABASE_ON_MIGRATION = true; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 122 | |
| 123 | private static final String LOG_TAG = "SettingsProvider"; |
Christopher Tate | 0da1357 | 2013-10-13 17:34:49 -0700 | [diff] [blame] | 124 | |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 125 | private static final String TABLE_SYSTEM = "system"; |
| 126 | private static final String TABLE_SECURE = "secure"; |
| 127 | private static final String TABLE_GLOBAL = "global"; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 128 | |
| 129 | // Old tables no longer exist. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | private static final String TABLE_FAVORITES = "favorites"; |
| 131 | private static final String TABLE_OLD_FAVORITES = "old_favorites"; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 132 | private static final String TABLE_BLUETOOTH_DEVICES = "bluetooth_devices"; |
| 133 | private static final String TABLE_BOOKMARKS = "bookmarks"; |
| 134 | private static final String TABLE_ANDROID_METADATA = "android_metadata"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 136 | // The set of removed legacy tables. |
| 137 | private static final Set<String> REMOVED_LEGACY_TABLES = new ArraySet<>(); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 138 | static { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 139 | REMOVED_LEGACY_TABLES.add(TABLE_FAVORITES); |
| 140 | REMOVED_LEGACY_TABLES.add(TABLE_OLD_FAVORITES); |
| 141 | REMOVED_LEGACY_TABLES.add(TABLE_BLUETOOTH_DEVICES); |
| 142 | REMOVED_LEGACY_TABLES.add(TABLE_BOOKMARKS); |
| 143 | REMOVED_LEGACY_TABLES.add(TABLE_ANDROID_METADATA); |
| 144 | } |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 145 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 146 | private static final int MUTATION_OPERATION_INSERT = 1; |
| 147 | private static final int MUTATION_OPERATION_DELETE = 2; |
| 148 | private static final int MUTATION_OPERATION_UPDATE = 3; |
Julia Reynolds | 5e458dd | 2014-07-07 16:07:01 -0400 | [diff] [blame] | 149 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 150 | private static final String[] ALL_COLUMNS = new String[] { |
| 151 | Settings.NameValueTable._ID, |
| 152 | Settings.NameValueTable.NAME, |
| 153 | Settings.NameValueTable.VALUE |
| 154 | }; |
| 155 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 156 | public static final int SETTINGS_TYPE_GLOBAL = 0; |
| 157 | public static final int SETTINGS_TYPE_SYSTEM = 1; |
| 158 | public static final int SETTINGS_TYPE_SECURE = 2; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 159 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 160 | public static final int SETTINGS_TYPE_MASK = 0xF0000000; |
| 161 | public static final int SETTINGS_TYPE_SHIFT = 28; |
| 162 | |
| 163 | private static final Bundle NULL_SETTING_BUNDLE = Bundle.forPair( |
| 164 | Settings.NameValueTable.VALUE, null); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 165 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 166 | // Per user secure settings that moved to the for all users global settings. |
| 167 | static final Set<String> sSecureMovedToGlobalSettings = new ArraySet<>(); |
| 168 | static { |
| 169 | Settings.Secure.getMovedToGlobalSettings(sSecureMovedToGlobalSettings); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 172 | // Per user system settings that moved to the for all users global settings. |
| 173 | static final Set<String> sSystemMovedToGlobalSettings = new ArraySet<>(); |
| 174 | static { |
| 175 | Settings.System.getMovedToGlobalSettings(sSystemMovedToGlobalSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 178 | // Per user system settings that moved to the per user secure settings. |
| 179 | static final Set<String> sSystemMovedToSecureSettings = new ArraySet<>(); |
| 180 | static { |
| 181 | Settings.System.getMovedToSecureSettings(sSystemMovedToSecureSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 184 | // Per all users global settings that moved to the per user secure settings. |
| 185 | static final Set<String> sGlobalMovedToSecureSettings = new ArraySet<>(); |
| 186 | static { |
| 187 | Settings.Global.getMovedToSecureSettings(sGlobalMovedToSecureSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 190 | // Per user secure settings that are cloned for the managed profiles of the user. |
| 191 | private static final Set<String> sSecureCloneToManagedSettings = new ArraySet<>(); |
| 192 | static { |
| 193 | Settings.Secure.getCloneToManagedProfileSettings(sSecureCloneToManagedSettings); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 196 | // Per user system settings that are cloned for the managed profiles of the user. |
| 197 | private static final Set<String> sSystemCloneToManagedSettings = new ArraySet<>(); |
| 198 | static { |
| 199 | Settings.System.getCloneToManagedProfileSettings(sSystemCloneToManagedSettings); |
Julia Reynolds | 5e458dd | 2014-07-07 16:07:01 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 202 | // Per user system settings that are cloned from the profile's parent when a dependency |
| 203 | // in {@link Settings.Secure} is set to "1". |
| 204 | public static final Map<String, String> sSystemCloneFromParentOnDependency = new ArrayMap<>(); |
| 205 | static { |
| 206 | Settings.System.getCloneFromParentOnValueSettings(sSystemCloneFromParentOnDependency); |
| 207 | } |
| 208 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 209 | private final Object mLock = new Object(); |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 210 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 211 | @GuardedBy("mLock") |
| 212 | private SettingsRegistry mSettingsRegistry; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 213 | |
Svet Ganov | a8f9026 | 2016-05-10 08:44:48 -0700 | [diff] [blame] | 214 | @GuardedBy("mLock") |
| 215 | private HandlerThread mHandlerThread; |
| 216 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 217 | // We have to call in the user manager with no lock held, |
| 218 | private volatile UserManager mUserManager; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 219 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 220 | // We have to call in the package manager with no lock held, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 221 | private volatile IPackageManager mPackageManager; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 222 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 223 | public static int makeKey(int type, int userId) { |
| 224 | return (type << SETTINGS_TYPE_SHIFT) | userId; |
| 225 | } |
| 226 | |
| 227 | public static int getTypeFromKey(int key) { |
| 228 | return key >>> SETTINGS_TYPE_SHIFT; |
| 229 | } |
| 230 | |
| 231 | public static int getUserIdFromKey(int key) { |
| 232 | return key & ~SETTINGS_TYPE_MASK; |
| 233 | } |
| 234 | |
| 235 | public static String settingTypeToString(int type) { |
| 236 | switch (type) { |
| 237 | case SETTINGS_TYPE_GLOBAL: { |
| 238 | return "SETTINGS_GLOBAL"; |
| 239 | } |
| 240 | case SETTINGS_TYPE_SECURE: { |
| 241 | return "SETTINGS_SECURE"; |
| 242 | } |
| 243 | case SETTINGS_TYPE_SYSTEM: { |
| 244 | return "SETTINGS_SYSTEM"; |
| 245 | } |
| 246 | default: { |
| 247 | return "UNKNOWN"; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | public static String keyToString(int key) { |
| 253 | return "Key[user=" + getUserIdFromKey(key) + ";type=" |
| 254 | + settingTypeToString(getTypeFromKey(key)) + "]"; |
| 255 | } |
| 256 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 257 | @Override |
| 258 | public boolean onCreate() { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 259 | synchronized (mLock) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 260 | mUserManager = UserManager.get(getContext()); |
| 261 | mPackageManager = AppGlobals.getPackageManager(); |
Svet Ganov | a8f9026 | 2016-05-10 08:44:48 -0700 | [diff] [blame] | 262 | mHandlerThread = new HandlerThread(LOG_TAG, |
| 263 | Process.THREAD_PRIORITY_BACKGROUND); |
| 264 | mHandlerThread.start(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 265 | mSettingsRegistry = new SettingsRegistry(); |
| 266 | } |
| 267 | registerBroadcastReceivers(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 268 | startWatchingUserRestrictionChanges(); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 269 | ServiceManager.addService("settings", new SettingsService(this)); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 270 | return true; |
| 271 | } |
| 272 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 273 | @Override |
| 274 | public Bundle call(String method, String name, Bundle args) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 275 | final int requestingUserId = getRequestingUserId(args); |
| 276 | switch (method) { |
| 277 | case Settings.CALL_METHOD_GET_GLOBAL: { |
| 278 | Setting setting = getGlobalSetting(name); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 279 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 280 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 281 | |
| 282 | case Settings.CALL_METHOD_GET_SECURE: { |
| 283 | Setting setting = getSecureSetting(name, requestingUserId); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 284 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | case Settings.CALL_METHOD_GET_SYSTEM: { |
| 288 | Setting setting = getSystemSetting(name, requestingUserId); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 289 | return packageValueForCallResult(setting, isTrackingGeneration(args)); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | case Settings.CALL_METHOD_PUT_GLOBAL: { |
| 293 | String value = getSettingValue(args); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 294 | insertGlobalSetting(name, value, requestingUserId, false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 295 | break; |
| 296 | } |
| 297 | |
| 298 | case Settings.CALL_METHOD_PUT_SECURE: { |
| 299 | String value = getSettingValue(args); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 300 | insertSecureSetting(name, value, requestingUserId, false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | |
| 304 | case Settings.CALL_METHOD_PUT_SYSTEM: { |
| 305 | String value = getSettingValue(args); |
| 306 | insertSystemSetting(name, value, requestingUserId); |
| 307 | break; |
| 308 | } |
| 309 | |
| 310 | default: { |
| 311 | Slog.w(LOG_TAG, "call() with invalid method: " + method); |
| 312 | } break; |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 313 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 314 | |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 315 | return null; |
| 316 | } |
| 317 | |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 318 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 319 | public String getType(Uri uri) { |
| 320 | Arguments args = new Arguments(uri, null, null, true); |
| 321 | if (TextUtils.isEmpty(args.name)) { |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 322 | return "vnd.android.cursor.dir/" + args.table; |
| 323 | } else { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 324 | return "vnd.android.cursor.item/" + args.table; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 329 | public Cursor query(Uri uri, String[] projection, String where, String[] whereArgs, |
| 330 | String order) { |
| 331 | if (DEBUG) { |
| 332 | Slog.v(LOG_TAG, "query() for user: " + UserHandle.getCallingUserId()); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 335 | Arguments args = new Arguments(uri, where, whereArgs, true); |
| 336 | String[] normalizedProjection = normalizeProjection(projection); |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 337 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 338 | // If a legacy table that is gone, done. |
| 339 | if (REMOVED_LEGACY_TABLES.contains(args.table)) { |
| 340 | return new MatrixCursor(normalizedProjection, 0); |
| 341 | } |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 342 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 343 | switch (args.table) { |
| 344 | case TABLE_GLOBAL: { |
| 345 | if (args.name != null) { |
| 346 | Setting setting = getGlobalSetting(args.name); |
| 347 | return packageSettingForQuery(setting, normalizedProjection); |
| 348 | } else { |
| 349 | return getAllGlobalSettings(projection); |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 350 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 351 | } |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 352 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 353 | case TABLE_SECURE: { |
| 354 | final int userId = UserHandle.getCallingUserId(); |
| 355 | if (args.name != null) { |
| 356 | Setting setting = getSecureSetting(args.name, userId); |
| 357 | return packageSettingForQuery(setting, normalizedProjection); |
| 358 | } else { |
| 359 | return getAllSecureSettings(userId, projection); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 360 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 361 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 362 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 363 | case TABLE_SYSTEM: { |
| 364 | final int userId = UserHandle.getCallingUserId(); |
| 365 | if (args.name != null) { |
| 366 | Setting setting = getSystemSetting(args.name, userId); |
| 367 | return packageSettingForQuery(setting, normalizedProjection); |
| 368 | } else { |
| 369 | return getAllSystemSettings(userId, projection); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 370 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 371 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 372 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 373 | default: { |
| 374 | throw new IllegalArgumentException("Invalid Uri path:" + uri); |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 377 | } |
| 378 | |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 379 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 380 | public Uri insert(Uri uri, ContentValues values) { |
| 381 | if (DEBUG) { |
| 382 | Slog.v(LOG_TAG, "insert() for user: " + UserHandle.getCallingUserId()); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 385 | String table = getValidTableOrThrow(uri); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 386 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 387 | // If a legacy table that is gone, done. |
| 388 | if (REMOVED_LEGACY_TABLES.contains(table)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | return null; |
| 390 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 391 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 392 | String name = values.getAsString(Settings.Secure.NAME); |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 393 | if (!isKeyValid(name)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 394 | return null; |
Mike Lockwood | bd2a712 | 2009-04-02 23:41:33 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 397 | String value = values.getAsString(Settings.Secure.VALUE); |
| 398 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 399 | switch (table) { |
| 400 | case TABLE_GLOBAL: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 401 | if (insertGlobalSetting(name, value, UserHandle.getCallingUserId(), false)) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 402 | return Uri.withAppendedPath(Settings.Global.CONTENT_URI, name); |
Christopher Tate | c221d2b | 2012-10-03 18:33:52 -0700 | [diff] [blame] | 403 | } |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 404 | } break; |
| 405 | |
| 406 | case TABLE_SECURE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 407 | if (insertSecureSetting(name, value, UserHandle.getCallingUserId(), false)) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 408 | return Uri.withAppendedPath(Settings.Secure.CONTENT_URI, name); |
| 409 | } |
| 410 | } break; |
| 411 | |
| 412 | case TABLE_SYSTEM: { |
| 413 | if (insertSystemSetting(name, value, UserHandle.getCallingUserId())) { |
| 414 | return Uri.withAppendedPath(Settings.System.CONTENT_URI, name); |
| 415 | } |
| 416 | } break; |
| 417 | |
| 418 | default: { |
| 419 | throw new IllegalArgumentException("Bad Uri path:" + uri); |
Christopher Tate | c221d2b | 2012-10-03 18:33:52 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 423 | return null; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 427 | public int bulkInsert(Uri uri, ContentValues[] allValues) { |
| 428 | if (DEBUG) { |
| 429 | Slog.v(LOG_TAG, "bulkInsert() for user: " + UserHandle.getCallingUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 431 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 432 | int insertionCount = 0; |
| 433 | final int valuesCount = allValues.length; |
| 434 | for (int i = 0; i < valuesCount; i++) { |
| 435 | ContentValues values = allValues[i]; |
| 436 | if (insert(uri, values) != null) { |
| 437 | insertionCount++; |
| 438 | } |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 439 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 440 | |
| 441 | return insertionCount; |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Override |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 445 | public int delete(Uri uri, String where, String[] whereArgs) { |
| 446 | if (DEBUG) { |
| 447 | Slog.v(LOG_TAG, "delete() for user: " + UserHandle.getCallingUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 449 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 450 | Arguments args = new Arguments(uri, where, whereArgs, false); |
| 451 | |
| 452 | // If a legacy table that is gone, done. |
| 453 | if (REMOVED_LEGACY_TABLES.contains(args.table)) { |
| 454 | return 0; |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 455 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 456 | |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 457 | if (!isKeyValid(args.name)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 458 | return 0; |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 459 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 460 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 461 | switch (args.table) { |
| 462 | case TABLE_GLOBAL: { |
| 463 | final int userId = UserHandle.getCallingUserId(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 464 | return deleteGlobalSetting(args.name, userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 465 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 466 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 467 | case TABLE_SECURE: { |
| 468 | final int userId = UserHandle.getCallingUserId(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 469 | return deleteSecureSetting(args.name, userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 470 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 471 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 472 | case TABLE_SYSTEM: { |
| 473 | final int userId = UserHandle.getCallingUserId(); |
| 474 | return deleteSystemSetting(args.name, userId) ? 1 : 0; |
| 475 | } |
| 476 | |
| 477 | default: { |
| 478 | throw new IllegalArgumentException("Bad Uri path:" + uri); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 479 | } |
Dianne Hackborn | 8d05172 | 2014-10-01 14:59:58 -0700 | [diff] [blame] | 480 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | @Override |
| 484 | public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { |
| 485 | if (DEBUG) { |
| 486 | Slog.v(LOG_TAG, "update() for user: " + UserHandle.getCallingUserId()); |
Christopher Tate | 06efb53 | 2012-08-24 15:29:27 -0700 | [diff] [blame] | 487 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 488 | |
| 489 | Arguments args = new Arguments(uri, where, whereArgs, false); |
| 490 | |
| 491 | // If a legacy table that is gone, done. |
| 492 | if (REMOVED_LEGACY_TABLES.contains(args.table)) { |
| 493 | return 0; |
| 494 | } |
| 495 | |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 496 | String name = values.getAsString(Settings.Secure.NAME); |
| 497 | if (!isKeyValid(name)) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 498 | return 0; |
| 499 | } |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 500 | String value = values.getAsString(Settings.Secure.VALUE); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 501 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 502 | switch (args.table) { |
| 503 | case TABLE_GLOBAL: { |
| 504 | final int userId = UserHandle.getCallingUserId(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 505 | return updateGlobalSetting(args.name, value, userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 506 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 507 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 508 | case TABLE_SECURE: { |
| 509 | final int userId = UserHandle.getCallingUserId(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 510 | return updateSecureSetting(args.name, value, userId, false) ? 1 : 0; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 511 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 512 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 513 | case TABLE_SYSTEM: { |
| 514 | final int userId = UserHandle.getCallingUserId(); |
| 515 | return updateSystemSetting(args.name, value, userId) ? 1 : 0; |
| 516 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 517 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 518 | default: { |
| 519 | throw new IllegalArgumentException("Invalid Uri path:" + uri); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 520 | } |
| 521 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { |
Robin Lee | 2ab02e2 | 2016-07-28 18:41:23 +0100 | [diff] [blame] | 526 | final int userId = getUserIdFromUri(uri, UserHandle.getCallingUserId()); |
| 527 | if (userId != UserHandle.getCallingUserId()) { |
| 528 | getContext().enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS, |
| 529 | "Access files from the settings of another user"); |
| 530 | } |
| 531 | uri = ContentProvider.getUriWithoutUserId(uri); |
| 532 | |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 533 | final String cacheRingtoneSetting; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 534 | final String cacheName; |
| 535 | if (Settings.System.RINGTONE_CACHE_URI.equals(uri)) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 536 | cacheRingtoneSetting = Settings.System.RINGTONE; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 537 | cacheName = Settings.System.RINGTONE_CACHE; |
| 538 | } else if (Settings.System.NOTIFICATION_SOUND_CACHE_URI.equals(uri)) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 539 | cacheRingtoneSetting = Settings.System.NOTIFICATION_SOUND; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 540 | cacheName = Settings.System.NOTIFICATION_SOUND_CACHE; |
| 541 | } else if (Settings.System.ALARM_ALERT_CACHE_URI.equals(uri)) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 542 | cacheRingtoneSetting = Settings.System.ALARM_ALERT; |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 543 | cacheName = Settings.System.ALARM_ALERT_CACHE; |
| 544 | } else { |
| 545 | throw new FileNotFoundException("Direct file access no longer supported; " |
| 546 | + "ringtone playback is available through android.media.Ringtone"); |
| 547 | } |
| 548 | |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 549 | int actualCacheOwner; |
| 550 | // Redirect cache to parent if ringtone setting is owned by profile parent |
| 551 | synchronized (mLock) { |
| 552 | actualCacheOwner = resolveOwningUserIdForSystemSettingLocked(userId, |
| 553 | cacheRingtoneSetting); |
| 554 | } |
| 555 | final File cacheFile = new File(getRingtoneCacheDir(actualCacheOwner), cacheName); |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 556 | return ParcelFileDescriptor.open(cacheFile, ParcelFileDescriptor.parseMode(mode)); |
| 557 | } |
| 558 | |
| 559 | private File getRingtoneCacheDir(int userId) { |
| 560 | final File cacheDir = new File(Environment.getDataSystemDeDirectory(userId), "ringtones"); |
| 561 | cacheDir.mkdir(); |
| 562 | SELinux.restorecon(cacheDir); |
| 563 | return cacheDir; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 564 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 565 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 566 | public void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) { |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 567 | synchronized (mLock) { |
| 568 | final long identity = Binder.clearCallingIdentity(); |
| 569 | try { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 570 | SparseBooleanArray users = mSettingsRegistry.getKnownUsersLocked(); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 571 | final int userCount = users.size(); |
| 572 | for (int i = 0; i < userCount; i++) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 573 | dumpForUserLocked(users.keyAt(i), pw); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 574 | } |
| 575 | } finally { |
| 576 | Binder.restoreCallingIdentity(identity); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 581 | private void dumpForUserLocked(int userId, PrintWriter pw) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 582 | if (userId == UserHandle.USER_SYSTEM) { |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 583 | pw.println("GLOBAL SETTINGS (user " + userId + ")"); |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 584 | SettingsState globalSettings = mSettingsRegistry.getSettingsLocked( |
| 585 | SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 586 | if (globalSettings != null) { |
| 587 | dumpSettingsLocked(globalSettings, pw); |
| 588 | } |
| 589 | pw.println(); |
| 590 | |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 591 | globalSettings.dumpHistoricalOperations(pw); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | pw.println("SECURE SETTINGS (user " + userId + ")"); |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 595 | SettingsState secureSettings = mSettingsRegistry.getSettingsLocked( |
| 596 | SETTINGS_TYPE_SECURE, userId); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 597 | if (secureSettings != null) { |
| 598 | dumpSettingsLocked(secureSettings, pw); |
| 599 | } |
| 600 | pw.println(); |
| 601 | |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 602 | secureSettings.dumpHistoricalOperations(pw); |
| 603 | |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 604 | pw.println("SYSTEM SETTINGS (user " + userId + ")"); |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 605 | SettingsState systemSettings = mSettingsRegistry.getSettingsLocked( |
| 606 | SETTINGS_TYPE_SYSTEM, userId); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 607 | if (systemSettings != null) { |
| 608 | dumpSettingsLocked(systemSettings, pw); |
| 609 | } |
| 610 | pw.println(); |
| 611 | |
Svetoslav Ganov | a340bfd | 2016-08-02 18:24:49 -0700 | [diff] [blame] | 612 | systemSettings.dumpHistoricalOperations(pw); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 615 | private void dumpSettingsLocked(SettingsState settingsState, PrintWriter pw) { |
| 616 | List<String> names = settingsState.getSettingNamesLocked(); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 617 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 618 | final int nameCount = names.size(); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 619 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 620 | for (int i = 0; i < nameCount; i++) { |
| 621 | String name = names.get(i); |
| 622 | Setting setting = settingsState.getSettingLocked(name); |
| 623 | pw.print("_id:"); pw.print(toDumpString(setting.getId())); |
| 624 | pw.print(" name:"); pw.print(toDumpString(name)); |
| 625 | if (setting.getPackageName() != null) { |
| 626 | pw.print(" pkg:"); pw.print(toDumpString(setting.getPackageName())); |
| 627 | } |
| 628 | pw.print(" value:"); pw.print(toDumpString(setting.getValue())); |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 629 | pw.println(); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 630 | } |
Svetoslav | b505ccc | 2015-02-17 12:41:04 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 633 | private static String toDumpString(String s) { |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 634 | if (s != null) { |
| 635 | return s; |
| 636 | } |
| 637 | return "{null}"; |
| 638 | } |
| 639 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 640 | private void registerBroadcastReceivers() { |
| 641 | IntentFilter userFilter = new IntentFilter(); |
| 642 | userFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 643 | userFilter.addAction(Intent.ACTION_USER_STOPPED); |
| 644 | |
| 645 | getContext().registerReceiver(new BroadcastReceiver() { |
| 646 | @Override |
| 647 | public void onReceive(Context context, Intent intent) { |
| 648 | final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 649 | UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 650 | |
| 651 | switch (intent.getAction()) { |
| 652 | case Intent.ACTION_USER_REMOVED: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 653 | synchronized (mLock) { |
| 654 | mSettingsRegistry.removeUserStateLocked(userId, true); |
| 655 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 656 | } break; |
| 657 | |
| 658 | case Intent.ACTION_USER_STOPPED: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 659 | synchronized (mLock) { |
| 660 | mSettingsRegistry.removeUserStateLocked(userId, false); |
| 661 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 662 | } break; |
| 663 | } |
| 664 | } |
| 665 | }, userFilter); |
| 666 | |
| 667 | PackageMonitor monitor = new PackageMonitor() { |
| 668 | @Override |
| 669 | public void onPackageRemoved(String packageName, int uid) { |
| 670 | synchronized (mLock) { |
| 671 | mSettingsRegistry.onPackageRemovedLocked(packageName, |
| 672 | UserHandle.getUserId(uid)); |
| 673 | } |
| 674 | } |
| 675 | }; |
| 676 | |
| 677 | // package changes |
| 678 | monitor.register(getContext(), BackgroundThread.getHandler().getLooper(), |
| 679 | UserHandle.ALL, true); |
| 680 | } |
| 681 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 682 | private void startWatchingUserRestrictionChanges() { |
| 683 | // TODO: The current design of settings looking different based on user restrictions |
| 684 | // should be reworked to keep them separate and system code should check the setting |
| 685 | // first followed by checking the user restriction before performing an operation. |
| 686 | UserManagerInternal userManager = LocalServices.getService(UserManagerInternal.class); |
| 687 | userManager.addUserRestrictionsListener((int userId, Bundle newRestrictions, |
| 688 | Bundle prevRestrictions) -> { |
| 689 | // We are changing the settings affected by restrictions to their current |
| 690 | // value with a forced update to ensure that all cross profile dependencies |
| 691 | // are taken into account. Also make sure the settings update to.. the same |
| 692 | // value passes the security checks, so clear binder calling id. |
| 693 | if (newRestrictions.containsKey(UserManager.DISALLOW_SHARE_LOCATION) |
| 694 | != prevRestrictions.containsKey(UserManager.DISALLOW_SHARE_LOCATION)) { |
| 695 | final long identity = Binder.clearCallingIdentity(); |
| 696 | try { |
| 697 | synchronized (mLock) { |
| 698 | Setting setting = getSecureSetting( |
| 699 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED, userId); |
| 700 | updateSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, |
| 701 | setting != null ? setting.getValue() : null, userId, true); |
| 702 | } |
| 703 | } finally { |
| 704 | Binder.restoreCallingIdentity(identity); |
| 705 | } |
| 706 | } |
| 707 | if (newRestrictions.containsKey(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) |
| 708 | != prevRestrictions.containsKey(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) { |
| 709 | final long identity = Binder.clearCallingIdentity(); |
| 710 | try { |
| 711 | synchronized (mLock) { |
| 712 | Setting setting = getGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS); |
| 713 | updateGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS, |
| 714 | setting != null ? setting.getValue() : null, userId, true); |
| 715 | } |
| 716 | } finally { |
| 717 | Binder.restoreCallingIdentity(identity); |
| 718 | } |
| 719 | } |
| 720 | if (newRestrictions.containsKey(UserManager.DISALLOW_DEBUGGING_FEATURES) |
| 721 | != prevRestrictions.containsKey(UserManager.DISALLOW_DEBUGGING_FEATURES)) { |
| 722 | final long identity = Binder.clearCallingIdentity(); |
| 723 | try { |
| 724 | synchronized (mLock) { |
| 725 | Setting setting = getGlobalSetting(Settings.Global.ADB_ENABLED); |
| 726 | updateGlobalSetting(Settings.Global.ADB_ENABLED, |
| 727 | setting != null ? setting.getValue() : null, userId, true); |
| 728 | } |
| 729 | } finally { |
| 730 | Binder.restoreCallingIdentity(identity); |
| 731 | } |
| 732 | } |
| 733 | if (newRestrictions.containsKey(UserManager.ENSURE_VERIFY_APPS) |
| 734 | != prevRestrictions.containsKey(UserManager.ENSURE_VERIFY_APPS)) { |
| 735 | final long identity = Binder.clearCallingIdentity(); |
| 736 | try { |
| 737 | synchronized (mLock) { |
| 738 | Setting enable = getGlobalSetting( |
| 739 | Settings.Global.PACKAGE_VERIFIER_ENABLE); |
| 740 | updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_ENABLE, |
| 741 | enable != null ? enable.getValue() : null, userId, true); |
| 742 | Setting include = getGlobalSetting( |
| 743 | Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB); |
| 744 | updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, |
| 745 | include != null ? include.getValue() : null, userId, true); |
| 746 | } |
| 747 | } finally { |
| 748 | Binder.restoreCallingIdentity(identity); |
| 749 | } |
| 750 | } |
| 751 | if (newRestrictions.containsKey(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS) |
| 752 | != prevRestrictions.containsKey(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
| 753 | final long identity = Binder.clearCallingIdentity(); |
| 754 | try { |
| 755 | synchronized (mLock) { |
| 756 | Setting setting = getGlobalSetting( |
| 757 | Settings.Global.PREFERRED_NETWORK_MODE); |
| 758 | updateGlobalSetting(Settings.Global.PREFERRED_NETWORK_MODE, |
| 759 | setting != null ? setting.getValue() : null, userId, true); |
| 760 | } |
| 761 | } finally { |
| 762 | Binder.restoreCallingIdentity(identity); |
| 763 | } |
| 764 | } |
| 765 | }); |
| 766 | } |
| 767 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 768 | private Cursor getAllGlobalSettings(String[] projection) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 769 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 770 | Slog.v(LOG_TAG, "getAllGlobalSettings()"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 771 | } |
| 772 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 773 | synchronized (mLock) { |
| 774 | // Get the settings. |
| 775 | SettingsState settingsState = mSettingsRegistry.getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 776 | SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 777 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 778 | List<String> names = settingsState.getSettingNamesLocked(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 779 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 780 | final int nameCount = names.size(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 781 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 782 | String[] normalizedProjection = normalizeProjection(projection); |
| 783 | MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 784 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 785 | // Anyone can get the global settings, so no security checks. |
| 786 | for (int i = 0; i < nameCount; i++) { |
| 787 | String name = names.get(i); |
| 788 | Setting setting = settingsState.getSettingLocked(name); |
| 789 | appendSettingToCursor(result, setting); |
| 790 | } |
| 791 | |
| 792 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 793 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 796 | private Setting getGlobalSetting(String name) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 797 | if (DEBUG) { |
| 798 | Slog.v(LOG_TAG, "getGlobalSetting(" + name + ")"); |
| 799 | } |
| 800 | |
| 801 | // Get the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 802 | synchronized (mLock) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 803 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_GLOBAL, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 804 | UserHandle.USER_SYSTEM, name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 805 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 808 | private boolean updateGlobalSetting(String name, String value, int requestingUserId, |
| 809 | boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 810 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 811 | Slog.v(LOG_TAG, "updateGlobalSetting(" + name + ", " + value + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 812 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 813 | return mutateGlobalSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE, |
| 814 | forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 817 | private boolean insertGlobalSetting(String name, String value, int requestingUserId, |
| 818 | boolean forceNotify) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 819 | if (DEBUG) { |
| 820 | Slog.v(LOG_TAG, "insertGlobalSetting(" + name + ", " + value + ")"); |
| 821 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 822 | return mutateGlobalSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT, |
| 823 | forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 826 | private boolean deleteGlobalSetting(String name, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 827 | if (DEBUG) { |
| 828 | Slog.v(LOG_TAG, "deleteGlobalSettingLocked(" + name + ")"); |
| 829 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 830 | return mutateGlobalSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE, |
| 831 | forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 834 | private boolean mutateGlobalSetting(String name, String value, int requestingUserId, |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 835 | int operation, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 836 | // Make sure the caller can change the settings - treated as secure. |
| 837 | enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); |
| 838 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 839 | // Resolve the userId on whose behalf the call is made. |
| 840 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 841 | |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 842 | // If this is a setting that is currently restricted for this user, do not allow |
| 843 | // unrestricting changes. |
Victor Chang | 9c7b706 | 2016-07-12 23:47:29 +0100 | [diff] [blame] | 844 | if (isGlobalOrSecureSettingRestrictedForUser(name, callingUserId, value, |
| 845 | Binder.getCallingUid())) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 846 | return false; |
| 847 | } |
| 848 | |
| 849 | // Perform the mutation. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 850 | synchronized (mLock) { |
| 851 | switch (operation) { |
| 852 | case MUTATION_OPERATION_INSERT: { |
| 853 | return mSettingsRegistry |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 854 | .insertSettingLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM, |
| 855 | name, value, getCallingPackage(), forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 856 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 857 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 858 | case MUTATION_OPERATION_DELETE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 859 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_GLOBAL, |
| 860 | UserHandle.USER_SYSTEM, name, forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 861 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 862 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 863 | case MUTATION_OPERATION_UPDATE: { |
| 864 | return mSettingsRegistry |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 865 | .updateSettingLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM, |
| 866 | name, value, getCallingPackage(), forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 867 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
| 871 | return false; |
| 872 | } |
| 873 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 874 | private Cursor getAllSecureSettings(int userId, String[] projection) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 875 | if (DEBUG) { |
| 876 | Slog.v(LOG_TAG, "getAllSecureSettings(" + userId + ")"); |
| 877 | } |
| 878 | |
| 879 | // Resolve the userId on whose behalf the call is made. |
| 880 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 881 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 882 | synchronized (mLock) { |
| 883 | List<String> names = mSettingsRegistry.getSettingsNamesLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 884 | SETTINGS_TYPE_SECURE, callingUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 885 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 886 | final int nameCount = names.size(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 887 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 888 | String[] normalizedProjection = normalizeProjection(projection); |
| 889 | MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 890 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 891 | for (int i = 0; i < nameCount; i++) { |
| 892 | String name = names.get(i); |
| 893 | // Determine the owning user as some profile settings are cloned from the parent. |
| 894 | final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, |
| 895 | name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 896 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 897 | // Special case for location (sigh). |
| 898 | if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) { |
Svetoslav Ganov | 83a1f7f | 2016-04-27 13:50:49 -0700 | [diff] [blame] | 899 | continue; |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 900 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 901 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 902 | Setting setting = mSettingsRegistry.getSettingLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 903 | SETTINGS_TYPE_SECURE, owningUserId, name); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 904 | appendSettingToCursor(result, setting); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 905 | } |
| 906 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 907 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 908 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 909 | } |
| 910 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 911 | private Setting getSecureSetting(String name, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 912 | if (DEBUG) { |
| 913 | Slog.v(LOG_TAG, "getSecureSetting(" + name + ", " + requestingUserId + ")"); |
| 914 | } |
| 915 | |
| 916 | // Resolve the userId on whose behalf the call is made. |
| 917 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 918 | |
| 919 | // Determine the owning user as some profile settings are cloned from the parent. |
| 920 | final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name); |
| 921 | |
| 922 | // Special case for location (sigh). |
| 923 | if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 924 | SettingsState settings = mSettingsRegistry.getSettingsLocked(SETTINGS_TYPE_SECURE, |
| 925 | owningUserId); |
| 926 | return settings != null ? settings.getNullSetting() : null; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | // Get the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 930 | synchronized (mLock) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 931 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SECURE, |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 932 | owningUserId, name); |
| 933 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 934 | } |
| 935 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 936 | private boolean insertSecureSetting(String name, String value, int requestingUserId, |
| 937 | boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 938 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 939 | Slog.v(LOG_TAG, "insertSecureSetting(" + name + ", " + value + ", " |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 940 | + requestingUserId + ")"); |
| 941 | } |
| 942 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 943 | return mutateSecureSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT, |
| 944 | forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 947 | private boolean deleteSecureSetting(String name, int requestingUserId, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 948 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 949 | Slog.v(LOG_TAG, "deleteSecureSetting(" + name + ", " + requestingUserId + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 950 | } |
| 951 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 952 | return mutateSecureSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE, |
| 953 | forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 956 | private boolean updateSecureSetting(String name, String value, int requestingUserId, |
| 957 | boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 958 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 959 | Slog.v(LOG_TAG, "updateSecureSetting(" + name + ", " + value + ", " |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 960 | + requestingUserId + ")"); |
| 961 | } |
| 962 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 963 | return mutateSecureSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE, |
| 964 | forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 965 | } |
| 966 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 967 | private boolean mutateSecureSetting(String name, String value, int requestingUserId, |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 968 | int operation, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 969 | // Make sure the caller can change the settings. |
| 970 | enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); |
| 971 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 972 | // Resolve the userId on whose behalf the call is made. |
| 973 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 974 | |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 975 | // If this is a setting that is currently restricted for this user, do not allow |
| 976 | // unrestricting changes. |
Victor Chang | 9c7b706 | 2016-07-12 23:47:29 +0100 | [diff] [blame] | 977 | if (isGlobalOrSecureSettingRestrictedForUser(name, callingUserId, value, |
| 978 | Binder.getCallingUid())) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 979 | return false; |
| 980 | } |
| 981 | |
| 982 | // Determine the owning user as some profile settings are cloned from the parent. |
| 983 | final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name); |
| 984 | |
| 985 | // Only the owning user can change the setting. |
| 986 | if (owningUserId != callingUserId) { |
| 987 | return false; |
| 988 | } |
| 989 | |
| 990 | // Special cases for location providers (sigh). |
| 991 | if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 992 | return updateLocationProvidersAllowedLocked(value, owningUserId, forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | // Mutate the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 996 | synchronized (mLock) { |
| 997 | switch (operation) { |
| 998 | case MUTATION_OPERATION_INSERT: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 999 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, |
| 1000 | owningUserId, name, value, getCallingPackage(), forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1001 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1002 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1003 | case MUTATION_OPERATION_DELETE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1004 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_SECURE, |
| 1005 | owningUserId, name, forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1006 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1007 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1008 | case MUTATION_OPERATION_UPDATE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1009 | return mSettingsRegistry.updateSettingLocked(SETTINGS_TYPE_SECURE, |
| 1010 | owningUserId, name, value, getCallingPackage(), forceNotify); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1011 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | return false; |
| 1016 | } |
| 1017 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1018 | private Cursor getAllSystemSettings(int userId, String[] projection) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1019 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1020 | Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | // Resolve the userId on whose behalf the call is made. |
| 1024 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId); |
| 1025 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1026 | synchronized (mLock) { |
| 1027 | List<String> names = mSettingsRegistry.getSettingsNamesLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1028 | SETTINGS_TYPE_SYSTEM, callingUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1029 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1030 | final int nameCount = names.size(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1031 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1032 | String[] normalizedProjection = normalizeProjection(projection); |
| 1033 | MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1034 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1035 | for (int i = 0; i < nameCount; i++) { |
| 1036 | String name = names.get(i); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1037 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1038 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1039 | final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, |
| 1040 | name); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1041 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1042 | Setting setting = mSettingsRegistry.getSettingLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1043 | SETTINGS_TYPE_SYSTEM, owningUserId, name); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1044 | appendSettingToCursor(result, setting); |
| 1045 | } |
| 1046 | |
| 1047 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1048 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1051 | private Setting getSystemSetting(String name, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1052 | if (DEBUG) { |
| 1053 | Slog.v(LOG_TAG, "getSystemSetting(" + name + ", " + requestingUserId + ")"); |
| 1054 | } |
| 1055 | |
| 1056 | // Resolve the userId on whose behalf the call is made. |
| 1057 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); |
| 1058 | |
| 1059 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1060 | final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name); |
| 1061 | |
| 1062 | // Get the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1063 | synchronized (mLock) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1064 | return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SYSTEM, owningUserId, name); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1065 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1068 | private boolean insertSystemSetting(String name, String value, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1069 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1070 | Slog.v(LOG_TAG, "insertSystemSetting(" + name + ", " + value + ", " |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1071 | + requestingUserId + ")"); |
| 1072 | } |
| 1073 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1074 | return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1077 | private boolean deleteSystemSetting(String name, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1078 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1079 | Slog.v(LOG_TAG, "deleteSystemSetting(" + name + ", " + requestingUserId + ")"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1082 | return mutateSystemSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1085 | private boolean updateSystemSetting(String name, String value, int requestingUserId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1086 | if (DEBUG) { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1087 | Slog.v(LOG_TAG, "updateSystemSetting(" + name + ", " + value + ", " |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1088 | + requestingUserId + ")"); |
| 1089 | } |
| 1090 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1091 | return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1092 | } |
| 1093 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1094 | private boolean mutateSystemSetting(String name, String value, int runAsUserId, |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1095 | int operation) { |
Billy Lau | 6ad2d66 | 2015-07-18 00:26:58 +0100 | [diff] [blame] | 1096 | if (!hasWriteSecureSettingsPermission()) { |
| 1097 | // If the caller doesn't hold WRITE_SECURE_SETTINGS, we verify whether this |
| 1098 | // operation is allowed for the calling package through appops. |
| 1099 | if (!Settings.checkAndNoteWriteSettingsOperation(getContext(), |
| 1100 | Binder.getCallingUid(), getCallingPackage(), true)) { |
| 1101 | return false; |
| 1102 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1103 | } |
| 1104 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1105 | // Resolve the userId on whose behalf the call is made. |
| 1106 | final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(runAsUserId); |
| 1107 | |
Svetoslav | d8d25e0 | 2015-11-20 13:09:26 -0800 | [diff] [blame] | 1108 | // Enforce what the calling package can mutate the system settings. |
| 1109 | enforceRestrictedSystemSettingsMutationForCallingPackage(operation, name, callingUserId); |
| 1110 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1111 | // Determine the owning user as some profile settings are cloned from the parent. |
| 1112 | final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name); |
| 1113 | |
| 1114 | // Only the owning user id can change the setting. |
| 1115 | if (owningUserId != callingUserId) { |
| 1116 | return false; |
| 1117 | } |
| 1118 | |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 1119 | // Invalidate any relevant cache files |
| 1120 | String cacheName = null; |
| 1121 | if (Settings.System.RINGTONE.equals(name)) { |
| 1122 | cacheName = Settings.System.RINGTONE_CACHE; |
| 1123 | } else if (Settings.System.NOTIFICATION_SOUND.equals(name)) { |
| 1124 | cacheName = Settings.System.NOTIFICATION_SOUND_CACHE; |
| 1125 | } else if (Settings.System.ALARM_ALERT.equals(name)) { |
| 1126 | cacheName = Settings.System.ALARM_ALERT_CACHE; |
| 1127 | } |
| 1128 | if (cacheName != null) { |
| 1129 | final File cacheFile = new File( |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 1130 | getRingtoneCacheDir(owningUserId), cacheName); |
Jeff Sharkey | 413573a | 2016-02-22 17:52:45 -0700 | [diff] [blame] | 1131 | cacheFile.delete(); |
| 1132 | } |
| 1133 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1134 | // Mutate the value. |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1135 | synchronized (mLock) { |
| 1136 | switch (operation) { |
| 1137 | case MUTATION_OPERATION_INSERT: { |
| 1138 | validateSystemSettingValue(name, value); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1139 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SYSTEM, |
| 1140 | owningUserId, name, value, getCallingPackage(), false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | case MUTATION_OPERATION_DELETE: { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1144 | return mSettingsRegistry.deleteSettingLocked(SETTINGS_TYPE_SYSTEM, |
| 1145 | owningUserId, name, false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | case MUTATION_OPERATION_UPDATE: { |
| 1149 | validateSystemSettingValue(name, value); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1150 | return mSettingsRegistry.updateSettingLocked(SETTINGS_TYPE_SYSTEM, |
| 1151 | owningUserId, name, value, getCallingPackage(), false); |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1152 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1155 | return false; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1156 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
Billy Lau | 6ad2d66 | 2015-07-18 00:26:58 +0100 | [diff] [blame] | 1159 | private boolean hasWriteSecureSettingsPermission() { |
Svetoslav | f41334b | 2015-06-23 12:06:03 -0700 | [diff] [blame] | 1160 | // Write secure settings is a more protected permission. If caller has it we are good. |
| 1161 | if (getContext().checkCallingOrSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1162 | == PackageManager.PERMISSION_GRANTED) { |
| 1163 | return true; |
| 1164 | } |
| 1165 | |
Svetoslav | f41334b | 2015-06-23 12:06:03 -0700 | [diff] [blame] | 1166 | return false; |
| 1167 | } |
| 1168 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1169 | private void validateSystemSettingValue(String name, String value) { |
| 1170 | Settings.System.Validator validator = Settings.System.VALIDATORS.get(name); |
| 1171 | if (validator != null && !validator.validate(value)) { |
| 1172 | throw new IllegalArgumentException("Invalid value: " + value |
| 1173 | + " for setting: " + name); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | private boolean isLocationProvidersAllowedRestricted(String name, int callingUserId, |
| 1178 | int owningUserId) { |
| 1179 | // Optimization - location providers are restricted only for managed profiles. |
| 1180 | if (callingUserId == owningUserId) { |
| 1181 | return false; |
| 1182 | } |
| 1183 | if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name) |
| 1184 | && mUserManager.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, |
| 1185 | new UserHandle(callingUserId))) { |
| 1186 | return true; |
| 1187 | } |
| 1188 | return false; |
| 1189 | } |
| 1190 | |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1191 | /** |
| 1192 | * Checks whether changing a setting to a value is prohibited by the corresponding user |
| 1193 | * restriction. |
| 1194 | * |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1195 | * <p>See also {@link com.android.server.pm.UserRestrictionsUtils#applyUserRestriction( |
| 1196 | * Context, int, String, boolean)}, which should be in sync with this method. |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1197 | * |
| 1198 | * @return true if the change is prohibited, false if the change is allowed. |
| 1199 | */ |
| 1200 | private boolean isGlobalOrSecureSettingRestrictedForUser(String setting, int userId, |
Victor Chang | 9c7b706 | 2016-07-12 23:47:29 +0100 | [diff] [blame] | 1201 | String value, int callingUid) { |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1202 | String restriction; |
| 1203 | switch (setting) { |
| 1204 | case Settings.Secure.LOCATION_MODE: |
| 1205 | // Note LOCATION_MODE will be converted into LOCATION_PROVIDERS_ALLOWED |
| 1206 | // in android.provider.Settings.Secure.putStringForUser(), so we shouldn't come |
| 1207 | // here normally, but we still protect it here from a direct provider write. |
| 1208 | if (String.valueOf(Settings.Secure.LOCATION_MODE_OFF).equals(value)) return false; |
| 1209 | restriction = UserManager.DISALLOW_SHARE_LOCATION; |
| 1210 | break; |
| 1211 | |
| 1212 | case Settings.Secure.LOCATION_PROVIDERS_ALLOWED: |
| 1213 | // See SettingsProvider.updateLocationProvidersAllowedLocked. "-" is to disable |
| 1214 | // a provider, which should be allowed even if the user restriction is set. |
| 1215 | if (value != null && value.startsWith("-")) return false; |
| 1216 | restriction = UserManager.DISALLOW_SHARE_LOCATION; |
| 1217 | break; |
| 1218 | |
| 1219 | case Settings.Secure.INSTALL_NON_MARKET_APPS: |
| 1220 | if ("0".equals(value)) return false; |
| 1221 | restriction = UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES; |
| 1222 | break; |
| 1223 | |
| 1224 | case Settings.Global.ADB_ENABLED: |
| 1225 | if ("0".equals(value)) return false; |
| 1226 | restriction = UserManager.DISALLOW_DEBUGGING_FEATURES; |
| 1227 | break; |
| 1228 | |
| 1229 | case Settings.Global.PACKAGE_VERIFIER_ENABLE: |
| 1230 | case Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB: |
| 1231 | if ("1".equals(value)) return false; |
| 1232 | restriction = UserManager.ENSURE_VERIFY_APPS; |
| 1233 | break; |
| 1234 | |
| 1235 | case Settings.Global.PREFERRED_NETWORK_MODE: |
| 1236 | restriction = UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS; |
| 1237 | break; |
| 1238 | |
Victor Chang | 9c7b706 | 2016-07-12 23:47:29 +0100 | [diff] [blame] | 1239 | case Settings.Secure.ALWAYS_ON_VPN_APP: |
| 1240 | case Settings.Secure.ALWAYS_ON_VPN_LOCKDOWN: |
| 1241 | // Whitelist system uid (ConnectivityService) and root uid to change always-on vpn |
| 1242 | if (callingUid == Process.SYSTEM_UID || callingUid == Process.ROOT_UID) { |
| 1243 | return false; |
| 1244 | } |
| 1245 | restriction = UserManager.DISALLOW_CONFIG_VPN; |
| 1246 | break; |
| 1247 | |
Benjamin Franz | 0ff13fc | 2016-07-12 13:42:21 +0100 | [diff] [blame] | 1248 | case Settings.Global.SAFE_BOOT_DISALLOWED: |
| 1249 | if ("1".equals(value)) return false; |
| 1250 | restriction = UserManager.DISALLOW_SAFE_BOOT; |
| 1251 | break; |
| 1252 | |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1253 | default: |
Mahaver Chopra | 8764875 | 2016-01-08 19:23:57 +0000 | [diff] [blame] | 1254 | if (setting != null && setting.startsWith(Settings.Global.DATA_ROAMING)) { |
Mahaver Chopra | dea471e | 2015-12-17 11:02:37 +0000 | [diff] [blame] | 1255 | if ("0".equals(value)) return false; |
| 1256 | restriction = UserManager.DISALLOW_DATA_ROAMING; |
| 1257 | break; |
| 1258 | } |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1259 | return false; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1260 | } |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1261 | |
| 1262 | return mUserManager.hasUserRestriction(restriction, UserHandle.of(userId)); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | private int resolveOwningUserIdForSecureSettingLocked(int userId, String setting) { |
| 1266 | return resolveOwningUserIdLocked(userId, sSecureCloneToManagedSettings, setting); |
| 1267 | } |
| 1268 | |
| 1269 | private int resolveOwningUserIdForSystemSettingLocked(int userId, String setting) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 1270 | final int parentId; |
| 1271 | // Resolves dependency if setting has a dependency and the calling user has a parent |
| 1272 | if (sSystemCloneFromParentOnDependency.containsKey(setting) |
| 1273 | && (parentId = getGroupParentLocked(userId)) != userId) { |
| 1274 | // The setting has a dependency and the profile has a parent |
| 1275 | String dependency = sSystemCloneFromParentOnDependency.get(setting); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1276 | Setting settingObj = getSecureSetting(dependency, userId); |
| 1277 | if (settingObj != null && settingObj.getValue().equals("1")) { |
Andre Lago | 3fa139c | 2016-08-04 13:53:44 +0100 | [diff] [blame] | 1278 | return parentId; |
| 1279 | } |
| 1280 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1281 | return resolveOwningUserIdLocked(userId, sSystemCloneToManagedSettings, setting); |
| 1282 | } |
| 1283 | |
| 1284 | private int resolveOwningUserIdLocked(int userId, Set<String> keys, String name) { |
| 1285 | final int parentId = getGroupParentLocked(userId); |
| 1286 | if (parentId != userId && keys.contains(name)) { |
| 1287 | return parentId; |
| 1288 | } |
| 1289 | return userId; |
| 1290 | } |
| 1291 | |
Svetoslav | f41334b | 2015-06-23 12:06:03 -0700 | [diff] [blame] | 1292 | private void enforceRestrictedSystemSettingsMutationForCallingPackage(int operation, |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1293 | String name, int userId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1294 | // System/root/shell can mutate whatever secure settings they want. |
| 1295 | final int callingUid = Binder.getCallingUid(); |
| 1296 | if (callingUid == android.os.Process.SYSTEM_UID |
| 1297 | || callingUid == Process.SHELL_UID |
| 1298 | || callingUid == Process.ROOT_UID) { |
| 1299 | return; |
| 1300 | } |
| 1301 | |
| 1302 | switch (operation) { |
| 1303 | case MUTATION_OPERATION_INSERT: |
| 1304 | // Insert updates. |
| 1305 | case MUTATION_OPERATION_UPDATE: { |
| 1306 | if (Settings.System.PUBLIC_SETTINGS.contains(name)) { |
| 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | // The calling package is already verified. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1311 | PackageInfo packageInfo = getCallingPackageInfoOrThrow(userId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1312 | |
| 1313 | // Privileged apps can do whatever they want. |
| 1314 | if ((packageInfo.applicationInfo.privateFlags |
| 1315 | & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) { |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk( |
| 1320 | packageInfo.applicationInfo.targetSdkVersion, name); |
| 1321 | } break; |
| 1322 | |
| 1323 | case MUTATION_OPERATION_DELETE: { |
| 1324 | if (Settings.System.PUBLIC_SETTINGS.contains(name) |
| 1325 | || Settings.System.PRIVATE_SETTINGS.contains(name)) { |
| 1326 | throw new IllegalArgumentException("You cannot delete system defined" |
| 1327 | + " secure settings."); |
| 1328 | } |
| 1329 | |
| 1330 | // The calling package is already verified. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1331 | PackageInfo packageInfo = getCallingPackageInfoOrThrow(userId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1332 | |
| 1333 | // Privileged apps can do whatever they want. |
| 1334 | if ((packageInfo.applicationInfo.privateFlags & |
| 1335 | ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) { |
| 1336 | return; |
| 1337 | } |
| 1338 | |
| 1339 | warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk( |
| 1340 | packageInfo.applicationInfo.targetSdkVersion, name); |
| 1341 | } break; |
| 1342 | } |
| 1343 | } |
| 1344 | |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1345 | private PackageInfo getCallingPackageInfoOrThrow(int userId) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1346 | try { |
Svetoslav Ganov | 67a8d35 | 2016-03-02 13:26:40 -0800 | [diff] [blame] | 1347 | PackageInfo packageInfo = mPackageManager.getPackageInfo( |
| 1348 | getCallingPackage(), 0, userId); |
| 1349 | if (packageInfo != null) { |
| 1350 | return packageInfo; |
| 1351 | } |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1352 | } catch (RemoteException e) { |
Svetoslav Ganov | 67a8d35 | 2016-03-02 13:26:40 -0800 | [diff] [blame] | 1353 | /* ignore */ |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1354 | } |
Svetoslav Ganov | 67a8d35 | 2016-03-02 13:26:40 -0800 | [diff] [blame] | 1355 | throw new IllegalStateException("Calling package doesn't exist"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | private int getGroupParentLocked(int userId) { |
| 1359 | // Most frequent use case. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1360 | if (userId == UserHandle.USER_SYSTEM) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1361 | return userId; |
| 1362 | } |
| 1363 | // We are in the same process with the user manager and the returned |
| 1364 | // user info is a cached instance, so just look up instead of cache. |
| 1365 | final long identity = Binder.clearCallingIdentity(); |
| 1366 | try { |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1367 | // Just a lookup and not reentrant, so holding a lock is fine. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1368 | UserInfo userInfo = mUserManager.getProfileParent(userId); |
| 1369 | return (userInfo != null) ? userInfo.id : userId; |
| 1370 | } finally { |
| 1371 | Binder.restoreCallingIdentity(identity); |
| 1372 | } |
| 1373 | } |
| 1374 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1375 | private void enforceWritePermission(String permission) { |
| 1376 | if (getContext().checkCallingOrSelfPermission(permission) |
| 1377 | != PackageManager.PERMISSION_GRANTED) { |
| 1378 | throw new SecurityException("Permission denial: writing to settings requires:" |
| 1379 | + permission); |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | /* |
| 1384 | * Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED. |
| 1385 | * This setting contains a list of the currently enabled location providers. |
| 1386 | * But helper functions in android.providers.Settings can enable or disable |
| 1387 | * a single provider by using a "+" or "-" prefix before the provider name. |
| 1388 | * |
Makoto Onuki | 28da2e3 | 2015-11-20 11:30:44 -0800 | [diff] [blame] | 1389 | * <p>See also {@link #isGlobalOrSecureSettingRestrictedForUser()}. If DISALLOW_SHARE_LOCATION |
| 1390 | * is set, the said method will only allow values with the "-" prefix. |
| 1391 | * |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1392 | * @returns whether the enabled location providers changed. |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1393 | */ |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1394 | private boolean updateLocationProvidersAllowedLocked(String value, int owningUserId, |
| 1395 | boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1396 | if (TextUtils.isEmpty(value)) { |
| 1397 | return false; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1400 | final char prefix = value.charAt(0); |
| 1401 | if (prefix != '+' && prefix != '-') { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1402 | if (forceNotify) { |
| 1403 | final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId); |
| 1404 | mSettingsRegistry.notifyForSettingsChange(key, |
| 1405 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED); |
| 1406 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1407 | return false; |
| 1408 | } |
| 1409 | |
| 1410 | // skip prefix |
| 1411 | value = value.substring(1); |
| 1412 | |
Svetoslav | 7ec28e8 | 2015-05-20 17:01:10 -0700 | [diff] [blame] | 1413 | Setting settingValue = getSecureSetting( |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1414 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED, owningUserId); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1415 | if (settingValue == null) { |
| 1416 | return false; |
| 1417 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1418 | |
| 1419 | String oldProviders = (settingValue != null) ? settingValue.getValue() : ""; |
| 1420 | |
| 1421 | int index = oldProviders.indexOf(value); |
| 1422 | int end = index + value.length(); |
| 1423 | |
| 1424 | // check for commas to avoid matching on partial string |
| 1425 | if (index > 0 && oldProviders.charAt(index - 1) != ',') { |
| 1426 | index = -1; |
| 1427 | } |
| 1428 | |
| 1429 | // check for commas to avoid matching on partial string |
| 1430 | if (end < oldProviders.length() && oldProviders.charAt(end) != ',') { |
| 1431 | index = -1; |
| 1432 | } |
| 1433 | |
| 1434 | String newProviders; |
| 1435 | |
| 1436 | if (prefix == '+' && index < 0) { |
| 1437 | // append the provider to the list if not present |
| 1438 | if (oldProviders.length() == 0) { |
| 1439 | newProviders = value; |
| 1440 | } else { |
| 1441 | newProviders = oldProviders + ',' + value; |
| 1442 | } |
| 1443 | } else if (prefix == '-' && index >= 0) { |
| 1444 | // remove the provider from the list if present |
| 1445 | // remove leading or trailing comma |
| 1446 | if (index > 0) { |
| 1447 | index--; |
| 1448 | } else if (end < oldProviders.length()) { |
| 1449 | end++; |
| 1450 | } |
| 1451 | |
| 1452 | newProviders = oldProviders.substring(0, index); |
| 1453 | if (end < oldProviders.length()) { |
| 1454 | newProviders += oldProviders.substring(end); |
| 1455 | } |
| 1456 | } else { |
| 1457 | // nothing changed, so no need to update the database |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1458 | if (forceNotify) { |
| 1459 | final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId); |
| 1460 | mSettingsRegistry.notifyForSettingsChange(key, |
| 1461 | Settings.Secure.LOCATION_PROVIDERS_ALLOWED); |
| 1462 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1463 | return false; |
| 1464 | } |
| 1465 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1466 | return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, |
Svetoslav | b596a2c | 2015-02-17 21:37:09 -0800 | [diff] [blame] | 1467 | owningUserId, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, newProviders, |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1468 | getCallingPackage(), forceNotify); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1469 | } |
| 1470 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1471 | private static void warnOrThrowForUndesiredSecureSettingsMutationForTargetSdk( |
| 1472 | int targetSdkVersion, String name) { |
| 1473 | // If the app targets Lollipop MR1 or older SDK we warn, otherwise crash. |
| 1474 | if (targetSdkVersion <= Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 1475 | if (Settings.System.PRIVATE_SETTINGS.contains(name)) { |
| 1476 | Slog.w(LOG_TAG, "You shouldn't not change private system settings." |
| 1477 | + " This will soon become an error."); |
| 1478 | } else { |
| 1479 | Slog.w(LOG_TAG, "You shouldn't keep your settings in the secure settings." |
| 1480 | + " This will soon become an error."); |
| 1481 | } |
| 1482 | } else { |
| 1483 | if (Settings.System.PRIVATE_SETTINGS.contains(name)) { |
| 1484 | throw new IllegalArgumentException("You cannot change private secure settings."); |
| 1485 | } else { |
| 1486 | throw new IllegalArgumentException("You cannot keep your settings in" |
| 1487 | + " the secure settings."); |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | private static int resolveCallingUserIdEnforcingPermissionsLocked(int requestingUserId) { |
| 1493 | if (requestingUserId == UserHandle.getCallingUserId()) { |
| 1494 | return requestingUserId; |
| 1495 | } |
| 1496 | return ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 1497 | Binder.getCallingUid(), requestingUserId, false, true, |
| 1498 | "get/set setting for user", null); |
| 1499 | } |
| 1500 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1501 | private Bundle packageValueForCallResult(Setting setting, |
| 1502 | boolean trackingGeneration) { |
| 1503 | if (!trackingGeneration) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1504 | if (setting == null || setting.isNull()) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1505 | return NULL_SETTING_BUNDLE; |
| 1506 | } |
| 1507 | return Bundle.forPair(Settings.NameValueTable.VALUE, setting.getValue()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1508 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1509 | Bundle result = new Bundle(); |
| 1510 | result.putString(Settings.NameValueTable.VALUE, |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1511 | setting != null && !setting.isNull() ? setting.getValue() : null); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1512 | mSettingsRegistry.mGenerationRegistry.addGenerationData(result, setting.getkey()); |
| 1513 | return result; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | private static int getRequestingUserId(Bundle args) { |
| 1517 | final int callingUserId = UserHandle.getCallingUserId(); |
| 1518 | return (args != null) ? args.getInt(Settings.CALL_METHOD_USER_KEY, callingUserId) |
| 1519 | : callingUserId; |
| 1520 | } |
| 1521 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1522 | private boolean isTrackingGeneration(Bundle args) { |
| 1523 | return args != null && args.containsKey(Settings.CALL_METHOD_TRACK_GENERATION_KEY); |
| 1524 | } |
| 1525 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1526 | private static String getSettingValue(Bundle args) { |
| 1527 | return (args != null) ? args.getString(Settings.NameValueTable.VALUE) : null; |
| 1528 | } |
| 1529 | |
| 1530 | private static String getValidTableOrThrow(Uri uri) { |
| 1531 | if (uri.getPathSegments().size() > 0) { |
| 1532 | String table = uri.getPathSegments().get(0); |
| 1533 | if (DatabaseHelper.isValidTable(table)) { |
| 1534 | return table; |
| 1535 | } |
| 1536 | throw new IllegalArgumentException("Bad root path: " + table); |
| 1537 | } |
| 1538 | throw new IllegalArgumentException("Invalid URI:" + uri); |
| 1539 | } |
| 1540 | |
| 1541 | private static MatrixCursor packageSettingForQuery(Setting setting, String[] projection) { |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 1542 | if (setting.isNull()) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1543 | return new MatrixCursor(projection, 0); |
| 1544 | } |
| 1545 | MatrixCursor cursor = new MatrixCursor(projection, 1); |
| 1546 | appendSettingToCursor(cursor, setting); |
| 1547 | return cursor; |
| 1548 | } |
| 1549 | |
| 1550 | private static String[] normalizeProjection(String[] projection) { |
| 1551 | if (projection == null) { |
| 1552 | return ALL_COLUMNS; |
| 1553 | } |
| 1554 | |
| 1555 | final int columnCount = projection.length; |
| 1556 | for (int i = 0; i < columnCount; i++) { |
| 1557 | String column = projection[i]; |
| 1558 | if (!ArrayUtils.contains(ALL_COLUMNS, column)) { |
| 1559 | throw new IllegalArgumentException("Invalid column: " + column); |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 1560 | } |
| 1561 | } |
| 1562 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1563 | return projection; |
| 1564 | } |
| 1565 | |
| 1566 | private static void appendSettingToCursor(MatrixCursor cursor, Setting setting) { |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1567 | if (setting == null || setting.isNull()) { |
Suprabh Shukla | c9d064a | 2016-04-12 18:45:34 -0700 | [diff] [blame] | 1568 | return; |
| 1569 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1570 | final int columnCount = cursor.getColumnCount(); |
| 1571 | |
| 1572 | String[] values = new String[columnCount]; |
| 1573 | |
| 1574 | for (int i = 0; i < columnCount; i++) { |
| 1575 | String column = cursor.getColumnName(i); |
| 1576 | |
| 1577 | switch (column) { |
| 1578 | case Settings.NameValueTable._ID: { |
| 1579 | values[i] = setting.getId(); |
| 1580 | } break; |
| 1581 | |
| 1582 | case Settings.NameValueTable.NAME: { |
| 1583 | values[i] = setting.getName(); |
| 1584 | } break; |
| 1585 | |
| 1586 | case Settings.NameValueTable.VALUE: { |
| 1587 | values[i] = setting.getValue(); |
| 1588 | } break; |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 1589 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1590 | } |
| 1591 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1592 | cursor.addRow(values); |
| 1593 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1594 | |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 1595 | private static boolean isKeyValid(String key) { |
| 1596 | return !(TextUtils.isEmpty(key) || SettingsState.isBinary(key)); |
| 1597 | } |
| 1598 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1599 | private static final class Arguments { |
| 1600 | private static final Pattern WHERE_PATTERN_WITH_PARAM_NO_BRACKETS = |
| 1601 | Pattern.compile("[\\s]*name[\\s]*=[\\s]*\\?[\\s]*"); |
| 1602 | |
| 1603 | private static final Pattern WHERE_PATTERN_WITH_PARAM_IN_BRACKETS = |
| 1604 | Pattern.compile("[\\s]*\\([\\s]*name[\\s]*=[\\s]*\\?[\\s]*\\)[\\s]*"); |
| 1605 | |
| 1606 | private static final Pattern WHERE_PATTERN_NO_PARAM_IN_BRACKETS = |
| 1607 | Pattern.compile("[\\s]*\\([\\s]*name[\\s]*=[\\s]*['\"].*['\"][\\s]*\\)[\\s]*"); |
| 1608 | |
| 1609 | private static final Pattern WHERE_PATTERN_NO_PARAM_NO_BRACKETS = |
| 1610 | Pattern.compile("[\\s]*name[\\s]*=[\\s]*['\"].*['\"][\\s]*"); |
| 1611 | |
| 1612 | public final String table; |
| 1613 | public final String name; |
| 1614 | |
| 1615 | public Arguments(Uri uri, String where, String[] whereArgs, boolean supportAll) { |
| 1616 | final int segmentSize = uri.getPathSegments().size(); |
| 1617 | switch (segmentSize) { |
| 1618 | case 1: { |
| 1619 | if (where != null |
| 1620 | && (WHERE_PATTERN_WITH_PARAM_NO_BRACKETS.matcher(where).matches() |
| 1621 | || WHERE_PATTERN_WITH_PARAM_IN_BRACKETS.matcher(where).matches()) |
| 1622 | && whereArgs.length == 1) { |
| 1623 | name = whereArgs[0]; |
| 1624 | table = computeTableForSetting(uri, name); |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 1625 | return; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1626 | } else if (where != null |
| 1627 | && (WHERE_PATTERN_NO_PARAM_NO_BRACKETS.matcher(where).matches() |
| 1628 | || WHERE_PATTERN_NO_PARAM_IN_BRACKETS.matcher(where).matches())) { |
| 1629 | final int startIndex = Math.max(where.indexOf("'"), |
| 1630 | where.indexOf("\"")) + 1; |
| 1631 | final int endIndex = Math.max(where.lastIndexOf("'"), |
| 1632 | where.lastIndexOf("\"")); |
| 1633 | name = where.substring(startIndex, endIndex); |
| 1634 | table = computeTableForSetting(uri, name); |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 1635 | return; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1636 | } else if (supportAll && where == null && whereArgs == null) { |
| 1637 | name = null; |
| 1638 | table = computeTableForSetting(uri, null); |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 1639 | return; |
Brad Fitzpatrick | 342984a | 2010-03-09 16:59:30 -0800 | [diff] [blame] | 1640 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1641 | } break; |
| 1642 | |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 1643 | case 2: { |
| 1644 | if (where == null && whereArgs == null) { |
| 1645 | name = uri.getPathSegments().get(1); |
| 1646 | table = computeTableForSetting(uri, name); |
| 1647 | return; |
| 1648 | } |
| 1649 | } break; |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1650 | } |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 1651 | |
| 1652 | EventLogTags.writeUnsupportedSettingsQuery( |
| 1653 | uri.toSafeString(), where, Arrays.toString(whereArgs)); |
| 1654 | String message = String.format( "Supported SQL:\n" |
| 1655 | + " uri content://some_table/some_property with null where and where args\n" |
| 1656 | + " uri content://some_table with query name=? and single name as arg\n" |
| 1657 | + " uri content://some_table with query name=some_name and null args\n" |
| 1658 | + " but got - uri:%1s, where:%2s whereArgs:%3s", uri, where, |
| 1659 | Arrays.toString(whereArgs)); |
| 1660 | throw new IllegalArgumentException(message); |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1661 | } |
| 1662 | |
Svetoslav | 2849465 | 2015-02-12 14:11:42 -0800 | [diff] [blame] | 1663 | private static String computeTableForSetting(Uri uri, String name) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1664 | String table = getValidTableOrThrow(uri); |
| 1665 | |
| 1666 | if (name != null) { |
| 1667 | if (sSystemMovedToSecureSettings.contains(name)) { |
| 1668 | table = TABLE_SECURE; |
| 1669 | } |
| 1670 | |
| 1671 | if (sSystemMovedToGlobalSettings.contains(name)) { |
| 1672 | table = TABLE_GLOBAL; |
| 1673 | } |
| 1674 | |
| 1675 | if (sSecureMovedToGlobalSettings.contains(name)) { |
| 1676 | table = TABLE_GLOBAL; |
| 1677 | } |
| 1678 | |
| 1679 | if (sGlobalMovedToSecureSettings.contains(name)) { |
| 1680 | table = TABLE_SECURE; |
| 1681 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1682 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1683 | |
| 1684 | return table; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | final class SettingsRegistry { |
| 1689 | private static final String DROPBOX_TAG_USERLOG = "restricted_profile_ssaid"; |
| 1690 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1691 | private static final String SETTINGS_FILE_GLOBAL = "settings_global.xml"; |
| 1692 | private static final String SETTINGS_FILE_SYSTEM = "settings_system.xml"; |
| 1693 | private static final String SETTINGS_FILE_SECURE = "settings_secure.xml"; |
| 1694 | |
| 1695 | private final SparseArray<SettingsState> mSettingsStates = new SparseArray<>(); |
| 1696 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1697 | private GenerationRegistry mGenerationRegistry; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1698 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 1699 | private final Handler mHandler; |
| 1700 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1701 | private final BackupManager mBackupManager; |
| 1702 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1703 | public SettingsRegistry() { |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 1704 | mHandler = new MyHandler(getContext().getMainLooper()); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1705 | mGenerationRegistry = new GenerationRegistry(mLock); |
| 1706 | mBackupManager = new BackupManager(getContext()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1707 | migrateAllLegacySettingsIfNeeded(); |
Brad Fitzpatrick | f366a9b | 2010-08-24 16:14:07 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1710 | public List<String> getSettingsNamesLocked(int type, int userId) { |
| 1711 | final int key = makeKey(type, userId); |
| 1712 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1713 | if (settingsState == null) { |
| 1714 | return new ArrayList<String>(); |
| 1715 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1716 | return settingsState.getSettingNamesLocked(); |
| 1717 | } |
| 1718 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1719 | public SparseBooleanArray getKnownUsersLocked() { |
| 1720 | SparseBooleanArray users = new SparseBooleanArray(); |
| 1721 | for (int i = mSettingsStates.size()-1; i >= 0; i--) { |
| 1722 | users.put(getUserIdFromKey(mSettingsStates.keyAt(i)), true); |
| 1723 | } |
| 1724 | return users; |
| 1725 | } |
| 1726 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1727 | public SettingsState getSettingsLocked(int type, int userId) { |
| 1728 | final int key = makeKey(type, userId); |
| 1729 | return peekSettingsStateLocked(key); |
| 1730 | } |
| 1731 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1732 | public boolean ensureSettingsForUserLocked(int userId) { |
| 1733 | // First make sure this user actually exists. |
| 1734 | if (mUserManager.getUserInfo(userId) == null) { |
| 1735 | Slog.wtf(LOG_TAG, "Requested user " + userId + " does not exist"); |
| 1736 | return false; |
| 1737 | } |
| 1738 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1739 | // Migrate the setting for this user if needed. |
| 1740 | migrateLegacySettingsForUserIfNeededLocked(userId); |
| 1741 | |
| 1742 | // Ensure global settings loaded if owner. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1743 | if (userId == UserHandle.USER_SYSTEM) { |
| 1744 | final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1745 | ensureSettingsStateLocked(globalKey); |
| 1746 | } |
| 1747 | |
| 1748 | // Ensure secure settings loaded. |
| 1749 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 1750 | ensureSettingsStateLocked(secureKey); |
| 1751 | |
| 1752 | // Make sure the secure settings have an Android id set. |
| 1753 | SettingsState secureSettings = getSettingsLocked(SETTINGS_TYPE_SECURE, userId); |
| 1754 | ensureSecureSettingAndroidIdSetLocked(secureSettings); |
| 1755 | |
| 1756 | // Ensure system settings loaded. |
| 1757 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 1758 | ensureSettingsStateLocked(systemKey); |
| 1759 | |
| 1760 | // Upgrade the settings to the latest version. |
| 1761 | UpgradeController upgrader = new UpgradeController(userId); |
| 1762 | upgrader.upgradeIfNeededLocked(); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1763 | return true; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | private void ensureSettingsStateLocked(int key) { |
| 1767 | if (mSettingsStates.get(key) == null) { |
| 1768 | final int maxBytesPerPackage = getMaxBytesPerPackageForType(getTypeFromKey(key)); |
| 1769 | SettingsState settingsState = new SettingsState(mLock, getSettingsFile(key), key, |
Svetoslav Ganov | 9205749 | 2016-05-16 12:36:43 -0700 | [diff] [blame] | 1770 | maxBytesPerPackage, mHandlerThread.getLooper()); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1771 | mSettingsStates.put(key, settingsState); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | public void removeUserStateLocked(int userId, boolean permanently) { |
| 1776 | // We always keep the global settings in memory. |
| 1777 | |
| 1778 | // Nuke system settings. |
| 1779 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 1780 | final SettingsState systemSettingsState = mSettingsStates.get(systemKey); |
| 1781 | if (systemSettingsState != null) { |
| 1782 | if (permanently) { |
| 1783 | mSettingsStates.remove(systemKey); |
| 1784 | systemSettingsState.destroyLocked(null); |
Brad Fitzpatrick | 342984a | 2010-03-09 16:59:30 -0800 | [diff] [blame] | 1785 | } else { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1786 | systemSettingsState.destroyLocked(new Runnable() { |
| 1787 | @Override |
| 1788 | public void run() { |
| 1789 | mSettingsStates.remove(systemKey); |
| 1790 | } |
| 1791 | }); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | // Nuke secure settings. |
| 1796 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 1797 | final SettingsState secureSettingsState = mSettingsStates.get(secureKey); |
| 1798 | if (secureSettingsState != null) { |
| 1799 | if (permanently) { |
| 1800 | mSettingsStates.remove(secureKey); |
| 1801 | secureSettingsState.destroyLocked(null); |
| 1802 | } else { |
| 1803 | secureSettingsState.destroyLocked(new Runnable() { |
| 1804 | @Override |
| 1805 | public void run() { |
| 1806 | mSettingsStates.remove(secureKey); |
| 1807 | } |
| 1808 | }); |
Brad Fitzpatrick | 342984a | 2010-03-09 16:59:30 -0800 | [diff] [blame] | 1809 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1810 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1811 | |
| 1812 | // Nuke generation tracking data |
| 1813 | mGenerationRegistry.onUserRemoved(userId); |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 1814 | } |
| 1815 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1816 | public boolean insertSettingLocked(int type, int userId, String name, String value, |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1817 | String packageName, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1818 | final int key = makeKey(type, userId); |
| 1819 | |
| 1820 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1821 | final boolean success = settingsState != null |
| 1822 | && settingsState.insertSettingLocked(name, value, packageName); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1823 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1824 | if (forceNotify || success) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1825 | notifyForSettingsChange(key, name); |
| 1826 | } |
| 1827 | return success; |
| 1828 | } |
| 1829 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1830 | public boolean deleteSettingLocked(int type, int userId, String name, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1831 | final int key = makeKey(type, userId); |
| 1832 | |
| 1833 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1834 | if (settingsState == null) { |
| 1835 | return false; |
| 1836 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1837 | final boolean success = settingsState.deleteSettingLocked(name); |
| 1838 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1839 | if (forceNotify || success) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1840 | notifyForSettingsChange(key, name); |
| 1841 | } |
| 1842 | return success; |
| 1843 | } |
| 1844 | |
| 1845 | public Setting getSettingLocked(int type, int userId, String name) { |
| 1846 | final int key = makeKey(type, userId); |
| 1847 | |
| 1848 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1849 | if (settingsState == null) { |
| 1850 | return null; |
| 1851 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1852 | return settingsState.getSettingLocked(name); |
| 1853 | } |
| 1854 | |
| 1855 | public boolean updateSettingLocked(int type, int userId, String name, String value, |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1856 | String packageName, boolean forceNotify) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1857 | final int key = makeKey(type, userId); |
| 1858 | |
| 1859 | SettingsState settingsState = peekSettingsStateLocked(key); |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1860 | final boolean success = settingsState != null |
| 1861 | && settingsState.updateSettingLocked(name, value, packageName); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1862 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 1863 | if (forceNotify || success) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1864 | notifyForSettingsChange(key, name); |
| 1865 | } |
| 1866 | |
| 1867 | return success; |
| 1868 | } |
| 1869 | |
| 1870 | public void onPackageRemovedLocked(String packageName, int userId) { |
Svet Ganov | 8de3480 | 2015-04-27 09:33:40 -0700 | [diff] [blame] | 1871 | // Global and secure settings are signature protected. Apps signed |
| 1872 | // by the platform certificate are generally not uninstalled and |
| 1873 | // the main exception is tests. We trust components signed |
| 1874 | // by the platform certificate and do not do a clean up after them. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1875 | |
| 1876 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 1877 | SettingsState systemSettings = mSettingsStates.get(systemKey); |
Svet Ganov | 8de3480 | 2015-04-27 09:33:40 -0700 | [diff] [blame] | 1878 | if (systemSettings != null) { |
| 1879 | systemSettings.onPackageRemovedLocked(packageName); |
| 1880 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | private SettingsState peekSettingsStateLocked(int key) { |
| 1884 | SettingsState settingsState = mSettingsStates.get(key); |
| 1885 | if (settingsState != null) { |
| 1886 | return settingsState; |
| 1887 | } |
| 1888 | |
Dianne Hackborn | 32f40ee | 2016-10-20 15:54:14 -0700 | [diff] [blame^] | 1889 | if (!ensureSettingsForUserLocked(getUserIdFromKey(key))) { |
| 1890 | return null; |
| 1891 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1892 | return mSettingsStates.get(key); |
| 1893 | } |
| 1894 | |
| 1895 | private void migrateAllLegacySettingsIfNeeded() { |
| 1896 | synchronized (mLock) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 1897 | final int key = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1898 | File globalFile = getSettingsFile(key); |
| 1899 | if (globalFile.exists()) { |
| 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | final long identity = Binder.clearCallingIdentity(); |
| 1904 | try { |
| 1905 | List<UserInfo> users = mUserManager.getUsers(true); |
| 1906 | |
| 1907 | final int userCount = users.size(); |
| 1908 | for (int i = 0; i < userCount; i++) { |
| 1909 | final int userId = users.get(i).id; |
| 1910 | |
| 1911 | DatabaseHelper dbHelper = new DatabaseHelper(getContext(), userId); |
| 1912 | SQLiteDatabase database = dbHelper.getWritableDatabase(); |
| 1913 | migrateLegacySettingsForUserLocked(dbHelper, database, userId); |
| 1914 | |
| 1915 | // Upgrade to the latest version. |
| 1916 | UpgradeController upgrader = new UpgradeController(userId); |
| 1917 | upgrader.upgradeIfNeededLocked(); |
| 1918 | |
| 1919 | // Drop from memory if not a running user. |
| 1920 | if (!mUserManager.isUserRunning(new UserHandle(userId))) { |
| 1921 | removeUserStateLocked(userId, false); |
| 1922 | } |
| 1923 | } |
| 1924 | } finally { |
| 1925 | Binder.restoreCallingIdentity(identity); |
| 1926 | } |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | private void migrateLegacySettingsForUserIfNeededLocked(int userId) { |
| 1931 | // Every user has secure settings and if no file we need to migrate. |
| 1932 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 1933 | File secureFile = getSettingsFile(secureKey); |
| 1934 | if (secureFile.exists()) { |
| 1935 | return; |
| 1936 | } |
| 1937 | |
| 1938 | DatabaseHelper dbHelper = new DatabaseHelper(getContext(), userId); |
| 1939 | SQLiteDatabase database = dbHelper.getWritableDatabase(); |
| 1940 | |
| 1941 | migrateLegacySettingsForUserLocked(dbHelper, database, userId); |
| 1942 | } |
| 1943 | |
| 1944 | private void migrateLegacySettingsForUserLocked(DatabaseHelper dbHelper, |
| 1945 | SQLiteDatabase database, int userId) { |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 1946 | // Move over the system settings. |
| 1947 | final int systemKey = makeKey(SETTINGS_TYPE_SYSTEM, userId); |
| 1948 | ensureSettingsStateLocked(systemKey); |
| 1949 | SettingsState systemSettings = mSettingsStates.get(systemKey); |
| 1950 | migrateLegacySettingsLocked(systemSettings, database, TABLE_SYSTEM); |
| 1951 | systemSettings.persistSyncLocked(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1952 | |
| 1953 | // Move over the secure settings. |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 1954 | // Do this after System settings, since this is the first thing we check when deciding |
| 1955 | // to skip over migration from db to xml for a secondary user. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1956 | final int secureKey = makeKey(SETTINGS_TYPE_SECURE, userId); |
| 1957 | ensureSettingsStateLocked(secureKey); |
| 1958 | SettingsState secureSettings = mSettingsStates.get(secureKey); |
| 1959 | migrateLegacySettingsLocked(secureSettings, database, TABLE_SECURE); |
| 1960 | ensureSecureSettingAndroidIdSetLocked(secureSettings); |
| 1961 | secureSettings.persistSyncLocked(); |
| 1962 | |
Amith Yamasani | bf2ef61 | 2016-03-07 16:37:18 -0800 | [diff] [blame] | 1963 | // Move over the global settings if owner. |
| 1964 | // Do this last, since this is the first thing we check when deciding |
| 1965 | // to skip over migration from db to xml for owner user. |
| 1966 | if (userId == UserHandle.USER_SYSTEM) { |
| 1967 | final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, userId); |
| 1968 | ensureSettingsStateLocked(globalKey); |
| 1969 | SettingsState globalSettings = mSettingsStates.get(globalKey); |
| 1970 | migrateLegacySettingsLocked(globalSettings, database, TABLE_GLOBAL); |
| 1971 | globalSettings.persistSyncLocked(); |
| 1972 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1973 | |
| 1974 | // Drop the database as now all is moved and persisted. |
| 1975 | if (DROP_DATABASE_ON_MIGRATION) { |
| 1976 | dbHelper.dropDatabase(); |
| 1977 | } else { |
| 1978 | dbHelper.backupDatabase(); |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | private void migrateLegacySettingsLocked(SettingsState settingsState, |
| 1983 | SQLiteDatabase database, String table) { |
| 1984 | SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); |
| 1985 | queryBuilder.setTables(table); |
| 1986 | |
| 1987 | Cursor cursor = queryBuilder.query(database, ALL_COLUMNS, |
| 1988 | null, null, null, null, null); |
| 1989 | |
| 1990 | if (cursor == null) { |
| 1991 | return; |
| 1992 | } |
| 1993 | |
| 1994 | try { |
| 1995 | if (!cursor.moveToFirst()) { |
| 1996 | return; |
| 1997 | } |
| 1998 | |
| 1999 | final int nameColumnIdx = cursor.getColumnIndex(Settings.NameValueTable.NAME); |
| 2000 | final int valueColumnIdx = cursor.getColumnIndex(Settings.NameValueTable.VALUE); |
| 2001 | |
| 2002 | settingsState.setVersionLocked(database.getVersion()); |
| 2003 | |
| 2004 | while (!cursor.isAfterLast()) { |
| 2005 | String name = cursor.getString(nameColumnIdx); |
| 2006 | String value = cursor.getString(valueColumnIdx); |
| 2007 | settingsState.insertSettingLocked(name, value, |
| 2008 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2009 | cursor.moveToNext(); |
| 2010 | } |
| 2011 | } finally { |
| 2012 | cursor.close(); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | private void ensureSecureSettingAndroidIdSetLocked(SettingsState secureSettings) { |
| 2017 | Setting value = secureSettings.getSettingLocked(Settings.Secure.ANDROID_ID); |
| 2018 | |
Seigo Nonaka | 6e5b602 | 2016-04-27 16:32:44 +0900 | [diff] [blame] | 2019 | if (!value.isNull()) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2020 | return; |
| 2021 | } |
| 2022 | |
| 2023 | final int userId = getUserIdFromKey(secureSettings.mKey); |
| 2024 | |
| 2025 | final UserInfo user; |
| 2026 | final long identity = Binder.clearCallingIdentity(); |
| 2027 | try { |
| 2028 | user = mUserManager.getUserInfo(userId); |
| 2029 | } finally { |
| 2030 | Binder.restoreCallingIdentity(identity); |
| 2031 | } |
| 2032 | if (user == null) { |
| 2033 | // Can happen due to races when deleting users - treat as benign. |
| 2034 | return; |
| 2035 | } |
| 2036 | |
| 2037 | String androidId = Long.toHexString(new SecureRandom().nextLong()); |
| 2038 | secureSettings.insertSettingLocked(Settings.Secure.ANDROID_ID, androidId, |
| 2039 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2040 | |
| 2041 | Slog.d(LOG_TAG, "Generated and saved new ANDROID_ID [" + androidId |
| 2042 | + "] for user " + userId); |
| 2043 | |
| 2044 | // Write a drop box entry if it's a restricted profile |
| 2045 | if (user.isRestricted()) { |
| 2046 | DropBoxManager dbm = (DropBoxManager) getContext().getSystemService( |
| 2047 | Context.DROPBOX_SERVICE); |
| 2048 | if (dbm != null && dbm.isTagEnabled(DROPBOX_TAG_USERLOG)) { |
| 2049 | dbm.addText(DROPBOX_TAG_USERLOG, System.currentTimeMillis() |
| 2050 | + "," + DROPBOX_TAG_USERLOG + "," + androidId + "\n"); |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | private void notifyForSettingsChange(int key, String name) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2056 | final int userId = getUserIdFromKey(key); |
| 2057 | Uri uri = getNotificationUriFor(key, name); |
| 2058 | |
Phil Weaver | 83fec00 | 2016-05-11 10:55:29 -0700 | [diff] [blame] | 2059 | mGenerationRegistry.incrementGeneration(key); |
| 2060 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 2061 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, |
| 2062 | userId, 0, uri).sendToTarget(); |
| 2063 | |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2064 | if (isSecureSettingsKey(key)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2065 | maybeNotifyProfiles(getTypeFromKey(key), userId, uri, name, |
| 2066 | sSecureCloneToManagedSettings); |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2067 | } else if (isSystemSettingsKey(key)) { |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2068 | maybeNotifyProfiles(getTypeFromKey(key), userId, uri, name, |
| 2069 | sSystemCloneToManagedSettings); |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2070 | } |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2071 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2072 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget(); |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2073 | } |
| 2074 | |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2075 | private void maybeNotifyProfiles(int type, int userId, Uri uri, String name, |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2076 | Set<String> keysCloned) { |
| 2077 | if (keysCloned.contains(name)) { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 2078 | for (int profileId : mUserManager.getProfileIdsWithDisabled(userId)) { |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2079 | // the notification for userId has already been sent. |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 2080 | if (profileId != userId) { |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 2081 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_URI_CHANGED, |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 2082 | profileId, 0, uri).sendToTarget(); |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2083 | final int key = makeKey(type, profileId); |
| 2084 | mGenerationRegistry.incrementGeneration(key); |
| 2085 | |
| 2086 | mHandler.obtainMessage(MyHandler.MSG_NOTIFY_DATA_CHANGED).sendToTarget(); |
Nicolas Prevot | 310e1ee | 2015-07-02 14:03:06 +0100 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2092 | private boolean isGlobalSettingsKey(int key) { |
| 2093 | return getTypeFromKey(key) == SETTINGS_TYPE_GLOBAL; |
| 2094 | } |
| 2095 | |
| 2096 | private boolean isSystemSettingsKey(int key) { |
| 2097 | return getTypeFromKey(key) == SETTINGS_TYPE_SYSTEM; |
| 2098 | } |
| 2099 | |
| 2100 | private boolean isSecureSettingsKey(int key) { |
| 2101 | return getTypeFromKey(key) == SETTINGS_TYPE_SECURE; |
| 2102 | } |
| 2103 | |
| 2104 | private File getSettingsFile(int key) { |
| 2105 | if (isGlobalSettingsKey(key)) { |
| 2106 | final int userId = getUserIdFromKey(key); |
| 2107 | return new File(Environment.getUserSystemDirectory(userId), |
| 2108 | SETTINGS_FILE_GLOBAL); |
| 2109 | } else if (isSystemSettingsKey(key)) { |
| 2110 | final int userId = getUserIdFromKey(key); |
| 2111 | return new File(Environment.getUserSystemDirectory(userId), |
| 2112 | SETTINGS_FILE_SYSTEM); |
| 2113 | } else if (isSecureSettingsKey(key)) { |
| 2114 | final int userId = getUserIdFromKey(key); |
| 2115 | return new File(Environment.getUserSystemDirectory(userId), |
| 2116 | SETTINGS_FILE_SECURE); |
| 2117 | } else { |
| 2118 | throw new IllegalArgumentException("Invalid settings key:" + key); |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | private Uri getNotificationUriFor(int key, String name) { |
| 2123 | if (isGlobalSettingsKey(key)) { |
| 2124 | return (name != null) ? Uri.withAppendedPath(Settings.Global.CONTENT_URI, name) |
| 2125 | : Settings.Global.CONTENT_URI; |
| 2126 | } else if (isSecureSettingsKey(key)) { |
| 2127 | return (name != null) ? Uri.withAppendedPath(Settings.Secure.CONTENT_URI, name) |
| 2128 | : Settings.Secure.CONTENT_URI; |
| 2129 | } else if (isSystemSettingsKey(key)) { |
| 2130 | return (name != null) ? Uri.withAppendedPath(Settings.System.CONTENT_URI, name) |
| 2131 | : Settings.System.CONTENT_URI; |
| 2132 | } else { |
| 2133 | throw new IllegalArgumentException("Invalid settings key:" + key); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | private int getMaxBytesPerPackageForType(int type) { |
| 2138 | switch (type) { |
| 2139 | case SETTINGS_TYPE_GLOBAL: |
| 2140 | case SETTINGS_TYPE_SECURE: { |
| 2141 | return SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED; |
| 2142 | } |
| 2143 | |
| 2144 | default: { |
| 2145 | return SettingsState.MAX_BYTES_PER_APP_PACKAGE_LIMITED; |
| 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 2150 | private final class MyHandler extends Handler { |
| 2151 | private static final int MSG_NOTIFY_URI_CHANGED = 1; |
| 2152 | private static final int MSG_NOTIFY_DATA_CHANGED = 2; |
| 2153 | |
| 2154 | public MyHandler(Looper looper) { |
| 2155 | super(looper); |
| 2156 | } |
| 2157 | |
| 2158 | @Override |
| 2159 | public void handleMessage(Message msg) { |
| 2160 | switch (msg.what) { |
| 2161 | case MSG_NOTIFY_URI_CHANGED: { |
| 2162 | final int userId = msg.arg1; |
| 2163 | Uri uri = (Uri) msg.obj; |
| 2164 | getContext().getContentResolver().notifyChange(uri, null, true, userId); |
| 2165 | if (DEBUG) { |
| 2166 | Slog.v(LOG_TAG, "Notifying for " + userId + ": " + uri); |
| 2167 | } |
| 2168 | } break; |
| 2169 | |
| 2170 | case MSG_NOTIFY_DATA_CHANGED: { |
| 2171 | mBackupManager.dataChanged(); |
| 2172 | } break; |
| 2173 | } |
| 2174 | } |
| 2175 | } |
| 2176 | |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2177 | private final class UpgradeController { |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2178 | private static final int SETTINGS_VERSION = 134; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2179 | |
| 2180 | private final int mUserId; |
| 2181 | |
| 2182 | public UpgradeController(int userId) { |
| 2183 | mUserId = userId; |
| 2184 | } |
| 2185 | |
| 2186 | public void upgradeIfNeededLocked() { |
| 2187 | // The version of all settings for a user is the same (all users have secure). |
| 2188 | SettingsState secureSettings = getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2189 | SETTINGS_TYPE_SECURE, mUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2190 | |
| 2191 | // Try an update from the current state. |
| 2192 | final int oldVersion = secureSettings.getVersionLocked(); |
| 2193 | final int newVersion = SETTINGS_VERSION; |
| 2194 | |
Svet Ganov | c9755bc | 2015-03-28 13:21:22 -0700 | [diff] [blame] | 2195 | // If up do date - done. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2196 | if (oldVersion == newVersion) { |
| 2197 | return; |
| 2198 | } |
| 2199 | |
| 2200 | // Try to upgrade. |
| 2201 | final int curVersion = onUpgradeLocked(mUserId, oldVersion, newVersion); |
| 2202 | |
| 2203 | // If upgrade failed start from scratch and upgrade. |
| 2204 | if (curVersion != newVersion) { |
| 2205 | // Drop state we have for this user. |
| 2206 | removeUserStateLocked(mUserId, true); |
| 2207 | |
| 2208 | // Recreate the database. |
| 2209 | DatabaseHelper dbHelper = new DatabaseHelper(getContext(), mUserId); |
| 2210 | SQLiteDatabase database = dbHelper.getWritableDatabase(); |
| 2211 | dbHelper.recreateDatabase(database, newVersion, curVersion, oldVersion); |
| 2212 | |
| 2213 | // Migrate the settings for this user. |
| 2214 | migrateLegacySettingsForUserLocked(dbHelper, database, mUserId); |
| 2215 | |
| 2216 | // Now upgrade should work fine. |
| 2217 | onUpgradeLocked(mUserId, oldVersion, newVersion); |
Svetoslav Ganov | 264c7a9 | 2016-08-24 17:31:14 -0700 | [diff] [blame] | 2218 | |
| 2219 | // Make a note what happened, so we don't wonder why data was lost |
| 2220 | String reason = "Settings rebuilt! Current version: " |
| 2221 | + curVersion + " while expected: " + newVersion; |
| 2222 | getGlobalSettingsLocked().insertSettingLocked( |
| 2223 | Settings.Global.DATABASE_DOWNGRADE_REASON, reason, "android"); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | // Set the global settings version if owner. |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 2227 | if (mUserId == UserHandle.USER_SYSTEM) { |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2228 | SettingsState globalSettings = getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2229 | SETTINGS_TYPE_GLOBAL, mUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2230 | globalSettings.setVersionLocked(newVersion); |
| 2231 | } |
| 2232 | |
| 2233 | // Set the secure settings version. |
| 2234 | secureSettings.setVersionLocked(newVersion); |
| 2235 | |
| 2236 | // Set the system settings version. |
| 2237 | SettingsState systemSettings = getSettingsLocked( |
Svet Ganov | 53a441c | 2016-04-19 19:38:00 -0700 | [diff] [blame] | 2238 | SETTINGS_TYPE_SYSTEM, mUserId); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2239 | systemSettings.setVersionLocked(newVersion); |
| 2240 | } |
| 2241 | |
| 2242 | private SettingsState getGlobalSettingsLocked() { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 2243 | return getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | private SettingsState getSecureSettingsLocked(int userId) { |
| 2247 | return getSettingsLocked(SETTINGS_TYPE_SECURE, userId); |
| 2248 | } |
| 2249 | |
| 2250 | private SettingsState getSystemSettingsLocked(int userId) { |
| 2251 | return getSettingsLocked(SETTINGS_TYPE_SYSTEM, userId); |
| 2252 | } |
| 2253 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 2254 | /** |
| 2255 | * You must perform all necessary mutations to bring the settings |
| 2256 | * for this user from the old to the new version. When you add a new |
| 2257 | * upgrade step you *must* update SETTINGS_VERSION. |
| 2258 | * |
| 2259 | * This is an example of moving a setting from secure to global. |
| 2260 | * |
| 2261 | * // v119: Example settings changes. |
| 2262 | * if (currentVersion == 118) { |
| 2263 | * if (userId == UserHandle.USER_OWNER) { |
| 2264 | * // Remove from the secure settings. |
| 2265 | * SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2266 | * String name = "example_setting_to_move"; |
| 2267 | * String value = secureSettings.getSetting(name); |
| 2268 | * secureSettings.deleteSetting(name); |
| 2269 | * |
| 2270 | * // Add to the global settings. |
| 2271 | * SettingsState globalSettings = getGlobalSettingsLocked(); |
| 2272 | * globalSettings.insertSetting(name, value, SettingsState.SYSTEM_PACKAGE_NAME); |
| 2273 | * } |
| 2274 | * |
| 2275 | * // Update the current version. |
| 2276 | * currentVersion = 119; |
| 2277 | * } |
| 2278 | */ |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2279 | private int onUpgradeLocked(int userId, int oldVersion, int newVersion) { |
| 2280 | if (DEBUG) { |
| 2281 | Slog.w(LOG_TAG, "Upgrading settings for user: " + userId + " from version: " |
| 2282 | + oldVersion + " to version: " + newVersion); |
| 2283 | } |
| 2284 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 2285 | int currentVersion = oldVersion; |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2286 | |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 2287 | // v119: Reset zen + ringer mode. |
| 2288 | if (currentVersion == 118) { |
Xiaohui Chen | 43765b7 | 2015-08-31 10:57:33 -0700 | [diff] [blame] | 2289 | if (userId == UserHandle.USER_SYSTEM) { |
John Spurlock | e11ae11 | 2015-05-11 16:09:03 -0400 | [diff] [blame] | 2290 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 2291 | globalSettings.updateSettingLocked(Settings.Global.ZEN_MODE, |
| 2292 | Integer.toString(Settings.Global.ZEN_MODE_OFF), |
| 2293 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2294 | globalSettings.updateSettingLocked(Settings.Global.MODE_RINGER, |
| 2295 | Integer.toString(AudioManager.RINGER_MODE_NORMAL), |
| 2296 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2297 | } |
| 2298 | currentVersion = 119; |
| 2299 | } |
| 2300 | |
Jason Monk | 27bbb2d | 2015-03-31 16:46:39 -0400 | [diff] [blame] | 2301 | // v120: Add double tap to wake setting. |
| 2302 | if (currentVersion == 119) { |
| 2303 | SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2304 | secureSettings.insertSettingLocked(Settings.Secure.DOUBLE_TAP_TO_WAKE, |
| 2305 | getContext().getResources().getBoolean( |
| 2306 | R.bool.def_double_tap_to_wake) ? "1" : "0", |
| 2307 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2308 | |
| 2309 | currentVersion = 120; |
| 2310 | } |
| 2311 | |
Svetoslav | 7e0683b | 2015-08-03 16:02:52 -0700 | [diff] [blame] | 2312 | if (currentVersion == 120) { |
| 2313 | // Before 121, we used a different string encoding logic. We just bump the |
| 2314 | // version here; SettingsState knows how to handle pre-version 120 files. |
| 2315 | currentVersion = 121; |
| 2316 | } |
Makoto Onuki | 3a2c3578 | 2015-06-18 11:21:58 -0700 | [diff] [blame] | 2317 | |
Martijn Coenen | 7ab4b7f | 2015-07-27 15:58:32 +0200 | [diff] [blame] | 2318 | if (currentVersion == 121) { |
| 2319 | // Version 122: allow OEMs to set a default payment component in resources. |
| 2320 | // Note that we only write the default if no default has been set; |
| 2321 | // if there is, we just leave the default at whatever it currently is. |
| 2322 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2323 | String defaultComponent = (getContext().getResources().getString( |
| 2324 | R.string.def_nfc_payment_component)); |
| 2325 | Setting currentSetting = secureSettings.getSettingLocked( |
| 2326 | Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT); |
| 2327 | if (defaultComponent != null && !defaultComponent.isEmpty() && |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 2328 | currentSetting.isNull()) { |
Martijn Coenen | 7ab4b7f | 2015-07-27 15:58:32 +0200 | [diff] [blame] | 2329 | secureSettings.insertSettingLocked( |
| 2330 | Settings.Secure.NFC_PAYMENT_DEFAULT_COMPONENT, |
| 2331 | defaultComponent, |
| 2332 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2333 | } |
| 2334 | currentVersion = 122; |
| 2335 | } |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 2336 | |
| 2337 | if (currentVersion == 122) { |
| 2338 | // Version 123: Adding a default value for the ability to add a user from |
| 2339 | // the lock screen. |
| 2340 | if (userId == UserHandle.USER_SYSTEM) { |
| 2341 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 2342 | Setting currentSetting = globalSettings.getSettingLocked( |
| 2343 | Settings.Global.ADD_USERS_WHEN_LOCKED); |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 2344 | if (currentSetting.isNull()) { |
Suprabh Shukla | 269c11e | 2015-12-02 16:51:16 -0800 | [diff] [blame] | 2345 | globalSettings.insertSettingLocked( |
| 2346 | Settings.Global.ADD_USERS_WHEN_LOCKED, |
| 2347 | getContext().getResources().getBoolean( |
| 2348 | R.bool.def_add_users_from_lockscreen) ? "1" : "0", |
| 2349 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2350 | } |
| 2351 | } |
| 2352 | currentVersion = 123; |
| 2353 | } |
Bryce Lee | bd17928 | 2015-12-17 19:01:37 -0800 | [diff] [blame] | 2354 | |
| 2355 | if (currentVersion == 123) { |
Bryce Lee | ec85f34 | 2015-12-16 13:32:28 -0800 | [diff] [blame] | 2356 | final SettingsState globalSettings = getGlobalSettingsLocked(); |
| 2357 | String defaultDisabledProfiles = (getContext().getResources().getString( |
| 2358 | R.string.def_bluetooth_disabled_profiles)); |
| 2359 | globalSettings.insertSettingLocked(Settings.Global.BLUETOOTH_DISABLED_PROFILES, |
| 2360 | defaultDisabledProfiles, SettingsState.SYSTEM_PACKAGE_NAME); |
Bryce Lee | bd17928 | 2015-12-17 19:01:37 -0800 | [diff] [blame] | 2361 | currentVersion = 124; |
Bryce Lee | ec85f34 | 2015-12-16 13:32:28 -0800 | [diff] [blame] | 2362 | } |
| 2363 | |
Prathmesh Prabhu | de16b86 | 2016-03-04 15:22:24 -0800 | [diff] [blame] | 2364 | if (currentVersion == 124) { |
| 2365 | // Version 124: allow OEMs to set a default value for whether IME should be |
| 2366 | // shown when a physical keyboard is connected. |
| 2367 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2368 | Setting currentSetting = secureSettings.getSettingLocked( |
| 2369 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 2370 | if (currentSetting.isNull()) { |
Prathmesh Prabhu | de16b86 | 2016-03-04 15:22:24 -0800 | [diff] [blame] | 2371 | secureSettings.insertSettingLocked( |
| 2372 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, |
| 2373 | getContext().getResources().getBoolean( |
| 2374 | R.bool.def_show_ime_with_hard_keyboard) ? "1" : "0", |
| 2375 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2376 | } |
| 2377 | currentVersion = 125; |
| 2378 | } |
| 2379 | |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 2380 | if (currentVersion == 125) { |
| 2381 | // Version 125: Allow OEMs to set the default VR service. |
| 2382 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2383 | |
| 2384 | Setting currentSetting = secureSettings.getSettingLocked( |
| 2385 | Settings.Secure.ENABLED_VR_LISTENERS); |
Svetoslav Ganov | fedb230 | 2016-04-26 18:36:42 -0700 | [diff] [blame] | 2386 | if (currentSetting.isNull()) { |
Ruben Brunk | 98576cf | 2016-03-07 18:54:28 -0800 | [diff] [blame] | 2387 | ArraySet<ComponentName> l = |
| 2388 | SystemConfig.getInstance().getDefaultVrComponents(); |
| 2389 | |
| 2390 | if (l != null && !l.isEmpty()) { |
| 2391 | StringBuilder b = new StringBuilder(); |
| 2392 | boolean start = true; |
| 2393 | for (ComponentName c : l) { |
| 2394 | if (!start) { |
| 2395 | b.append(':'); |
| 2396 | } |
| 2397 | b.append(c.flattenToString()); |
| 2398 | start = false; |
| 2399 | } |
| 2400 | secureSettings.insertSettingLocked( |
| 2401 | Settings.Secure.ENABLED_VR_LISTENERS, b.toString(), |
| 2402 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2403 | } |
| 2404 | |
| 2405 | } |
| 2406 | currentVersion = 126; |
| 2407 | } |
| 2408 | |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 2409 | if (currentVersion == 126) { |
| 2410 | // Version 126: copy the primary values of LOCK_SCREEN_SHOW_NOTIFICATIONS and |
| 2411 | // LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS into managed profile. |
| 2412 | if (mUserManager.isManagedProfile(userId)) { |
| 2413 | final SettingsState systemSecureSettings = |
| 2414 | getSecureSettingsLocked(UserHandle.USER_SYSTEM); |
| 2415 | |
| 2416 | final Setting showNotifications = systemSecureSettings.getSettingLocked( |
| 2417 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); |
Seigo Nonaka | 6e5b602 | 2016-04-27 16:32:44 +0900 | [diff] [blame] | 2418 | if (!showNotifications.isNull()) { |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 2419 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2420 | secureSettings.insertSettingLocked( |
| 2421 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, |
| 2422 | showNotifications.getValue(), |
| 2423 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2424 | } |
| 2425 | |
| 2426 | final Setting allowPrivate = systemSecureSettings.getSettingLocked( |
| 2427 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); |
Seigo Nonaka | 6e5b602 | 2016-04-27 16:32:44 +0900 | [diff] [blame] | 2428 | if (!allowPrivate.isNull()) { |
Daniel U | 02ba612 | 2016-04-01 18:41:42 +0100 | [diff] [blame] | 2429 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2430 | secureSettings.insertSettingLocked( |
| 2431 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, |
| 2432 | allowPrivate.getValue(), |
| 2433 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2434 | } |
| 2435 | } |
| 2436 | currentVersion = 127; |
| 2437 | } |
| 2438 | |
Steven Ng | dc20ba6 | 2016-04-26 18:19:04 +0100 | [diff] [blame] | 2439 | if (currentVersion == 127) { |
Mahaver Chopra | 3d9805d | 2016-07-07 16:25:05 +0100 | [diff] [blame] | 2440 | // version 127 is no longer used. |
Steven Ng | dc20ba6 | 2016-04-26 18:19:04 +0100 | [diff] [blame] | 2441 | currentVersion = 128; |
| 2442 | } |
| 2443 | |
Julia Reynolds | 1f721e1 | 2016-07-11 08:50:58 -0400 | [diff] [blame] | 2444 | if (currentVersion == 128) { |
| 2445 | // Version 128: Allow OEMs to grant DND access to default apps. Note that |
| 2446 | // the new apps are appended to the list of already approved apps. |
| 2447 | final SettingsState systemSecureSettings = |
| 2448 | getSecureSettingsLocked(userId); |
| 2449 | |
| 2450 | final Setting policyAccess = systemSecureSettings.getSettingLocked( |
| 2451 | Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES); |
| 2452 | String defaultPolicyAccess = getContext().getResources().getString( |
| 2453 | com.android.internal.R.string.config_defaultDndAccessPackages); |
| 2454 | if (!TextUtils.isEmpty(defaultPolicyAccess)) { |
| 2455 | if (policyAccess.isNull()) { |
| 2456 | systemSecureSettings.insertSettingLocked( |
| 2457 | Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES, |
| 2458 | defaultPolicyAccess, |
| 2459 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2460 | } else { |
| 2461 | StringBuilder currentSetting = |
| 2462 | new StringBuilder(policyAccess.getValue()); |
| 2463 | currentSetting.append(":"); |
| 2464 | currentSetting.append(defaultPolicyAccess); |
| 2465 | systemSecureSettings.updateSettingLocked( |
| 2466 | Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES, |
| 2467 | currentSetting.toString(), |
| 2468 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | currentVersion = 129; |
| 2473 | } |
| 2474 | |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 2475 | if (currentVersion == 129) { |
| 2476 | // default longpress timeout changed from 500 to 400. If unchanged from the old |
| 2477 | // default, update to the new default. |
| 2478 | final SettingsState systemSecureSettings = |
| 2479 | getSecureSettingsLocked(userId); |
| 2480 | final String oldValue = systemSecureSettings.getSettingLocked( |
| 2481 | Settings.Secure.LONG_PRESS_TIMEOUT).getValue(); |
| 2482 | if (TextUtils.equals("500", oldValue)) { |
| 2483 | systemSecureSettings.insertSettingLocked( |
| 2484 | Settings.Secure.LONG_PRESS_TIMEOUT, |
| 2485 | String.valueOf(getContext().getResources().getInteger( |
| 2486 | R.integer.def_long_press_timeout_millis)), |
| 2487 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2488 | } |
| 2489 | currentVersion = 130; |
| 2490 | } |
| 2491 | |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 2492 | if (currentVersion == 130) { |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2493 | // Split Ambient settings |
| 2494 | final SettingsState secureSettings = getSecureSettingsLocked(userId); |
| 2495 | boolean dozeExplicitlyDisabled = "0".equals(secureSettings. |
| 2496 | getSettingLocked(Settings.Secure.DOZE_ENABLED).getValue()); |
| 2497 | |
| 2498 | if (dozeExplicitlyDisabled) { |
| 2499 | secureSettings.insertSettingLocked(Settings.Secure.DOZE_PULSE_ON_PICK_UP, |
| 2500 | "0", SettingsState.SYSTEM_PACKAGE_NAME); |
| 2501 | secureSettings.insertSettingLocked(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, |
| 2502 | "0", SettingsState.SYSTEM_PACKAGE_NAME); |
| 2503 | } |
| 2504 | currentVersion = 131; |
| 2505 | } |
| 2506 | |
| 2507 | if (currentVersion == 131) { |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 2508 | // Initialize new multi-press timeout to default value |
| 2509 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 2510 | final String oldValue = systemSecureSettings.getSettingLocked( |
| 2511 | Settings.Secure.MULTI_PRESS_TIMEOUT).getValue(); |
| 2512 | if (TextUtils.equals(null, oldValue)) { |
| 2513 | systemSecureSettings.insertSettingLocked( |
| 2514 | Settings.Secure.MULTI_PRESS_TIMEOUT, |
| 2515 | String.valueOf(getContext().getResources().getInteger( |
| 2516 | R.integer.def_multi_press_timeout_millis)), |
| 2517 | SettingsState.SYSTEM_PACKAGE_NAME); |
| 2518 | } |
| 2519 | |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2520 | currentVersion = 132; |
Anthony Hugh | 96e9cc5 | 2016-07-12 15:17:24 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2523 | if (currentVersion == 132) { |
| 2524 | // Version 132: Allow managed profile to optionally use the parent's ringtones |
Andre Lago | ea35e07 | 2016-08-04 13:41:13 +0100 | [diff] [blame] | 2525 | final SettingsState systemSecureSettings = getSecureSettingsLocked(userId); |
| 2526 | String defaultSyncParentSounds = (getContext().getResources() |
| 2527 | .getBoolean(R.bool.def_sync_parent_sounds) ? "1" : "0"); |
| 2528 | systemSecureSettings.insertSettingLocked( |
| 2529 | Settings.Secure.SYNC_PARENT_SOUNDS, |
| 2530 | defaultSyncParentSounds, |
| 2531 | SettingsState.SYSTEM_PACKAGE_NAME); |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2532 | currentVersion = 133; |
Andre Lago | ea35e07 | 2016-08-04 13:41:13 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2535 | if (currentVersion == 133) { |
| 2536 | // Version 133: Add default end button behavior |
Keun-young Park | ec7a118 | 2016-10-18 11:52:38 -0700 | [diff] [blame] | 2537 | final SettingsState systemSettings = getSystemSettingsLocked(userId); |
| 2538 | if (systemSettings.getSettingLocked(Settings.System.END_BUTTON_BEHAVIOR) == |
| 2539 | null) { |
| 2540 | String defaultEndButtonBehavior = Integer.toString(getContext() |
| 2541 | .getResources().getInteger(R.integer.def_end_button_behavior)); |
| 2542 | systemSettings.insertSettingLocked(Settings.System.END_BUTTON_BEHAVIOR, |
| 2543 | defaultEndButtonBehavior, SettingsState.SYSTEM_PACKAGE_NAME); |
| 2544 | } |
Adrian Roos | 69741a2 | 2016-10-21 14:49:17 -0700 | [diff] [blame] | 2545 | currentVersion = 134; |
Keun-young Park | ec7a118 | 2016-10-18 11:52:38 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 2548 | if (currentVersion != newVersion) { |
Svetoslav Ganov | 264c7a9 | 2016-08-24 17:31:14 -0700 | [diff] [blame] | 2549 | Slog.wtf("SettingsProvider", "warning: upgrading settings database to version " |
Dan Sandler | 71f85e9 | 2016-07-20 13:46:05 -0400 | [diff] [blame] | 2550 | + newVersion + " left it at " |
| 2551 | + currentVersion + " instead; this is probably a bug", new Throwable()); |
| 2552 | if (DEBUG) { |
| 2553 | throw new RuntimeException("db upgrade error"); |
| 2554 | } |
| 2555 | } |
| 2556 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 2557 | // vXXX: Add new settings above this point. |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 2558 | |
Jeff Brown | 503cffc | 2015-03-26 18:08:51 -0700 | [diff] [blame] | 2559 | // Return the current version. |
| 2560 | return currentVersion; |
Brad Fitzpatrick | 547a96b | 2010-03-09 17:58:53 -0800 | [diff] [blame] | 2561 | } |
| 2562 | } |
Brad Fitzpatrick | 1bd62bd | 2010-03-08 18:30:52 -0800 | [diff] [blame] | 2563 | } |
The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2564 | } |