コード例 #1
0
ファイル: BundleParser.java プロジェクト: yhsj0919/Small
  public boolean parsePackage() {
    AssetManager assmgr = null;
    boolean assetError = true;
    try {
      assmgr = ReflectAccelerator.newAssetManager();
      if (assmgr == null) return false;

      int cookie = ReflectAccelerator.addAssetPath(assmgr, mArchiveSourcePath);
      if (cookie != 0) {
        parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
        assetError = false;
      } else {
        Log.w(TAG, "Failed adding asset path:" + mArchiveSourcePath);
      }
    } catch (Exception e) {
      Log.w(TAG, "Unable to read AndroidManifest.xml of " + mArchiveSourcePath, e);
    }
    if (assetError) {
      if (assmgr != null) assmgr.close();
      return false;
    }

    res = new Resources(assmgr, Small.getContext().getResources().getDisplayMetrics(), null);
    return parsePackage(res, parser);
  }
コード例 #2
0
  private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {
      final String thisPackage = activity.getClass().getName();
      if (DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);

      final String packageName = activity.getApplicationInfo().packageName;
      final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
      final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");

      int eventType = xml.getEventType();
      while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
          String name = xml.getName();

          if ("application".equals(name)) {
            // Check if the <application> has the attribute
            if (DEBUG) Log.d(TAG, "Got <application>");

            for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
              if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

              if ("uiOptions".equals(xml.getAttributeName(i))) {
                uiOptions = xml.getAttributeIntValue(i, 0);
                break; // out of for loop
              }
            }
          } else if ("activity".equals(name)) {
            // Check if the <activity> is us and has the attribute
            if (DEBUG) Log.d(TAG, "Got <activity>");
            Integer activityUiOptions = null;
            String activityPackage = null;
            boolean isOurActivity = false;

            for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
              if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

              // We need both uiOptions and name attributes
              String attrName = xml.getAttributeName(i);
              if ("uiOptions".equals(attrName)) {
                activityUiOptions = xml.getAttributeIntValue(i, 0);
              } else if ("name".equals(attrName)) {
                activityPackage = cleanActivityName(packageName, xml.getAttributeValue(i));
                if (!thisPackage.equals(activityPackage)) {
                  break; // out of for loop
                }
                isOurActivity = true;
              }

              // Make sure we have both attributes before processing
              if ((activityUiOptions != null) && (activityPackage != null)) {
                // Our activity, uiOptions specified, override with our value
                uiOptions = activityUiOptions.intValue();
              }
            }
            if (isOurActivity) {
              // If we matched our activity but it had no logo don't
              // do any more processing of the manifest
              break;
            }
          }
        }
        eventType = xml.nextToken();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
    return uiOptions;
  }