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 
32   public static void setSdkVersions(List<String> sdkVersions) {
33     ABI_VERSIONS = TextUtils.join(",", sdkVersions);
34 
35     // NOTE: Currently public-facing SDK versions and internal ABI versions are the same, but
36     // eventually we may decouple them
37     SDK_VERSIONS = ABI_VERSIONS;
38     SDK_VERSIONS_LIST = sdkVersions;
39   }
40 
41   static {
42     List<String> abiVersions = new ArrayList<>();
43     // THIS COMMENT IS USED BY android-build-aar.sh DO NOT MODIFY
44     abiVersions.add("20.0.0");
45     abiVersions.add("19.0.0");
46     abiVersions.add("18.0.0");
47     abiVersions.add("17.0.0");
48     abiVersions.add("16.0.0");
49     abiVersions.add("15.0.0");
50     abiVersions.add("14.0.0");
51 
52     if (TEMPORARY_ABI_VERSION != null) {
53       abiVersions.add(TEMPORARY_ABI_VERSION);
54     }
55 
56     setSdkVersions(abiVersions);
57 
58     List<EmbeddedResponse> embeddedResponses = new ArrayList<>();
59     embeddedResponses.add(new EmbeddedResponse("https://exp.host/@exponent/home/bundle", EMBEDDED_KERNEL_PATH, "application/javascript"));
60     // ADD EMBEDDED RESPONSES HERE
61     // START EMBEDDED RESPONSES
62     // END EMBEDDED RESPONSES
63     EMBEDDED_RESPONSES = embeddedResponses;
64   }
65 
66   public static final boolean DEBUG_COLD_START_METHOD_TRACING = false;
67   public static final boolean DEBUG_MANIFEST_METHOD_TRACING = false;
68   public static final boolean DEBUG_METHOD_TRACING = DEBUG_COLD_START_METHOD_TRACING || DEBUG_MANIFEST_METHOD_TRACING;
69   public static final boolean ENABLE_LEAK_CANARY = false;
70   public static final boolean WRITE_BUNDLE_TO_LOG = false;
71   public static final boolean WAIT_FOR_DEBUGGER = false;
72 
73   public static boolean isShellApp() {
74     return INITIAL_URL != null;
75   }
76 
77   public static class EmbeddedResponse {
78     public final String url;
79     public final String responseFilePath;
80     public final String mediaType;
81 
82     public EmbeddedResponse(final String url, final String responseFilePath, final String mediaType) {
83       this.url = url;
84       this.responseFilePath = responseFilePath;
85       this.mediaType = mediaType;
86     }
87   }
88 
89   public static String getVersionName(Context context) {
90     if (VERSION_NAME != null) {
91       // This will be set in shell apps
92       return VERSION_NAME;
93     } else {
94       try {
95         PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
96         return pInfo.versionName;
97       } catch (PackageManager.NameNotFoundException e) {
98         EXL.e(TAG, e.toString());
99         return "";
100       }
101     }
102   }
103 
104   private static boolean sIsDetached = true;
105   public static void setIsDetached(boolean isDetached) {
106     sIsDetached = isDetached;
107   }
108 
109   public static boolean isDetached() {
110     return sIsDetached;
111   }
112 }
113