Beispiel #1
0
  /** ************************* 获取手机内所有应用 ************************* */
  public static List<PackageInfo> getAllApps(Context context) {

    List<PackageInfo> apps = new ArrayList<PackageInfo>();
    PackageManager pManager = context.getPackageManager();
    List<PackageInfo> packlist = null;
    try {
      packlist = pManager.getInstalledPackages(0);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (packlist == null) {
      return null;
    }

    for (int i = 0; i < packlist.size(); i++) {
      PackageInfo pak = (PackageInfo) packlist.get(i);

      // 判断是否为非系统预装的应用程序
      // 这里还可以添加系统自带的,这里就先不添加了,如果有需要可以自己添加
      // if()里的值如果<=0则为自己装的程序,否则为系统工程自带
      if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <= 0) {
        // 添加自己已经安装的应用程序
        apps.add(pak);
      }
    }
    return apps;
  }
Beispiel #2
0
 private void getAllGameApp() {
   List<PackageInfo> apps = new ArrayList<PackageInfo>();
   PackageManager pManager = getPackageManager();
   // 获取手机内所有应用
   List<PackageInfo> packlist = pManager.getInstalledPackages(0);
   for (int i = 0; i < packlist.size(); i++) {
     PackageInfo pak = packlist.get(i);
     // if()里的值如果==0则为自己装的程序,否则为系统工程自带
     if ((pak.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
       // 添加自己已经安装的应用程序
       apps.add(pak);
       String appName = pManager.getApplicationLabel(pak.applicationInfo).toString();
       if (MyApp.gnList.contains(appName)) {
         AppsItemInfo aii = new AppsItemInfo();
         aii.setIcon(pManager.getApplicationIcon(pak.applicationInfo));
         aii.setLabel(pManager.getApplicationLabel(pak.applicationInfo).toString());
         aii.setPackageName(pak.applicationInfo.packageName);
         String filePath = pak.applicationInfo.publicSourceDir;
         aii.setSize(
             Util.round(new File(filePath).length() * 1.0 / (1024 * 1024), 2, BigDecimal.ROUND_UP)
                 + "MB");
         appList.add(aii);
       }
     }
   }
 }
 public static List<AppInfo> getAppInfoMd5(Context context) {
   PackageManager pm = context.getPackageManager();
   // 所有的安装在系统上的应用程序包信息。
   List<PackageInfo> packInfos = pm.getInstalledPackages(0);
   List<AppInfo> appInfos = new ArrayList<AppInfo>();
   for (PackageInfo packInfo : packInfos) {
     AppInfo appInfo = new AppInfo();
     // packInfo 相当于一个应用程序apk包的清单文件
     String packname = packInfo.packageName;
     Drawable icon = packInfo.applicationInfo.loadIcon(pm);
     String name = packInfo.applicationInfo.loadLabel(pm).toString();
     String sourceDir = packInfo.applicationInfo.sourceDir;
     int flags = packInfo.applicationInfo.flags; // 应用程序信息的标记 相当于用户提交的答卷
     if ((flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
       // 用户程序
       appInfo.setUserApp(true);
     } else {
       // 系统程序
       appInfo.setUserApp(false);
     }
     appInfo.setPackname(packname);
     appInfo.setIcon(icon);
     appInfo.setName(name);
     appInfo.sourceDir = sourceDir;
     appInfos.add(appInfo);
   }
   return appInfos;
 }
Beispiel #4
0
  private void setApplicationData() {
    final String[] from = new String[] {"appname", "pname"};
    final int[] to = new int[] {android.R.id.text1, android.R.id.text2};
    List<Map<String, Object>> mSysData = new ArrayList<Map<String, Object>>();
    List<Map<String, Object>> mLocalData = new ArrayList<Map<String, Object>>();
    PackageManager pm = getPackageManager();
    List<PackageInfo> pal = pm.getInstalledPackages(0);
    for (int i = 0, size = pal.size(); i < size; i++) {
      PackageInfo p = pal.get(i);
      ApplicationInfo ai = p.applicationInfo;
      HashMap<String, Object> map = new HashMap<String, Object>();
      map.put(from[0], ai.loadLabel(pm).toString());
      map.put(from[1], p.packageName);
      if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) > 0) {
        mSysData.add(map);
      } else {
        mLocalData.add(map);
      }
    }

    if (!mSysData.isEmpty()) {
      mHandler.sendEmptyMessage(1);
      mSysLv.setAdapter(
          new SimpleAdapter(this, mSysData, android.R.layout.simple_list_item_2, from, to));
    }
    if (!mLocalData.isEmpty()) {
      mHandler.sendEmptyMessage(2);
      mLocalLv.setAdapter(
          new SimpleAdapter(this, mLocalData, android.R.layout.simple_list_item_2, from, to));
    }
    mHandler.sendEmptyMessage(0);
  }
  public List<AppInfo> getInstalledApps() {

    List<PackageInfo> packageInfos = pm.getInstalledPackages(PackageManager.MATCH_DEFAULT_ONLY);
    ArrayList<AppInfo> appList = new ArrayList<AppInfo>();
    List<PackageInfo> packages = pm.getInstalledPackages(0);

    for (PackageInfo info : packages) {
      AppInfo appinfo = new AppInfo();

      appinfo.setPackname(info.packageName);
      appinfo.setVersion(info.versionName);
      appinfo.setAppname(info.applicationInfo.loadLabel(pm).toString());
      appinfo.setAppicon(info.applicationInfo.loadIcon(pm));
      appinfo.setUserpp(filterApp(info.applicationInfo));
      appList.add(appinfo);

      appinfo = null;
    }

    //        ArrayList<AppInfo> appList = new ArrayList<AppInfo>();
    //        List<ApplicationInfo> applicationInfo = pm.getInstalledApplications(0);
    //
    //        for (ApplicationInfo info : applicationInfo) {
    //            AppInfo appinfo = new AppInfo();
    //
    //            Drawable app_icon = info.loadIcon(pm);
    //            appinfo.setAppicon(app_icon);
    //            String app_name = info.loadLabel(pm).toString();
    //            appinfo.setAppname(app_name);
    //            String packageName = info.packageName;
    //            appinfo.setPackname(packageName);
    //            try {
    //                //获取应用的版本号
    //                PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
    //                String app_version = packageInfo.versionName;
    //                appinfo.setVersion(app_version);
    //            } catch (PackageManager.NameNotFoundException e) {
    //                e.printStackTrace();
    //            }
    //            appList.add(appinfo);

    //            Log.i("duanlang", "applicationInfos = " + applicationInfo);

    //        }

    return appList;
  }
 /**
  * 返回所有进程
  *
  * @return List<ProcessInfo>
  */
 public List<ProcessInfo> getAllProcesses() {
   List<ProcessManager.ProcessInfo> list = new ArrayList<ProcessManager.ProcessInfo>();
   PackageManager packageManager = mContext.getPackageManager();
   List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
   for (PackageInfo info : installedPackages) {
     list.add(convert(info, packageManager));
   }
   return list;
 }
