Skip to content

Commit

Permalink
Added Tiramasu support with version check for older versions of getAp…
Browse files Browse the repository at this point in the history
…plicationInfo() API (#1092)

* added Tiramasu support with API check for older versions

* formatted file

* format correcetly

* format comment

* more formatting

* Added test

* removed unused imiports

* tiramisu check

* Update FlutterRequestAgentProviderTest.java

* Format Fix

---------

Co-authored-by: Justin Malandruccolo <[email protected]>
Co-authored-by: Aldo Becerril <[email protected]>
  • Loading branch information
3 people authored May 14, 2024
1 parent e2afe0e commit 6ec7165
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ class FlutterRequestAgentProvider {

private void processGameAndNewsTemplateVersions(Context context) {
try {
ApplicationInfo info =
context
.getApplicationContext()
.getPackageManager()
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
ApplicationInfo info;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
info =
context
.getApplicationContext()
.getPackageManager()
.getApplicationInfo(
context.getPackageName(),
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA));
} else {
info =
context
.getApplicationContext()
.getPackageManager()
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
}
Bundle metaData = info.metaData;
if (metaData != null) {
gameTemplateVersion = info.metaData.getString(GAME_VERSION_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package io.flutter.plugins.googlemobileads;

import static android.os.Build.VERSION_CODES.S;
import static android.os.Build.VERSION_CODES.TIRAMISU;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand All @@ -23,14 +26,17 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

/** Tests {@link FlutterRequestAgentProvider}. */
@RunWith(RobolectricTestRunner.class)
@Config(sdk = {S, TIRAMISU})
public class FlutterRequestAgentProviderTest {

private Context mockContext;
Expand All @@ -49,9 +55,15 @@ public void setUp() throws NameNotFoundException {
doReturn(mockContext).when(mockContext).getApplicationContext();
doReturn(mockPackageManager).when(mockContext).getPackageManager();
doReturn(PACKAGE_NAME).when(mockContext).getPackageName();
doReturn(mockApplicationInfo)
.when(mockPackageManager)
.getApplicationInfo(eq(PACKAGE_NAME), eq(PackageManager.GET_META_DATA));
if (Build.VERSION.SDK_INT >= TIRAMISU) {
doReturn(mockApplicationInfo)
.when(mockPackageManager)
.getApplicationInfo(eq(PACKAGE_NAME), any());
} else {
doReturn(mockApplicationInfo)
.when(mockPackageManager)
.getApplicationInfo(eq(PACKAGE_NAME), eq(PackageManager.GET_META_DATA));
}
}

@Test
Expand Down

0 comments on commit 6ec7165

Please sign in to comment.