Skip to content

Commit ba7d20c

Browse files
authored
Merge pull request #902 from Iterable/MOB-11167-Fix-ANR-Renaming-Config
Mob 11167 fix anr renaming config
2 parents 7a48374 + 7d453b7 commit ba7d20c

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ IterableKeychain getKeychain() {
144144
}
145145
if (keychain == null) {
146146
try {
147-
keychain = new IterableKeychain(getMainActivityContext(), config.decryptionFailureHandler, null, config.disableKeychainEncryption);
147+
keychain = new IterableKeychain(getMainActivityContext(), config.decryptionFailureHandler, null, config.keychainEncryption);
148148
} catch (Exception e) {
149149
IterableLogger.e(TAG, "Failed to create IterableKeychain", e);
150150
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class IterableConfig {
9797
* When set to true, disables encryption for keychain storage.
9898
* By default, encryption is enabled for storing sensitive user data.
9999
*/
100-
final boolean disableKeychainEncryption;
100+
final boolean keychainEncryption;
101101

102102
/**
103103
* Handler for decryption failures of PII information.
@@ -127,7 +127,7 @@ private IterableConfig(Builder builder) {
127127
dataRegion = builder.dataRegion;
128128
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
129129
enableEmbeddedMessaging = builder.enableEmbeddedMessaging;
130-
disableKeychainEncryption = builder.disableKeychainEncryption;
130+
keychainEncryption = builder.keychainEncryption;
131131
decryptionFailureHandler = builder.decryptionFailureHandler;
132132
mobileFrameworkInfo = builder.mobileFrameworkInfo;
133133
}
@@ -148,7 +148,7 @@ public static class Builder {
148148
private IterableDataRegion dataRegion = IterableDataRegion.US;
149149
private boolean useInMemoryStorageForInApps = false;
150150
private boolean enableEmbeddedMessaging = false;
151-
private boolean disableKeychainEncryption = false;
151+
private boolean keychainEncryption = true;
152152
private IterableDecryptionFailureHandler decryptionFailureHandler;
153153
private IterableAPIMobileFrameworkInfo mobileFrameworkInfo;
154154

@@ -314,11 +314,11 @@ public Builder setEnableEmbeddedMessaging(boolean enableEmbeddedMessaging) {
314314
/**
315315
* When set to true, disables encryption for Iterable's keychain storage.
316316
* By default, encryption is enabled for storing sensitive user data.
317-
* @param disableKeychainEncryption Whether to disable encryption for keychain
317+
* @param keychainEncryption Whether to disable encryption for keychain
318318
*/
319319
@NonNull
320-
public Builder setDisableKeychainEncryption(boolean disableKeychainEncryption) {
321-
this.disableKeychainEncryption = disableKeychainEncryption;
320+
public Builder setKeychainEncryption(boolean keychainEncryption) {
321+
this.keychainEncryption = keychainEncryption;
322322
return this;
323323
}
324324

iterableapi/src/main/java/com/iterable/iterableapi/IterableKeychain.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ class IterableKeychain {
1414
const val KEY_AUTH_TOKEN = "iterable-auth-token"
1515
private const val PLAINTEXT_SUFFIX = "_plaintext"
1616
private const val CRYPTO_OPERATION_TIMEOUT_MS = 500L
17-
private const val KEY_ENCRYPTION_DISABLED = "iterable-encryption-disabled"
17+
private const val KEY_ENCRYPTION_ENABLED = "iterable-encryption-enabled"
1818

1919
private val cryptoExecutor = Executors.newSingleThreadExecutor()
2020
}
2121

2222
private var sharedPrefs: SharedPreferences
2323
internal var encryptor: IterableDataEncryptor? = null
2424
private val decryptionFailureHandler: IterableDecryptionFailureHandler?
25-
private var encryptionDisabled: Boolean
25+
private var encryption: Boolean
2626

2727
@JvmOverloads
2828
constructor(
2929
context: Context,
3030
decryptionFailureHandler: IterableDecryptionFailureHandler? = null,
3131
migrator: IterableKeychainEncryptedDataMigrator? = null,
32-
encryptionDisabled: Boolean = false
32+
encryption: Boolean = true
3333
) {
3434
sharedPrefs = context.getSharedPreferences(
3535
IterableConstants.SHARED_PREFS_FILE,
3636
Context.MODE_PRIVATE
3737
)
3838
this.decryptionFailureHandler = decryptionFailureHandler
39-
this.encryptionDisabled = encryptionDisabled || sharedPrefs.getBoolean(KEY_ENCRYPTION_DISABLED, false)
39+
this.encryption = encryption && sharedPrefs.getBoolean(KEY_ENCRYPTION_ENABLED, true)
4040

41-
if (encryptionDisabled) {
41+
if (!encryption) {
4242
IterableLogger.v(TAG, "SharedPreferences being used without encryption")
4343
} else {
4444
encryptor = IterableDataEncryptor()
@@ -75,10 +75,10 @@ class IterableKeychain {
7575
.remove(KEY_EMAIL)
7676
.remove(KEY_USER_ID)
7777
.remove(KEY_AUTH_TOKEN)
78-
.putBoolean(KEY_ENCRYPTION_DISABLED, true)
78+
.putBoolean(KEY_ENCRYPTION_ENABLED, false)
7979
.apply()
8080

81-
encryptionDisabled = true
81+
encryption = false
8282

8383
decryptionFailureHandler?.let { handler ->
8484
val exception = e ?: Exception("Unknown decryption error")
@@ -99,7 +99,7 @@ class IterableKeychain {
9999

100100
private fun secureGet(key: String): String? {
101101
val hasPlainText = sharedPrefs.getBoolean(key + PLAINTEXT_SUFFIX, false)
102-
if (encryptionDisabled) {
102+
if (!encryption) {
103103
if (hasPlainText) {
104104
return sharedPrefs.getString(key, null)
105105
} else {
@@ -125,7 +125,7 @@ class IterableKeychain {
125125
return
126126
}
127127

128-
if (encryptionDisabled) {
128+
if (!encryption) {
129129
editor.putString(key, value).putBoolean(key + PLAINTEXT_SUFFIX, true).apply()
130130
return
131131
}

iterableapi/src/test/java/com/iterable/iterableapi/IterableConfigTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class IterableConfigTest {
2525
fun defaultDisableKeychainEncryption() {
2626
val configBuilder: IterableConfig.Builder = IterableConfig.Builder()
2727
val config: IterableConfig = configBuilder.build()
28-
assertFalse(config.disableKeychainEncryption)
28+
assertTrue(config.keychainEncryption)
2929
}
3030

3131
@Test
3232
fun setDisableKeychainEncryption() {
3333
val configBuilder: IterableConfig.Builder = IterableConfig.Builder()
34-
.setDisableKeychainEncryption(true)
34+
.setKeychainEncryption(false)
3535
val config: IterableConfig = configBuilder.build()
36-
assertTrue(config.disableKeychainEncryption)
36+
assertFalse(config.keychainEncryption)
3737
}
3838
}

iterableapi/src/test/java/com/iterable/iterableapi/IterableKeychainTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ class IterableKeychainTest {
6262

6363
// Mock migration-related SharedPreferences calls
6464
`when`(mockSharedPrefs.contains(any<String>())).thenReturn(false)
65-
`when`(mockSharedPrefs.getBoolean(any<String>(), anyBoolean())).thenReturn(false)
65+
// Mock encryption flag to be true by default
66+
`when`(mockSharedPrefs.getBoolean(eq("iterable-encryption-enabled"), anyBoolean())).thenReturn(true)
6667
`when`(mockSharedPrefs.getString(any<String>(), any())).thenReturn(null)
6768

6869
// Mock editor.apply() to do nothing
6970
Mockito.doNothing().`when`(mockEditor).apply()
7071

72+
// Create keychain with encryption enabled (default)
7173
keychain = IterableKeychain(
7274
mockContext,
7375
mockDecryptionFailureHandler
@@ -328,7 +330,7 @@ class IterableKeychainTest {
328330
mockContext,
329331
mockDecryptionFailureHandler,
330332
null,
331-
true
333+
false // encryption = false means encryption is disabled
332334
)
333335

334336
val testEmail = "[email protected]"

0 commit comments

Comments
 (0)