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;
}
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);
}
}
}
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();
}
};
}
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();
}
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();
}
};
}
Aggregations