正在查看: Hopscotch v9.7.2 应用的 PayuUploadDeviceAnalytics.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Hopscotch v9.7.2 应用的 PayuUploadDeviceAnalytics.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.payu.india.Tasks;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.support.v4.media.b;
import android.support.v4.media.d;
import android.util.Log;
import com.google.android.gms.ads.internal.client.z0;
import com.payu.custombrowser.util.CBConstant;
import com.payu.india.Payu.PayuConstants;
import com.payu.india.Payu.PayuUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.Thread;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class PayuUploadDeviceAnalytics {
private static final String PRODUCTION_URL = "https://info.payu.in/merchant/mobileWebService.php";
private static final String TEST_URL = "https://mobiletest.payu.in/merchant/mobileWebService.php";
private static long TIMER_DELAY = 0;
private static boolean isProduction = true;
private String ANALYTICS_URL;
private final Context appContext;
private String fileName;
private ArrayList<String> mBuffer;
private boolean mIsLocked;
private Timer mTimer;
public class UploadData extends AsyncTask<String, Void, String> {
private String temp;
public UploadData(String str) {
this.temp = str;
}
@Override
public String doInBackground(String... strArr) {
try {
try {
JSONArray jSONArray = new JSONArray(strArr[0]);
JSONArray jSONArray2 = jSONArray;
for (int i = 0; i < jSONArray.length(); i++) {
if (PayuUploadDeviceAnalytics.this.getbooleanSharedPreference(((JSONObject) jSONArray.get(i)).getString(PayuConstants.MERCHANT_KEY) + "|" + ((JSONObject) jSONArray.get(i)).getString("txnid"))) {
jSONArray2 = PayuUploadDeviceAnalytics.removeJsonObjectAtJsonArrayIndex(jSONArray, i);
}
}
if (jSONArray2.length() <= 0) {
return null;
}
String str = "mobile_data=" + jSONArray2.toString();
str.getBytes("UTF-8");
HttpsURLConnection httpsConn = PayuUtils.getHttpsConn(new URL(PayuUploadDeviceAnalytics.this.ANALYTICS_URL).toString(), str);
if (httpsConn == null) {
PayuUploadDeviceAnalytics.this.appContext.deleteFile(PayuUploadDeviceAnalytics.this.fileName);
return null;
}
int responseCode = httpsConn.getResponseCode();
InputStream inputStream = httpsConn.getInputStream();
StringBuffer stringBuffer = new StringBuffer();
byte[] bArr = new byte[1024];
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
stringBuffer.append(new String(bArr, 0, read));
}
if (responseCode != 200) {
try {
FileOutputStream openFileOutput = PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
openFileOutput.write(this.temp.getBytes());
openFileOutput.close();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
try {
JSONObject jSONObject = new JSONObject(stringBuffer.toString());
if (!jSONObject.has("status") || jSONObject.getString("status").equalsIgnoreCase("")) {
try {
FileOutputStream openFileOutput2 = PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
openFileOutput2.write(this.temp.getBytes());
openFileOutput2.close();
return null;
} catch (IOException e2) {
e2.printStackTrace();
return null;
}
}
PayuUploadDeviceAnalytics.this.appContext.deleteFile(PayuUploadDeviceAnalytics.this.fileName);
if (!jSONObject.has("status") || (!jSONObject.getString("status").equalsIgnoreCase(CBConstant.TRANSACTION_STATUS_SUCCESS) && !jSONObject.getString("status").equalsIgnoreCase("-1"))) {
try {
FileOutputStream openFileOutput3 = PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
openFileOutput3.write(this.temp.getBytes());
openFileOutput3.close();
return null;
} catch (IOException e3) {
e3.printStackTrace();
return null;
}
}
for (int i2 = 0; i2 < jSONArray2.length(); i2++) {
PayuUploadDeviceAnalytics.this.setBooleanSharedPreference(((JSONObject) jSONArray2.get(i2)).getString(PayuConstants.MERCHANT_KEY) + "|" + ((JSONObject) jSONArray2.get(i2)).getString("txnid"), true);
}
return null;
} catch (Exception e4) {
Log.d(getClass().getSimpleName(), "Exception " + e4.getMessage());
FileOutputStream openFileOutput4 = PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
openFileOutput4.write(this.temp.getBytes());
openFileOutput4.close();
return null;
}
Log.d(getClass().getSimpleName(), "Exception " + e4.getMessage());
try {
FileOutputStream openFileOutput42 = PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
openFileOutput42.write(this.temp.getBytes());
openFileOutput42.close();
return null;
} catch (IOException e5) {
e5.printStackTrace();
return null;
}
} catch (Exception e6) {
z0.l(e6, new StringBuilder("Exception "), getClass().getSimpleName());
return null;
}
} catch (MalformedURLException e7) {
e = e7;
Log.d(getClass().getSimpleName(), "Exception " + e.getMessage());
return null;
} catch (ProtocolException e8) {
e = e8;
Log.d(getClass().getSimpleName(), "Exception " + e.getMessage());
return null;
} catch (IOException e9) {
PayuUploadDeviceAnalytics.this.resetTimer();
Log.d(getClass().getSimpleName(), "IOException " + e9.getMessage());
return null;
}
}
@Override
public void onPostExecute(String str) {
super.onPostExecute((UploadData) str);
}
}
public PayuUploadDeviceAnalytics(Context context, String str) {
this.fileName = "sdk_local_cache_device";
this.ANALYTICS_URL = isProduction ? PRODUCTION_URL : TEST_URL;
this.mIsLocked = false;
this.mBuffer = new ArrayList<>();
this.appContext = context;
this.fileName = str;
final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable th) {
while (PayuUploadDeviceAnalytics.this.mIsLocked) {
}
PayuUploadDeviceAnalytics.this.setLock();
try {
FileOutputStream openFileOutput = PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
int size = PayuUploadDeviceAnalytics.this.mBuffer.size();
for (int i = 0; i < size; i++) {
openFileOutput.write((((String) PayuUploadDeviceAnalytics.this.mBuffer.get(i)) + "\r\n").getBytes());
}
openFileOutput.close();
} catch (IOException e) {
Log.d(getClass().getSimpleName(), "IOException " + e.getMessage());
}
PayuUploadDeviceAnalytics.this.releaseLock();
defaultUncaughtExceptionHandler.uncaughtException(thread, th);
}
});
}
public static JSONArray removeJsonObjectAtJsonArrayIndex(JSONArray jSONArray, int i) throws JSONException {
if (i < 0 || i > jSONArray.length() - 1) {
throw new IndexOutOfBoundsException();
}
JSONArray jSONArray2 = new JSONArray();
int length = jSONArray.length();
for (int i2 = 0; i2 < length; i2++) {
if (i2 != i) {
jSONArray2.put(jSONArray.get(i2));
}
}
return jSONArray2;
}
public void resetTimer() {
Timer timer = this.mTimer;
if (timer != null) {
timer.cancel();
}
Timer timer2 = new Timer();
this.mTimer = timer2;
timer2.schedule(new TimerTask() {
@Override
public void run() {
while (PayuUploadDeviceAnalytics.this.mIsLocked) {
}
long unused = PayuUploadDeviceAnalytics.TIMER_DELAY = 5000L;
PayuUploadDeviceAnalytics.this.setLock();
String str = "";
try {
try {
if (!new File(PayuUploadDeviceAnalytics.this.appContext.getFilesDir(), PayuUploadDeviceAnalytics.this.fileName).exists()) {
PayuUploadDeviceAnalytics.this.appContext.openFileOutput(PayuUploadDeviceAnalytics.this.fileName, 0);
}
FileInputStream openFileInput = PayuUploadDeviceAnalytics.this.appContext.openFileInput(PayuUploadDeviceAnalytics.this.fileName);
while (true) {
int read = openFileInput.read();
if (read == -1) {
break;
}
str = str + Character.toString((char) read);
}
openFileInput.close();
int size = PayuUploadDeviceAnalytics.this.mBuffer.size();
while (size > 0) {
size--;
str = b.k((String) PayuUploadDeviceAnalytics.this.mBuffer.get(size), "\r\n", d.i(str));
if (size >= 0 && PayuUploadDeviceAnalytics.this.mBuffer.size() > size) {
PayuUploadDeviceAnalytics.this.mBuffer.remove(size);
}
}
String trim = str.trim();
if (trim.length() > 0) {
PayuUploadDeviceAnalytics.this.new UploadData(trim).execute(trim);
}
} catch (IOException e) {
Log.d(getClass().getSimpleName(), "IOException " + e.getMessage());
int size2 = PayuUploadDeviceAnalytics.this.mBuffer.size();
while (size2 > 0) {
size2--;
str = b.k((String) PayuUploadDeviceAnalytics.this.mBuffer.get(size2), "\r\n", d.i(str));
if (size2 >= 0 && PayuUploadDeviceAnalytics.this.mBuffer.size() > size2) {
PayuUploadDeviceAnalytics.this.mBuffer.remove(size2);
}
}
String trim2 = str.trim();
if (trim2.length() > 0) {
PayuUploadDeviceAnalytics.this.new UploadData(trim2).execute(trim2);
}
}
if (PayuUploadDeviceAnalytics.this.mBuffer.size() > 0) {
PayuUploadDeviceAnalytics.this.resetTimer();
}
PayuUploadDeviceAnalytics.this.releaseLock();
} catch (Throwable th) {
int size3 = PayuUploadDeviceAnalytics.this.mBuffer.size();
while (size3 > 0) {
size3--;
str = b.k((String) PayuUploadDeviceAnalytics.this.mBuffer.get(size3), "\r\n", d.i(str));
if (size3 >= 0 && PayuUploadDeviceAnalytics.this.mBuffer.size() > size3) {
PayuUploadDeviceAnalytics.this.mBuffer.remove(size3);
}
}
String trim3 = str.trim();
if (trim3.length() > 0) {
PayuUploadDeviceAnalytics.this.new UploadData(trim3).execute(trim3);
}
throw th;
}
}
}, TIMER_DELAY);
}
public boolean getbooleanSharedPreference(String str) {
SharedPreferences encryptedSharedPreference = new PayuUtils().getEncryptedSharedPreference(this.appContext, "com.payu");
try {
return encryptedSharedPreference.getBoolean(str, false);
} catch (Exception unused) {
encryptedSharedPreference.edit().clear().apply();
return false;
}
}
public void log(String str) {
if (this.mIsLocked) {
this.mBuffer.add(str);
} else {
setLock();
try {
JSONObject jSONObject = new JSONObject(str);
new JSONArray();
if (!new File(this.appContext.getFilesDir(), this.fileName).exists()) {
this.appContext.openFileOutput(this.fileName, 0);
}
FileInputStream openFileInput = this.appContext.openFileInput(this.fileName);
String str2 = "";
while (openFileInput != null && openFileInput.available() > 0) {
int read = openFileInput.read();
if (read == -1) {
break;
}
str2 = str2 + Character.toString((char) read);
}
JSONArray jSONArray = str2.equalsIgnoreCase("") ? new JSONArray() : new JSONArray(str2);
openFileInput.close();
FileOutputStream openFileOutput = this.appContext.openFileOutput(this.fileName, 0);
jSONArray.put(jSONArray.length(), jSONObject);
openFileOutput.write((str2 + jSONArray.toString() + "\r\n").getBytes());
openFileOutput.close();
} catch (IOException e) {
Log.d(getClass().getSimpleName(), "IOException " + e.getMessage());
this.mBuffer.add(str);
} catch (JSONException e2) {
com.facebook.appevents.internal.b.k(e2, new StringBuilder("JSONException "), getClass().getSimpleName());
}
releaseLock();
}
resetTimer();
}
public synchronized void releaseLock() {
this.mIsLocked = false;
}
public void setBooleanSharedPreference(String str, boolean z) {
SharedPreferences.Editor edit = new PayuUtils().getEncryptedSharedPreference(this.appContext, "com.payu").edit();
edit.putBoolean(str, z);
edit.apply();
}
public synchronized void setLock() {
this.mIsLocked = true;
}
}