Example usage for android.content.pm PackageManager setComponentEnabledSetting

List of usage examples for android.content.pm PackageManager setComponentEnabledSetting

Introduction

In this page you can find the example usage for android.content.pm PackageManager setComponentEnabledSetting.

Prototype

public abstract void setComponentEnabledSetting(@NonNull ComponentName componentName,
        @EnabledState int newState, @EnabledFlags int flags);

Source Link

Document

Set the enabled setting for a package component (activity, receiver, service, provider).

Usage

From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java

protected void resetPreferredLauncherAndOpenChooser() {
    PackageManager packageManager = getPackageManager();
    ComponentName componentName = new ComponentName(this, HomeLauncherActivity.class);
    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    //        Intent selector = new Intent(Intent.ACTION_MAIN);
    //        selector.addCategory(Intent.CATEGORY_HOME);
    //        selector.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //        startActivity(selector);

    //        Intent fakeIntent = new Intent();
    //        fakeIntent.setAction(Intent.ACTION_MAIN);
    //        fakeIntent.addCategory(Intent.CATEGORY_HOME);
    //        fakeIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
    //                | Intent.FLAG_ACTIVITY_FORWARD_RESULT
    //                | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP
    //                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    //        startActivity(fakeIntent);

    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
            PackageManager.DONT_KILL_APP);
}

From source file:com.ichi2.anki.PreferenceContext.java

/**
 * Code which is run when a SharedPreference change has been detected
 * @param prefs instance of SharedPreferences
 * @param key key in prefs which is being updated
 * @param listener PreferenceActivity of PreferenceFragment which is hosting the preference
 *//*from w w  w . j ava2s .c  o m*/
private void updatePreference(SharedPreferences prefs, String key, PreferenceContext listener) {
    try {
        PreferenceScreen screen = listener.getPreferenceScreen();
        Preference pref = screen.findPreference(key);
        // Handle special cases
        switch (key) {
        case "timeoutAnswer": {
            CheckBoxPreference keepScreenOn = (CheckBoxPreference) screen.findPreference("keepScreenOn");
            keepScreenOn.setChecked(((CheckBoxPreference) pref).isChecked());
            break;
        }
        case LANGUAGE:
            closePreferences();
            break;
        case "convertFenText":
            if (((CheckBoxPreference) pref).isChecked()) {
                ChessFilter.install(Hooks.getInstance(getApplicationContext()));
            } else {
                ChessFilter.uninstall(Hooks.getInstance(getApplicationContext()));
            }
            break;
        case "fixHebrewText":
            if (((CheckBoxPreference) pref).isChecked()) {
                HebrewFixFilter.install(Hooks.getInstance(getApplicationContext()));
                showDialog(DIALOG_HEBREW_FONT);
            } else {
                HebrewFixFilter.uninstall(Hooks.getInstance(getApplicationContext()));
            }
            break;
        case "showProgress":
            getCol().getConf().put("dueCounts", ((CheckBoxPreference) pref).isChecked());
            getCol().setMod();
            break;
        case "showEstimates":
            getCol().getConf().put("estTimes", ((CheckBoxPreference) pref).isChecked());
            getCol().setMod();
            break;
        case "newSpread":
            getCol().getConf().put("newSpread", Integer.parseInt(((ListPreference) pref).getValue()));
            getCol().setMod();
            break;
        case "timeLimit":
            getCol().getConf().put("timeLim", ((NumberRangePreference) pref).getValue() * 60);
            getCol().setMod();
            break;
        case "learnCutoff":
            getCol().getConf().put("collapseTime", ((NumberRangePreference) pref).getValue() * 60);
            getCol().setMod();
            break;
        case "useCurrent":
            getCol().getConf().put("addToCur", ((ListPreference) pref).getValue().equals("0"));
            getCol().setMod();
            break;
        case "dayOffset": {
            int hours = ((SeekBarPreference) pref).getValue();
            Timestamp crtTime = new Timestamp(getCol().getCrt() * 1000);
            Calendar date = GregorianCalendar.getInstance();
            date.setTimeInMillis(crtTime.getTime());
            date.set(Calendar.HOUR_OF_DAY, hours);
            getCol().setCrt(date.getTimeInMillis() / 1000);
            getCol().setMod();
            break;
        }
        case "minimumCardsDueForNotification": {
            ListPreference listpref = (ListPreference) screen.findPreference("minimumCardsDueForNotification");
            if (listpref != null) {
                updateNotificationPreference(listpref);
            }
            break;
        }
        case "reportErrorMode": {
            String value = prefs.getString("reportErrorMode", "");
            AnkiDroidApp.getInstance().setAcraReportingMode(value);
            break;
        }
        case "syncAccount": {
            SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
            String username = preferences.getString("username", "");
            Preference syncAccount = screen.findPreference("syncAccount");
            if (syncAccount != null) {
                if (TextUtils.isEmpty(username)) {
                    syncAccount.setSummary(R.string.sync_account_summ_logged_out);
                } else {
                    syncAccount.setSummary(getString(R.string.sync_account_summ_logged_in, username));
                }
            }
            break;
        }
        case "providerEnabled": {
            ComponentName providerName = new ComponentName(this, "com.ichi2.anki.provider.CardContentProvider");
            PackageManager pm = getPackageManager();
            int state;
            if (((CheckBoxPreference) pref).isChecked()) {
                state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
                Timber.i("AnkiDroid ContentProvider enabled by user");
            } else {
                state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
                Timber.i("AnkiDroid ContentProvider disabled by user");
            }
            pm.setComponentEnabledSetting(providerName, state, PackageManager.DONT_KILL_APP);
            break;
        }
        }
        // Update the summary text to reflect new value
        updateSummary(pref);
    } catch (BadTokenException e) {
        Timber.e(e, "Preferences: BadTokenException on showDialog");
    } catch (NumberFormatException | JSONException e) {
        throw new RuntimeException();
    }
}

