1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 package host.exp.exponent;
4 
5 import android.content.Context;
6 import android.content.pm.PackageInfo;
7 import android.content.pm.PackageManager;
8 import android.net.Uri;
9 import android.text.TextUtils;
10 
11 import java.util.ArrayList;
12 import java.util.List;
13 
14 import host.exp.exponent.analytics.EXL;
15 
16 public class Constants {
17 
18   private static final String TAG = Constants.class.getSimpleName();
19 
20   public static final String VERSION_NAME = null;
21   public static String INITIAL_URL = null;
22   public static final String SHELL_APP_SCHEME = null;
23   public static final String API_HOST = "https://exp.host";
24   public static String ABI_VERSIONS;
25   public static String SDK_VERSIONS;
26   public static List<String> SDK_VERSIONS_LIST;
27   public static final String TEMPORARY_ABI_VERSION = null;
28   public static final String EMBEDDED_KERNEL_PATH = "assets://kernel.android.bundle";
29   public static final List<EmbeddedResponse> EMBEDDED_RESPONSES;
30   public static boolean DISABLE_NUX = false;
31   public static final String RELEASE_CHANNEL = "default";
32   public static boolean SHOW_LOADING_VIEW_IN_SHELL_APP = false;
33 
34   public static void setSdkVersions(List<String> sdkVersions) {
35     ABI_VERSIONS = TextUtils.join(",", sdkVersions);
36 
37     // NOTE: Currently public-facing SDK versions and internal ABI versions are the same, but
38     // eventually we may decouple them
39     SDK_VERSIONS = ABI_VERSIONS;
40     SDK_VERSIONS_LIST = sdkVersions;
41   }
42 
43   static {
44     List<String> abiVersions = new ArrayList<>();
45     // THIS COMMENT IS USED BY android-build-aar.sh DO NOT MODIFY
46     abiVersions.add("22.0.0");
47     abiVersions.add("21.0.0");
48     abiVersions.add("20.0.0");
49     abiVersions.add("19.0.0");
50     abiVersions.add("18.0.0");
51     abiVersions.add("17.0.0");
52     abiVersions.add("16.0.0");
53     abiVersions.add("15.0.0");
54     abiVersions.add("14.0.0");
55 
56     if (TEMPORARY_ABI_VERSION != null) {
57       abiVersions.add(TEMPORARY_ABI_VERSION);
58     }
59 
60     setSdkVersions(abiVersions);
61 
62     List<EmbeddedResponse> embeddedResponses = new ArrayList<>();
63     embeddedResponses.add(new EmbeddedResponse("https://exp.host/@exponent/home/bundle", EMBEDDED_KERNEL_PATH, "application/javascript"));
64     // ADD EMBEDDED RESPONSES HERE
65     // START EMBEDDED RESPONSES
66     // END EMBEDDED RESPONSES
67     EMBEDDED_RESPONSES = embeddedResponses;
68   }
69 
70   public static final boolean DEBUG_COLD_START_METHOD_TRACING = false;
71   public static final boolean DEBUG_MANIFEST_METHOD_TRACING = false;
72   public static final boolean DEBUG_METHOD_TRACING = DEBUG_COLD_START_METHOD_TRACING || DEBUG_MANIFEST_METHOD_TRACING;
73   public static final boolean ENABLE_LEAK_CANARY = false;
74   public static final boolean WRITE_BUNDLE_TO_LOG = false;
75   public static final boolean WAIT_FOR_DEBUGGER = false;
76 
77   public static boolean isShellApp() {
78     return INITIAL_URL != null;
79   }
80 
81   public static class EmbeddedResponse {
82     public final String url;
83     public final String responseFilePath;
84     public final String mediaType;
85 
86     public EmbeddedResponse(final String url, final String responseFilePath, final String mediaType) {
87       this.url = url;
88       this.responseFilePath = responseFilePath;
89       this.mediaType = mediaType;
90     }
91   }
92 
93   public static String getVersionName(Context context) {
94     if (VERSION_NAME != null) {
95       // This will be set in shell apps
96       return VERSION_NAME;
97     } else {
98       try {
99         PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
100         return pInfo.versionName;
101       } catch (PackageManager.NameNotFoundException e) {
102         EXL.e(TAG, e.toString());
103         return "";
104       }
105     }
106   }
107 
108   private static boolean sIsDetached = true;
109   public static void setIsDetached(boolean isDetached) {
110     sIsDetached = isDetached;
111   }
112 
113   public static boolean isDetached() {
114     return sIsDetached;
115   }
116 }
117