示例#1
0
  /**
   * Check if ads should be hidden.
   *
   * @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);
    if (ri == null) {
      return false;
    } else {
      ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name);
      int i = pm.getComponentEnabledSetting(cn);
      if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
          || i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && ri.serviceInfo.enabled) {
        int match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName);
        if (match != PackageManager.SIGNATURE_MATCH) {
          Log.e(TAG, "signatures do not match: " + match);
          return false;
        }
        donationCheck.setComponent(cn);
      } else {
        Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled);
        return false;
      }
    }

    double r = Math.random();
    if (r < CHECK_DONATOR_LIC) {
      // verify donator license
      ComponentName cn = context.startService(donationCheck);
      return cn != null;
    } else {
      return true;
    }
  }
示例#2
0
文件: K9.java 项目: klonikar/k-9
  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);
    }
  }
 public boolean getHideAppIcon() {
   PackageManager packageManager = getPackageManager();
   ComponentName componentName = new ComponentName(AppSettingActivity.this, SplashActivity.class);
   int res = packageManager.getComponentEnabledSetting(componentName);
   if (res == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
       || res == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
     LogUtil.e("colin", "获取到应用图标显示在桌面上");
     return true;
   } else {
     LogUtil.e("colin", "获取到应用图标不显示在桌面上");
     return false;
   }
 }
  private void removeLauncherIcon() {
    String className = MainActivity.class.getCanonicalName().replace(".MainActivity", ".Launcher");
    ComponentName componentName = new ComponentName(getPackageName(), className);
    PackageManager packageManager = 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(this);
      builder.setIcon(android.R.drawable.ic_dialog_alert);
      builder.setMessage(getString(R.string.hidden_alert));
      builder.setPositiveButton(android.R.string.ok, null);
      builder.show();
    }
  }
 private void checkIcon() {
   final ComponentName aliasName =
       new ComponentName(this, SettingsActivity.this.getClass().getName() + "-Alias");
   final PackageManager packageManager = getPackageManager();
   if (packageManager.getComponentEnabledSetting(aliasName)
       != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
     new AlertDialog.Builder(this)
         .setMessage(R.string.pref_hint_hide_icon)
         .setPositiveButton(
             R.string.ok,
             new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                 packageManager.setComponentEnabledSetting(
                     aliasName,
                     PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                     PackageManager.DONT_KILL_APP);
               }
             })
         .show();
   }
 }
 public void setHideAppIcon() {
   PackageManager packageManager = getPackageManager();
   ComponentName componentName = new ComponentName(AppSettingActivity.this, SplashActivity.class);
   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);
     appLockApplication.appIconIsHided = true;
     LogUtil.e("colin", "隐藏应用图标");
   } else {
     // 显示应用图标
     packageManager.setComponentEnabledSetting(
         componentName,
         PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
         PackageManager.DONT_KILL_APP);
     appLockApplication.appIconIsHided = false;
     LogUtil.e("colin", "显示应用图标");
   }
 }
  @Override
  public void onCreate() {
    if (BuildConfig.DEBUG) {
      StrictModeUtils.detectAllVmPolicy();
    }
    super.onCreate();
    initDebugMode();
    initBugReport();
    mHandler = new Handler();
    initializeAsyncTask();
    initAccountColor(this);

    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();
    startRefreshServiceIfNeeded(this);

    reloadConnectivitySettings();

    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);
  }
 private boolean isLaunchFromBgEnabled() {
   ComponentName componentName = new ComponentName(this, BackgroundTagActivity.class);
   PackageManager packageManager = getPackageManager();
   int componentEnabledSetting = packageManager.getComponentEnabledSetting(componentName);
   return componentEnabledSetting == COMPONENT_ENABLED_STATE_ENABLED;
 }