Search in sources :

Example 1 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method makeWimaxStateTracker.

/**
     * Loads external WiMAX library and registers as system service, returning a
     * {@link NetworkStateTracker} for WiMAX. Caller is still responsible for
     * invoking {@link NetworkStateTracker#startMonitoring(Context, Handler)}.
     */
private static NetworkStateTracker makeWimaxStateTracker(Context context, Handler trackerHandler) {
    // Initialize Wimax
    DexClassLoader wimaxClassLoader;
    Class wimaxStateTrackerClass = null;
    Class wimaxServiceClass = null;
    Class wimaxManagerClass;
    String wimaxJarLocation;
    String wimaxLibLocation;
    String wimaxManagerClassName;
    String wimaxServiceClassName;
    String wimaxStateTrackerClassName;
    NetworkStateTracker wimaxStateTracker = null;
    boolean isWimaxEnabled = context.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
    if (isWimaxEnabled) {
        try {
            wimaxJarLocation = context.getResources().getString(com.android.internal.R.string.config_wimaxServiceJarLocation);
            wimaxLibLocation = context.getResources().getString(com.android.internal.R.string.config_wimaxNativeLibLocation);
            wimaxManagerClassName = context.getResources().getString(com.android.internal.R.string.config_wimaxManagerClassname);
            wimaxServiceClassName = context.getResources().getString(com.android.internal.R.string.config_wimaxServiceClassname);
            wimaxStateTrackerClassName = context.getResources().getString(com.android.internal.R.string.config_wimaxStateTrackerClassname);
            if (DBG)
                log("wimaxJarLocation: " + wimaxJarLocation);
            wimaxClassLoader = new DexClassLoader(wimaxJarLocation, new ContextWrapper(context).getCacheDir().getAbsolutePath(), wimaxLibLocation, ClassLoader.getSystemClassLoader());
            try {
                wimaxManagerClass = wimaxClassLoader.loadClass(wimaxManagerClassName);
                wimaxStateTrackerClass = wimaxClassLoader.loadClass(wimaxStateTrackerClassName);
                wimaxServiceClass = wimaxClassLoader.loadClass(wimaxServiceClassName);
            } catch (ClassNotFoundException ex) {
                loge("Exception finding Wimax classes: " + ex.toString());
                return null;
            }
        } catch (Resources.NotFoundException ex) {
            loge("Wimax Resources does not exist!!! ");
            return null;
        }
        try {
            if (DBG)
                log("Starting Wimax Service... ");
            Constructor wmxStTrkrConst = wimaxStateTrackerClass.getConstructor(new Class[] { Context.class, Handler.class });
            wimaxStateTracker = (NetworkStateTracker) wmxStTrkrConst.newInstance(context, trackerHandler);
            Constructor wmxSrvConst = wimaxServiceClass.getDeclaredConstructor(new Class[] { Context.class, wimaxStateTrackerClass });
            wmxSrvConst.setAccessible(true);
            IBinder svcInvoker = (IBinder) wmxSrvConst.newInstance(context, wimaxStateTracker);
            wmxSrvConst.setAccessible(false);
            ServiceManager.addService(WimaxManagerConstants.WIMAX_SERVICE, svcInvoker);
        } catch (Exception ex) {
            loge("Exception creating Wimax classes: " + ex.toString());
            return null;
        }
    } else {
        loge("Wimax is not enabled or not added to the network attributes!!! ");
        return null;
    }
    return wimaxStateTracker;
}
Also used : IBinder(android.os.IBinder) Constructor(java.lang.reflect.Constructor) DexClassLoader(dalvik.system.DexClassLoader) Resources(android.content.res.Resources) NetworkStateTracker(android.net.NetworkStateTracker) ContextWrapper(android.content.ContextWrapper) RemoteException(android.os.RemoteException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 2 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method handleConfigurationChanged.

final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
    int configDiff = 0;
    int diff = 0;
    synchronized (mPackages) {
        if (mPendingConfiguration != null) {
            if (!mPendingConfiguration.isOtherSeqNewer(config)) {
                config = mPendingConfiguration;
                mCurDefaultDisplayDpi = config.densityDpi;
                updateDefaultDensity();
            }
            mPendingConfiguration = null;
        }
        if (config == null) {
            return;
        }
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Handle configuration changed: " + config);
        diff = applyConfigurationToResourcesLocked(config, compat);
        if (mConfiguration == null) {
            mConfiguration = new Configuration();
        }
        if (!mConfiguration.isOtherSeqNewer(config) && compat == null) {
            return;
        }
        configDiff = mConfiguration.diff(config);
        mConfiguration.updateFrom(config);
        config = applyCompatConfiguration(mCurDefaultDisplayDpi);
    }
    ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
    // Cleanup hardware accelerated stuff
    WindowManagerGlobal.getInstance().trimLocalMemory();
    freeTextLayoutCachesIfNeeded(configDiff);
    if (callbacks != null) {
        final int N = callbacks.size();
        for (int i = 0; i < N; i++) {
            ComponentCallbacks2 cb = callbacks.get(i);
            // cache, now we need to trigger an update for each application.
            if ((diff & ActivityInfo.CONFIG_THEME_RESOURCE) != 0) {
                if (cb instanceof ContextWrapper) {
                    Context context = ((ContextWrapper) cb).getBaseContext();
                    if (context instanceof ContextImpl) {
                        ((ContextImpl) context).refreshResourcesIfNecessary();
                    }
                }
            }
            performConfigurationChanged(cb, config);
        }
    }
}
Also used : Context(android.content.Context) Configuration(android.content.res.Configuration) ComponentCallbacks2(android.content.ComponentCallbacks2) ContextWrapper(android.content.ContextWrapper)

