/** * Install the condom protection for current process if it is not the default process. * * <p>This method must be called in {@link Application#onCreate()} to eliminate potential leakage. */ public static void installExceptDefaultProcess(final Application app) { installExceptDefaultProcess(app, new CondomOptions()); }
@Override public ProviderInfo resolveContentProvider(final String name, final int flags) { final ProviderInfo provider = super.resolveContentProvider(name, flags); if (! mCondom.shouldAllowProvider(provider)) return null; return provider; }
@Override public List<PackageInfo> getInstalledPackages(final int flags) { mCondom.logConcern(TAG, "PackageManager.getInstalledPackages"); return super.getInstalledPackages(flags); }
@Test public void testPreventNone() { final TestContext context = new TestContext(); final CondomOptions options = new CondomOptions().preventServiceInBackgroundPackages(false).preventBroadcastToBackgroundPackages(false); final CondomContext condom = CondomContext.wrap(context, TAG, options), dry_condom = CondomContext.wrap(context, TAG, options.setDryRun(true)); //noinspection deprecation, intentional test for deprecated method condom.preventWakingUpStoppedPackages(false); //noinspection deprecation dry_condom.preventWakingUpStoppedPackages(false); for (final Context context2test : new Context[] {condom, condom.getApplicationContext(), dry_condom, dry_condom.getApplicationContext()}) with(ALL_SORT_OF_INTENTS, allBroadcastAndServiceApis(context2test), context.EXPECT_BASE_CALLED, context.expectFlags(0)); }
@Test public void testPreventBroadcastToBackgroundPackages() { final TestContext context = new TestContext(); final CondomOptions options = new CondomOptions().preventBroadcastToBackgroundPackages(true); final CondomContext condom = CondomContext.wrap(context, TAG, options), dry_condom = CondomContext.wrap(context, TAG, options.setDryRun(true)); final int extra_flag = SDK_INT >= N ? CondomCore.FLAG_RECEIVER_EXCLUDE_BACKGROUND : FLAG_RECEIVER_REGISTERED_ONLY; for (final Context context2test : new Context[] {condom, condom.getApplicationContext()}) with(ALL_SORT_OF_INTENTS, allBroadcastApis(context2test), context.EXPECT_BASE_CALLED, context.expectFlags(FLAG_EXCLUDE_STOPPED_PACKAGES | extra_flag)); for (final Context context2test : new Context[] {dry_condom, dry_condom.getApplicationContext()}) with(ALL_SORT_OF_INTENTS, allBroadcastApis(context2test), context.EXPECT_BASE_CALLED, context.expectFlags(0)); }
@Override public boolean bindService(final Intent intent, final ServiceConnection conn, final int flags) { final boolean result = mCondom.proceed(OutboundType.BIND_SERVICE, intent, Boolean.FALSE, new CondomCore.WrappedValueProcedure<Boolean>() { @Override public Boolean proceed() { return CondomContext.super.bindService(intent, conn, flags); }}); if (result) mCondom.logIfOutboundPass(TAG, intent, CondomCore.getTargetPackage(intent), CondomCore.CondomEvent.BIND_PASS); return result; }
@Override public IContentProvider acquireUnstableProvider(final Context context, final String name) { if (! mCondom.shouldAllowProvider(context, name, PackageManager.MATCH_ALL)) return null; return super.acquireUnstableProvider(context, name); }
@Override public List<ApplicationInfo> getInstalledApplications(final int flags) { mCondom.logConcern(TAG, "PackageManager.getInstalledApplications"); return super.getInstalledApplications(flags); }
@Override public IContentProvider acquireProvider(final Context context, final String name) { if (! mCondom.shouldAllowProvider(context, name, PackageManager.MATCH_ALL)) return null; return super.acquireProvider(context, name); }
@Override public ResolveInfo resolveService(final Intent intent, final int flags) { check(intent); return buildResolveInfo(DISALLOWED_PACKAGE, true, 7777777); // Must be consistent with the first entry from queryIntentServices(). }
@Override public void sendOrderedBroadcast(final Intent intent, final String receiverPermission) { mCondom.proceedBroadcast(this, intent, new CondomCore.WrappedProcedure() { @Override public void run() { CondomContext.super.sendOrderedBroadcast(intent, receiverPermission); }}, null); }
@Override public int checkPermission(final String permName, final String pkgName) { return mCondom.proceed(OutboundType.CHECK_PERMISSION, pkgName, PERMISSION_DENIED, new CondomCore.WrappedValueProcedure<Integer>() { @Override public Integer proceed() { return CondomPackageManager.super.checkPermission(permName, pkgName); } }); }
/** * Install the condom protection for current process. This method should generally never be called in the main process of app. * * <p>It is suggested to use {@link android.content.ContentProvider ContentProvider} with "android:process", to install it in specified process. */ public static void installInCurrentProcess(final Application app, final String tag, final CondomOptions options) { install(app, tag, options); }
context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { future.set(getResultCode()); }}, null, Activity.RESULT_CANCELED, null, null); final int result = waitForCompletion(future);
final Runnable EXPECT_OUTBOUND_JUDGE_PASS = new Runnable() { @Override public void run() { context.assertBaseCalled(); assertOutboundJudgeCalled(1); }}; for (final Context context2test : new Context[] {condom, condom.getApplicationContext()})
@Override public void sendBroadcast(final Intent intent) { mCondom.proceedBroadcast(this, intent, new CondomCore.WrappedProcedure() { @Override public void run() { CondomContext.super.sendBroadcast(intent); }}, null); }
@Override public ApplicationInfo getApplicationInfo(final String pkg, final int flags) throws NameNotFoundException { return mCondom.proceed(OutboundType.GET_APPLICATION_INFO, pkg, null, new CondomCore.WrappedValueProcedureThrows<ApplicationInfo, NameNotFoundException>() { @Override public ApplicationInfo proceed() throws NameNotFoundException { return CondomPackageManager.super.getApplicationInfo(pkg, flags); } }); }
@Override public void sendOrderedBroadcast(final Intent intent, final String receiverPermission, final BroadcastReceiver resultReceiver, final Handler scheduler, final int initialCode, final String initialData, final Bundle initialExtras) { mCondom.proceedBroadcast(this, intent, new CondomCore.WrappedProcedure() { @Override public void run() { CondomContext.super.sendOrderedBroadcast(intent, receiverPermission, resultReceiver, scheduler, initialCode, initialData, initialExtras); }}, resultReceiver); }
@Override public void sendOrderedBroadcast(final Intent intent, final String receiverPermission) { mCondom.proceedBroadcast(this, intent, new CondomCore.WrappedProcedure() { @Override public void run() { mApplication.sendOrderedBroadcast(intent, receiverPermission); }}, null); }
@Override public void sendBroadcast(final Intent intent, final String receiverPermission) { mCondom.proceedBroadcast(this, intent, new CondomCore.WrappedProcedure() { @Override public void run() { mApplication.sendBroadcast(intent, receiverPermission); }}, null); }