Java Code Examples for android.content.pm.PackageManager#getComponentEnabledSetting()

The following examples show how to use android.content.pm.PackageManager#getComponentEnabledSetting() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityAliasTools.java    From external-nfc-api with Apache License 2.0 6 votes vote down vote up
public static void setFilter(String component, Context context, boolean enabled) {

        String playIdentifier = getPlayIdentifier(context);

        ComponentName componentName = new ComponentName(playIdentifier, playIdentifier + component);

        // disable alias so that we do not receive our own intents
        PackageManager pm = context.getPackageManager();

        int code;
        if (enabled) {
            Log.d(TAG, "Enable feature " + componentName.getClassName());

            code = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        } else {
            code = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

            Log.d(TAG, "Disable feature " + componentName.getClassName());
        }

        if (pm.getComponentEnabledSetting(componentName) != code) {
            pm.setComponentEnabledSetting(componentName, code, PackageManager.DONT_KILL_APP);
        }
    }
 
Example 2
Source File: GetAwayNotificationListenerService.java    From timecat with Apache License 2.0 6 votes vote down vote up
public static void enableNotificationListener(Context paramContext, ComponentName paramComponentName, boolean paramBoolean) {
    if (Build.VERSION.SDK_INT >= 18) {
        if (checkWriteSecureSettingPermission(paramContext)) {
            if (paramBoolean) {
                PackageManager packageManager = paramContext.getPackageManager();
                if (packageManager.getComponentEnabledSetting(paramComponentName) != 1) {
                    packageManager.setComponentEnabledSetting(paramComponentName, 1, 1);
                }
            }
            ContentResolver contentResolver = paramContext.getContentResolver();
            List localObject = getEnabledNotificationListeners(contentResolver);
            if (paramBoolean) {
                if (!(localObject).contains(paramComponentName)) {
                    (localObject).add(paramComponentName);
                    addNotificationListeners(contentResolver, localObject);
                }
            } else {
                localObject.remove(localObject);
                addNotificationListeners(contentResolver, localObject);
            }
            return;
        }
        throw new SecurityException("android.permission.WRITE_SECURE_SETTINGS not be granted on this devices(SDK=)" + Build.VERSION.SDK_INT);
    }
    throw new UnsupportedOperationException("ENABLED_NOTIFICATION_LISTENERS not be supported on this devices(SDK=)" + Build.VERSION.SDK_INT);
}
 
Example 3
Source File: AppDumperPlugin.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
private void displayBootReceiverState(PrintStream writer) {
    ComponentName componentName = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    writer.print("Boot receiver state: ");
    int state = pm.getComponentEnabledSetting(componentName);
    switch (state) {
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            writer.println("default");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            writer.println("enabled");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            writer.println("disabled");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
            writer.println("disabled by user");
            break;
        default:
            writer.println(state);
            break;
    }
}
 
Example 4
Source File: SipService.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
private void applyComponentEnablingState(boolean active) {
    int enableState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if(active && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.INTEGRATE_TEL_PRIVILEGED) ) {
           // Check whether we should register for stock tel: intents
           // Useful for devices without gsm
           enableState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    }
       PackageManager pm = getPackageManager();
       
       ComponentName cmp = new ComponentName(this, "com.csipsimple.ui.PrivilegedOutgoingCallBroadcaster");
       try {
           if (pm.getComponentEnabledSetting(cmp) != enableState) {
               pm.setComponentEnabledSetting(cmp, enableState, PackageManager.DONT_KILL_APP);
           }
       } catch (IllegalArgumentException e) {
           Log.d(THIS_FILE,
                   "Current manifest has no PrivilegedOutgoingCallBroadcaster -- you can ignore this if voluntary", e);
       }
}
 
Example 5
Source File: WifiBroadcastReceiver.java    From WiFiAfterConnect with Apache License 2.0 5 votes vote down vote up
public static void setEnabled (Context context, boolean enable) {
	if (context == null)
		return;
	PackageManager pm = context.getPackageManager();
	if (pm == null)
		return;
	ComponentName component = new ComponentName (context, WifiBroadcastReceiver.class);
	int status = pm.getComponentEnabledSetting(component);
	int statusNew = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
	if (status != statusNew)
		pm.setComponentEnabledSetting(component,  statusNew, PackageManager.DONT_KILL_APP);
}
 
