// Copyright 2015-present 650 Industries. All rights reserved.

package host.exp.exponent.kernel.services.linking;

import android.net.Uri;

import host.exp.exponent.Constants;
import host.exp.exponent.kernel.KernelConstants;
import host.exp.exponent.kernel.KernelProvider;

public class LinkingKernelService {

  public LinkingKernelService() {
  }

  public void openURI(Uri uri) {
    KernelProvider.getInstance().openExperience(
        new KernelConstants.ExperienceOptions(uri.toString(), uri.toString(), null)
    );
  }

  public boolean canOpenURI(Uri uri) {
    String scheme = uri.getScheme();
    if ("exp".equals(scheme) || "exps".equals(scheme)) {
      return true;
    }

    if (Constants.SHELL_APP_SCHEME != null && Constants.SHELL_APP_SCHEME.equals(scheme)) {
      return true;
    }

    String host = uri.getHost();

    return host != null && ("exp.host".equals(host) || host.endsWith("exp.direct"));
  }
}

@@ -373,24 +373,148 @@
 (Uri uri) %7B%0A
+    String manifestUrl = (Constants.isStandaloneApp()%0A        ? Constants.INITIAL_URL.toString()%0A        : uri.toString());%0A
     KernelPr
@@ -533,16 +533,25 @@
 stance()
+%0A        
 .openExp
@@ -558,25 +558,16 @@
 erience(
-%0A        
 new Kern
@@ -596,30 +596,27 @@
 Options(
-uri.toString()
+manifestUrl
 , uri.to
@@ -630,21 +630,16 @@
 ), null)
-%0A    
 );%0A  %7D%0A%0A

allow Linking.openUrl while app is foregrounded (#6077)