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

The following are Jave code examples for showing how to use COMPONENT_ENABLED_STATE_ENABLED of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: adyen-android   File: RedirectionHandlerReceiver.java   View Source Code Vote up 6 votes
@Override
public void onReceive(final Context context, final Intent intent) {
    if (intent == null) {
        return;
    }
    final String packageName = intent.getStringExtra("PackageName");
    PackageManager pm = context.getApplicationContext().getPackageManager();
    if (PackageManager.COMPONENT_ENABLED_STATE_ENABLED == pm.getComponentEnabledSetting(new ComponentName(context,
            RedirectHandlerActivity.class))
            && !context.getPackageName().equals(packageName)) {
        Log.d(TAG, "Disabling RedirectHandlerActivity for this application: " + context.getPackageName());
        pm.setComponentEnabledSetting(new ComponentName(context, RedirectHandlerActivity.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        final Intent returnIntent = new Intent();
        returnIntent.setAction(REDIRECT_PROBLEM_INTENT);
        returnIntent.putExtra(REDIRECT_RETURN_URI_KEY, intent.getData());
        LocalBroadcastManager.getInstance(context).sendBroadcast(returnIntent);
    }

}
 
Example 2
Project: CSipSimple   File: SipService.java   View Source Code Vote up 6 votes
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: ScreenOffTime   File: MainActivity.java   View Source Code Vote up 6 votes
private void disableComponent() {
        PackageManager packageManager = getPackageManager();
        ComponentName componentName = new ComponentName(this, MainActivity.class);
//        packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
//                PackageManager.DONT_KILL_APP);
        int res = packageManager.getComponentEnabledSetting(componentName);
        if (res == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
                || res == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            // 隐藏应用图标
            packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        } else {
            // 显示应用图标
            packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
                    PackageManager.DONT_KILL_APP);
        }
    }
 
Example 4
Project: bluewatcher   File: SettingsActivity.java   View Source Code Vote up 6 votes
private void loadConfiguration() throws JSONException {
	ComponentName componentName = new ComponentName("com.bluewatcher", "com.bluewatcher.BootupLoader");
    int setting = pm.getComponentEnabledSetting(componentName);
    boolean enabled = false;
    if(setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
    	enabled = true;
    }
	String reconnectMessage = ConfigurationManager.getInstance().load(RECONNECT_MESSAGE_CONFIG, Boolean.toString(true));
	String controlMode = ConfigurationManager.getInstance().load(SEND_CONTROL_MODE, Boolean.toString(true));
	String gba400Clean = ConfigurationManager.getInstance().load(GBA400_CLEAN_NOTIFICATION, Boolean.toString(false));
	String disableServerOption = ConfigurationManager.getInstance().load(DISABLE_SERVER_SERVICES, Boolean.toString(false));
	startAtBoot.setChecked(enabled);
	showReconnectMessage.setChecked(Boolean.parseBoolean(reconnectMessage));
	sendControlMode.setChecked(Boolean.parseBoolean(controlMode));
	gba400CleanNotification.setChecked(Boolean.parseBoolean(gba400Clean));
	disableServer.setChecked(Boolean.parseBoolean(disableServerOption));
}
 
Example 5
Project: Android-Firewall   File: Rule.java   View Source Code Vote up 6 votes
private Rule(PackageInfo info, boolean wifi_blocked, boolean other_blocked, boolean changed, Context context) {
    PackageManager pm = context.getPackageManager();
    this.info = info;
    this.name = info.applicationInfo.loadLabel(pm).toString();
    this.system = ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);

    int setting = pm.getApplicationEnabledSetting(info.packageName);
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        this.disabled = !info.applicationInfo.enabled;
    else
        this.disabled = (setting != PackageManager.COMPONENT_ENABLED_STATE_ENABLED);

    this.wifi_blocked = wifi_blocked;
    this.other_blocked = other_blocked;
    this.changed = changed;
}
 
Example 6
Project: XPrivacy   File: ApplicationInfoEx.java   View Source Code Vote up 6 votes
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 7
Project: q-mail   File: QMail.java   View Source Code Vote up 5 votes
private static void setServicesEnabled(Context context, boolean enabled, Integer wakeLockId) {

        PackageManager pm = context.getPackageManager();

        if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            /*
             * If no accounts now exist but the service is still enabled we're about to disable it
             * so we'll reschedule to kill off any existing alarms.
             */
            MailService.actionReset(context, wakeLockId);
        }
        Class<?>[] classes = { MessageCompose.class, BootReceiver.class, MailService.class };

        for (Class<?> clazz : classes) {

            boolean alreadyEnabled = pm.getComponentEnabledSetting(new ComponentName(context, clazz)) ==
                                     PackageManager.COMPONENT_ENABLED_STATE_ENABLED;

            if (enabled != alreadyEnabled) {
                pm.setComponentEnabledSetting(
                    new ComponentName(context, clazz),
                    enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
            }
        }

        if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            /*
             * And now if accounts do exist then we've just enabled the service and we want to
             * schedule alarms for the new accounts.
             */
            MailService.actionReset(context, wakeLockId);
        }

    }
 
Example 8
Project: JobSchedulerCompat   File: DeviceTestUtils.java   View Source Code Vote up 5 votes
@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 9
Project: SOS-The-Healthcare-Companion   File: GlucosioAlarmManager.java   View Source Code Vote up 5 votes
private void enableBootReceiver(boolean value) {
    ComponentName receiver = new ComponentName(context, GlucosioBroadcastReceiver.class);
    PackageManager pm = context.getPackageManager();

    int componentState = value ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

    pm.setComponentEnabledSetting(receiver,
            componentState,
            PackageManager.DONT_KILL_APP);
}
 
Example 10
Project: Bridge   File: PackageManagerUtils.java   View Source Code Vote up 5 votes
public static void setComponentState(PackageManager pm, ComponentName componentName, boolean enable) {
    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 11
Project: Bridge   File: PackageManagerUtils.java   View Source Code Vote up 5 votes
public static boolean isComponentEnabled(PackageManager pm, String pkg, String cls) {
    ComponentName componentName = new ComponentName(pkg, cls);
    int componentEnabledSetting = pm.getComponentEnabledSetting(componentName);

    switch (componentEnabledSetting) {
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return false;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return true;
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
        default:
            // We need to get the application info to get the component's default state
            try {
                PackageInfo packageInfo = pm.getPackageInfo(pkg, 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(cls)) {
                        return componentInfo.enabled; //This is the default value (set in AndroidManifest.xml)
                        //return componentInfo.isEnabled(); //Whole package dependant
                    }
                }

                // the component is not declared in the AndroidManifest
                return false;
            } catch (PackageManager.NameNotFoundException e) {
                // the package isn't installed on the device
                return false;
            }
    }
}
 
Example 12
Project: MiPushFramework   File: CheckSupportUtils.java   View Source Code Vote up 5 votes
/**
 * Check package's MiPush custom receiver (handle com.xiaomi.mipush.RECEIVE_MESSAGE action)
 * is enabled.
 * @see PushMessageReceiver
 * @see Constants#ACTION_RECEIVE_MESSAGE
 * @param info Package info
 * @return enable status. If this package not have custom receiver, will
 * still returns true.
 */
private boolean customReceiverPass (PackageInfo info, PackageManager packageManager) {
    //if (info.receivers == null)
    //    return true;
    Intent intent = new Intent();
    intent.setPackage(info.packageName);
    //intent.setAction(Constants.ACTION_RECEIVE_MESSAGE);
    for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent,
            PackageManager.GET_RESOLVED_FILTER |
    PackageManager.GET_DISABLED_COMPONENTS)) {
        ActivityInfo activityInfo = resolveInfo.activityInfo;
        if (!activityInfo.packageName.equals(info.packageName))
            continue;
        IntentFilter filter = resolveInfo.filter;
        if (filter != null && filter.hasAction(Constants.ACTION_RECEIVE_MESSAGE)) {
            boolean enabled = packageManager.getComponentEnabledSetting(new ComponentName(
                    activityInfo.packageName, activityInfo.name
            )) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
            Log4a.i(TAG, "Handle receiver: " + activityInfo.name +
            "; enabled: " + enabled);
            return enabled;
        }
    }
    Log4a.d(TAG, "Not found custom message receiver in " + info.packageName);
    // Not found
    return true;
}
 
Example 13
Project: MKAPP   File: Util.java   View Source Code Vote up 5 votes
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 14
Project: BlackList   File: DefaultSMSAppHelper.java   View Source Code Vote up 5 votes
public static void enableSMSReceiving(Context context, boolean enable) {
    int state = (enable ?
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    PackageManager packageManager = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, SMSBroadcastReceiver.class);
    packageManager.setComponentEnabledSetting(
            componentName,
            state,
            PackageManager.DONT_KILL_APP);
}
 
Example 15
Project: KTools   File: SystemActivity.java   View Source Code Vote up 5 votes
@OnClick(R.id.btn_hide_app_icon)
public void onHideAppIconClicked() {
    PackageManager manager = getPackageManager();
    ComponentName componentName = new ComponentName(this, MainActivity.class);
    int status = manager.getComponentEnabledSetting(componentName);
    if (status == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT ||
            status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
        manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    } else {
        manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
    }

}
 
Example 16
Project: bluewatcher   File: SettingsActivity.java   View Source Code Vote up 5 votes
private void saveConfiguration() throws JSONException {
	PackageManager pm = getPackageManager();
	ComponentName componentName = new ComponentName("com.bluewatcher", "com.bluewatcher.BootupLoader");
	int state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
	if( !startAtBoot.isChecked() )
		state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
	pm.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
	ConfigurationManager.getInstance().save(RECONNECT_MESSAGE_CONFIG, Boolean.toString(showReconnectMessage.isChecked()));
	ConfigurationManager.getInstance().save(SEND_CONTROL_MODE, Boolean.toString(sendControlMode.isChecked()));
	ConfigurationManager.getInstance().save(GBA400_CLEAN_NOTIFICATION, Boolean.toString(gba400CleanNotification.isChecked()));
	ConfigurationManager.getInstance().save(DISABLE_SERVER_SERVICES, Boolean.toString(disableServer.isChecked()));
}
 
Example 17
Project: custode   File: SettingsActivity.java   View Source Code Vote up 5 votes
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(PREFERENCES_REPLY_LOCATION_REQUESTS_ALWAYS_KEY)) {
        boolean replyAlways = sharedPreferences.getBoolean(PREFERENCES_REPLY_LOCATION_REQUESTS_ALWAYS_KEY, false);
        int state = replyAlways ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        ComponentName receiver = new ComponentName(this, SmsUpdateReceiver.class);
        this.getPackageManager().setComponentEnabledSetting(receiver, state, PackageManager.DONT_KILL_APP);
    } else if (key.equals(PREFERENCES_SMS_LIMIT_KEY) && generalPreferenceFragment != null) {
        String newSummary = generalPreferenceFragment.getSmsLimitSummary();
        generalPreferenceFragment.findPreference(PREFERENCES_SMS_LIMIT_KEY).setSummary(newSummary);
    }
}
 
Example 18
Project: GitHub   File: SettingsActivity.java   View Source Code Vote up 4 votes
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference pref = findPreference(key);
    setSummary(pref, true);
    switch (key) {
        case "is_telnet":
            // start/stop telnetd
            EnvUtils.execService(getBaseContext(), "telnetd", null);
            break;
        case "telnet_port":
            // restart httpd
            EnvUtils.execService(getBaseContext(), "httpd", "restart");
        case "telnet_localhost":
            // restart telnetd
            EnvUtils.execService(getBaseContext(), "telnetd", "restart");
            break;
        case "is_http":
            // start/stop httpd
            EnvUtils.execService(getBaseContext(), "httpd", null);
            break;
        case "http_port":
        case "http_conf":
            // restart httpd
            EnvUtils.execService(getBaseContext(), "httpd", "restart");
            break;
        case "autostart":
            // set autostart settings
            int autostartFlag = (PrefStore.isAutostart(this) ?
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
            ComponentName bootComponent = new ComponentName(this, BootReceiver.class);
            getPackageManager().setComponentEnabledSetting(bootComponent, autostartFlag,
                    PackageManager.DONT_KILL_APP);
            break;
        case "nettrack":
            // set handler for network change action
            int nettrackFlag = (PrefStore.isTrackNetwork(this) ?
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
            ComponentName networkComponent = new ComponentName(this, NetworkReceiver.class);
            getPackageManager().setComponentEnabledSetting(networkComponent, nettrackFlag,
                    PackageManager.DONT_KILL_APP);
            break;
        case "stealth":
            // set stealth mode
            // Run app without launcher: am start -n ru.meefik.linuxdeploy/.MainActivity
            int stealthFlag = (PrefStore.isStealth(this) ?
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
            ComponentName mainComponent = new ComponentName(getPackageName(), getPackageName() + ".Launcher");
            getPackageManager().setComponentEnabledSetting(mainComponent, stealthFlag,
                    PackageManager.DONT_KILL_APP);
            break;
    }
}
 
Example 19
Project: OpenHub   File: AppUtils.java   View Source Code Vote up 4 votes
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;
}