Example 6
Source File: GcmAvailableHelper.java    From android-job with Apache License 2.0 5 votes vote down vote up
private static void setServiceEnabled(Context context, boolean enabled) {
    try {
        PackageManager packageManager = context.getPackageManager();

        // use a string, the class object probably cannot be instantiated
        ComponentName component = new ComponentName(context, getPlatformGcmServiceClassName());

        int componentEnabled = packageManager.getComponentEnabledSetting(component);
        switch (componentEnabled) {
            case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
                if (!enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                    CAT.i("GCM service disabled");
                }
                break;

            case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT: // default is disable
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
                if (enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    CAT.i("GCM service enabled");
                }
                break;
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
                // do nothing
                break;
        }

    } catch (Throwable t) {
        // just in case, don't let the app crash with each restart
        if (BuildConfig.DEBUG) {
            CAT.e(t.getMessage());
        }
    }
}
 
Example 7
Source File: PropUtil.java    From LocationReportEnabler with GNU General Public License v3.0 5 votes vote down vote up
public static void hideOrShowLauncher(Context context, boolean isHide) {
    PackageManager p = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, SettingActivity.class);
    if (isHide) {
        if (p.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
            p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            Log.d("PropUtil", "Hide the icon.");
        }
    } else {
        if (p.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            Log.d("PropUtil", "Show the icon.");
        }
    }
}
 
Example 8
Source File: VisibilityManager.java    From droid-stealth with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method hides the given class
 *
 * @param context the context to use for this operation
 * @param toHide  the class to hide
 */
public static void hideClass(Context context, Class<?> toHide, int flag) {
	PackageManager pm = context.getPackageManager();
	ComponentName homeName = new ComponentName(context, toHide);
	if (pm != null
			&& pm.getComponentEnabledSetting(homeName) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
		pm.setComponentEnabledSetting(homeName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, flag);
	}
}
 
Example 9
Source File: DeviceTestUtils.java    From JobSchedulerCompat with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean isComponentEnabled(PackageManager manager, ComponentName component) {
    switch (manager.getComponentEnabledSetting(component)) {
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return false;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return true;
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
        default:
            try {
                PackageInfo packageInfo = manager.getPackageInfo(
                        component.getPackageName(),
                        PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES
                                | PackageManager.GET_PROVIDERS | PackageManager.GET_DISABLED_COMPONENTS);
                List<ComponentInfo> components = new ArrayList<>();
                if (packageInfo.activities != null) {
                    Collections.addAll(components, packageInfo.activities);
                }
                if (packageInfo.services != null) {
                    Collections.addAll(components, packageInfo.services);
                }
                if (packageInfo.providers != null) {
                    Collections.addAll(components, packageInfo.providers);
                }
                for (ComponentInfo componentInfo : components) {
                    if (componentInfo.name.equals(component.getClassName())) {
                        return componentInfo.isEnabled();
                    }
                }
                return false;
            } catch (PackageManager.NameNotFoundException e) {
                // the package isn't installed on the device
                return false;
            }
    }
}
 
Example 10
Source File: AlarmUtil.java    From react-native-alarm-notification with MIT License 5 votes vote down vote up
private void enableBootReceiver(Context context) {
    ComponentName receiver = new ComponentName(context, AlarmBootReceiver.class);
    PackageManager pm = context.getPackageManager();

    int setting = pm.getComponentEnabledSetting(receiver);
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
        pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }
}
 
Example 11
Source File: SettingsPresenter.java    From XposedSmsCode with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void hideOrShowLauncherIcon(boolean hide) {
    PackageManager pm = mContext.getPackageManager();
    ComponentName launcherCN = new ComponentName(mContext, Const.HOME_ACTIVITY_ALIAS);
    int state = hide ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    if (pm.getComponentEnabledSetting(launcherCN) != state) {
        pm.setComponentEnabledSetting(launcherCN, state, PackageManager.DONT_KILL_APP);
    }
}
 
