Skip to content

Commit

Permalink
Renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslabari committed Mar 4, 2024
1 parent 5201211 commit d74b3aa
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion embrace-android-sdk/api/embrace-android-sdk.api
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public abstract interface class io/embrace/android/embracesdk/ReactNativeInterna
public abstract fun logRnAction (Ljava/lang/String;JJLjava/util/Map;ILjava/lang/String;)V
public abstract fun logRnView (Ljava/lang/String;)V
public abstract fun logUnhandledJsException (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public abstract fun setCacheableJavaScriptBundleUrl (Landroid/content/Context;Ljava/lang/String;Z)V
public abstract fun setJavaScriptBundleUrl (Landroid/content/Context;Ljava/lang/String;)V
public abstract fun setJavaScriptBundleUrlForCodePush (Landroid/content/Context;Ljava/lang/String;Z)V
public abstract fun setJavaScriptPatchNumber (Ljava/lang/String;)V
public abstract fun setReactNativeSdkVersion (Ljava/lang/String;)V
public abstract fun setReactNativeVersionNumber (Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ public interface ReactNativeInternalInterface : EmbraceInternalInterface {

public fun setReactNativeVersionNumber(version: String?)

/**
* Sets the React Native Bundle URL.
* @param context the context
* @param url the JavaScript bundle URL
*/
public fun setJavaScriptBundleUrl(context: Context, url: String)

/**
* Sets the React Native Bundle URL, indicating if the bundle was updated or not.
* If it was updated, the bundle ID will be recomputed.
* If not, the bundle ID will be retrieved from cache.
* @param context the context
* @param url the JavaScript bundle URL
* @param didUpdate if the bundle was updated
*/
public fun setCacheableJavaScriptBundleUrl(context: Context, url: String, didUpdate: Boolean)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ internal class EmbraceMetadataService private constructor(

override fun getEgl(): String? = egl

override fun setReactNativeBundleId(context: Context, jsBundleUrl: String?, didCodePushBundleUpdate: Boolean?) {
override fun setReactNativeBundleId(context: Context, jsBundleUrl: String?, forceUpdate: Boolean?) {
val currentUrl = preferencesService.javaScriptBundleURL

if (currentUrl != jsBundleUrl || didCodePushBundleUpdate == true) {
if (currentUrl != jsBundleUrl || forceUpdate == true) {
// It`s a new JS bundle URL, save the new value in preferences.
preferencesService.javaScriptBundleURL = jsBundleUrl

Expand All @@ -397,9 +397,9 @@ internal class EmbraceMetadataService private constructor(
jsBundleUrl,
buildInfo.buildId
)
if (didCodePushBundleUpdate != null) {
// If this was originated by Code Push, we should update the codePushJsBundleId in preferences.
preferencesService.codePushJsBundleId = bundleId
if (forceUpdate != null) {
// if we have a value for forceUpdate, it means the bundleId is cacheable and we should store it.
preferencesService.javaScriptBundleId = bundleId
}
bundleId
}
Expand Down Expand Up @@ -506,17 +506,13 @@ internal class EmbraceMetadataService private constructor(
if (appFramework == AppFramework.REACT_NATIVE) {
reactNativeBundleId = metadataBackgroundWorker.submit<String?> {
val lastKnownJsBundleUrl = preferencesService.javaScriptBundleURL
val lastKnownCodePushJsBundleId = preferencesService.codePushJsBundleId
if (!lastKnownJsBundleUrl.isNullOrEmpty() && !lastKnownCodePushJsBundleId.isNullOrEmpty()) {
// If we have a lastKnownCodePushJsBundleId, we use that as the last known bundle ID.
// This is because for CodePush, we'll be notified if the bundle is updated, and we can
// update the bundle ID at that moment.
return@submit lastKnownCodePushJsBundleId
val lastKnownJsBundleId = preferencesService.javaScriptBundleId
if (!lastKnownJsBundleUrl.isNullOrEmpty() && !lastKnownJsBundleId.isNullOrEmpty()) {
// If we have a lastKnownJsBundleId, we use that as the last known bundle ID.
return@submit lastKnownJsBundleId
} else {
// For other OTAs like Expo, we should calculate the bundle ID on each startup,
// as we don't have a way to know if the bundle was updated.
// If lastKnownJsBundleUrl is null, it means that neither CodePush nor any other OTA
// is being used, so the function will return the default buildId.
// If we don't have a lastKnownJsBundleId, we compute the bundle ID from the last known JS bundle URL.
// If the last known JS bundle URL is null, we set React Native bundle ID to the buildId.
return@submit computeReactNativeBundleId(
context,
lastKnownJsBundleUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ internal interface MetadataService {
* Sets React Native Bundle ID from a custom JavaScript Bundle URL.
* @param context the context
* @param jsBundleUrl the JavaScript bundle URL
* @param didCodePushBundleUpdate if the bundle was updated and we need to recompute the bundleId
* @param forceUpdate if the bundle was updated and we need to recompute the bundleId
*/
fun setReactNativeBundleId(context: Context, jsBundleUrl: String?, didCodePushBundleUpdate: Boolean? = null)
fun setReactNativeBundleId(context: Context, jsBundleUrl: String?, forceUpdate: Boolean? = null)

/**
* Sets the Embrace Flutter SDK version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ internal class EmbracePreferencesService(
get() = prefs.getStringPreference(JAVA_SCRIPT_BUNDLE_URL_KEY)
set(value) = prefs.setStringPreference(JAVA_SCRIPT_BUNDLE_URL_KEY, value)

override var codePushJsBundleId: String?
override var javaScriptBundleId: String?
get() = prefs.getStringPreference(JAVA_SCRIPT_BUNDLE_ID_KEY)
set(value) = prefs.setStringPreference(JAVA_SCRIPT_BUNDLE_ID_KEY, value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ internal interface PreferencesService {
var javaScriptBundleURL: String?

/**
* Last Code Push javaScript bundle ID.
* Last javaScript bundle ID.
*/
var codePushJsBundleId: String?
var javaScriptBundleId: String?

/**
* Embrace sdk version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ internal class ReactNativeInternalInterfaceImplTest {
impl.setCacheableJavaScriptBundleUrl(context, "index.android.bundle", true)
// Test that the metadata service was called with the correct parameters
assertEquals("index.android.bundle", metadataService.fakeReactNativeBundleId)
assertEquals(true, metadataService.didCodePushBundleUpdate)
assertEquals(true, metadataService.forceUpdate)
}

@Test
Expand All @@ -193,7 +193,7 @@ internal class ReactNativeInternalInterfaceImplTest {
impl.setJavaScriptBundleUrl(context, "index.android.bundle")
// Test that the metadata service was called with the correct parameters
assertEquals("index.android.bundle", metadataService.fakeReactNativeBundleId)
assertEquals(null, metadataService.didCodePushBundleUpdate)
assertEquals(null, metadataService.forceUpdate)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ internal class EmbraceMetadataReactNativeTest {
}

@Test
fun `test React Native bundle ID url as Asset with CodePush didUpdate param in true`() {
fun `test React Native bundle ID url as Asset with forceUpdate param in true`() {
val bundleIdFile = Files.createTempFile("bundle-test", ".temp").toFile()
val inputStream = FileInputStream(bundleIdFile)
preferencesService.javaScriptBundleURL = null
preferencesService.codePushJsBundleId = null
preferencesService.javaScriptBundleId = null

every { context.assets } returns assetManager
every { assetManager.open(any()) } returns inputStream
Expand All @@ -148,15 +148,15 @@ internal class EmbraceMetadataReactNativeTest {

assertNotEquals(buildInfo.buildId, metadataService.getReactNativeBundleId())
assertEquals("D41D8CD98F00B204E9800998ECF8427E", metadataService.getReactNativeBundleId())
assertEquals("D41D8CD98F00B204E9800998ECF8427E", preferencesService.codePushJsBundleId)
assertEquals("D41D8CD98F00B204E9800998ECF8427E", preferencesService.javaScriptBundleId)
}

@Test
fun `test React Native bundle ID url as Asset with CodePush didUpdate param in false`() {
fun `test React Native bundle ID url as Asset with forceUpdate param in false`() {
val bundleIdFile = Files.createTempFile("bundle-test", ".temp").toFile()
val inputStream = FileInputStream(bundleIdFile)
preferencesService.javaScriptBundleURL = "assets:https://index.android.bundle"
preferencesService.codePushJsBundleId = "persistedBundleId"
preferencesService.javaScriptBundleId = "persistedBundleId"

every { context.assets } returns assetManager
every { assetManager.open(any()) } returns inputStream
Expand All @@ -166,15 +166,15 @@ internal class EmbraceMetadataReactNativeTest {

assertNotEquals(buildInfo.buildId, metadataService.getReactNativeBundleId())
assertEquals("persistedBundleId", metadataService.getReactNativeBundleId())
assertEquals("persistedBundleId", preferencesService.codePushJsBundleId)
assertEquals("persistedBundleId", preferencesService.javaScriptBundleId)
}

@Test
fun `test React Native bundle ID url as Asset with CodePush didUpdate param being null`() {
fun `test React Native bundle ID url as Asset with forceUpdate param being null`() {
val bundleIdFile = Files.createTempFile("bundle-test", ".temp").toFile()
val inputStream = FileInputStream(bundleIdFile)
preferencesService.javaScriptBundleURL = null
preferencesService.codePushJsBundleId = null
preferencesService.javaScriptBundleId = null

every { context.assets } returns assetManager
every { assetManager.open(any()) } returns inputStream
Expand All @@ -184,7 +184,7 @@ internal class EmbraceMetadataReactNativeTest {

assertNotEquals(buildInfo.buildId, metadataService.getReactNativeBundleId())
assertEquals("D41D8CD98F00B204E9800998ECF8427E", metadataService.getReactNativeBundleId())
assertEquals(null, preferencesService.codePushJsBundleId)
assertEquals(null, preferencesService.javaScriptBundleId)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ internal class EmbraceMetadataServiceTest {
every { preferencesService.rnSdkVersion }.returns(null)
every { preferencesService.javaScriptPatchNumber }.returns(null)
every { preferencesService.javaScriptBundleURL }.returns(null)
every { preferencesService.codePushJsBundleId }.returns(null)
every { preferencesService.javaScriptBundleId }.returns(null)
every { MetadataUtils.appEnvironment(any()) }.returns("UNKNOWN")

val metadataService = getReactNativeMetadataService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class FakeMetadataService(sessionId: String? = null) : MetadataService
var fakeAppId: String = "o0o0o"
var fakeDeviceId: String = "07D85B44E4E245F4A30E559BFC0D07FF"
var fakeReactNativeBundleId: String? = "fakeReactNativeBundleId"
var didCodePushBundleUpdate: Boolean? = null
var forceUpdate: Boolean? = null
var fakeFlutterSdkVersion: String? = "fakeFlutterSdkVersion"
var fakeDartVersion: String? = "fakeDartVersion"
var fakeRnSdkVersion: String? = "fakeRnSdkVersion"
Expand Down Expand Up @@ -97,9 +97,9 @@ internal class FakeMetadataService(sessionId: String? = null) : MetadataService

override fun getAppState(): String = appState

override fun setReactNativeBundleId(context: Context, jsBundleUrl: String?, didCodePushBundleUpdate: Boolean?) {
override fun setReactNativeBundleId(context: Context, jsBundleUrl: String?, forceUpdate: Boolean?) {
fakeReactNativeBundleId = jsBundleUrl
this.didCodePushBundleUpdate = didCodePushBundleUpdate
this.forceUpdate = forceUpdate
}

override fun setEmbraceFlutterSdkVersion(version: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class FakePreferenceService(
override var backgroundActivityEnabled: Boolean = false,
override var dartSdkVersion: String? = null,
override var javaScriptBundleURL: String? = null,
override var codePushJsBundleId: String? = null,
override var javaScriptBundleId: String? = null,
override var rnSdkVersion: String? = null,
override var javaScriptPatchNumber: String? = null,
override var embraceFlutterSdkVersion: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ internal class EmbracePreferencesServiceTest {
}

@Test
fun `test code push JS bundle id is saved`() {
assertNull(service.codePushJsBundleId)
fun `test java script bundle id is saved`() {
assertNull(service.javaScriptBundleId)

val id = "0d48510589c0426b43f01a5fa060a333"
service.codePushJsBundleId = id
assertEquals(id, service.codePushJsBundleId)
service.javaScriptBundleId = id
assertEquals(id, service.javaScriptBundleId)
}

@Test
Expand Down

0 comments on commit d74b3aa

Please sign in to comment.