Exemplo n.º 1
0
  @Override
  public ActivityInfo getActivityInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String activityName = className.getClassName();
    ActivityData activityData = androidManifest.getActivityData(activityName);
    ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = packageName;
    activityInfo.name = activityName;
    if (activityData != null) {
      activityInfo.parentActivityName = activityData.getParentActivityName();
      activityInfo.metaData = metaDataToBundle(activityData.getMetaData().getValueMap());
      ResourceIndex resourceIndex = shadowsAdapter.getResourceLoader().getResourceIndex();
      String themeRef;

      // Based on ShadowActivity
      if (activityData.getThemeRef() != null) {
        themeRef = activityData.getThemeRef();
      } else {
        themeRef = androidManifest.getThemeRef();
      }
      if (themeRef != null) {
        ResName style = ResName.qualifyResName(themeRef.replace("@", ""), packageName, "style");
        activityInfo.theme = resourceIndex.getResourceId(style);
      }
    }
    activityInfo.applicationInfo = getApplicationInfo(packageName, flags);
    return activityInfo;
  }
  public boolean setThemeFromManifest() {
    ShadowApplication shadowApplication = shadowOf(realActivity.getApplication());
    AndroidManifest appManifest = shadowApplication.getAppManifest();
    if (appManifest == null) return false;

    String themeRef = appManifest.getThemeRef(realActivity.getClass());

    if (themeRef != null) {
      ResName style =
          ResName.qualifyResName(themeRef.replace("@", ""), appManifest.getPackageName(), "style");
      Integer themeRes =
          shadowApplication.getResourceLoader().getResourceIndex().getResourceId(style);
      if (themeRes == null)
        throw new Resources.NotFoundException("no such theme " + style.getFullyQualifiedName());
      realActivity.setTheme(themeRes);
      return true;
    }
    return false;
  }
Exemplo n.º 3
0
  @Implementation
  public int getIdentifier(String name, String defType, String defPackage) {
    ResourceIndex resourceIndex = resourceLoader.getResourceIndex();

    // Probably ResName should be refactored to accept partial names.
    // ResName should act as a qualifiedName parser in this case.
    if (!name.contains("/") && defType != null) {
      name = defType + "/" + name;
    }

    Integer index = ResName.getResourceId(resourceIndex, name, defPackage);
    if (index == null) {
      return 0;
    }
    return index;
  }
Exemplo n.º 4
0
 public void setCreatedFromResId(int resId, ResName resName) {
   this.createdFromResId = resId;
   appendDescription(" for resource:" + resName.getFullyQualifiedName());
 }
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);
  }