From source file:com.android.launcher3.Utilities.java

private static void changeDefaultLauncher(Context context) {
    PackageManager packageManager = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, FakeActivity.class);
    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    Intent selector = new Intent(Intent.ACTION_MAIN);
    selector.addCategory(Intent.CATEGORY_HOME);
    selector.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(selector);/*from  w  ww  . j a v a 2 s  .  c o m*/

    packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
            PackageManager.DONT_KILL_APP);
}

From source file:com.android.usbtuner.UsbInputController.java

/**
 * Enable/disable the component {@link UsbTunerTvInputService}.
 *
 * @param context {@link Context} instance
 * @param enabled {@code true} to enable the service; otherwise {@code false}
 *//* ww  w. ja  va 2 s . c o  m*/
private void enableUsbTunerTvInputService(Context context, boolean enabled) {
    PackageManager pm = context.getPackageManager();
    ComponentName USBTUNER = new ComponentName(context, UsbTunerTvInputService.class);

    // Don't kill app by enabling/disabling TvActivity. If LC is killed by enabling/disabling
    // TvActivity, the following pm.setComponentEnabledSetting doesn't work.
    ((TvApplication) context.getApplicationContext()).handleInputCountChanged(true, enabled, true);
    // Since PackageManager.DONT_KILL_APP delays the operation by 10 seconds
    // (PackageManagerService.BROADCAST_DELAY), we'd better avoid using it. It is used only
    // when the LiveChannels app is active since we don't want to kill the running app.
    int flags = TvApplication.getSingletons(context).getMainActivityWrapper().isCreated()
            ? PackageManager.DONT_KILL_APP
            : 0;
    int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (newState != pm.getComponentEnabledSetting(USBTUNER)) {
        // Send/cancel the USB tuner TV input setup recommendation card.
        TunerSetupActivity.onTvInputEnabled(context, enabled);
        // Enable/disable the USB tuner TV input.
        pm.setComponentEnabledSetting(USBTUNER, newState, flags);
        if (DEBUG)
            Log.d(TAG, "Status updated:" + enabled);
    }
    if (enabled && BuildCompat.isAtLeastN()) {
        TvInputInfo info = mDvbDeviceAccessor.buildTvInputInfo(context);
        if (info != null) {
            Log.i(TAG, "TvInputInfo updated: " + info.toString());
            ((TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE)).updateTvInputInfo(info);
        }
    }
}

