Exemplo n.º 1
0
 public ContentProvider addProvider(
     Class<? extends ContentProvider> providerClass, String authority) throws Exception {
   ContentProvider provider = providerClass.newInstance();
   ProviderInfo info = new ProviderInfo();
   info.authority = authority;
   provider.attachInfo(mProviderContext, info);
   resolver.addProvider(authority, provider);
   return provider;
 }
 public void writeToParcel(Parcel dest, int parcelableFlags) {
   if (activityInfo != null) {
     dest.writeInt(1);
     activityInfo.writeToParcel(dest, parcelableFlags);
   } else if (serviceInfo != null) {
     dest.writeInt(2);
     serviceInfo.writeToParcel(dest, parcelableFlags);
   } else if (providerInfo != null) {
     dest.writeInt(3);
     providerInfo.writeToParcel(dest, parcelableFlags);
   } else {
     dest.writeInt(0);
   }
   if (filter != null) {
     dest.writeInt(1);
     filter.writeToParcel(dest, parcelableFlags);
   } else {
     dest.writeInt(0);
   }
   dest.writeInt(priority);
   dest.writeInt(preferredOrder);
   dest.writeInt(match);
   dest.writeInt(specificIndex);
   dest.writeInt(labelRes);
   TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);
   dest.writeInt(icon);
   dest.writeString(resolvePackageName);
   dest.writeInt(system ? 1 : 0);
 }
 public void dump(Printer pw, String prefix) {
   if (filter != null) {
     pw.println(prefix + "Filter:");
     filter.dump(pw, prefix + "  ");
   }
   pw.println(
       prefix
           + "priority="
           + priority
           + " preferredOrder="
           + preferredOrder
           + " match=0x"
           + Integer.toHexString(match)
           + " specificIndex="
           + specificIndex
           + " isDefault="
           + isDefault);
   if (resolvePackageName != null) {
     pw.println(prefix + "resolvePackageName=" + resolvePackageName);
   }
   if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
     pw.println(
         prefix
             + "labelRes=0x"
             + Integer.toHexString(labelRes)
             + " nonLocalizedLabel="
             + nonLocalizedLabel
             + " icon=0x"
             + Integer.toHexString(icon));
   }
   if (activityInfo != null) {
     pw.println(prefix + "ActivityInfo:");
     activityInfo.dump(pw, prefix + "  ");
   } else if (serviceInfo != null) {
     pw.println(prefix + "ServiceInfo:");
     serviceInfo.dump(pw, prefix + "  ");
   } else if (providerInfo != null) {
     pw.println(prefix + "ProviderInfo:");
     providerInfo.dump(pw, prefix + "  ");
   }
 }
Exemplo n.º 4
0
  private static void showPluginInfo(PluginPackageParser pluginPackageParser) {

    PluginInfo pluginInfo = new PluginInfo();
    pluginInfo.pkgParser = pluginPackageParser;

    PackageInfo packageInfo = null;

    try {
      packageInfo =
          pluginPackageParser.getPackageInfo(
              PackageManager.GET_ACTIVITIES
                  | PackageManager.GET_SERVICES
                  | PackageManager.GET_PROVIDERS
                  | PackageManager.GET_RECEIVERS
                  | PackageManager.GET_META_DATA);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (packageInfo != null) {
      pluginInfo.packageName = packageInfo.packageName;

      // test
      Log.d(TAG, "\n## packageInfo.packageInfo.applicationInfo: ");
      packageInfo.applicationInfo.dump(new LogPrinter(Log.DEBUG, TAG), "");
      Log.d(TAG, "\n\n");

      if (packageInfo.activities != null) {
        Log.d(TAG, "\n## packageInfo.activities: ");
        int i = 0;
        for (ActivityInfo activityInfo : packageInfo.activities) {
          Log.d(TAG, "packageInfo.activitie No." + ++i);
          activityInfo.dump(new LogPrinter(Log.DEBUG, TAG), "");
          Log.d(TAG, "\n");
        }
      }

      if (packageInfo.services != null) {
        Log.d(TAG, "\n## packageInfo.services: ");
        int i = 0;
        for (ServiceInfo serviceInfo : packageInfo.services) {
          Log.d(TAG, "packageInfo.service No." + ++i);
          serviceInfo.dump(new LogPrinter(Log.DEBUG, TAG), "");
          Log.d(TAG, "\n");
        }
      }

      if (packageInfo.receivers != null) {
        Log.d(TAG, "\n## packageInfo.receivers: ");
        int i = 0;
        for (ActivityInfo receiverInfo : packageInfo.receivers) {
          Log.d(TAG, "packageInfo.receiver No." + ++i);
          receiverInfo.dump(new LogPrinter(Log.DEBUG, TAG), "");
          Log.d(TAG, "\n");
        }
      }

      if (packageInfo.providers != null) {
        Log.d(TAG, "\n## packageInfo.providers: ");
        int i = 0;
        for (ProviderInfo providerInfo : packageInfo.providers) {
          Log.d(TAG, "packageInfo.provider No." + ++i);
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            providerInfo.dump(new LogPrinter(Log.DEBUG, TAG), "");
          } else {
            Log.d(TAG, " " + providerInfo);
          }
          Log.d(TAG, "\n");
        }
      }
    }
  }
