List of usage examples for android.content.pm PackageManager getComponentEnabledSetting
public abstract @EnabledState int getComponentEnabledSetting(@NonNull ComponentName componentName);
From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java
public void setTileEnabled(ComponentName component, boolean enabled) { PackageManager pm = getPackageManager(); int state = pm.getComponentEnabledSetting(component); boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { if (enabled) { sTileBlacklist.remove(component); } else {/* ww w. j a v a 2 s. c om*/ sTileBlacklist.add(component); } pm.setComponentEnabledSetting(component, enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); new CategoriesUpdater().execute(); } }
From source file:com.android.tv.TvApplication.java
/** * Checks the input counts and enable/disable TvActivity. Also updates the input list in * {@link SetupUtils}.//from w ww . j a va 2 s. c o m * * @param calledByTunerServiceChanged true if it is called when UsbTunerTvInputService * is enabled or disabled. * @param tunerServiceEnabled it's available only when calledByTunerServiceChanged is true. * @param dontKillApp when TvActivity is enabled or disabled by this method, the app restarts * by default. But, if dontKillApp is true, the app won't restart. */ public void handleInputCountChanged(boolean calledByTunerServiceChanged, boolean tunerServiceEnabled, boolean dontKillApp) { TvInputManager inputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); boolean enable = (calledByTunerServiceChanged && tunerServiceEnabled) || Features.UNHIDE.isEnabled(TvApplication.this); if (!enable) { List<TvInputInfo> inputs = inputManager.getTvInputList(); boolean skipTunerInputCheck = false; // Enable the TvActivity only if there is at least one tuner type input. if (!skipTunerInputCheck) { for (TvInputInfo input : inputs) { if (calledByTunerServiceChanged && !tunerServiceEnabled && UsbTunerTvInputService.getInputId(this).equals(input.getId())) { continue; } if (input.getType() == TvInputInfo.TYPE_TUNER) { enable = true; break; } } } if (DEBUG) Log.d(TAG, "Enable MainActivity: " + enable); } PackageManager packageManager = getPackageManager(); ComponentName name = new ComponentName(this, TvActivity.class); int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (packageManager.getComponentEnabledSetting(name) != newState) { packageManager.setComponentEnabledSetting(name, newState, dontKillApp ? PackageManager.DONT_KILL_APP : 0); } SetupUtils.getInstance(TvApplication.this).onInputListUpdated(inputManager); }
From source file:com.android.purenexussettings.TinkerActivity.java
public boolean isLauncherIconEnabled() { PackageManager packman = getPackageManager(); return (packman.getComponentEnabledSetting(new ComponentName(this, LauncherActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED); }
From source file:org.mariotaku.twidere.app.TwidereApplication.java
@Override public void onCreate() { sInstance = this; if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); }/*w ww.j av a 2s .c o m*/ final SharedPreferences preferences = getSharedPreferences(); resetTheme(preferences); super.onCreate(); mProfileImageViewViewProcessor = new ProfileImageViewViewProcessor(); mFontFamilyTagProcessor = new FontFamilyTagProcessor(); ATE.registerViewProcessor(TabPagerIndicator.class, new TabPagerIndicatorViewProcessor()); ATE.registerViewProcessor(FloatingActionButton.class, new FloatingActionButtonViewProcessor()); ATE.registerViewProcessor(ActionBarContextView.class, new ActionBarContextViewViewProcessor()); ATE.registerViewProcessor(SwipeRefreshLayout.class, new SwipeRefreshLayoutViewProcessor()); ATE.registerViewProcessor(TimelineContentTextView.class, new TimelineContentTextViewViewProcessor()); ATE.registerViewProcessor(TextView.class, new TextViewViewProcessor()); ATE.registerViewProcessor(ImageView.class, new ImageViewViewProcessor()); ATE.registerViewProcessor(MaterialEditText.class, new MaterialEditTextViewProcessor()); ATE.registerViewProcessor(ProgressWheel.class, new ProgressWheelViewProcessor()); ATE.registerViewProcessor(ProfileImageView.class, mProfileImageViewViewProcessor); ATE.registerTagProcessor(OptimalLinkColorTagProcessor.TAG, new OptimalLinkColorTagProcessor()); ATE.registerTagProcessor(FontFamilyTagProcessor.TAG, mFontFamilyTagProcessor); ATE.registerTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR, new IconActionButtonTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR)); ATE.registerTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_ACTIVATED, new IconActionButtonTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_ACTIVATED)); ATE.registerTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_DISABLED, new IconActionButtonTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_DISABLED)); ATE.registerTagProcessor(ThemedMultiValueSwitch.PREFIX_TINT, new ThemedMultiValueSwitch.TintTagProcessor()); mProfileImageViewViewProcessor.setStyle(Utils.getProfileImageStyle(preferences)); mFontFamilyTagProcessor.setFontFamily(ThemeUtils.getThemeFontFamily(preferences)); final int themeColor = preferences.getInt(KEY_THEME_COLOR, ContextCompat.getColor(this, R.color.branding_color)); if (!ATE.config(this, VALUE_THEME_NAME_LIGHT).isConfigured()) { //noinspection WrongConstant ATE.config(this, VALUE_THEME_NAME_LIGHT).primaryColor(themeColor) .accentColor(ThemeUtils.getOptimalAccentColor(themeColor, Color.BLACK)).coloredActionBar(true) .coloredStatusBar(true).commit(); } if (!ATE.config(this, VALUE_THEME_NAME_DARK).isConfigured()) { ATE.config(this, VALUE_THEME_NAME_DARK) .accentColor(ThemeUtils.getOptimalAccentColor(themeColor, Color.WHITE)).coloredActionBar(false) .coloredStatusBar(true).statusBarColor(Color.BLACK).commit(); } if (!ATE.config(this, null).isConfigured()) { ATE.config(this, null).accentColor(ThemeUtils.getOptimalAccentColor(themeColor, Color.WHITE)) .coloredActionBar(false).coloredStatusBar(false).commit(); } initializeAsyncTask(); initDebugMode(); initBugReport(); mHandler = new Handler(); final PackageManager pm = getPackageManager(); final ComponentName main = new ComponentName(this, MainActivity.class); final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class); final boolean mainDisabled = pm .getComponentEnabledSetting(main) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; final boolean main2Disabled = pm .getComponentEnabledSetting(main2) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED; final boolean noEntry = mainDisabled && main2Disabled; if (noEntry) { pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } else if (!mainDisabled) { pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } if (!Utils.isComposeNowSupported(this)) { final ComponentName assist = new ComponentName(this, AssistLauncherActivity.class); pm.setComponentEnabledSetting(assist, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } migrateUsageStatisticsPreferences(); Utils.startRefreshServiceIfNeeded(this); DependencyHolder holder = DependencyHolder.get(this); registerActivityLifecycleCallbacks(holder.getActivityTracker()); final IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); packageFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); final String[] packages = getPackageManager().getPackagesForUid(uid); DependencyHolder holder = DependencyHolder.get(context); final ExternalThemeManager manager = holder.getExternalThemeManager(); if (ArrayUtils.contains(packages, manager.getEmojiPackageName())) { manager.reloadEmojiPreferences(); } } }, packageFilter); }
From source file:com.chummy.jezebel.material.dark.activities.Main.java
public boolean isLauncherIconEnabled() { PackageManager pm = getPackageManager(); return (pm.getComponentEnabledSetting(new ComponentName(this, com.chummy.jezebel.material.dark.LauncherActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED); }
From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);// w w w. j av a2 s. c om Bundle intent = getArguments(); mPackageName = intent.getString(ARG_PACKAGE_NAME); mComponentName = intent.getString(ARG_COMPONENT_NAME); ExtendedPackageInfo.getExtendedPackageInfo(getActivity(), mPackageName, new ExtendedPackageInfo.Callback() { @Override public void onPackageInfoAvailable(ExtendedPackageInfo epi) { // Get loaded component info mExtendedComponentInfo = epi.getComponentInfo(mComponentName); if (mExtendedComponentInfo == null) { Log.e(TAG, "component not found in manifest"); Log.e(TAG, "packageName=" + mPackageName); Log.e(TAG, "componentName=" + mComponentName); Toast.makeText(getActivity(), R.string.component_not_found, Toast.LENGTH_SHORT).show(); //finish(); // TODO: Show message directly in fragment instead of Toast if in tablet view return; } PackageManager packageManager = getActivity().getPackageManager(); // Header icon and component name mTitleText = mExtendedComponentInfo.systemComponentInfo.loadLabel(packageManager); // Description text FormattedTextBuilder text = new FormattedTextBuilder(); // Description: disabled if (isComponentDisabledState( packageManager.getComponentEnabledSetting(new ComponentName(mPackageName, mComponentName)), mExtendedComponentInfo.systemComponentInfo.enabled)) { text.appendHeader(getString(R.string.component_disabled)); } else if (!mExtendedComponentInfo.systemComponentInfo.applicationInfo.enabled) { text.appendHeader(getString(R.string.component_in_disabled_application)); } // Description: permission/exported if (!mExtendedComponentInfo.systemComponentInfo.exported) { text.appendHeader(getString(R.string.component_not_exported)); } else { String permission = mExtendedComponentInfo.getPermission(); if (permission != null) { text.appendValue(getString(R.string.permission_required_title), permission, true, FormattedTextBuilder.ValueSemantic.PERMISSION); } } // Description: <intent-filter>'s final boolean isBroadcast = mExtendedComponentInfo.componentType == IntentEditorConstants.BROADCAST; if (mExtendedComponentInfo.intentFilters == null) { text.appendHeader(getString(R.string.unknown_intent_filters)); } else if (mExtendedComponentInfo.intentFilters.length == 0) { text.appendHeader(getString(R.string.no_intent_filters)); } else { text.appendHeader(getString(R.string.intent_filters)); for (IntentFilter filter : mExtendedComponentInfo.intentFilters) { text.appendFormattedText(dumpIntentFilter(filter, getResources(), isBroadcast)); } } text.appendFormattedText(dumpMetaData(getActivity(), mPackageName, mExtendedComponentInfo.systemComponentInfo.metaData)); // Put text in TextView mDescription = text.getText(); // Show or hide "Receive broadcast" button mShowReceiveBroadcast = isBroadcast && mExtendedComponentInfo.intentFilters != null && mExtendedComponentInfo.intentFilters.length != 0; if (haveView()) { fillViews(); } } }); }
From source file:com.android.usbtuner.UsbInputController.java
/** * Enable/disable the component {@link UsbTunerTvInputService}. * * @param context {@link Context} instance * @param enabled {@code true} to enable the service; otherwise {@code false} *//*from w ww .java 2 s . c o m*/ private void enableUsbTunerTvInputService(Context context, boolean enabled) { PackageManager pm = context.getPackageManager(); ComponentName USBTUNER = new ComponentName(context, UsbTunerTvInputService.class); // Don't kill app by enabling/disabling TvActivity. If LC is killed by enabling/disabling // TvActivity, the following pm.setComponentEnabledSetting doesn't work. ((TvApplication) context.getApplicationContext()).handleInputCountChanged(true, enabled, true); // Since PackageManager.DONT_KILL_APP delays the operation by 10 seconds // (PackageManagerService.BROADCAST_DELAY), we'd better avoid using it. It is used only // when the LiveChannels app is active since we don't want to kill the running app. int flags = TvApplication.getSingletons(context).getMainActivityWrapper().isCreated() ? PackageManager.DONT_KILL_APP : 0; int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (newState != pm.getComponentEnabledSetting(USBTUNER)) { // Send/cancel the USB tuner TV input setup recommendation card. TunerSetupActivity.onTvInputEnabled(context, enabled); // Enable/disable the USB tuner TV input. pm.setComponentEnabledSetting(USBTUNER, newState, flags); if (DEBUG) Log.d(TAG, "Status updated:" + enabled); } if (enabled && BuildCompat.isAtLeastN()) { TvInputInfo info = mDvbDeviceAccessor.buildTvInputInfo(context); if (info != null) { Log.i(TAG, "TvInputInfo updated: " + info.toString()); ((TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE)).updateTvInputInfo(info); } } }
From source file:com.csipsimple.service.SipService.java
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; }/*w w w. ja va2 s . com*/ 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); } }
From source file:com.newsrob.EntryManager.java
public void maintainBootReceiverState() { final ComponentName cName = new ComponentName(ctx, BootReceiver.class); final PackageManager pm = ctx.getPackageManager(); final int newComponentState = isAutoSyncEnabled() ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (pm.getComponentEnabledSetting(cName) != newComponentState) { Log.d(TAG, "Setting new component enabled state on BootReceiver: " + isAutoSyncEnabled()); pm.setComponentEnabledSetting(cName, newComponentState, PackageManager.DONT_KILL_APP); }//from w ww . ja v a 2 s. c o m PL.log("EntryManager.maintainBootReceiverState(): Component enabled=" + pm.getComponentEnabledSetting(cName), ctx); }
From source file:com.grazerss.EntryManager.java
public void maintainBootReceiverStateAndScheduler() { final ComponentName cName = new ComponentName(ctx, BootReceiver.class); final PackageManager pm = ctx.getPackageManager(); final int newComponentState = isAutoSyncEnabled() ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (pm.getComponentEnabledSetting(cName) != newComponentState) { Log.d(TAG, "Setting new component enabled state on BootReceiver: " + isAutoSyncEnabled()); pm.setComponentEnabledSetting(cName, newComponentState, PackageManager.DONT_KILL_APP); }/*w w w . j a v a 2s.c o m*/ PL.log("EntryManager.maintainBootReceiverState(): Component enabled=" + pm.getComponentEnabledSetting(cName), ctx); if (isAutoSyncEnabled()) { scheduler.ensureSchedulingIsEnabled(); } }