From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be called from
 * {@link #onServiceConnected} and when ScreenSpeak resumes from a suspended state.
 *///from w  w  w . j a v a2  s .  c om
private void suspendInfrastructure() {
    if (!isServiceActive()) {
        if (LogUtils.LOG_LEVEL <= Log.ERROR) {
            Log.e(LOGTAG, "Attempted to suspend while already suspended");
        }
        return;
    }

    mDimScreenController.makeScreenBright();

    interruptAllFeedback();
    setServiceState(SERVICE_STATE_SUSPENDED);

    // Some apps depend on these being set to false when ScreenSpeak is disabled.
    if (mSupportsTouchScreen) {
        requestTouchExploration(false);
    }

    if (SUPPORTS_WEB_SCRIPT_TOGGLE) {
        requestWebScripts(false);
    }

    mPrefs.unregisterOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    unregisterReceiver(mActiveReceiver);

    if (mCallStateMonitor != null) {
        mCallStateMonitor.stopMonitor();
    }

    if (mRingerModeAndScreenMonitor != null) {
        unregisterReceiver(mRingerModeAndScreenMonitor);
    }

    if (mMenuManager != null) {
        mMenuManager.clearCache();
    }

    if (mVolumeMonitor != null) {
        unregisterReceiver(mVolumeMonitor);
        mVolumeMonitor.releaseControl();
    }

    if (mBatteryMonitor != null) {
        unregisterReceiver(mBatteryMonitor);
    }

    if (mPackageReceiver != null) {
        unregisterReceiver(mPackageReceiver);
    }

    if (mShakeDetector != null) {
        mShakeDetector.setEnabled(false);
    }

    // The tap detector is enabled through reloadPreferences
    if (mSideTapManager != null) {
        unregisterReceiver(mSideTapManager);
        mSideTapManager.onSuspendInfrastructure();
    }

    // Disable the proxy activity for long-press search.
    final PackageManager packageManager = getPackageManager();
    final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class);
    packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    // Remove any pending notifications that shouldn't persist.
    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancelAll();
}

From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when ScreenSpeak resumes from a
 * suspended state.//w w  w . ja  v a 2 s .co m
 */
private void resumeInfrastructure() {
    if (isServiceActive()) {
        if (LogUtils.LOG_LEVEL <= Log.ERROR) {
            Log.e(LOGTAG, "Attempted to resume while not suspended");
        }
        return;
    }

    setServiceState(SERVICE_STATE_ACTIVE);
    stopForeground(true);

    final AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_SPOKEN;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_HAPTIC;
    info.flags |= AccessibilityServiceInfo.DEFAULT;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
        info.flags |= AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
        info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        info.flags |= AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
    }
    info.notificationTimeout = 0;

    // Ensure the initial touch exploration request mode is correct.
    if (mSupportsTouchScreen && SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(),
            R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default)) {
        info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE;
    }

    setServiceInfo(info);

    if (mRingerModeAndScreenMonitor != null) {
        registerReceiver(mRingerModeAndScreenMonitor, mRingerModeAndScreenMonitor.getFilter());
        // It could now be confused with the current screen state
        mRingerModeAndScreenMonitor.updateScreenState();
    }

    if (mVolumeMonitor != null) {
        registerReceiver(mVolumeMonitor, mVolumeMonitor.getFilter());
    }

    if (mBatteryMonitor != null) {
        registerReceiver(mBatteryMonitor, mBatteryMonitor.getFilter());
    }

    if (mPackageReceiver != null) {
        registerReceiver(mPackageReceiver, mPackageReceiver.getFilter());
        if (mLabelManager != null) {
            mLabelManager.ensureDataConsistency();
        }
    }

    if (mSideTapManager != null) {
        registerReceiver(mSideTapManager, SideTapManager.getFilter());
    }

    mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    // Add the broadcast listener for gestures.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_PERFORM_GESTURE_ACTION);
    registerReceiver(mActiveReceiver, filter, PERMISSION_SCREENSPEAK, null);

    // Enable the proxy activity for long-press search.
    final PackageManager packageManager = getPackageManager();
    final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class);
    packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    reloadPreferences();

    if (mDimScreenController.isDimmingEnabled()) {
        mDimScreenController.makeScreenDim();
    }
}

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when TalkBack resumes from a
 * suspended state./* w  w w .  j  a  va2 s  . co  m*/
 */