Exemplo n.º 5
0
  @Override
  public void addManifest(AndroidManifest androidManifest) {
    androidManifests.put(androidManifest.getPackageName(), androidManifest);

    // first opportunity to access a resource index for this manifest, use it to init the references
    androidManifest.initMetaData(RuntimeEnvironment.getAppResourceLoader());

    PackageInfo packageInfo = new PackageInfo();
    packageInfo.packageName = androidManifest.getPackageName();
    packageInfo.versionName = androidManifest.getVersionName();
    packageInfo.versionCode = androidManifest.getVersionCode();

    ContentProviderData[] cpdata =
        androidManifest.getContentProviders().toArray(new ContentProviderData[] {});
    if (cpdata.length == 0) {
      packageInfo.providers = null;
    } else {
      packageInfo.providers = new ProviderInfo[cpdata.length];
      for (int i = 0; i < cpdata.length; i++) {
        ProviderInfo info = new ProviderInfo();
        info.authority = cpdata[i].getAuthority();
        info.name = cpdata[i].getClassName();
        info.packageName = androidManifest.getPackageName();
        packageInfo.providers[i] = info;
      }
    }

    // Populate information related to BroadcastReceivers. Broadcast receivers can be queried in two
    // possible ways,
    // 1. PackageManager#getPackageInfo(...),
    // 2. PackageManager#queryBroadcastReceivers(...)
    // The following piece of code will let you enable querying receivers through both the methods.
    List<ActivityInfo> receiverActivityInfos = new ArrayList<>();
    for (int i = 0; i < androidManifest.getBroadcastReceivers().size(); ++i) {
      ActivityInfo activityInfo = new ActivityInfo();
      activityInfo.name = androidManifest.getBroadcastReceivers().get(i).getClassName();
      activityInfo.permission = androidManifest.getBroadcastReceivers().get(i).getPermission();
      receiverActivityInfos.add(activityInfo);

      ResolveInfo resolveInfo = new ResolveInfo();
      resolveInfo.activityInfo = activityInfo;
      IntentFilter filter = new IntentFilter();
      for (String action : androidManifest.getBroadcastReceivers().get(i).getActions()) {
        filter.addAction(action);
      }
      resolveInfo.filter = filter;

      for (String action : androidManifest.getBroadcastReceivers().get(i).getActions()) {
        Intent intent = new Intent(action);
        intent.setPackage(androidManifest.getPackageName());
        addResolveInfoForIntent(intent, resolveInfo);
      }
    }
    packageInfo.receivers = receiverActivityInfos.toArray(new ActivityInfo[0]);

    String[] usedPermissions = androidManifest.getUsedPermissions().toArray(new String[] {});
    if (usedPermissions.length == 0) {
      packageInfo.requestedPermissions = null;
    } else {
      packageInfo.requestedPermissions = usedPermissions;
    }

    ApplicationInfo applicationInfo = new ApplicationInfo();
    applicationInfo.flags = androidManifest.getApplicationFlags();
    applicationInfo.targetSdkVersion = androidManifest.getTargetSdkVersion();
    applicationInfo.packageName = androidManifest.getPackageName();
    applicationInfo.processName = androidManifest.getProcessName();
    applicationInfo.name = androidManifest.getApplicationName();
    applicationInfo.metaData = metaDataToBundle(androidManifest.getApplicationMetaData());
    applicationInfo.sourceDir = new File(".").getAbsolutePath();
    applicationInfo.dataDir = TempDirectory.create().toAbsolutePath().toString();

    ResourceIndex resourceIndex = RuntimeEnvironment.getAppResourceLoader().getResourceIndex();
    if (androidManifest.getLabelRef() != null && resourceIndex != null) {
      Integer id =
          ResName.getResourceId(
              resourceIndex, androidManifest.getLabelRef(), androidManifest.getPackageName());
      applicationInfo.labelRes = id != null ? id : 0;
    }

    packageInfo.applicationInfo = applicationInfo;
    addPackage(packageInfo);
  }