Beispiel #7
0
  /**
   * @param context
   * @param packageName
   * @return
   */
  public boolean isAvilible(String packageName) {
    PackageManager packageManager = context.getPackageManager();

    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    for (int i = 0; i < pinfo.size(); i++) {
      if (((PackageInfo) pinfo.get(i)).packageName.equalsIgnoreCase(packageName)) return true;
    }
    return false;
  }
  public boolean isMobile_spExist(String packName) {
    PackageManager manager = mContext.getPackageManager();
    List<PackageInfo> pkgList = manager.getInstalledPackages(0);
    for (int i = 0; i < pkgList.size(); i++) {
      PackageInfo pI = pkgList.get(i);
      if (pI.packageName.equalsIgnoreCase(packName /*"com.alipay.android.app"*/)) return true;
    }

    return false;
  }
Beispiel #9
0
 public static boolean isAliInstalled() {
   String packageName = "com.eg.android.AlipayGphone";
   final PackageManager packageManager = MainApplication.getInstance().getPackageManager();
   // 获取所有已安装程序的包信息
   List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
   for (int i = 0; i < pinfo.size(); i++) {
     if (pinfo.get(i).packageName.equalsIgnoreCase(packageName)) return true;
   }
   return false;
 }
Beispiel #10
0
  /**
   * 获取一个已经安装的应用程序签名
   *
   * @param context
   * @param packageName
   * @return
   */
  public static String getAppSign(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_SIGNATURES);
    for (PackageInfo pkg : packages) {
      if (packageName.equals(pkg.packageName)) {
        return pkg.signatures[0].toCharsString();
      }
    }

    return null;
  }
