Example usage for android.content.pm PackageManager DONT_KILL_APP

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

Introduction

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

Prototype

int DONT_KILL_APP

To view the source code for android.content.pm PackageManager DONT_KILL_APP.

Click Source Link

Document

Flag parameter for #setComponentEnabledSetting(android.content.ComponentName,int,int) to indicate that you don't want to kill the app containing the component.

Usage

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}
 *///w  w  w . j a  v  a  2  s .  c om
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.p3authentication.preferences.Prefs.java

@SuppressWarnings("deprecation")
@Override/*from  www . j  a v  a  2 s .  c o m*/
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    addPreferencesFromResource(R.xml.pref);

    AccessPin = (EditTextPreference) getPreferenceManager().findPreference("KeypadKey");
    final Preference ResetPreference = getPreferenceManager().findPreference("reset_data");
    final Preference EULAPreference = getPreferenceManager().findPreference("eula");
    final Preference AboutUsPreference = getPreferenceManager().findPreference("about_us");
    final Preference UnlockAppsPreference = getPreferenceManager().findPreference("unlock_apps");
    final Preference TouchTolerance = getPreferenceManager().findPreference("touch_tolerance");
    final Preference RedownloadImage = getPreferenceManager().findPreference("redownload_images");
    final Preference RateApp = getPreferenceManager().findPreference("rate_app");
    final CheckBoxPreference GhostStatusPref = (CheckBoxPreference) getPreferenceManager()
            .findPreference("GhostStatus");
    final CheckBoxPreference StartServicePref = (CheckBoxPreference) getPreferenceManager()
            .findPreference("startup_service");
    final ListPreference patterntype = (ListPreference) getPreferenceManager().findPreference("PatternType");
    final ListPreference PatternStealth = (ListPreference) getPreferenceManager()
            .findPreference("PatternStealth");
    if (patterntype.getValue().toString().equals("No Pattern")) {
        PatternStealth.setEnabled(false);
    } else {
        PatternStealth.setEnabled(true);
    }

    if (GhostStatusPref.isChecked()) {
        AccessPin.setEnabled(true);
    } else {
        AccessPin.setEnabled(false);
    }
    AccessPin.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // TODO Auto-generated method stub
            if (newValue.toString().trim().equals("")) {

                Toast.makeText(Prefs.this, "Your Custom PIN cannot be empty.", Toast.LENGTH_LONG).show();

                return false;
            } else if (newValue.toString().length() < 5) {
                Toast.makeText(Prefs.this, "Your Custom PIN must be atleast 5 Digits.", Toast.LENGTH_LONG)
                        .show();

                return false;
            }
            Toast.makeText(Prefs.this, "Your Custom PIN is set.", Toast.LENGTH_LONG).show();
            return true;
        }

    });
    GhostStatusPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                hideLauncherIcon();
                Toast.makeText(Prefs.this, "P3 hidden from App Menu", Toast.LENGTH_SHORT).show();
            } else {
                showLauncherIcon();
                Toast.makeText(Prefs.this, "P3 visible on App Menu", Toast.LENGTH_SHORT).show();
            }
            return true;
        }

    });
    StartServicePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                ComponentName receiver = new ComponentName(Prefs.this, Startup.class);
                PackageManager pm = getPackageManager();

                pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                        PackageManager.DONT_KILL_APP);

            } else {
                ComponentName receiver = new ComponentName(Prefs.this, Startup.class);
                PackageManager pm = getPackageManager();

                pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
            return true;
        }

    });
    patterntype.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // TODO Auto-generated method stub
            if (!newValue.toString().equals("No Pattern")) {
                PatternStealth.setEnabled(true);
            } else {
                PatternStealth.setEnabled(false);
            }
            return true;
        }
    });
    ResetPreference.setOnPreferenceClickListener(this);
    UnlockAppsPreference.setOnPreferenceClickListener(this);
    TouchTolerance.setOnPreferenceClickListener(this);
    RedownloadImage.setOnPreferenceClickListener(this);
    RateApp.setOnPreferenceClickListener(this);
    AboutUsPreference.setOnPreferenceClickListener(this);
    EULAPreference.setOnPreferenceClickListener(this);

}

From source file:co.edu.uniajc.vtf.content.SwipeContentActivity.java

@Override
protected void onPause() {
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    super.onPause();
}

