aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java')
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java31
1 files changed, 12 insertions, 19 deletions
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java
index 86998b8f5..d55ba45c7 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowContextImpl.java
@@ -1,8 +1,5 @@
package org.robolectric.shadows;
-import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
-import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
-import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.N;
@@ -177,14 +174,14 @@ public class ShadowContextImpl {
intent, /*userHandle=*/ null, receiverPermission, realContextImpl);
}
- @Implementation(minSdk = JELLY_BEAN_MR1)
+ @Implementation
@RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
protected void sendBroadcastAsUser(@RequiresPermission Intent intent, UserHandle user) {
getShadowInstrumentation()
.sendBroadcastWithPermission(intent, user, /*receiverPermission=*/ null, realContextImpl);
}
- @Implementation(minSdk = JELLY_BEAN_MR1)
+ @Implementation
@RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
protected void sendBroadcastAsUser(
@RequiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission) {
@@ -224,7 +221,7 @@ public class ShadowContextImpl {
* Allows the test to query for the broadcasts for specific users, for everything else behaves as
* {@link #sendOrderedBroadcastAsUser}.
*/
- @Implementation(minSdk = JELLY_BEAN_MR1)
+ @Implementation
protected void sendOrderedBroadcastAsUser(
Intent intent,
UserHandle userHandle,
@@ -312,7 +309,7 @@ public class ShadowContextImpl {
.registerReceiver(receiver, filter, broadcastPermission, scheduler, flags, realContextImpl);
}
- @Implementation(minSdk = JELLY_BEAN_MR1)
+ @Implementation
protected Intent registerReceiverAsUser(
BroadcastReceiver receiver,
UserHandle user,
@@ -371,7 +368,7 @@ public class ShadowContextImpl {
}
// This is a private method in ContextImpl so we copy the relevant portions of it here.
- @Implementation(minSdk = KITKAT)
+ @Implementation
protected void validateServiceIntent(Intent service) {
if (service.getComponent() == null
&& service.getPackage() == null
@@ -396,7 +393,7 @@ public class ShadowContextImpl {
this.userId = userId;
}
- @Implementation(minSdk = JELLY_BEAN_MR2)
+ @Implementation
protected int getUserId() {
if (userId != null) {
return userId;
@@ -405,7 +402,7 @@ public class ShadowContextImpl {
}
}
- @Implementation(maxSdk = JELLY_BEAN_MR2)
+ @Implementation
protected File getExternalFilesDir(String type) {
File externalDir = Environment.getExternalStoragePublicDirectory(/* type= */ null);
if (externalDir == null) {
@@ -421,7 +418,7 @@ public class ShadowContextImpl {
return externalFilesDir;
}
- @Implementation(minSdk = KITKAT)
+ @Implementation
protected File[] getExternalFilesDirs(String type) {
return new File[] {getExternalFilesDir(type)};
}
@@ -430,11 +427,10 @@ public class ShadowContextImpl {
public static void reset() {
String prefsCacheFieldName =
RuntimeEnvironment.getApiLevel() >= N ? "sSharedPrefsCache" : "sSharedPrefs";
- Object prefsDefaultValue = RuntimeEnvironment.getApiLevel() >= KITKAT ? null : new HashMap<>();
Class<?> contextImplClass =
ReflectionHelpers.loadClass(
ShadowContextImpl.class.getClassLoader(), "android.app.ContextImpl");
- ReflectionHelpers.setStaticField(contextImplClass, prefsCacheFieldName, prefsDefaultValue);
+ ReflectionHelpers.setStaticField(contextImplClass, prefsCacheFieldName, null);
if (RuntimeEnvironment.getApiLevel() <= VERSION_CODES.LOLLIPOP_MR1) {
HashMap<String, Object> fetchers =
@@ -450,12 +446,9 @@ public class ShadowContextImpl {
}
}
- if (RuntimeEnvironment.getApiLevel() >= KITKAT) {
-
- Object windowServiceFetcher = fetchers.get(Context.WINDOW_SERVICE);
- ReflectionHelpers.setField(
- windowServiceFetcher.getClass(), windowServiceFetcher, "mDefaultDisplay", null);
- }
+ Object windowServiceFetcher = fetchers.get(Context.WINDOW_SERVICE);
+ ReflectionHelpers.setField(
+ windowServiceFetcher.getClass(), windowServiceFetcher, "mDefaultDisplay", null);
}
}