Search in sources :

Example 6 with BroadcastReceiver

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

the class BroadcastTest method testRemoteReceivePermissionDenied.

public void testRemoteReceivePermissionDenied() throws Exception {
    setExpectedReceivers(new String[] { RECEIVER_RESULTS });
    BroadcastReceiver finish = new BroadcastReceiver() {

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

Example 7 with BroadcastReceiver

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

the class SettingsProvider method onCreate.

@Override
public boolean onCreate() {
    mBackupManager = new BackupManager(getContext());
    mUserManager = UserManager.get(getContext());
    setAppOps(AppOpsManager.OP_NONE, AppOpsManager.OP_WRITE_SETTINGS);
    establishDbTracking(UserHandle.USER_OWNER);
    IntentFilter userFilter = new IntentFilter();
    userFilter.addAction(Intent.ACTION_USER_REMOVED);
    getContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_USER_REMOVED)) {
                final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_OWNER);
                if (userHandle != UserHandle.USER_OWNER) {
                    onUserRemoved(userHandle);
                }
            }
        }
    }, userFilter);
    return true;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) BackupManager(android.app.backup.BackupManager)

Example 8 with BroadcastReceiver

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

the class BaseStatusBar method start.

public void start() {
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
    mDisplay = mWindowManager.getDefaultDisplay();
    // set up
    mProvisioningObserver.onChange(false);
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mProvisioningObserver);
    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    mStatusBarContainer = new FrameLayout(mContext);
    mLocale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
    // Connect in to the status bar manager service
    StatusBarIconList iconList = new StatusBarIconList();
    ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
    ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
    mCommandQueue = new CommandQueue(this, iconList);
    int[] switches = new int[7];
    ArrayList<IBinder> binders = new ArrayList<IBinder>();
    try {
        mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, switches, binders);
    } catch (RemoteException ex) {
    // If the system process isn't there we're doomed anyway.
    }
    mHaloActive = Settings.System.getInt(mContext.getContentResolver(), Settings.System.HALO_ACTIVE, 0) == 1;
    createAndAddWindows();
    disable(switches[0]);
    setSystemUiVisibility(switches[1], 0xffffffff);
    topAppWindowChanged(switches[2] != 0);
    // StatusBarManagerService has a back up of IME token and it's restored here.
    setImeWindowStatus(binders.get(0), switches[3], switches[4]);
    setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);
    // Set up the initial icon state
    int N = iconList.size();
    int viewIndex = 0;
    for (int i = 0; i < N; i++) {
        StatusBarIcon icon = iconList.getIcon(i);
        if (icon != null) {
            addIcon(iconList.getSlot(i), i, viewIndex, icon);
            viewIndex++;
        }
    }
    // Set up the initial notification state
    N = notificationKeys.size();
    if (N == notifications.size()) {
        for (int i = 0; i < N; i++) {
            addNotification(notificationKeys.get(i), notifications.get(i));
        }
    } else {
        Log.wtf(TAG, "Notification list length mismatch: keys=" + N + " notifications=" + notifications.size());
    }
    if (DEBUG) {
        Slog.d(TAG, String.format("init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", iconList.size(), switches[0], switches[1], switches[2], switches[3]));
    }
    mCurrentUserId = ActivityManager.getCurrentUser();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_SWITCHED);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (true)
                    Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
                userSwitched(mCurrentUserId);
            }
        }
    }, filter);
    // Only watch for per app color changes when the setting is in check
    if (ColorUtils.getPerAppColorState(mContext)) {
        // Reset all colors
        Bitmap currentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mCurrentCanvas = new Canvas(currentBitmap);
        mCurrentCanvas.drawColor(0xFF000000);
        BitmapDrawable currentBitmapDrawable = new BitmapDrawable(currentBitmap);
        Bitmap newBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mNewCanvas = new Canvas(newBitmap);
        mNewCanvas.drawColor(0xFF000000);
        BitmapDrawable newBitmapDrawable = new BitmapDrawable(newBitmap);
        mTransition = new TransitionDrawable(new Drawable[] { currentBitmapDrawable, newBitmapDrawable });
        mBarView.setBackground(mTransition);
        mLastIconColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
        mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR);
        updateIconColor();
        updateBackgroundColor();
        // Listen for status bar icon color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.STATUS_ICON_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateIconColor();
            }
        });
        // Listen for status bar background color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateBackgroundColor();
            }
        });
        // Listen for per-app-color state changes, this one will revert to stock colors all over
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PER_APP_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                if (!ColorUtils.getPerAppColorState(mContext)) {
                    for (int i = 0; i < ExtendedPropertiesUtils.PARANOID_COLORS_COUNT; i++) {
                        ColorUtils.ColorSettingInfo colorInfo = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
                        ColorUtils.setColor(mContext, ExtendedPropertiesUtils.PARANOID_COLORS_SETTINGS[i], colorInfo.systemColorString, "NULL", 1, 250);
                    }
                }
            }
        });
    }
    attachPie();
    // Listen for PIE gravity
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PIE_GRAVITY), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updatePieControls();
        }
    });
    // Listen for HALO state
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_ACTIVE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updateHalo();
        }
    });
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_SIZE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            restartHalo();
        }
    });
    updateHalo();
    SettingsObserver settingsObserver = new SettingsObserver(new Handler());
    settingsObserver.observe();
}
Also used : ArrayList(java.util.ArrayList) IBinder(android.os.IBinder) Bitmap(android.graphics.Bitmap) StatusBarNotification(android.service.notification.StatusBarNotification) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) ContentObserver(android.database.ContentObserver) Context(android.content.Context) IntentFilter(android.content.IntentFilter) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StatusBarIconList(com.android.internal.statusbar.StatusBarIconList) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) Paint(android.graphics.Paint) FrameLayout(android.widget.FrameLayout) RemoteException(android.os.RemoteException)

