private static @Nullable AdvertisingIdClientInfo resolveAdvertisingIdClientInfo(Context context) { try { Invocation advertisingIdClient = Invocation.fromClass(CLASS_ADVERTISING_ID_CLIENT); Object infoObject = advertisingIdClient.invokeMethod(METHOD_GET_ADVERTISING_ID_INFO, new Class<?>[] { Context.class }, new Object[] { context }); if (infoObject == null) { ApptentiveLog.w("Unable to resolve advertising ID: '%s' did not return a valid value", METHOD_GET_ADVERTISING_ID_INFO); return null; } Invocation info = Invocation.fromObject(infoObject); String id = info.invokeStringMethod(METHOD_GET_ID); boolean limitAdTrackingEnabled = info.invokeBooleanMethod(METHOD_IS_LIMIT_AD_TRACKING_ENABLED); return new AdvertisingIdClientInfo(id, limitAdTrackingEnabled); } catch (Exception e) { Throwable cause = e.getCause(); if (cause != null) { if (StringUtils.equal(cause.getClass().getSimpleName(), "GooglePlayServicesNotAvailableException")) { ApptentiveLog.e(e, "Unable to resolve advertising ID: Google Play is not installed on this device"); return null; } if (StringUtils.equal(cause.getClass().getSimpleName(), "GooglePlayServicesRepairableException")) { ApptentiveLog.e(e, "Unable to resolve advertising ID: error connecting to Google Play Services"); return null; } } ApptentiveLog.e(e, "Unable to resolve advertising ID"); logException(e); return null; } }
if (configuration.isCollectingAdID()) { AdvertiserManager.AdvertisingIdClientInfo info = AdvertiserManager.getAdvertisingIdClientInfo(); if (info != null && !info.isLimitAdTrackingEnabled()) { device.setAdvertiserId(info.getId()); } else { ApptentiveLog.w("Advertising ID tracking is not available or limited");
/** * Returns true if changed */ public static synchronized boolean updateAdvertisingIdClientInfo(Context context) { ApptentiveLog.v(ADVERTISER_ID, "Updating advertiser ID client info..."); AdvertisingIdClientInfo clientInfo = resolveAdvertisingIdClientInfo(context); if (clientInfo != null && clientInfo.equals(cachedClientInfo)) { return false; // no changes } ApptentiveLog.v(ADVERTISER_ID, "Advertiser ID client info changed: %s", clientInfo); cachedClientInfo = clientInfo; notifyClientInfoChanged(cachedClientInfo); return true; }
private void updateConversationAdvertiserIdentifier(Conversation conversation) { checkConversationQueue(); try { Configuration config = Configuration.load(); if (config.isCollectingAdID()) { AdvertisingIdClientInfo info = AdvertiserManager.getAdvertisingIdClientInfo(); String advertiserId = info != null && !info.isLimitAdTrackingEnabled() ? info.getId() : null; conversation.getDevice().setAdvertiserId(advertiserId); } } catch (Exception e) { ApptentiveLog.e(ADVERTISER_ID, e, "Exception while updating conversation advertiser id"); logException(e); } }