Beispiel #11
0
 /**
  * 获取所有已安装App信息
  *
  * <p>AppInfo(名称,图标,包名,版本号,版本Code,是否安装在SD卡,是否是用户程序)
  */
 public static List<AppInfo> getAllAppsInfo(Context context) {
   List<AppInfo> list = new ArrayList<>();
   PackageManager pm = context.getPackageManager();
   // 获取系统中安装的所有软件信息
   List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
   for (PackageInfo pi : installedPackages) {
     if (pi != null) {
       list.add(getBean(pm, pi));
     }
   }
   return list;
 }
 @Override
 protected void onPreExecute() {
   PackageManager pm = getPackageManager();
   try {
     pkgAppsList = pm.getInstalledPackages(0);
   } catch (RuntimeException e) {
     // this is usually thrown when people have too many things installed (or bloatware in the
     // case of Samsung devices)
     pm = getPackageManager();
     appsList = pm.getInstalledApplications(0);
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    pm = getPackageManager();

    device = new Device();

    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getSupportActionBar();
    pagerAdapter = new PagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(pagerAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (String tab_name : tabs) {
      actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
    }

    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
          }

          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {}

          @Override
          public void onPageScrollStateChanged(int arg0) {}
        });

    List<PackageInfo> installedApplications =
        pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    device.apps = App.scanApps(installedApplications, this.getApplicationContext());
    double sum = 0.0;
    for (App a : device.apps) {
      sum += a.getScore();
    }
    device.setAppScore(sum / device.apps.size());

    device.os = OS.scanOS(android.os.Build.VERSION.RELEASE, getApplicationContext());
    device.setOsScore(device.os.getScore());

    Securitometer securitometer = (Securitometer) getApplicationContext();
    securitometer.setDevice(device);
  }
Beispiel #14
0
 /**
  * @Title: isAlreadyInstall @Description: 由package name判断程序是否已经安装应用
  *
  * @param context
  * @param pkgName
  * @return
  * @throws
  */
 public static boolean isAlreadyInstall(Context context, String pkgName) {
   final PackageManager packageManager = context.getPackageManager(); // 获取packagemanager
   List<PackageInfo> pinfo = packageManager.getInstalledPackages(0); // 获取所有已安装程序的包信息
   List<String> pName = new ArrayList<String>(); // 用于存储所有已安装程序的包名
   // 从pinfo中将包名字逐一取出,压入pName list中
   if (pinfo != null) {
     for (int i = 0; i < pinfo.size(); i++) {
       String pn = pinfo.get(i).packageName;
       pName.add(pn);
     }
   }
   return pName.contains(pkgName);
 }
Beispiel #15
0
 public List<PackageInfo> getAllApps() {
   List<PackageInfo> apps = new ArrayList<PackageInfo>();
   PackageManager pManager = this.getPackageManager();
   // 获取手机内所有应用
   List<PackageInfo> paklist = pManager.getInstalledPackages(0);
   for (int i = 0; i < paklist.size(); i++) {
     PackageInfo pak = (PackageInfo) paklist.get(i);
     // 判断是否为非系统预装的应用  (大于0为系统预装应用)
     if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <= 0) {
       apps.add(pak);
     }
   }
   return apps;
 }
  // Intended to be called only once at startup, after the system is ready. Installs a broadcast
  // receiver to monitor ongoing UID changes, so this shouldn't/needn't be called again.
  public synchronized void startMonitoring() {
    log("Monitoring");

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_USER_ADDED);
    intentFilter.addAction(Intent.ACTION_USER_REMOVED);
    mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null);

    intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null);

    List<PackageInfo> apps = mPackageManager.getInstalledPackages(GET_PERMISSIONS);
    if (apps == null) {
      loge("No apps");
      return;
    }

    for (PackageInfo app : apps) {
      int uid = app.applicationInfo != null ? app.applicationInfo.uid : -1;
      if (uid < 0) {
        continue;
      }

      boolean isNetwork = hasNetworkPermission(app);
      boolean isSystem = hasSystemPermission(app);

      if (isNetwork || isSystem) {
        Boolean permission = mApps.get(uid);
        // If multiple packages share a UID (cf: android:sharedUserId) and ask for different
        // permissions, don't downgrade (i.e., if it's already SYSTEM, leave it as is).
        if (permission == null || permission == NETWORK) {
          mApps.put(uid, isSystem);
        }
      }
    }

    List<UserInfo> users = mUserManager.getUsers(true); // exclude dying users
    if (users != null) {
      for (UserInfo user : users) {
        mUsers.add(user.id);
      }
    }

    log("Users: " + mUsers.size() + ", Apps: " + mApps.size());
    update(mUsers, mApps, true);
  }
