private void onFetchCurrentLocation(final Location location, final OpenLocateLocationCallback callback) { FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(context, new FetchAdvertisingInfoTaskCallback() { @Override public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info info) { callback.onLocationFetch( OpenLocateLocation.from( location, info, InformationFieldsFactory.collectInformationFields(context, configuration) ) ); } }); task.execute(); }
@SuppressWarnings("unchecked") private void setValues(Intent intent) { endpoints = intent.getParcelableArrayListExtra(Constants.ENDPOINTS_KEY); advertisingInfo = new AdvertisingIdClient.Info( intent.getStringExtra(Constants.ADVERTISING_ID_KEY), intent.getBooleanExtra(Constants.LIMITED_AD_TRACKING_ENABLED_KEY, false) ); setLocationRequestIntervalInSecs(intent); setTransmissionIntervalInSecs(intent); setLocationAccuracy(intent); setFieldsConfiguration(intent); }
/** * Retrieves the advertising ID. Requires Google Play Services. Note: This method must not run on * the main thread. */ private static DeviceIdInfo getAdvertisingId(Context caller) throws Exception { try { AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(caller); if (info != null) { String advertisingId = info.getId(); String deviceId = checkDeviceId("advertising id", advertisingId); if (deviceId != null) { boolean limitedTracking = info.isLimitAdTrackingEnabled(); return new DeviceIdInfo(deviceId, limitedTracking); } } } catch (Throwable t) { Log.e("Error getting advertising ID. Google Play Services are not available: ", t); } return null; }
private void setAdvertisingIdClient() { new Thread(new Runnable() { @Override public void run() { String aaid = ""; if (AptoideUtils.GoogleServices.checkGooglePlayServices(context)) { try { aaid = AdvertisingIdClient.getAdvertisingIdInfo(Aptoide.this).getId(); } catch (Exception e) { e.printStackTrace(); } } else { byte[] data = new byte[16]; String deviceId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); SecureRandom secureRandom = new SecureRandom(); secureRandom.setSeed(deviceId.hashCode()); secureRandom.nextBytes(data); aaid = UUID.nameUUIDFromBytes(data).toString(); } AptoideUtils.getSharedPreferences().edit().putString("advertisingIdClient", aaid).apply(); } }).start(); }
@NonNull private Observable<String> getAdIdFromGoogleObservable() { return Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<? super String> subscriber) { try { subscriber.onNext(AdvertisingIdClient.getAdvertisingIdInfo(context).getId()); } catch (Exception e) { Timber.e(e, "Error getting google Advertising ID!"); String diskValue = valueManager.getAdId(); if (null == diskValue || diskValue.isEmpty()) subscriber.onError(e); else subscriber.onNext(diskValue); } } }) .doOnNext(adId -> this.adId = adId) .doOnNext(adId -> valueManager.setAdId(adId)) .subscribeOn(scheduler.backgroundThread()) .observeOn(scheduler.mainThread()); }
@NonNull private Observable<Boolean> getAdIdEnabledFromGoogleObservable() { return Observable.create(new Observable.OnSubscribe<Boolean>() { @Override public void call(Subscriber<? super Boolean> subscriber) { try { subscriber.onNext(AdvertisingIdClient.getAdvertisingIdInfo(context).isLimitAdTrackingEnabled()); } catch (Exception e) { Timber.e(e, "Error getting google Tracking Enabled!"); Boolean diskValue = valueManager.getAdIdEnabled(); if (null == diskValue) subscriber.onError(e); else subscriber.onNext(diskValue); } } }) .doOnNext(adIdEnabled -> this.adIdEnabled = adIdEnabled) .doOnNext(adIdEnabled -> valueManager.setAdIdEnabled(adIdEnabled)) .subscribeOn(scheduler.backgroundThread()) .observeOn(scheduler.mainThread()); }
final Pair<String, Boolean> zzCw() { checkOnWorkerThread(); long l = getClock().elapsedRealtime(); if ((this.zzbnx != null) && (l < this.zzbnz)) { return new Pair(this.zzbnx, Boolean.valueOf(this.zzbny)); } this.zzbnz = (l + zzc.zzBG()); AdvertisingIdClient.setShouldSkipGmsCoreVersionCheck(true); try { AdvertisingIdClient.Info localInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); this.zzbnx = localInfo.zzpp; this.zzbny = localInfo.zzpq; AdvertisingIdClient.setShouldSkipGmsCoreVersionCheck(false); return new Pair(this.zzbnx, Boolean.valueOf(this.zzbny)); } catch (Throwable localThrowable) { for (;;) { zzBh().zzbnd.zzm("Unable to get advertising id", localThrowable); this.zzbnx = ""; } } }
@Override public LinkedHashMap<String, String> getDumpMap(Context context) throws DumpException { LinkedHashMap<String, String> dumps = new LinkedHashMap<>(); dumps.put(Settings.Secure.ANDROID_ID, getAndroidId(context)); dumps.put("UUID", getUUID()); String adIdKey = "AdvertisingId"; String adOptoutKey = "isAdOptout"; AdvertisingIdClient.Info adInfo = getAdInfo(context); if (adInfo == null) { dumps.put(adIdKey, "Getting AdvertisingId need a android.permission.INTERNET"); dumps.put(adOptoutKey, "Getting AdvertisingId need a android.permission.INTERNET"); } else { dumps.put(adIdKey, adInfo.getId()); dumps.put(adOptoutKey, Boolean.toString(adInfo.isLimitAdTrackingEnabled())); } return dumps; }
public void updateAdvertisingId() { new Thread(new Runnable() { @Override public void run() { AdvertisingIdClient.Info adInfo = null; try { adInfo = AdvertisingIdClient.getAdvertisingIdInfo(TweetingActivity.this); } catch (IOException | GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException exception) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } if (adInfo != null) { mAdversitingId = adInfo.getId(); } } }); }
OpenLocateLocation( Location location, AdvertisingIdClient.Info advertisingInfo, InformationFields informationFields) { this.location = new LocationInfo(location); this.advertisingInfo = advertisingInfo; this.informationFields = informationFields; this.created = new Date(); }
void onPermissionsGranted() { FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(context, new FetchAdvertisingInfoTaskCallback() { @Override public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info info) { onFetchAdvertisingInfo(info); } }); task.execute(); }
private void onFetchAdvertisingInfo(AdvertisingIdClient.Info info) { Intent intent = new Intent(context, LocationService.class); intent.putParcelableArrayListExtra(Constants.ENDPOINTS_KEY, endpoints); updateLocationConfigurationInfo(intent); updateFieldsConfigurationInfo(intent); if (info != null) { updateAdvertisingInfo(intent, info.getId(), info.isLimitAdTrackingEnabled()); } context.startService(intent); setStartedPreferences(); }
@Override protected Void doInBackground(Void... params) { try { info = AdvertisingIdClient.getAdvertisingIdInfo(context); } catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { Log.e(TAG, e.getMessage()); } return null; }
@Test public void testFetchAdvertisingInfoTask() { // Given final Object syncObject = new Object(); FetchAdvertisingInfoTaskCallback callback = new FetchAdvertisingInfoTaskCallback() { @Override public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info advertisingInfo) { assertNotNull(advertisingInfo); synchronized (syncObject) { syncObject.notify(); } } }; FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(InstrumentationRegistry.getTargetContext(), callback); // When task.execute(); // Then synchronized (syncObject) { try { syncObject.wait(); } catch (InterruptedException e) { assertTrue(false); } } }
@Test public void testOpenLocateConstructor() { // Given double lat = 10.40; double lng = 10.234; double accuracy = 40.43; boolean adOptOut = true; String adId = "1234"; Location location = new Location(""); location.setLatitude(lat); location.setLongitude(lng); location.setAccuracy((float) accuracy); AdvertisingIdClient.Info info = new AdvertisingIdClient.Info(adId, adOptOut); OpenLocateLocation openLocateLocation = new OpenLocateLocation(location, info, null); // When JSONObject json = openLocateLocation.getJson(); // Then assertNotNull(openLocateLocation); try { assertEquals(json.getDouble(OpenLocateLocation.Keys.LATITUDE), lat, 0.0d); assertEquals(json.getDouble(OpenLocateLocation.Keys.LONGITUDE), lng, 0.0d); assertEquals(json.getDouble(OpenLocateLocation.Keys.HORIZONTAL_ACCURACY), accuracy, 0.1); assertEquals(json.getBoolean(OpenLocateLocation.Keys.AD_OPT_OUT), adOptOut); assertEquals(json.getString(OpenLocateLocation.Keys.AD_ID), adId); } catch (JSONException e) { e.printStackTrace(); } }
private Info n() { Info info = null; try { info = AdvertisingIdClient.getAdvertisingIdInfo(hn.a().c()); } catch (Exception e) { ib.b(a, "GOOGLE PLAY SERVICES ERROR: " + e.getMessage()); ib.b(a, "There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising."); } return info; }
private static String replaceAdvertisementId(String clickUrl, Context context) throws IOException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException { String aaId = ""; if (GoogleServices.checkGooglePlayServices(context)) { if (AptoideUtils.getSharedPreferences().contains("advertisingIdClient")) { aaId = AptoideUtils.getSharedPreferences().getString("advertisingIdClient", ""); } else { try { aaId = AdvertisingIdClient.getAdvertisingIdInfo(context).getId(); } catch (Exception e) { // In case we try to do this from a Broadcast Receiver, exception will be thrown. Logger.w("AptoideUtils", e.getMessage()); } } } else { byte[] data = new byte[16]; String deviceId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); SecureRandom secureRandom = new SecureRandom(); secureRandom.setSeed(deviceId.hashCode()); secureRandom.nextBytes(data); aaId = UUID.nameUUIDFromBytes(data).toString(); } clickUrl = clickUrl.replace("[USER_AAID]", aaId); return clickUrl; }
private String getAdvertisementId() { try { return AdvertisingIdClient.getAdvertisingIdInfo(Aptoide.getContext()).getId(); } catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { Logger.printException(e); } return null; }
@Override protected String doInBackground(Void... params) { try { AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(mContext); success = true; return info.getId(); } catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { e.printStackTrace(); success = false; return e.getMessage(); } }
@WorkerThread public synchronized String getGoogleAdvertisingId() { String googleAdvertisingId = sharedPreferences.getString(GOOGLE_ADVERTISING_ID_CLIENT, null); if (!TextUtils.isEmpty(googleAdvertisingId)) { return googleAdvertisingId; } if (AptoideUtils.ThreadU.isUiThread()) { throw new IllegalStateException("You cannot run this method from the main thread"); } if (AdNetworkUtils.isGooglePlayServicesAvailable(context)) { try { googleAdvertisingId = AdvertisingIdClient.getAdvertisingIdInfo(context) .getId(); } catch (Exception e) { CrashReport.getInstance() .log(e); } } sharedPreferences.edit() .putString(GOOGLE_ADVERTISING_ID_CLIENT, googleAdvertisingId) .apply(); sharedPreferences.edit() .putBoolean(GOOGLE_ADVERTISING_ID_CLIENT_SET, true) .apply(); return googleAdvertisingId; }
/** * Provides the <a href="https://support.google.com/googleplay/android-developer/answer/6048248?hl=en">Google Advertising Identifier (GAID)</a> * <strong>This method cannot be called in the main thread, as it might block the thread leading to ANRs. * An IllegalStateException will be thrown if this is called on the main thread.</strong> * @return user identifier as provided by Google Play Services */ public String getUserIdentifier() { String value = "unknown"; try { String googleAdId = AdvertisingIdClient.getAdvertisingIdInfo(appContext).getId(); if(googleAdId != null) { value = googleAdId; } }catch(Exception e) { Logger.debug(e); } return value; }
private zza zzZ() throws IOException { try { if (!zznX.await(2L, TimeUnit.SECONDS)) { zza localzza1 = new zza(null, false); return localzza1; } } catch (InterruptedException localInterruptedException) { return new zza(null, false); } try { if (zznW == null) { zza localzza2 = new zza(null, false); return localzza2; } } finally {} AdvertisingIdClient.Info localInfo = zznW.getInfo(); return new zza(zzk(localInfo.zzpp), localInfo.zzpq); }
a f(Context paramContext) { AdvertisingIdClient.Info localInfo; try { localInfo = AdvertisingIdClient.getAdvertisingIdInfo(paramContext); } catch (GooglePlayServicesRepairableException localGooglePlayServicesRepairableException) { throw new IOException(localGooglePlayServicesRepairableException); } String str1 = localInfo.getId(); String str2 = str1; if ((str1 != null) && (str2.matches("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"))) { byte[] arrayOfByte = new byte[16]; int i = 0; for (int j = 0; j < str2.length(); j += 2) { if ((j == 8) || (j == 13) || (j == 18) || (j == 23)) j++; arrayOfByte[i] = ((byte)((Character.digit(str2.charAt(j), 16) << 4) + Character.digit(str2.charAt(j + 1), 16))); i++; } str2 = this.dw.a(arrayOfByte, true); } return new a(str2, localInfo.isLimitAdTrackingEnabled()); }
public static Future<Boolean> getTrackingEnabled() { FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { public Boolean call() throws Exception { try { Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(Growthbeat.getInstance().getContext()); return !adInfo.isLimitAdTrackingEnabled(); } catch (Throwable e) { return null; } } }); Growthbeat.getInstance().getExecutor().execute(future); return future; }
public static Future<String> getAdvertisingId() { FutureTask<String> future = new FutureTask<String>(new Callable<String>() { public String call() throws Exception { try { Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(Growthbeat.getInstance().getContext()); return adInfo.getId(); } catch (Throwable e) { return null; } } }); Growthbeat.getInstance().getExecutor().execute(future); return future; }
@Override protected String doInBackground(Void... voids) { String result = null; try { result = AdvertisingIdClient.getAdvertisingIdInfo(mContext).getId(); } catch (Exception e) { Timber.e(e); } return result; }
public AdvertisingIdClient.Info getAdvertisingInfo() { return advertisingInfo; }
public void setAdvertisingInfo(AdvertisingIdClient.Info advertisingInfo) { this.advertisingInfo = advertisingInfo; }
public static OpenLocateLocation from(Location location, AdvertisingIdClient.Info advertisingInfo, InformationFields informationFields) { return new OpenLocateLocation(location, advertisingInfo, informationFields); }
OpenLocateLocation(Date created, String jsonString) { this.created = created; try { JSONObject json = new JSONObject(jsonString); location = new LocationInfo(); location.setLatitude(json.getDouble(Keys.LATITUDE)); location.setLongitude(json.getDouble(Keys.LONGITUDE)); location.setHorizontalAccuracy(Float.parseFloat(json.getString(Keys.HORIZONTAL_ACCURACY))); location.setTimeStampSecs(json.getLong(Keys.TIMESTAMP)); location.setAltitude(json.getDouble(Keys.ALTITUDE)); location.setCourse(Float.parseFloat(json.getString(Keys.COURSE))); location.setSpeed(Float.parseFloat(json.getString(Keys.SPEED))); String deviceManufacturer = ""; if (json.has(Keys.DEVICE_MANUFACTURER)) { deviceManufacturer = json.getString(Keys.DEVICE_MANUFACTURER); } String deviceModel = ""; if (json.has(Keys.DEVICE_MODEL)) { deviceModel = json.getString(Keys.DEVICE_MODEL); } String chargingState = ""; if (json.has(Keys.IS_CHARGING)) { chargingState = json.getString(Keys.IS_CHARGING); } String operatingSystem = ""; if (json.has(Keys.OPERATING_SYSTEM)) { operatingSystem = json.getString(Keys.OPERATING_SYSTEM); } String carrierName = ""; if (json.has(Keys.CARRIER_NAME)) { carrierName = json.getString(Keys.CARRIER_NAME); } String wifiSSID = ""; if (json.has(Keys.WIFI_SSID)) { wifiSSID = json.getString(Keys.WIFI_SSID); } String wifiBSSID = ""; if (json.has(Keys.WIFI_BSSID)) { wifiBSSID = json.getString(Keys.WIFI_BSSID); } String connectionType = ""; if (json.has(Keys.CONNECTION_TYPE)) { connectionType = json.getString(Keys.CONNECTION_TYPE); } String locationMethod = ""; if (json.has(Keys.LOCATION_METHOD)) { locationMethod = json.getString(Keys.LOCATION_METHOD); } String locationContext = ""; if (json.has(Keys.LOCATION_CONTEXT)) { locationContext = json.getString(Keys.LOCATION_CONTEXT); } informationFields = InformationFieldsFactory.getInformationFields(deviceManufacturer, deviceModel, chargingState, operatingSystem, carrierName, wifiSSID, wifiBSSID, connectionType, locationMethod, locationContext); advertisingInfo = new AdvertisingIdClient.Info( json.getString(Keys.AD_ID), json.getBoolean(Keys.AD_OPT_OUT) ); } catch (JSONException exception) { exception.printStackTrace(); } }
AdvertisingIdClient.Info getAdvertisingInfo() { return advertisingInfo; }
public KomicaAccountManager(Context context) { contextWeakReference = new WeakReference<Context>(context); myAccount = new MyAccount(); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(contextWeakReference.get()); editor = sharedPreferences.edit(); myAccount.setAdId(sharedPreferences.getString(KOMICA_ACCOUNT_AD_ID, null)); myAccount.setFbId(sharedPreferences.getString(KOMICA_ACCOUNT_FB_ID, "")); myAccount.setUsername(sharedPreferences.getString(KOMICA_ACCOUNT_USERNAME, "Guest")); myAccount.setEmail(sharedPreferences.getString(KOMICA_ACCOUNT_EMAIL, "")); myAccount.setHeaderPic(sharedPreferences.getString(KOMICA_ACCOUNT_PHOTO, "")); myAccount.setCoverPic(sharedPreferences.getString(KOMICA_ACCOUNT_COVER, "")); noClearSharedPreferences = contextWeakReference.get().getSharedPreferences("NO_CLEAR", Context.MODE_PRIVATE); KomicaManager.getInstance().enableSwitchLogin(noClearSharedPreferences.getBoolean(PREFERENCE_SWITCH_LOGIN, false)); handlerThread.start(); handler = new Handler(handlerThread.getLooper()) { @Override public void handleMessage(Message msg) { try { String adId = AdvertisingIdClient.getAdvertisingIdInfo(contextWeakReference.get()).getId(); adIdTmp = adId; if (null != myAccount) { myAccount.setAdId(adId); } FirebaseManager.getInstance().updateUserPushData(); } catch (NullPointerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } catch (GooglePlayServicesRepairableException e) { e.printStackTrace(); } finally { handlerThread.quit(); handlerThread.interrupt(); } } }; if (myAccount.getAdId() != null) { KLog.v(TAG, "Ad Id is not null."); handlerThread.quit(); handlerThread.interrupt(); } else { KLog.v(TAG, "Ad Id is null."); handler.sendEmptyMessage(0); } }
void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info advertisingInfo);