Beispiel #1
0
  public static PackageParser.Package getPackageInfoFromPackage(
      String filePath, boolean collectSignature) {
    PackageParser packageParser = new PackageParser(filePath);
    File sourceFile = new File(filePath);
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    PackageParser.Package pkg = packageParser.parsePackage(sourceFile, filePath, metrics, 0);
    if (pkg != null && collectSignature) {
      packageParser.collectCertificates(pkg, 0);
    }

    return pkg;
  }
Beispiel #2
0
  public static Drawable getIconFromPackage(Context context, String archiveFilePath) {
    PackageParser packageParser = new PackageParser(archiveFilePath);
    File sourceFile = new File(archiveFilePath);
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
    if (pkg == null) {
      return context.getResources().getDrawable(R.drawable.android);
    }
    ApplicationInfo info = pkg.applicationInfo;

    Resources pRes = context.getResources();
    AssetManager assmgr = new AssetManager();
    assmgr.addAssetPath(archiveFilePath);
    Resources res = new Resources(assmgr, pRes.getDisplayMetrics(), pRes.getConfiguration());

    if (info.icon != 0) {
      Drawable icon = res.getDrawable(info.icon);
      return icon;
    } else {
      return context.getResources().getDrawable(R.drawable.android);
    }
  }
Beispiel #3
0
  // Load all application into PackageManager
  public PackageManagerService(Context context, boolean factoryTest) {

    // Collect all system packages.
    mSystemAppDir = new File(Environment.getRootDirectory(), "app");
    mSystemInstallObserver = new AppDirObserver(mSystemAppDir.getPath(), OBSERVER_EVENTS, true);
    mSystemInstallObserver.startWatching();
    // scan all apks in /system/app
    scanDirLI(
        mSystemAppDir,
        PackageParser.PARSE_IS_SYSTEM | PackageParser.PARSE_IS_SYSTEM_DIR,
        scanMode,
        0);
    // private void scanDirLI(File dir, int flags, int scanMode, long currentTime)
    {
      // for every files
      File file = new File(dir, files[i]);
      PackageParser.Package pkg =
          scanPackageLI(file, flags | PackageParser.PARSE_MUST_BE_APK, scanMode, currentTime);
      // private PackageParser.Package scanPackageLI(File scanFile,
      //      int parseFlags, int scanMode, long currentTime)
      // Scan a package and return the newly parsed package.
      {
        PackageParser pp = new PackageParser(scanPath);
        // XXX: here to load and parse one package
        final PackageParser.Package pkg = pp.parsePackage(scanFile, scanPath, mMetrics, parseFlags);
      } // scanPackageLI()

      // XXX: Verify certificates against what was last scanned
      collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags);
      // private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps,
      //      PackageParser.Package pkg, File srcFile, int parseFlags)
      {
        pp.collectCertificates(pkg, parseFlags);
      }
    } // scanDirLI()
  }
Beispiel #4
0
 // getPackageInfo()
 public PackageInfo getPackageInfo(String packageName, int flags) {
   PackageParser.Package p = mPackages.get(packageName);
   generatePackageInfo(p, flags);
   // PackageInfo generatePackageInfo(PackageParser.Package p, int flags)
   {
     // Everything is already preinstalled in PackageParser.Package
     PackageParser.generatePackageInfo(p, null, flags, 0, 0);
     // frameworks/base/core/java/android/content/pm/PackageParser.java
     // public static PackageInfo generatePackageInfo(PackageParser.Package p,
     //      int gids[], int flags, long firstInstallTime, long lastUpdateTime)
     {
       PackageInfo pi = new PackageInfo();
       pi.signatures = new Signature[N];
       System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
     } // PackageParser.generatePackageInfo()
   } // getPackageInfo()
 } // PackageManagerService.getPackageInfo()