Search in sources :

Example 96 with BroadcastReceiver

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

the class EventConditionProvider method onBootComplete.

@Override
public void onBootComplete() {
    if (DEBUG)
        Slog.d(TAG, "onBootComplete");
    if (mBootComplete)
        return;
    mBootComplete = true;
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
    filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            reloadTrackers();
        }
    }, filter);
    reloadTrackers();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 97 with BroadcastReceiver

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

the class TvInputManagerService method registerBroadcastReceivers.

private void registerBroadcastReceivers() {
    PackageMonitor monitor = new PackageMonitor() {

        private void buildTvInputList(String[] packages) {
            synchronized (mLock) {
                if (mCurrentUserId == getChangingUserId()) {
                    buildTvInputListLocked(mCurrentUserId, packages);
                    buildTvContentRatingSystemListLocked(mCurrentUserId);
                }
            }
        }

        @Override
        public void onPackageUpdateFinished(String packageName, int uid) {
            if (DEBUG)
                Slog.d(TAG, "onPackageUpdateFinished(packageName=" + packageName + ")");
            // This callback is invoked when the TV input is reinstalled.
            // In this case, isReplacing() always returns true.
            buildTvInputList(new String[] { packageName });
        }

        @Override
        public void onPackagesAvailable(String[] packages) {
            if (DEBUG) {
                Slog.d(TAG, "onPackagesAvailable(packages=" + Arrays.toString(packages) + ")");
            }
            // available.
            if (isReplacing()) {
                buildTvInputList(packages);
            }
        }

        @Override
        public void onPackagesUnavailable(String[] packages) {
            // unavailable.
            if (DEBUG) {
                Slog.d(TAG, "onPackagesUnavailable(packages=" + Arrays.toString(packages) + ")");
            }
            if (isReplacing()) {
                buildTvInputList(packages);
            }
        }

        @Override
        public void onSomePackagesChanged() {
            // the TV inputs.
            if (DEBUG)
                Slog.d(TAG, "onSomePackagesChanged()");
            if (isReplacing()) {
                if (DEBUG)
                    Slog.d(TAG, "Skipped building TV input list due to replacing");
                // methods instead.
                return;
            }
            buildTvInputList(null);
        }

        @Override
        public boolean onPackageChanged(String packageName, int uid, String[] components) {
            // the update can be handled in {@link #onSomePackagesChanged}.
            return true;
        }

        @Override
        public void onPackageRemoved(String packageName, int uid) {
            synchronized (mLock) {
                UserState userState = getOrCreateUserStateLocked(getChangingUserId());
                if (!userState.packageSet.contains(packageName)) {
                    // Not a TV input package.
                    return;
                }
            }
            ArrayList<ContentProviderOperation> operations = new ArrayList<>();
            String selection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=?";
            String[] selectionArgs = { packageName };
            operations.add(ContentProviderOperation.newDelete(TvContract.Channels.CONTENT_URI).withSelection(selection, selectionArgs).build());
            operations.add(ContentProviderOperation.newDelete(TvContract.Programs.CONTENT_URI).withSelection(selection, selectionArgs).build());
            operations.add(ContentProviderOperation.newDelete(TvContract.WatchedPrograms.CONTENT_URI).withSelection(selection, selectionArgs).build());
            ContentProviderResult[] results = null;
            try {
                ContentResolver cr = getContentResolverForUser(getChangingUserId());
                results = cr.applyBatch(TvContract.AUTHORITY, operations);
            } catch (RemoteException | OperationApplicationException e) {
                Slog.e(TAG, "error in applyBatch", e);
            }
            if (DEBUG) {
                Slog.d(TAG, "onPackageRemoved(packageName=" + packageName + ", uid=" + uid + ")");
                Slog.d(TAG, "results=" + results);
            }
        }
    };
    monitor.register(mContext, null, UserHandle.ALL, true);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
    intentFilter.addAction(Intent.ACTION_USER_REMOVED);
    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_USER_REMOVED.equals(action)) {
                removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
            }
        }
    }, UserHandle.ALL, intentFilter, null, null);
}
Also used : Context(android.content.Context) ContentProviderResult(android.content.ContentProviderResult) IntentFilter(android.content.IntentFilter) ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) PackageMonitor(com.android.internal.content.PackageMonitor) ContentResolver(android.content.ContentResolver) RemoteException(android.os.RemoteException) OperationApplicationException(android.content.OperationApplicationException)

