124 lines
5.7 KiB
Java
124 lines
5.7 KiB
Java
package com.peaky.binders;
|
|
|
|
import android.app.Service;
|
|
import android.content.Intent;
|
|
import android.os.Binder;
|
|
import android.os.IBinder;
|
|
import android.os.RemoteException;
|
|
import android.util.Log;
|
|
import com.peaky.binders.IPeakyService;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
|
|
/* JADX INFO: loaded from: classes.dex */
|
|
public class PeakyService extends Service {
|
|
public static final String ACTION_ACHIEVEMENT_UNLOCKED = "com.peaky.binders.ACHIEVEMENT_UNLOCKED";
|
|
public static final String EXTRA_ACHIEVEMENT_INDEX = "achievement_index";
|
|
private static final String LOG_FILE_PATH = "/data/data/com.peaky.binders/logs/logs.txt";
|
|
private static boolean debugMode;
|
|
private final IBinder binder = new IPeakyService.Stub() { // from class: com.peaky.binders.PeakyService.1
|
|
@Override // com.peaky.binders.IPeakyService
|
|
public void DebugCheckFile(byte[] bArr) throws RemoteException {
|
|
int callingPid = Binder.getCallingPid();
|
|
if (callingPid != 0) {
|
|
Log.d("PeakyService", "We allow a root process only: " + callingPid);
|
|
PeakyService.this.logToFile("DebugCheckFile called - rejected, PID: " + callingPid);
|
|
return;
|
|
}
|
|
Log.d("PeakyService", "Called from a root process: " + callingPid);
|
|
PeakyService.this.logToFile("DebugCheckFile called from root process - PID: " + callingPid);
|
|
String str = new String(bArr);
|
|
PeakyService.this.logToFile("Caller name: ".concat(str));
|
|
String[] strArrRetrieveLog = PeakyService.this.RetrieveLog(str);
|
|
if (strArrRetrieveLog != null && strArrRetrieveLog.length == 2) {
|
|
final String str2 = strArrRetrieveLog[0];
|
|
final String str3 = strArrRetrieveLog[1];
|
|
Log.d("PeakyService", "DEBUG serverUrl: " + str2);
|
|
Log.d("PeakyService", "DEBUG logContent length: " + str3.length());
|
|
PeakyService.this.logToFile("DEBUG serverUrl: " + str2);
|
|
new Thread(new Runnable() { // from class: com.peaky.binders.PeakyService.1.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str2 + "/logs/").openConnection();
|
|
httpURLConnection.setRequestMethod("POST");
|
|
httpURLConnection.setDoOutput(true);
|
|
httpURLConnection.setRequestProperty("Content-Type", "text/plain");
|
|
OutputStream outputStream = httpURLConnection.getOutputStream();
|
|
outputStream.write(str3.getBytes());
|
|
outputStream.flush();
|
|
outputStream.close();
|
|
Log.d("PeakyService", "HTTP Response: " + httpURLConnection.getResponseCode());
|
|
httpURLConnection.disconnect();
|
|
} catch (Exception e) {
|
|
Log.e("PeakyService", "Failed to send logs: " + e.getMessage());
|
|
}
|
|
}
|
|
}).start();
|
|
}
|
|
Intent intent = new Intent(PeakyService.ACTION_ACHIEVEMENT_UNLOCKED);
|
|
intent.putExtra(PeakyService.EXTRA_ACHIEVEMENT_INDEX, 2);
|
|
PeakyService.this.sendBroadcast(intent);
|
|
}
|
|
|
|
@Override // com.peaky.binders.IPeakyService
|
|
public boolean isAchievementUnlocked(int i) throws RemoteException {
|
|
Log.d("PeakyService", "Checking achievement " + i + " status via native code");
|
|
PeakyService.this.logToFile("Checking achievement " + i + " status via native code");
|
|
return PeakyService.this.checkAchievementNative(i);
|
|
}
|
|
|
|
@Override // com.peaky.binders.IPeakyService
|
|
public void enableDebugMode(boolean z) throws RemoteException {
|
|
boolean unused = PeakyService.debugMode = z;
|
|
String strConcat = "Debug mode ".concat(z ? "enabled" : "disabled");
|
|
Log.d("PeakyService", strConcat);
|
|
PeakyService.this.logToFile(strConcat);
|
|
if (z) {
|
|
File file = new File("/data/data/com.peaky.binders/logs");
|
|
if (file.exists()) {
|
|
return;
|
|
}
|
|
file.mkdirs();
|
|
}
|
|
}
|
|
};
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public native String[] RetrieveLog(String str);
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public native boolean checkAchievementNative(int i);
|
|
|
|
static {
|
|
System.loadLibrary("peaky");
|
|
debugMode = false;
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public IBinder onBind(Intent intent) {
|
|
return this.binder;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void logToFile(String str) {
|
|
if (debugMode) {
|
|
try {
|
|
File file = new File(LOG_FILE_PATH);
|
|
File parentFile = file.getParentFile();
|
|
if (parentFile != null && !parentFile.exists()) {
|
|
parentFile.mkdirs();
|
|
}
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file, true);
|
|
fileOutputStream.write((System.currentTimeMillis() + " - " + str + "\n").getBytes());
|
|
fileOutputStream.close();
|
|
} catch (IOException e) {
|
|
Log.e("PeakyService", "Failed to write to log file: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
} |