Search in sources :

Example 81 with BroadcastReceiver

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

the class BroadcastTest method testRegisteredReceivePermissionDenied.

public void testRegisteredReceivePermissionDenied() throws Exception {
    setExpectedReceivers(new String[] { RECEIVER_RESULTS });
    registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_DENIED);
    addIntermediate("after-register");
    BroadcastReceiver finish = new BroadcastReceiver() {

        public void onReceive(Context context, Intent intent) {
            gotReceive(RECEIVER_RESULTS, intent);
        }
    };
    getContext().sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_REGISTERED), null, finish, null, Activity.RESULT_CANCELED, null, null);
    waitForResultOrThrow(BROADCAST_TIMEOUT);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 82 with BroadcastReceiver

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

the class LocationManagerService method systemRunning.

public void systemRunning() {
    synchronized (mLock) {
        if (D)
            Log.d(TAG, "systemRunning()");
        // fetch package manager
        mPackageManager = mContext.getPackageManager();
        // fetch power manager
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        // prepare worker thread
        mLocationHandler = new LocationWorkerHandler(BackgroundThread.get().getLooper());
        // prepare mLocationHandler's dependents
        mLocationFudger = new LocationFudger(mContext, mLocationHandler);
        mBlacklist = new LocationBlacklist(mContext, mLocationHandler);
        mBlacklist.init();
        mGeofenceManager = new GeofenceManager(mContext, mBlacklist);
        // Monitor for app ops mode changes.
        AppOpsManager.OnOpChangedListener callback = new AppOpsManager.OnOpChangedInternalListener() {

            public void onOpChanged(int op, String packageName) {
                synchronized (mLock) {
                    for (Receiver receiver : mReceivers.values()) {
                        receiver.updateMonitoring(true);
                    }
                    applyAllProviderRequirementsLocked();
                }
            }
        };
        mAppOps.startWatchingMode(AppOpsManager.OP_COARSE_LOCATION, null, callback);
        PackageManager.OnPermissionsChangedListener permissionListener = new PackageManager.OnPermissionsChangedListener() {

            @Override
            public void onPermissionsChanged(final int uid) {
                synchronized (mLock) {
                    applyAllProviderRequirementsLocked();
                }
            }
        };
        mPackageManager.addOnPermissionsChangeListener(permissionListener);
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        updateUserProfiles(mCurrentUserId);
        // prepare providers
        loadProvidersLocked();
        updateProvidersLocked();
    }
    // listen for settings changes
    mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), true, new ContentObserver(mLocationHandler) {

        @Override
        public void onChange(boolean selfChange) {
            synchronized (mLock) {
                updateProvidersLocked();
            }
        }
    }, UserHandle.USER_ALL);
    mPackageMonitor.register(mContext, mLocationHandler.getLooper(), true);
    // listen for user change
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
    intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
    intentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
    intentFilter.addAction(Intent.ACTION_SHUTDOWN);
    mContext.registerReceiverAsUser(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
            } else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action) || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
                updateUserProfiles(mCurrentUserId);
            } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
                // shutdown only if UserId indicates whole system, not just one user
                if (D)
                    Log.d(TAG, "Shutdown received with UserId: " + getSendingUserId());
                if (getSendingUserId() == UserHandle.USER_ALL) {
                    shutdownComponents();
                }
            }
        }
    }, UserHandle.ALL, intentFilter, null, mLocationHandler);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) LocationBlacklist(com.android.server.location.LocationBlacklist) GeofenceManager(com.android.server.location.GeofenceManager) BroadcastReceiver(android.content.BroadcastReceiver) LocationFudger(com.android.server.location.LocationFudger) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) AppOpsManager(android.app.AppOpsManager) PackageManager(android.content.pm.PackageManager) ContentObserver(android.database.ContentObserver)

Example 83 with BroadcastReceiver

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

the class ActivityManagerService method finishBooting.

