List of usage examples for android.content.pm PackageManager setComponentEnabledSetting
public abstract void setComponentEnabledSetting(@NonNull ComponentName componentName, @EnabledState int newState, @EnabledFlags int flags);
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 w w . j av a 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 void setLauncherIconEnabled(boolean enabled) { int newState; PackageManager packman = getPackageManager(); if (enabled) { newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; } else {// w ww. j a va 2 s . c o m newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; } packman.setComponentEnabledSetting(new ComponentName(this, LauncherActivity.class), newState, PackageManager.DONT_KILL_APP); }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
@Override protected Integer doInBackground(Void... params) { SharedPreferences prefs = dataService.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE); // Connectivity receiver. final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); ComponentName receiver = new ComponentName(dataService, WifiReceiver.class); PackageManager pm = dataService.getPackageManager(); if (activeNetwork == null || !activeNetwork.isConnected()) { // We've missed a scheduled update. Enable the receiver so it can launch an update when we reconnect. Log.d(LOG_TAG, "Missed library update: not connected. Enabling connectivity receiver."); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); return RESULT_CODE_FAILURE; } else {/*from w w w. j a va 2 s .c om*/ // We are connected. Disable the receiver. Log.d(LOG_TAG, "Library updater connected. Disabling connectivity receiver."); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } InputStream in = null; String etag = prefs.getString(SETTING_LIBRARY_ETAG, null); try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); if (etag != null && !force) { conn.setRequestProperty("If-None-Match", etag); } int code = conn.getResponseCode(); switch (code) { case HttpStatus.SC_NOT_MODIFIED: // If we got a 304, we're done. // Use failure code to indicate there is no temp db to copy over. Log.d(LOG_TAG, "304 in library response."); return RESULT_CODE_FAILURE; default: // Odd, but on 1/3/13 I received correct json responses with a -1 for responseCode. Fall through. Log.w(LOG_TAG, "Error code in library response: " + code); case HttpStatus.SC_OK: // Parse response. in = conn.getInputStream(); JsonFactory factory = new JsonFactory(); final JsonParser parser = factory.createJsonParser(in); SQLiteDatabase tempDb = tempDbHelper.getWritableDatabase(); tempDb.beginTransaction(); try { tempDb.execSQL("delete from topic"); tempDb.execSQL("delete from topicvideo"); tempDb.execSQL("delete from video"); parseObject(parser, tempDb, null, 0); tempDb.setTransactionSuccessful(); } catch (Exception e) { e.printStackTrace(); return RESULT_CODE_FAILURE; } finally { tempDb.endTransaction(); tempDb.close(); } // Save etag once we've successfully parsed the response. etag = conn.getHeaderField("ETag"); prefs.edit().putString(SETTING_LIBRARY_ETAG, etag).apply(); // Move this new content from the temp db into the main one. mergeDbs(); return RESULT_CODE_SUCCESS; } } catch (MalformedURLException e) { e.printStackTrace(); } catch (JsonParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { tempDbHelper.close(); } return RESULT_CODE_FAILURE; }
From source file:com.cyanogenmod.account.ui.SetupWizardActivity.java
private void disableSetupWizards(Intent intent) { final PackageManager pm = getPackageManager(); final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo info : resolveInfos) { if (GOOGLE_SETUPWIZARD_PACKAGE.equals(info.activityInfo.packageName)) { final ComponentName componentName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name); pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }/*from ww w . ja va 2 s . c om*/ } pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }
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 {/* w w w . j ava 2s. 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.chummy.jezebel.material.dark.activities.Main.java
public void setLauncherIconEnabled(boolean enabled) { int newState; PackageManager pm = getPackageManager(); if (enabled) { newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; } else {/*from w w w .ja v a 2 s.c o m*/ newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; } pm.setComponentEnabledSetting( new ComponentName(this, com.chummy.jezebel.material.dark.LauncherActivity.class), newState, PackageManager.DONT_KILL_APP); }
From source file:org.getlantern.firetweet.service.BackgroundOperationService.java
private void triggerEasterEgg(boolean notReplyToOther, boolean hasEasterEggTriggerText, boolean hasEasterEggRestoreText) { final PackageManager pm = getPackageManager(); final ComponentName main = new ComponentName(this, MainActivity.class); final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class); if (hasEasterEggTriggerText && notReplyToOther) { pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); showToast(R.string.easter_egg_triggered_message, Toast.LENGTH_SHORT); } else if (hasEasterEggRestoreText) { pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); showToast(R.string.icon_restored_message, Toast.LENGTH_SHORT); }/*from ww w . ja v a 2 s . c o m*/ }
From source file:org.mariotaku.twidere.app.TwidereApplication.java
@Override public void onCreate() { sInstance = this; if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); }/* w w w. jav a 2 s . 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.air.mobilebrowser.BrowserActivity.java
/** * Clear the setting for default home./*from w w w .ja v a 2s. c om*/ */ private void clearHome() { PackageManager pm = getPackageManager(); ComponentName fauxHomeComponent = new ComponentName(getApplicationContext(), FauxHome.class); ComponentName homeComponent = new ComponentName(getApplicationContext(), BrowserActivity.class); pm.setComponentEnabledSetting(fauxHomeComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(homeComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(fauxHomeComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(homeComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }
From source file:com.air.mobilebrowser.BrowserActivity.java
/** * Cleanup everything that was changed.//w w w. ja v a 2s. c o m */ public void cleanup() { stopService(new Intent(getApplicationContext(), ActivityWatchService.class)); //clear home and exit PackageManager pm = getPackageManager(); ComponentName fauxHomeComponent = new ComponentName(getApplicationContext(), FauxHome.class); ComponentName homeComponent = new ComponentName(getApplicationContext(), BrowserActivity.class); pm.setComponentEnabledSetting(fauxHomeComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(homeComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); mAudioManager.setMicrophoneMute(OrigSettings.getInstance().isMicMuted()); String curKeyboard = KeyboardUtil.getKeyboardPackage(BrowserActivity.this.getContentResolver()); if (!curKeyboard.equals(OrigSettings.getInstance().getKeyboard())) { KeyboardUtil.showInputChangedExitDialog(this, new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); } else { finish(); } }