Beispiel #17
0
 /**
  * * 取得微信版本号
  *
  * @param packageName
  * @return
  */
 public int getWeixinVersionCode() {
   PackageInfo packageInfo = null;
   final PackageManager packageManager = activity.getPackageManager();
   List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
   if (packageInfos == null) {
     return Integer.MAX_VALUE;
   }
   for (int index = 0; index < packageInfos.size(); index++) {
     packageInfo = packageInfos.get(index);
     final String name = packageInfo.packageName;
     if (WEIXIN_PKG.equals(name)) {
       return packageInfo.versionCode;
     }
   }
   return Integer.MAX_VALUE;
 }
Beispiel #18
0
  /**
   * Tells whether in-app billing is ready to work with specified app For OpenStore app: if any
   * in-app item for this app published in store
   */
  @Override
  public boolean isBillingAvailable(final String packageName) {
    Logger.i("NokiaStore.isBillingAvailable");
    Logger.d("packageName = ", packageName);

    final PackageManager packageManager = context.getPackageManager();
    final List<PackageInfo> allPackages = packageManager.getInstalledPackages(0);

    for (final PackageInfo packageInfo : allPackages) {

      if (NOKIA_INSTALLER.equals(packageInfo.packageName)) {
        return verifyFingreprint();
      }
    }

    return false;
  }
 private int hasBadPackages() {
   PackageManager pm = getPackageManager();
   List<PackageInfo> packages = pm.getInstalledPackages(0);
   HashMap<String, PackageInfo> map = new HashMap<String, PackageInfo>();
   if (DEBUG) Log.d(TAG, "Num Packages: " + packages.size());
   for (PackageInfo pi : packages) {
     map.put(pi.packageName.trim(), pi);
   }
   int count = 0;
   for (int i = 0; i < badPackages.length; i++) {
     if (map.containsKey(badPackages[i])) {
       if (DEBUG) Log.d(TAG, "contained package :" + badPackages[i]);
       count++;
     }
   }
   return count;
 }
    private void populatePreferences() {
      final PackageManager packageManager = getActivity().getPackageManager();
      List<PackageInfo> allInstalledPackages =
          packageManager.getInstalledPackages(PackageManager.GET_META_DATA);
      PreferenceScreen screen = getPreferenceScreen();
      Collections.sort(
          allInstalledPackages,
          new Comparator<PackageInfo>() {
            @Override
            public int compare(PackageInfo p1, PackageInfo p2) {
              return packageManager
                  .getApplicationLabel(p1.applicationInfo)
                  .toString()
                  .compareTo(packageManager.getApplicationLabel(p2.applicationInfo).toString());
            }
          });
      for (PackageInfo p : allInstalledPackages) {
        if (packageManager.getLaunchIntentForPackage(p.packageName) == null) {
          continue;
        }

        CheckBoxPreference pref = new CheckBoxPreference(screen.getContext());
        pref.setKey(getString(R.string.pref_app_notif_base) + "-" + p.packageName);
        pref.setTitle(packageManager.getApplicationLabel(p.applicationInfo));
        pref.setIcon(packageManager.getApplicationIcon(p.applicationInfo));
        pref.setChecked(
            PreferenceManager.getDefaultSharedPreferences(getActivity())
                .getBoolean(getString(R.string.pref_app_notif_base) + "-" + p.packageName, true));
        pref.setOnPreferenceChangeListener(
            new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                Bundle b = new Bundle();
                b.putString(
                    getString(R.string.analytics_param_app_name), preference.getTitle().toString());
                String newValueStr = newValue.toString().equals("true") ? "enabled" : "disabled";
                b.putString(getString(R.string.analytics_param_new_value), newValueStr);
                ((PreferencesActivity) getActivity())
                    .firebaseAnalytics.logEvent(getString(R.string.analytics_tap_app), b);
                return true;
              }
            });
        screen.addPreference(pref);
      }
    }
