-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Paywalls V2] Handles configuring while the device is locked #2077
Draft
JayShortway
wants to merge
4
commits into
main
Choose a base branch
from
device-locked
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f6e7c3
Uses the provided context instead of the application when the device …
JayShortway cd21438
Fixes PurchasesConfigureTest.
JayShortway 8717459
Refactors PurchasesFactoryTest to use shadows.
JayShortway efaaf1f
Revert "Refactors PurchasesFactoryTest to use shadows."
JayShortway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,11 @@ | |
|
||
package com.revenuecat.purchases | ||
|
||
import android.Manifest | ||
import android.app.Activity | ||
import android.app.Application | ||
import android.content.Context | ||
import androidx.lifecycle.ProcessLifecycleOwner | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.android.billingclient.api.Purchase | ||
import com.android.billingclient.api.PurchaseHistoryRecord | ||
import com.revenuecat.purchases.PurchasesAreCompletedBy.REVENUECAT | ||
|
@@ -50,19 +51,16 @@ import io.mockk.slot | |
import io.mockk.unmockkStatic | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.robolectric.Shadows.shadowOf | ||
|
||
internal open class BasePurchasesTest { | ||
protected val mockBillingAbstract: BillingAbstract = mockk() | ||
protected val mockBackend: Backend = mockk() | ||
protected val mockCache: DeviceCache = mockk() | ||
protected val updatedCustomerInfoListener: UpdatedCustomerInfoListener = mockk() | ||
private val mockApplication = mockk<Application>(relaxed = true).apply { | ||
every { applicationContext } returns this | ||
} | ||
protected val mockContext = mockk<Context>(relaxed = true).apply { | ||
every { | ||
applicationContext | ||
} returns mockApplication | ||
protected val mockContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
private val mockApplication = (mockContext.applicationContext as Application).apply { | ||
shadowOf(this).grantPermissions(Manifest.permission.INTERNET) | ||
Comment on lines
-59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required, because a mocked |
||
} | ||
protected val mockIdentityManager = mockk<IdentityManager>() | ||
protected val mockSubscriberAttributesManager = mockk<SubscriberAttributesManager>() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have only one concern with this PR... That is, if the shared preferences we obtain with the given context is different than the one we obtain through the application, there is a chance of us losing the entire cached shared preferences right? This could result in using anonymous ids inadvertently (unless the developer always passes us the user id when configuring), losing entitlements until the cache can be refreshed, or losing subscriber attributes.
I'm just wondering if we should try to store this data in files, instead of shared preferences to avoid these possible issues...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this back to draft, as this is indeed an issue. Good one! I'm not entirely sure if moving the data in a non-sharedprefs file is a solution, as I believe the data directory is different for a "regular" context vs a "device-protected-storage" context. So we'd still end up with 2 copies, depending on when the SDK is configured.
Thinking about this, I'm starting to think we should not try to be smart about it, and just pass the
Context
directly togetDefaultSharedPreferences()
. That way app developers that need this can make sure to always give us a consistent one (e.g. always a "device-protected-storage" context).