Search in sources :

Example 21 with IIntentReceiver

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

the class ContextImpl method registerReceiverInternal.

private Intent registerReceiverInternal(BroadcastReceiver receiver, int userId, IntentFilter filter, String broadcastPermission, Handler scheduler, Context context) {
    IIntentReceiver rd = null;
    if (receiver != null) {
        if (mPackageInfo != null && context != null) {
            if (scheduler == null) {
                scheduler = mMainThread.getHandler();
            }
            rd = mPackageInfo.getReceiverDispatcher(receiver, context, scheduler, mMainThread.getInstrumentation(), true);
        } else {
            if (scheduler == null) {
                scheduler = mMainThread.getHandler();
            }
            rd = new LoadedApk.ReceiverDispatcher(receiver, context, scheduler, null, true).getIIntentReceiver();
        }
    }
    try {
        final Intent intent = ActivityManagerNative.getDefault().registerReceiver(mMainThread.getApplicationThread(), mBasePackageName, rd, filter, broadcastPermission, userId);
        if (intent != null) {
            intent.setExtrasClassLoader(getClassLoader());
            intent.prepareToEnterProcess();
        }
        return intent;
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : IIntentReceiver(android.content.IIntentReceiver) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 22 with IIntentReceiver

use of android.content.IIntentReceiver in project VirtualApp by asLody.

the class RegisterReceiver method call.

@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    HookUtils.replaceFirstAppPkg(args);
    args[IDX_RequiredPermission] = null;
    IntentFilter filter = (IntentFilter) args[IDX_IntentFilter];
    IntentFilter backupFilter = new IntentFilter(filter);
    protectIntentFilter(filter);
    if (args.length > IDX_IIntentReceiver && IIntentReceiver.class.isInstance(args[IDX_IIntentReceiver])) {
        final IInterface old = (IInterface) args[IDX_IIntentReceiver];
        if (!IIntentReceiverProxy.class.isInstance(old)) {
            final IBinder token = old.asBinder();
            if (token != null) {
                token.linkToDeath(new IBinder.DeathRecipient() {

                    @Override
                    public void binderDied() {
                        token.unlinkToDeath(this, 0);
                        mProxyIIntentReceivers.remove(token);
                    }
                }, 0);
                IIntentReceiver proxyIIntentReceiver = mProxyIIntentReceivers.get(token);
                if (proxyIIntentReceiver == null) {
                    proxyIIntentReceiver = new IIntentReceiverProxy(old);
                    mProxyIIntentReceivers.put(token, proxyIIntentReceiver);
                }
                WeakReference mDispatcher = LoadedApk.ReceiverDispatcher.InnerReceiver.mDispatcher.get(old);
                if (mDispatcher != null) {
                    LoadedApk.ReceiverDispatcher.mIIntentReceiver.set(mDispatcher.get(), proxyIIntentReceiver);
                    args[IDX_IIntentReceiver] = proxyIIntentReceiver;
                }
            }
        }
    }
    Object res = method.invoke(who, args);
    Intent intent = VActivityManager.get().dispatchStickyBroadcast(backupFilter);
    if (intent != null) {
        return intent;
    }
    return res;
}
Also used : IntentFilter(android.content.IntentFilter) IBinder(android.os.IBinder) WeakReference(java.lang.ref.WeakReference) IInterface(android.os.IInterface) IIntentReceiver(android.content.IIntentReceiver) Intent(android.content.Intent)

Example 23 with IIntentReceiver

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

the class ContextImpl method sendOrderedBroadcast.

@Override
public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
    warnIfCallingFromSystemProcess();
    IIntentReceiver rd = null;
    if (resultReceiver != null) {
        if (mPackageInfo != null) {
            if (scheduler == null) {
                scheduler = mMainThread.getHandler();
            }
            rd = mPackageInfo.getReceiverDispatcher(resultReceiver, getOuterContext(), scheduler, mMainThread.getInstrumentation(), false);
        } else {
            if (scheduler == null) {
                scheduler = mMainThread.getHandler();
            }
            rd = new LoadedApk.ReceiverDispatcher(resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver();
        }
    }
    String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
    try {
        intent.prepareToLeaveProcess();
        ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(), intent, resolvedType, rd, initialCode, initialData, initialExtras, receiverPermission, appOp, true, false, getUserId());
    } catch (RemoteException e) {
    }
}
Also used : IIntentReceiver(android.content.IIntentReceiver) RemoteException(android.os.RemoteException)

