Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.1+2

* Fix potential casting crash on Android v1 embedding when registering life cycle callbacks.
* Remove hard-coded legacy xcode build setting.

## 0.3.1+1

* Add `pedantic` to dev_dependency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static final class MethodNames {
public static void registerWith(Registrar registrar) {
InAppPurchasePlugin plugin = new InAppPurchasePlugin();
plugin.setupMethodChannel(registrar.activity(), registrar.messenger(), registrar.context());
((Application) registrar.context())
Copy link
Contributor

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.

Copy link
Contributor Author

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.

((Application) registrar.context().getApplicationContext())
.registerActivityLifecycleCallbacks(plugin.methodCallHandler);
}

Expand Down
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);
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion packages/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: in_app_purchase
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase
version: 0.3.1+1
version: 0.3.1+2


dependencies:
Expand Down