Example 98 with BroadcastReceiver

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

the class DevicePolicyManagerService method choosePrivateKeyAlias.

@Override
public void choosePrivateKeyAlias(final int uid, final Uri uri, final String alias, final IBinder response) {
    // Caller UID needs to be trusted, so we restrict this method to SYSTEM_UID callers.
    if (!isCallerWithSystemUid()) {
        return;
    }
    final UserHandle caller = mInjector.binderGetCallingUserHandle();
    // If there is a profile owner, redirect to that; otherwise query the device owner.
    ComponentName aliasChooser = getProfileOwner(caller.getIdentifier());
    if (aliasChooser == null && caller.isSystem()) {
        ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
        if (deviceOwnerAdmin != null) {
            aliasChooser = deviceOwnerAdmin.info.getComponent();
        }
    }
    if (aliasChooser == null) {
        sendPrivateKeyAliasResponse(null, response);
        return;
    }
    Intent intent = new Intent(DeviceAdminReceiver.ACTION_CHOOSE_PRIVATE_KEY_ALIAS);
    intent.setComponent(aliasChooser);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, uid);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_URI, uri);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_ALIAS, alias);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_RESPONSE, response);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    final long id = mInjector.binderClearCallingIdentity();
    try {
        mContext.sendOrderedBroadcastAsUser(intent, caller, null, new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                final String chosenAlias = getResultData();
                sendPrivateKeyAliasResponse(chosenAlias, response);
            }
        }, null, Activity.RESULT_OK, null, null);
    } finally {
        mInjector.binderRestoreCallingIdentity(id);
    }
}
Also used : Context(android.content.Context) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ParcelableString(com.android.internal.util.ParcelableString) BroadcastReceiver(android.content.BroadcastReceiver)

Example 99 with BroadcastReceiver

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

the class DevicePolicyManagerService method removeActiveAdminLocked.

void removeActiveAdminLocked(final ComponentName adminReceiver, final int userHandle) {
    final ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
    DevicePolicyData policy = getUserData(userHandle);
    if (admin != null && !policy.mRemovingAdmins.contains(adminReceiver)) {
        policy.mRemovingAdmins.add(adminReceiver);
        sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED, new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                removeAdminArtifacts(adminReceiver, userHandle);
                removePackageIfRequired(adminReceiver.getPackageName(), userHandle);
            }
        });
    }
}
Also used : Context(android.content.Context) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 100 with BroadcastReceiver

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

the class WebViewUpdateService method onStart.

@Override
public void onStart() {
    mWebViewUpdatedReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
            switch(intent.getAction()) {
                case Intent.ACTION_PACKAGE_REMOVED:
                    // run the update-logic twice.
                    if (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING))
                        return;
                    mImpl.packageStateChanged(packageNameFromIntent(intent), PACKAGE_REMOVED, userId);
                    break;
                case Intent.ACTION_PACKAGE_CHANGED:
                    // entire package, not just a component
                    if (entirePackageChanged(intent)) {
                        mImpl.packageStateChanged(packageNameFromIntent(intent), PACKAGE_CHANGED, userId);
                    }
                    break;
                case Intent.ACTION_PACKAGE_ADDED:
                    mImpl.packageStateChanged(packageNameFromIntent(intent), (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING) ? PACKAGE_ADDED_REPLACED : PACKAGE_ADDED), userId);
                    break;
                case Intent.ACTION_USER_ADDED:
                    mImpl.handleNewUser(userId);
                    break;
            }
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    // Make sure we only receive intents for WebView packages from our config file.
    for (WebViewProviderInfo provider : mImpl.getWebViewPackages()) {
        filter.addDataSchemeSpecificPart(provider.packageName, PatternMatcher.PATTERN_LITERAL);
    }
    getContext().registerReceiverAsUser(mWebViewUpdatedReceiver, UserHandle.ALL, filter, null, /* broadcast permission */
    null);
    IntentFilter userAddedFilter = new IntentFilter();
    userAddedFilter.addAction(Intent.ACTION_USER_ADDED);
    getContext().registerReceiverAsUser(mWebViewUpdatedReceiver, UserHandle.ALL, userAddedFilter, null, /* broadcast permission */
    null);
    publishBinderService("webviewupdate", new BinderService(), true);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) WebViewProviderInfo(android.webkit.WebViewProviderInfo) 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