tweaselORG / TrackHAR

Library for detecting tracking data transmissions from traffic in HAR format.
Creative Commons Zero v1.0 Universal
7 stars 1 forks source link

Towards #9: Document OneSignal adapter #49

Closed baltpeter closed 1 year ago

baltpeter commented 1 year ago

OneSignal does have an API documentation (archived), but that doesn't cover nearly all the transmitted values we've seen.

But the SDKs are open source (https://github.com/OneSignal/OneSignal-Android-SDK, https://github.com/OneSignal/OneSignal-iOS-SDK) and do fill in some of the missing values.

baltpeter commented 1 year ago

On Android, the android_package property is the app ID. This can be verified by looking at the source code of the OneSignal Android Push Notification Plugin.

Here, the android_package property is set to the value of the variable packageName (source):

deviceInfo.put("android_package", packageName);

This variable is set to the return value of the getPackageName() function on the appContext static property (source):

String packageName = appContext.getPackageName();

The static property appContext is an instance of the android.content.Context class (source 1 and 2):

import android.content.Context;

// […]

static Context appContext;

The getPackageName() function of that class returns the app ID ([source](https://developer.android.com/reference/android/content/Context#getPackageName())).

baltpeter commented 1 year ago

On iOS, the ios_bundle property is the app ID. This can be verified by looking at the source code of the OneSignal iOS SDK.

Here, the ios_bundle property is set to the property iOSBundle of the OSUserState class (source):

if (_iOSBundle)
    dataDic[@"ios_bundle"] = _iOSBundle;

The iOSBundle property is set to the return value of the function call [[NSBundle mainBundle] bundleIdentifier] (source):

userState.iOSBundle = [[NSBundle mainBundle] bundleIdentifier];

[NSBundle mainBundle] is an accessor for getting the current app's bundle (source). And the bundleIdentifier function returns the app ID (source).

baltpeter commented 1 year ago

The sdk property is the SDK version. This can be verified by looking at the source code of the Android and iOS SDKs.

In the OneSignal Android Push Notification Plugin, the sdk property is set to the static value VERSION (source):

deviceInfo.put("sdk", VERSION);

That value holds the SDK version (source):

private static final String VERSION = "040806";
public static String getSdkVersionRaw() {
  return VERSION;
}

In the OneSignal iOS SDK, the sdk property is set to the property sdk of the OSUserState class (source):

NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:
               // […]
               _sdk, @"sdk",
               nil];

This sdk property is set to the ONESIGNAL_VERSION constant (source):

userState.sdk = ONESIGNAL_VERSION;

The ONESIGNAL_VERSION constant holds the SDK version (source):

#define ONESIGNAL_VERSION                                                   @"031207"
baltpeter commented 1 year ago

The carrier property is the carrier of the SIM card inserted into the device. This can be verified by looking at the source code of the Android and iOS SDKs.

In the OneSignal Android Push Notification Plugin, the carrier property is set to the return value of the function call osUtils.getCarrierName() (source):

deviceInfo.put("carrier", osUtils.getCarrierName());

The static osUtils variable is an instance of the TODO class (source 1 and 2):

@NonNull private static OSUtils osUtils = new OSUtils();

The getCarrierName() function in that class uses the getNetworkOperatorName() function of the TelephonyManager class ([documentation](https://developer.android.com/reference/android/telephony/TelephonyManager#getNetworkOperatorName())) to get the carrier name (source):

String getCarrierName() {
  try {
     TelephonyManager manager = (TelephonyManager) OneSignal.appContext.getSystemService(Context.TELEPHONY_SERVICE);
     // May throw even though it's not in noted in the Android docs.
     // Issue #427
     String carrierName = manager.getNetworkOperatorName();
     return "".equals(carrierName) ? null : carrierName;
  } catch(Throwable t) {
     t.printStackTrace();
     return null;
  }
}

In the OneSignal iOS SDK, the carrier property is set to the property carrier of the OSUserState class (source):

if (_carrier)
    dataDic[@"carrier"] = _carrier;

This carrier property is set to the carrierName variable (source):

if (carrierName)
    userState.carrier = carrierName;

The carrierName variable is set to the return value of [[instance valueForKey:@"subscriberCellularProvider"] valueForKey:@"carrierName"], where instance is an instance of CTTelephonyNetworkInfo (source):

let CTTelephonyNetworkInfoClass = NSClassFromString(@"CTTelephonyNetworkInfo");
if (CTTelephonyNetworkInfoClass) {
    id instance = [[CTTelephonyNetworkInfoClass alloc] init];
    let carrierName = (NSString *)[[instance valueForKey:@"subscriberCellularProvider"] valueForKey:@"carrierName"];

    // […]
}

That function call returns the carrier name (documentation 1 and 2).