/**
   * Returns a detailed exception message for the supplied URI. It includes the calling user and
   * calling package(s).
   */
  public String exceptionMessage(String message, Uri uri) {
    StringBuilder sb = new StringBuilder();
    if (message != null) {
      sb.append(message).append("; ");
    }
    sb.append("URI: ").append(uri);
    final PackageManager pm = mContext.getPackageManager();
    int callingUid = Binder.getCallingUid();
    sb.append(", calling user: "******", calling package:");
        sb.append(callerPackages[0]);
      } else {
        sb.append(", calling package is one of: [");
        for (int i = 0; i < callerPackages.length; i++) {
          if (i != 0) {
            sb.append(", ");
          }
          sb.append(callerPackages[i]);
        }
        sb.append("]");
      }
    }

    return sb.toString();
  }
示例#2
0
  /** Build {@link UidDetail} object, blocking until all {@link Drawable} lookup is finished. */
  private UidDetail buildUidDetail(int uid) {
    final Resources res = mContext.getResources();
    final PackageManager pm = mContext.getPackageManager();

    final UidDetail detail = new UidDetail();
    detail.label = pm.getNameForUid(uid);
    detail.icon = pm.getDefaultActivityIcon();

    // handle special case labels
    switch (uid) {
      case android.os.Process.SYSTEM_UID:
        detail.label = res.getString(R.string.process_kernel_label);
        detail.icon = pm.getDefaultActivityIcon();
        return detail;
      case TrafficStats.UID_REMOVED:
        detail.label = res.getString(R.string.data_usage_uninstalled_apps);
        detail.icon = pm.getDefaultActivityIcon();
        return detail;
      case TrafficStats.UID_TETHERING:
        final ConnectivityManager cm =
            (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        detail.label = res.getString(Utils.getTetheringLabel(cm));
        detail.icon = pm.getDefaultActivityIcon();
        return detail;
    }

    // otherwise fall back to using packagemanager labels
    final String[] packageNames = pm.getPackagesForUid(uid);
    final int length = packageNames != null ? packageNames.length : 0;

    try {
      if (length == 1) {
        final ApplicationInfo info = pm.getApplicationInfo(packageNames[0], 0);
        detail.label = info.loadLabel(pm).toString();
        detail.icon = info.loadIcon(pm);
      } else if (length > 1) {
        detail.detailLabels = new CharSequence[length];
        for (int i = 0; i < length; i++) {
          final String packageName = packageNames[i];
          final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
          final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);

          detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
          if (packageInfo.sharedUserLabel != 0) {
            detail.label =
                pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo)
                    .toString();
            detail.icon = appInfo.loadIcon(pm);
          }
        }
      }
    } catch (NameNotFoundException e) {
    }

    if (TextUtils.isEmpty(detail.label)) {
      detail.label = Integer.toString(uid);
    }

    return detail;
  }
示例#3
0
  public static String getUidName(Context c, int uid, boolean withUid) {
    PackageManager pm = c.getPackageManager();
    String uidName = "";
    if (uid == 0) {
      uidName = "root";
    } else {
      pm.getNameForUid(uid);
    }

    if (withUid) {
      uidName += " (" + uid + ")";
    }

    return uidName;
  }
 public String getSavedNetworkSummary() {
   if (mConfig != null) {
     PackageManager pm = mContext.getPackageManager();
     String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID);
     int userId = UserHandle.getUserId(mConfig.creatorUid);
     ApplicationInfo appInfo = null;
     if (mConfig.creatorName != null && mConfig.creatorName.equals(systemName)) {
       appInfo = mContext.getApplicationInfo();
     } else {
       try {
         IPackageManager ipm = AppGlobals.getPackageManager();
         appInfo = ipm.getApplicationInfo(mConfig.creatorName, 0 /* flags */, userId);
       } catch (RemoteException rex) {
       }
     }
     if (appInfo != null
         && !appInfo.packageName.equals(mContext.getString(R.string.settings_package))
         && !appInfo.packageName.equals(mContext.getString(R.string.certinstaller_package))) {
       return mContext.getString(R.string.saved_network, appInfo.loadLabel(pm));
     }
   }
   return "";
 }