code: private static void setSourceApplication(Activity activity) {
  
          ComponentName callingApplication = activity.getCallingActivity();
          if (callingApplication != null) {
              String callingApplicationPackage = callingApplication.getPackageName();
              if (callingApplicationPackage.equals(activity.getPackageName())) {
                  // open by own app.
                  resetSourceApplication();
                  return;
              }
              sourceApplication = callingApplicationPackage;
          }
  
          // Tap icon to open an app will still get the old intent if the activity was opened by an intent before.
          // Introduce an extra field in the intent to force clear the sourceApplication.
          Intent openIntent = activity.getIntent();
          if (openIntent == null || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
              resetSourceApplication();
              return;
          }
  
          Bundle applinkData = AppLinks.getAppLinkData(openIntent);
  
          if (applinkData == null) {
              resetSourceApplication();
              return;
          }
  
          isOpenedByApplink = true;
  
          Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");
  
          if (applinkReferrerData == null) {
              sourceApplication = null;
              return;
          }
  
          String applinkReferrerPackage = applinkReferrerData.getString("package");
          sourceApplication = applinkReferrerPackage;
  
          // Mark this intent has been used to avoid use this intent again and again.
          openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);
  
          return;
      }
docs: Source Application setters and getters