Skip to content

Commit 98d3dcf

Browse files
authored
UPDATE flutter-hms-adsprime 13.4.55+301
1 parent 4449a57 commit 98d3dcf

32 files changed

+599
-544
lines changed

flutter-hms-adsprime/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 13.4.55+301
2+
3+
- Fixed an issue when destroying NativeAd.
4+
- Fixed an issue that caused RewardAd listeners to not work properly.
5+
- Fixed an issue that caused InterstitialAd listeners to not work properly.
6+
- Fixed an issue that caused some device information to be processed without user agreement.
7+
18
## 13.4.55+300
29

310
- Initial release.

flutter-hms-adsprime/android/src/main/java/com/huawei/hms/flutter/ads/HmsAdsPlugin.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.huawei.hms.ads.BannerAdSize;
2828
import com.huawei.hms.ads.HwAds;
2929
import com.huawei.hms.ads.RequestOptions;
30-
import com.huawei.hms.ads.consent.inter.Consent;
3130
import com.huawei.hms.ads.identifier.AdIdVerifyException;
3231
import com.huawei.hms.ads.identifier.AdvertisingIdClient;
3332
import com.huawei.hms.flutter.ads.adslite.banner.Banner;
@@ -80,7 +79,6 @@ public class HmsAdsPlugin implements FlutterPlugin, ActivityAware, MethodCallHan
8079
private MethodChannel methodChannel;
8180
private BinaryMessenger messenger;
8281
private FlutterPluginBinding flutterPluginBinding;
83-
private Consent consentInfo;
8482

