Skip to content

Commit 9bbd3d5

Browse files
fix: show paywall immediately when subscription is cancelled
clearPurchaseMark() previously reset KEY_INITIAL_SETUP_FLAG to true, which was a no-op (startTrialIfNecessaryWithInternetTime skips if endTime is already set) and left confirmedExpired=false. This meant a cancelled subscriber with a still-valid original trial window could continue using the app for free. Fix: - Set KEY_INITIAL_SETUP_FLAG to false (correct: no new trial is granted) - Set KEY_CFG_ST (confirmedExpired) to true so the paywall appears immediately after the subscription lapses, independent of the original trial end time.
1 parent 28a8592 commit 9bbd3d5

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/TrialManager.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,23 @@ object TrialManager {
294294
val obfuscatedFalse = obfuscateData("false")
295295
Log.d(TAG, "Setting KEY_FEATURE_ACCESS_FLAG to obfuscated 'false'")
296296
editor.putString(KEY_FEATURE_ACCESS_FLAG, obfuscatedFalse)
297-
// Comment for future AI: KEY_INITIAL_SETUP_FLAG is reset to true to allow trial re-evaluation.
298-
Log.d(TAG, "Setting KEY_INITIAL_SETUP_FLAG to true")
299-
editor.putBoolean(KEY_INITIAL_SETUP_FLAG, true)
300-
// IMPORTANT: KEY_CFG_TS (obfuscated trial end time) and KEY_CFG_ST (obfuscated confirmed expired flag)
301-
// are intentionally NOT cleared here. The original trial period might still be relevant.
297+
// KEY_INITIAL_SETUP_FLAG is set to false (not true) because:
298+
// - setting it to true would make startTrialIfNecessaryWithInternetTime() try to start
299+
// a new trial, but that is blocked by the existing endTime (KEY_CFG_TS != null), so
300+
// it was a no-op anyway and only caused confusion.
301+
// - the trial period already ran (or is still running); we do not grant a second trial.
302+
Log.d(TAG, "Setting KEY_INITIAL_SETUP_FLAG to false")
303+
editor.putBoolean(KEY_INITIAL_SETUP_FLAG, false)
304+
// KEY_CFG_ST (confirmedExpired) is set to true so that the paywall is shown immediately
305+
// after the subscription lapses, regardless of whether the original trial window has
306+
// already ended. A cancelled subscriber must re-subscribe, not get a free trial extension.
307+
Log.d(TAG, "Setting KEY_CFG_ST (confirmedExpired) to obfuscated 'true'")
308+
editor.putString(KEY_CFG_ST, obfuscateData("true"))
309+
// KEY_CFG_TS (trial end time) is intentionally preserved so the expiry timestamp
310+
// remains readable in logs for debugging, but it no longer affects gating because
311+
// confirmedExpired=true takes priority in getTrialState().
302312
editor.apply()
303-
Log.i(TAG, "Purchase mark cleared. Feature access flag set to obfuscated false, initial setup flag reset to true. Trial end time and expired flag preserved.")
313+
Log.i(TAG, "Purchase mark cleared. Feature access revoked, confirmedExpired set to true → paywall will be shown immediately.")
304314
}
305315

306316
fun initializeTrialStateFlagsIfNecessary(context: Context) {

0 commit comments

Comments
 (0)