Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/Editor/UmpKitDependencies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="com.google.android.ump:user-messaging-platform:4.0.0+" />
</androidPackages>
<iosPods>
<iosPod name="GoogleUserMessagingPlatform" />
</iosPods>
</dependencies>
7 changes: 7 additions & 0 deletions src/Editor/UmpKitDependencies.xml.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/Runtime/Appegy.Ump.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "Appegy.Ump",
"rootNamespace": "Appegy.Ump",
"references": [],
"references": [
"UniTask"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
Expand Down
18 changes: 18 additions & 0 deletions src/Runtime/IUmpConsentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Threading;
using Cysharp.Threading.Tasks;

namespace Appegy.Ump
{
public interface IUmpConsentService
{
bool IsPrivacyOptionsRequired { get; }

UniTask<UmpResult> InitializeAsync(UmpInitializeParameters parameters, CancellationToken ct);

UniTask<UmpResult> ShowFormIfRequiredAsync(CancellationToken ct);

UniTask<UmpResult> ShowPrivacyOptionsFormAsync(CancellationToken ct);

UniTask ResetConsentAsync(CancellationToken ct);
}
}
2 changes: 2 additions & 0 deletions src/Runtime/IUmpConsentService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Runtime/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Runtime/Plugins/Android.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

164 changes: 164 additions & 0 deletions src/Runtime/Plugins/Android/UmpKitConsent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package com.appegy.ump;

import com.google.android.ump.ConsentDebugSettings;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.FormError;
import com.google.android.ump.UserMessagingPlatform;
import com.unity3d.player.UnityPlayer;

import android.app.Activity;

public final class UmpKitConsent
{
private static final String GAME_OBJECT = "UmpKit";
private static final String METHOD = "OnUmpMessage";

private static ConsentInformation consentInformation;
private static boolean formAvailable = false;

private UmpKitConsent() {}

private static Activity activity()
{
return UnityPlayer.currentActivity;
}

private static int status()
{
try
{
return consentInformation == null ? 0 : consentInformation.getConsentStatus();
}
catch (Exception e)
{
return 0;
}
}

private static void send(String op, int status, int error, int nativeCode, String message)
{
if (message == null)
{
message = "";
}
String payload = op + "|" + status + "|" + error + "|" + nativeCode + "|" + message;
UnityPlayer.UnitySendMessage(GAME_OBJECT, METHOD, payload);
}

public static void Initialize(final int debugGeography, final String testDevice)
{
activity().runOnUiThread(() -> doInitialize(debugGeography, testDevice));
}

private static void doInitialize(int debugGeography, String testDevice)
{
ConsentRequestParameters.Builder builder = new ConsentRequestParameters.Builder()
.setTagForUnderAgeOfConsent(false);

if (debugGeography > 0 && testDevice != null && testDevice.length() > 0)
{
ConsentDebugSettings debug = new ConsentDebugSettings.Builder(activity())
.setDebugGeography(debugGeography)
.addTestDeviceHashedId(testDevice)
.build();
builder.setConsentDebugSettings(debug);
}

ConsentRequestParameters params = builder.build();
consentInformation = UserMessagingPlatform.getConsentInformation(activity());
consentInformation.requestConsentInfoUpdate(
activity(),
params,
() ->
{
formAvailable = consentInformation.isConsentFormAvailable();
send("init", status(), 0, 0, "");
},
formError ->
{
send("init", status(), 1, formError.getErrorCode(), formError.getMessage());
});
}

public static void ShowFormIfRequired()
{
activity().runOnUiThread(UmpKitConsent::doShowFormIfRequired);
}

private static void doShowFormIfRequired()
{
if (consentInformation == null)
{
send("show", 0, 4, 0, "not initialized");
return;
}

if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED && !formAvailable)
{
send("show", status(), 2, 0, "form not available");
return;
}

UserMessagingPlatform.loadAndShowConsentFormIfRequired(
activity(),
formError ->
{
if (formError != null)
{
send("show", status(), 3, formError.getErrorCode(), formError.getMessage());
}
else
{
send("show", status(), 0, 0, "");
}
});
}

public static void ShowPrivacyOptionsForm()
{
activity().runOnUiThread(UmpKitConsent::doShowPrivacyOptions);
}

private static void doShowPrivacyOptions()
{
if (consentInformation == null)
{
send("privacy", 0, 4, 0, "not initialized");
return;
}

UserMessagingPlatform.showPrivacyOptionsForm(
activity(),
formError ->
{
if (formError != null)
{
send("privacy", status(), 3, formError.getErrorCode(), formError.getMessage());
}
else
{
send("privacy", status(), 0, 0, "");
}
});
}

public static void ResetConsent()
{
if (consentInformation != null)
{
consentInformation.reset();
}
formAvailable = false;
}

public static boolean IsPrivacyOptionsRequired()
{
if (consentInformation == null)
{
return false;
}
return consentInformation.getPrivacyOptionsRequirementStatus()
== ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED;
}
}
2 changes: 2 additions & 0 deletions src/Runtime/Plugins/Android/UmpKitConsent.java.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/Runtime/Plugins/Android/UmpKitProguard.androidlib.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.appegy.ump.proguard"
android:versionCode="1"
android:versionName="1.0">
</manifest>
17 changes: 17 additions & 0 deletions src/Runtime/Plugins/Android/UmpKitProguard.androidlib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apply plugin: 'com.android.library'

android {
namespace "io.appegy.ump.proguard"
compileSdk 36

defaultConfig {
minSdk 29
consumerProguardFiles 'proguard.txt'
}

lint { abortOnError false }

sourceSets {
main { manifest.srcFile 'AndroidManifest.xml' }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keep class com.appegy.ump.** { *; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target=android-9
android.library=true
8 changes: 8 additions & 0 deletions src/Runtime/Plugins/iOS.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading