List of usage examples for android.content.pm PackageManager getComponentEnabledSetting
public abstract @EnabledState int getComponentEnabledSetting(@NonNull ComponentName componentName);
From source file:Main.java
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; }
From source file:com.google.android.gm.ay.java
public static boolean bi(final Context context) { final PackageManager packageManager = context.getPackageManager(); return packageManager.getComponentEnabledSetting(ay.aZe) == 1 || packageManager.getComponentEnabledSetting(ay.aZd) == 1; }
From source file:com.cognizant.trumobi.em.Email.java
public static void setServicesEnabled(Context context, boolean enabled) { PackageManager pm = context.getPackageManager(); if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /*// www .j a v a2 s.c om * 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. */ EmMailService.actionReschedule(context); } pm.setComponentEnabledSetting(new ComponentName(context, EmMessageCompose.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmAccountShortcutPicker.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmMailService.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.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. */ EmMailService.actionReschedule(context); } }
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Check if ads should be hidden.//from w w w . j a v a2 s. c o m * * @param context * {@link Context} * @return true if ads should be hidden */ public static boolean hideAds(final Context context) { PackageManager pm = context.getPackageManager(); Intent donationCheck = new Intent(DONATOR_BROADCAST_CHECK); ResolveInfo ri = pm.resolveService(donationCheck, 0); // Log.d(TAG, "ri: " + ri); int match = PackageManager.SIGNATURE_UNKNOWN_PACKAGE; if (ri != null) { Log.d(TAG, "found package: " + ri.serviceInfo.packageName); ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name); // Log.d(TAG, "component name: " + cn); int i = pm.getComponentEnabledSetting(cn); // Log.d(TAG, "component status: " + i); // Log.d(TAG, "package status: " + ri.serviceInfo.enabled); if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && ri.serviceInfo.enabled) { match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName); } else { Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled); } } Log.i(TAG, "signature match: " + match); if (match != PackageManager.SIGNATURE_UNKNOWN_PACKAGE) { if (Math.random() < CHECK_DONATOR_LIC) { // verify donator license ComponentName cn = context.startService(donationCheck); Log.d(TAG, "Started service: " + cn); if (cn == null) { return false; } } return match == PackageManager.SIGNATURE_MATCH; } pm = null; // no donator app installed, check donation traditionally // do not drop legacy donators boolean ret = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_HIDEADS, false); Log.d(TAG, "legacy donation check: " + ret); return ret; }
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; }// w w w.j av a2s .c o m 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:com.lee.sdk.utils.Utils.java
/** * component??//from w w w. j av a 2 s. c o m * * @param ctx context * @param className class name * @return ?? */ public static boolean isComponentEnable(Context ctx, String className) { PackageManager pm = ctx.getPackageManager(); ComponentName cn = new ComponentName(ctx.getPackageName(), className); int ret = pm.getComponentEnabledSetting(cn); if (ret == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || ret == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { return true; } return false; }
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.android.tv.receiver.BootCompletedReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (DEBUG)/*from w ww . j ava 2 s.c om*/ Log.d(TAG, "boot completed " + intent); // Start {@link NotificationService}. Intent notificationIntent = new Intent(context, NotificationService.class); notificationIntent.setAction(NotificationService.ACTION_SHOW_RECOMMENDATION); context.startService(notificationIntent); // Grant permission to already set up packages after the system has finished booting. SetupUtils.grantEpgPermissionToSetUpPackages(context); if (Features.UNHIDE.isEnabled(context)) { if (OnboardingUtils.isFirstBoot(context)) { // Enable the application if this is the first "unhide" feature is enabled just in // case when the app has been disabled before. PackageManager pm = context.getPackageManager(); ComponentName name = new ComponentName(context, TvActivity.class); if (pm.getComponentEnabledSetting(name) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0); } OnboardingUtils.setFirstBootCompleted(context); } } if (CommonFeatures.DVR.isEnabled(context) && BuildCompat.isAtLeastN()) { DvrRecordingService.startService(context); } }
From source file:com.github.michalbednarski.intentslab.StartActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: startActivity(new Intent(this, PrefsActivity.class)); return true; case R.id.interception: { final PackageManager packageManager = getPackageManager(); boolean enable = packageManager.getComponentEnabledSetting( mInterceptActivityComponentName) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; packageManager/* www .ja v a 2 s . co m*/ .setComponentEnabledSetting(mInterceptActivityComponentName, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); Toast.makeText(this, enable ? getString(R.string.interception_enabled) : getString(R.string.interception_disabled), Toast.LENGTH_SHORT).show(); ActivityCompat.invalidateOptionsMenu(this); return true; } case R.id.system_services: (new SystemServicesDialog()).show(getSupportFragmentManager(), "systemServices"); return true; case R.id.provider_lab: startActivity(new Intent(StartActivity.this, AdvancedQueryActivity.class)); return true; } return false; }
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 w w . j a v a2 s. c o m } }