Example usage for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DISABLED

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

Introduction

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

Prototype

int COMPONENT_ENABLED_STATE_DISABLED

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

Click Source Link

Document

Flag for #setApplicationEnabledSetting(String,int,int) and #setComponentEnabledSetting(ComponentName,int,int) : This component or application has been explicitly disabled, regardless of what it has specified in its manifest.

Usage

From source file:com.android.messaging.receiver.SmsReceiver.java

/**
 * Enable or disable the SmsReceiver as appropriate. Pre-KLP we use this receiver for
 * receiving incoming SMS messages. For KLP+ this receiver is not used when running as the
 * primary user and the SmsDeliverReceiver is used for receiving incoming SMS messages.
 * When running as a secondary user, this receiver is still used to trigger the incoming
 * notification.//ww w .j a v  a 2  s .  com
 */
public static void updateSmsReceiveHandler(final Context context) {
    boolean smsReceiverEnabled;
    boolean mmsWapPushReceiverEnabled;
    boolean respondViaMessageEnabled;
    boolean broadcastAbortEnabled;

    if (OsUtil.isAtLeastKLP()) {
        // When we're running as the secondary user, we don't get the new SMS_DELIVER intent,
        // only the primary user receives that. As secondary, we need to go old-school and
        // listen for the SMS_RECEIVED intent. For the secondary user, use this SmsReceiver
        // for both sms and mms notification. For the primary user on KLP (and above), we don't
        // use the SmsReceiver.
        smsReceiverEnabled = OsUtil.isSecondaryUser();
        // On KLP use the new deliver event for mms
        mmsWapPushReceiverEnabled = false;
        // On KLP we need to always enable this handler to show in the list of sms apps
        respondViaMessageEnabled = true;
        // On KLP we don't need to abort the broadcast
        broadcastAbortEnabled = false;
    } else {
        // On JB we use the sms receiver for both sms/mms delivery
        final boolean carrierSmsEnabled = PhoneUtils.getDefault().isSmsEnabled();
        smsReceiverEnabled = carrierSmsEnabled;

        // On JB we use the mms receiver when sms/mms is enabled
        mmsWapPushReceiverEnabled = carrierSmsEnabled;
        // On JB this is dynamic to make sure we don't show in dialer if sms is disabled
        respondViaMessageEnabled = carrierSmsEnabled;
        // On JB we need to abort broadcasts if SMS is enabled
        broadcastAbortEnabled = carrierSmsEnabled;
    }

    final PackageManager packageManager = context.getPackageManager();
    final boolean logv = LogUtil.isLoggable(TAG, LogUtil.VERBOSE);
    if (smsReceiverEnabled) {
        if (logv) {
            LogUtil.v(TAG, "Enabling SMS message receiving");
        }
        packageManager.setComponentEnabledSetting(new ComponentName(context, SmsReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    } else {
        if (logv) {
            LogUtil.v(TAG, "Disabling SMS message receiving");
        }
        packageManager.setComponentEnabledSetting(new ComponentName(context, SmsReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
    if (mmsWapPushReceiverEnabled) {
        if (logv) {
            LogUtil.v(TAG, "Enabling MMS message receiving");
        }
        packageManager.setComponentEnabledSetting(new ComponentName(context, MmsWapPushReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    } else {
        if (logv) {
            LogUtil.v(TAG, "Disabling MMS message receiving");
        }
        packageManager.setComponentEnabledSetting(new ComponentName(context, MmsWapPushReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
    if (broadcastAbortEnabled) {
        if (logv) {
            LogUtil.v(TAG, "Enabling SMS/MMS broadcast abort");
        }
        packageManager.setComponentEnabledSetting(new ComponentName(context, AbortSmsReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
        packageManager.setComponentEnabledSetting(new ComponentName(context, AbortMmsWapPushReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    } else {
        if (logv) {
            LogUtil.v(TAG, "Disabling SMS/MMS broadcast abort");
        }
        packageManager.setComponentEnabledSetting(new ComponentName(context, AbortSmsReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        packageManager.setComponentEnabledSetting(new ComponentName(context, AbortMmsWapPushReceiver.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
    if (respondViaMessageEnabled) {
        if (logv) {
            LogUtil.v(TAG, "Enabling respond via message intent");
        }
        packageManager.setComponentEnabledSetting(
                new ComponentName(context, NoConfirmationSmsSendService.class),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    } else {
        if (logv) {
            LogUtil.v(TAG, "Disabling respond via message intent");
        }
        packageManager.setComponentEnabledSetting(
                new ComponentName(context, NoConfirmationSmsSendService.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
}

From source file:com.emotion.emotioncontrol.MainActivity.java

public void setLauncherIconEnabled(boolean enabled) {
    PackageManager p = getPackageManager();
    int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    p.setComponentEnabledSetting(new ComponentName(this, LauncherActivity.class), newState,
            PackageManager.DONT_KILL_APP);
}

From source file:com.farmerbb.taskbar.fragment.AdvancedFragment.java

@SuppressLint("SetTextI18n")
@Override/*from  w w  w  .  ja  v a2s.c om*/
public boolean onPreferenceClick(final Preference p) {
    final SharedPreferences pref = U.getSharedPreferences(getActivity());

    switch (p.getKey()) {
    case "clear_pinned_apps":
        Intent clearIntent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            clearIntent = new Intent(getActivity(), ClearDataActivity.class);
            break;
        case "dark":
            clearIntent = new Intent(getActivity(), ClearDataActivityDark.class);
            break;
        }

        startActivity(clearIntent);
        break;
    case "launcher":
        if (U.canDrawOverlays(getActivity())) {
            ComponentName component = new ComponentName(getActivity(), HomeActivity.class);
            getActivity().getPackageManager().setComponentEnabledSetting(component,
                    ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        } else {
            U.showPermissionDialog(getActivity());
            ((CheckBoxPreference) p).setChecked(false);
        }

        if (!((CheckBoxPreference) p).isChecked())
            LocalBroadcastManager.getInstance(getActivity())
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
        break;
    case "keyboard_shortcut":
        ComponentName component = new ComponentName(getActivity(), KeyboardShortcutActivity.class);
        getActivity().getPackageManager()
                .setComponentEnabledSetting(component,
                        ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
        break;
    case "dashboard_grid_size":
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LinearLayout dialogLayout = (LinearLayout) View.inflate(getActivity(), R.layout.dashboard_size_dialog,
                null);

        boolean isPortrait = getActivity().getApplicationContext().getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
        boolean isLandscape = getActivity().getApplicationContext().getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

        int editTextId = -1;
        int editText2Id = -1;

        if (isPortrait) {
            editTextId = R.id.fragmentEditText2;
            editText2Id = R.id.fragmentEditText1;
        }

        if (isLandscape) {
            editTextId = R.id.fragmentEditText1;
            editText2Id = R.id.fragmentEditText2;
        }

        final EditText editText = (EditText) dialogLayout.findViewById(editTextId);
        final EditText editText2 = (EditText) dialogLayout.findViewById(editText2Id);

        builder.setView(dialogLayout).setTitle(R.string.dashboard_grid_size)
                .setPositiveButton(R.string.action_ok, (dialog, id) -> {
                    boolean successfullyUpdated = false;

                    String widthString = editText.getText().toString();
                    String heightString = editText2.getText().toString();

                    if (widthString.length() > 0 && heightString.length() > 0) {
                        int width = Integer.parseInt(widthString);
                        int height = Integer.parseInt(heightString);

                        if (width > 0 && height > 0) {
                            SharedPreferences.Editor editor = pref.edit();
                            editor.putInt("dashboard_width", width);
                            editor.putInt("dashboard_height", height);
                            editor.apply();

                            updateDashboardGridSize(true);
                            successfullyUpdated = true;
                        }
                    }

                    if (!successfullyUpdated)
                        U.showToast(getActivity(), R.string.invalid_grid_size);
                }).setNegativeButton(R.string.action_cancel, null);

        editText.setText(Integer.toString(pref.getInt("dashboard_width",
                getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_width))));
        editText2.setText(Integer.toString(pref.getInt("dashboard_height",
                getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_height))));

        AlertDialog dialog = builder.create();
        dialog.show();

        new Handler().post(() -> {
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT);
        });

        break;
    case "navigation_bar_buttons":
        Intent intent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            intent = new Intent(getActivity(), NavigationBarButtonsActivity.class);
            break;
        case "dark":
            intent = new Intent(getActivity(), NavigationBarButtonsActivityDark.class);
            break;
        }

        startActivity(intent);
        break;
    }

    return true;
}

From source file:com.emotion.emotioncontrol.MainActivity.java

public boolean isLauncherIconEnabled() {
    PackageManager p = getPackageManager();
    int componentStatus = p.getComponentEnabledSetting(new ComponentName(this, LauncherActivity.class));
    return componentStatus != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}

From source file:com.github.michalbednarski.intentslab.editor.ComponentPickerDialogFragment.java

private static boolean isComponentEnabled(PackageManager pm, ResolveInfo info) {
    final boolean defaultEnabled;
    final ComponentName componentName;

    ActivityInfo activityInfo = info.activityInfo;
    if (activityInfo != null) {
        if (!activityInfo.applicationInfo.enabled) {
            return false;
        }/*from w  w w  .  jav a2 s.com*/
        defaultEnabled = activityInfo.enabled;
        componentName = new ComponentName(activityInfo.packageName, activityInfo.name);
    } else {
        ServiceInfo serviceInfo = info.serviceInfo;
        if (!serviceInfo.applicationInfo.enabled) {
            return false;
        }
        defaultEnabled = serviceInfo.enabled;
        componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
    }

    int enabledSetting = pm.getComponentEnabledSetting(componentName);
    if (enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
        return defaultEnabled;
    } else {
        return enabledSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }
}

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

@Override
public void onPause() {
    super.onPause();
    ComponentName loComponent = new ComponentName(this, NetworkStatusReceiver.class);
    this.getPackageManager().setComponentEnabledSetting(loComponent,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    try {//from  w  w w  . ja  v  a 2s. c  o  m
        LocationServices.FusedLocationApi.removeLocationUpdates(coGoogleApiClient, this);
    } catch (Exception ex) {
    }
    this.hideProgressDialog();
}

From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java

@Override
protected Integer doInBackground(Void... params) {

    SharedPreferences prefs = dataService.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);

    // Connectivity receiver.
    final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    ComponentName receiver = new ComponentName(dataService, WifiReceiver.class);
    PackageManager pm = dataService.getPackageManager();
    if (activeNetwork == null || !activeNetwork.isConnected()) {
        // We've missed a scheduled update. Enable the receiver so it can launch an update when we reconnect.
        Log.d(LOG_TAG, "Missed library update: not connected. Enabling connectivity receiver.");
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
        return RESULT_CODE_FAILURE;
    } else {// w w  w.jav  a  2 s  .  c o  m
        // We are connected. Disable the receiver.
        Log.d(LOG_TAG, "Library updater connected. Disabling connectivity receiver.");
        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

    InputStream in = null;
    String etag = prefs.getString(SETTING_LIBRARY_ETAG, null);

    try {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        if (etag != null && !force) {
            conn.setRequestProperty("If-None-Match", etag);
        }

        int code = conn.getResponseCode();
        switch (code) {
        case HttpStatus.SC_NOT_MODIFIED:
            // If we got a 304, we're done.
            // Use failure code to indicate there is no temp db to copy over.
            Log.d(LOG_TAG, "304 in library response.");
            return RESULT_CODE_FAILURE;
        default:
            // Odd, but on 1/3/13 I received correct json responses with a -1 for responseCode. Fall through.
            Log.w(LOG_TAG, "Error code in library response: " + code);
        case HttpStatus.SC_OK:
            // Parse response.
            in = conn.getInputStream();
            JsonFactory factory = new JsonFactory();
            final JsonParser parser = factory.createJsonParser(in);

            SQLiteDatabase tempDb = tempDbHelper.getWritableDatabase();
            tempDb.beginTransaction();
            try {
                tempDb.execSQL("delete from topic");
                tempDb.execSQL("delete from topicvideo");
                tempDb.execSQL("delete from video");

                parseObject(parser, tempDb, null, 0);
                tempDb.setTransactionSuccessful();
            } catch (Exception e) {
                e.printStackTrace();
                return RESULT_CODE_FAILURE;
            } finally {
                tempDb.endTransaction();
                tempDb.close();
            }

            // Save etag once we've successfully parsed the response.
            etag = conn.getHeaderField("ETag");
            prefs.edit().putString(SETTING_LIBRARY_ETAG, etag).apply();

            // Move this new content from the temp db into the main one.
            mergeDbs();

            return RESULT_CODE_SUCCESS;
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        tempDbHelper.close();
    }

    return RESULT_CODE_FAILURE;
}

From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java

public void cancelAlarm(Context context, int ID) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Cancel Alarm using Reminder ID
    mPendingIntent = PendingIntent.getBroadcast(context, ID, new Intent(context, AlarmReceiver.class), 0);
    mAlarmManager.cancel(mPendingIntent);

    // Disable alarm
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:org.traccar.client.MainFragment.java

private void removeLauncherIcon() {
    String className = MainActivity.class.getCanonicalName().replace(".MainActivity", ".Launcher");
    ComponentName componentName = new ComponentName(getActivity().getPackageName(), className);
    PackageManager packageManager = getActivity().getPackageManager();
    if (packageManager
            .getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
        packageManager.setComponentEnabledSetting(componentName,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setMessage(getString(R.string.hidden_alert));
        builder.setPositiveButton(android.R.string.ok, null);
        builder.show();/*from   w  ww  .  ja  va  2s  .c o  m*/
    }
}

From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java

public void cancelAlarm(Context context, int ID) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Cancel Alarm using Reminder ID
    mPendingIntent = PendingIntent.getBroadcast(context, ID, new Intent(context, AutomuteAlarmReceiver.class),
            0);//from www.j av  a 2s  . com
    mAlarmManager.cancel(mPendingIntent);

    // Disable alarm
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}