private void suspendInfrastructure() {
    if (!isServiceActive()) {
        LogUtils.log(this, Log.ERROR, "Attempted to suspend while already suspended");
        return;
    }

    interruptAllFeedback();
    setServiceState(ServiceState.SUSPENDED);

    setServiceInfo(new AccessibilityServiceInfo());

    mPrefs.unregisterOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    unregisterReceiver(mActiveReceiver);

    if (mCallStateMonitor != null) {
        unregisterReceiver(mCallStateMonitor);
    }

    if (mRingerModeAndScreenMonitor != null) {
        unregisterReceiver(mRingerModeAndScreenMonitor);
    }

    if (mRadialMenuManager != null) {
        unregisterReceiver(mRadialMenuManager);
        mRadialMenuManager.clearCache();
    }

    if (mVolumeMonitor != null) {
        unregisterReceiver(mVolumeMonitor);
        mVolumeMonitor.releaseControl();
    }

    if (mShakeDetector != null) {
        mShakeDetector.setEnabled(false);
    }

    if (SUPPORTS_TOUCH_PREF) {
        final ContentResolver resolver = getContentResolver();
        resolver.unregisterContentObserver(mTouchExploreObserver);
    }

    // Disable the proxy activity for long-press search.
    final PackageManager packageManager = getPackageManager();
    final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class);
    packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    // Remove any pending notifications that shouldn't persist.
    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancelAll();

    if (mTtsOverlay != null) {
        mTtsOverlay.hide();
    }
}

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when TalkBack resumes from a
 * suspended state.//from  www  .j  a  va2 s  . c om
 */
private void resumeInfrastructure() {
    if (isServiceActive()) {
        LogUtils.log(this, Log.ERROR, "Attempted to resume while not suspended");
        return;
    }

    setServiceState(ServiceState.ACTIVE);
    stopForeground(true);

    final AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_SPOKEN;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_HAPTIC;
    info.flags |= AccessibilityServiceInfo.DEFAULT;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REPORT_VIEW_IDS;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_FILTER_KEY_EVENTS;
    info.notificationTimeout = 0;

    // Ensure the initial touch exploration request mode is correct.
    if (SUPPORTS_TOUCH_PREF && SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(),
            R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default)) {
        info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_TOUCH_EXPLORATION_MODE;
    }

    setServiceInfo(info);

    if (mCallStateMonitor != null) {
        registerReceiver(mCallStateMonitor, mCallStateMonitor.getFilter());
    }

    if (mRingerModeAndScreenMonitor != null) {
        registerReceiver(mRingerModeAndScreenMonitor, mRingerModeAndScreenMonitor.getFilter());
    }

    if (mTextToSpeechManager != null) {
        mTextToSpeechManager.startDiscovery();
    }

    if (mRadialMenuManager != null) {
        registerReceiver(mRadialMenuManager, mRadialMenuManager.getFilter());
    }

    if (mVolumeMonitor != null) {
        registerReceiver(mVolumeMonitor, mVolumeMonitor.getFilter());
    }

    mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    // Add the broadcast listener for gestures.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_PERFORM_GESTURE);
    registerReceiver(mActiveReceiver, filter, PERMISSION_TALKBACK, null);

    // Enable the proxy activity for long-press search.
    final PackageManager packageManager = getPackageManager();
    final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class);
    packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    reloadPreferences();
}

