Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fb619b7
feat: [SDK-4774] add optional location module disable
fadi-george Jun 12, 2026
4291ea8
feat(examples): add no-location demo project
fadi-george Jun 12, 2026
6e9c68f
docs(examples): clarify no-location setup
fadi-george Jun 12, 2026
cd3a148
feat(examples): add build scripts for no-location demo
fadi-george Jun 12, 2026
f93d84f
fix(examples): enforce no-location in scripted builds
fadi-george Jun 12, 2026
ccf13de
chore: bump Android to 5.9.5, iOS to 5.5.3
fadi-george Jun 29, 2026
688d184
feat(examples): redesign no-location demo UI
fadi-george Jun 29, 2026
a515431
docs(examples): expand no-location demo README
fadi-george Jun 29, 2026
b522eae
feat(examples): inject app ID during scripted builds
fadi-george Jun 29, 2026
54775fc
fix(examples): preserve OneSignal assemblies in no-location demo
fadi-george Jun 30, 2026
bee7273
docs(examples): note required link.xml in no-location demo
fadi-george Jun 30, 2026
01aea3f
feat: [SDK-4774] add test notification button to no-location demo
fadi-george Jun 30, 2026
06b4c06
chore(examples): add UnityWebRequest package lock entry
fadi-george Jun 30, 2026
79d56f0
fix(examples): prefer brew rsync over openrsync
fadi-george Jun 30, 2026
6423e81
fix(examples): expand location card UI height
fadi-george Jun 30, 2026
c56f7f3
fix(ios): log error when location module missing
fadi-george Jun 30, 2026
f46893a
chore(examples): configure Android build for no-location demo
fadi-george Jun 30, 2026
93006c2
chore(examples): disable Android fullscreen safe area
fadi-george Jun 30, 2026
479be50
fix(android): log error when location module missing
fadi-george Jun 30, 2026
ae5bd1f
refactor(deps): move EDM4U manifests to Assets/OneSignal/Editor
fadi-george Jun 30, 2026
a1ba64a
style(ios): condense podfile string assignment
fadi-george Jun 30, 2026
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
10 changes: 6 additions & 4 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@

