示例#1
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;
  }
  private void initSmsApplicationSetting() {
    log("initSmsApplicationSetting:");
    Collection<SmsApplicationData> smsApplications =
        SmsApplication.getApplicationCollection(getActivity());

    // If the list is empty the dialog will be empty, but we will not crash.
    int count = smsApplications.size();
    CharSequence[] entries = new CharSequence[count];
    CharSequence[] entryValues = new CharSequence[count];
    Drawable[] entryImages = new Drawable[count];

    PackageManager packageManager = getPackageManager();
    int i = 0;
    for (SmsApplicationData smsApplicationData : smsApplications) {
      entries[i] = smsApplicationData.mApplicationName;
      entryValues[i] = smsApplicationData.mPackageName;
      try {
        entryImages[i] = packageManager.getApplicationIcon(smsApplicationData.mPackageName);
      } catch (NameNotFoundException e) {
        entryImages[i] = packageManager.getDefaultActivityIcon();
      }
      i++;
    }
    mSmsApplicationPreference.setEntries(entries);
    mSmsApplicationPreference.setEntryValues(entryValues);
    mSmsApplicationPreference.setEntryDrawables(entryImages);
    updateSmsApplicationSetting();
  }
示例#3
0
 private Bitmap makeDefaultIcon() {
   Drawable d = mPackageManager.getDefaultActivityIcon();
   Bitmap b =
       Bitmap.createBitmap(
           Math.max(d.getIntrinsicWidth(), 1),
           Math.max(d.getIntrinsicHeight(), 1),
           Bitmap.Config.ARGB_8888);
   Canvas c = new Canvas(b);
   d.setBounds(0, 0, b.getWidth(), b.getHeight());
   d.draw(c);
   return b;
 }
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main3);
    mPm = getPackageManager();
    Intent i = getIntent();
    String title = i.getStringExtra("title");
    final String PackageName = title.substring(8);

    ExpandableListView list = (ExpandableListView) findViewById(R.id.permissionList);
    mGroupData = new ArrayList<Map<String, String>>();
    mChildData = new ArrayList<List<Map<String, String>>>();
    String permissionName;
    String applicationLabel;
    String packageName;
    PackageInfo pi = null;
    ApplicationInfo ai = null;
    applicationLabel = PackageName;
    int packageVersionCode;
    String packageVersionName;
    String AppName;
    Drawable icon;
    long lastUpdate;
    int system;
    int install;

    try {
      pi = mPm.getPackageInfo(PackageName, PackageManager.GET_META_DATA);

      try {
        icon = mPm.getApplicationIcon(PackageName); // ///icon  빼기

      } catch (PackageManager.NameNotFoundException e) {
        icon = mPm.getDefaultActivityIcon();
      }

      ImageView imageView = (ImageView) findViewById(android.R.id.icon);
      imageView.setImageDrawable(icon);

      AppName = pi.packageName;
      packageVersionCode = pi.versionCode;
      packageVersionName = pi.versionName;
      Log.v("XXXX7", "name:     " + packageVersionName);

      ai = mPm.getApplicationInfo(PackageName, PackageManager.GET_META_DATA); // //라벨 빼오기
      String labelName = mPm.getApplicationLabel(ai).toString();

      ((TextView) findViewById(R.id.curAppName)).setText(labelName); // Appname layout 연결
      ((TextView) findViewById(R.id.packagea)).setText(AppName); // Appname layout 연결
      ((TextView) findViewById(R.id.curAppversion))
          .setText(packageVersionCode + " / " + packageVersionName);

    } catch (Exception ex) {
      packageVersionCode = 0;
      packageVersionName = "n/a";
      // Log.e("PM", "Error fetching app version");
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////

    manageButton = (ImageButton) findViewById(R.id.application_detail_manage_button);
    manageButton.setImageResource(R.drawable.ic_menu_manage);
    manageButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= 9) {
              try {
                Intent i = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                i.addCategory(Intent.CATEGORY_DEFAULT);
                i.setData(Uri.parse("package:" + PackageName));
                startActivity(i);
              } catch (ActivityNotFoundException anfe) {
                Intent i = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                i.addCategory(Intent.CATEGORY_DEFAULT);
                startActivity(i);
              }
            } else {
              Toast.makeText(
                      MarketPlay.this,
                      context.getText(R.string.application_detail_manager_unavailable),
                      Toast.LENGTH_LONG)
                  .show();
            }
          }
        });

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////
    try {
      pi = mPm.getPackageInfo(PackageName, PackageManager.GET_PERMISSIONS);

    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }

    mChildData.clear();
    mGroupData.clear();

    //        int count = 0;
    //        try {
    //            for (String key : pi.requestedPermissions) {
    //                if (key.startsWith("android.permission.")) count++;
    //            }
    //            curGroupMap.put(NAME, applicationLabel + "(" + count + ")");
    //            Log.v("XXXX7", "count :     " + count);
    //        } catch (NullPointerException e) {
    //            curGroupMap.put(NAME, applicationLabel + "(" + 0 + ")");
    //            Log.v("XXXX7", "///count :     " + count);
    //        }
    //        curGroupMap.put(DESCRIPTION, packageVersionName);
    //        Log.v("XXXX7", "Description  :     " + packageVersionName);
    //        curGroupMap.put(PACKAGENAME, PackageName);
    //        Log.v("XXXX7", "packageName  :     " + PackageName);
    //
    //        mGroupData.add(curGroupMap);

    Log.v("1", "" + mChildData);

    Log.v("2", "" + mChildData);
    try {
      Log.v("3", "" + mChildData);
      if (pi.requestedPermissions != null) {
        for (String key : pi.requestedPermissions) {
          try {
            if (!(key.startsWith("android.permission."))) continue;
            Log.d("BBB", key);
            PermissionInfo pinfo = mPm.getPermissionInfo(key, PackageManager.GET_META_DATA);
            Map<String, String> curGroupMap = new HashMap<String, String>();
            Map<String, String> curChildMap = new HashMap<String, String>();
            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            CharSequence label = pinfo.loadLabel(mPm);
            CharSequence desc = pinfo.loadDescription(mPm);

            curGroupMap.put(NAME, (label == null) ? pinfo.name : label.toString());
            Log.d("AAA", label.toString());
            curGroupMap.put(SECURITYLEVEL, String.valueOf(pinfo.protectionLevel));
            curChildMap.put(PERMISSION, key);
            curChildMap.put(DESCRIPTION, (desc == null) ? "" : desc.toString());
            curChildMap.put(SECURITYLEVEL, String.valueOf(pinfo.protectionLevel));
            children.add(curChildMap);

            mGroupData.add(curGroupMap);
            Log.d("CCC", "" + mGroupData);
            mChildData.add(children);
            Log.d("DDD", "" + mChildData);

          } catch (PackageManager.NameNotFoundException e) {
            Log.i(TAG, "Ignoring unknown permission ");
            continue;
          }
        }
      } else {
        ((TextView) findViewById(R.id.iff)).setText(" App 의 요구 권한 이 없습니다 ^^  ");

        //                mGroupData.add(curGroupMap);
        //                mChildData.add(children);
      }
    } catch (NullPointerException e) {
      Log.i(TAG, "Ignoring unknown permission ");
    }

    //        SimpleAdapter adapter = new SimpleAdapter(this, children,
    // R.layout.permission_list_item, new String[]{"", "Name", "Description"}, new
    // int[]{R.id.listviewpermissiontext, R.id.text1, R.id.text2});
    //        if (pi.requestedPermissions != null) {
    //            permissionList = (ListView) findViewById(R.id.permissionList);
    //            permissionList.setAdapter(adapter);
    //        } else {
    //            ((TextView) findViewById(R.id.iff)).setText(" App 의 요구 권한 이 없습니다 ^^  ");
    //        }

    PermissionAdapter mAdapter =
        new PermissionAdapter(
            MarketPlay.this,
            mGroupData,
            R.layout.marketplay_item,
            new String[] {NAME},
            new int[] {R.id.text1},
            mChildData,
            R.layout.marketplay_item_child,
            new String[] {DESCRIPTION, PERMISSION},
            new int[] {R.id.text1, R.id.text2});

    list.setAdapter(mAdapter);

    Log.v("BBB", "" + mChildData);

    // permissionList = (ListView)findViewById(R.id.permissionL);
    // permissionList.setAdapter(adapter);    ///권한들 .. layout

  }