Beispiel #21
0
 private boolean installedApp(String packageName) {
   PackageInfo packageInfo = null;
   if (TextUtils.isEmpty(packageName)) {
     return false;
   }
   final PackageManager packageManager = activity.getPackageManager();
   List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
   if (packageInfos == null) {
     return false;
   }
   for (int index = 0; index < packageInfos.size(); index++) {
     packageInfo = packageInfos.get(index);
     final String name = packageInfo.packageName;
     if (packageName.equals(name)) {
       return true;
     }
   }
   return false;
 }
  protected void updateAppList() {
    android.content.pm.PackageManager pm = _context.getPackageManager();
    List<android.content.pm.PackageInfo> list = pm.getInstalledPackages(0);

    for (android.content.pm.PackageInfo pi : list) {
      try {
        android.content.pm.ApplicationInfo ai = pm.getApplicationInfo(pi.packageName, 0);
        String currAppName = pm.getApplicationLabel(pi.applicationInfo).toString();
        if ((ai.flags & 129) == 0) {
          // one list for display and one list to keep track of app dirs
          _completeAppList.add("[" + currAppName + "]\n" + pi.applicationInfo.packageName);
          _appList.add(pi.applicationInfo.dataDir);
        }

      } catch (Exception e) {
        Log.w("IntrospyConfig", "Error: " + e);
      }
    }
  }
