Skip to content

Instantly share code, notes, and snippets.

@harrylepotter
Last active February 11, 2024 19:47
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrylepotter/f4bfb37f11faf9efcfd6cd4b189cfa33 to your computer and use it in GitHub Desktop.
Save harrylepotter/f4bfb37f11faf9efcfd6cd4b189cfa33 to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.os.Process;
import android.support.p018v7.p019a.C0367a;
import android.util.Log;
import com.yalantis.ucrop.BuildConfig;
import com.yalantis.ucrop.view.CropImageView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/* renamed from: cn.manstep.phonemirrorBox.b.e */
public class BoxProtocol {
/* renamed from: a */
public static boolean f2571a = false;
/* renamed from: b */
public static boolean f2572b = false;
/* renamed from: c */
public static boolean f2573c = false;
/* renamed from: d */
public static boolean f2574d = false;
/* renamed from: e */
public static boolean f2575e = false;
/* renamed from: h */
private static int f2576h = 2;
/* renamed from: A */
private Thread audioRecordThread;
/* access modifiers changed from: private */
/* renamed from: B */
public boolean f2578B;
/* access modifiers changed from: private */
/* renamed from: C */
public C0769a f2579C;
/* access modifiers changed from: private */
/* renamed from: D */
public List<C0735a> f2580D;
/* access modifiers changed from: private */
/* renamed from: E */
public boolean f2581E;
/* renamed from: F */
private int possibleWidth;
/* renamed from: G */
private int possibleHeight;
/* renamed from: H */
private C0735a f2584H;
/* renamed from: I */
private byte[] f2585I = new byte[20];
/* renamed from: J */
private boolean f2586J = true;
/* renamed from: f */
public WeakReference<Context> mContext;
/* renamed from: g */
public C0740b f2588g;
/* renamed from: i */
private boolean f2589i = true;
/* renamed from: j */
private int f2590j = 2;
/* renamed from: k */
private int f2591k = 0;
/* renamed from: l */
private int f2592l = 0;
/* renamed from: m */
private int f2593m = 0;
/* renamed from: n */
private int f2594n = 0;
/* renamed from: o */
private String f2595o = BuildConfig.FLAVOR;
/* renamed from: p */
private String f2596p = BuildConfig.FLAVOR;
/* renamed from: q */
private String f2597q = BuildConfig.FLAVOR;
/* access modifiers changed from: private */
/* renamed from: r */
public boolean f2598r = false;
/* renamed from: s */
private C0834f f2599s;
/* renamed from: t */
private boolean f2600t = false;
/* renamed from: u */
private PossibleVideoFrame f2601u;
/* access modifiers changed from: private */
/* renamed from: v */
public C0882j<Boolean> f2602v;
/* renamed from: w */
private Thread readThread;
/* access modifiers changed from: private */
/* renamed from: x */
public Thread f2604x;
/* renamed from: y */
private Thread iosAudioThread;
/* access modifiers changed from: private */
/* renamed from: z */
public ScheduledExecutorService f2606z;
/* renamed from: a */
public C0834f mo3426a() {
return this.f2599s;
}
/* renamed from: b */
public String mo3437b() {
return this.f2596p;
}
/* renamed from: c */
public String mo3442c() {
return this.f2595o;
}
/* renamed from: d */
public String getBluetoothAddress() {
String g = Preferences.m4120g((Context) this.mContext.get());
if (g.equals(BuildConfig.FLAVOR) || g.equals("00:00:00:00:00:00")) {
return BuildConfig.FLAVOR;
}
Logger.someLog("BoxProtocol,getBluetoothAddress: Local bluetooth mac address: " + g);
return g;
}
/* renamed from: a */
private boolean copyFileToDevice(Context context, String str) {
return copyAssetFileToBox(context, str, "/tmp/" + str + "\u0000");
}
/* renamed from: a */
private boolean copyLocalFileToBox(String str, String str2) {
File file = new File(str);
if (!file.exists() || !file.isFile()) {
return false;
}
int length = (int) file.length();
Logger.log("BoxProtocol,copyLocalFileToBox: " + str + ", length = " + length);
if (length > 102400) {
Logger.log("BoxProtocol,copyLocalFileToBox: The local file that needs to be sent to the box is larger than 100kb!!! ");
return false;
}
try {
byte[] bArr = new byte[length];
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bArr);
fileInputStream.close();
return upload_file_to_box(str2, bArr);
} catch (Exception e) {
Logger.someLog("BoxProtocol,copyLocalFileToBox: " + Log.getStackTraceString(e));
return false;
}
}
/* renamed from: a */
private boolean copyAssetFileToBox(Context context, String str, String str2) {
boolean z = true;
try {
InputStream open = context.getAssets().open(str);
int available = open.available();
byte[] bArr = new byte[available];
int read = open.read(bArr);
if (read != available) {
Logger.someLog("filename = " + str + " readCount = " + read + ", length = " + available);
z = false;
}
upload_file_to_box(str2, bArr);
open.close();
return z;
} catch (Exception e) {
Logger.someLog("BoxProtocol,copyAssetFiletoBox: \n" + Log.getStackTraceString(e));
return false;
}
}
/* renamed from: a */
public boolean uploadAssets(Context context) {
if (context == null) {
Logger.someLog("BoxProtocol,UploadAssets: context==null");
return false;
} else if (!copyFileToDevice(context, "adb") || !copyFileToDevice(context, "adb.pub") || !copyFileToDevice(context, "helloworld0") || !copyFileToDevice(context, "helloworld1") || !copyFileToDevice(context, "helloworld2") || !copyFileToDevice(context, "libby265n.so") || !copyFileToDevice(context, "libby265n_x86.so") || !copyFileToDevice(context, "libscreencap40.so") || !copyFileToDevice(context, "libscreencap41.so") || !copyFileToDevice(context, "libscreencap43.so") || !copyFileToDevice(context, "libscreencap50.so") || !copyFileToDevice(context, "libscreencap50_x86.so") || !copyFileToDevice(context, "libscreencap442.so") || !copyFileToDevice(context, "libscreencap422.so") || !copyFileToDevice(context, "mirrorcoper.apk") || !copyFileToDevice(context, "libscreencap60.so") || !copyFileToDevice(context, "libscreencap70.so") || !copyFileToDevice(context, "libscreencap71.so") || !copyFileToDevice(context, "libscreencap80.so") || !copyFileToDevice(context, "libscreencap90.so") || !copyFileToDevice(context, "HWTouch.dex")) {
return false;
} else {
return true;
}
}
/* renamed from: b */
public boolean uploadWifiModule(Context context) {
if (context == null) {
Logger.someLog("BoxProtocol,UploadWifiModule: context==null");
return false;
}
Logger.log("BoxProtocol,UploadWifiModule: send 88x2bs.ko");
return copyAssetFileToBox(context, "8848", "/tmp/88x2bs.ko\u0000");
}
/* renamed from: e */
public void copyIconsToBox() {
int i = 0;
String[] strArr = {C0883k.getPhoneDataPath(), "/sdcard", "/mnt/extsd"};
while (true) {
int i2 = i;
if (i2 < strArr.length) {
String str = strArr[i2] + "/carplay.png";
File file = new File(str);
if (file.exists()) {
byte[] bArr = new byte[((int) file.length())];
Logger.m4223a(bArr, 0, str);
send_CarplayLogoType(1);
upload_file_to_box("/etc/oem_icon.png\u0000", bArr);
return;
}
if (i2 == strArr.length - 1) {
BoxInterface.f2536b.send_CarplayLogoType(Preferences.m4136m((Context) this.mContext.get()));
}
i = i2 + 1;
} else {
return;
}
}
}
/* renamed from: c */
public void uploadLocalLogoPngPublic(Context context) {
String r;
int p;
if (context != null) {
int m = Preferences.m4136m(context);
if (m == 2) {
r = "CarPlayOEM/AutoKit_siri.png";
p = 0;
} else {
r = Preferences.m4146r(context);
p = Preferences.m4142p(context);
}
sendCarManufacturerInfo(p, 0);
Logger.log("BoxProtocol,UploadLocalLogoPNGPublic: filePath = " + r);
if (r.equals(BuildConfig.FLAVOR)) {
return;
}
if (r.contains("custom")) {
copyLocalFileToBox(r, "/etc/icon_120x120.png\u0000");
copyLocalFileToBox(r, "/etc/icon_180x180.png\u0000");
copyLocalFileToBox(r, "/etc/icon_256x256.png\u0000");
uploadAirplayPrefs((Context) this.mContext.get());
return;
}
copyAssetFileToBox(context, r, "/etc/icon_120x120.png\u0000");
copyAssetFileToBox(context, r, "/etc/icon_180x180.png\u0000");
copyAssetFileToBox(context, r, "/etc/icon_256x256.png\u0000");
if (m == 2) {
send_CarplayLogoType(2);
return;
}
send_CarplayLogoType(1);
uploadAirplayPrefs((Context) this.mContext.get());
}
}
/* renamed from: f */
public void UploadLocalLogoPNGPublic() {
boolean z = false;
Logger.log("BoxProtocol,UploadLocalLogoPNGPublic");
String[] strArr = {C0883k.getPhoneDataPath(), "/sdcard", "/mnt/extsd"};
int i = 0;
while (true) {
if (i >= strArr.length) {
break;
}
String str = strArr[i] + "/" + "carplay" + "_120x120.png";
File file = new File(str);
String str2 = strArr[i] + "/" + "carplay" + "_180x180.png";
File file2 = new File(str2);
String str3 = strArr[i] + "/" + "carplay" + "_256x256.png";
File file3 = new File(str3);
if (file.exists() && file.exists() && file3.exists()) {
byte[] bArr = new byte[((int) file.length())];
Logger.m4223a(bArr, 0, str);
upload_file_to_box("/etc/icon_120x120.png\u0000", bArr);
byte[] bArr2 = new byte[((int) file2.length())];
Logger.m4223a(bArr2, 0, str2);
upload_file_to_box("/etc/icon_180x180.png\u0000", bArr2);
byte[] bArr3 = new byte[((int) file3.length())];
Logger.m4223a(bArr3, 0, str3);
upload_file_to_box("/etc/icon_256x256.png\u0000", bArr3);
send_CarplayLogoType(1);
z = true;
break;
}
i++;
}
if (!z) {
uploadLocalLogoPngPublic((Context) this.mContext.get());
}
}
/* renamed from: g */
public void getAndUploadAirplayPrefs() {
boolean z = false;
String[] strArr = {C0883k.getPhoneDataPath(), "/sdcard", "/mnt/extsd"};
int i = 0;
while (true) {
if (i >= strArr.length) {
break;
}
String str = strArr[i] + "/carplay.conf";
Logger.m4226b("BoxProtocol", "localPNGPath: " + str);
File file = new File(str);
if (file.exists()) {
byte[] bArr = new byte[((int) file.length())];
Logger.m4223a(bArr, 0, str);
upload_file_to_box("/etc/airplay.conf\u0000", bArr);
z = true;
break;
}
i++;
}
if (!z) {
uploadAirplayPrefs((Context) this.mContext.get());
}
}
/* renamed from: d */
public void uploadAirplayPrefs(Context context) {
String str;
if (context != null && Preferences.m4136m(context) != 2) {
String q = Preferences.m4144q(context);
if (!q.equals(BuildConfig.FLAVOR)) {
if (q.toLowerCase().contains("default") || q.toLowerCase().contains("custom")) {
str = BuildConfig.FLAVOR;
} else {
str = "oemIconLabel = " + q + "\n";
}
upload_file_to_box("/etc/airplay.conf\u0000", ("oemIconVisible = 1\n" + str + ("name = " + getBoxNameProbably() + "\n") + "model = Magic-Car-Link-1.00\noemIconPath = /etc/oem_icon.png\n").getBytes());
}
}
}
/* renamed from: cn.manstep.phonemirrorBox.b.e$b */
class MessageFrame {
/* access modifiers changed from: private */
/* renamed from: b */
public int possiblyDataLength = 0;
/* access modifiers changed from: private */
/* renamed from: c */
public int length = 0;
/* access modifiers changed from: private */
/* renamed from: d */
public int messageType = 0;
/* access modifiers changed from: private */
/* renamed from: e */
public int possiblyArguments = 0;
public MessageFrame() {
}
/* renamed from: a */
public int possibleLength() {
return 16;
}
/* renamed from: b */
public boolean mo3485b() {
return 1437226410 == this.possiblyDataLength && this.possiblyArguments == (this.messageType ^ -1);
}
/* renamed from: c */
public void mo3486c() {
this.possiblyArguments = this.messageType ^ -1;
this.possiblyDataLength = 1437226410;
}
}
/* renamed from: cn.manstep.phonemirrorBox.b.e$e */
class MegaBuffer {
/* access modifiers changed from: private */
/* renamed from: b */
public MessageFrame message;
/* renamed from: c */
private byte[] f2642c = null;
/* renamed from: d */
private ByteBuffer possiblyOutputBuffer = ByteBuffer.allocate(this.message.possibleLength());
/* access modifiers changed from: private */
/* renamed from: e */
public ByteBuffer dataBuffer;
public MegaBuffer() {
this.message = new MessageFrame();
this.possiblyOutputBuffer.order(ByteOrder.LITTLE_ENDIAN);
this.dataBuffer = ByteBuffer.allocate(1048576);
this.dataBuffer.order(ByteOrder.LITTLE_ENDIAN);
}
public MegaBuffer(int i) {
this.message = new MessageFrame();
this.possiblyOutputBuffer.order(ByteOrder.LITTLE_ENDIAN);
this.dataBuffer = ByteBuffer.allocate(i);
this.dataBuffer.order(ByteOrder.LITTLE_ENDIAN);
int unused = this.message.length = i;
}
/* renamed from: a */
public void mo3490a() {
int unused = this.message.possiblyDataLength = this.possiblyOutputBuffer.getInt(0);
int unused2 = this.message.length = this.possiblyOutputBuffer.getInt(4);
int unused3 = this.message.messageType = this.possiblyOutputBuffer.getInt(8);
int unused4 = this.message.possiblyArguments = this.possiblyOutputBuffer.getInt(12);
}
/* renamed from: b */
public void mo3491b() {
this.f2642c = this.dataBuffer.array();
}
/* renamed from: c */
public byte[] possiblyHeaderBufferAsArray() {
return this.possiblyOutputBuffer.array();
}
/* renamed from: d */
public int possibleLength() {
return this.message.possibleLength();
}
/* renamed from: e */
public byte[] dataBufferAsArray() {
return this.dataBuffer.array();
}
/* renamed from: f */
public ByteBuffer outputBuffer() {
return this.dataBuffer;
}
/* renamed from: g */
public int lenght() {
return this.message.length;
}
/* renamed from: h */
public void checkBufferCapacity() {
if (this.message.length > this.dataBuffer.capacity()) {
Logger.someLog("Out of dataBuffer.capacity");
this.dataBuffer = ByteBuffer.allocate(this.message.length);
this.dataBuffer.order(ByteOrder.LITTLE_ENDIAN);
}
}
/* renamed from: i */
public void possiblyPopulateMessage() {
this.message.mo3486c();
this.possiblyOutputBuffer.putInt(0, this.message.possiblyDataLength);
this.possiblyOutputBuffer.putInt(4, this.message.length);
this.possiblyOutputBuffer.putInt(8, this.message.messageType);
this.possiblyOutputBuffer.putInt(12, this.message.possiblyArguments);
if (this.f2642c != null) {
this.dataBuffer.put(this.f2642c);
}
}
}
/* renamed from: cn.manstep.phonemirrorBox.b.e$d */
public static class PossibleVideoFrame {
/* renamed from: g */
static int f2631g = 2;
/* renamed from: h */
static int f2632h = 1;
/* renamed from: a */
int f2633a;
/* renamed from: b */
int f2634b;
/* renamed from: c */
int framerate;
/* renamed from: d */
int format;
/* renamed from: e */
int packetMax;
/* renamed from: f */
int f2638f;
/* renamed from: i */
private ByteBuffer f2639i;
public PossibleVideoFrame() {
if (C0844k.f2883g) {
Logger.someLog("use soft-decode, framerate = 25 !!!!!!!!!!!!!!!");
C0844k.f2894r = 25;
}
this.f2633a = 0;
this.f2634b = 0;
this.framerate = C0844k.f2894r;
Logger.m4226b("BoxProtocol", "videoFrameRate = " + this.framerate);
this.format = 5;
this.packetMax = 49152;
this.f2638f = 0;
this.f2639i = ByteBuffer.allocate(m3610c());
this.f2639i.order(ByteOrder.LITTLE_ENDIAN);
}
/* renamed from: a */
public static boolean m3607a() {
return f2631g == 2;
}
/* renamed from: a */
public static void m3606a(int i) {
f2631g = i;
}
/* renamed from: b */
public static void m3609b(int i) {
Logger.log("changeAndroidWorkMode: " + i);
f2632h = i;
}
/* renamed from: b */
public static int m3608b() {
return f2632h;
}
/* renamed from: c */
public static int m3610c() {
return 28;
}
/* renamed from: d */
public byte[] getPhoneWorkModeBytes() {
this.f2639i.putInt(0, this.f2633a);
this.f2639i.putInt(4, this.f2634b);
this.f2639i.putInt(8, this.framerate);
this.f2639i.putInt(12, this.format);
this.f2639i.putInt(16, this.packetMax);
this.f2639i.putInt(20, this.f2638f);
this.f2639i.putInt(24, f2631g);
Logger.someLog("getBytes: PhoneWorkMode:" + f2631g);
return this.f2639i.array();
}
/* renamed from: a */
public void mo3488a(ByteBuffer byteBuffer) {
this.f2633a = byteBuffer.getInt(0);
this.f2634b = byteBuffer.getInt(4);
this.framerate = byteBuffer.getInt(8);
this.format = byteBuffer.getInt(12);
this.packetMax = byteBuffer.getInt(16);
this.f2638f = byteBuffer.getInt(20);
f2631g = byteBuffer.getInt(24);
}
}
/* renamed from: cn.manstep.phonemirrorBox.b.e$a */
class C0769a {
/* renamed from: b */
private MegaBuffer f2616b = new MegaBuffer();
/* renamed from: c */
private C0868f f2617c = new C0868f();
/* renamed from: a */
public synchronized MegaBuffer mo3482a() {
MegaBuffer eVar;
eVar = null;
while (this.f2617c.mo3720d() > 10) {
Logger.someLog("dataVec_.size = " + this.f2617c.mo3720d());
this.f2617c.mo3714a(0);
}
if (!this.f2617c.mo3716a()) {
int unused = this.f2616b.message.length = this.f2617c.mo3717b().length;
this.f2616b.dataBuffer.rewind();
this.f2616b.dataBuffer.put(this.f2617c.mo3717b());
this.f2617c.mo3714a(0);
eVar = this.f2616b;
} else {
wait(100);
}
return eVar;
}
/* renamed from: b */
public synchronized void mo3483b() {
notify();
}
public C0769a() {
}
}
public BoxProtocol(Context context) {
Logger.log("BoxProtocol,BoxProtocol: ===***===");
this.f2580D = new ArrayList();
this.f2580D.add(new C0735a(2, 1, context));
this.f2580D.add(new C0735a(2, 2, context));
this.f2580D.add(new C0735a(3, 1, context));
C0735a aVar = new C0735a(4, 1, context);
this.f2580D.add(aVar);
this.f2584H = aVar;
if (C0844k.f2892p) {
this.f2580D.add(new C0735a(7, 1, context));
} else {
this.f2580D.add(new C0735a(5, 1, context));
}
this.f2580D.add(new C0735a(6, 1, context));
this.f2580D.add(new C0735a(5, 2, context));
this.f2580D.add(new C0735a(4, 2, context));
this.f2581E = false;
this.f2593m = 0;
this.f2594n = 0;
this.f2601u = new PossibleVideoFrame();
this.f2602v = new C0882j<>();
this.f2602v.mo3743a(false);
this.mContext = new WeakReference<>(context);
this.f2579C = new C0769a();
initBoundSize();
setupSendThread();
setupHeartbeat();
if (this.readThread == null) {
this.readThread = new Thread(new Runnable() {
public void run() {
Logger.someLog("start readThread------:" + this);
MegaBuffer eVar = new MegaBuffer();
while (true) {
if (!BoxProtocol.this.f2581E) {
if (!BoxInterface.m3485a(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
BoxProtocol.this.f2602v.mo3743a(false);
Logger.log("readThread err 1");
break;
}
eVar.mo3490a();
if (eVar.message.mo3485b()) {
eVar.checkBufferCapacity();
if (!BoxInterface.m3485a(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.log("readThread err 2");
break;
}
eVar.mo3491b();
if (7 == eVar.message.messageType) {
for (C0735a a : BoxProtocol.this.f2580D) {
a.mo3361a(eVar);
}
} else {
BoxProtocol.this.onCmd(eVar);
}
} else {
Logger.someLog("Recv error head!!!");
BoxProtocol.this.f2602v.mo3743a(false);
}
} else {
break;
}
}
Logger.someLog("end readThread------:" + this);
}
});
}
if (this.iosAudioThread == null) {
this.iosAudioThread = new Thread(new Runnable() {
public void run() {
Logger.someLog("iosAudioThread_ id=" + Thread.currentThread().getId());
Process.setThreadPriority(-19);
while (!BoxProtocol.this.f2581E) {
try {
MegaBuffer a = BoxProtocol.this.f2579C.mo3482a();
if (a != null) {
for (C0735a a2 : BoxProtocol.this.f2580D) {
a2.mo3361a(a);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
Logger.someLog(Log.getStackTraceString(e));
return;
}
}
}
});
}
if (this.audioRecordThread == null) {
this.audioRecordThread = new Thread(new Runnable() {
public void run() {
Logger.someLog("audioRecordThread_ id=" + Thread.currentThread().getId());
Process.setThreadPriority(-19);
while (!BoxProtocol.this.f2581E) {
synchronized (C0735a.f2452b) {
if (!BoxProtocol.this.f2578B) {
try {
C0735a.f2452b.wait();
Thread.sleep((long) C0844k.f2899w);
} catch (InterruptedException e) {
e.printStackTrace();
Logger.someLog(Log.getStackTraceString(e));
}
}
}
if (BoxProtocol.this.f2581E) {
break;
} else if (BoxProtocol.this.f2578B && C0735a.f2452b.mo3794c() != 0) {
C0735a.f2452b.mo3788a();
MegaBuffer eVar = new MegaBuffer(C0735a.f2452b.mo3794c() + 12);
int unused = eVar.message.messageType = 7;
eVar.checkBufferCapacity();
ByteBuffer f = eVar.outputBuffer();
f.putInt(0, C0735a.f2453c);
f.putFloat(4, CropImageView.DEFAULT_ASPECT_RATIO);
f.putInt(8, 3);
eVar.possiblyPopulateMessage();
while (!BoxProtocol.this.f2581E && BoxProtocol.this.f2578B) {
if (C0735a.f2452b.mo3793b(eVar.dataBufferAsArray(), 12, eVar.lenght() - 12)) {
BoxProtocol.this.sendAudioRecord(eVar);
} else {
try {
Thread.sleep(10);
} catch (InterruptedException e2) {
e2.printStackTrace();
Logger.someLog(Log.getStackTraceString(e2));
}
}
}
C0735a.f2452b.mo3792b();
}
}
Logger.someLog("audioRecordThread_ Exit");
}
});
this.f2578B = false;
}
this.f2588g = new C0740b(context);
this.f2604x.start();
Logger.log("checkOpenThread_ started");
this.readThread.start();
Logger.log("readThread_ started");
this.audioRecordThread.start();
}
/* renamed from: t */
private void initBoundSize() {
int i;
int i2;
if (C0844k.f2886j == 0 || C0844k.f2887k == 0) {
int i3 = MainActivity.f2262a;
int i4 = MainActivity.f2263b;
if (C0844k.m4037f()) {
i = MainActivity.f2264c;
i2 = MainActivity.f2265d;
} else {
i = i3;
i2 = i4;
}
boolean z = true;
if (((float) i2) / ((float) i) > 0.9f) {
z = false;
}
Logger.log("BoxProtocol,initBoundSize: screen: " + i + " " + i2 + " bVerticalScreen=" + z);
if (z) {
if (i >= 800 && i2 >= 480) {
this.possibleWidth = i;
this.possibleHeight = i2;
} else if (((double) (((float) i) / ((float) i2))) > 1.7777777777777777d) {
this.possibleWidth = i;
this.possibleHeight = i2;
} else {
this.possibleWidth = 800;
this.possibleHeight = 480;
}
} else if (C0844k.f2885i) {
this.possibleWidth = 800;
this.possibleHeight = 720;
float f = ((float) MainActivity.f2265d) / ((float) MainActivity.f2264c);
if (f < 1.2f) {
this.possibleWidth = 800;
this.possibleHeight = 720;
} else if (f >= 1.2f && f < 1.5f) {
this.possibleWidth = 800;
this.possibleHeight = 960;
} else if (f >= 1.5f) {
this.possibleWidth = 720;
this.possibleHeight = 1280;
}
} else {
this.possibleWidth = 800;
this.possibleHeight = 480;
Logger.log("portrait screen use default size");
}
Logger.log("BoxProtocol,initBoundSize: New mVideoWidth=" + this.possibleWidth + ", mVideoHeight=" + this.possibleHeight);
C0844k.f2886j = this.possibleWidth;
C0844k.f2887k = this.possibleHeight;
Preferences.m4110d((Context) this.mContext.get(), this.possibleWidth, this.possibleHeight);
return;
}
this.possibleWidth = C0844k.f2886j;
this.possibleHeight = C0844k.f2887k;
Logger.log("BoxProtocol,initBoundSize: Old mVideoWidth=" + this.possibleWidth + ", mVideoHeight=" + this.possibleHeight);
}
/* renamed from: h */
public void setupSendThread() {
if (this.f2604x == null) {
this.f2604x = new Thread(new Runnable() {
public void run() {
final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
scheduledThreadPoolExecutor.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (BoxProtocol.this.f2581E) {
Logger.log("checkOpenThread_ bThreadExit ");
scheduledThreadPoolExecutor.shutdown();
} else if (!((Boolean) BoxProtocol.this.f2602v.bOpened()).booleanValue()) {
Logger.log("bOpened_ = false");
boolean gOpen = BoxProtocol.this.send_g_open();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Logger.log("Send g_Open = " + gOpen + " !!!");
} else {
Logger.log("bOpened_ = true , cancel timer");
if (!C0844k.f2901y) {
BoxProtocol.this.sendCarPlayCmd(13);
Logger.log("send CarPlay_OpenBoxAudioProcess");
}
BoxProtocol.this.sendConfig();
scheduledThreadPoolExecutor.shutdown();
Thread unused = BoxProtocol.this.f2604x = null;
}
}
}, 0, 1000, TimeUnit.MILLISECONDS);
}
});
}
}
/* renamed from: i */
public void setupHeartbeat() {
if (this.f2606z == null) {
this.f2606z = new ScheduledThreadPoolExecutor(1);
this.f2606z.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (BoxProtocol.this.f2581E) {
Logger.log("bThreadExit ");
BoxProtocol.this.f2606z.shutdown();
ScheduledExecutorService unused = BoxProtocol.this.f2606z = null;
} else if (((Boolean) BoxProtocol.this.f2602v.bOpened()).booleanValue()) {
Logger.someLog("send heart beat Start");
MegaBuffer eVar = new MegaBuffer(0);
int unused2 = eVar.message.messageType = 170;
int unused3 = eVar.message.length = 0;
eVar.checkBufferCapacity();
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("send heart beat err");
}
}
}
}
}, 0, 2000, TimeUnit.MILLISECONDS);
}
}
/* renamed from: j */
public void sendConfig() {
String d = getBluetoothAddress();
Logger.log("BoxProtocol,sendConfig: bluetoothAddress = " + d);
byte[] bytes = d.getBytes();
if (bytes.length >= 17 && sendBluetoothAddr(bytes)) {
Logger.log("BoxProtocol,sendConfig: Send Bluetooth Address Success");
}
byte[] bytes2 = Preferences.getBluetoothPin((Context) this.mContext.get()).getBytes();
if (bytes2.length == 4 && sendBluetoothAddress(bytes2)) {
Logger.log("BoxProtocol,sendConfig: Send Bluetooth Pin Code Success:" + new String(bytes2));
}
Logger.log("BoxProtocol,sendConfig: UploadLocalLogoPNGPublic");
copyIconsToBox();
UploadLocalLogoPNGPublic();
getAndUploadAirplayPrefs();
sendNightMode(Preferences.getNightMode((Context) this.mContext.get()));
setHandDriveMode(Preferences.getHandDriveMode((Context) this.mContext.get()));
sendChargeMode(Preferences.getChargeMode((Context) this.mContext.get()));
if (Logger.f2981a) {
sendDebugCmd(1);
}
sendCustomBoxBtName(this.f2596p);
sendCustomBoxWifiName(this.f2597q);
sendBoxName(getBoxNameProbably().getBytes());
}
/* renamed from: k */
public String getBoxNameProbably() {
if (!BuildConfig.FLAVOR.equals(this.f2596p)) {
return this.f2596p;
}
switch (7) {
case 7:
return "AutoKit";
default:
return "Auto Box";
}
}
/* renamed from: l */
public boolean send_g_open() {
this.f2601u.framerate = C0844k.f2894r;
if (C0844k.f2883g) {
this.f2601u.f2633a = 800;
this.f2601u.f2634b = 480;
setScreenDPI(160);
} else {
this.f2601u.f2633a = this.possibleWidth;
this.f2601u.f2634b = this.possibleHeight;
setScreenDPI(MainActivity.f2266e);
}
Logger.log("BoxProtocol,send_g_open: AutoPlay resolution and frame rate: " + (BuildConfig.FLAVOR + this.f2601u.f2633a + "x" + this.f2601u.f2634b + "@" + this.f2601u.framerate + "fps") + ", Config.bUseSoftDecode = " + C0844k.f2883g);
if (C0844k.m4034c()) {
set_AndroidWorkMode(PossibleVideoFrame.m3608b());
}
String a = C0844k.m4031a("ro.product.manufacturer", (String) null);
new File("/mnt/sdcard/EasyConnected/License.ini").exists();
Logger.someLog("BoxProtocol,send_g_open: manufacturer: " + a);
this.f2601u.f2638f = 255;
switch (7) {
case 7:
case 8:
this.f2601u.f2638f = 2;
break;
case 13:
this.f2601u.f2638f = 3;
break;
default:
this.f2601u.f2638f = C0844k.f2888l;
break;
}
Logger.log("BoxProtocol,send_g_open: g_Open.iBoxversion = " + this.f2601u.f2638f);
Logger.someLog("BoxProtocol,send_g_open: send_g_open() start ");
MegaBuffer eVar = new MegaBuffer(PossibleVideoFrame.m3610c());
int unused = eVar.message.messageType = 1;
int unused2 = eVar.message.length = PossibleVideoFrame.m3610c();
eVar.checkBufferCapacity();
byte[] d = this.f2601u.getPhoneWorkModeBytes();
System.arraycopy(d, 0, eVar.dataBufferAsArray(), 0, d.length);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,send_g_open: Write g_Open head err");
return false;
} else if (BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("BoxProtocol,send_g_open: success ");
return true;
} else {
Logger.someLog("BoxProtocol,send_g_open: Write g_Open data err");
return false;
}
}
}
/* renamed from: a */
public boolean sendAudioRecord(MegaBuffer eVar) {
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,send_audio_record: Write audioRecord head err");
return false;
} else if (BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
return true;
} else {
Logger.someLog("BoxProtocol,send_audio_record: Write audioRecord data err");
return false;
}
}
}
/* renamed from: a */
public boolean mo3430a(int i) {
if (i == 1) {
return sendCarPlayCmd(15);
}
return sendCarPlayCmd(7);
}
/* renamed from: b */
public boolean sendCarPlayCmd(int cmdCode) {
if (cmdCode == 202) {
if (this.f2584H != null) {
this.f2584H.mo3362a(true);
}
} else if (cmdCode == 201 && this.f2584H != null) {
this.f2584H.mo3362a(false);
}
if (!this.f2602v.bOpened().booleanValue()) {
Logger.someLog("BoxProtocol,send_carplay_cmd: failed: cmd=" + cmdCode);
return false;
}
Logger.someLog("BoxProtocol,send_carplay_cmd: start, cmd=" + cmdCode);
MegaBuffer eVar = new MegaBuffer(4);
eVar.message.messageType = 8;
eVar.message.length = 4;
eVar.checkBufferCapacity();
eVar.outputBuffer().putInt(0, cmdCode);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,send_carplay_cmd: Write carplay_cmd head err");
return false;
} else if (BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("BoxProtocol,send_carplay_cmd: success ");
return true;
} else {
Logger.someLog("BoxProtocol,send_carplay_cmd: Write carplay_cmd data err");
return false;
}
}
}
/* renamed from: a */
public boolean sendAutoConnByBtAddr(byte[] bArr) {
Logger.log("BoxProtocol,sendAutoConnByBtAddr: " + bArr.length);
if (bArr.length != 17) {
return false;
}
return sendDevInfo(17, bArr, 17);
}
/* renamed from: b */
public boolean sendBluetoothAddr(byte[] bArr) {
Logger.log("BoxProtocol,sendBluetoothAddr: " + bArr.length);
if (bArr.length != 17) {
return false;
}
return sendDevInfo(10, bArr, 17);
}
/* renamed from: c */
public boolean sendBluetoothAddress(byte[] bArr) {
Logger.log("BoxProtocol,sendBluetoothAddr: " + bArr.length);
if (bArr.length != 4) {
return false;
}
return sendDevInfo(12, bArr, 4);
}
/* renamed from: d */
public boolean msetBoxBluetoothName(byte[] bArr) {
Logger.log("BoxProtocol,setBoxBluetoothName: " + bArr.length);
if (bArr.length <= 16) {
return sendDevInfo(13, bArr, bArr.length);
}
Logger.log("BoxProtocol,setBoxBluetoothName: Bluetooth name is too long.");
return false;
}
/* renamed from: e */
public boolean setBoxWifiName(byte[] bArr) {
Logger.log("BoxProtocol,setBoxWifiName: " + bArr.length);
if (bArr.length <= 16) {
return sendDevInfo(14, bArr, bArr.length);
}
Logger.log("BoxProtocol,setBoxWifiName: Wifi name is too long.");
return false;
}
/* renamed from: a */
public boolean mo3436a(byte[] bArr, int i) {
return sendDevInfo(18, bArr, i);
}
/* renamed from: a */
public boolean sendCarManufacturerInfo(int i, int i2) {
Logger.log("BoxProtocol,sendCarManufacturerInfo: " + i + ", " + i2);
ByteBuffer allocate = ByteBuffer.allocate(8);
allocate.order(ByteOrder.LITTLE_ENDIAN);
allocate.putInt(0, i);
allocate.putInt(4, i2);
return sendDevInfo(20, allocate.array(), 8);
}
/* renamed from: a */
private boolean sendDevInfo(int i, byte[] bArr, int i2) {
Logger.log("BoxProtocol,sendDevInfo: " + bArr.length + " " + i2 + " " + this.f2602v.bOpened());
if (!this.f2602v.bOpened().booleanValue()) {
return false;
}
Logger.log("BoxProtocol,sendDevInfo: cmd=" + i);
MegaBuffer eVar = new MegaBuffer(i2);
int unused = eVar.message.messageType = i;
int unused2 = eVar.message.length = i2;
eVar.checkBufferCapacity();
System.arraycopy(bArr, 0, eVar.dataBufferAsArray(), 0, i2);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,sendDevInfo: Write device info head err");
return false;
} else if (BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("BoxProtocol,sendDevInfo: sendDevInfo() success ");
return true;
} else {
Logger.someLog("BoxProtocol,sendDevInfo: Write device info data err");
return false;
}
}
}
/* renamed from: c */
public boolean send_CarplayLogoType(int i) {
MegaBuffer eVar = new MegaBuffer(4);
int unused = eVar.message.messageType = 9;
int unused2 = eVar.message.length = 4;
eVar.checkBufferCapacity();
eVar.outputBuffer().putInt(0, i);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,send_CarplayLogoType: Write carplay_cmd head err");
return false;
} else if (!BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("BoxProtocol,send_CarplayLogoType: Write carplay_cmd data err");
return false;
} else {
Logger.someLog("BoxProtocol,send_CarplayLogoType: send_carplay_cmd() success, type=" + i);
return true;
}
}
}
/* renamed from: a */
public boolean upload_file_to_box(String str, byte[] content) {
Logger.m4219a("BoxProtocol,upload_file_to_box: Upload file " + str + " to Box, file content " + content.length + " byte");
byte[] bytes = str.getBytes();
int length = bytes.length;
int length2 = content.length;
MegaBuffer eVar = new MegaBuffer(length + 4 + 4 + length2);
int unused = eVar.message.messageType = 153;
int unused2 = eVar.message.length = length + 4 + 4 + length2;
eVar.checkBufferCapacity();
eVar.outputBuffer().putInt(0, length);
int i = 4;
int i2 = 0;
while (i2 < bytes.length) {
eVar.outputBuffer().put(i, bytes[i2]);
i2++;
i++;
}
eVar.outputBuffer().putInt(i, length2);
System.arraycopy(content, 0, eVar.dataBufferAsArray(), i + 4, length2);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,upload_file_to_box: Write carplay_cmd head err, boxFileName: " + str);
return false;
} else if (!BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("BoxProtocol,upload_file_to_box: Write carplay_cmd data err, boxFileName: " + str);
return false;
} else {
Logger.someLog("BoxProtocol,upload_file_to_box: upload_file_to_box: send_carplay_cmd() success , boxFileName: " + str);
return true;
}
}
}
/* renamed from: m */
public boolean setIphoneWorkMode() {
return upload_file_to_box("/tmp/iphone_work_mode\u0000", new byte[]{0});
}
/* renamed from: d */
public boolean set_AndroidWorkMode(int i) {
Logger.m4228c("BOX_TEST", "send_AndroidWorkMode() " + i);
if (PossibleVideoFrame.m3608b() == 3 && !this.f2600t) {
if (!uploadAssets((Context) this.mContext.get())) {
Logger.someLog("UploadAssets failed!");
} else {
this.f2600t = true;
}
}
return upload_file_to_box("/etc/android_work_mode\u0000", new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)});
}
/* renamed from: e */
public boolean sendChargeMode(int i) {
Logger.log("BoxProtocol,sendChargeMode: " + i);
return upload_file_to_box("/tmp/charge_mode\u0000", new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)});
}
/* renamed from: f */
public boolean sendBoxVerType(int i) {
Logger.m4226b("BoxProtocol", "sendBoxVerType: " + i);
return upload_file_to_box("/etc/box_version\u0000", new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)});
}
/* renamed from: g */
public boolean sendNightMode(int i) {
Logger.log("BoxProtocol,send_NightMode: " + i + " (0:day 1:night)");
return upload_file_to_box("/tmp/night_mode\u0000", new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)});
}
/* renamed from: h */
public boolean setHandDriveMode(int i) {
Logger.log("BoxProtocol,send_HandDriveMode: " + i + " (0:left 1:right)");
try {
return upload_file_to_box("/tmp/hand_drive_mode\u0000", new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)});
} catch (Exception e) {
Logger.someLog(Log.getStackTraceString(e));
return false;
}
}
/* renamed from: i */
public boolean setScreenDPI(int i) {
Logger.log("BoxProtocol,send_ScreenDPI: " + i);
try {
return upload_file_to_box("/tmp/screen_dpi\u0000", new byte[]{(byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255)});
} catch (Exception e) {
Logger.someLog(Log.getStackTraceString(e));
return false;
}
}
/* renamed from: j */
public boolean sendDebugCmd(int i) {
if (!this.f2602v.bOpened().booleanValue()) {
return false;
}
Logger.someLog("BoxProtocol,send_debug_cmd: send_debug_cmd() start, cmd=" + i);
MegaBuffer eVar = new MegaBuffer(4);
int unused = eVar.message.messageType = 136;
int unused2 = eVar.message.length = 4;
eVar.checkBufferCapacity();
eVar.outputBuffer().putInt(0, i);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("Write debug_cmd head err");
return false;
} else if (BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
return true;
} else {
Logger.someLog("Write debug_cmd data err");
return false;
}
}
}
/* renamed from: n */
public boolean sendManualDisconnect() {
if (!this.f2602v.bOpened().booleanValue()) {
return false;
}
Logger.someLog("BoxProtocol,send_manualDisconnect() start");
MegaBuffer eVar = new MegaBuffer(0);
int unused = eVar.message.messageType = 15;
int unused2 = eVar.message.length = 0;
eVar.checkBufferCapacity();
eVar.possiblyPopulateMessage();
synchronized (this) {
if (BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
return true;
}
Logger.someLog("Write send_manualDisconnect head err");
return false;
}
}
/* renamed from: o */
public boolean sendStopPhoneConnection() {
if (!this.f2602v.bOpened().booleanValue()) {
return false;
}
Logger.someLog("BoxProtocol,send_StopPhoneConnection() start");
MegaBuffer eVar = new MegaBuffer(0);
int unused = eVar.message.messageType = 21;
int unused2 = eVar.message.length = 0;
eVar.checkBufferCapacity();
eVar.possiblyPopulateMessage();
synchronized (this) {
if (BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
return true;
}
Logger.someLog("Write send_StopPhoneConnection head err");
return false;
}
}
/* renamed from: p */
public boolean sendAutoConnect() {
Logger.log("BoxProtocol,sendAutoConnect: cmd=1002");
return sendCarPlayCmd(1002);
}
/* renamed from: q */
public boolean getBluetoothOnlineList() {
Logger.log("BoxProtocol,getBluetoothOnlineList: 1013");
return sendCarPlayCmd(1013);
}
/* renamed from: a */
public void sendCustomBoxBtName(String str) {
Logger.log("BoxProtocol,sendCustomBoxBtName: oldName=" + str);
if (!BuildConfig.FLAVOR.equals(str)) {
String str2 = "AutoPlay";
switch (7) {
case 7:
case 8:
str2 = "AutoKit";
break;
}
int lastIndexOf = str.lastIndexOf("-");
if (lastIndexOf > 0 && lastIndexOf + 1 < str.length()) {
str2 = str2 + str.substring(lastIndexOf);
}
if (str.equals(str2)) {
return;
}
if (!msetBoxBluetoothName(str2.getBytes())) {
Logger.log("BoxProtocol,sendCustomBoxBtName: Failed!");
} else {
this.f2596p = str2;
}
}
}
/* renamed from: b */
public void sendCustomBoxWifiName(String str) {
Logger.log("BoxProtocol,sendCustomBoxWifiName: oldName=" + str);
if (!BuildConfig.FLAVOR.equals(str)) {
String str2 = "AutoKit";
int lastIndexOf = str.lastIndexOf("-");
if (lastIndexOf > 0 && lastIndexOf + 1 < str.length()) {
str2 = str2 + str.substring(lastIndexOf);
}
if (str.equals(str2)) {
return;
}
if (!setBoxWifiName(str2.getBytes())) {
Logger.log("BoxProtocol,sendCustomBoxWifiName: Failed!");
} else {
this.f2597q = str2;
}
}
}
/* renamed from: f */
public boolean sendBoxName(byte[] bArr) {
Logger.m4228c("BOX_TEST", "sendBoxName() " + bArr);
if (bArr.length <= 16) {
return upload_file_to_box("/etc/box_name\u0000", bArr);
}
Logger.log("BoxProtocol,sendBoxName: Box name is too long.");
return false;
}
/* renamed from: g */
public boolean sendCameraInfo(byte[] bArr) {
if (bArr == null) {
return false;
}
MegaBuffer eVar = new MegaBuffer(0);
int unused = eVar.message.messageType = 22;
int unused2 = eVar.message.length = bArr.length + 4;
eVar.checkBufferCapacity();
eVar.outputBuffer().putInt(0, 1);
System.arraycopy(bArr, 0, eVar.dataBufferAsArray(), 4, bArr.length);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("BoxProtocol,send_camera_info: Write head err");
return false;
} else if (BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
return true;
} else {
Logger.someLog("BoxProtocol,send_camera_info: Write data err");
return false;
}
}
}
/* access modifiers changed from: private */
/* renamed from: b */
public void onCmd(MegaBuffer eVar) {
UnsupportedEncodingException e;
String str;
UnsupportedEncodingException e2;
String str2;
String str3;
switch (eVar.message.messageType) {
case 1:
if (PossibleVideoFrame.m3610c() == eVar.lenght()) {
this.f2602v.mo3743a(true);
this.f2601u.mo3488a(eVar.outputBuffer());
int i = (this.f2601u.f2633a * this.f2601u.f2634b * 4) + 32 + 1024;
StringBuilder append = new StringBuilder().append("BoxProtocol,onCmd: Recv CMD_OPEN: ").append(eVar.lenght()).append(" ").append(this.f2601u.f2633a).append(" ").append(this.f2601u.f2634b).append(" ").append(this.f2601u.framerate).append(" ").append(this.f2601u.format).append(" ").append(this.f2601u.packetMax).append(" ");
PossibleVideoFrame dVar = this.f2601u;
Logger.someLog(append.append(PossibleVideoFrame.f2631g).toString());
if (this.f2601u.f2638f == 0) {
BoxInterface.m3483a(1, 123);
}
if (f2572b && C0735a.f2451a) {
mo3430a(0);
}
Logger.someLog("BoxProtocol,onCmd: Recv CMD_OPEN: g_Open.iBoxversion = " + this.f2601u.f2638f);
return;
} else if (eVar.lenght() == 0) {
send_g_open();
Logger.log("Resend g_Open!!");
return;
} else {
Logger.log("NULL!!!!!!");
return;
}
case 2:
this.f2591k = 0;
this.f2590j = 2;
this.f2593m = 0;
this.f2594n = 0;
if (eVar.lenght() == 4) {
f2576h = eVar.outputBuffer().getInt(0);
m3538m(f2576h);
} else if (eVar.lenght() == 8) {
f2576h = eVar.outputBuffer().getInt(0);
m3538m(f2576h);
f2575e = eVar.outputBuffer().getInt(4) == 1;
Logger.log("BoxProtocol,onCmd: Recv bWifiDeviceConected: " + f2575e);
}
Logger.log("BoxProtocol,onCmd: Recv CMD_PLUG, Phone Type: " + f2576h);
C0844k.f2899w = this.f2599s.mo3658e();
m3541v();
f2571a = true;
return;
case 3:
if (4 == eVar.lenght()) {
int i2 = eVar.outputBuffer().getInt(0);
Logger.log("BoxProtocol,onCmd: Recv CMD_PHASE iPhase = " + i2);
switch (i2) {
case 3:
BoxInterface.m3483a(1, 15);
return;
case 4:
BoxInterface.m3483a(1, 5);
return;
case 5:
BoxInterface.m3483a(1, 6);
return;
case 6:
BoxInterface.m3483a(1, 15);
return;
case 8:
BoxInterface.m3483a(1, 9);
BoxInterface.m3483a(1, 15);
this.f2588g.mo3371a(2, this.f2593m, this.f2594n, (byte[]) null, 0);
return;
case 10:
BoxInterface.m3483a(1, 9);
BoxInterface.m3483a(1, 15);
this.f2588g.mo3371a(2, this.f2593m, this.f2594n, (byte[]) null, 0);
return;
case 11:
BoxInterface.m3483a(1, 16);
return;
default:
return;
}
} else {
return;
}
case 4:
Logger.log("BoxProtocol,onCmd: CMD_PLUGOUT");
if (!(f2576h == -1 || this.f2588g == null)) {
this.f2588g.mo3371a(4, this.f2593m, this.f2594n, (byte[]) null, 0);
}
m3540u();
BoxInterface.m3483a(1, f2576h == -1 ? 0 : 2);
f2571a = false;
f2575e = false;
return;
case 6:
if (this.f2602v.bOpened().booleanValue()) {
int i3 = eVar.outputBuffer().getInt(0);
int i4 = eVar.outputBuffer().getInt(4);
int i5 = eVar.outputBuffer().getInt(8);
int i6 = i5 & 1;
int i7 = (i5 >> 2) & 3;
this.f2592l = (i5 >> 1) & 1;
switch (i7) {
case 0:
i7 = 2;
break;
case 1:
i7 = 1;
break;
case 2:
i7 = 4;
break;
}
if (i7 != this.f2590j) {
this.f2590j = i7;
if (1 == this.f2590j || 4 == this.f2590j) {
BoxInterface.m3483a(2, 0);
} else {
this.f2592l = 0;
BoxInterface.m3483a(2, 1);
}
}
if (this.f2591k != i6) {
this.f2591k = i6;
if (this.f2601u.format == 5) {
if (i6 == 0) {
if (!(f2576h == -1 || this.f2588g == null)) {
this.f2588g.mo3371a(9, i3, i4, (byte[]) null, 0);
}
} else if (!(f2576h == -1 || this.f2588g == null)) {
this.f2588g.mo3371a(10, i3, i4, (byte[]) null, 0);
}
Logger.log("COMPRESS_METHORD_H264 boffscreen= " + this.f2591k);
}
BoxInterface.m3483a(1, this.f2591k == 1 ? 10 : 11);
}
if (!(i3 == this.f2593m && i4 == this.f2594n)) {
this.f2593m = i3;
this.f2594n = i4;
BoxInterface.m3483a(3, 0);
if (!(this.f2601u.format != 5 || f2576h == -1 || this.f2588g == null)) {
Logger.someLog("new w h ");
this.f2588g.mo3371a(0, i3, i4, (byte[]) null, 0);
}
}
if (eVar.lenght() > 20 && this.f2589i) {
switch (this.f2601u.format) {
case 3:
if (f2576h == -1) {
int g = eVar.lenght() - 20;
byte[] bArr = new byte[(g + 32)];
ByteBuffer wrap = ByteBuffer.wrap(bArr);
wrap.order(ByteOrder.LITTLE_ENDIAN);
wrap.putInt(4, g + 36);
wrap.putInt(8, i3);
wrap.putInt(12, i4);
wrap.putInt(24, 131072);
System.arraycopy(eVar.dataBufferAsArray(), 20, bArr, 32, g);
BoxInterface.m3484a(bArr);
return;
}
return;
case 5:
if (f2576h != -1) {
int g2 = eVar.lenght() - 20;
if (this.f2588g != null) {
this.f2588g.mo3371a(1, i3, i4, eVar.dataBufferAsArray(), g2);
return;
}
return;
} else if (f2576h == -1) {
int g3 = eVar.lenght() - 20;
byte[] bArr2 = new byte[(g3 + 32)];
ByteBuffer wrap2 = ByteBuffer.wrap(bArr2);
wrap2.order(ByteOrder.LITTLE_ENDIAN);
wrap2.putInt(4, g3 + 36);
wrap2.putInt(8, i3);
wrap2.putInt(12, i4);
wrap2.putInt(24, 65536);
System.arraycopy(eVar.dataBufferAsArray(), 20, bArr2, 32, g3);
BoxInterface.m3484a(bArr2);
return;
} else {
return;
}
default:
return;
}
} else {
return;
}
} else {
return;
}
case 7:
case 255:
return;
case 8:
int i8 = eVar.outputBuffer().getInt(0);
Logger.someLog("BoxProtocol,onCmd: Recv CarPlay_CMD: " + i8);
switch (i8) {
case 1:
if (C0735a.f2451a) {
this.f2578B = true;
synchronized (C0735a.f2452b) {
C0735a.f2452b.notify();
Logger.someLog("Start record audio========");
}
return;
}
return;
case 2:
if (C0735a.f2451a) {
this.f2578B = false;
Logger.someLog("Stop record audio========");
return;
}
return;
case 3:
Logger.log("recv CarPlay_RequestHostUI...");
C0838a.m4006e(10);
if (!new File("/sdcard/carplay.png").exists()) {
BoxInterface.m3483a(4, 0);
}
if (f2576h == 5) {
C0838a.sendCarControl(200);
return;
}
return;
case 7:
C0735a.f2451a = true;
Logger.log("BoxProtocol,onCmd: ======Car Mic======");
BoxInterface.m3483a(1, (int) C0367a.C0377j.AppCompatTheme_tooltipFrameBackground);
return;
case 8:
C0735a.f2451a = false;
BoxInterface.m3483a(1, (int) C0367a.C0377j.AppCompatTheme_tooltipForegroundColor);
return;
case 9:
BoxInterface.m3483a(1, (int) C0367a.C0377j.AppCompatTheme_colorError);
return;
case 10:
BoxInterface.m3483a(1, 119);
sendCarPlayCmd(11);
return;
case 15:
Logger.someLog("Config.bUseBoxMic: " + C0844k.f2889m);
Logger.log("BoxProtocol,onCmd: ======Box Mic======");
f2572b = true;
BoxInterface.m3483a(1, (int) C0367a.C0377j.AppCompatTheme_tooltipFrameBackground);
C0735a.f2451a = !C0844k.f2889m;
return;
case 1000:
Logger.log("BoxProtocol,onCmd: Recv CarPlay_SupportWifi");
f2573c = true;
return;
case 1001:
f2574d = true;
BoxInterface.m3483a(1, 200);
return;
case 1003:
BoxInterface.m3483a(1, 201);
return;
case 1004:
BoxInterface.m3483a(1, 202);
return;
case 1005:
BoxInterface.m3483a(1, 203);
return;
case 1006:
BoxInterface.m3483a(1, 204);
return;
case 1007:
BoxInterface.m3483a(1, 205);
return;
case 1008:
BoxInterface.m3483a(1, 206);
return;
case 1009:
BoxInterface.m3483a(1, 207);
return;
case 1010:
BoxInterface.m3483a(1, 208);
return;
case 1011:
BoxInterface.m3483a(1, 209);
return;
case 1012:
Logger.log("BoxProtocol,onCmd: Recv CarPlay_SupportWifiNeedKo");
f2573c = true;
if (!this.f2598r) {
this.f2598r = true;
new ScheduledThreadPoolExecutor(1).schedule(new TimerTask() {
public void run() {
if (!BoxProtocol.this.uploadWifiModule((Context) BoxProtocol.this.mContext.get())) {
boolean unused = BoxProtocol.this.f2598r = false;
}
}
}, 1, TimeUnit.MILLISECONDS);
return;
}
return;
default:
return;
}
case 11:
if (ProtocolFrame.m3604a() == eVar.lenght()) {
ProtocolFrame cVar = new ProtocolFrame();
cVar.mo3487a(eVar.outputBuffer());
Logger.someLog("BoxProtocol,onCmd: Recv CMD_CARPLAY_MODE_CHANGE: " + eVar.lenght() + " " + cVar.arg1 + " " + cVar.arg2 + " " + cVar.arg3 + " " + cVar.arg4 + " " + cVar.arg5 + " " + cVar.arg6 + " " + cVar.arg7);
return;
}
return;
case 13:
if (eVar.lenght() <= 16) {
try {
str2 = new String(eVar.dataBufferAsArray(), 0, eVar.lenght() - 1, "ISO-8859-1");
try {
this.f2596p = str2;
} catch (UnsupportedEncodingException e3) {
e2 = e3;
Logger.someLog(Log.getStackTraceString(e2));
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_BLUETOOTH_NAME: " + str2);
return;
}
} catch (UnsupportedEncodingException e4) {
UnsupportedEncodingException unsupportedEncodingException = e4;
str2 = BuildConfig.FLAVOR;
e2 = unsupportedEncodingException;
Logger.someLog(Log.getStackTraceString(e2));
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_BLUETOOTH_NAME: " + str2);
return;
}
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_BLUETOOTH_NAME: " + str2);
return;
}
return;
case 14:
if (eVar.lenght() <= 16) {
try {
str = new String(eVar.dataBufferAsArray(), 0, eVar.lenght() - 1, "ISO-8859-1");
try {
this.f2597q = str;
} catch (UnsupportedEncodingException e5) {
e = e5;
Logger.someLog(Log.getStackTraceString(e));
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_WIFI_NAME: " + str);
return;
}
} catch (UnsupportedEncodingException e6) {
UnsupportedEncodingException unsupportedEncodingException2 = e6;
str = BuildConfig.FLAVOR;
e = unsupportedEncodingException2;
Logger.someLog(Log.getStackTraceString(e));
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_WIFI_NAME: " + str);
return;
}
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_WIFI_NAME: " + str);
return;
}
return;
case 18:
saveBluetoothPairList(eVar);
return;
case 19:
try {
this.f2595o = new String(eVar.dataBufferAsArray(), 0, eVar.lenght() - 1, "ISO-8859-1");
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BLUETOOTH_ONLINE_LIST: " + this.f2595o);
BoxInterface.m3483a(1, 211);
return;
} catch (Exception e7) {
Logger.someLog(Log.getStackTraceString(e7));
return;
}
case 22:
m3531c(eVar);
return;
case 136:
int i9 = eVar.outputBuffer().getInt(0);
Logger.someLog("recv CMD_DEBUG_TEST: " + i9);
switch (i9) {
}
return;
case 153:
saveFileFromBox(eVar);
return;
case 187:
if (4 == eVar.lenght()) {
int i10 = eVar.outputBuffer().getInt(0);
Logger.someLog("CMD_UPDATE: " + i10);
m3537l(i10);
return;
}
return;
case 204:
if (32 == eVar.lenght()) {
try {
str3 = new String(eVar.dataBufferAsArray(), 0, 18, "ISO-8859-1");
} catch (UnsupportedEncodingException e8) {
e8.printStackTrace();
Logger.someLog(Log.getStackTraceString(e8));
str3 = "unknown";
}
Logger.someLog("BoxProtocol,onCmd: Recv CMD_BOX_SOFTWARE_VERSION: " + str3);
C0844k.f2878b = "BOX:" + str3;
if (f2573c) {
C0844k.f2878b += "W";
}
BoxInterface.m3483a(1, 124);
return;
}
return;
default:
Logger.log("Unknown cmd = " + eVar.message.messageType);
return;
}
}
/* renamed from: l */
private void m3537l(int i) {
switch (i) {
case 1:
BoxInterface.m3483a(1, 120);
return;
case 2:
BoxInterface.m3483a(1, 121);
return;
case 3:
BoxInterface.m3483a(1, 122);
return;
case 5:
BoxInterface.m3483a(1, 125);
return;
case 6:
BoxInterface.m3483a(1, 126);
return;
case 7:
BoxInterface.m3483a(1, 127);
return;
default:
return;
}
}
/* renamed from: b */
private void someSortOfCopyEvent(byte[] bArr, int i) {
System.arraycopy(bArr, i, this.f2585I, 0, this.f2585I.length);
}
/* renamed from: r */
public byte[] mo3473r() {
return this.f2585I;
}
/* renamed from: c */
private void m3531c(MegaBuffer eVar) {
if (eVar.lenght() >= 4) {
switch (eVar.outputBuffer().getInt(0)) {
case 2:
if (eVar.lenght() - 4 == this.f2585I.length) {
someSortOfCopyEvent(eVar.dataBufferAsArray(), 4);
BoxInterface.m3483a(1, 29);
return;
}
return;
case 3:
Logger.log("Open camera");
BoxInterface.m3483a(1, 30);
return;
case 4:
Logger.log("Close camera");
BoxInterface.m3483a(1, 31);
return;
default:
return;
}
}
}
/* renamed from: d */
private void saveBluetoothPairList(MegaBuffer eVar) {
Context context = (Context) this.mContext.get();
if (context != null) {
File filesDir = context.getFilesDir();
if (filesDir.exists() && filesDir.isDirectory()) {
try {
int g = eVar.lenght() - 1;
String str = new String(eVar.dataBufferAsArray(), 0, g, "UTF-8");
Logger.log("BoxProtocol,saveBluetoothPairList: " + str);
Logger.log("BoxProtocol,saveBluetoothPairList: " + g);
FileOutputStream fileOutputStream = new FileOutputStream(filesDir.getAbsolutePath() + "bluetooth_pair_list");
fileOutputStream.write(str.getBytes(), 0, g);
fileOutputStream.close();
BoxInterface.m3483a(1, 210);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/* renamed from: e */
private void saveFileFromBox(MegaBuffer eVar) {
String c = C0883k.getPhoneDataPath();
File file = new File(c);
if (!file.exists() || !file.isDirectory()) {
Logger.someLog("BoxProtocolsaveFileFromBox: Sdcard does not exist !!!");
return;
}
try {
int i = eVar.outputBuffer().getInt(0);
String str = new String(eVar.dataBufferAsArray(), 4, i - 1, "ISO-8859-1");
int i2 = i + 4;
int i3 = eVar.outputBuffer().getInt(i2);
int i4 = i2 + 4;
String substring = str.substring(str.lastIndexOf("/") + 1);
String str2 = c + "/" + substring;
if (substring.toLowerCase().contains("log")) {
C0844k.f2881e = c + "/hwbox.log";
str2 = C0844k.f2881e;
}
Logger.m4219a("BoxProtocol,saveFileFromBox: Recv file " + substring + " from Box, file content " + i3 + " byte");
Logger.m4222a(eVar.dataBufferAsArray(), i4, i3, str2);
} catch (Exception e) {
Logger.someLog("BoxProtocol, saveFileFromBox: \n" + Log.getStackTraceString(e));
}
}
/* renamed from: a */
public void sendTouch(int action, int i2, int x, int y) {
if (this.f2602v.bOpened().booleanValue()) {
MegaBuffer eVar = new MegaBuffer(16);
int unused = eVar.message.messageType = 5;
eVar.checkBufferCapacity();
switch (action) {
case 0:
eVar.outputBuffer().putInt(0, 14); //Down
break;
case 1:
eVar.outputBuffer().putInt(0, 15); //Move
break;
case 2:
eVar.outputBuffer().putInt(0, 16); //Up
break;
}
eVar.outputBuffer().putInt(0, eVar.outputBuffer().getInt(0) | (i2 << 8));
eVar.outputBuffer().putInt(4, x);
eVar.outputBuffer().putInt(8, y);
eVar.outputBuffer().putInt(12, this.f2590j | (this.f2591k << 16));
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("Send touch head err");
} else if (!BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("Send touch data err");
}
}
}
}
/* renamed from: a */
public void sendMultiTouch(C0760d dVar) {
if (this.f2602v.bOpened().booleanValue()) {
MegaBuffer eVar = new MegaBuffer(dVar.mo3424a());
int unused = eVar.message.messageType = 23;
eVar.checkBufferCapacity();
dVar.mo3425a(eVar.outputBuffer(), 0);
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("Send multi touch head err");
} else if (!BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("Send multi touch data err");
}
}
}
}
/* renamed from: k */
public void sendCommand(int i) {
if (this.f2602v.bOpened().booleanValue()) {
MegaBuffer eVar = new MegaBuffer(16);
int unused = eVar.message.length = 16;
int unused2 = eVar.message.messageType = 5;
eVar.checkBufferCapacity();
switch (i) {
case 0:
eVar.outputBuffer().putInt(0, 11);
break;
case 1:
eVar.outputBuffer().putInt(0, 12);
break;
case 2:
eVar.outputBuffer().putInt(0, 13);
break;
default:
return;
}
eVar.possiblyPopulateMessage();
synchronized (this) {
if (!BoxInterface.possiblySendMessage(eVar.possiblyHeaderBufferAsArray(), eVar.possibleLength())) {
Logger.someLog("Send commadn head err");
} else if (!BoxInterface.possiblySendMessage(eVar.dataBufferAsArray(), eVar.lenght())) {
Logger.someLog("Send command data err");
}
}
}
}
/* renamed from: u */
private void m3540u() {
if (C0735a.f2451a) {
this.f2578B = false;
}
for (C0735a c : this.f2580D) {
c.mo3363c();
}
}
/* renamed from: s */
public void destroy() {
this.f2581E = true;
this.f2593m = 0;
this.f2594n = 0;
if (this.f2579C != null) {
this.f2579C.mo3483b();
this.f2579C = null;
}
try {
if (this.f2606z != null) {
this.f2606z.shutdown();
}
if (this.f2604x != null) {
this.f2604x.join();
}
if (this.readThread != null) {
this.readThread.join();
}
if (this.iosAudioThread != null) {
this.iosAudioThread.join();
}
if (this.audioRecordThread != null) {
synchronized (C0735a.f2452b) {
C0735a.f2452b.notify();
}
this.audioRecordThread.join();
}
this.f2606z = null;
this.readThread = null;
this.f2604x = null;
this.iosAudioThread = null;
this.audioRecordThread = null;
} catch (InterruptedException e) {
try {
e.printStackTrace();
Logger.someLog(Log.getStackTraceString(e));
} finally {
this.f2606z = null;
this.readThread = null;
this.f2604x = null;
this.iosAudioThread = null;
this.audioRecordThread = null;
}
}
for (C0735a d : this.f2580D) {
d.mo3364d();
}
this.f2580D.clear();
if (this.f2588g != null) {
this.f2588g.mo3373b();
}
this.f2588g = null;
Logger.someLog("Boxprotocol destroy()");
}
/* renamed from: v */
private void m3541v() {
BoxInterface.m3483a(1, 4);
for (int i = 0; i < 10 && !MainActivity.f2270m; i++) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (f2576h == -1) {
BoxInterface.m3483a(1, 1);
} else if (this.f2586J) {
BoxInterface.m3483a(1, 3);
this.f2586J = true;
} else {
this.f2586J = false;
}
if (f2576h != -1 && this.f2588g != null) {
this.f2588g.mo3371a(3, this.f2593m, this.f2594n, (byte[]) null, 0);
}
}
/* renamed from: cn.manstep.phonemirrorBox.b.e$c */
public static class ProtocolFrame {
/* renamed from: a */
public int arg1 = 0;
/* renamed from: b */
public int arg2 = 0;
/* renamed from: c */
public int arg3 = 1;
/* renamed from: d */
public int arg4 = 2;
/* renamed from: e */
public int arg5 = 0;
/* renamed from: f */
public int arg6 = 0;
/* renamed from: g */
public int arg7 = 0;
/* renamed from: h */
private ByteBuffer f2630h = ByteBuffer.allocate(m3604a());
public ProtocolFrame() {
this.f2630h.order(ByteOrder.LITTLE_ENDIAN);
}
/* renamed from: a */
public static int m3604a() {
return 28;
}
/* renamed from: a */
public void mo3487a(ByteBuffer byteBuffer) {
this.arg1 = byteBuffer.getInt(0);
this.arg2 = byteBuffer.getInt(4);
this.arg3 = byteBuffer.getInt(8);
this.arg4 = byteBuffer.getInt(12);
this.arg5 = byteBuffer.getInt(16);
this.arg6 = byteBuffer.getInt(20);
this.arg7 = byteBuffer.getInt(24);
}
}
/* renamed from: m */
private void m3538m(int i) {
switch (i) {
case 1:
this.f2599s = new C0830b(i, 17, 18);
return;
case 3:
this.f2599s = new C0831c(i, 5, 2);
return;
case 4:
this.f2599s = new C0833e(i, 15, 16);
return;
case 5:
this.f2599s = new C0829a(i, 1, 2);
return;
case 6:
C0844k.f2898v = 1;
this.f2599s = new C0832d(i, 22, 23);
return;
default:
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment