This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[in_app_purchase] Android: fix potential crash when casting in v1 embedding. (Trivial) #2585
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5b437f5
fix potential crash
fa6804a
tests
2423162
remove legacy build setting
216ee9b
Update CHANGELOG.md
a3abc72
remove the null check
80d6869
Merge branch 'iap_crash_fix' of github.com:cyanglaz/plugins into iap_…
365b46a
update test
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 hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
...e/android/app/src/test/java/io/flutter/plugins/inapppurchase/InAppPurchasePluginTest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2019 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.plugins.inapppurchase; | ||
|
|
||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import android.app.Activity; | ||
| import android.app.Application; | ||
| import android.content.Context; | ||
| import io.flutter.plugin.common.BinaryMessenger; | ||
| import io.flutter.plugin.common.PluginRegistry; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| public class InAppPurchasePluginTest { | ||
| @Mock Activity activity; | ||
| @Mock Context context; | ||
| @Mock PluginRegistry.Registrar mockRegistrar; // For v1 embedding | ||
| @Mock BinaryMessenger mockMessenger; | ||
| @Mock Application mockApplication; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| MockitoAnnotations.initMocks(this); | ||
| when(mockRegistrar.activity()).thenReturn(activity); | ||
| when(mockRegistrar.messenger()).thenReturn(mockMessenger); | ||
| when(mockRegistrar.context()).thenReturn(context); | ||
| } | ||
|
|
||
| @Test | ||
| public void registerWith_doNotCrashWhenRegisterContextIsActivity_V1Embedding() { | ||
| when(mockRegistrar.context()).thenReturn(activity); | ||
| when(activity.getApplicationContext()).thenReturn(mockApplication); | ||
| InAppPurchasePlugin.registerWith(mockRegistrar); | ||
| } | ||
| } |
8 changes: 0 additions & 8 deletions
8
.../in_app_purchase/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
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.
Just for a little more info in case this doesn't make sense, the bug here is that sometimes
registrar.context()will return an Activity context instead of an Application context if it's available and this case will fail. My understanding is that it's the typical for it to do this so I'm actually surprised that this was routinely working before.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.
this was newly added in my new patch so it might be that my patch broke it. However, when I tested locally, it was working. I wonder why activity was not available when i was testing it.