Search in sources :

Example 31 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 32 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 33 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)

Example 34 with BroadcastReceiver

use of android.content.BroadcastReceiver in project google-services by googlesamples.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                mInformationTextView.setText(getString(R.string.gcm_send_message));
            } else {
                mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };
    mInformationTextView = (TextView) findViewById(R.id.informationTextView);
    // Registering BroadcastReceiver
    registerReceiver();
    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 35 with BroadcastReceiver

use of android.content.BroadcastReceiver in project ListenerMusicPlayer by hefuyicoder.

the class MusicService method registerExternalStorageListener.

/**
     * 注册存储状态相关的广播接收器
     */
public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(final Context context, final Intent intent) {
                final String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mMediaMountedCount++;
                    mCardId = getCardId();
                    reloadQueueAfterPermissionCheck();
                    mQueueIsSaveable = true;
                    notifyChange(QUEUE_CHANGED);
                    notifyChange(META_CHANGED);
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, filter);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)381 Intent (android.content.Intent)354 Context (android.content.Context)337 IntentFilter (android.content.IntentFilter)280 PendingIntent (android.app.PendingIntent)91 RemoteException (android.os.RemoteException)26 Test (org.junit.Test)24 Semaphore (java.util.concurrent.Semaphore)20 IOException (java.io.IOException)18 Point (android.graphics.Point)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ArrayList (java.util.ArrayList)15 AndroidRuntimeException (android.util.AndroidRuntimeException)14 GlobalContext (org.qii.weiciyuan.support.utils.GlobalContext)13 ComponentName (android.content.ComponentName)11 Handler (android.os.Handler)11 ContentObserver (android.database.ContentObserver)9 Bundle (android.os.Bundle)9 ErrnoException (android.system.ErrnoException)9 View (android.view.View)9