use of android.content.ContextWrapper in project robolectric by robolectric.
the class ShadowApplication method assertNoBroadcastListenersOfActionRegistered.
public void assertNoBroadcastListenersOfActionRegistered(ContextWrapper context, String action) {
for (Wrapper registeredReceiver : registeredReceivers) {
if (registeredReceiver.context == context.getBaseContext()) {
Iterator<String> actions = registeredReceiver.intentFilter.actionsIterator();
while (actions.hasNext()) {
if (actions.next().equals(action)) {
RuntimeException e = new IllegalStateException("Unexpected BroadcastReceiver on " + context + " with action " + action + " " + registeredReceiver.broadcastReceiver + " that was originally registered here:");
e.setStackTrace(registeredReceiver.exception.getStackTrace());
throw e;
}
}
}
}
}
use of android.content.ContextWrapper in project platform_frameworks_base by android.
the class ModelTest method setupTestContext.
private void setupTestContext() {
final MockContentResolver resolver = new MockContentResolver();
context = new ContextWrapper(getContext()) {
@Override
public ContentResolver getContentResolver() {
return resolver;
}
};
provider = new TestContentProvider();
resolver.addProvider(AUTHORITY, provider);
}
use of android.content.ContextWrapper in project platform_frameworks_base by android.
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 ListenerMusicPlayer by hefuyicoder.
the class MusicPlayer method bindToService.
public static ServiceToken bindToService(final Context context, final ServiceConnection callback) {
Activity realActivity = ((Activity) context).getParent();
if (realActivity == null) {
realActivity = (Activity) context;
}
final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
contextWrapper.startService(new Intent(contextWrapper, MusicService.class));
final ServiceBinder binder = new ServiceBinder(callback, contextWrapper.getApplicationContext());
if (contextWrapper.bindService(new Intent().setClass(contextWrapper, MusicService.class), binder, 0)) {
mConnectionMap.put(contextWrapper, binder);
return new ServiceToken(contextWrapper);
}
return null;
}
use of android.content.ContextWrapper in project ListenerMusicPlayer by hefuyicoder.
the class MusicPlayer method unbindFromService.
public static void unbindFromService(final ServiceToken token) {
if (token == null) {
return;
}
final ContextWrapper mContextWrapper = token.mWrappedContext;
final ServiceBinder mBinder = mConnectionMap.remove(mContextWrapper);
if (mBinder == null) {
return;
}
mContextWrapper.unbindService(mBinder);
if (mConnectionMap.isEmpty()) {
mService = null;
}
}
Aggregations