Loading core/java/android/app/ActivityThread.java +6 −0 Original line number Diff line number Diff line Loading @@ -182,6 +182,8 @@ import android.provider.DeviceConfigServiceManager; import android.provider.Downloads; import android.provider.FontsContract; import android.provider.Settings; import android.ravenwood.annotation.RavenwoodIgnore; import android.ravenwood.annotation.RavenwoodRedirect; import android.renderscript.RenderScriptCacheDir; import android.se.omapi.SeFrameworkInitializer; import android.se.omapi.SeServiceManager; Loading Loading @@ -3065,6 +3067,7 @@ public final class ActivityThread extends ClientTransactionHandler } @UnsupportedAppUsage @RavenwoodRedirect public Handler getHandler() { return mH; } Loading Loading @@ -3302,10 +3305,12 @@ public final class ActivityThread extends ClientTransactionHandler } @UnsupportedAppUsage @RavenwoodRedirect public Looper getLooper() { return mLooper; } @RavenwoodRedirect public Executor getExecutor() { return mExecutor; } Loading Loading @@ -9231,6 +9236,7 @@ public final class ActivityThread extends ClientTransactionHandler return false; } @RavenwoodIgnore void addApplication(@NonNull Application app) { mAllApplications.add(app); VMDebug.addApplication(app.mLoadedApk.mPackageName); Loading core/java/android/app/ActivityThread_ravenwood.java +30 −1 Original line number Diff line number Diff line Loading @@ -16,15 +16,32 @@ package android.app; import android.content.Context; import android.os.Handler; import android.os.HandlerExecutor; import android.os.Looper; import android.platform.test.ravenwood.RavenwoodAppDriver; import java.util.concurrent.Executor; /** * Inject Ravenwood methods to {@link ActivityThread}. * * TODO: Stop using Objensis to instantiate ActivityThread and start using more of the * real code, rather than handling all methods here with @RavenwoodRedirect. * At that point, the initialization logic should be moved from RavenwoodAppDriver to this class. */ public class ActivityThread_ravenwood { public final class ActivityThread_ravenwood { private ActivityThread_ravenwood() { } /** Backdoor to set ActivityThread's package-private member field. */ public static void setInstrumentation(ActivityThread at, Instrumentation inst) { at.mInstrumentation = inst; } private static final Handler sHandler = new Handler(Looper.getMainLooper()); private static final HandlerExecutor sHandlerExecutor = new HandlerExecutor(sHandler); /** Override the corresponding ActivityThread method. */ public static Context currentSystemContext() { return RavenwoodAppDriver.getInstance().getAndroidAppBridge().getSystemContext(); Loading @@ -34,4 +51,16 @@ public class ActivityThread_ravenwood { public static Application currentApplication() { return RavenwoodAppDriver.getInstance().getApplication(); } static Looper getLooper(ActivityThread at) { return Looper.getMainLooper(); } static Handler getHandler(ActivityThread at) { return sHandler; } static Executor getExecutor(ActivityThread at) { return sHandlerExecutor; } } core/java/android/app/Application_ravenwood.java +3 −3 Original line number Diff line number Diff line Loading @@ -24,8 +24,8 @@ import android.content.Context; * It's more of a "reverse" redirect class. */ public class Application_ravenwood { /** Calls {@link Application#attach} */ public static void attach(Application application, Context context) { application.attach(context); /** Backdoor to {@link Application#attach}, which is package-private */ public static void attachBaseContext(Application application, Context baseContext) { application.attach(baseContext); } } core/java/android/app/ContextImpl.java +50 −15 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ import android.ravenwood.annotation.RavenwoodKeepPartialClass; import android.ravenwood.annotation.RavenwoodRedirect; import android.ravenwood.annotation.RavenwoodRedirectionClass; import android.ravenwood.annotation.RavenwoodReplace; import android.ravenwood.annotation.RavenwoodSupported.RavenwoodProvidingImplementation; import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; Loading Loading @@ -206,6 +207,7 @@ class ReceiverRestrictedContext extends ContextWrapper { */ @RavenwoodKeepPartialClass @RavenwoodRedirectionClass("ContextImpl_ravenwood") @RavenwoodProvidingImplementation(target = Context.class) class ContextImpl extends Context { private final static String TAG = "ContextImpl"; private final static boolean DEBUG = false; Loading Loading @@ -381,16 +383,7 @@ class ContextImpl extends Context { // The system service cache for the system services that are cached per-ContextImpl. @UnsupportedAppUsage final Object[] mServiceCache = createServiceCache(); @RavenwoodReplace private static Object[] createServiceCache() { return SystemServiceRegistry.createServiceCache(); } private static Object[] createServiceCache$ravenwood() { return new Object[0]; } final Object[] mServiceCache = SystemServiceRegistry.createServiceCache(); static final int STATE_UNINITIALIZED = 0; static final int STATE_INITIALIZING = 1; Loading Loading @@ -455,17 +448,23 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public PackageManager getPackageManager() { if (mPackageManager != null) { return mPackageManager; } // Doesn't matter if we make more than one instance, so no synchronization // is needed on mPackageManager. mPackageManager = getPackageManagerInner(); return mPackageManager; } @RavenwoodRedirect private PackageManager getPackageManagerInner() { final IPackageManager pm = ActivityThread.getPackageManager(); if (pm != null) { // Doesn't matter if we make more than one instance. return (mPackageManager = new ApplicationPackageManager(this, pm)); return new ApplicationPackageManager(this, pm); } return null; } Loading Loading @@ -512,6 +511,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public Resources.Theme getTheme() { synchronized (mThemeLock) { if (mTheme != null) { Loading @@ -520,12 +520,13 @@ class ContextImpl extends Context { mThemeResource = Resources.selectDefaultTheme(mThemeResource, getOuterContext().getApplicationInfo().targetSdkVersion); initializeTheme(); initializeTheme(); // XXX TODO: does it work?? return mTheme; } } @RavenwoodKeep private void initializeTheme() { if (mTheme == null) { mTheme = mResources.newTheme(); Loading Loading @@ -584,6 +585,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public ApplicationInfo getApplicationInfo() { if (mPackageInfo != null) { return mPackageInfo.getApplicationInfo(); Loading @@ -592,6 +594,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public String getPackageResourcePath() { if (mPackageInfo != null) { return mPackageInfo.getResDir(); Loading Loading @@ -791,6 +794,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public FileInputStream openFileInput(String name) throws FileNotFoundException { File f = makeFilename(getFilesDir(), name); Loading @@ -798,6 +802,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException { checkMode(mode); final boolean append = (mode&MODE_APPEND) != 0; Loading @@ -821,6 +826,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public boolean deleteFile(String name) { File f = makeFilename(getFilesDir(), name); return f.delete(); Loading @@ -829,15 +835,18 @@ class ContextImpl extends Context { /** * Common-path handling of app data dir creation */ @RavenwoodKeep private static File ensurePrivateDirExists(File file) { return ensurePrivateDirExists(file, 0771, -1, null); } @RavenwoodKeep(comment = "xattr is ignored") private static File ensurePrivateCacheDirExists(File file, String xattr) { final int gid = UserHandle.getCacheAppGid(Process.myUid()); return ensurePrivateDirExists(file, 02771, gid, xattr); } @RavenwoodRedirect(comment = "gid, xattr are ignored") private static File ensurePrivateDirExists(File file, int mode, int gid, String xattr) { if (!file.exists()) { final String path = file.getAbsolutePath(); Loading Loading @@ -870,6 +879,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getFilesDir() { synchronized (mFilesDirLock) { if (mFilesDir == null) { Loading Loading @@ -898,6 +908,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getNoBackupFilesDir() { synchronized (mNoBackupFilesDirLock) { if (mNoBackupFilesDir == null) { Loading Loading @@ -941,6 +952,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getCacheDir() { synchronized (mCacheDirLock) { if (mCacheDir == null) { Loading @@ -951,6 +963,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getCodeCacheDir() { synchronized (mCodeCacheDirLock) { if (mCodeCacheDir == null) { Loading Loading @@ -1005,11 +1018,13 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getFileStreamPath(String name) { return makeFilename(getFilesDir(), name); } @Override @RavenwoodKeep public File getSharedPreferencesPath(String name) { return makeFilename(getPreferencesDir(), name + ".xml"); } Loading Loading @@ -2342,6 +2357,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public Object getSystemService(String name) { if (vmIncorrectContextUseEnabled()) { // Check incorrect Context usage. Loading @@ -2362,6 +2378,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public String getSystemServiceName(Class<?> serviceClass) { return SystemServiceRegistry.getSystemServiceName(serviceClass); } Loading Loading @@ -2394,6 +2411,7 @@ class ContextImpl extends Context { * TODO(b/147647877): Fix usages and remove. */ @SuppressWarnings("AndroidFrameworkClientSidePermissionCheck") @RavenwoodIgnore // Always false on Ravenwood. private static boolean isSystemOrSystemUI(Context context) { return ActivityThread.isSystem() || context.checkPermission( "android.permission.STATUS_BAR_SERVICE", Loading Loading @@ -3185,16 +3203,19 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public boolean isDeviceProtectedStorage() { return (mFlags & Context.CONTEXT_DEVICE_PROTECTED_STORAGE) != 0; } @Override @RavenwoodKeep public boolean isCredentialProtectedStorage() { return (mFlags & Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) != 0; } @Override @RavenwoodKeep public boolean canLoadUnsafeResources() { if (getPackageName().equals(getOpPackageName())) { return true; Loading Loading @@ -3382,6 +3403,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getDataDir() { if (mPackageInfo != null) { File res = null; Loading Loading @@ -3410,6 +3432,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getDir(String name, int mode) { checkMode(mode); name = "app_" + name; Loading Loading @@ -3516,10 +3539,12 @@ class ContextImpl extends Context { } @UnsupportedAppUsage @RavenwoodKeep static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { return createAppContext(mainThread, packageInfo, null); } @RavenwoodKeep static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo, String opPackageName) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); Loading Loading @@ -3752,11 +3777,13 @@ class ContextImpl extends Context { } @UnsupportedAppUsage @RavenwoodKeep final void setOuterContext(@NonNull Context context) { mOuterContext = context; } @UnsupportedAppUsage @RavenwoodKeep final Context getOuterContext() { return mOuterContext; } Loading @@ -3778,6 +3805,7 @@ class ContextImpl extends Context { } } @RavenwoodIgnore(comment = "Not simulating file permissions") private void checkMode(int mode) { if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { if ((mode & MODE_WORLD_READABLE) != 0) { Loading @@ -3790,6 +3818,7 @@ class ContextImpl extends Context { } @SuppressWarnings("deprecation") @RavenwoodIgnore(comment = "Not simulating file permissions") static void setFilePermissionsFromMode(String name, int mode, int extraPermissions) { int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR Loading @@ -3808,18 +3837,24 @@ class ContextImpl extends Context { FileUtils.setPermissions(name, perms, -1, -1); } @RavenwoodKeep private File makeFilename(File base, String name) { if (name.indexOf(File.separatorChar) < 0) { final File res = new File(base, name); // We report as filesystem access here to give us the best shot at // detecting apps that will pass the path down to native code. BlockGuard.getVmPolicy().onPathAccess(res.getPath()); onPathAccess(res.getPath()); return res; } throw new IllegalArgumentException( "File " + name + " contains a path separator"); } @RavenwoodIgnore(blockedBy = BlockGuard.class) private static void onPathAccess(@NonNull String path) { BlockGuard.getVmPolicy().onPathAccess(path); } /** * Ensure that given directories exist, trying to create them if missing. If * unable to create, they are filtered by replacing with {@code null}. Loading core/java/android/app/ContextImpl_ravenwood.java +48 −0 Original line number Diff line number Diff line Loading @@ -15,5 +15,53 @@ */ package android.app; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import android.content.Context; import android.content.pm.PackageManager; import android.os.FileUtils; import android.platform.test.ravenwood.RavenwoodPackageManager; import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; public class ContextImpl_ravenwood { private static final String TAG = "ContextImpl_ravenwood"; /** Indicates a {@link Context} is really a {@link ContextImpl}. */ @Target({FIELD, METHOD, PARAMETER}) @Retention(RetentionPolicy.SOURCE) public @interface ReallyContextImpl { } /** Backdoor to a package-private method. */ public static ContextImpl createSystemContext(ActivityThread at) { return ContextImpl.createSystemContext(at); } /** Backdoor to a package-private method. */ public static ContextImpl createAppContext(ActivityThread at, LoadedApk la) { return ContextImpl.createAppContext(at, la); } static PackageManager getPackageManagerInner(ContextImpl contextImpl) { return new RavenwoodPackageManager(contextImpl); } static File ensurePrivateDirExists(File file, int mode, int gid, String xattr) { if (!file.exists()) { final String path = file.getAbsolutePath(); file.mkdirs(); // setPermissions() may fail and return an error status, but we just ignore // it just like the real method ignores exceptions. // setPermissions() does a log though. FileUtils.setPermissions(path, mode, -1, -1); } return file; } } Loading
core/java/android/app/ActivityThread.java +6 −0 Original line number Diff line number Diff line Loading @@ -182,6 +182,8 @@ import android.provider.DeviceConfigServiceManager; import android.provider.Downloads; import android.provider.FontsContract; import android.provider.Settings; import android.ravenwood.annotation.RavenwoodIgnore; import android.ravenwood.annotation.RavenwoodRedirect; import android.renderscript.RenderScriptCacheDir; import android.se.omapi.SeFrameworkInitializer; import android.se.omapi.SeServiceManager; Loading Loading @@ -3065,6 +3067,7 @@ public final class ActivityThread extends ClientTransactionHandler } @UnsupportedAppUsage @RavenwoodRedirect public Handler getHandler() { return mH; } Loading Loading @@ -3302,10 +3305,12 @@ public final class ActivityThread extends ClientTransactionHandler } @UnsupportedAppUsage @RavenwoodRedirect public Looper getLooper() { return mLooper; } @RavenwoodRedirect public Executor getExecutor() { return mExecutor; } Loading Loading @@ -9231,6 +9236,7 @@ public final class ActivityThread extends ClientTransactionHandler return false; } @RavenwoodIgnore void addApplication(@NonNull Application app) { mAllApplications.add(app); VMDebug.addApplication(app.mLoadedApk.mPackageName); Loading
core/java/android/app/ActivityThread_ravenwood.java +30 −1 Original line number Diff line number Diff line Loading @@ -16,15 +16,32 @@ package android.app; import android.content.Context; import android.os.Handler; import android.os.HandlerExecutor; import android.os.Looper; import android.platform.test.ravenwood.RavenwoodAppDriver; import java.util.concurrent.Executor; /** * Inject Ravenwood methods to {@link ActivityThread}. * * TODO: Stop using Objensis to instantiate ActivityThread and start using more of the * real code, rather than handling all methods here with @RavenwoodRedirect. * At that point, the initialization logic should be moved from RavenwoodAppDriver to this class. */ public class ActivityThread_ravenwood { public final class ActivityThread_ravenwood { private ActivityThread_ravenwood() { } /** Backdoor to set ActivityThread's package-private member field. */ public static void setInstrumentation(ActivityThread at, Instrumentation inst) { at.mInstrumentation = inst; } private static final Handler sHandler = new Handler(Looper.getMainLooper()); private static final HandlerExecutor sHandlerExecutor = new HandlerExecutor(sHandler); /** Override the corresponding ActivityThread method. */ public static Context currentSystemContext() { return RavenwoodAppDriver.getInstance().getAndroidAppBridge().getSystemContext(); Loading @@ -34,4 +51,16 @@ public class ActivityThread_ravenwood { public static Application currentApplication() { return RavenwoodAppDriver.getInstance().getApplication(); } static Looper getLooper(ActivityThread at) { return Looper.getMainLooper(); } static Handler getHandler(ActivityThread at) { return sHandler; } static Executor getExecutor(ActivityThread at) { return sHandlerExecutor; } }
core/java/android/app/Application_ravenwood.java +3 −3 Original line number Diff line number Diff line Loading @@ -24,8 +24,8 @@ import android.content.Context; * It's more of a "reverse" redirect class. */ public class Application_ravenwood { /** Calls {@link Application#attach} */ public static void attach(Application application, Context context) { application.attach(context); /** Backdoor to {@link Application#attach}, which is package-private */ public static void attachBaseContext(Application application, Context baseContext) { application.attach(baseContext); } }
core/java/android/app/ContextImpl.java +50 −15 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ import android.ravenwood.annotation.RavenwoodKeepPartialClass; import android.ravenwood.annotation.RavenwoodRedirect; import android.ravenwood.annotation.RavenwoodRedirectionClass; import android.ravenwood.annotation.RavenwoodReplace; import android.ravenwood.annotation.RavenwoodSupported.RavenwoodProvidingImplementation; import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; Loading Loading @@ -206,6 +207,7 @@ class ReceiverRestrictedContext extends ContextWrapper { */ @RavenwoodKeepPartialClass @RavenwoodRedirectionClass("ContextImpl_ravenwood") @RavenwoodProvidingImplementation(target = Context.class) class ContextImpl extends Context { private final static String TAG = "ContextImpl"; private final static boolean DEBUG = false; Loading Loading @@ -381,16 +383,7 @@ class ContextImpl extends Context { // The system service cache for the system services that are cached per-ContextImpl. @UnsupportedAppUsage final Object[] mServiceCache = createServiceCache(); @RavenwoodReplace private static Object[] createServiceCache() { return SystemServiceRegistry.createServiceCache(); } private static Object[] createServiceCache$ravenwood() { return new Object[0]; } final Object[] mServiceCache = SystemServiceRegistry.createServiceCache(); static final int STATE_UNINITIALIZED = 0; static final int STATE_INITIALIZING = 1; Loading Loading @@ -455,17 +448,23 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public PackageManager getPackageManager() { if (mPackageManager != null) { return mPackageManager; } // Doesn't matter if we make more than one instance, so no synchronization // is needed on mPackageManager. mPackageManager = getPackageManagerInner(); return mPackageManager; } @RavenwoodRedirect private PackageManager getPackageManagerInner() { final IPackageManager pm = ActivityThread.getPackageManager(); if (pm != null) { // Doesn't matter if we make more than one instance. return (mPackageManager = new ApplicationPackageManager(this, pm)); return new ApplicationPackageManager(this, pm); } return null; } Loading Loading @@ -512,6 +511,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public Resources.Theme getTheme() { synchronized (mThemeLock) { if (mTheme != null) { Loading @@ -520,12 +520,13 @@ class ContextImpl extends Context { mThemeResource = Resources.selectDefaultTheme(mThemeResource, getOuterContext().getApplicationInfo().targetSdkVersion); initializeTheme(); initializeTheme(); // XXX TODO: does it work?? return mTheme; } } @RavenwoodKeep private void initializeTheme() { if (mTheme == null) { mTheme = mResources.newTheme(); Loading Loading @@ -584,6 +585,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public ApplicationInfo getApplicationInfo() { if (mPackageInfo != null) { return mPackageInfo.getApplicationInfo(); Loading @@ -592,6 +594,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public String getPackageResourcePath() { if (mPackageInfo != null) { return mPackageInfo.getResDir(); Loading Loading @@ -791,6 +794,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public FileInputStream openFileInput(String name) throws FileNotFoundException { File f = makeFilename(getFilesDir(), name); Loading @@ -798,6 +802,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException { checkMode(mode); final boolean append = (mode&MODE_APPEND) != 0; Loading @@ -821,6 +826,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public boolean deleteFile(String name) { File f = makeFilename(getFilesDir(), name); return f.delete(); Loading @@ -829,15 +835,18 @@ class ContextImpl extends Context { /** * Common-path handling of app data dir creation */ @RavenwoodKeep private static File ensurePrivateDirExists(File file) { return ensurePrivateDirExists(file, 0771, -1, null); } @RavenwoodKeep(comment = "xattr is ignored") private static File ensurePrivateCacheDirExists(File file, String xattr) { final int gid = UserHandle.getCacheAppGid(Process.myUid()); return ensurePrivateDirExists(file, 02771, gid, xattr); } @RavenwoodRedirect(comment = "gid, xattr are ignored") private static File ensurePrivateDirExists(File file, int mode, int gid, String xattr) { if (!file.exists()) { final String path = file.getAbsolutePath(); Loading Loading @@ -870,6 +879,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getFilesDir() { synchronized (mFilesDirLock) { if (mFilesDir == null) { Loading Loading @@ -898,6 +908,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getNoBackupFilesDir() { synchronized (mNoBackupFilesDirLock) { if (mNoBackupFilesDir == null) { Loading Loading @@ -941,6 +952,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getCacheDir() { synchronized (mCacheDirLock) { if (mCacheDir == null) { Loading @@ -951,6 +963,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getCodeCacheDir() { synchronized (mCodeCacheDirLock) { if (mCodeCacheDir == null) { Loading Loading @@ -1005,11 +1018,13 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getFileStreamPath(String name) { return makeFilename(getFilesDir(), name); } @Override @RavenwoodKeep public File getSharedPreferencesPath(String name) { return makeFilename(getPreferencesDir(), name + ".xml"); } Loading Loading @@ -2342,6 +2357,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public Object getSystemService(String name) { if (vmIncorrectContextUseEnabled()) { // Check incorrect Context usage. Loading @@ -2362,6 +2378,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public String getSystemServiceName(Class<?> serviceClass) { return SystemServiceRegistry.getSystemServiceName(serviceClass); } Loading Loading @@ -2394,6 +2411,7 @@ class ContextImpl extends Context { * TODO(b/147647877): Fix usages and remove. */ @SuppressWarnings("AndroidFrameworkClientSidePermissionCheck") @RavenwoodIgnore // Always false on Ravenwood. private static boolean isSystemOrSystemUI(Context context) { return ActivityThread.isSystem() || context.checkPermission( "android.permission.STATUS_BAR_SERVICE", Loading Loading @@ -3185,16 +3203,19 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public boolean isDeviceProtectedStorage() { return (mFlags & Context.CONTEXT_DEVICE_PROTECTED_STORAGE) != 0; } @Override @RavenwoodKeep public boolean isCredentialProtectedStorage() { return (mFlags & Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) != 0; } @Override @RavenwoodKeep public boolean canLoadUnsafeResources() { if (getPackageName().equals(getOpPackageName())) { return true; Loading Loading @@ -3382,6 +3403,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getDataDir() { if (mPackageInfo != null) { File res = null; Loading Loading @@ -3410,6 +3432,7 @@ class ContextImpl extends Context { } @Override @RavenwoodKeep public File getDir(String name, int mode) { checkMode(mode); name = "app_" + name; Loading Loading @@ -3516,10 +3539,12 @@ class ContextImpl extends Context { } @UnsupportedAppUsage @RavenwoodKeep static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { return createAppContext(mainThread, packageInfo, null); } @RavenwoodKeep static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo, String opPackageName) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); Loading Loading @@ -3752,11 +3777,13 @@ class ContextImpl extends Context { } @UnsupportedAppUsage @RavenwoodKeep final void setOuterContext(@NonNull Context context) { mOuterContext = context; } @UnsupportedAppUsage @RavenwoodKeep final Context getOuterContext() { return mOuterContext; } Loading @@ -3778,6 +3805,7 @@ class ContextImpl extends Context { } } @RavenwoodIgnore(comment = "Not simulating file permissions") private void checkMode(int mode) { if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { if ((mode & MODE_WORLD_READABLE) != 0) { Loading @@ -3790,6 +3818,7 @@ class ContextImpl extends Context { } @SuppressWarnings("deprecation") @RavenwoodIgnore(comment = "Not simulating file permissions") static void setFilePermissionsFromMode(String name, int mode, int extraPermissions) { int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR Loading @@ -3808,18 +3837,24 @@ class ContextImpl extends Context { FileUtils.setPermissions(name, perms, -1, -1); } @RavenwoodKeep private File makeFilename(File base, String name) { if (name.indexOf(File.separatorChar) < 0) { final File res = new File(base, name); // We report as filesystem access here to give us the best shot at // detecting apps that will pass the path down to native code. BlockGuard.getVmPolicy().onPathAccess(res.getPath()); onPathAccess(res.getPath()); return res; } throw new IllegalArgumentException( "File " + name + " contains a path separator"); } @RavenwoodIgnore(blockedBy = BlockGuard.class) private static void onPathAccess(@NonNull String path) { BlockGuard.getVmPolicy().onPathAccess(path); } /** * Ensure that given directories exist, trying to create them if missing. If * unable to create, they are filtered by replacing with {@code null}. Loading
core/java/android/app/ContextImpl_ravenwood.java +48 −0 Original line number Diff line number Diff line Loading @@ -15,5 +15,53 @@ */ package android.app; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import android.content.Context; import android.content.pm.PackageManager; import android.os.FileUtils; import android.platform.test.ravenwood.RavenwoodPackageManager; import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; public class ContextImpl_ravenwood { private static final String TAG = "ContextImpl_ravenwood"; /** Indicates a {@link Context} is really a {@link ContextImpl}. */ @Target({FIELD, METHOD, PARAMETER}) @Retention(RetentionPolicy.SOURCE) public @interface ReallyContextImpl { } /** Backdoor to a package-private method. */ public static ContextImpl createSystemContext(ActivityThread at) { return ContextImpl.createSystemContext(at); } /** Backdoor to a package-private method. */ public static ContextImpl createAppContext(ActivityThread at, LoadedApk la) { return ContextImpl.createAppContext(at, la); } static PackageManager getPackageManagerInner(ContextImpl contextImpl) { return new RavenwoodPackageManager(contextImpl); } static File ensurePrivateDirExists(File file, int mode, int gid, String xattr) { if (!file.exists()) { final String path = file.getAbsolutePath(); file.mkdirs(); // setPermissions() may fail and return an error status, but we just ignore // it just like the real method ignores exceptions. // setPermissions() does a log though. FileUtils.setPermissions(path, mode, -1, -1); } return file; } }