<lambda>null1 package expo.modules.updates.manifest
2 
3 import android.content.Context
4 import android.util.Log
5 import expo.modules.updates.UpdatesConfiguration
6 import org.apache.commons.io.IOUtils
7 import org.json.JSONObject
8 
9 /**
10  * Helper object for accessing and memoizing the manifest embedded in the application package.
11  */
12 object EmbeddedManifest {
13   private val TAG = EmbeddedManifest::class.java.simpleName
14 
15   private const val MANIFEST_FILENAME = "app.manifest"
16 
17   private var sEmbeddedManifest: UpdateManifest? = null
18 
19   fun get(context: Context, configuration: UpdatesConfiguration): UpdateManifest? {
20     if (!configuration.hasEmbeddedUpdate) {
21       return null
22     }
23     if (sEmbeddedManifest == null) {
24       try {
25         context.assets.open(MANIFEST_FILENAME).use { stream ->
26           val manifestString = IOUtils.toString(stream, "UTF-8")
27           val manifestJson = JSONObject(manifestString)
28           // automatically verify embedded manifest since it was already codesigned
29           manifestJson.put("isVerified", true)
30           sEmbeddedManifest = ManifestFactory.getEmbeddedManifest(manifestJson, configuration)
31         }
32       } catch (e: Exception) {
33         Log.e(TAG, "Could not read embedded manifest", e)
34         throw AssertionError("The embedded manifest is invalid or could not be read. Make sure you have configured expo-updates correctly in android/app/build.gradle. " + e.message)
35       }
36     }
37     return sEmbeddedManifest!!
38   }
39 }
40