Search in sources :

Example 86 with IntentFilter

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

the class BluetoothTestUtils method discoverable.

/**
     * Puts the local device into discoverable mode and checks to make sure that the local device
     * is in discoverable mode and that the correct actions were broadcast.
     *
     * @param adapter The BT adapter.
     */
public void discoverable(BluetoothAdapter adapter) {
    if (!adapter.isEnabled()) {
        fail("discoverable() bluetooth not enabled");
    }
    int scanMode = adapter.getScanMode();
    if (scanMode != BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
        return;
    }
    final Semaphore completionSemaphore = new Semaphore(0);
    final BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (!BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action)) {
                return;
            }
            final int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
            if (mode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
                completionSemaphore.release();
            }
        }
    };
    final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
    mContext.registerReceiver(receiver, filter);
    assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
    boolean success = false;
    try {
        success = completionSemaphore.tryAcquire(DISCOVERABLE_UNDISCOVERABLE_TIMEOUT, TimeUnit.MILLISECONDS);
        writeOutput(String.format("discoverable() completed in 0 ms"));
    } catch (final InterruptedException e) {
    // This should never happen but just in case it does, the test will fail anyway.
    }
    mContext.unregisterReceiver(receiver);
    if (!success) {
        fail(String.format("discoverable() timeout: scanMode=%d (expected %d)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Semaphore(java.util.concurrent.Semaphore) BroadcastReceiver(android.content.BroadcastReceiver)

Example 87 with IntentFilter

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

the class BluetoothTestUtils method enable.

/**
     * Enables Bluetooth and checks to make sure that Bluetooth was turned on and that the correct
     * actions were broadcast.
     *
     * @param adapter The BT adapter.
     */
public void enable(BluetoothAdapter adapter) {
    writeOutput("Enabling Bluetooth adapter.");
    assertFalse(adapter.isEnabled());
    int btState = adapter.getState();
    final Semaphore completionSemaphore = new Semaphore(0);
    final BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                return;
            }
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            if (state == BluetoothAdapter.STATE_ON) {
                completionSemaphore.release();
            }
        }
    };
    final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    mContext.registerReceiver(receiver, filter);
    assertTrue(adapter.enable());
    boolean success = false;
    try {
        success = completionSemaphore.tryAcquire(ENABLE_DISABLE_TIMEOUT, TimeUnit.MILLISECONDS);
        writeOutput(String.format("enable() completed in 0 ms"));
    } catch (final InterruptedException e) {
    // This should never happen but just in case it does, the test will fail anyway.
    }
    mContext.unregisterReceiver(receiver);
    if (!success) {
        fail(String.format("enable() timeout: state=%d (expected %d)", btState, BluetoothAdapter.STATE_ON));
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Semaphore(java.util.concurrent.Semaphore) BroadcastReceiver(android.content.BroadcastReceiver)

Example 88 with IntentFilter

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

the class DownloadManagerBaseTest method setWiFiStateOn.

/**
     * Enables or disables WiFi.
     *
     * Note: Needs the following permissions:
     *  android.permission.ACCESS_WIFI_STATE
     *  android.permission.CHANGE_WIFI_STATE
     * @param enable true if it should be enabled, false if it should be disabled
     */
protected void setWiFiStateOn(boolean enable) throws Exception {
    Log.i(LOG_TAG, "Setting WiFi State to: " + enable);
    WifiManager manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    manager.setWifiEnabled(enable);
    String timeoutMessage = "Timed out waiting for Wifi to be " + (enable ? "enabled!" : "disabled!");
    WiFiChangedReceiver receiver = new WiFiChangedReceiver(mContext);
    mContext.registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    synchronized (receiver) {
        long timeoutTime = SystemClock.elapsedRealtime() + DEFAULT_MAX_WAIT_TIME;
        boolean timedOut = false;
        while (receiver.getWiFiIsOn() != enable && !timedOut) {
            try {
                receiver.wait(DEFAULT_WAIT_POLL_TIME);
                if (SystemClock.elapsedRealtime() > timeoutTime) {
                    timedOut = true;
                }
            } catch (InterruptedException e) {
            // ignore InterruptedExceptions
            }
        }
        if (timedOut) {
            fail(timeoutMessage);
        }
    }
    assertEquals(enable, receiver.getWiFiIsOn());
}
Also used : WifiManager(android.net.wifi.WifiManager) IntentFilter(android.content.IntentFilter)

Example 89 with IntentFilter

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

the class PhoneStatusBar method makeStatusBarView.

// ================================================================================
// Constructing the view
// ================================================================================
protected PhoneStatusBarView makeStatusBarView() {
    final Context context = mContext;
    // populates mDisplayMetrics
    updateDisplaySize();
    updateResources();
    inflateStatusBarWindow(context);
    mStatusBarWindow.setService(this);
    mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            checkUserAutohide(v, event);
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (mExpandedVisible) {
                    animateCollapsePanels();
                }
            }
            return mStatusBarWindow.onTouchEvent(event);
        }
    });
    mNotificationPanel = (NotificationPanelView) mStatusBarWindow.findViewById(R.id.notification_panel);
    mNotificationPanel.setStatusBar(this);
    mNotificationPanel.setGroupManager(mGroupManager);
    mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
    mStatusBarView.setBar(this);
    mStatusBarView.setPanel(mNotificationPanel);
    if (!ActivityManager.isHighEndGfx()) {
        mStatusBarWindow.setBackground(null);
        mNotificationPanel.setBackground(new FastColorDrawable(context.getColor(R.color.notification_panel_solid_background)));
    }
    mHeadsUpManager = new HeadsUpManager(context, mStatusBarWindow, mGroupManager);
    mHeadsUpManager.setBar(this);
    mHeadsUpManager.addListener(this);
    mHeadsUpManager.addListener(mNotificationPanel);
    mHeadsUpManager.addListener(mGroupManager);
    mNotificationPanel.setHeadsUpManager(mHeadsUpManager);
    mNotificationData.setHeadsUpManager(mHeadsUpManager);
    mGroupManager.setHeadsUpManager(mHeadsUpManager);
    if (MULTIUSER_DEBUG) {
        mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
        mNotificationPanelDebugText.setVisibility(View.VISIBLE);
    }
    try {
        boolean showNav = mWindowManagerService.hasNavigationBar();
        if (DEBUG)
            Log.v(TAG, "hasNavigationBar=" + showNav);
        if (showNav) {
            createNavigationBarView(context);
        }
    } catch (RemoteException ex) {
    // no window manager? good luck with that
    }
    mAssistManager = SystemUIFactory.getInstance().createAssistManager(this, context);
    // figure out which pixel-format to use for the status bar.
    mPixelFormat = PixelFormat.OPAQUE;
    mStackScroller = (NotificationStackScrollLayout) mStatusBarWindow.findViewById(R.id.notification_stack_scroller);
    mStackScroller.setLongPressListener(getNotificationLongClicker());
    mStackScroller.setPhoneStatusBar(this);
    mStackScroller.setGroupManager(mGroupManager);
    mStackScroller.setHeadsUpManager(mHeadsUpManager);
    mGroupManager.setOnGroupChangeListener(mStackScroller);
    inflateOverflowContainer();
    inflateEmptyShadeView();
    inflateDismissView();
    mExpandedContents = mStackScroller;
    mBackdrop = (BackDropView) mStatusBarWindow.findViewById(R.id.backdrop);
    mBackdropFront = (ImageView) mBackdrop.findViewById(R.id.backdrop_front);
    mBackdropBack = (ImageView) mBackdrop.findViewById(R.id.backdrop_back);
    if (ENABLE_LOCKSCREEN_WALLPAPER) {
        mLockscreenWallpaper = new LockscreenWallpaper(mContext, this, mHandler);
    }
    ScrimView scrimBehind = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_behind);
    ScrimView scrimInFront = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_in_front);
    View headsUpScrim = mStatusBarWindow.findViewById(R.id.heads_up_scrim);
    mScrimController = SystemUIFactory.getInstance().createScrimController(scrimBehind, scrimInFront, headsUpScrim, mLockscreenWallpaper);
    if (mScrimSrcModeEnabled) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                boolean asSrc = mBackdrop.getVisibility() != View.VISIBLE;
                mScrimController.setDrawBehindAsSrc(asSrc);
                mStackScroller.setDrawBackgroundAsSrc(asSrc);
            }
        };
        mBackdrop.setOnVisibilityChangedRunnable(runnable);
        runnable.run();
    }
    mHeadsUpManager.addListener(mScrimController);
    mStackScroller.setScrimController(mScrimController);
    mStatusBarView.setScrimController(mScrimController);
    mDozeScrimController = new DozeScrimController(mScrimController, context);
    mKeyguardStatusBar = (KeyguardStatusBarView) mStatusBarWindow.findViewById(R.id.keyguard_header);
    mKeyguardStatusView = mStatusBarWindow.findViewById(R.id.keyguard_status_view);
    mKeyguardBottomArea = (KeyguardBottomAreaView) mStatusBarWindow.findViewById(R.id.keyguard_bottom_area);
    mKeyguardBottomArea.setActivityStarter(this);
    mKeyguardBottomArea.setAssistManager(mAssistManager);
    mKeyguardIndicationController = new KeyguardIndicationController(mContext, (KeyguardIndicationTextView) mStatusBarWindow.findViewById(R.id.keyguard_indication_text), mKeyguardBottomArea.getLockIcon());
    mKeyguardBottomArea.setKeyguardIndicationController(mKeyguardIndicationController);
    // set the initial view visibility
    setAreThereNotifications();
    createIconController();
    // Background thread for any controllers that need it.
    mHandlerThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    // Other icons
    mLocationController = new LocationControllerImpl(mContext, // will post a notification
    mHandlerThread.getLooper());
    mBatteryController = createBatteryController();
    mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() {

        @Override
        public void onPowerSaveChanged(boolean isPowerSave) {
            mHandler.post(mCheckBarModes);
            if (mDozeServiceHost != null) {
                mDozeServiceHost.firePowerSaveChanged(isPowerSave);
            }
        }

        @Override
        public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
        // noop
        }
    });
    mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper());
    mNetworkController.setUserSetupComplete(mUserSetup);
    mHotspotController = new HotspotControllerImpl(mContext);
    mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper());
    mSecurityController = new SecurityControllerImpl(mContext);
    if (mContext.getResources().getBoolean(R.bool.config_showRotationLock)) {
        mRotationLockController = new RotationLockControllerImpl(mContext);
    }
    mUserInfoController = new UserInfoController(mContext);
    mVolumeComponent = getComponent(VolumeComponent.class);
    if (mVolumeComponent != null) {
        mZenModeController = mVolumeComponent.getZenController();
    }
    mCastController = new CastControllerImpl(mContext);
    initSignalCluster(mStatusBarView);
    initSignalCluster(mKeyguardStatusBar);
    initEmergencyCryptkeeperText();
    mFlashlightController = new FlashlightController(mContext);
    mKeyguardBottomArea.setFlashlightController(mFlashlightController);
    mKeyguardBottomArea.setPhoneStatusBar(this);
    mKeyguardBottomArea.setUserSetupComplete(mUserSetup);
    mAccessibilityController = new AccessibilityController(mContext);
    mKeyguardBottomArea.setAccessibilityController(mAccessibilityController);
    mNextAlarmController = new NextAlarmController(mContext);
    mLightStatusBarController = new LightStatusBarController(mIconController, mBatteryController);
    mKeyguardMonitor = new KeyguardMonitor(mContext);
    mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor, mHandler, this);
    if (UserManager.get(mContext).isUserSwitcherEnabled()) {
        createUserSwitcher();
    }
    // Set up the quick settings tile panel
    AutoReinflateContainer container = (AutoReinflateContainer) mStatusBarWindow.findViewById(R.id.qs_auto_reinflate_container);
    if (container != null) {
        final QSTileHost qsh = SystemUIFactory.getInstance().createQSTileHost(mContext, this, mBluetoothController, mLocationController, mRotationLockController, mNetworkController, mZenModeController, mHotspotController, mCastController, mFlashlightController, mUserSwitcherController, mUserInfoController, mKeyguardMonitor, mSecurityController, mBatteryController, mIconController, mNextAlarmController);
        mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindow);
        container.addInflateListener(new InflateListener() {

            @Override
            public void onInflated(View v) {
                QSContainer qsContainer = (QSContainer) v.findViewById(R.id.quick_settings_container);
                qsContainer.setHost(qsh);
                mQSPanel = qsContainer.getQsPanel();
                mQSPanel.setBrightnessMirror(mBrightnessMirrorController);
                mKeyguardStatusBar.setQSPanel(mQSPanel);
                mHeader = qsContainer.getHeader();
                initSignalCluster(mHeader);
                mHeader.setActivityStarter(PhoneStatusBar.this);
            }
        });
    }
    // User info. Trigger first load.
    mKeyguardStatusBar.setUserInfoController(mUserInfoController);
    mKeyguardStatusBar.setUserSwitcherController(mUserSwitcherController);
    mUserInfoController.reloadUserInfo();
    ((BatteryMeterView) mStatusBarView.findViewById(R.id.battery)).setBatteryController(mBatteryController);
    mKeyguardStatusBar.setBatteryController(mBatteryController);
    mReportRejectedTouch = mStatusBarWindow.findViewById(R.id.report_rejected_touch);
    if (mReportRejectedTouch != null) {
        updateReportRejectedTouchVisibility();
        mReportRejectedTouch.setOnClickListener(v -> {
            Uri session = mFalsingManager.reportRejectedTouch();
            if (session == null) {
                return;
            }
            StringWriter message = new StringWriter();
            message.write("Build info: ");
            message.write(SystemProperties.get("ro.build.description"));
            message.write("\nSerial number: ");
            message.write(SystemProperties.get("ro.serialno"));
            message.write("\n");
            PrintWriter falsingPw = new PrintWriter(message);
            FalsingLog.dump(falsingPw);
            falsingPw.flush();
            startActivityDismissingKeyguard(Intent.createChooser(new Intent(Intent.ACTION_SEND).setType("*/*").putExtra(Intent.EXTRA_SUBJECT, "Rejected touch report").putExtra(Intent.EXTRA_STREAM, session).putExtra(Intent.EXTRA_TEXT, message.toString()), "Share rejected touch report").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), true, true);
        });
    }
    PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mBroadcastReceiver.onReceive(mContext, new Intent(pm.isScreenOn() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF));
    mGestureWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "GestureWakeLock");
    mVibrator = mContext.getSystemService(Vibrator.class);
    // receive broadcasts
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
    IntentFilter demoFilter = new IntentFilter();
    if (DEBUG_MEDIA_FAKE_ARTWORK) {
        demoFilter.addAction(ACTION_FAKE_ARTWORK);
    }
    demoFilter.addAction(ACTION_DEMO);
    context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter, android.Manifest.permission.DUMP, null);
    // listen for USER_SETUP_COMPLETE setting (per-user)
    resetUserSetupObserver();
    // disable profiling bars, since they overlap and clutter the output on app windows
    ThreadedRenderer.overrideProperty("disableProfileBars", "true");
    // Private API call to make the shadows look better for Recents
    ThreadedRenderer.overrideProperty("ambientRatio", String.valueOf(1.5f));
    return mStatusBarView;
}
Also used : BrightnessMirrorController(com.android.systemui.statusbar.policy.BrightnessMirrorController) CastControllerImpl(com.android.systemui.statusbar.policy.CastControllerImpl) ScrimView(com.android.systemui.statusbar.ScrimView) RotationLockControllerImpl(com.android.systemui.statusbar.policy.RotationLockControllerImpl) Uri(android.net.Uri) PowerManager(android.os.PowerManager) VolumeComponent(com.android.systemui.volume.VolumeComponent) NextAlarmController(com.android.systemui.statusbar.policy.NextAlarmController) HotspotControllerImpl(com.android.systemui.statusbar.policy.HotspotControllerImpl) StringWriter(java.io.StringWriter) NetworkControllerImpl(com.android.systemui.statusbar.policy.NetworkControllerImpl) KeyguardMonitor(com.android.systemui.statusbar.policy.KeyguardMonitor) FlashlightController(com.android.systemui.statusbar.policy.FlashlightController) LocationControllerImpl(com.android.systemui.statusbar.policy.LocationControllerImpl) PrintWriter(java.io.PrintWriter) Context(android.content.Context) QSContainer(com.android.systemui.qs.QSContainer) IntentFilter(android.content.IntentFilter) BatteryStateChangeCallback(com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback) KeyguardIndicationController(com.android.systemui.statusbar.KeyguardIndicationController) BluetoothControllerImpl(com.android.systemui.statusbar.policy.BluetoothControllerImpl) BatteryMeterView(com.android.systemui.BatteryMeterView) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) HeadsUpManager(com.android.systemui.statusbar.policy.HeadsUpManager) ImageView(android.widget.ImageView) ActivatableNotificationView(com.android.systemui.statusbar.ActivatableNotificationView) BatteryMeterView(com.android.systemui.BatteryMeterView) BackDropView(com.android.systemui.statusbar.BackDropView) DismissView(com.android.systemui.statusbar.DismissView) EmptyShadeView(com.android.systemui.statusbar.EmptyShadeView) View(android.view.View) TextView(android.widget.TextView) ScrimView(com.android.systemui.statusbar.ScrimView) SignalClusterView(com.android.systemui.statusbar.SignalClusterView) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent) AccessibilityController(com.android.systemui.statusbar.policy.AccessibilityController) InflateListener(com.android.systemui.AutoReinflateContainer.InflateListener) SecurityControllerImpl(com.android.systemui.statusbar.policy.SecurityControllerImpl) AutoReinflateContainer(com.android.systemui.AutoReinflateContainer) HandlerThread(android.os.HandlerThread) UserInfoController(com.android.systemui.statusbar.policy.UserInfoController) Vibrator(android.os.Vibrator) RemoteException(android.os.RemoteException) UserSwitcherController(com.android.systemui.statusbar.policy.UserSwitcherController)

