Java Code Examples for android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_ENABLED

The following examples show how to use android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_ENABLED .
Example 1
Project: XPrivacy   File: ApplicationInfoEx.java    License: GNU General Public License v3.0 6 votes vote down vote up
public boolean isFrozen(Context context) {
	if (mFrozen == null) {
		PackageManager pm = context.getPackageManager();
		boolean enabled = false;
		for (ApplicationInfo appInfo : mMapAppInfo.values())
			try {
				int setting = pm.getApplicationEnabledSetting(appInfo.packageName);
				enabled = (enabled || setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
				enabled = (enabled || setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
				if (enabled)
					break;
			} catch (IllegalArgumentException ignored) {
			}
		mFrozen = !enabled;
	}
	return mFrozen;
}
 
Example 2
Project: CSipSimple   File: SipService.java    License: 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 3
Project: Android-Next   File: PackageUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setComponentState(Context context, Class<?> clazz, boolean enable) {
    ComponentName componentName = new ComponentName(context, clazz);
    PackageManager pm = context.getPackageManager();
    final int oldState = pm.getComponentEnabledSetting(componentName);
    final int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (newState != oldState) {
        final int flags = PackageManager.DONT_KILL_APP;
        pm.setComponentEnabledSetting(componentName, newState, flags);
    }
}
 
Example 4
Project: android-browser-helper   File: EnableComponentsTestRule.java    License: Apache License 2.0 5 votes vote down vote up
private static void setComponentEnabled(Class clazz, boolean enabled) {
    Context context = InstrumentationRegistry.getContext();
    PackageManager pm = context.getPackageManager();
    ComponentName name = new ComponentName(context, clazz);

    int newState = enabled
            ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    int flags = PackageManager.DONT_KILL_APP;

    if (pm.getComponentEnabledSetting(name) != newState) {
        pm.setComponentEnabledSetting(name, newState, flags);
    }
}
 
Example 5
Project: WiFiAfterConnect   File: WifiBroadcastReceiver.java    License: 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
Project: android_9.0.0_r45   File: PackageManagerShellCommand.java    License: Apache License 2.0 5 votes vote down vote up
private static String enabledSettingToString(int state) {
    switch (state) {
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            return "default";
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return "enabled";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return "disabled";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
            return "disabled-user";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
            return "disabled-until-used";
    }
    return "unknown";
}
 
Example 7
Project: NetGuard   File: Util.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static boolean isEnabled(PackageInfo info, Context context) {
    int setting;
    try {
        PackageManager pm = context.getPackageManager();
        setting = pm.getApplicationEnabledSetting(info.packageName);
    } catch (IllegalArgumentException ex) {
        setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        return info.applicationInfo.enabled;
    else
        return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}
 
Example 8
Project: android-utils   File: BroadcastReceiverUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Enable/Disable Broadcast Receiver
 *
 * @param context the context
 * @param brClass the br class
 * @param enabled the enabled
 */
public static void setStateOfReceiver(Context context, Class<?> brClass, boolean enabled) {
    ComponentName receiverName = new ComponentName(context, brClass.getName());
    PackageManager pm = context.getPackageManager();

    int newstate;
    if (enabled) {
        newstate = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    } else {
        newstate = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }

    pm.setComponentEnabledSetting(receiverName, newstate, PackageManager.DONT_KILL_APP);
}
 
Example 9
Project: custom-tabs-client   File: EnableComponentsTestRule.java    License: Apache License 2.0 5 votes vote down vote up
private static void setComponentEnabled(Class clazz, boolean enabled) {
    Context context = InstrumentationRegistry.getContext();
    PackageManager pm = context.getPackageManager();
    ComponentName name = new ComponentName(context, clazz);

    int newState = enabled
            ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    int flags = PackageManager.DONT_KILL_APP;

    if (pm.getComponentEnabledSetting(name) != newState) {
        pm.setComponentEnabledSetting(name, newState, flags);
    }
}
 
Example 10
Project: InviZible   File: Util.java    License: GNU General Public License v3.0 5 votes vote down vote up
static boolean isEnabled(PackageInfo info, Context context) {
    int setting;
    try {
        PackageManager pm = context.getPackageManager();
        setting = pm.getApplicationEnabledSetting(info.packageName);
    } catch (IllegalArgumentException ex) {
        setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
        Log.w(LOG_TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        return info.applicationInfo.enabled;
    else
        return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}
 
Example 11
Project: mobile-messaging-sdk-android   File: ComponentUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Enables or disables component
 *
 * @param context        context object
 * @param enabled        desired state
 * @param componentClass class of the component
 * @throws ConfigurationException if desired component is not registered in manifest
 */
public static void setState(Context context, boolean enabled, Class componentClass) {
    int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    ComponentName componentName = new ComponentName(context, componentClass);
    try {
        context.getPackageManager().setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
    } catch (Exception e) {
        throw new ConfigurationException(ConfigurationException.Reason.MISSING_REQUIRED_COMPONENT, componentClass.getCanonicalName());
    }
}
 
Example 12
Project: android-host-monitor   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Enables or disables a {@link BroadcastReceiver}.
 * Note: be aware that enabling or disabling a component with DONT_KILL_APP on API 14 or 15
 * will wipe out any ongoing notifications your app has created.
 * http://stackoverflow.com/questions/5624470/enable-and-disable-a-broadcast-receiver
 * @param context application context
 * @param receiver broadcast receiver class to enable or disable
 * @param enabled new status
 */
public static void setBroadcastReceiverEnabled(Context context,
                                               Class<? extends BroadcastReceiver> receiver,
                                               boolean enabled) {
    int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                           : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

    Logger.debug(LOG_TAG, (enabled ? "enabling" : "disabling") + " connectivity receiver");

    context.getPackageManager()
           .setComponentEnabledSetting(new ComponentName(context, receiver),
                                       newState, PackageManager.DONT_KILL_APP);
}
 
Example 13
Project: XposedSmsCode   File: SettingsPresenter.java    License: 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 14
Project: HideMockLocation   File: SettingsFragment.java    License: MIT License 5 votes vote down vote up
private void changeIconView(boolean showIcon) {
    PackageManager packageManager = getActivity().getPackageManager();
    int state = showIcon ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    String alias_package = Common.PACKAGE_NAME + ".MainAlias";
    ComponentName alias = new ComponentName(getActivity(), alias_package);
    packageManager.setComponentEnabledSetting(alias, state,
            PackageManager.DONT_KILL_APP);
}
 
Example 15
Project: Easer   File: SkillUtils.java    License: 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 16
Project: MiPushFramework   File: PushControllerUtils.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static boolean isBootReceiverEnable(Context context) {
    return context.getPackageManager()
            .getComponentEnabledSetting(new ComponentName(context,
                    BootReceiver.class)) ==
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}
 
Example 17
Project: Maying   File: BootReceiver.java    License: Apache License 2.0 4 votes vote down vote up
public static void setEnabled(Context context, boolean enabled) {
    PackageManager pm = context.getPackageManager();
    ComponentName cn = new ComponentName(context, BootReceiver.class);
    int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    pm.setComponentEnabledSetting(cn, state, PackageManager.DONT_KILL_APP);
}
 
Example 18
Project: android-app   File: Settings.java    License: GNU General Public License v3.0 4 votes vote down vote up
public boolean isHandlingHttpScheme() {
    return context.getPackageManager()
            .getComponentEnabledSetting(getHttpSchemeHandlingComponent())
            == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}
 
Example 19
Project: aard2-android   File: Application.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Void doInBackground(Slob[] slobs) {
    Set<String> hosts = new HashSet<String>();
    for (Slob slob : slobs) {
        try {
            String uriValue = slob.getTags().get("uri");
            Uri uri = Uri.parse(uriValue);
            String host = uri.getHost();
            if (host != null) {
                hosts.add(host.toLowerCase());
            }
        }
        catch (Exception ex) {
            Log.w(TAG, ex);
        }
    }

    long t0 = System.currentTimeMillis();
    String packageName = getPackageName();
    try {
        PackageManager pm = getPackageManager();
        PackageInfo p = pm.getPackageInfo(packageName,
                PackageManager.GET_ACTIVITIES | PackageManager.GET_DISABLED_COMPONENTS);
        Log.d(TAG, "Done getting available activities in " + (System.currentTimeMillis() - t0));
        t0 = System.currentTimeMillis();
        for (ActivityInfo activityInfo : p.activities) {
            if (isCancelled()) break;
            if (activityInfo.targetActivity != null) {
                boolean enabled = hosts.contains(activityInfo.name);
                if (enabled) {
                    Log.d(TAG, "Enabling links handling for " + activityInfo.name);
                }
                int setting = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
                pm.setComponentEnabledSetting(new ComponentName(getApplicationContext(), activityInfo.name),
                        setting, PackageManager.DONT_KILL_APP);
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, e);
    }
    Log.d(TAG, "Done enabling activities in " + (System.currentTimeMillis() - t0));
    return null;
}
 
Example 20
Project: OpenHub   File: AppUtils.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static boolean checkApplicationEnabledSetting(Context context, String packageName) {
    int state = context.getPackageManager().getApplicationEnabledSetting(packageName);
    return state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT ||
            state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}