Example 9 with BroadcastReceiver

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

the class VibratorService method systemReady.

public void systemReady() {
    mIm = (InputManager) mContext.getSystemService(Context.INPUT_SERVICE);
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES), true, new ContentObserver(mH) {

        @Override
        public void onChange(boolean selfChange) {
            updateInputDeviceVibrators();
        }
    }, UserHandle.USER_ALL);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            updateInputDeviceVibrators();
        }
    }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mH);
    updateInputDeviceVibrators();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) ContentObserver(android.database.ContentObserver)

Example 10 with BroadcastReceiver

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

the class ActivityManagerService method finishBooting.

final void finishBooting() {
    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, 0)) {
                            setResultCode(Activity.RESULT_OK);
                            return;
                        }
                    }
                }
            }
        }
    }, pkgFilter);
    ThemeUtils.registerThemeChangeReceiver(mContext, new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            mUiContext = null;
        }
    });
    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, "Starting process on hold: " + procs.get(ip));
                startProcessLocked(procs.get(ip), "on-hold", null);
            }
        }
        if (mFactoryTest != SystemServer.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");
            SystemProperties.set("dev.bootcomplete", "1");
            for (int i = 0; i < mStartedUsers.size(); i++) {
                UserStartedState uss = mStartedUsers.valueAt(i);
                if (uss.mState == UserStartedState.STATE_BOOTING) {
                    uss.mState = UserStartedState.STATE_RUNNING;
                    final int userId = mStartedUsers.keyAt(i);
                    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
                    intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
                    broadcastIntentLocked(null, null, intent, null, null, 0, null, null, android.Manifest.permission.RECEIVE_BOOT_COMPLETED, AppOpsManager.OP_NONE, false, false, MY_PID, Process.SYSTEM_UID, userId);
                }
            }
        }
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Message(android.os.Message) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)375 Intent (android.content.Intent)349 Context (android.content.Context)333 IntentFilter (android.content.IntentFilter)270 PendingIntent (android.app.PendingIntent)90 RemoteException (android.os.RemoteException)26 Test (org.junit.Test)23 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)10 ErrnoException (android.system.ErrnoException)9 PackageManager (android.content.pm.PackageManager)8 ContentObserver (android.database.ContentObserver)8 Bundle (android.os.Bundle)8