# Get versions from target branch (not the release branch)
CURRENT_VERSION=$(git show origin/${{ inputs.target_branch }}:examples/demo/Assets/OneSignal/VERSION | tr -d '\n\r' | xargs)
ANDROID_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml | grep -oE 'spec="com.onesignal:OneSignal:[0-9]+\.[0-9]+\.[0-9]+"' | sed -E 's/.*OneSignal:([0-9]+\.[0-9]+\.[0-9]+)".*/\1/' | head -1)
IOS_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml | grep -oE 'version="[0-9.]+"' | grep -oE '[0-9.]+' | head -1)
ANDROID_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs | grep -oE 'Version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
IOS_VERSION=$(git show origin/${{ inputs.target_branch }}:com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs | grep -oE 'Version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
echo "unity_from=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
echo "android_from=${ANDROID_VERSION}" >> $GITHUB_OUTPUT
echo "ios_from=${IOS_VERSION}" >> $GITHUB_OUTPUT
Expand All @@ -106,13 +106,14 @@
FOUND=true; break
fi
echo "Attempt $i: Android SDK version ${VERSION} not found, retrying in 30s..."
sleep 30
done
if [ "$FOUND" != "true" ]; then echo "✗ Android SDK version ${VERSION} not found after 5 attempts"; exit 1; fi
sed -i -E "s/spec=\"com\.onesignal:OneSignal:[0-9][0-9.]*\"/spec=\"com.onesignal:OneSignal:$VERSION\"/" com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml
sed -i -E "s/const string Version = \"[0-9][0-9.]*\"/const string Version = \"$VERSION\"/" com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs
sed -i -E "s/<androidPackage spec=\"com\.onesignal:OneSignal:[0-9][0-9.]*\"/<androidPackage spec=\"com.onesignal:OneSignal:$VERSION\"/" examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml
sed -i -E "s/'com\.onesignal:OneSignal:[0-9][0-9.]*'/'com.onesignal:OneSignal:$VERSION'/" examples/demo/Assets/Plugins/Android/mainTemplate.gradle
sed -i -E "s/<package>com\.onesignal:OneSignal:[0-9][0-9.]*<\/package>/<package>com.onesignal:OneSignal:$VERSION<\/package>/" examples/demo/ProjectSettings/AndroidResolverDependencies.xml

Check failure on line 116 in .github/workflows/create-release-pr.yml

View check run for this annotation

Claude / Claude Code Review

Release workflow does not update demo-no-location dependency files

The release workflow in `.github/workflows/create-release-pr.yml` only updates files under `examples/demo/` and never touches the new `examples/demo-no-location/` project, so the four committed dependency files there (`Assets/OneSignal/Editor/OneSignal{Android,iOS}Dependencies.xml`, `Assets/Plugins/Android/mainTemplate.gradle`, `ProjectSettings/AndroidResolverDependencies.xml`) will retain stale versions after each release. Additionally, the existing sed patterns only match the umbrella `com.one
Comment on lines 109 to 116

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 The release workflow in .github/workflows/create-release-pr.yml only updates files under examples/demo/ and never touches the new examples/demo-no-location/ project, so the four committed dependency files there (Assets/OneSignal/Editor/OneSignal{Android,iOS}Dependencies.xml, Assets/Plugins/Android/mainTemplate.gradle, ProjectSettings/AndroidResolverDependencies.xml) will retain stale versions after each release. Additionally, the existing sed patterns only match the umbrella com.onesignal:OneSignal:VERSION artifact and would not match this demo's granular artifacts (core/notifications/in-app-messages, OneSignalXCFramework/OneSignal\[InAppMessages\]) even if the paths were added. Fix needs both path additions and new sed patterns that target the granular coordinate forms.

Extended reasoning...

What the bug is. This PR adds a new demo project at examples/demo-no-location/ and checks in four files that hardcode the OneSignal native SDK versions (currently 5.9.5 for Android, 5.5.3 for iOS). The release workflow at .github/workflows/create-release-pr.yml is responsible for bumping these hardcoded versions in the umbrella examples/demo/ project on every release, but its sed steps only enumerate examples/demo/ paths — examples/demo-no-location/ is never touched.

The specific code path. Lines 113-115 (Android) update examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml, examples/demo/Assets/Plugins/Android/mainTemplate.gradle, and examples/demo/ProjectSettings/AndroidResolverDependencies.xml. Line 137 (iOS) updates examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml. None of these touch examples/demo-no-location/. Beyond the missing paths, the regexes themselves are umbrella-artifact-only: com\.onesignal:OneSignal:[0-9][0-9.]* matches com.onesignal:OneSignal:5.9.5 but does not match the granular forms used by the no-location demo (com.onesignal:core:5.9.5, com.onesignal:notifications:5.9.5, com.onesignal:in-app-messages:5.9.5).

Why existing code doesn't prevent it. The new OneSignalAndroidDependencies.cs / OneSignaliOSDependencies.cs files do regenerate the XML manifests via [InitializeOnLoad] when Unity opens the project, so the two XMLs under Assets/OneSignal/Editor/ will eventually self-heal — but only once a developer opens demo-no-location in the Unity Editor. The release workflow runs in CI without Unity, so the committed release state still ships stale XML. More importantly, Assets/Plugins/Android/mainTemplate.gradle and ProjectSettings/AndroidResolverDependencies.xml are EDM4U snapshots that only refresh on an explicit Force Resolve, which is not triggered by anything in the release pipeline.

Impact. A release bump produces a commit where examples/demo/ is at the new version and examples/demo-no-location/ is still at the previous version, across both Android (gradle + resolver xml) and iOS (pod manifest). Anyone checking out the release tag sees inconsistent demo state. SDK consumers installing via UPM are unaffected — this is a release-engineering / demo-hygiene correctness issue, not a runtime bug.

Step-by-step proof. Suppose the next release is invoked with android_version=5.10.0, ios_version=5.6.0:

  1. Workflow updates com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs Version const → 5.10.0. ✓
  2. Workflow runs sed -i -E "s/<androidPackage spec=\"com\.onesignal:OneSignal:[0-9][0-9.]*\"/.../" examples/demo/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml → matches and rewrites. ✓
  3. Workflow does NOT run sed on examples/demo-no-location/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml. The file still reads com.onesignal:core:5.9.5, com.onesignal:notifications:5.9.5, com.onesignal:in-app-messages:5.9.5. ✗
  4. Even if the path were added, the regex com\.onesignal:OneSignal:[0-9][0-9.]* does not match com.onesignal:core:5.9.5 (artifact id core, not OneSignal). Still stale. ✗
  5. Same outcome for examples/demo-no-location/Assets/Plugins/Android/mainTemplate.gradle (implementation 'com.onesignal:core:5.9.5' etc.) and examples/demo-no-location/ProjectSettings/AndroidResolverDependencies.xml (<package>com.onesignal:core:5.9.5</package> etc.). ✗
  6. The release commit lands with examples/demo/ updated to 5.10.0/5.6.0 and examples/demo-no-location/ stuck at 5.9.5/5.5.3.

How to fix. Extend the Android step to also run granular-artifact substitutions across the demo-no-location files, e.g.:

for artifact in core notifications in-app-messages; do
  sed -i -E "s/(com\.onesignal::)[0-9][0-9.]*/\1$VERSION/g" \
    examples/demo-no-location/Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml \
    examples/demo-no-location/Assets/Plugins/Android/mainTemplate.gradle \
    examples/demo-no-location/ProjectSettings/AndroidResolverDependencies.xml
done

And the iOS step needs to update examples/demo-no-location/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml — the existing version="[0-9][0-9.]*" regex would actually match the granular OneSignalXCFramework/OneSignal and OneSignalXCFramework/OneSignalInAppMessages iosPod entries, so just adding the path to line 137 is sufficient on the iOS side.

# Only commit if there are changes
git add -A
git diff --staged --quiet && exit 0
Expand All @@ -132,7 +133,8 @@
sleep 30
done
if [ "$FOUND" != "true" ]; then echo "✗ iOS SDK version ${VERSION} not found after 5 attempts"; exit 1; fi
sed -i -E "s/version=\"[0-9][0-9.]*\"/version=\"$VERSION\"/" com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.xml
sed -i -E "s/const string Version = \"[0-9][0-9.]*\"/const string Version = \"$VERSION\"/" com.onesignal.unity.ios/Editor/OneSignaliOSDependencies.cs
sed -i -E "s/version=\"[0-9][0-9.]*\"/version=\"$VERSION\"/" examples/demo/Assets/OneSignal/Editor/OneSignaliOSDependencies.xml

# Only commit if there are changes
git add -A
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ jobs:
- name: Resolve OneSignal Android SDK version
id: android-sdk-version
run: |
VERSION=$(grep -oE 'com\.onesignal:OneSignal:[^"]+' com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.xml | head -n1 | cut -d: -f3)
VERSION=$(grep -oE 'Version = "[0-9]+\.[0-9]+\.[0-9]+"' com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs | head -n1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$VERSION" ]; then
echo "::error::Could not parse OneSignal Android SDK version from OneSignalAndroidDependencies.xml"
echo "::error::Could not parse OneSignal Android SDK version from OneSignalAndroidDependencies.cs"
exit 1
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ The only thing remaining is to setup your own notification icons. You can do thi
with your own. There is a complete guide for this [in the plugin's README](com.onesignal.unity.android/Editor/OneSignalConfig.androidlib/README.md). See our
[Customize Notification Icons](https://documentation.onesignal.com/docs/customize-notification-icons) page for additional details.

### Disable Location Module

By default, the OneSignal Unity SDK includes OneSignal's native location module so `OneSignal.Location` works without extra setup. If your app does not use location features, you can exclude the native location module from iOS and Android builds. There are two ways to opt out:

- **Editor toggle** (interactive): select **OneSignal > Disable Location Module** in the Unity Editor before resolving Android dependencies or building iOS. This is persisted per project in `ProjectSettings/OneSignalSettings.json`.
- **Environment variable** (CLI/CI): set `ONESIGNAL_DISABLE_LOCATION=true` (or `1`) in the environment before launching Unity, for example:

```sh
ONESIGNAL_DISABLE_LOCATION=true /path/to/Unity -batchmode -quit -projectPath . -buildTarget iOS -executeMethod BuildScript.BuildiOSSimulator
```

When set, the environment variable takes precedence over the Editor toggle, so headless builds can opt out without changing project settings.

With the location module disabled, Android resolves OneSignal's native modules without the location artifact and iOS uses OneSignal pods without `OneSignalLocation`. `OneSignal.Location.RequestPermission()` and `OneSignal.Location.IsShared = ...` no-op on native builds without the location module, and `OneSignal.Location.IsShared` returns `false`.

When toggling the flag, clear stale native outputs (the generated Xcode project, CocoaPods/Gradle caches, and prior `Build/` artifacts) so a previously linked location module isn't reused.

## Usage
You can find a complete implementation in our included [example MonoBehaviour](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleBehaviour.cs). Additionally we have included a
[sample scene](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleScene.unity) which you can run to test out the SDK.
Expand Down
103 changes: 103 additions & 0 deletions com.onesignal.unity.android/Editor/OneSignalAndroidDependencies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Modified MIT License
*
* Copyright 2023 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using UnityEditor;
using UnityDebug = UnityEngine.Debug;

namespace OneSignalSDK
{
[InitializeOnLoad]
internal static class OneSignalAndroidDependencies
{
static OneSignalAndroidDependencies()
{
OneSignalSDKSettings.Changed += WriteDependencies;
WriteDependencies();
}

internal static void WriteDependencies()
{
var contents = OneSignalSDKSettings.EffectiveDisableLocation
? DisabledLocationDependencies
: DefaultDependencies;

try
{
if (
File.Exists(_dependenciesPath)
&& File.ReadAllText(_dependenciesPath) == contents
)
return;

Directory.CreateDirectory(Path.GetDirectoryName(_dependenciesPath));
File.WriteAllText(_dependenciesPath, contents);
AssetDatabase.ImportAsset(_dependenciesPath);
}
catch (Exception exception)
{
UnityDebug.LogWarning(
$"Could not update OneSignal Android dependencies at {_dependenciesPath}: {exception.Message}"
);
}
}

internal const string Version = "5.9.5";

private static readonly string _dependenciesPath = Path.Combine(
"Assets",
"OneSignal",
"Editor",
"OneSignalAndroidDependencies.xml"
);

private static string DefaultDependencies =>
$@"<dependencies>
<androidPackages>
<repositories>
<repository>https://repo.maven.apache.org/maven2</repository>
</repositories>
<androidPackage spec=""com.onesignal:OneSignal:{Version}"" />
</androidPackages>
</dependencies>
";

private static string DisabledLocationDependencies =>
$@"<dependencies>
<androidPackages>
<repositories>
<repository>https://repo.maven.apache.org/maven2</repository>
</repositories>
<androidPackage spec=""com.onesignal:core:{Version}"" />
<androidPackage spec=""com.onesignal:notifications:{Version}"" />
<androidPackage spec=""com.onesignal:in-app-messages:{Version}"" />
</androidPackages>
</dependencies>
";
}
}

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

52 changes: 46 additions & 6 deletions com.onesignal.unity.android/Runtime/AndroidLocationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,72 @@
* THE SOFTWARE.
*/

using System.Threading.Tasks;
using System;
using OneSignalSDK.Android.Utilities;
using OneSignalSDK.Debug.Utilities;
using OneSignalSDK.Location;
using UnityEngine;

namespace OneSignalSDK.Android.Location
{
internal sealed class AndroidLocationManager : ILocationManager
{
private const string LocationModuleNotAvailable =
"OneSignal location module is not available. Add the location dependency to use OneSignal.Location.";

private readonly AndroidJavaObject _location;

public AndroidLocationManager(AndroidJavaClass sdkClass)
{
_location = sdkClass.CallStatic<AndroidJavaObject>("getLocation");
try
{
_location = sdkClass.CallStatic<AndroidJavaObject>("getLocation");
}
catch (Exception)
{
SDKDebug.Error(LocationModuleNotAvailable);
}
}

public bool IsShared
{
get => _location.Call<bool>("isShared");
set => _location.Call("setShared", value);
get
{
try
{
return _location != null && _location.Call<bool>("isShared");
}
catch (Exception)
{
SDKDebug.Error(LocationModuleNotAvailable);
return false;
}
}
set
{
try
{
if (_location != null)
_location.Call("setShared", value);
}
catch (Exception)
{
SDKDebug.Error(LocationModuleNotAvailable);
}
}
}

Check warning on line 81 in com.onesignal.unity.android/Runtime/AndroidLocationManager.cs

View check run for this annotation

Claude / Claude Code Review

AndroidLocationManager IsShared silently no-ops without logging

On Android, when the native location module is missing, `IsShared` getter/setter silently no-op without logging because the `_location != null` short-circuit skips the try-block before `SDKDebug.Error` can fire. This is inconsistent with `RequestPermission` in the same file (which always logs via the caught NRE) and with the iOS bridge in `OneSignalUnityBridgeLocation.mm` (which logs on every call). Suggest dropping the null guards (let the NRE catch and log, matching `RequestPermission`) or add
Comment on lines 55 to 81

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 On Android, when the native location module is missing, IsShared getter/setter silently no-op without logging because the _location != null short-circuit skips the try-block before SDKDebug.Error can fire. This is inconsistent with RequestPermission in the same file (which always logs via the caught NRE) and with the iOS bridge in OneSignalUnityBridgeLocation.mm (which logs on every call). Suggest dropping the null guards (let the NRE catch and log, matching RequestPermission) or adding an explicit if (_location == null) { SDKDebug.Error(LocationModuleNotAvailable); ... } branch in each accessor.

Extended reasoning...

Bug: In com.onesignal.unity.android/Runtime/AndroidLocationManager.cs the constructor catches the missing-module exception from sdkClass.CallStatic<AndroidJavaObject>("getLocation"), logs LocationModuleNotAvailable once, and leaves _location = null. After that, the IsShared accessors are guarded with a null short-circuit:

  • Getter (line 61): return _location != null && _location.Call<bool>("isShared"); — when _location == null, C# short-circuits the && and returns false without entering the try body, so SDKDebug.Error is never invoked.
  • Setter (lines 73-74): if (_location != null) _location.Call("setShared", value); — same short-circuit; nothing is logged.
  • RequestPermission (line 88): unconditionally dereferences _location.Call(...), so a null _location throws a NullReferenceException that the catch block converts into SDKDebug.Error(LocationModuleNotAvailable) on every call.

Why existing code doesn't prevent it: the try/catch around each accessor only catches the JNI exception that would come from a real Call(...) on a non-null _location. The null guard added in this PR sits outside that path, so no exception is ever thrown for the null branch and the diagnostic log added in the same change is unreachable for the IsShared accessors.

Impact: the PR description says it 'logs SDK-level errors when location APIs are called without the native location module', and the iOS bridge (OneSignalUnityBridgeLocation.mm) enforces that contract by logging OneSignalLocationModuleNotFoundMessage on every _oneSignalLocationGetIsShared, _oneSignalLocationSetIsShared, and _oneSignalLocationRequestPermission call via the ONESIGNAL_DISABLE_LOCATION macro. On Android, RequestPermission matches that contract but the IsShared accessors are silent for every call after construction. A developer toggling off the module and trying to debug why OneSignal.Location.IsShared = true had no effect on Android would see only the one boot-time error, while the iOS counterpart would emit an API-call-site error each time. This is a cross-platform diagnostic divergence rather than a functional break — the no-op + false return value documented in the README still holds.

Step-by-step proof: consider the no-location demo (which this PR adds) with disableLocation = true. (1) AndroidOneSignal.Initialize constructs AndroidLocationManager. (2) sdkClass.CallStatic<AndroidJavaObject>("getLocation") throws because the com.onesignal:location module is absent; the constructor's catch logs once. (3) The app reads OneSignal.Location.IsShared once per frame to display state. (4) Each call enters the getter, evaluates _location != null to false, short-circuits, returns false. No Call is made, no exception, the catch block is dead code for this path. (5) On iOS, the same loop hits _oneSignalLocationGetIsShared, which goes through #if ONESIGNAL_DISABLE_LOCATION and logs every frame. Result: same code path, divergent diagnostic output.

Addressing the refutation: the refuter is right that (a) the constructor already logs once, (b) the README documents the no-op contract, and (c) logging every frame can be argued as spam. Those are fair points — which is why this is filed as a nit, not normal severity. But the PR's own description and the iOS implementation set the precedent that each API call without the module produces a log, and RequestPermission in this same file already honors that contract via the NRE catch. The Android IsShared accessors are the only callers that diverge. If log-once-at-boot is the intended contract, the iOS bridge and RequestPermission should be updated to match; otherwise IsShared should follow them. Either resolution works — the current state where three of four call sites log and one doesn't is the issue.

Fix: remove the null short-circuit so the NRE path catches and logs (matching RequestPermission), or add an explicit early-return:

get {
    if (_location == null) {
        SDKDebug.Error(LocationModuleNotAvailable);
        return false;
    }
    try { return _location.Call<bool>("isShared"); }
    catch (Exception) { SDKDebug.Error(LocationModuleNotAvailable); return false; }
}


public void RequestPermission()
{
var continuation = new BoolContinuation();
_location.Call<AndroidJavaObject>("requestPermission", continuation.Proxy);
try
{
var continuation = new BoolContinuation();
_location.Call<AndroidJavaObject>("requestPermission", continuation.Proxy);
}
catch (Exception)
{
SDKDebug.Error(LocationModuleNotAvailable);
}
}
}
}
125 changes: 125 additions & 0 deletions com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Modified MIT License
*
* Copyright 2023 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace OneSignalSDK
{
public static class OneSignalSDKSettings
{
public const string DisableLocationEnvVar = "ONESIGNAL_DISABLE_LOCATION";

public static event Action Changed;

public static bool DisableLocation
{
get => _settings.disableLocation;
set
{
if (_settings.disableLocation == value)
return;

_settings.disableLocation = value;
Save();
Changed?.Invoke();
AssetDatabase.Refresh();
}
}

/// <summary>
/// Resolved value used by the build pipeline. The <see cref="DisableLocationEnvVar"/>
/// environment variable, when present, overrides the persisted Editor setting so CLI
/// and CI builds can opt out without mutating project settings.
/// </summary>
public static bool EffectiveDisableLocation
{
get
{
var environmentValue = Environment.GetEnvironmentVariable(DisableLocationEnvVar);
if (!string.IsNullOrEmpty(environmentValue))
{
var normalized = environmentValue.Trim();
return normalized.Equals("true", StringComparison.OrdinalIgnoreCase)
|| normalized == "1";
}

return _settings.disableLocation;
}
}

public static void Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(_settingsPath));
File.WriteAllText(_settingsPath, JsonUtility.ToJson(_settings, true));
}

[MenuItem("OneSignal/Disable Location Module")]
private static void ToggleDisableLocation()
{
DisableLocation = !DisableLocation;
}

[MenuItem("OneSignal/Disable Location Module", true)]
private static bool ToggleDisableLocationValidate()
{
Menu.SetChecked("OneSignal/Disable Location Module", DisableLocation);
return true;
}

private static readonly string _settingsPath = Path.Combine(
"ProjectSettings",
"OneSignalSettings.json"
);

private static Settings _settings = Load();

private static Settings Load()
{
if (!File.Exists(_settingsPath))
return new Settings();

try
{
return JsonUtility.FromJson<Settings>(File.ReadAllText(_settingsPath))
?? new Settings();
}
catch
{
return new Settings();
}
}

[Serializable]
private sealed class Settings
{
public bool disableLocation;
}
}
}
11 changes: 11 additions & 0 deletions com.onesignal.unity.core/Editor/OneSignalSDKSettings.cs.meta

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

Loading