Example 90 with IntentFilter

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

the class Clock method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (!mAttached) {
        mAttached = true;
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        filter.addAction(Intent.ACTION_USER_SWITCHED);
        getContext().registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, filter, null, getHandler());
        TunerService.get(getContext()).addTunable(this, CLOCK_SECONDS, StatusBarIconController.ICON_BLACKLIST);
    }
    // NOTE: It's safe to do these after registering the receiver since the receiver always runs
    // in the main thread, therefore the receiver can't run before this method returns.
    // The time zone may have changed while the receiver wasn't registered, so update the Time
    mCalendar = Calendar.getInstance(TimeZone.getDefault());
    // Make sure we update to the current time
    updateClock();
    updateShowSeconds();
}
Also used : IntentFilter(android.content.IntentFilter)

Aggregations

IntentFilter (android.content.IntentFilter)1505 Intent (android.content.Intent)516 Context (android.content.Context)305 BroadcastReceiver (android.content.BroadcastReceiver)285 PendingIntent (android.app.PendingIntent)155 RemoteException (android.os.RemoteException)80 Handler (android.os.Handler)65 ComponentName (android.content.ComponentName)55 PowerManager (android.os.PowerManager)50 View (android.view.View)50 Uri (android.net.Uri)42 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)39 TextView (android.widget.TextView)37 HandlerThread (android.os.HandlerThread)34 ResolveInfo (android.content.pm.ResolveInfo)30 File (java.io.File)30 PackageManager (android.content.pm.PackageManager)28 Point (android.graphics.Point)28 IOException (java.io.IOException)28