code: public void installPackage(PackageInfo packageInfo) {
      ApplicationInfo appInfo = packageInfo.applicationInfo;
      if (appInfo == null) {
        appInfo = new ApplicationInfo();
        packageInfo.applicationInfo = appInfo;
      }
      if (appInfo.packageName == null) {
        appInfo.packageName = packageInfo.packageName;
      }
      if (appInfo.processName == null) {
        appInfo.processName = appInfo.packageName;
      }
      appInfo.flags |= ApplicationInfo.FLAG_INSTALLED;
      ComponentInfo[][] componentInfoArrays =
          new ComponentInfo[][] {
            packageInfo.activities,
            packageInfo.services,
            packageInfo.providers,
            packageInfo.receivers,
          };
      int uniqueNameCounter = 0;
      for (ComponentInfo[] componentInfos : componentInfoArrays) {
        if (componentInfos == null) {
          continue;
        }
        for (ComponentInfo componentInfo : componentInfos) {
          if (componentInfo.name == null) {
            componentInfo.name = appInfo.packageName + ".DefaultName" + uniqueNameCounter++;
            componentInfo.packageName = packageInfo.packageName;
          }
          componentInfo.applicationInfo = appInfo;
          componentInfo.packageName = appInfo.packageName;
          if (componentInfo.processName == null) {
            componentInfo.processName = appInfo.processName;
          }
        }
      }
      addPackageNoDefaults(packageInfo);
    }
docs: Installs a package with the {@link PackageManager}.
  
  In order to create PackageInfo objects in a valid state please use {@link
  androidx.test.core.content.pm.PackageInfoBuilder}.
  
  This method automatically simulates instalation of a package in the system, so it adds a
  flag {@link ApplicationInfo#FLAG_INSTALLED} to the application info and makes sure it exits. It
  will update applicationInfo in package components as well.
  
  If you don't want the package to be installed, use {@link #addPackageNoDefaults} instead.