@Implementation @Nullable protected <T> T get(Key<T> key) { return (T) charactersKeyToValue.get(key); }
@Implementation @Nullable protected PackageInstaller.SessionInfo getSessionInfo(int sessionId) { return sessionInfos.get(sessionId); }
@Implementation protected @Nullable String getNameForUid(int uid) { return namesForUid.get(uid); }
@Implementation(minSdk = M) protected @Nullable Object getPrimaryStorageCurrentVolume() { return null; }
/** Prevents calling Android-only methods on basic ByteBuffer objects. */ @Implementation(minSdk = LOLLIPOP) protected void invalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index) {}
/** Prevents attempting to free non-direct ByteBuffer objects. */ @Implementation(minSdk = LOLLIPOP) protected void freeByteBuffer(@Nullable ByteBuffer buffer) {}
/** Prevents calling Android-only methods on basic ByteBuffer objects. */ @Implementation(minSdk = LOLLIPOP) protected void validateInputByteBuffer(@Nullable ByteBuffer[] buffers, int index) {}
/** Prevents calling Android-only methods on basic ByteBuffer objects. */ @Implementation(minSdk = LOLLIPOP) protected void revalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index) {}
/** Prevents calling Android-only methods on basic ByteBuffer objects. */ @Implementation(minSdk = LOLLIPOP) protected void invalidateByteBuffers(@Nullable ByteBuffer[] buffers) {}
@Implementation protected @Nullable String[] getPackagesForUid(int uid) { String[] packageNames = packagesForUid.get(uid); if (packageNames != null) { return packageNames; } Set<String> results = new HashSet<>(); for (PackageInfo packageInfo : packageInfos.values()) { if (packageInfo.applicationInfo != null && packageInfo.applicationInfo.uid == uid) { results.add(packageInfo.packageName); } } return results.isEmpty() ? null : results.toArray(new String[results.size()]); }
@android.annotation.Nullable String getNullable(); }
@Implements(value = Sms.class, minSdk = VERSION_CODES.KITKAT) public static class ShadowSms { @Nullable private static String defaultSmsPackage; @Implementation protected static String getDefaultSmsPackage(Context context) { return defaultSmsPackage; } /** * Override the package name returned from calling {@link Sms#getDefaultSmsPackage(Context)}. * * <p>This will be reset for the next test. */ public static void setDefaultSmsPackage(String defaultSmsPackage) { ShadowSms.defaultSmsPackage = defaultSmsPackage; } @Resetter public static synchronized void reset() { defaultSmsPackage = null; } } }
@Nullable @Implementation protected Drawable getDrawable( String packageName, @DrawableRes int resId, @Nullable ApplicationInfo appInfo) { Drawable result = drawables.get(new Pair<>(packageName, resId)); if (result != null) { return result; } return Shadow.directlyOn(realObject, ApplicationPackageManager.class) .getDrawable(packageName, resId, appInfo); }
@Nullable public ModeAndException getRestriction(int code, @AttributeUsage int usage) { // this gives us room for 256 op_codes. There are 78 as of P. return audioRestrictions.get(getAudioRestrictionKey(code, usage)); }
/** * Prevents calling Android-only methods on basic ByteBuffer objects. Replicates existing behavior * adjusting buffer positions and limits. */ @Implementation(minSdk = LOLLIPOP) protected void validateOutputByteBuffer( @Nullable ByteBuffer[] buffers, int index, @NonNull BufferInfo info) { if (buffers != null && index >= 0 && index < buffers.length) { ByteBuffer buffer = buffers[index]; if (buffer != null) { buffer.limit(info.offset + info.size).position(info.offset); } } }
@Implementation(minSdk = LOLLIPOP) @Nullable protected List<String> getPermittedInputMethods(ComponentName admin) { enforceDeviceOwnerOrProfileOwner(admin); return permittedInputMethods; }
@Implementation(minSdk = LOLLIPOP) @Nullable protected List<String> getPermittedAccessibilityServices(ComponentName admin) { enforceDeviceOwnerOrProfileOwner(admin); return permittedAccessibilityServices; }
private void applyFlagsToApplicationInfo(@Nullable ApplicationInfo appInfo, int flags) throws NameNotFoundException { if (appInfo == null) { return; } String packageName = appInfo.packageName; Integer stateOverride = applicationEnabledSettingMap.get(packageName); if (stateOverride == null) { stateOverride = COMPONENT_ENABLED_STATE_DEFAULT; } appInfo.enabled = (appInfo.enabled && stateOverride == COMPONENT_ENABLED_STATE_DEFAULT) || stateOverride == COMPONENT_ENABLED_STATE_ENABLED; if (deletedPackages.contains(packageName)) { appInfo.flags &= ~FLAG_INSTALLED; } if ((flags & MATCH_ALL) != 0 && Build.VERSION.SDK_INT >= 23) { return; } if ((flags & MATCH_UNINSTALLED_PACKAGES) == 0 && (appInfo.flags & FLAG_INSTALLED) == 0) { throw new NameNotFoundException("Package not installed: " + packageName); } if ((flags & MATCH_UNINSTALLED_PACKAGES) == 0 && hiddenPackages.contains(packageName)) { throw new NameNotFoundException("Package hidden: " + packageName); } }
/** * Returns the handle to a system-level service by name. If the service is not available in * Roboletric, or it is set to unavailable in {@link ShadowServiceManager#setServiceAvailability}, * {@code null} will be returned. */ @Implementation @Nullable protected Object getSystemService(String name) { if (removedSystemServices.contains(name)) { return null; } if (!systemServices.containsKey(name)) { return directlyOn( realContextImpl, ShadowContextImpl.CLASS_NAME, "getSystemService", ClassParameter.from(String.class, name)); } return systemServices.get(name); }