Search in sources :

Example 36 with IIntentReceiver

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

the class ContextImpl method sendStickyOrderedBroadcastAsUser.

@Override
@Deprecated
public void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, 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(this);
        ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(), intent, resolvedType, rd, initialCode, initialData, initialExtras, null, AppOpsManager.OP_NONE, null, true, true, user.getIdentifier());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : IIntentReceiver(android.content.IIntentReceiver) RemoteException(android.os.RemoteException)

Example 37 with IIntentReceiver

use of android.content.IIntentReceiver in project cornerstone by Onskreen.

the class ActivityManagerService method systemReady.

public void systemReady(final Runnable goingCallback) {
    synchronized (this) {
        if (mSystemReady) {
            if (goingCallback != null)
                goingCallback.run();
            return;
        }
        // Check to see if there are any update receivers to run.
        if (!mDidUpdate) {
            if (mWaitingUpdate) {
                return;
            }
            Intent intent = new Intent(Intent.ACTION_PRE_BOOT_COMPLETED);
            List<ResolveInfo> ris = null;
            try {
                ris = AppGlobals.getPackageManager().queryIntentReceivers(intent, null, 0, 0);
            } catch (RemoteException e) {
            }
            if (ris != null) {
                for (int i = ris.size() - 1; i >= 0; i--) {
                    if ((ris.get(i).activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                        ris.remove(i);
                    }
                }
                intent.addFlags(Intent.FLAG_RECEIVER_BOOT_UPGRADE);
                ArrayList<ComponentName> lastDoneReceivers = readLastDonePreBootReceivers();
                final ArrayList<ComponentName> doneReceivers = new ArrayList<ComponentName>();
                for (int i = 0; i < ris.size(); i++) {
                    ActivityInfo ai = ris.get(i).activityInfo;
                    ComponentName comp = new ComponentName(ai.packageName, ai.name);
                    if (lastDoneReceivers.contains(comp)) {
                        ris.remove(i);
                        i--;
                    }
                }
                for (int i = 0; i < ris.size(); i++) {
                    ActivityInfo ai = ris.get(i).activityInfo;
                    ComponentName comp = new ComponentName(ai.packageName, ai.name);
                    doneReceivers.add(comp);
                    intent.setComponent(comp);
                    IIntentReceiver finisher = null;
                    if (i == ris.size() - 1) {
                        finisher = new IIntentReceiver.Stub() {

                            public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky) {
                                // The raw IIntentReceiver interface is called
                                // with the AM lock held, so redispatch to
                                // execute our code without the lock.
                                mHandler.post(new Runnable() {

                                    public void run() {
                                        synchronized (ActivityManagerService.this) {
                                            mDidUpdate = true;
                                        }
                                        writeLastDonePreBootReceivers(doneReceivers);
                                        showBootMessage(mContext.getText(R.string.android_upgrading_complete), false);
                                        systemReady(goingCallback);
                                    }
                                });
                            }
                        };
                    }
                    Slog.i(TAG, "Sending system update to: " + intent.getComponent());
                    /* TODO: Send this to all users */
                    broadcastIntentLocked(null, null, intent, null, finisher, 0, null, null, null, true, false, MY_PID, Process.SYSTEM_UID, 0);
                    if (finisher != null) {
                        mWaitingUpdate = true;
                    }
                }
            }
            if (mWaitingUpdate) {
                return;
            }
            mDidUpdate = true;
        }
        mSystemReady = true;
        if (!mStartRunning) {
            return;
        }
    }
    ArrayList<ProcessRecord> procsToKill = null;
    synchronized (mPidsSelfLocked) {
        for (int i = mPidsSelfLocked.size() - 1; i >= 0; i--) {
            ProcessRecord proc = mPidsSelfLocked.valueAt(i);
            if (!isAllowedWhileBooting(proc.info)) {
                if (procsToKill == null) {
                    procsToKill = new ArrayList<ProcessRecord>();
                }
                procsToKill.add(proc);
            }
        }
    }
    synchronized (this) {
        if (procsToKill != null) {
            for (int i = procsToKill.size() - 1; i >= 0; i--) {
                ProcessRecord proc = procsToKill.get(i);
                Slog.i(TAG, "Removing system update proc: " + proc);
                removeProcessLocked(proc, true, false, "system update done");
            }
        }
        // Now that we have cleaned up any update processes, we
        // are ready to start launching real processes and know that
        // we won't trample on them any more.
        mProcessesReady = true;
    }
    Slog.i(TAG, "System now ready");
    EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_AMS_READY, SystemClock.uptimeMillis());
    synchronized (this) {
        if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
            ResolveInfo ri = mContext.getPackageManager().resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS);
            CharSequence errorMsg = null;
            if (ri != null) {
                ActivityInfo ai = ri.activityInfo;
                ApplicationInfo app = ai.applicationInfo;
                if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    mTopAction = Intent.ACTION_FACTORY_TEST;
                    mTopData = null;
                    mTopComponent = new ComponentName(app.packageName, ai.name);
                } else {
                    errorMsg = mContext.getResources().getText(com.android.internal.R.string.factorytest_not_system);
                }
            } else {
                errorMsg = mContext.getResources().getText(com.android.internal.R.string.factorytest_no_action);
            }
            if (errorMsg != null) {
                mTopAction = null;
                mTopData = null;
                mTopComponent = null;
                Message msg = Message.obtain();
                msg.what = SHOW_FACTORY_ERROR_MSG;
                msg.getData().putCharSequence("msg", errorMsg);
                mHandler.sendMessage(msg);
            }
        }
    }
    retrieveSettings();
    if (goingCallback != null)
        goingCallback.run();
    synchronized (this) {
        if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
            try {
                List apps = AppGlobals.getPackageManager().getPersistentApplications(STOCK_PM_FLAGS);
                if (apps != null) {
                    int N = apps.size();
                    int i;
                    for (i = 0; i < N; i++) {
                        ApplicationInfo info = (ApplicationInfo) apps.get(i);
                        if (info != null && !info.packageName.equals("android")) {
                            addAppLocked(info, false);
                        }
                    }
                }
            } catch (RemoteException ex) {
            // pm is in same process, this will never happen.
            }
        }
        // Start up initial activity.
        mBooting = true;
        try {
            if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
                Message msg = Message.obtain();
                msg.what = SHOW_UID_ERROR_MSG;
                mHandler.sendMessage(msg);
            }
        } catch (RemoteException e) {
        }
        mMainStack.resumeTopActivityLocked(null);
    /**
             * Author: Onskreen
             * Date: 27/01/2011
             *
             * This would only be mirrored in cornerstone if Cornerstone Panel
             * were launched at system start and kept alive like the HS
             *
             * mCornerstoneStack.resumeTopActivityLocked(null);
             */
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Message(android.os.Message) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) IIntentReceiver(android.content.IIntentReceiver) ComponentName(android.content.ComponentName) ArrayList(java.util.ArrayList) RemoteCallbackList(android.os.RemoteCallbackList) List(java.util.List) RemoteException(android.os.RemoteException)

