private CondomContext(final CondomCore condom, final @Nullable Context app_context, final @Nullable @Size(max=16) String tag) { super(condom.mBase); final Context base = condom.mBase; mCondom = condom; mApplicationContext = app_context != null ? app_context : this; mBaseContext = new Lazy<Context>() { @Override protected Context create() { return new PseudoContextImpl(CondomContext.this); }}; TAG = CondomCore.buildLogTag("Condom", "Condom.", tag); }
CondomApplication(final CondomCore condom, final Application app, final @Nullable @Size(max = 13) String tag) { mCondom = condom; mApplication = app; TAG = CondomCore.buildLogTag("CondomApp", "CondomApp.", tag); }
/** * This is the very first (probably only) API you need to wrap the naked {@link Context} under protection of <code>CondomContext</code> * * @param base the original context used before <code>CondomContext</code> is introduced. * @param tag the optional tag to distinguish between multiple instances of <code>CondomContext</code> used parallel. */ public static @CheckResult CondomContext wrap(final Context base, final @Nullable @Size(max=13) String tag, final CondomOptions options) { if (base instanceof CondomContext) { final CondomContext condom = ((CondomContext) base); Log.w("Condom", "The wrapped context is already a CondomContext (tag: " + condom.TAG + "), tag and options specified here will be ignore."); return condom; } final Context app_context = base.getApplicationContext(); final CondomCore condom = new CondomCore(base, options, CondomCore.buildLogTag("Condom", "Condom.", tag)); if (app_context instanceof Application) { // The application context is indeed an Application, this should be preserved semantically. final Application app = (Application) app_context; final CondomApplication condom_app = new CondomApplication(condom, app, tag); // TODO: Application instance should be unique across CondomContext. final CondomContext condom_context = new CondomContext(condom, condom_app, tag); condom_app.attachBaseContext(base == app_context ? condom_context : new CondomContext(condom, app, tag)); return condom_context; } else return new CondomContext(condom, base == app_context ? null : new CondomContext(condom, app_context, tag), tag); }
CondomApplication(final CondomCore condom, final Application app, final @Nullable @Size(max=13) String tag) { mCondom = condom; mApplication = app; TAG = CondomCore.buildLogTag("CondomApp", "CondomApp.", tag); }
private CondomContext(final CondomCore condom, final @Nullable Context app_context, final @Nullable @Size(max=16) String tag) { super(condom.mBase); final Context base = condom.mBase; mCondom = condom; mApplicationContext = app_context != null ? app_context : this; mBaseContext = new Lazy<Context>() { @Override protected Context create() { return new PseudoContextImpl(CondomContext.this); }}; mPackageManager = new Lazy<PackageManager>() { @Override protected PackageManager create() { return new CondomPackageManager(base.getPackageManager()); }}; mContentResolver = new Lazy<ContentResolver>() { @Override protected ContentResolver create() { return new CondomContentResolver(base, base.getContentResolver()); }}; final List<CondomKit> kits = condom.mKits; if (kits != null && ! kits.isEmpty()) { mKitManager = new KitManager(); for (final CondomKit kit : kits) kit.onRegister(mKitManager); } else mKitManager = null; TAG = CondomCore.buildLogTag("Condom", "Condom.", tag); }