@Override protected void onPostExecute(HTTPResponse httpResponse) { if (this.ignoreResult) { Clog.i(Clog.httpRespLogTag, Clog.getString(R.string.result_cb_ignored)); return; } AdRequester requester = this.requester.get(); if (requester == null) { Clog.w(Clog.httpRespLogTag, Clog.getString(R.string.fire_cb_requester_null)); return; } AdResponse response = null; if ((httpResponse != null) && httpResponse.getSucceeded()) { response = new AdResponse(httpResponse, MediaType.NATIVE); if (extras.containsKey(AdResponse.EXTRAS_KEY_ORIENTATION)) { response.addToExtras( AdResponse.EXTRAS_KEY_ORIENTATION, extras.get(AdResponse.EXTRAS_KEY_ORIENTATION)); } } else { Clog.w(Clog.httpRespLogTag, Clog.getString(R.string.result_cb_bad_response)); } requester.onReceiveResponse(response); }
/* Result CB Code */ @SuppressLint({ "InlinedApi", "NewApi" }) /* suppress AsyncTask.THREAD_POOL_EXECUTOR warning for < HONEYCOMB */ private void fireResultCB(final ResultCode result) { if (hasFailed) return; AdRequester requester = this.adFetcher.get(); // if resultCB is empty don't fire resultCB, and just continue to next ad if ((currentAd == null) || StringUtil.isEmpty(currentAd.getResultCB())) { if (result == ResultCode.SUCCESS) return; Clog.w(Clog.mediationLogTag, Clog.getString(R.string.fire_cb_result_null)); // just making sure if (requester == null) { Clog.e(Clog.httpRespLogTag, Clog.getString(R.string.fire_cb_requester_null)); return; } requester.onReceiveResponse(null); return; } boolean ignoreResult = false; // default is to not ignore if ((requester != null) && (requester.getMediatedAds() != null)) { // ignore resultCB except on the last mediated ad ignoreResult = requester.getMediatedAds().size() > 0; } // ignore resultCB if succeeded already if (result == ResultCode.SUCCESS) { ignoreResult = true; } // fire call to result cb url ResultCBRequest cb = new ResultCBRequest( requester, currentAd.getResultCB(), result, currentAd.getExtras(), ignoreResult, getLatencyParam(), getTotalLatencyParam(requester)); // Spawn GET call if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { cb.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { cb.execute(); } // if currentAd failed and next ad is available, continue to next ad if (ignoreResult && result != ResultCode.SUCCESS) { if (requester != null) { requester.onReceiveResponse(null); } } }
/** * The running total latency of the ad call. * * @return the running total latency, -1 if `latencyStop` not set. */ private long getTotalLatencyParam(AdRequester requester) { if ((requester != null) && (latencyStop > 0)) { return requester.getLatency(latencyStop); } // return -1 if invalid. return -1; }