From source file:com.google.android.marvin.talkback.TalkBackService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when TalkBack resumes from a
 * suspended state.//from   w  w  w . j  ava  2 s  .  co m
 */
private void suspendInfrastructure() {
    if (!isServiceActive()) {
        LogUtils.log(this, Log.ERROR, "Attempted to suspend while already suspended");
        return;
    }

    interruptAllFeedback();
    setServiceState(ServiceState.SUSPENDED);

    setServiceInfo(new AccessibilityServiceInfo());

    mPrefs.unregisterOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    unregisterReceiver(mActiveReceiver);

    if (mCallStateMonitor != null) {
        unregisterReceiver(mCallStateMonitor);
    }

    if (mRingerModeAndScreenMonitor != null) {
        unregisterReceiver(mRingerModeAndScreenMonitor);
    }

    if (mRadialMenuManager != null) {
        unregisterReceiver(mRadialMenuManager);
        mRadialMenuManager.clearCache();
    }

    if (mVolumeMonitor != null) {
        unregisterReceiver(mVolumeMonitor);
        mVolumeMonitor.releaseControl();
    }

    if (mPackageReceiver != null) {
        unregisterReceiver(mPackageReceiver);
    }

    if (mShakeDetector != null) {
        mShakeDetector.setEnabled(false);
    }

    if (SUPPORTS_TOUCH_PREF) {
        final ContentResolver resolver = getContentResolver();
        resolver.unregisterContentObserver(mTouchExploreObserver);
    }

    // Disable the proxy activity for long-press search.
    final PackageManager packageManager = getPackageManager();
    final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class);
    packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);

    // Remove any pending notifications that shouldn't persist.
    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancelAll();

    if (mTtsOverlay != null) {
        mTtsOverlay.hide();
    }
}

From source file:com.google.android.marvin.talkback.TalkBackService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when TalkBack resumes from a
 * suspended state./*w  w  w  . j  a v a 2s . c o  m*/
 */
private void resumeInfrastructure() {
    if (isServiceActive()) {
        LogUtils.log(this, Log.ERROR, "Attempted to resume while not suspended");
        return;
    }

    setServiceState(ServiceState.ACTIVE);
    stopForeground(true);

    final AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_SPOKEN;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
    info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_HAPTIC;
    info.flags |= AccessibilityServiceInfo.DEFAULT;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REPORT_VIEW_IDS;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_FILTER_KEY_EVENTS;
    info.notificationTimeout = 0;

    // Ensure the initial touch exploration request mode is correct.
    if (SUPPORTS_TOUCH_PREF && SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(),
            R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default)) {
        info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_TOUCH_EXPLORATION_MODE;
    }

    setServiceInfo(info);

    if (mCallStateMonitor != null) {
        registerReceiver(mCallStateMonitor, mCallStateMonitor.getFilter());
    }

    if (mRingerModeAndScreenMonitor != null) {
        registerReceiver(mRingerModeAndScreenMonitor, mRingerModeAndScreenMonitor.getFilter());
    }

    if (mTextToSpeechManager != null) {
        mTextToSpeechManager.startDiscovery();
    }

    if (mRadialMenuManager != null) {
        registerReceiver(mRadialMenuManager, mRadialMenuManager.getFilter());
    }

    if (mVolumeMonitor != null) {
        registerReceiver(mVolumeMonitor, mVolumeMonitor.getFilter());
    }

    if (mPackageReceiver != null) {
        registerReceiver(mPackageReceiver, mPackageReceiver.getFilter());
        if (mLabelManager != null) {
            mLabelManager.ensureDataConsistency();
        }
    }

    mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    // Add the broadcast listener for gestures.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_PERFORM_GESTURE_ACTION);
    registerReceiver(mActiveReceiver, filter, PERMISSION_TALKBACK, null);

    // Enable the proxy activity for long-press search.
    final PackageManager packageManager = getPackageManager();
    final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class);
    packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    reloadPreferences();
}