Example 24 with IIntentReceiver

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

the class ContextImpl method sendOrderedBroadcastAsUser.

@Override
public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
    IIntentReceiver rd = null;
    if (resultReceiver != null) {
        if (mPackageInfo != null) {
            if (scheduler == null) {
                scheduler = mMainThread.getHandler();
            }
            rd = mPackageInfo.getReceiverDispatcher(resultReceiver, getOuterContext(), scheduler, mMainThread.getInstrumentation(), false);
        } else {
            if (scheduler == null) {
                scheduler = mMainThread.getHandler();
            }
            rd = new LoadedApk.ReceiverDispatcher(resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver();
        }
    }
    String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
    try {
        intent.prepareToLeaveProcess();
        ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(), intent, resolvedType, rd, initialCode, initialData, initialExtras, receiverPermission, AppOpsManager.OP_NONE, true, false, user.getIdentifier());
    } catch (RemoteException e) {
    }
}
Also used : IIntentReceiver(android.content.IIntentReceiver) RemoteException(android.os.RemoteException)

Example 25 with IIntentReceiver

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

the class ActivityManagerService method stopUserLocked.

private int stopUserLocked(final int userId, final IStopUserCallback callback) {
    if (mCurrentUserId == userId) {
        return ActivityManager.USER_OP_IS_CURRENT;
    }
    final UserStartedState uss = mStartedUsers.get(userId);
    if (uss == null) {
        // callback if requested.
        if (callback != null) {
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    try {
                        callback.userStopped(userId);
                    } catch (RemoteException e) {
                    }
                }
            });
        }
        return ActivityManager.USER_OP_SUCCESS;
    }
    if (callback != null) {
        uss.mStopCallbacks.add(callback);
    }
    if (uss.mState != UserStartedState.STATE_STOPPING && uss.mState != UserStartedState.STATE_SHUTDOWN) {
        uss.mState = UserStartedState.STATE_STOPPING;
        updateStartedUserArrayLocked();
        long ident = Binder.clearCallingIdentity();
        try {
            // We are going to broadcast ACTION_USER_STOPPING and then
            // once that is done send a final ACTION_SHUTDOWN and then
            // stop the user.
            final Intent stoppingIntent = new Intent(Intent.ACTION_USER_STOPPING);
            stoppingIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
            stoppingIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
            final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN);
            // This is the result receiver for the final shutdown broadcast.
            final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() {

                @Override
                public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
                    finishUserStop(uss);
                }
            };
            // This is the result receiver for the initial stopping broadcast.
            final IIntentReceiver stoppingReceiver = new IIntentReceiver.Stub() {

                @Override
                public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
                    // On to the next.
                    synchronized (ActivityManagerService.this) {
                        if (uss.mState != UserStartedState.STATE_STOPPING) {
                            // Whoops, we are being started back up.  Abort, abort!
                            return;
                        }
                        uss.mState = UserStartedState.STATE_SHUTDOWN;
                    }
                    broadcastIntentLocked(null, null, shutdownIntent, null, shutdownReceiver, 0, null, null, null, AppOpsManager.OP_NONE, true, false, MY_PID, Process.SYSTEM_UID, userId);
                }
            };
            // Kick things off.
            broadcastIntentLocked(null, null, stoppingIntent, null, stoppingReceiver, 0, null, null, android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE, true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    return ActivityManager.USER_OP_SUCCESS;
}
Also used : Bundle(android.os.Bundle) IIntentReceiver(android.content.IIntentReceiver) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Aggregations

IIntentReceiver (android.content.IIntentReceiver)45 RemoteException (android.os.RemoteException)39 Intent (android.content.Intent)19 Bundle (android.os.Bundle)13 PendingIntent (android.app.PendingIntent)3 ComponentName (android.content.ComponentName)2 ActivityInfo (android.content.pm.ActivityInfo)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 ResolveInfo (android.content.pm.ResolveInfo)2 Message (android.os.Message)2 RemoteCallbackList (android.os.RemoteCallbackList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IntentFilter (android.content.IntentFilter)1 IBinder (android.os.IBinder)1 IInterface (android.os.IInterface)1 WeakReference (java.lang.ref.WeakReference)1