Beispiel #23
0
 /**
  * 判断指定软件是否安装
  *
  * @param context
  * @param packageName 应用包名
  * @return
  */
 public static boolean isAppInstalled(Context context, String packageName) {
   try {
     if (context != null && !StringUtil.isEmpty(packageName)) {
       PackageManager packageManager = context.getPackageManager();
       // 获取所有已安装程序的包信息
       List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(0);
       List<String> packageNameList = new ArrayList<String>();
       if (packageInfoList != null) {
         for (int i = 0; i < packageInfoList.size(); i++) {
           String packName = packageInfoList.get(i).packageName;
           packageNameList.add(packName);
         }
       }
       // 判断包名列表中是否有目标程序的包名
       return packageNameList.contains(packageName);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
Beispiel #24
0
  /** Show task killer helper */
  private static void showTaskKillerHelp(final Context context) {
    if (!Preferences.getBoolean(P_TASK_KILLER_HELP, false)) {
      return;
    }

    // search for task killers. if they exist, show the help!
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> apps = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    outer:
    for (PackageInfo app : apps) {
      if (app == null || app.requestedPermissions == null) {
        continue;
      }
      if (app.packageName.startsWith("com.android")) // $NON-NLS-1$
      {
        continue;
      }
      for (String permission : app.requestedPermissions) {
        if (Manifest.permission.RESTART_PACKAGES.equals(permission)) {
          CharSequence appName = app.applicationInfo.loadLabel(pm);
          OnClickListener listener =
              new OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                  Preferences.setBoolean(P_TASK_KILLER_HELP, true);
                }
              };

          new AlertDialog.Builder(context)
              .setTitle(R.string.DLG_information_title)
              .setMessage(context.getString(R.string.task_killer_help, appName))
              .setIcon(android.R.drawable.ic_dialog_alert)
              .setPositiveButton(R.string.task_killer_help_ok, listener)
              .show();

          break outer;
        }
      }
    }
  }
  public static ArrayList<AppInfo> getInstallApp(Context con) {
    PackageManager pm = con.getPackageManager();
    List<PackageInfo> installedPackages = pm.getInstalledPackages(0);

    ArrayList<AppInfo> list = new ArrayList<AppInfo>();
    for (PackageInfo packageInfo : installedPackages) {
      AppInfo info = new AppInfo();

      String packageName = packageInfo.packageName;
      ApplicationInfo applicationInfo = packageInfo.applicationInfo;
      String name = applicationInfo.loadLabel(pm).toString();
      Drawable icon = applicationInfo.loadIcon(pm);

      int flags = applicationInfo.flags;
      // 判断应用是否是用户应用
      if ((flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) {
        // 系统APP
        info.isUserApp = false;
      } else {
        // 用户APP
        info.isUserApp = true;
      }
      // 判断应用安装位置
      if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE)
          == ApplicationInfo.FLAG_EXTERNAL_STORAGE) {
        // SD卡
        info.isRom = false;
      } else {
        info.isRom = true;
      }
      // 将用户信息封装到AppInfo中
      info.packageName = packageName;
      info.name = name;
      info.icon = icon;
      // 将应用信息保存到集合中
      list.add(info);
    }

    return list;
  }
  private void doCheckItem() {
    switch (id) {
      case 1:
        String loggerState = getprop("persist.service.logr.enable", "");
        String adbdState = getprop("init.svc.adbd", "");
        if (((loggerState != "" && "0".equals(loggerState)))
            && (adbdState != "" && "running".equals(adbdState))) {
          flag = true;
        } else {
          flag = false;
        }
        break;
      case 2:
        TelephonyManager TELEPHONY_SERVICE =
            (TelephonyManager) getSystemService(Service.TELEPHONY_SERVICE);

        int simState = TELEPHONY_SERVICE.getSimState();

        value =
            android.provider.Settings.System.getString(
                getContentResolver(), Settings.Secure.ADB_ENABLED);

        if ((simState == TelephonyManager.SIM_STATE_ABSENT)
            && (value != null && "1".equals(value))) {
          flag = true;
        } else {
          flag = false;
        }
        break;
      case 3:
        File Path = Environment.getExternalStorageDirectory();

        StatFs statFs = new StatFs(Path.getPath());

        long blockSize = statFs.getBlockSizeLong();

        long blockAvaliable = statFs.getAvailableBlocksLong();

        String avaliableSize = Formatter.formatFileSize(this, blockSize * blockAvaliable);

        long totalSize = getSectorTotalSize();

        Toast.makeText(
                this, "总存储空间 :" + totalSize + "G" + "可用存储空间 :" + avaliableSize, Toast.LENGTH_SHORT)
            .show();

        break;
      case 4:
        Toast.makeText(AutotestItemDetailActivity.this, "请手动查看", Toast.LENGTH_SHORT).show();
        break;
      case 5:
        MySQLiteOperator operator = new MySQLiteOperator();
        Cursor cursor = operator.launcherQuery();

        PackageManager pm = getPackageManager();
        List<PackageInfo> piList = pm.getInstalledPackages(0);

        if (cursor != null && cursor.getCount() > 0) {
          while (!cursor.isLast()) {

            value = cursor.getString(0);
            int start = value.indexOf("component=");
            int end = value.indexOf("/", start);
            value = value.substring(start + 10, end);

            boolean findme = findme(value, piList);
            if (findme == false) {
              flag = false;
              break;
            } else {
              flag = true;
            }
            cursor.moveToNext();
          }
        }
        break;
      case 6:
        value =
            android.provider.Settings.System.getString(
                getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);

        if (value != null && value.equals("com.iflytek.inputmethod/.FlyIME")) {
          flag = true;
        } else {
          flag = false;
        }
        break;
      case 7:
        Toast.makeText(this, "受Sim卡空间限制,复制话机联系人到Sim卡上仅保存联系人名称和号码", Toast.LENGTH_SHORT).show();
        break;
      case 8:
        TELEPHONY_SERVICE = (TelephonyManager) getSystemService(Service.TELEPHONY_SERVICE);
        simState = TELEPHONY_SERVICE.getSimState();
        if (simState == 5) {
          Uri uri = Uri.parse("content://icc/adn");
          ContentValues values = new ContentValues();

          values.put("_id", 10);
          values.put("index", 11);
          values.put("name", " A SimCard Test Contacts");
          values.put("number", "10086");
          values.put("email", "*****@*****.**");
          getContentResolver().insert(uri, values);

          Toast.makeText(getApplicationContext(), "手动重启后查看联系人是否添加成功", Toast.LENGTH_LONG).show();
        } else {
          Toast.makeText(this, "请插入Sim卡进行测试", Toast.LENGTH_SHORT).show();
        }
        break;
    }
  }