8583
private EventChannel consentEventChannel;
8684
private MethodChannel splashMethodChannel;
@@ -127,10 +125,10 @@ private void attachedToActivity(@NonNull ActivityPluginBinding binding) {
127125

128126
this.activity = binding.getActivity();
129127
this.context = flutterPluginBinding.getApplicationContext();
130-
this.methodChannel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), Channels.LIBRARY_METHOD_CHANNEL);
131128
this.messenger = flutterPluginBinding.getBinaryMessenger();
129+
this.methodChannel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), Channels.LIBRARY_METHOD_CHANNEL);
132130
this.methodChannel.setMethodCallHandler(this);
133-
this.consentInfo = Consent.getInstance(binding.getActivity());
131+
134132
initAdChannels(flutterPluginBinding.getBinaryMessenger());
135133
initAdHandlers();
136134
setAdHandlers();
@@ -145,7 +143,6 @@ public void onDetachedFromActivityForConfigChanges() {
145143
HmsRewardAd.destroyAll();
146144
HmsInstallReferrer.disposeAll();
147145
activity = null;
148-
consentInfo = null;
149146
resetAdHandlers();
150147
removeAdHandlers();
151148
removeAdChannels();
@@ -158,7 +155,6 @@ public void onDetachedFromActivity() {
158155
Banner.destroyAll();
159156
HmsRewardAd.destroyAll();
160157
HmsInstallReferrer.disposeAll();
161-
consentInfo = null;
162158
activity = null;
163159
resetAdHandlers();
164160
removeAdHandlers();
@@ -176,7 +172,6 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
176172
methodChannel = null;
177173
messenger = null;
178174
activity = null;
179-
consentInfo = null;
180175
resetAdHandlers();
181176
removeAdHandlers();
182177
removeAdChannels();
@@ -202,8 +197,8 @@ private void initAdHandlers() {
202197
instreamMethodHandler = new InstreamMethodHandler(messenger, context);
203198
vastMethodHandler = new VastMethodHandler(context);
204199
installReferrerMethodHandler = new InstallReferrerMethodHandler(activity, referrerMethodChannel);
205-
consentMethodHandler = new ConsentMethodHandler(context, consentInfo);
206-
consentStreamHandler = new ConsentStreamHandler(consentInfo, context);
200+
consentMethodHandler = new ConsentMethodHandler(context);
201+
consentStreamHandler = new ConsentStreamHandler(context);
207202
}
208203

209204
private void setAdHandlers() {

flutter-hms-adsprime/android/src/main/java/com/huawei/hms/flutter/ads/adslite/interstitial/InterstitialMethodHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ private void initInterstitialAd(MethodCall call, Result result) {
9090

9191
EventChannelFactory.create(rId, Channels.REWARD_EVENT_CHANNEL, messenger);
9292
EventChannelFactory.setup(rId, new RewardStreamHandler(context));
93-
94-
new Interstitial(id, openInHmsCore, activity, context);
9593
result.success(true);
94+
95+
new Interstitial(id, openInHmsCore, activity, context);
9696
HMSLogger.getInstance(context).sendSingleEvent("initInterstitialAd");
9797
}
9898

flutter-hms-adsprime/android/src/main/java/com/huawei/hms/flutter/ads/adslite/nativead/NativeAdControllerFactory.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.util.Log;
2121
import android.util.SparseArray;
2222

23+
import com.huawei.hms.ads.nativead.NativeAd;
2324
import com.huawei.hms.flutter.ads.utils.constants.Channels;
2425

2526
import io.flutter.plugin.common.BinaryMessenger;
@@ -49,9 +50,12 @@ public static NativeAdController get(Integer id) {
4950
}
5051

5152
public static boolean dispose(int id) {
52-
NativeAdController controller = allControllers.get(id);
53+
final NativeAdController controller = allControllers.get(id);
5354
if (controller != null) {
54-
controller.getNativeAd().destroy();
55+
final NativeAd nativeAd = controller.getNativeAd();
56+
if (nativeAd != null) {
57+
nativeAd.destroy();
58+
}
5559
allControllers.remove(id);
5660
return true;
5761
}

flutter-hms-adsprime/android/src/main/java/com/huawei/hms/flutter/ads/adslite/reward/RewardMethodHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private void initRewardAd(MethodCall call, Result result) {
9393

9494
EventChannelFactory.create(id, Channels.REWARD_EVENT_CHANNEL, messenger);
9595
EventChannelFactory.setup(id, new RewardStreamHandler(context));
96+
result.success(true);
9697

9798
new HmsRewardAd(id, openInHmsCore, activity, context);
9899
HMSLogger.getInstance(context).sendSingleEvent("initRewardAd");

flutter-hms-adsprime/android/src/main/java/com/huawei/hms/flutter/ads/consent/ConsentMethodHandler.java

+9-18
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@
3838
public class ConsentMethodHandler implements MethodChannel.MethodCallHandler {
3939
private static final String TAG = "ConsentMethodHandler";
4040
private final Context context;
41-
private Consent consentInfo;
4241

43-
public ConsentMethodHandler(final Context context, final Consent consentInfo) {
42+
public ConsentMethodHandler(final Context context) {
4443
this.context = context;
45-
this.consentInfo = consentInfo;
4644
}
4745

4846
@Override
@@ -77,28 +75,21 @@ public void onMethodCall(@NonNull final MethodCall call, @NonNull final Result r
7775

7876
private void getTestDeviceId(Result result) {
7977
HMSLogger.getInstance(context).startMethodExecutionTimer("getTestDeviceId");
80-
if (consentInfo != null) {
81-
result.success(consentInfo.getTestDeviceId());
82-
HMSLogger.getInstance(context).sendSingleEvent("getTestDeviceId");
83-
} else {
84-
result.error(ErrorCodes.INNER, "Consent instance is null. getTestDeviceId failed.", "");
85-
HMSLogger.getInstance(context).sendSingleEvent("getTestDeviceId", ErrorCodes.INNER);
86-
}
78+
result.success(Consent.getInstance(context).getTestDeviceId());
79+
HMSLogger.getInstance(context).sendSingleEvent("getTestDeviceId");
8780
}
8881

8982
private void addTestDeviceId(MethodCall call, MethodChannel.Result result) {
9083
HMSLogger.getInstance(context).startMethodExecutionTimer("addTestDeviceId");
9184
String deviceId = FromMap.toString("deviceId", call.argument("deviceId"));
92-
if (deviceId != null && consentInfo != null) {
85+
if (deviceId != null) {
9386
Log.i(TAG, "SDK addTestDeviceId begin");
94-
consentInfo.addTestDeviceId(deviceId);
87+
Consent.getInstance(context).addTestDeviceId(deviceId);
9588
Log.i(TAG, "SDK addTestDeviceId end");
9689
result.success(true);
9790
HMSLogger.getInstance(context).sendSingleEvent("addTestDeviceId");
9891
} else {
99-
result.error(ErrorCodes.NULL_PARAM,
100-
"Test deviceId is null? : " + (deviceId == null) + ". | Consent initialized? : " + (consentInfo != null) + ". addTestDevice failed.",
101-
"");
92+
result.error(ErrorCodes.NULL_PARAM, "Test deviceId is null? : true. addTestDevice failed.", "");
10293
HMSLogger.getInstance(context).sendSingleEvent("addTestDeviceId", ErrorCodes.NULL_PARAM);
10394
}
10495
}
@@ -109,7 +100,7 @@ private void setDebugNeedConsent(MethodCall call, MethodChannel.Result result) {
109100
if (consentStr != null) {
110101
DebugNeedConsent needConsent = DebugNeedConsent.valueOf(consentStr);
111102
Log.i(TAG, "SDK setDebugNeedConsent begin");
112-
consentInfo.setDebugNeedConsent(needConsent);
103+
Consent.getInstance(context).setDebugNeedConsent(needConsent);
113104
Log.i(TAG, "SDK setDebugNeedConsent end");
114105
result.success(true);
115106
HMSLogger.getInstance(context).sendSingleEvent("setDebugNeedConsent");
@@ -124,7 +115,7 @@ private void setDebugNeedConsent(MethodCall call, MethodChannel.Result result) {
124115
private void setUnderAgeOfPromise(MethodCall call, MethodChannel.Result result) {
125116
HMSLogger.getInstance(context).startMethodExecutionTimer("setUnderAgeOfPromise");
126117
Boolean ageOfPromise = FromMap.toBoolean("ageOfPromise", call.argument("ageOfPromise"));
127-
consentInfo.setUnderAgeOfPromise(ageOfPromise);
118+
Consent.getInstance(context).setUnderAgeOfPromise(ageOfPromise);
128119
result.success(true);
129120
HMSLogger.getInstance(context).sendSingleEvent("setUnderAgeOfPromise");
130121
}
@@ -135,7 +126,7 @@ private void setConsentStatus(MethodCall call, MethodChannel.Result result) {
135126
if (status != null) {
136127
ConsentStatus consentStatus = ConsentStatus.valueOf(status);
137128
Log.i(TAG, "setConsentStatus begin");
138-
consentInfo.setConsentStatus(consentStatus);
129+
Consent.getInstance(context).setConsentStatus(consentStatus);
139130
Log.i(TAG, "setConsentStatus end");
140131
result.success(true);
141132
HMSLogger.getInstance(context).sendSingleEvent("setConsentStatus");

flutter-hms-adsprime/android/src/main/java/com/huawei/hms/flutter/ads/consent/ConsentStreamHandler.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@
3232

3333
public class ConsentStreamHandler implements EventChannel.StreamHandler {
3434
private static final String TAG = "ConsentStreamHandler";
35-
private final Consent consentInfo;
3635
private final Context context;
3736

38-
public ConsentStreamHandler(final Consent consentInfo, Context context) {
39-
this.consentInfo = consentInfo;
37+
public ConsentStreamHandler(Context context) {
4038
this.context = context;
4139
}
4240

4341
@Override
4442
public void onListen(Object args, final EventChannel.EventSink event) {
45-
consentInfo.requestConsentUpdate(new ConsentUpdateListenerImpl(context, event));
43+
Consent.getInstance(context).requestConsentUpdate(new ConsentUpdateListenerImpl(context, event));
4644
}
4745

4846
@Override

flutter-hms-adsprime/example/lib/pages/ads_menu_page.dart

+32-20
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ class AdsMenuPage extends StatelessWidget {
4545
style: Styles.menuButtonStyle,
4646
),
4747
onPressed: () {
48-
Navigator.push(context, MaterialPageRoute<dynamic>(
49-
builder: (BuildContext context) {
50-
return const PublisherPage();
51-
},
52-
));
48+
Navigator.push(
49+
context,
50+
MaterialPageRoute<dynamic>(
51+
builder: (BuildContext context) {
52+
return const PublisherPage();
53+
},
54+
),
55+
);
5356
},
5457
),
5558
ElevatedButton(
@@ -58,11 +61,14 @@ class AdsMenuPage extends StatelessWidget {
5861
style: Styles.menuButtonStyle,
5962
),
6063
onPressed: () {
61-
Navigator.push(context, MaterialPageRoute<dynamic>(
62-
builder: (BuildContext context) {
63-
return const OaidPage();
64-
},
65-
));
64+
Navigator.push(
65+
context,
66+
MaterialPageRoute<dynamic>(
67+
builder: (BuildContext context) {
68+
return const OaidPage();
69+
},
70+
),
71+
);
6672
},
6773
),
6874
ElevatedButton(
@@ -71,11 +77,14 @@ class AdsMenuPage extends StatelessWidget {
7177
style: Styles.menuButtonStyle,
7278
),
7379
onPressed: () {
74-
Navigator.push(context, MaterialPageRoute<dynamic>(
75-
builder: (BuildContext context) {
76-
return const InstallReferrerPage();
77-
},
78-
));
80+
Navigator.push(
81+
context,
82+
MaterialPageRoute<dynamic>(
83+
builder: (BuildContext context) {
84+
return const InstallReferrerPage();
85+
},
86+
),
87+
);
7988
},
8089
),
8190
ElevatedButton(
@@ -84,11 +93,14 @@ class AdsMenuPage extends StatelessWidget {
8493
style: Styles.menuButtonStyle,
8594
),
8695
onPressed: () {
87-
Navigator.push(context, MaterialPageRoute<dynamic>(
88-
builder: (BuildContext context) {
89-
return const VastAdPage();
90-
},
91-
));
96+
Navigator.push(
97+
context,
98+
MaterialPageRoute<dynamic>(
99+
builder: (BuildContext context) {
100+
return const VastAdPage();
101+
},
102+
),
103+
);
92104
},
93105
),
94106
],

flutter-hms-adsprime/example/lib/pages/identifier/oaid_page.dart

+12-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class OaidPage extends StatefulWidget {
2222
const OaidPage({Key? key}) : super(key: key);
2323

2424
@override
25-
_OaidPageState createState() => _OaidPageState();
25+
State<OaidPage> createState() => _OaidPageState();
2626
}
2727

2828
class _OaidPageState extends State<OaidPage> {
@@ -44,7 +44,9 @@ class _OaidPageState extends State<OaidPage> {
4444

4545
void testVerifyAdId() async {
4646
bool? isVerified = await AdvertisingIdClient.verifyAdId(
47-
_oaid!, _client!.isLimitAdTrackingEnabled!);
47+
_oaid!,
48+
_client!.isLimitAdTrackingEnabled!,
49+
);
4850
setState(() {
4951
_verified = isVerified;
5052
});
@@ -70,32 +72,24 @@ class _OaidPageState extends State<OaidPage> {
7072
crossAxisAlignment: CrossAxisAlignment.center,
7173
children: <Widget>[
7274
const Text('OAID', style: Styles.headerTextStyle),
73-
const SizedBox(
74-
height: 10,
75-
),
75+
const SizedBox(height: 10),
7676
Text(
7777
'$_oaid',
7878
style: Styles.textContentStyle,
7979
),
80-
const SizedBox(
81-
height: 30,
82-
),
83-
const Text('Limit Ad Tracking Enabled',
84-
style: Styles.headerTextStyle),
85-
const SizedBox(
86-
height: 10,
80+
const SizedBox(height: 30),
81+
const Text(
82+
'Limit Ad Tracking Enabled',
83+
style: Styles.headerTextStyle,
8784
),
85+
const SizedBox(height: 10),
8886
Text(
8987
'${_limitAdTracking ?? ''}',
9088
style: Styles.textContentStyle,
9189
),
92-
const SizedBox(
93-
height: 30,
94-
),
90+
const SizedBox(height: 30),
9591
const Text('Verify Ad Id', style: Styles.headerTextStyle),
96-
const SizedBox(
97-
height: 10,
98-
),
92+
const SizedBox(height: 10),
9993
Text(
10094
'${_verified ?? 'This method takes a long time. You may need to wait a while to see the verification result.'}',
10195
style: _verified != null

0 commit comments

Comments
 (0)