Skip to content

Commit 9589874

Browse files
authored
fix(android): enable hardware acceleration for IAM transparency (#855)
1 parent 3fc0fb6 commit 9589874

5 files changed

Lines changed: 75 additions & 4 deletions

File tree

.cursor/rules/pr-conventions.mdc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: Conventions for pull request titles and body content
3+
alwaysApply: true
4+
---
5+
6+
# Pull Request Conventions
7+
8+
## PR Title
9+
10+
Use semantic/conventional commit prefixes in PR titles:
11+
12+
- `fix:` for bug fixes
13+
- `feat:` for new features
14+
- `chore:` for maintenance tasks (deps, CI, tooling)
15+
- `refactor:` for code restructuring without behavior changes
16+
- `docs:` for documentation-only changes
17+
- `test:` for test-only changes
18+
19+
Example: `fix: resolve notification grouping on Android 14`
20+
21+
## PR Body
22+
23+
Follow the repo's PR template at `.github/pull_request_template.md`. Every PR body must include:
24+
25+
1. **One Line Summary** (required)
26+
2. **Motivation** (required) explaining why the change is being made
27+
3. **Scope** (recommended) describing what is and isn't affected
28+
4. **Testing** section with manual and/or unit testing details
29+
5. **Affected code checklist** with relevant items checked
30+
6. **Checklist** sections confirmed
31+
32+
Remove the instructional header block (between `<!-- START -->` and `<!-- END -->`) before submitting.

com.onesignal.unity.android/Runtime/OneSignalAndroid.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public override void Initialize(string appId)
133133
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
134134
var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
135135

136+
_enableHardwareAcceleration(activity);
137+
136138
_sdkWrapperClass.CallStatic("setSdkType", "unity");
137139
_sdkWrapperClass.CallStatic("setSdkVersion", VersionHeader);
138140

@@ -174,6 +176,27 @@ public override void Initialize(string appId)
174176
_completedInit(appId);
175177
}
176178

179+
/// <summary>
180+
/// Unity sets android:hardwareAccelerated="false" on its Activity which
181+
/// prevents WebView transparent backgrounds from rendering. The native SDK
182+
/// displays in-app messages via a PopupWindow whose window inherits this
183+
/// setting, causing the IAM to render with an opaque white background.
184+
/// Enabling the flag at the window level restores transparency without
185+
/// affecting Unity's own GL/Vulkan rendering surface.
186+
/// </summary>
187+
private static void _enableHardwareAcceleration(AndroidJavaObject activity)
188+
{
189+
activity.Call(
190+
"runOnUiThread",
191+
new AndroidJavaRunnable(() =>
192+
{
193+
const int FLAG_HARDWARE_ACCELERATED = 0x01000000;
194+
using var window = activity.Call<AndroidJavaObject>("getWindow");
195+
window.Call("setFlags", FLAG_HARDWARE_ACCELERATED, FLAG_HARDWARE_ACCELERATED);
196+
})
197+
);
198+
}
199+
177200
public override void Login(string externalId, string jwtBearerToken = null)
178201
{
179202
_sdkClass.CallStatic("login", externalId, jwtBearerToken);

examples/demo/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
# Testing on Example App
1+
# Testing on the Demo App
22

33
First try to use a more recent Unity version for testing on the emulators.
44

55
![Unity Version](docs/unity-version.png)
66

7+
## Command Line
8+
9+
You can build and install without opening the Unity editor by using the provided scripts. Have an emulator/simulator booted first, then run:
10+
11+
```sh
12+
# Android — builds APK and installs on a running emulator
13+
./run-android.sh
14+
15+
# iOS — generates Xcode project, builds, and installs on a booted simulator
16+
./run-ios.sh
17+
```
18+
19+
Both scripts accept `--no-install` to build only, `--install-only` to skip rebuilding, and `run-ios.sh` also supports `--open` to open the generated Xcode workspace. Set `UNITY_PATH` if Unity is not at the default location.
20+
21+
## Unity Editor
22+
723
### Android
824

925
Check your build profiles and make sure Android platform is selected.
@@ -20,6 +36,6 @@ Check your build profiles and make sure iOS platform is selected.
2036
Then configure your play settings and set `Target SDK` to `Simulator SDK`
2137
![iOS Example 1](docs/ios-example-1.png)
2238

23-
Then click `Build and Run` and select a location for the apk bundle. Or click `Build` to use own simualtor.
39+
Then click `Build and Run` and select a location for the apk bundle. Or click `Build` to use own simulator.
2440

2541
![iOS Example 1](docs/ios-example-2.png)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
99
UNITY="${UNITY_PATH:-/Applications/Unity/Hub/Editor/6000.3.6f1/Unity.app/Contents/MacOS/Unity}"
1010
ADB="/Applications/Unity/Hub/Editor/6000.3.6f1/PlaybackEngines/AndroidPlayer/SDK/platform-tools/adb"
1111
OUTPUT="$SCRIPT_DIR/Build/Android/onesignal-demo.apk"
12-
LOG="$SCRIPT_DIR/Build/build.log"
12+
LOG="$SCRIPT_DIR/Build/build-android.log"
1313
INSTALL=true
1414
SKIP_BUILD=false
1515

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -eu
88
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
99
UNITY="${UNITY_PATH:-/Applications/Unity/Hub/Editor/6000.3.6f1/Unity.app/Contents/MacOS/Unity}"
1010
XCODE_DIR="$SCRIPT_DIR/Build/iOS"
11-
LOG="$SCRIPT_DIR/Build/build.log"
11+
LOG="$SCRIPT_DIR/Build/build-ios.log"
1212
SCHEME="Unity-iPhone"
1313
DERIVED="$SCRIPT_DIR/Build/iOS-DerivedData"
1414
APP_BUNDLE_ID="com.onesignal.example"

0 commit comments

Comments
 (0)