Example 38 with IIntentReceiver

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

the class UserController method finishUserStopping.

void finishUserStopping(final int userId, final UserState uss) {
    // On to the next.
    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) {
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    finishUserStopped(uss);
                }
            });
        }
    };
    synchronized (mService) {
        if (uss.state != UserState.STATE_STOPPING) {
            // Whoops, we are being started back up.  Abort, abort!
            return;
        }
        uss.setState(UserState.STATE_SHUTDOWN);
    }
    getUserManagerInternal().setUserState(userId, uss.state);
    mService.mBatteryStatsService.noteEvent(BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH, Integer.toString(userId), userId);
    mService.mSystemServiceManager.stopUser(userId);
    synchronized (mService) {
        mService.broadcastIntentLocked(null, null, shutdownIntent, null, shutdownReceiver, 0, null, null, null, AppOpsManager.OP_NONE, null, true, false, MY_PID, SYSTEM_UID, userId);
    }
}
Also used : Bundle(android.os.Bundle) IIntentReceiver(android.content.IIntentReceiver) Intent(android.content.Intent)

Example 39 with IIntentReceiver

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

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 40 with IIntentReceiver

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

the class ContextImpl method sendOrderedBroadcastAsUser.

@Override
public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, int appOp, Bundle options, 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());
    String[] receiverPermissions = receiverPermission == null ? null : new String[] { receiverPermission };
    try {
        intent.prepareToLeaveProcess(this);
        ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(), intent, resolvedType, rd, initialCode, initialData, initialExtras, receiverPermissions, appOp, options, true, false, user.getIdentifier());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : IIntentReceiver(android.content.IIntentReceiver) 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