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