From source file:com.svpino.longhorn.MarketCollectorService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE);
    long lastUpdate = sharedPreferences.getLong(Constants.PREFERENCE_COLLECTOR_LAST_UPDATE, 0);
    boolean retrying = sharedPreferences.getBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, false);
    int retries = sharedPreferences.getInt(Constants.PREFERENCE_COLLECTOR_RETRIES, 0);
    boolean wereWeWaitingForConnectivity = sharedPreferences
            .getBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, false);

    boolean isGlobalCollection = intent.getExtras() == null
            || (intent.getExtras() != null && !intent.getExtras().containsKey(EXTRA_TICKER));

    if (wereWeWaitingForConnectivity) {
        Editor editor = sharedPreferences.edit();
        editor.putBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, false);
        editor.commit();//  w w  w. j a  va 2  s.co m
    }

    if (retrying && isGlobalCollection) {
        Editor editor = sharedPreferences.edit();
        editor.putBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, false);
        editor.putInt(Constants.PREFERENCE_COLLECTOR_RETRIES, 0);
        editor.commit();

        ((AlarmManager) getSystemService(Context.ALARM_SERVICE))
                .cancel(Extensions.createPendingIntent(this, Constants.SCHEDULE_RETRY));
    }

    long currentTime = System.currentTimeMillis();
    if (retrying || wereWeWaitingForConnectivity || !isGlobalCollection
            || (isGlobalCollection && currentTime - lastUpdate > Constants.COLLECTOR_MIN_REFRESH_INTERVAL)) {
        String[] tickers = null;

        if (isGlobalCollection) {
            Log.d(LOG_TAG, "Executing global market information collection...");
            tickers = DataProvider.getStockDataTickers(this);
        } else {
            String ticker = intent.getExtras().containsKey(EXTRA_TICKER)
                    ? intent.getExtras().getString(EXTRA_TICKER)
                    : null;

            Log.d(LOG_TAG, "Executing market information collection for ticker " + ticker + ".");

            tickers = new String[] { ticker };
        }

        try {
            collect(tickers);

            if (isGlobalCollection) {
                Editor editor = sharedPreferences.edit();
                editor.putLong(Constants.PREFERENCE_COLLECTOR_LAST_UPDATE, System.currentTimeMillis());
                editor.commit();
            }

            DataProvider.notifyDataCollectionIsFinished(this, tickers);

            Log.d(LOG_TAG, "Market information collection was successfully completed");
        } catch (Exception e) {
            Log.e(LOG_TAG, "Market information collection failed.", e);

            if (Extensions.areWeOnline(this)) {
                Log.d(LOG_TAG, "Scheduling an alarm for retrying a global market information collection...");

                retries++;

                Editor editor = sharedPreferences.edit();
                editor.putBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, true);
                editor.putInt(Constants.PREFERENCE_COLLECTOR_RETRIES, retries);
                editor.commit();

                long interval = Constants.COLLECTOR_MIN_RETRY_INTERVAL * retries;
                if (interval > Constants.COLLECTOR_MAX_REFRESH_INTERVAL) {
                    interval = Constants.COLLECTOR_MAX_REFRESH_INTERVAL;
                }

                ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC,
                        System.currentTimeMillis() + interval,
                        Extensions.createPendingIntent(this, Constants.SCHEDULE_RETRY));
            } else {
                Log.d(LOG_TAG,
                        "It appears that we are not online, so let's start listening for connectivity updates.");

                Editor editor = sharedPreferences.edit();
                editor.putBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, true);
                editor.commit();

                ComponentName componentName = new ComponentName(this, ConnectivityBroadcastReceiver.class);
                getPackageManager().setComponentEnabledSetting(componentName,
                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            }
        }
    } else if (isGlobalCollection && currentTime - lastUpdate <= Constants.COLLECTOR_MIN_REFRESH_INTERVAL) {
        Log.d(LOG_TAG, "Global market information collection will be skipped since it was performed less than "
                + (Constants.COLLECTOR_MIN_REFRESH_INTERVAL / 60 / 1000) + " minutes ago.");
    }

    stopSelf();
}

From source file:de.stadtrallye.rallyesoft.services.UploadService.java

private void setEnableNetworkStateListener(boolean enable) {
    ComponentName receiver = new ComponentName(getApplicationContext(), NetworkStatusReceiver.class);

    PackageManager pm = getApplicationContext().getPackageManager();

    pm.setComponentEnabledSetting(receiver, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}

From source file:com.heightechllc.breakify.MainActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();

    // Enable or disable the RescheduleReceiver, which restores AlarmManagers when the system
    //  boots or the time changes. We only want it enabled if an alarm is scheduled, or if
    //  Scheduled Start is enabled.
    int enabledState;
    if (timerState == TIMER_STATE_RUNNING || ScheduledStart.isEnabled(this))
        enabledState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    else//from  w  w w  .j a v  a 2 s . c  o m
        enabledState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

    ComponentName receiver = new ComponentName(this, RescheduleReceiver.class);
    getPackageManager().setComponentEnabledSetting(receiver, enabledState, PackageManager.DONT_KILL_APP);

    // Send any unsent analytics events
    if (mixpanel != null)
        mixpanel.flush();
}

From source file:co.edu.uniajc.vtf.content.SwipeContentActivity.java

@Override
protected void onResume() {
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    super.onResume();
}

From source file:com.tasomaniac.muzei.earthview.ui.SettingsFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
    new BackupManager(getActivity()).dataChanged();

    // Potentially enable/disable the launcher activity if the settings button
    // preference has changed.
    final String launcherIntentKey = getString(R.string.pref_key_launcher_intent);
    if (isAdded() && launcherIntentKey.equals(s)) {

        final boolean hideLauncher = sharedPreferences.getBoolean(launcherIntentKey, false);
        getActivity().getPackageManager().setComponentEnabledSetting(
                new ComponentName(getActivity().getPackageName(), LAUNCHER_ACTIVITY_NAME),
                hideLauncher ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }//w  w w.  j a va  2 s  .c  o  m
}

From source file:net.gsantner.opoc.util.ActivityUtils.java

public void setLauncherActivityEnabled(Class activityClass, boolean enable) {
    Context context = _context.getApplicationContext();
    PackageManager pkg = context.getPackageManager();
    ComponentName component = new ComponentName(context, activityClass);
    pkg.setComponentEnabledSetting(component, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}

From source file:com.p3authentication.preferences.Prefs.java

protected void showLauncherIcon() {
    // TODO Auto-generated method stub
    Prefs.this.getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    ComponentName receiver = new ComponentName(Prefs.this, NumberListerner.class);
    PackageManager pm = Prefs.this.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
    AccessPin.setEnabled(false);//w  ww . jav a2s  .c om
}