Example #1
0
  /**
   * Retrieves the entry from the cache. If the entry is not present, it creates a new entry. This
   * method is not thread safe, it must be called from a synchronized method.
   */
  private CacheEntry cacheLocked(
      ComponentName componentName,
      LauncherActivityInfoCompat info,
      UserHandleCompat user,
      boolean usePackageIcon,
      boolean useLowResIcon) {
    ComponentKey cacheKey = new ComponentKey(componentName, user);
    CacheEntry entry = mCache.get(cacheKey);
    if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
      entry = new CacheEntry();
      mCache.put(cacheKey, entry);

      // Check the DB first.
      if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
        if (info != null) {
          entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext);
        } else {
          if (usePackageIcon) {
            CacheEntry packageEntry =
                getEntryForPackageLocked(componentName.getPackageName(), user, false);
            if (packageEntry != null) {
              if (DEBUG)
                Log.d(TAG, "using package default icon for " + componentName.toShortString());
              entry.icon = packageEntry.icon;
              entry.title = packageEntry.title;
              entry.contentDescription = packageEntry.contentDescription;
            }
          }
          if (entry.icon == null) {
            if (DEBUG) Log.d(TAG, "using default icon for " + componentName.toShortString());
            entry.icon = getDefaultIcon(user);
          }
        }
      }

      if (TextUtils.isEmpty(entry.title) && info != null) {
        entry.title = info.getLabel();
        entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
      }
    }
    return entry;
  }
Example #2
0
  private String getMiscInfos() {
    String result = "<table>";

    // admins
    {
      DevicePolicyManager dPM =
          (DevicePolicyManager) _context.getSystemService(Context.DEVICE_POLICY_SERVICE);
      String admins = "";

      if (dPM == null) {
        admins = "<li>No Device Policy Manager support.";
      } else if (dPM.getActiveAdmins() == null || dPM.getActiveAdmins().size() == 0) {
        admins = "<li>no active device admins.";
      } else {
        for (ComponentName name : dPM.getActiveAdmins()) {
          admins += "\r\n<li>" + name.toShortString();
        }
      }
      result += "\r\n<tr><td>List of device admin</td><td><ul>" + admins + "</ul></td></tr>\r\n";
    }

    {
      result +=
          "\r\n<tr><td>Android ID</td><td><ul><li>"
              + Secure.getString(_context.getContentResolver(), Secure.ANDROID_ID)
              + "</ul></td></tr>\r\n";
    }

    {
      result += "\r\n<tr><td>Configuration</td><td><ul>";

      Configuration config = _context.getResources().getConfiguration();
      for (Field field : Configuration.class.getDeclaredFields()) {
        try {
          // discard constants
          if (field.get(config) != null && !field.getName().toUpperCase().equals(field.getName())) {
            result += "\r\n<li>" + field.getName() + ": " + field.get(config).toString();
          }
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IllegalArgumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      result += "</ul></td></tr>\r\n";
    }

    result += "</table>";

    return result;
  }
Example #3
0
  private void runSetEnabledSetting(int state) {
    int userId = 0;
    String option = nextOption();
    if (option != null && option.equals("--user")) {
      String optionData = nextOptionData();
      if (optionData == null || !isNumber(optionData)) {
        System.err.println("Error: no USER_ID specified");
        showUsage();
        return;
      } else {
        userId = Integer.parseInt(optionData);
      }
    }

    String pkg = nextArg();
    if (pkg == null) {
      System.err.println("Error: no package or component specified");
      showUsage();
      return;
    }
    ComponentName cn = ComponentName.unflattenFromString(pkg);
    if (cn == null) {
      try {
        mPm.setApplicationEnabledSetting(pkg, state, 0, userId);
        System.err.println(
            "Package "
                + pkg
                + " new state: "
                + enabledSettingToString(mPm.getApplicationEnabledSetting(pkg, userId)));
      } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
      }
    } else {
      try {
        mPm.setComponentEnabledSetting(cn, state, 0, userId);
        System.err.println(
            "Component "
                + cn.toShortString()
                + " new state: "
                + enabledSettingToString(mPm.getComponentEnabledSetting(cn, userId)));
      } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
      }
    }
  }