Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.server.devicepolicy; |
| 18 | |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 19 | import static org.mockito.Mockito.mock; |
| 20 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 22 | import android.content.ContentResolver; |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 26 | import android.content.pm.ApplicationInfo; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 28 | import android.content.res.Resources; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 29 | import android.os.Bundle; |
| 30 | import android.os.Handler; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 31 | import android.os.UserHandle; |
Christine Franks | 361b825 | 2017-06-23 18:12:46 -0700 | [diff] [blame] | 32 | import android.os.UserManagerInternal; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 33 | import android.test.mock.MockContext; |
Robin Lee | 7f5c91c | 2017-02-08 21:27:02 +0000 | [diff] [blame] | 34 | import android.util.ArrayMap; |
yuemingw | e43cdf7 | 2017-10-12 16:52:11 +0100 | [diff] [blame] | 35 | import android.util.ExceptionUtils; |
| 36 | |
Brett Chabot | ec6bcbc | 2018-11-05 21:21:35 -0800 | [diff] [blame] | 37 | import androidx.annotation.NonNull; |
| 38 | |
yuemingw | e43cdf7 | 2017-10-12 16:52:11 +0100 | [diff] [blame] | 39 | import com.android.internal.util.FunctionalUtils; |
Tony Mak | 2f26b79 | 2016-11-28 17:54:51 +0000 | [diff] [blame] | 40 | |
Makoto Onuki | b643fb0 | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 41 | import org.junit.Assert; |
| 42 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 43 | import java.util.ArrayList; |
| 44 | import java.util.List; |
Robin Lee | 7f5c91c | 2017-02-08 21:27:02 +0000 | [diff] [blame] | 45 | import java.util.Map; |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 46 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Context used throughout DPMS tests. |
| 49 | */ |
| 50 | public class DpmMockContext extends MockContext { |
| 51 | /** |
| 52 | * User-id of a non-system user we use throughout unit tests. |
| 53 | */ |
| 54 | public static final int CALLER_USER_HANDLE = 20; |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 55 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 56 | /** |
Makoto Onuki | b643fb0 | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 57 | * UID corresponding to {@link #CALLER_USER_HANDLE}. |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 58 | */ |
Makoto Onuki | d932f76 | 2015-09-29 16:53:38 -0700 | [diff] [blame] | 59 | public static final int CALLER_UID = UserHandle.getUid(CALLER_USER_HANDLE, 20123); |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 60 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 61 | /** |
Makoto Onuki | b643fb0 | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 62 | * UID used when a caller is on the system user. |
| 63 | */ |
Makoto Onuki | d932f76 | 2015-09-29 16:53:38 -0700 | [diff] [blame] | 64 | public static final int CALLER_SYSTEM_USER_UID = 20321; |
Makoto Onuki | b643fb0 | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 67 | * PID of the caller. |
| 68 | */ |
| 69 | public static final int CALLER_PID = 22222; |
| 70 | |
| 71 | /** |
| 72 | * UID of the system server. |
| 73 | */ |
| 74 | public static final int SYSTEM_UID = android.os.Process.SYSTEM_UID; |
| 75 | |
| 76 | /** |
| 77 | * PID of the system server. |
| 78 | */ |
| 79 | public static final int SYSTEM_PID = 11111; |
| 80 | |
Nicolas Prevot | 45d2907 | 2017-01-18 16:11:19 +0000 | [diff] [blame] | 81 | public static final String ANOTHER_PACKAGE_NAME = "com.another.package.name"; |
Nicolas Prevot | 45d2907 | 2017-01-18 16:11:19 +0000 | [diff] [blame] | 82 | public static final int ANOTHER_UID = UserHandle.getUid(UserHandle.USER_SYSTEM, 18434); |
| 83 | |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 84 | private final MockSystemServices mMockSystemServices; |
| 85 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 86 | public static class MockBinder { |
Makoto Onuki | f76b06a | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 87 | public int callingUid = CALLER_UID; |
| 88 | public int callingPid = CALLER_PID; |
Robin Lee | 2c68dad | 2017-03-17 12:50:24 +0000 | [diff] [blame] | 89 | public final Map<Integer, List<String>> callingPermissions = new ArrayMap<>(); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 90 | |
| 91 | public long clearCallingIdentity() { |
Makoto Onuki | f76b06a | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 92 | final long token = (((long) callingUid) << 32) | (callingPid); |
| 93 | callingUid = SYSTEM_UID; |
| 94 | callingPid = SYSTEM_PID; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 95 | return token; |
| 96 | } |
| 97 | |
| 98 | public void restoreCallingIdentity(long token) { |
Makoto Onuki | f76b06a | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 99 | callingUid = (int) (token >> 32); |
| 100 | callingPid = (int) token; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 101 | } |
| 102 | |
yuemingw | e43cdf7 | 2017-10-12 16:52:11 +0100 | [diff] [blame] | 103 | public void withCleanCallingIdentity(@NonNull FunctionalUtils.ThrowingRunnable action) { |
| 104 | long callingIdentity = clearCallingIdentity(); |
| 105 | Throwable throwableToPropagate = null; |
| 106 | try { |
Eugene Susla | 2f5ee71 | 2017-06-23 17:25:24 -0700 | [diff] [blame] | 107 | action.runOrThrow(); |
yuemingw | e43cdf7 | 2017-10-12 16:52:11 +0100 | [diff] [blame] | 108 | } catch (Throwable throwable) { |
| 109 | throwableToPropagate = throwable; |
| 110 | } finally { |
| 111 | restoreCallingIdentity(callingIdentity); |
| 112 | if (throwableToPropagate != null) { |
| 113 | throw ExceptionUtils.propagate(throwableToPropagate); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 118 | public int getCallingUid() { |
Makoto Onuki | f76b06a | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 119 | return callingUid; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | public int getCallingPid() { |
Makoto Onuki | f76b06a | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 123 | return callingPid; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | public UserHandle getCallingUserHandle() { |
| 127 | return new UserHandle(UserHandle.getUserId(getCallingUid())); |
| 128 | } |
| 129 | |
| 130 | public boolean isCallerUidMyUid() { |
Makoto Onuki | f76b06a | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 131 | return callingUid == SYSTEM_UID; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 132 | } |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 135 | private final Context realTestContext; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Use this instance to verify unimplemented methods such as {@link #sendBroadcast}. |
| 139 | * (Spying on {@code this} instance will confuse mockito somehow and I got weired "wrong number |
| 140 | * of arguments" exceptions.) |
| 141 | */ |
| 142 | public final Context spiedContext; |
| 143 | |
| 144 | public final MockBinder binder; |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 145 | public final Resources resources; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 146 | |
Robin Lee | 2c68dad | 2017-03-17 12:50:24 +0000 | [diff] [blame] | 147 | /** TODO: Migrate everything to use {@link #permissions} to avoid confusion. */ |
| 148 | @Deprecated |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 149 | public final List<String> callerPermissions = new ArrayList<>(); |
| 150 | |
Robin Lee | 2c68dad | 2017-03-17 12:50:24 +0000 | [diff] [blame] | 151 | /** Less confusing alias for {@link #callerPermissions}. */ |
| 152 | public final List<String> permissions = callerPermissions; |
| 153 | |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 154 | public String packageName = null; |
| 155 | |
| 156 | public ApplicationInfo applicationInfo = null; |
| 157 | |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 158 | public DpmMockContext(MockSystemServices mockSystemServices, Context context) { |
| 159 | mMockSystemServices = mockSystemServices; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 160 | realTestContext = context; |
Makoto Onuki | d932f76 | 2015-09-29 16:53:38 -0700 | [diff] [blame] | 161 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 162 | binder = new MockBinder(); |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 163 | resources = mock(Resources.class); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 164 | spiedContext = mock(Context.class); |
Robin Lee | 2c68dad | 2017-03-17 12:50:24 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 167 | @Override |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 168 | public Resources getResources() { |
| 169 | return resources; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public Resources.Theme getTheme() { |
| 174 | return spiedContext.getTheme(); |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public String getPackageName() { |
| 179 | if (packageName != null) { |
| 180 | return packageName; |
| 181 | } |
| 182 | return super.getPackageName(); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public ApplicationInfo getApplicationInfo() { |
| 187 | if (applicationInfo != null) { |
| 188 | return applicationInfo; |
| 189 | } |
| 190 | return super.getApplicationInfo(); |
| 191 | } |
| 192 | |
| 193 | @Override |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 194 | public Object getSystemService(String name) { |
| 195 | switch (name) { |
Robin Lee | d2a73ed | 2016-12-19 09:07:16 +0000 | [diff] [blame] | 196 | case Context.ALARM_SERVICE: |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 197 | return mMockSystemServices.alarmManager; |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 198 | case Context.USER_SERVICE: |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 199 | return mMockSystemServices.userManager; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 200 | case Context.POWER_SERVICE: |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 201 | return mMockSystemServices.powerManager; |
Makoto Onuki | a31ebbc | 2015-11-23 17:15:21 -0800 | [diff] [blame] | 202 | case Context.WIFI_SERVICE: |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 203 | return mMockSystemServices.wifiManager; |
Makoto Onuki | 606da77 | 2016-12-15 14:26:55 -0800 | [diff] [blame] | 204 | case Context.ACCOUNT_SERVICE: |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 205 | return mMockSystemServices.accountManager; |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 206 | } |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 207 | throw new UnsupportedOperationException(); |
| 208 | } |
| 209 | |
| 210 | @Override |
Makoto Onuki | 72a3a0c | 2015-09-25 16:01:43 -0700 | [diff] [blame] | 211 | public String getSystemServiceName(Class<?> serviceClass) { |
| 212 | return realTestContext.getSystemServiceName(serviceClass); |
| 213 | } |
| 214 | |
| 215 | @Override |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 216 | public PackageManager getPackageManager() { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 217 | return mMockSystemServices.packageManager; |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Christine Franks | 361b825 | 2017-06-23 18:12:46 -0700 | [diff] [blame] | 220 | public UserManagerInternal getUserManagerInternal() { |
| 221 | return mMockSystemServices.userManagerInternal; |
| 222 | } |
| 223 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 224 | @Override |
| 225 | public void enforceCallingOrSelfPermission(String permission, String message) { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 226 | if (UserHandle.isSameApp(binder.getCallingUid(), SYSTEM_UID)) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 227 | return; // Assume system has all permissions. |
| 228 | } |
Robin Lee | 2c68dad | 2017-03-17 12:50:24 +0000 | [diff] [blame] | 229 | List<String> permissions = binder.callingPermissions.get(binder.getCallingUid()); |
| 230 | if (permissions == null) { |
| 231 | // TODO: delete the following line. to do this without breaking any tests, first it's |
| 232 | // necessary to remove all tests that set it directly. |
| 233 | permissions = callerPermissions; |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 234 | // throw new UnsupportedOperationException( |
| 235 | // "Caller UID " + binder.getCallingUid() + " doesn't exist"); |
Robin Lee | 2c68dad | 2017-03-17 12:50:24 +0000 | [diff] [blame] | 236 | } |
| 237 | if (!permissions.contains(permission)) { |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 238 | throw new SecurityException("Caller doesn't have " + permission + " : " + message); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public void sendBroadcast(Intent intent) { |
| 244 | spiedContext.sendBroadcast(intent); |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public void sendBroadcast(Intent intent, String receiverPermission) { |
| 249 | spiedContext.sendBroadcast(intent, receiverPermission); |
| 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions) { |
| 254 | spiedContext.sendBroadcastMultiplePermissions(intent, receiverPermissions); |
| 255 | } |
| 256 | |
| 257 | @Override |
Tyler Gunn | f955e56 | 2018-04-26 14:43:31 -0700 | [diff] [blame] | 258 | public void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user, |
| 259 | String[] receiverPermissions) { |
| 260 | spiedContext.sendBroadcastAsUserMultiplePermissions(intent, user, receiverPermissions); |
| 261 | } |
| 262 | |
| 263 | @Override |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 264 | public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) { |
| 265 | spiedContext.sendBroadcast(intent, receiverPermission, options); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public void sendBroadcast(Intent intent, String receiverPermission, int appOp) { |
| 270 | spiedContext.sendBroadcast(intent, receiverPermission, appOp); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public void sendOrderedBroadcast(Intent intent, String receiverPermission) { |
| 275 | spiedContext.sendOrderedBroadcast(intent, receiverPermission); |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public void sendOrderedBroadcast(Intent intent, String receiverPermission, |
| 280 | BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, |
| 281 | String initialData, Bundle initialExtras) { |
| 282 | spiedContext.sendOrderedBroadcast(intent, receiverPermission, resultReceiver, scheduler, |
| 283 | initialCode, initialData, initialExtras); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void sendOrderedBroadcast(Intent intent, String receiverPermission, Bundle options, |
| 288 | BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, |
| 289 | String initialData, Bundle initialExtras) { |
| 290 | spiedContext.sendOrderedBroadcast(intent, receiverPermission, options, resultReceiver, |
| 291 | scheduler, |
| 292 | initialCode, initialData, initialExtras); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, |
| 297 | BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, |
| 298 | String initialData, Bundle initialExtras) { |
| 299 | spiedContext.sendOrderedBroadcast(intent, receiverPermission, appOp, resultReceiver, |
| 300 | scheduler, |
| 301 | initialCode, initialData, initialExtras); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public void sendBroadcastAsUser(Intent intent, UserHandle user) { |
Makoto Onuki | b643fb0 | 2015-09-22 15:03:44 -0700 | [diff] [blame] | 306 | if (binder.callingPid != SYSTEM_PID) { |
| 307 | // Unless called as the system process, can only call if the target user is the |
| 308 | // calling user. |
| 309 | // (The actual check is more complex; we may need to change it later.) |
| 310 | Assert.assertEquals(UserHandle.getUserId(binder.getCallingUid()), user.getIdentifier()); |
| 311 | } |
| 312 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 313 | spiedContext.sendBroadcastAsUser(intent, user); |
| 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission) { |
| 318 | spiedContext.sendBroadcastAsUser(intent, user, receiverPermission); |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, |
| 323 | int appOp) { |
| 324 | spiedContext.sendBroadcastAsUser(intent, user, receiverPermission, appOp); |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 329 | String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, |
| 330 | int initialCode, String initialData, Bundle initialExtras) { |
| 331 | spiedContext.sendOrderedBroadcastAsUser(intent, user, receiverPermission, resultReceiver, |
| 332 | scheduler, initialCode, initialData, initialExtras); |
Suprabh Shukla | 3cb2b49 | 2016-08-09 17:20:57 -0700 | [diff] [blame] | 333 | resultReceiver.onReceive(spiedContext, intent); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 338 | String receiverPermission, int appOp, BroadcastReceiver resultReceiver, |
| 339 | Handler scheduler, int initialCode, String initialData, Bundle initialExtras) { |
| 340 | spiedContext.sendOrderedBroadcastAsUser(intent, user, receiverPermission, appOp, |
| 341 | resultReceiver, |
| 342 | scheduler, initialCode, initialData, initialExtras); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 347 | String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver, |
| 348 | Handler scheduler, int initialCode, String initialData, Bundle initialExtras) { |
| 349 | spiedContext.sendOrderedBroadcastAsUser(intent, user, receiverPermission, appOp, options, |
| 350 | resultReceiver, scheduler, initialCode, initialData, initialExtras); |
| 351 | } |
| 352 | |
| 353 | @Override |
| 354 | public void sendStickyBroadcast(Intent intent) { |
| 355 | spiedContext.sendStickyBroadcast(intent); |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, |
| 360 | Handler scheduler, int initialCode, String initialData, Bundle initialExtras) { |
| 361 | spiedContext.sendStickyOrderedBroadcast(intent, resultReceiver, scheduler, initialCode, |
| 362 | initialData, initialExtras); |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public void removeStickyBroadcast(Intent intent) { |
| 367 | spiedContext.removeStickyBroadcast(intent); |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) { |
| 372 | spiedContext.sendStickyBroadcastAsUser(intent, user); |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 377 | BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, |
| 378 | String initialData, Bundle initialExtras) { |
| 379 | spiedContext.sendStickyOrderedBroadcastAsUser(intent, user, resultReceiver, scheduler, initialCode, |
| 380 | initialData, initialExtras); |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) { |
| 385 | spiedContext.removeStickyBroadcastAsUser(intent, user); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 390 | mMockSystemServices.registerReceiver(receiver, filter, null); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 391 | return spiedContext.registerReceiver(receiver, filter); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, |
| 396 | String broadcastPermission, Handler scheduler) { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 397 | mMockSystemServices.registerReceiver(receiver, filter, scheduler); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 398 | return spiedContext.registerReceiver(receiver, filter, broadcastPermission, scheduler); |
| 399 | } |
| 400 | |
| 401 | @Override |
| 402 | public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, |
| 403 | IntentFilter filter, String broadcastPermission, Handler scheduler) { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 404 | mMockSystemServices.registerReceiver(receiver, filter, scheduler); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 405 | return spiedContext.registerReceiverAsUser(receiver, user, filter, broadcastPermission, |
| 406 | scheduler); |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public void unregisterReceiver(BroadcastReceiver receiver) { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 411 | mMockSystemServices.unregisterReceiver(receiver); |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 412 | spiedContext.unregisterReceiver(receiver); |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 413 | } |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 414 | |
| 415 | @Override |
Robin Lee | 7f5c91c | 2017-02-08 21:27:02 +0000 | [diff] [blame] | 416 | public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) |
| 417 | throws PackageManager.NameNotFoundException { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 418 | return mMockSystemServices.createPackageContextAsUser(packageName, flags, user); |
Robin Lee | 7f5c91c | 2017-02-08 21:27:02 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Override |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 422 | public ContentResolver getContentResolver() { |
Pavel Grafov | 75c0a89 | 2017-05-18 17:28:27 +0100 | [diff] [blame] | 423 | return mMockSystemServices.contentResolver; |
Makoto Onuki | a52562c | 2015-10-01 16:12:31 -0700 | [diff] [blame] | 424 | } |
Bartosz Fabianowski | b21b241 | 2016-11-17 04:53:33 +0100 | [diff] [blame] | 425 | |
| 426 | @Override |
| 427 | public int getUserId() { |
| 428 | return UserHandle.getUserId(binder.getCallingUid()); |
| 429 | } |
Makoto Onuki | c9754cf | 2015-08-31 11:58:43 -0700 | [diff] [blame] | 430 | } |