Example 3 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by ResurrectionRemix.

the class LockSettingsStorageTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mStorageDir = new File(getContext().getFilesDir(), "locksettings");
    mDb = getContext().getDatabasePath("locksettings.db");
    assertTrue(mStorageDir.exists() || mStorageDir.mkdirs());
    assertTrue(FileUtils.deleteContents(mStorageDir));
    assertTrue(!mDb.exists() || mDb.delete());
    final Context ctx = getContext();
    setContext(new ContextWrapper(ctx) {

        @Override
        public Object getSystemService(String name) {
            if (USER_SERVICE.equals(name)) {
                return new UserManager(ctx, null) {

                    @Override
                    public UserInfo getProfileParent(int userHandle) {
                        if (userHandle == 2) {
                            // User 2 is a profile of user 1.
                            return new UserInfo(1, "name", 0);
                        }
                        if (userHandle == 3) {
                            // User 3 is a profile of user 0.
                            return new UserInfo(0, "name", 0);
                        }
                        return null;
                    }
                };
            }
            return super.getSystemService(name);
        }
    });
    mStorage = new LockSettingsStorage(getContext(), new LockSettingsStorage.Callback() {

        @Override
        public void initialize(SQLiteDatabase db) {
            mStorage.writeKeyValue(db, "initializedKey", "initialValue", 0);
        }
    }) {

        @Override
        String getLockPatternFilename(int userId) {
            return new File(mStorageDir, super.getLockPatternFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getLockPasswordFilename(int userId) {
            return new File(mStorageDir, super.getLockPasswordFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getChildProfileLockFile(int userId) {
            return new File(mStorageDir, super.getChildProfileLockFile(userId).replace('/', '-')).getAbsolutePath();
        }
    };
}
Also used : Context(android.content.Context) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

Example 4 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by ResurrectionRemix.

the class Dialog method getAssociatedActivity.

/**
     * @return The activity associated with this dialog, or null if there is no associated activity.
     */
private ComponentName getAssociatedActivity() {
    Activity activity = mOwnerActivity;
    Context context = getContext();
    while (activity == null && context != null) {
        if (context instanceof Activity) {
            // found it!
            activity = (Activity) context;
        } else {
            context = (context instanceof ContextWrapper) ? // unwrap one level
            ((ContextWrapper) context).getBaseContext() : // done
            null;
        }
    }
    return activity == null ? null : activity.getComponentName();
}
Also used : Context(android.content.Context) ContextWrapper(android.content.ContextWrapper)

Example 5 with ContextWrapper

use of android.content.ContextWrapper in project android_frameworks_base by DirtyUnicorns.

the class LockSettingsStorageTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mStorageDir = new File(getContext().getFilesDir(), "locksettings");
    mDb = getContext().getDatabasePath("locksettings.db");
    assertTrue(mStorageDir.exists() || mStorageDir.mkdirs());
    assertTrue(FileUtils.deleteContents(mStorageDir));
    assertTrue(!mDb.exists() || mDb.delete());
    final Context ctx = getContext();
    setContext(new ContextWrapper(ctx) {

        @Override
        public Object getSystemService(String name) {
            if (USER_SERVICE.equals(name)) {
                return new UserManager(ctx, null) {

                    @Override
                    public UserInfo getProfileParent(int userHandle) {
                        if (userHandle == 2) {
                            // User 2 is a profile of user 1.
                            return new UserInfo(1, "name", 0);
                        }
                        if (userHandle == 3) {
                            // User 3 is a profile of user 0.
                            return new UserInfo(0, "name", 0);
                        }
                        return null;
                    }
                };
            }
            return super.getSystemService(name);
        }
    });
    mStorage = new LockSettingsStorage(getContext(), new LockSettingsStorage.Callback() {

        @Override
        public void initialize(SQLiteDatabase db) {
            mStorage.writeKeyValue(db, "initializedKey", "initialValue", 0);
        }
    }) {

        @Override
        String getLockPatternFilename(int userId) {
            return new File(mStorageDir, super.getLockPatternFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getLockPasswordFilename(int userId) {
            return new File(mStorageDir, super.getLockPasswordFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getChildProfileLockFile(int userId) {
            return new File(mStorageDir, super.getChildProfileLockFile(userId).replace('/', '-')).getAbsolutePath();
        }
    };
}
Also used : Context(android.content.Context) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

Aggregations

ContextWrapper (android.content.ContextWrapper)109 Context (android.content.Context)37 Activity (android.app.Activity)25 File (java.io.File)16 Test (org.junit.Test)13 Intent (android.content.Intent)11 MockContentResolver (android.test.mock.MockContentResolver)11 PackageManager (android.content.pm.PackageManager)10 View (android.view.View)10 Resources (android.content.res.Resources)9 IOException (java.io.IOException)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)6 UserManager (android.os.UserManager)6 LayoutInflater (android.view.LayoutInflater)6 ThemePreferenceController (com.android.settings.display.ThemePreferenceController)6 OverlayManager (com.android.settings.display.ThemePreferenceController.OverlayManager)6 ArrayList (java.util.ArrayList)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 JsonParser (com.google.gson.JsonParser)5