final void finishBooting() {
    synchronized (this) {
        if (!mBootAnimationComplete) {
            mCallFinishBooting = true;
            return;
        }
        mCallFinishBooting = false;
    }
    ArraySet<String> completedIsas = new ArraySet<String>();
    for (String abi : Build.SUPPORTED_ABIS) {
        Process.zygoteProcess.establishZygoteConnectionForAbi(abi);
        final String instructionSet = VMRuntime.getInstructionSet(abi);
        if (!completedIsas.contains(instructionSet)) {
            try {
                mInstaller.markBootComplete(VMRuntime.getInstructionSet(abi));
            } catch (InstallerException e) {
                Slog.w(TAG, "Unable to mark boot complete for abi: " + abi + " (" + e.getMessage() + ")");
            }
            completedIsas.add(instructionSet);
        }
    }
    IntentFilter pkgFilter = new IntentFilter();
    pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
    pkgFilter.addDataScheme("package");
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String[] pkgs = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
            if (pkgs != null) {
                for (String pkg : pkgs) {
                    synchronized (ActivityManagerService.this) {
                        if (forceStopPackageLocked(pkg, -1, false, false, false, false, false, 0, "query restart")) {
                            setResultCode(Activity.RESULT_OK);
                            return;
                        }
                    }
                }
            }
        }
    }, pkgFilter);
    IntentFilter dumpheapFilter = new IntentFilter();
    dumpheapFilter.addAction(DumpHeapActivity.ACTION_DELETE_DUMPHEAP);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getBooleanExtra(DumpHeapActivity.EXTRA_DELAY_DELETE, false)) {
                mHandler.sendEmptyMessageDelayed(POST_DUMP_HEAP_NOTIFICATION_MSG, 5 * 60 * 1000);
            } else {
                mHandler.sendEmptyMessage(POST_DUMP_HEAP_NOTIFICATION_MSG);
            }
        }
    }, dumpheapFilter);
    // Let system services know.
    mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETED);
    synchronized (this) {
        // Ensure that any processes we had put on hold are now started
        // up.
        final int NP = mProcessesOnHold.size();
        if (NP > 0) {
            ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>(mProcessesOnHold);
            for (int ip = 0; ip < NP; ip++) {
                if (DEBUG_PROCESSES)
                    Slog.v(TAG_PROCESSES, "Starting process on hold: " + procs.get(ip));
                startProcessLocked(procs.get(ip), "on-hold", null);
            }
        }
        if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
            // Start looking for apps that are abusing wake locks.
            Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
            mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
            // Tell anyone interested that we are done booting!
            SystemProperties.set("sys.boot_completed", "1");
            // And trigger dev.bootcomplete if we are not showing encryption progress
            if (!"trigger_restart_min_framework".equals(SystemProperties.get("vold.decrypt")) || "".equals(SystemProperties.get("vold.encrypt_progress"))) {
                SystemProperties.set("dev.bootcomplete", "1");
            }
            mUserController.sendBootCompletedLocked(new IIntentReceiver.Stub() {

                @Override
                public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
                    synchronized (ActivityManagerService.this) {
                        requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
                    }
                }
            });
            scheduleStartProfilesLocked();
        }
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ArraySet(android.util.ArraySet) Message(android.os.Message) Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Point(android.graphics.Point) IIntentReceiver(android.content.IIntentReceiver) InstallerException(com.android.server.pm.Installer.InstallerException)

Example 84 with BroadcastReceiver

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

the class DreamManagerService method onBootPhase.

@Override
public void onBootPhase(int phase) {
    if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
        if (Build.IS_DEBUGGABLE) {
            SystemProperties.addChangeCallback(mSystemPropertiesChanged);
        }
        mContext.registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                writePulseGestureEnabled();
                synchronized (mLock) {
                    stopDreamLocked(false);
                }
            }
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
        mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.DOZE_ENABLED), false, mDozeEnabledObserver, UserHandle.USER_ALL);
        writePulseGestureEnabled();
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 85 with BroadcastReceiver

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

the class MediaRouterService method systemRunning.

public void systemRunning() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_USER_SWITCHED)) {
                switchUser();
            }
        }
    }, filter);
    switchUser();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)637 Intent (android.content.Intent)564 Context (android.content.Context)493 IntentFilter (android.content.IntentFilter)441 PendingIntent (android.app.PendingIntent)120 Test (org.junit.Test)109 ArrayList (java.util.ArrayList)34 RemoteException (android.os.RemoteException)29 Bundle (android.os.Bundle)24 IOException (java.io.IOException)23 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 Handler (android.os.Handler)18 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 ComponentName (android.content.ComponentName)16 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14