Source:
public void onTokenRefresh() { SharedPreferences sharedPreferences = sharedPreferencesProvider.get(this); Map<String, ?> preferences = sharedPreferences.getAll(); for (Map.Entry<String, ?> preference : preferences.entrySet()) { if (preference.getKey().matches(REGISTRAR_PREFERENCE_PATTERN)) { String senderId = preference.getKey().split(":")[1]; InstanceID instanceID = instanceIdProvider.get(this); try { String regid = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE); JsonObject oldPostData = new JsonParser().parse(preference.getValue().toString()).getAsJsonObject(); URL deviceRegistryURL = new URL(oldPostData.get("deviceRegistryURL").getAsString()); String variantId = oldPostData.get("variantId").getAsString(); String secret = oldPostData.get("secret").getAsString(); HttpProvider httpProvider = httpProviderProvider.get(deviceRegistryURL, TIMEOUT); setPasswordAuthentication(variantId, secret, httpProvider); JsonObject postData = new JsonObject(); if (oldPostData.has("deviceType")&& !oldPostData.get("deviceType").isJsonNull()) { postData.addProperty("deviceType", oldPostData.get("deviceType").getAsString()); } postData.addProperty("deviceToken", regid); if (oldPostData.has("alias") && !oldPostData.get("alias").isJsonNull()) { postData.addProperty("alias", oldPostData.get("alias").getAsString()); } if (oldPostData.has("operatingSystem")&& !oldPostData.get("operatingSystem").isJsonNull()) { postData.addProperty("operatingSystem", oldPostData.get("operatingSystem").getAsString()); } if (oldPostData.has("osVersion")&& !oldPostData.get("osVersion").isJsonNull()) { postData.addProperty("osVersion", oldPostData.get("osVersion").getAsString()); } if (oldPostData.has("categories")&& !oldPostData.get("categories").isJsonNull()) { postData.add("categories", oldPostData.get("categories").getAsJsonArray()); } httpProvider.post(postData.toString()); } catch (IOException ex) { Log.e(TAG, ex.getMessage(), ex); } } } }

Target:
public void onTokenRefresh() { SharedPreferences sharedPreferences = sharedPreferencesProvider.get(this); Map<String, ?> preferences = sharedPreferences.getAll(); for (Map.Entry<String, ?> preference : preferences.entrySet()) { if (preference.getKey().matches(REGISTRAR_PREFERENCE_PATTERN)) { String senderId = preference.getKey().split(":")[1]; InstanceID instanceID = instanceIdProvider.get(this); try { String token = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE); JsonObject oldPostData = new JsonParser().parse(preference.getValue().toString()).getAsJsonObject(); URL deviceRegistryURL = new URL(oldPostData.get("deviceRegistryURL").getAsString()); String variantId = oldPostData.get("variantId").getAsString(); String secret = oldPostData.get("secret").getAsString(); HttpProvider httpProvider = httpProviderProvider.get(deviceRegistryURL, TIMEOUT); setPasswordAuthentication(variantId, secret, httpProvider); JsonObject postData = new JsonObject(); if (oldPostData.has("deviceType")&& !oldPostData.get("deviceType").isJsonNull()) { postData.addProperty("deviceType", oldPostData.get("deviceType").getAsString()); } postData.addProperty("deviceToken", token); if (oldPostData.has("alias") && !oldPostData.get("alias").isJsonNull()) { postData.addProperty("alias", oldPostData.get("alias").getAsString()); } if (oldPostData.has("operatingSystem")&& !oldPostData.get("operatingSystem").isJsonNull()) { postData.addProperty("operatingSystem", oldPostData.get("operatingSystem").getAsString()); } if (oldPostData.has("osVersion")&& !oldPostData.get("osVersion").isJsonNull()) { postData.addProperty("osVersion", oldPostData.get("osVersion").getAsString()); } if (oldPostData.has("categories")&& !oldPostData.get("categories").isJsonNull()) { postData.add("categories", oldPostData.get("categories").getAsJsonArray()); } httpProvider.post(postData.toString()); } catch (IOException ex) { Log.e(TAG, ex.getMessage(), ex); } } } }