microsoft / appcenter-sdk-android

Development repository for the App Center SDK for Android
Other
274 stars 135 forks source link

Exclude properties from DeviceInfo #1716

Closed NikolaDespotoski closed 5 months ago

NikolaDespotoski commented 8 months ago

We need to exclude some properties to be legally compliant for anonymous events that might lead to backtracking user.

We want to exclude carrierName and jailbreak flag from the data. Carrier name could lead to backtracking exact user when we have a usecase of exactly one user in particular country.

We looked at ways to pre-process data using WrapperSdk but DeviceInfo is appended after. Is there way to override this property or exclude it?

So far we have tried:

A factory that will override the property.

    private fun overrideLogFactories() {
        val factories = Analytics.getInstance().logFactories!!.entries.copy()
        for (entry in factories) {
            val (type, backingFactory) = entry
            //skip if already replaced since Analytics.getInstance() is singleton
            if (backingFactory is OverrideDeviceInfoEventLogFactory) {
                continue
            }
            Analytics.getInstance().logFactories?.put(
                type,
                OverrideDeviceInfoEventLogFactory(
                    context = context,
                    backingLogFactory = backingFactory
                )
            )
        }
    }

    private class OverrideDeviceInfoEventLogFactory(
        private val context: Context,
        private val backingLogFactory: LogFactory
    ) : LogFactory by backingLogFactory {
        override fun create(): Log {
            val log = backingLogFactory.create()
            val device = log.device ?: DeviceInfoHelper.getDeviceInfo(context)
            val newDevice = device.apply {
                carrierName = null
                carrierCountry = null
            }
            log.device = newDevice
            return log
        }
    }

It is worth to mention that these factories are called when triggerIngestion() is called.

DmitriyKirakosyan commented 7 months ago

Hello @NikolaDespotoski, thank you for getting in touch! Regrettably, we don't have a public API available for modifying or restricting the property carrierName. There is API for changing carrierCountry (ie. countryCode), please check https://learn.microsoft.com/en-us/appcenter/sdk/analytics/android#country-code.

Did your workaround prove successful? If not, one option you might consider is forking the repository and creating a custom version of the SDK that includes the changes you need.

NikolaDespotoski commented 6 months ago

I managed to override the country using setCountryCode() static API, but nothing more than that.

Overriding log factories works, but somehow in the app center local db the device record is still written with country and carrier name, although the object coming from the factories has different Device object.

It would be great if a factory for the Device exist.

Is this on your roadmap? or maybe I can make a PR?

DmitriyKirakosyan commented 6 months ago

We currently do not have this feature on our roadmap. Contributions are welcome, though it's a bit more complex than it appears. We aim for consistent functionality across all SDKs, including those for Apple, .NET, and ReactNative. One approach might be to implement changes in the Android SDK first and monitor feedback before applying similar updates to others. This needs to be discussed within the team. In the meantime, submitting a PR is fine. If you have the time and are willing, your contribution would be appreciated, and we will review it. Even if it isn't merged, you can still utilize the changes in your own fork.