use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.
the class ViewFlipper method onAttachedToWindow.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
// Listen for broadcasts related to user-presence
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
getContext().registerReceiver(mReceiver, filter);
if (mAutoStart) {
// Automatically start when requested
startFlipping();
}
}
use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.
the class LocalReceiver method onReceive.
public void onReceive(Context context, Intent intent) {
String resultString = LaunchpadActivity.RECEIVER_LOCAL;
if (BroadcastTest.BROADCAST_FAIL_REGISTER.equals(intent.getAction())) {
resultString = "Successfully registered, but expected it to fail";
try {
context.registerReceiver(this, new IntentFilter("foo.bar"));
context.unregisterReceiver(this);
} catch (ReceiverCallNotAllowedException e) {
//resultString = "This is the correct behavior but not yet implemented";
resultString = LaunchpadActivity.RECEIVER_LOCAL;
}
} else if (BroadcastTest.BROADCAST_FAIL_BIND.equals(intent.getAction())) {
resultString = "Successfully bound to service, but expected it to fail";
try {
ServiceConnection sc = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
}
public void onServiceDisconnected(ComponentName name) {
}
};
context.bindService(new Intent(context, LocalService.class), sc, 0);
context.unbindService(sc);
} catch (ReceiverCallNotAllowedException e) {
//resultString = "This is the correct behavior but not yet implemented";
resultString = LaunchpadActivity.RECEIVER_LOCAL;
}
} else if (LaunchpadActivity.BROADCAST_REPEAT.equals(intent.getAction())) {
Intent newIntent = new Intent(intent);
newIntent.setAction(LaunchpadActivity.BROADCAST_LOCAL);
context.sendOrderedBroadcast(newIntent, null);
}
try {
IBinder caller = intent.getIBinderExtra("caller");
Parcel data = Parcel.obtain();
data.writeInterfaceToken(LaunchpadActivity.LAUNCH);
data.writeString(resultString);
caller.transact(LaunchpadActivity.GOT_RECEIVE_TRANSACTION, data, null, 0);
data.recycle();
} catch (RemoteException ex) {
}
}
use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.
the class IntentSenderTest method testRegisteredReceivePermissionGranted.
public void testRegisteredReceivePermissionGranted() throws Exception {
setExpectedReceivers(new String[] { RECEIVER_REG });
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_GRANTED);
addIntermediate("after-register");
PendingIntent is = PendingIntent.getBroadcast(getContext(), 0, makeBroadcastIntent(BROADCAST_REGISTERED), 0);
is.send();
waitForResultOrThrow(BROADCAST_TIMEOUT);
is.cancel();
}
use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.
the class IntentSenderTest method testRegisteredReceivePermissionDenied.
public void testRegisteredReceivePermissionDenied() throws Exception {
final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED);
setExpectedReceivers(new String[] { RECEIVER_RESULTS });
registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_DENIED);
addIntermediate("after-register");
PendingIntent.OnFinished finish = new PendingIntent.OnFinished() {
public void onSendFinished(PendingIntent pi, Intent intent, int resultCode, String resultData, Bundle resultExtras) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
PendingIntent is = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
is.send(Activity.RESULT_CANCELED, finish, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
is.cancel();
}
use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.
the class AppCacheTest method testFreeStorage.
// TODO: flaky test, omit from LargeTest for now
//@LargeTest
public void testFreeStorage() throws Exception {
boolean TRACKING = true;
StatFs st = new StatFs("/data");
long blks1 = getFreeStorageBlks(st);
if (localLOGV || TRACKING)
Log.i(TAG, "Available free blocks=" + blks1);
long availableMem = getFreeStorageSize(st);
File cacheDir = mContext.getCacheDir();
assertNotNull(cacheDir);
createTestFiles1(cacheDir, "testtmpdir", 5);
long blks2 = getFreeStorageBlks(st);
if (localLOGV || TRACKING)
Log.i(TAG, "Available blocks after writing test files in application cache=" + blks2);
// Create receiver and register it
FreeStorageReceiver receiver = new FreeStorageReceiver();
mContext.registerReceiver(receiver, new IntentFilter(FreeStorageReceiver.ACTION_FREE));
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent(FreeStorageReceiver.ACTION_FREE), 0);
// Invoke PackageManager api
if (!invokePMFreeStorage(availableMem, receiver, pi)) {
fail("Could not invoke PackageManager free storage API");
}
long blks3 = getFreeStorageBlks(st);
if (localLOGV || TRACKING)
Log.i(TAG, "Available blocks after freeing cache" + blks3);
assertEquals(receiver.getResultCode(), 1);
mContext.unregisterReceiver(receiver);
// Verify result
verifyTestFiles1(cacheDir, "testtmpdir", 5);
}
Aggregations