Beispiel #27
0
 public static List<PackageInfo> getAllApp(Context context) {
   PackageManager packageManager = context.getPackageManager();
   List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(0);
   return packageInfoList;
 }
Beispiel #28
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.arc);
    locHelper = new LocationHelper();
    locHelper.getLocation(ARC.this, locationResult);
    locationControlTask = new LocationControl();
    /*lstView = (ListView)findViewById(R.id.listView1);
    lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lstView.setTextFilterEnabled(true);*/
    colleges = getResources().getStringArray(R.array.colleges_array);
    longitude = getResources().getStringArray(R.array.longitude_array);
    latitude = getResources().getStringArray(R.array.latitude_array);
    college_address = getResources().getStringArray(R.array.College_address);
    // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.simplerow, colleges);

    // Assign adapter to ListView
    // lstView.setAdapter(adapter);
    // setListAdapter(new ArrayAdapter<String>(this,
    // android.R.layout.simple_list_item_checked, colleges));

    listView = (ExpandableListView) findViewById(R.id.list);
    List<Map<String, Object>> parentsList = new ArrayList<Map<String, Object>>();
    List<List<Map<String, Object>>> childrenList = new ArrayList<List<Map<String, Object>>>();

    PackageManager pm = getPackageManager();
    List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    for (int i = 0; i < colleges.length; i++) {
      // String[] permissions = info.requestedPermissions;
      if (colleges != null) {
        Map<String, Object> parentData = new HashMap<String, Object>();
        parentData.put(PARENT, colleges[i]);
        parentsList.add(parentData);

        List<Map<String, Object>> childList = new ArrayList<Map<String, Object>>();
        for (int j = i; j <= i; j++) {
          Map<String, Object> childData = new HashMap<String, Object>();
          childData.put(CHILD, college_address[i]);
          childList.add(childData);
        }
        childrenList.add(childList);
      }
    }

    /* btnShowLocation = (Button) findViewById(R.id.btnShowLocation);

          // show location button click event
          btnShowLocation.setOnClickListener(new View.OnClickListener() {

    	@Override
    	public void onClick(View arg0) {
    		// create class object
            gps = new GPSTracker(ARC.this);

    		// check if GPS enabled
            if(gps.canGetLocation()){

            	 lat = gps.getLatitude();
            	 lng = gps.getLongitude();

            	// \n is for new line

            	double mindist=100000.0,l=0.0,g=0.0;
      		  int i,m=0;
      		  for(i=0;i<colleges.length;i++)
      		  {   Double c_lat=Double.parseDouble(latitude[i]);
      		      Double c_lng=Double.parseDouble(longitude[i]);

      			  double min=sqrt(pow((c_lat-lat),2)+pow((c_lng-lng),2));
      		       if (min<mindist)
      		       {
      		    	   l=c_lat;
      		    	   g=c_lng;
      		    	   mindist=min;
      		    	   m=i;

      		       }}
      		Toast.makeText(getApplicationContext(),"Nearest ARC is "+ colleges[m], Toast.LENGTH_LONG).show();

      		  listView.smoothScrollToPosition(m);


            }else{
            	// can't get location
            	// GPS or Network is not enabled
            	// Ask user to enable GPS/network in settings
            	gps.showSettingsAlert();
            }

    	}
    });*/
    SimpleExpandableListAdapter adapter =
        new SimpleExpandableListAdapter(
            ARC.this,
            parentsList,
            R.layout.expandablelistview_group,
            new String[] {PARENT},
            new int[] {R.id.TextViewGroup},
            childrenList,
            R.layout.raw,
            new String[] {CHILD},
            new int[] {R.id.permission});

    listView.setAdapter(adapter);
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    Log.i("NetworkIntentService", "onHandleIntent");

    PackageManager manager = getApplicationContext().getPackageManager();
    packages = manager.getInstalledPackages(0);
    Log.i("onHandleIntent", Integer.toString(packages.size()) + " pakietów znaleziono");

    // Get the timestamp
    Date date = new Date();
    Timestamp timestamp = new Timestamp(date.getTime());
    String stringDate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(timestamp);

    for (int i = 0; i < packages.size(); i++) {
      // actually processed package
      PackageInfo pack = packages.get(i);
      // application uID
      int uid = pack.applicationInfo.uid;
      // packages Name
      String appName = pack.applicationInfo.packageName;
      // total data sent by the app
      Long sent = TrafficStats.getUidTxBytes(uid) / 1024;
      // total data received by the app
      Long received = TrafficStats.getUidRxBytes(uid) / 1024;

      if ((sent > 0 || received > 0) && appName != null) {
        // query to select temporary data for
        String[] projection = {
          TemporaryDataTable.COLUMN_ID,
          TemporaryDataTable.COLUMN_APP_NAME,
          TemporaryDataTable.COLUMN_DATA_SENT,
          TemporaryDataTable.COLUMN_DATA_RECEIVED
        };
        String selection = TemporaryDataTable.COLUMN_APP_NAME + " = ?";
        String[] selectionArgs = new String[] {appName};
        String orderBy = null;
        Cursor tempCursor =
            getContentResolver()
                .query(
                    DataMonitorContentProvider.CONTENT_URI_TEMP_DATAS,
                    projection,
                    selection,
                    selectionArgs,
                    orderBy);

        // obliczanie różnicy w wysłanych danych
        if (tempCursor != null) {
          Long tempSent = new Long("0");
          Long tempReceived = new Long("0");

          for (tempCursor.moveToFirst(); !tempCursor.isAfterLast(); tempCursor.moveToNext()) {
            tempSent =
                tempCursor.getLong(tempCursor.getColumnIndex(TemporaryDataTable.COLUMN_DATA_SENT));
            tempReceived =
                tempCursor.getLong(
                    tempCursor.getColumnIndex(TemporaryDataTable.COLUMN_DATA_RECEIVED));
          }

          if ((sent - tempSent) > 0 || (received - tempReceived) > 0) {
            ContentValues values = new ContentValues();
            values.put(DataTable.COLUMN_DATA_SENT, sent - tempSent);
            values.put(DataTable.COLUMN_DATA_RECEIVED, received - tempReceived);
            values.put(DataTable.COLUMN_APP_NAME, appName);
            values.put(DataTable.COLUMN_DATA_TIMESTAMP, stringDate);
            Log.i("onHandleIntent", appName + " dodano do bazy");
            dataUri =
                getContentResolver().insert(DataMonitorContentProvider.CONTENT_URI_DATAS, values);
          }
        }

        // insert gathered data to the SQLite Database
        ContentValues tempValues = new ContentValues();
        tempValues.put(TemporaryDataTable.COLUMN_APP_NAME, appName);
        tempValues.put(TemporaryDataTable.COLUMN_DATA_SENT, sent);
        tempValues.put(TemporaryDataTable.COLUMN_DATA_RECEIVED, received);
        tempValues.put(TemporaryDataTable.COLUMN_DATA_TIMESTAMP, stringDate);

        // usuwanie użytej danej
        getContentResolver()
            .delete(DataMonitorContentProvider.CONTENT_URI_TEMP_DATAS, selection, selectionArgs);
        tempDataUri =
            getContentResolver()
                .insert(DataMonitorContentProvider.CONTENT_URI_TEMP_DATAS, tempValues);
      }
    }
  }
Beispiel #30
-1
 /**
  * 这个奇怪的函数
  *
  * @param context
  * @param flags
  * @return
  */
 public List<PackageInfo> getInstalledPackages(Context context, int flags) {
   try {
     return pm.getInstalledPackages(flags);
   } catch (Exception ignored) {
     // we don't care why it didn't succeed. We'll do it using an alternative way instead
   }
   // use fallback:
   Process process;
   List<PackageInfo> result = new ArrayList<>();
   BufferedReader bufferedReader = null;
   try {
     process = Runtime.getRuntime().exec("pm list packages");
     bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
     String line;
     while ((line = bufferedReader.readLine()) != null) {
       final String packageName = line.substring(line.indexOf(':') + 1);
       final PackageInfo packageInfo = pm.getPackageInfo(packageName, flags);
       result.add(packageInfo);
     }
     process.waitFor();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (bufferedReader != null)
       try {
         bufferedReader.close();
       } catch (Exception e) {
         e.printStackTrace();
       }
   }
   return result;
 }