// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.oliodevices.assist.app.controller; import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import com.olio.data.object.analytics.AnalyticsPayload; import com.olio.util.ALog; import com.olio.util.RecoveryTimer; import com.oliodevices.assist.app.api.OlioApi; import com.oliodevices.assist.app.api.UserManager; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; public class WatchAnalytics { private static final int MAX_LINES_PER_REQUEST = 100; private static final int MAX_RETRY_COUNT = 3; private static WatchAnalytics sInstance = null; private static final String sharedKey = "cache_files"; private static final String sharedName = "cache_file_list"; private Context mContext; private Handler mHandler; private HandlerThread mThread; private RecoveryTimer mTimer; private int retryCount; private String tempFileName; public WatchAnalytics() { retryCount = 0; mContext = null; mThread = null; mHandler = null; tempFileName = null; } private void appendPhoneInformationToLogs(AnalyticsPayload analyticspayload) { String s = UserManager.getInstance().getUnitId(); StringBuilder stringbuilder = new StringBuilder(); stringbuilder.append("Android: ").append(Build.MANUFACTURER).append(" ").append(Build.MODEL).append(" (").append(Build.BRAND).append(") ").append(Build.DEVICE).append(":").append(Build.PRODUCT); StringBuilder stringbuilder1 = new StringBuilder(); stringbuilder1.append(android.os.Build.VERSION.RELEASE).append(" (API ").append(android.os.Build.VERSION.SDK_INT).append(") Build ").append(Build.DISPLAY); HashMap hashmap = new HashMap(); String s1; ArrayList arraylist; for (Iterator iterator = analyticspayload.getData().keySet().iterator(); iterator.hasNext(); hashmap.put(s1, arraylist)) { s1 = (String)iterator.next(); Object obj = (List)analyticspayload.getData().get(s1); arraylist = new ArrayList(((List) (obj)).size()); for (obj = ((List) (obj)).iterator(); ((Iterator) (obj)).hasNext(); arraylist.add(String.format("%s,%s,%s,%s,%s", new Object[] { (String)((Iterator) (obj)).next(), s, "1.7.54", stringbuilder.toString(), stringbuilder1.toString() }))) { } } analyticspayload.setData(hashmap); } private void deleteCacheFiles(Set set) { File file = mContext.getCacheDir(); String s; for (set = set.iterator(); set.hasNext(); (new File(file, (new StringBuilder()).append(s).append(".csv").toString())).delete()) { s = (String)set.next(); } } public static WatchAnalytics getInstance() { if (sInstance == null) { sInstance = new WatchAnalytics(); } return sInstance; } private void saveToCache(AnalyticsPayload analyticspayload) { String s1 = UserManager.getInstance().getUnitId(); StringBuilder stringbuilder = new StringBuilder(); stringbuilder.append("Android: ").append(Build.MANUFACTURER).append(" ").append(Build.MODEL).append(" (").append(Build.BRAND).append(") ").append(Build.DEVICE).append(":").append(Build.PRODUCT); StringBuilder stringbuilder1 = new StringBuilder(); stringbuilder1.append(android.os.Build.VERSION.RELEASE).append(" (API ").append(android.os.Build.VERSION.SDK_INT).append(") Build ").append(Build.DISPLAY); SharedPreferences sharedpreferences = mContext.getSharedPreferences("cache_file_list", 0); HashSet hashset = new HashSet(sharedpreferences.getStringSet("cache_files", new HashSet())); String s; String s2; for (Iterator iterator = analyticspayload.getData().keySet().iterator(); iterator.hasNext(); writeToFile((new StringBuilder()).append(s2).append(".csv").toString(), s)) { s2 = (String)iterator.next(); Object obj = (List)analyticspayload.getData().get(s2); s = ""; for (obj = ((List) (obj)).iterator(); ((Iterator) (obj)).hasNext();) { String s3 = (String)((Iterator) (obj)).next(); s = (new StringBuilder()).append(s).append(String.format("%s,%s,%s,%s,%s", new Object[] { s3, s1, "1.7.54", stringbuilder.toString(), stringbuilder1.toString() })).toString(); s = (new StringBuilder()).append(s).append("\n").toString(); } hashset.add(s2); } sharedpreferences.edit().putStringSet("cache_files", hashset).apply(); } private void sendLogToServer() { final File cacheDir; final HashSet keysToDelete; HashMap hashmap; Iterator iterator; int i; ALog.v("sendLogToServer()", new Object[0]); i = 0; cacheDir = mContext.getCacheDir(); Set set = mContext.getSharedPreferences("cache_file_list", 0).getStringSet("cache_files", new HashSet()); keysToDelete = new HashSet(set.size()); hashmap = new HashMap(); iterator = set.iterator(); _L4: Object obj; Object obj1; Object obj2; Object obj3; Object obj4; String s; ArrayList arraylist; String s1; do { if (!iterator.hasNext()) { break; /* Loop/switch isn't completed */ } s = (String)iterator.next(); ALog.v("Processing key: %s", new Object[] { s }); obj2 = null; obj = null; obj4 = null; obj3 = null; arraylist = new ArrayList(); s1 = (new StringBuilder()).append(s).append(".csv").toString(); obj1 = new File(cacheDir, s1); if (((File) (obj1)).exists()) { break; } ALog.v("Input file for %s does NOT exist", new Object[] { s }); } while (true); obj1 = new BufferedReader(new FileReader(((File) (obj1)))); obj = null; _L1: String s2 = ((BufferedReader) (obj1)).readLine(); if (s2 == null) { break MISSING_BLOCK_LABEL_430; } if (i < 100) { break MISSING_BLOCK_LABEL_419; } if (obj != null) { break MISSING_BLOCK_LABEL_319; } tempFileName = (new StringBuilder()).append(s1).append(".tmp").toString(); obj4 = new BufferedWriter(new FileWriter(new File(cacheDir, tempFileName))); int j; obj2 = obj4; obj3 = obj4; j = i; ALog.d("created temp file %s", new Object[] { tempFileName }); obj = obj4; obj2 = obj; obj3 = obj; j = i; ((BufferedWriter) (obj)).write((new StringBuilder()).append(s2).append("\n").toString()); obj2 = obj; obj3 = obj; j = i; ALog.v("Wrote\n%s\nto %s", new Object[] { s2, tempFileName }); _L2: i++; obj2 = obj; obj3 = obj; j = i; ALog.d("lineCount = %d", new Object[] { Integer.valueOf(i) }); goto _L1 arraylist.add(s2); goto _L2 if (obj1 != null) { try { ((BufferedReader) (obj1)).close(); } // Misplaced declaration of an exception variable catch (Object obj1) { ((IOException) (obj1)).printStackTrace(); } } if (obj == null) { break MISSING_BLOCK_LABEL_690; } ((BufferedWriter) (obj)).close(); j = i; _L5: hashmap.put(s, arraylist); keysToDelete.add(s); i = j; if (j < 100) goto _L4; else goto _L3 _L3: obj = new AnalyticsPayload(new HashMap(), 0, 0); ((AnalyticsPayload) (obj)).setData(hashmap); OlioApi.getInstance().postLogs(((AnalyticsPayload) (obj)), new Callback() { final WatchAnalytics this$0; final File val$cacheDir; final Set val$keysToDelete; public void failure(RetrofitError retrofiterror) { ALog.e("Unable to post logs, error: ", new Object[] { retrofiterror.toString() }); if (tempFileName != null) { (new File(cacheDir, tempFileName)).delete(); tempFileName = null; } if (retryCount < 3) { int i = // JavaClassFileOutputException: get_constant: invalid tag public volatile void success(Object obj5, Response response) { success((Response)obj5, response); } public void success(Response response, Response response1) { ALog.d("Successfully posted logs", new Object[0]); deleteCacheFiles(keysToDelete); retryCount = 0; if (tempFileName != null) { response1 = tempFileName.substring(0, tempFileName.length() - 4); response = new File(cacheDir, tempFileName); response1 = new File(cacheDir, response1); if (response.exists()) { response.renameTo(response1); } tempFileName = null; mHandler.post(new Runnable() { final _cls2 this$1; public void run() { sendLogToServer(); } { this$1 = _cls2.this; super(); } }); } } { this$0 = WatchAnalytics.this; keysToDelete = set; cacheDir = file; super(); } }); return; obj; ((IOException) (obj)).printStackTrace(); j = i; goto _L5 obj1; _L9: obj2 = obj; obj4 = obj3; ((IOException) (obj1)).printStackTrace(); if (obj != null) { try { ((BufferedReader) (obj)).close(); } // Misplaced declaration of an exception variable catch (Object obj) { ((IOException) (obj)).printStackTrace(); } } j = i; if (obj3 == null) goto _L5; else goto _L6 _L6: ((BufferedWriter) (obj3)).close(); j = i; goto _L5 obj; ((IOException) (obj)).printStackTrace(); j = i; goto _L5 obj1; obj = obj2; _L8: if (obj != null) { try { ((BufferedReader) (obj)).close(); } // Misplaced declaration of an exception variable catch (Object obj) { ((IOException) (obj)).printStackTrace(); } } if (obj4 != null) { try { ((BufferedWriter) (obj4)).close(); } // Misplaced declaration of an exception variable catch (Object obj) { ((IOException) (obj)).printStackTrace(); } } throw obj1; obj2; obj4 = obj; obj = obj1; obj1 = obj2; continue; /* Loop/switch isn't completed */ obj3; obj = obj1; obj4 = obj2; obj1 = obj3; if (true) goto _L8; else goto _L7 _L7: IOException ioexception; ioexception; obj3 = obj; obj = obj1; obj1 = ioexception; goto _L9 ioexception; obj = obj1; obj1 = ioexception; i = j; goto _L9 j = i; goto _L5 } private void writeToFile(String s, String s1) { String s2; Object obj; Object obj1; Object obj2; File file; obj2 = null; obj1 = null; obj = null; file = mContext.getCacheDir(); s2 = obj2; s = new File(file, s); s2 = obj2; if (s.exists()) { break MISSING_BLOCK_LABEL_50; } s2 = obj2; s.createNewFile(); s2 = obj2; s = new FileOutputStream(s, true); s = new OutputStreamWriter(s); s.append(s1); if (s == null) { break MISSING_BLOCK_LABEL_167; } s.close(); _L2: return; s; s.printStackTrace(); return; s; s1 = obj; _L5: s2 = s1; s.printStackTrace(); if (s1 == null) goto _L2; else goto _L1 _L1: try { s1.close(); return; } // Misplaced declaration of an exception variable catch (String s) { s.printStackTrace(); } return; s; _L4: if (s2 != null) { try { s2.close(); } // Misplaced declaration of an exception variable catch (String s1) { s1.printStackTrace(); } } throw s; s; s2 = obj1; continue; /* Loop/switch isn't completed */ s1; s2 = s; s = s1; if (true) goto _L4; else goto _L3 _L3: s; s1 = obj; goto _L5 IOException ioexception; ioexception; s1 = s; s = ioexception; goto _L5 } public void handleAnalytics(AnalyticsPayload analyticspayload) { ALog.v("handleAnalytics", new Object[0]); if (mContext == null) { ALog.e("Must initialize with context first.", new Object[0]); return; } if (mTimer == null) { mTimer = new RecoveryTimer("sendLogToServer"); mTimer.init(mContext, mHandler); } saveToCache(analyticspayload); mTimer.startOrRestart(60000L, new Runnable() { final WatchAnalytics this$0; public void run() { retryCount = 0; sendLogToServer(); } { this$0 = WatchAnalytics.this; super(); } }); } public WatchAnalytics initialize(Context context) { if (mContext == null) { mContext = context; } if (mThread == null) { mThread = new HandlerThread("WatchAnalyticsThread", 10); mThread.start(); mHandler = new Handler(mThread.getLooper()); } return sInstance; } /* static int access$002(WatchAnalytics watchanalytics, int i) { watchanalytics.retryCount = i; return i; } */ /* static int access$004(WatchAnalytics watchanalytics) { int i = watchanalytics.retryCount + 1; watchanalytics.retryCount = i; return i; } */ /* static String access$302(WatchAnalytics watchanalytics, String s) { watchanalytics.tempFileName = s; return s; } */ // Unreferenced inner class com/oliodevices/assist/app/controller/WatchAnalytics$2$2 /* anonymous class */ class _cls2 implements Runnable { final _cls2 this$1; public void run() { sendLogToServer(); } { this$1 = _cls2.this; super(); } } }