Search in sources :

Example 1 with ReceiverCallNotAllowedException

use of android.content.ReceiverCallNotAllowedException 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) {
    }
}
Also used : ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) IntentFilter(android.content.IntentFilter) ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Parcel(android.os.Parcel) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 2 with ReceiverCallNotAllowedException

use of android.content.ReceiverCallNotAllowedException in project Parse-SDK-Android by ParsePlatform.

the class ConnectivityNotifier method tryToRegisterForNetworkStatusNotifications.

private boolean tryToRegisterForNetworkStatusNotifications(Context context) {
    synchronized (lock) {
        if (hasRegisteredReceiver) {
            return true;
        }
        try {
            if (context == null) {
                return false;
            }
            context = context.getApplicationContext();
            context.registerReceiver(this, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
            hasRegisteredReceiver = true;
            return true;
        } catch (ReceiverCallNotAllowedException e) {
            // In practice, this only happens with the push service, which will trigger a retry soon afterwards.
            PLog.v(TAG, "Cannot register a broadcast receiver because the executing " + "thread is currently in a broadcast receiver. Will try again later.");
            return false;
        }
    }
}
Also used : ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) IntentFilter(android.content.IntentFilter)

Example 3 with ReceiverCallNotAllowedException

use of android.content.ReceiverCallNotAllowedException in project platform_frameworks_base by android.

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) {
    }
}
Also used : ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) IntentFilter(android.content.IntentFilter) ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Parcel(android.os.Parcel) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 4 with ReceiverCallNotAllowedException

use of android.content.ReceiverCallNotAllowedException in project android_frameworks_base by AOSPA.

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) {
    }
}
Also used : ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) IntentFilter(android.content.IntentFilter) ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Parcel(android.os.Parcel) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 5 with ReceiverCallNotAllowedException

use of android.content.ReceiverCallNotAllowedException in project android_frameworks_base by crdroidandroid.

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) {
    }
}
Also used : ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) IntentFilter(android.content.IntentFilter) ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Parcel(android.os.Parcel) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Aggregations

IntentFilter (android.content.IntentFilter)7 ReceiverCallNotAllowedException (android.content.ReceiverCallNotAllowedException)7 ComponentName (android.content.ComponentName)6 Intent (android.content.Intent)6 ServiceConnection (android.content.ServiceConnection)6 IBinder (android.os.IBinder)6 Parcel (android.os.Parcel)6 RemoteException (android.os.RemoteException)6