Source:
<code>public void saveLastId(String id) { logger.log(OneSignal.LOG_LEVEL.DEBUG, "OneSignal OSChannelTracker for: " + getIdTag() + " saveLastId: " + id); if (id == null || id.isEmpty()) return; JSONArray lastChannelObjectReceived = getLastChannelObjectsReceivedByNewId(id); logger.log(OneSignal.LOG_LEVEL.DEBUG, "OneSignal OSChannelTracker for: " + getIdTag() + " saveLastId with lastChannelObjectReceived: " + lastChannelObjectReceived); try { JSONObject newInfluenceId = new JSONObject() .put(getIdTag(), id) .put(TIME, System.currentTimeMillis()); lastChannelObjectReceived.put(newInfluenceId); } catch (JSONException exception) { logger.log(OneSignal.LOG_LEVEL.ERROR, "Generating tracker newInfluenceId JSONObject ", exception); return; } int channelLimit = getChannelLimit(); JSONArray channelObjectToSave = lastChannelObjectReceived; <START> if (lastChannelObjectReceived.length() > channelLimit) { <END> int lengthDifference = lastChannelObjectReceived.length() - channelLimit; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { for (int i = 0; i < lengthDifference; i++) { lastChannelObjectReceived.remove(i); } } else { channelObjectToSave = new JSONArray(); for (int i = lengthDifference; i < lastChannelObjectReceived.length(); i++) { try { channelObjectToSave.put(lastChannelObjectReceived.get(i)); } catch (JSONException exception) { logger.log(OneSignal.LOG_LEVEL.ERROR, "Before KITKAT API, Generating tracker lastChannelObjectReceived get JSONObject ", exception); } } } } logger.log(OneSignal.LOG_LEVEL.DEBUG, "OneSignal OSChannelTracker for: " + getIdTag() + " with channelObjectToSave: " + channelObjectToSave); saveChannelObjects(channelObjectToSave); }</code><technical_language>Remove this Build.VERSION_CODES.KITKAT implementation in favor of implementation for versions of Android. performance benefits negotiable, prefer a simpler implementation</technical_language>

Target:
public void saveLastId(String id) { logger.debug("OneSignal OSChannelTracker for: " + getIdTag() + " saveLastId: " + id); if (id == null || id.isEmpty()) return; JSONArray lastChannelObjectsReceived = getLastChannelObjectsReceivedByNewId(id); logger.debug("OneSignal OSChannelTracker for: " + getIdTag() + " saveLastId with lastChannelObjectsReceived: " + lastChannelObjectsReceived); try { JSONObject newInfluenceId = new JSONObject() .put(getIdTag(), id) .put(TIME, System.currentTimeMillis()); lastChannelObjectsReceived.put(newInfluenceId); } catch (JSONException exception) { logger.error("Generating tracker newInfluenceId JSONObject ", exception); return; } int channelLimit = getChannelLimit(); JSONArray channelObjectToSave = lastChannelObjectsReceived; if (lastChannelObjectsReceived.length() > channelLimit) { int lengthDifference = lastChannelObjectsReceived.length() - channelLimit; channelObjectToSave = new JSONArray(); for (int i = lengthDifference; i < lastChannelObjectsReceived.length(); i++) { try { channelObjectToSave.put(lastChannelObjectsReceived.get(i)); } catch (JSONException exception) { logger.error("Before KITKAT API, Generating tracker lastChannelObjectsReceived get JSONObject ", exception); } } } logger.debug("OneSignal OSChannelTracker for: " + getIdTag() + " with channelObjectToSave: " + channelObjectToSave); saveChannelObjects(channelObjectToSave); }