package com.glu.plugins.gluanalytics; import android.os.SystemClock; import android.text.TextUtils; import com.glu.plugins.gluanalytics.network.NetworkResponse; import com.glu.plugins.gluanalytics.network.NetworkUtils; import com.glu.plugins.gluanalytics.util.CollectionUtil; import com.glu.plugins.gluanalytics.util.YLogger; import com.ironsource.nb; import java.net.URL; import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; /* loaded from: classes2.dex */ public class CacheService { private String mBundleId; private long mCacheServiceTimeout; private Map mHeaders; private String mLastGameName; private String mLastRevId; private String mLastS; private long mLastSentTime; private String mLastSessId; private String mLastUid; private URL mUrl; private final YLogger mLog = YLogger.create(getClass()); private ScheduledExecutorService mExecutor = Executors.newSingleThreadScheduledExecutor(); public CacheService(String str, String str2, long j) { this.mBundleId = str; try { this.mUrl = new URL(str2); } catch (Exception e) { this.mLog.i("CacheService", "URL", e.getMessage()); } Map createMap = CollectionUtil.createMap(); this.mHeaders = createMap; createMap.put("Content-Type", nb.L); this.mLastSentTime = -1L; this.mCacheServiceTimeout = j; scheduleUpdate(); } public void destroy() { this.mExecutor.shutdownNow(); } public void putData(final String str, final String str2, final String str3, final String str4, final String str5, String str6) { try { this.mExecutor.execute(new Runnable() { // from class: com.glu.plugins.gluanalytics.CacheService.1 @Override // java.lang.Runnable public void run() { CacheService.this.doPutData(str, str2, str3, str4, str5); } }); } catch (Exception e) { this.mLog.i("CacheService", "Exception", e.getMessage()); } } private void scheduleUpdate() { try { this.mExecutor.scheduleAtFixedRate(new Runnable() { // from class: com.glu.plugins.gluanalytics.CacheService.2 @Override // java.lang.Runnable public void run() { CacheService cacheService = CacheService.this; cacheService.doPutData(cacheService.mLastS, CacheService.this.mLastGameName, CacheService.this.mLastUid, CacheService.this.mLastRevId, CacheService.this.mLastSessId); } }, 1L, 1L, TimeUnit.MINUTES); } catch (Exception e) { this.mLog.i("CacheService", "Exception", e.getMessage()); } } /* JADX INFO: Access modifiers changed from: private */ public void doPutData(String str, String str2, String str3, String str4, String str5) { if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || TextUtils.isEmpty(str3) || TextUtils.isEmpty(str4) || TextUtils.isEmpty(str5)) { this.mLog.i("CacheService", "Ignore", String.format("s=%s, game_name=%s, uid=%s, rev_id=%s, sess_id=%s, bundle_id=%s", str, str2, str3, str4, str5, this.mBundleId)); return; } if (!str.equals(this.mLastS) || !str2.equals(this.mLastGameName) || !str3.equals(this.mLastUid) || !str4.equals(this.mLastRevId) || !str5.equals(this.mLastSessId)) { this.mLastS = str; this.mLastGameName = str2; this.mLastUid = str3; this.mLastRevId = str4; this.mLastSessId = str5; this.mLastSentTime = -1L; } sendPutRequset(str, str2, str3, str4, str5); } private void sendPutRequset(String str, String str2, String str3, String str4, String str5) { long elapsedRealtime = SystemClock.elapsedRealtime() / 1000; long j = this.mLastSentTime; if (j < 0 || elapsedRealtime - j >= this.mCacheServiceTimeout) { String format = String.format("{\"s\":\"%s\",\"game_name\":\"%s\",\"uid\":\"%s\",\"rev_id\":\"%s\",\"sess_id\":\"%s\",\"bundle_id\":\"%s\"}", str, str2, str3, str4, str5, this.mBundleId); this.mLog.i("CacheService", "Data", format); NetworkResponse sendRequest = NetworkUtils.sendRequest("POST", this.mUrl, this.mHeaders, format, 0); Throwable th = sendRequest.throwable; if (th == null) { byte[] bArr = sendRequest.body; this.mLog.i("CacheService", "SendRequest", Integer.valueOf(sendRequest.code), "Body", (bArr != null ? new String(bArr) : "null").replaceAll("\\s", "")); this.mLastSentTime = elapsedRealtime; return; } this.mLog.i("CacheService", "SendRequest", th.getMessage()); return; } this.mLog.i("CacheService", "Ignore", "Not expired"); } }