Example 12
Source File: FragmentOptionsMisc.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void setOptions() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    PackageManager pm = getContext().getPackageManager();
    int state = pm.getComponentEnabledSetting(new ComponentName(getContext(), ActivitySearch.class));

    swExternalSearch.setChecked(state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    swShortcuts.setChecked(prefs.getBoolean("shortcuts", true));
    swFts.setChecked(prefs.getBoolean("fts", false));
    swEnglish.setChecked(prefs.getBoolean("english", false));
    swWatchdog.setChecked(prefs.getBoolean("watchdog", true));
    swUpdates.setChecked(prefs.getBoolean("updates", true));
    swUpdates.setVisibility(
            Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext())
                    ? View.GONE : View.VISIBLE);
    swExperiments.setChecked(prefs.getBoolean("experiments", false));
    swQueries.setChecked(prefs.getInt("query_threads", 4) < 4);
    swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
    tvUuid.setText(prefs.getString("uuid", null));
    swDebug.setChecked(prefs.getBoolean("debug", false));
    swAuthSasl.setChecked(prefs.getBoolean("auth_sasl", true));
    swCleanupAttachments.setChecked(prefs.getBoolean("cleanup_attachments", false));

    tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors()));

    ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    int class_mb = am.getMemoryClass();
    tvMemoryClass.setText(getString(R.string.title_advanced_memory_class, class_mb + " MB"));

    tvStorageSpace.setText(getString(R.string.title_advanced_storage_space,
            Helper.humanReadableByteCount(Helper.getAvailableStorageSpace(), true),
            Helper.humanReadableByteCount(Helper.getTotalStorageSpace(), true)));
    tvFingerprint.setText(Helper.getFingerprint(getContext()));

    grpDebug.setVisibility(swDebug.isChecked() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
}
 
Example 13
Source File: MainActivity.java    From BiliRoaming with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if ("hide_icon".equals(preference.getKey())) {
        boolean isShow = (boolean) newValue;
        ComponentName aliasName = new ComponentName(getActivity(), MainActivity.class.getName() + "Alias");
        PackageManager packageManager = getActivity().getPackageManager();
        int status = isShow ?
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        if (packageManager.getComponentEnabledSetting(aliasName) != status) {
            packageManager.setComponentEnabledSetting(aliasName, status, PackageManager.DONT_KILL_APP);
        }
    }
    return true;
}
 
Example 14
Source File: HidingManager.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isHidden(Context context) {
    PackageManager pm = context.getPackageManager();
    int state = pm.getComponentEnabledSetting(LAUNCHER_NAME);
    return state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}
 
Example 15
Source File: PackageUtils.java    From Android-Next with Apache License 2.0 4 votes vote down vote up
public static boolean isEnabled(Context context, Class<?> clazz) {
    ComponentName componentName = new ComponentName(context, clazz);
    PackageManager pm = context.getPackageManager();
    return pm.getComponentEnabledSetting(componentName)
            != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}
 
Example 16
Source File: SkillUtils.java    From Easer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isServiceEnabled(Context context, Class<? extends Service> serviceClass) {
    PackageManager pm = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, serviceClass);
    return pm.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}
 
Example 17
Source File: BootReceiver.java    From Maying with Apache License 2.0 4 votes vote down vote up
public static boolean getEnabled(Context context) {
    PackageManager pm = context.getPackageManager();
    ComponentName cn = new ComponentName(context, BootReceiver.class);
    return PackageManager.COMPONENT_ENABLED_STATE_ENABLED == pm.getComponentEnabledSetting(cn);
}
 
Example 18
Source File: DeviceUtil.java    From haxsync with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isWizardShown(Context c){
	PackageManager pm = c.getPackageManager();
	return (pm.getComponentEnabledSetting(new ComponentName(c, WelcomeActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
}
 
Example 19
Source File: PackageUtils.java    From MarsDaemon with Apache License 2.0 4 votes vote down vote up
/**
 * get the component in our package default
 * @param context
 * @param componentClassName
 */
public static boolean isComponentDefault(Context context, String componentClassName){
	PackageManager pm = context.getPackageManager();
	ComponentName componentName = new ComponentName(context.getPackageName(), componentClassName);
	return pm.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}
 
Example 20
Source File: ActivityAliasTools.java    From external-nfc-api with Apache License 2.0 3 votes vote down vote up
public static boolean getFilter(String component, Context context) {
    PackageManager pm = context.getPackageManager();

    String playIdentifier = getPlayIdentifier(context);

    ComponentName componentName = new ComponentName(playIdentifier, playIdentifier + component);

    // disable alias so that we do not receive our own intents

    return pm.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}