360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0
以下内容为反编译后的 ae.java 源代码,内容仅作参考
package com.qihoo360.mobilesafe.pcdaemon;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.FileUtils;
import android.os.StatFs;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import com.qihoo.appstore.clear.ClearBackgroundHelper;
import com.qihoo360.mobilesafe.pcdaemon.data.ACSIITextPdu;
import com.qihoo360.mobilesafe.pcdaemon.data.FilePdu;
import com.qihoo360.mobilesafe.pcdaemon.data.InputStreamPdu;
import com.qihoo360.mobilesafe.pcdaemon.data.PduBase;
import com.qihoo360.mobilesafe.ui.index.MobileSafeApplication;
import com.qihoo360.mobilesafe.util.PatchUtil;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.codec.binary.Base64;
public class ae extends r {
PackageManager f5451a;
public ae(Context context) {
super(context);
this.f5451a = null;
this.f5451a = context.getPackageManager();
}
private File a(File file) {
File parentFile = file.getParentFile();
return parentFile.exists() ? parentFile : a(parentFile);
}
private void a(Context context, String str) {
try {
ContentResolver contentResolver = context.getContentResolver();
com.qihoo360.mobilesafe.util.aj.a("FileHandle", "deleteFileFromMediaLib deleted=" + (contentResolver.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "LOWER(_data)=?", new String[]{str.toLowerCase()}) + contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "LOWER(_data)=?", new String[]{str.toLowerCase()}) + 0 + contentResolver.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "LOWER(_data)=?", new String[]{str.toLowerCase()})) + ",path=" + str);
} catch (Throwable th) {
com.qihoo360.mobilesafe.util.aj.a("FileHandle", "deleteFileFromMediaLib", th);
}
}
private void a(File file, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
File[] listFiles;
if (file.isDirectory() && (listFiles = file.listFiles()) != null && listFiles.length > 0) {
for (File file2 : listFiles) {
if (file2.isDirectory()) {
a(file2, aVar);
} else {
boolean delete = file2.delete();
if (delete) {
a(this.f, file2.getAbsolutePath());
}
if (!aVar.a(ACSIITextPdu.a("RET_FILE_RM:PROGRESS:" + file2.getPath() + ":" + delete))) {
throw new RuntimeException("Socket is closed by client");
}
}
}
}
boolean delete2 = file.delete();
if (delete2) {
a(this.f, file.getAbsolutePath());
}
if (!aVar.a(ACSIITextPdu.a("RET_FILE_RM:PROGRESS:" + file.getPath() + ":" + delete2))) {
throw new RuntimeException("Socket is closed by client");
}
}
private void a(File file, File file2, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
if (!file2.exists()) {
file2.mkdirs();
}
File[] listFiles = file.listFiles();
if (listFiles == null || listFiles.length <= 0) {
return;
}
for (File file3 : listFiles) {
if (file3.isDirectory()) {
try {
StatFs statFs = new StatFs(file2.getPath());
long blockSize = statFs.getBlockSize() * statFs.getAvailableBlocks();
if (ClearBackgroundHelper.SIZE_K >= blockSize) {
com.qihoo360.mobilesafe.util.aj.a("FileHandle", "Abort copy:have no enough space:" + blockSize);
throw new RuntimeException("NO_ENOUGH_SPACE");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
a(file3, new File(file2, file3.getName()), aVar);
} else {
try {
StatFs statFs2 = new StatFs(file2.getPath());
long blockSize2 = statFs2.getBlockSize() * statFs2.getAvailableBlocks();
if (file3.length() + ClearBackgroundHelper.SIZE_K >= blockSize2) {
com.qihoo360.mobilesafe.util.aj.a("FileHandle", "Abort copy:have no enough space:" + blockSize2);
throw new RuntimeException("NO_ENOUGH_SPACE");
break;
}
} catch (Exception e2) {
e2.printStackTrace();
}
File file4 = new File(file2, file3.getName());
if (file4.exists()) {
aVar.a(ACSIITextPdu.a("RET_FILE_CP:PROGRESS:" + file.getPath() + ":DST_HAS_EXISTS"));
} else if (file3.canRead() && !b(file3, file4, aVar)) {
throw new RuntimeException("Copy file fail");
}
}
}
}
private void a(String str, String str2) {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "saveToDbByBroadcast.savePath = " + str + ", jsonStr = " + str2, new Object[0]);
}
try {
Intent intent = new Intent("com.qihoo360.mobilesafe.pcdaemon.filehandle");
intent.putExtra("path", str);
intent.putExtra("json", str2);
this.f.startService(intent);
} catch (Exception e) {
}
}
private PduBase b(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
String[] d = pduBase.d();
String str = (d == null || d.length <= 0) ? null : new String(Base64.decodeBase64(d[0].getBytes()));
if (TextUtils.isEmpty(str)) {
return new ACSIITextPdu("RET_PUSH_DOWNLOAD_FILE:ERR_FAILED:");
}
String str2 = d.length > 1 ? new String(Base64.decodeBase64(d[1].getBytes())) : null;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "doPushDownloadFile.jsonStr = " + str, new Object[0]);
}
a(str2, str);
return new ACSIITextPdu("RET_PUSH_DOWNLOAD_FILE:OK:");
} catch (Exception e) {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
e.printStackTrace();
}
return new ACSIITextPdu("RET_PUSH_DOWNLOAD_FILE:ERR_FAILED:");
}
}
private boolean b(File file, File file2, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
AtomicLong atomicLong = new AtomicLong(file.length());
AtomicLong atomicLong2 = new AtomicLong(0L);
AtomicBoolean atomicBoolean = new AtomicBoolean(true);
AtomicBoolean atomicBoolean2 = new AtomicBoolean(false);
AtomicBoolean atomicBoolean3 = new AtomicBoolean(true);
af afVar = new af(this, file, file2, atomicBoolean2, atomicLong2, atomicBoolean3, atomicBoolean);
if (atomicLong.get() < ClearBackgroundHelper.SIZE_M) {
afVar.run();
} else {
new Thread(afVar).start();
}
long j = 0;
while (true) {
if (!atomicBoolean.get()) {
break;
}
try {
Thread.sleep(100L);
} catch (Exception e) {
}
if (atomicLong2.get() != j) {
j = atomicLong2.get();
if (!aVar.a(ACSIITextPdu.a("RET_FILE_CP:PROGRESS:" + file.getPath() + ":" + file2.getPath() + ":" + atomicLong2.get() + "/" + atomicLong.get()))) {
atomicBoolean2.set(true);
atomicBoolean3.set(false);
break;
}
}
}
if (atomicBoolean3.get()) {
aVar.a(ACSIITextPdu.a("RET_FILE_CP:PROGRESS:" + file.getPath() + ":" + file2.getPath() + ":" + atomicLong2.get() + "/" + atomicLong.get()));
}
return atomicBoolean3.get();
}
private PduBase c(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
if (!PatchUtil.a()) {
throw new w();
}
String[] d = pduBase.d();
String str = null;
if (d != null && d.length > 0) {
str = d[0];
}
if (TextUtils.isEmpty(str)) {
throw new w("ERR_INVALID_ARGUMENT:");
}
String a2 = PatchUtil.a(this.f.getPackageManager().getPackageInfo(str, 0).applicationInfo.publicSourceDir);
if (TextUtils.isEmpty(a2)) {
throw new w();
}
return new ACSIITextPdu("RET_FILE_GET_APKMD5:OK:" + a2);
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_GET_APKMD5:ERR_FAILED:" + e.getMessage());
}
}
private PduBase d(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
String str;
String str2 = null;
try {
if (!PatchUtil.a()) {
throw new w();
}
String[] d = pduBase.d();
if (d == null || d.length <= 1) {
str = null;
} else {
str = d[0];
str2 = d[1];
}
if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
throw new w("ERR_INVALID_ARGUMENT:");
}
String str3 = this.f.getPackageManager().getPackageInfo(str, 0).applicationInfo.publicSourceDir;
File file = new File(str2);
String str4 = file.getParent() + "/merged_" + file.getName() + ".apk";
if (PatchUtil.patch(0, str2, str3, str4) == 0) {
return new ACSIITextPdu("RET_FILE_MERGE_APK:OK:" + str4);
}
throw new w();
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_MERGE_APK:ERR_FAILED:" + e.getMessage());
}
}
private PduBase e(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
ACSIITextPdu aCSIITextPdu;
try {
String[] split = pduBase.f().split(" ");
if (split.length <= 1) {
aCSIITextPdu = new ACSIITextPdu("RET_MOVE_FILE:ERR_FAILED:");
} else {
File file = new File(split[0]);
File file2 = new File(split[1]);
boolean isFile = file.isFile();
if (TextUtils.isEmpty(com.qihoo360.mobilesafe.d.a.a((File) null, "mv", split[0], split[1]))) {
if (isFile) {
try {
a(this.f, file.getAbsolutePath());
String absolutePath = file2.isFile() ? file2.getAbsolutePath() : new File(file2.getAbsoluteFile(), file.getName()).getAbsolutePath();
if (absolutePath != null) {
com.qihoo360.mobilesafe.util.r.b(this.f, absolutePath, null);
}
} catch (Exception e) {
}
}
aCSIITextPdu = new ACSIITextPdu("RET_MOVE_FILE:OK:");
} else {
aCSIITextPdu = new ACSIITextPdu("RET_MOVE_FILE:ERR_FAILED:");
}
}
return aCSIITextPdu;
} catch (Exception e2) {
e2.printStackTrace();
return new ACSIITextPdu("RET_MOVE_FILE:ERR_FAILED:");
}
}
private PduBase f(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
String str;
ACSIITextPdu aCSIITextPdu;
try {
File file = new File(pduBase.f());
if (file.exists()) {
try {
boolean delete = file.delete();
String str2 = "RET_DELETE_FILE:" + (delete ? "OK:" : "ERR_FAILED:");
if (delete) {
a(this.f, file.getPath());
}
str = str2;
} catch (Exception e) {
str = "RET_DELETE_FILE:ERR_FAILED:";
}
aCSIITextPdu = new ACSIITextPdu(str);
} else {
aCSIITextPdu = new ACSIITextPdu("RET_DELETE_FILE:ERR_NOT_FOUND:");
}
return aCSIITextPdu;
} catch (Exception e2) {
return new ACSIITextPdu("RET_DELETE_FILE:ERR_FAILED:");
}
}
private PduBase g(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
return ACSIITextPdu.a("RET_FILE_BEGIN:OK:");
}
private PduBase h(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
ACSIITextPdu a2;
try {
String[] split = new String(pduBase.d).split(":");
if (split.length != 3) {
a2 = ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:PRM_INVALID");
} else {
String str = split[1];
String str2 = split[2];
if (TextUtils.isEmpty(str)) {
a2 = ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:MODE_IS_INVALID");
} else if (TextUtils.isEmpty(str2)) {
a2 = ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:DST_IS_INVALID");
} else {
int c = com.qihoo360.mobilesafe.util.aj.c(str);
if (c < 0) {
a2 = ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:MODE_IS_INVALID");
} else if (new File(str2).exists()) {
int permissions = FileUtils.setPermissions(str2, c, -1, -1);
a2 = permissions == 0 ? ACSIITextPdu.a("RET_FILE_CHMOD:OK:") : ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:" + permissions);
} else {
a2 = ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:DST_NOT_EXISTS");
}
}
}
return a2;
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_CHMOD:ERR_FAILED:" + e.getClass().getSimpleName() + " " + e.getMessage());
}
}
private PduBase i(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
PduBase a2;
try {
String f = pduBase.f();
if (TextUtils.isEmpty(f)) {
a2 = ACSIITextPdu.a("RET_FILE_INFO:ERR_FAILED:DST_IS_INVALID");
} else {
File file = new File(f);
a2 = !file.exists() ? ACSIITextPdu.a("RET_FILE_INFO:ERR_FAILED:DST_NOT_EXISTS") : new InputStreamPdu("RET_FILE_INFO:OK:", new ByteArrayInputStream(com.qihoo360.mobilesafe.businesscard.c.a.a.a(file, true).a().getBytes(com.qihoo360.mobilesafe.a.a.f5314b)));
}
return a2;
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_INFO:ERR_FAILED:" + e.getClass().getSimpleName() + " " + e.getMessage());
}
}
private PduBase j(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
String f = pduBase.f();
return TextUtils.isEmpty(f) ? ACSIITextPdu.a("RET_FILE_EXISTS:ERR_FAILED:DST_IS_INVALID") : new File(f).exists() ? ACSIITextPdu.a("RET_FILE_EXISTS:OK:TRUE") : ACSIITextPdu.a("RET_FILE_EXISTS:OK:FALSE");
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_EXISTS:ERR_FAILED:" + e.getClass().getSimpleName() + " " + e.getMessage());
}
}
private PduBase k(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
ACSIITextPdu a2;
try {
String[] split = new String(pduBase.d).split(":");
if (split.length != 3) {
a2 = ACSIITextPdu.a("RET_FILE_RENAME:ERR_FAILED:PRM_INVALID");
} else {
String str = split[1];
String str2 = split[2];
if (TextUtils.isEmpty(str)) {
a2 = ACSIITextPdu.a("RET_FILE_RENAME:ERR_FAILED:SRC_IS_INVALID");
} else if (TextUtils.isEmpty(str2)) {
a2 = ACSIITextPdu.a("RET_FILE_RENAME:ERR_FAILED:DST_IS_INVALID");
} else {
File file = new File(str);
File file2 = new File(str2);
if (file.exists()) {
boolean isFile = file.isFile();
if (file.renameTo(file2)) {
if (isFile) {
try {
a(this.f, file.getAbsolutePath());
String absolutePath = file2.isFile() ? file2.getAbsolutePath() : new File(file2.getAbsoluteFile(), file.getName()).getAbsolutePath();
if (absolutePath != null) {
com.qihoo360.mobilesafe.util.r.b(this.f, absolutePath, null);
}
} catch (Exception e) {
}
}
a2 = ACSIITextPdu.a("RET_FILE_RENAME:OK:");
} else {
a2 = ACSIITextPdu.a("RET_FILE_RENAME:ERR_FAILED:");
}
} else {
a2 = ACSIITextPdu.a("RET_FILE_RENAME:ERR_FAILED:SRC_NOT_EXISTS");
}
}
}
return a2;
} catch (Exception e2) {
return ACSIITextPdu.a("RET_FILE_RENAME:ERR_FAILED:" + e2.getClass().getSimpleName() + " " + e2.getMessage());
}
}
private PduBase l(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
boolean z;
File file;
File parentFile;
try {
String[] split = new String(pduBase.d).split(":");
if (split.length != 4 && split.length != 3) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:PRM_INVALID");
}
String str = split[1];
String str2 = split[2];
if (split.length == 4) {
String str3 = split[3];
z = !TextUtils.isEmpty(str3) && "OVER_FILE".equalsIgnoreCase(str3);
} else {
z = false;
}
if (TextUtils.isEmpty(str)) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:SRC_IS_INVALID");
}
if (TextUtils.isEmpty(str2)) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:DST_IS_INVALID");
}
File file2 = new File(str);
File file3 = new File(str2);
if (!file2.exists()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:SRC_NOT_EXISTS");
}
if (!file2.isFile()) {
if (file3.exists() && file3.isFile()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:DST_IS_FILE");
}
if ((file3.exists() || file3.mkdirs()) && file3.canWrite()) {
if (!file2.canRead()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:SRC_NOT_BE_READ");
}
aVar.a(ACSIITextPdu.a("RET_FILE_CP:STARTING:"));
a(file2, file3, aVar);
return ACSIITextPdu.a("RET_FILE_CP:OK:");
}
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:DST_READ_ONLY");
}
if (file3.exists()) {
if (!file3.canWrite()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:DST_READ_ONLY");
}
if (!file3.isFile()) {
file = new File(file3, file2.getName());
if (file.exists() && z) {
file.delete();
}
parentFile = file.getParentFile();
if ((!parentFile.exists() || parentFile.mkdirs()) && a(file).canWrite()) {
if (file2.canRead()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:SRC_NOT_BE_READ");
}
if (file.exists()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:DST_HAS_EXISTS");
}
StatFs statFs = new StatFs(file.getParent());
if (statFs.getBlockSize() * statFs.getAvailableBlocks() <= file2.length()) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:NO_ENOUGH_SPACE");
}
aVar.a(ACSIITextPdu.a("RET_FILE_CP:STARTING:"));
return ACSIITextPdu.a("RET_FILE_CP:" + (b(file2, file, aVar) ? "OK:" : "ERR_FAILED:"));
}
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:DST_READ_ONLY");
}
}
file = file3;
if (file.exists()) {
file.delete();
}
parentFile = file.getParentFile();
if (!parentFile.exists()) {
}
if (file2.canRead()) {
}
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_CP:ERR_FAILED:" + e.getMessage());
}
}
private PduBase m(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
String[] split = new String(pduBase.d).split(":");
if (split.length != 3) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:PRM_INVALID");
}
String str = split[1];
String str2 = split[2];
if (TextUtils.isEmpty(str)) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:SRC_IS_INVALID");
}
if (TextUtils.isEmpty(str2)) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:DST_IS_INVALID");
}
File file = new File(str);
File file2 = new File(str2);
if (!file.exists()) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:SRC_NOT_EXISTS");
}
if (file2.exists() && !file2.canWrite()) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:DST_READ_ONLY");
}
if (!file.canRead()) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:SRC_NOT_BE_READ");
}
if (!file.canWrite()) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:SRC_NOT_BE_WRITE");
}
if (file2.exists() && file2.isFile()) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:DST_HAS_EXISTS");
}
boolean isFile = file.isFile();
String a2 = com.qihoo360.mobilesafe.d.a.a((File) null, "mv", file.getPath(), file2.getPath());
if (TextUtils.isEmpty(a2) && isFile) {
try {
a(this.f, file.getAbsolutePath());
String absolutePath = file2.isFile() ? file2.getAbsolutePath() : new File(file2.getAbsoluteFile(), file.getName()).getAbsolutePath();
if (absolutePath != null) {
com.qihoo360.mobilesafe.util.r.b(this.f, absolutePath, null);
}
} catch (Exception e) {
}
}
return ACSIITextPdu.a("RET_FILE_MV:" + (TextUtils.isEmpty(a2) ? "OK:" : "ERR_FAILED:" + a2));
} catch (Exception e2) {
return ACSIITextPdu.a("RET_FILE_MV:ERR_FAILED:" + e2.getClass().getSimpleName() + " " + e2.getMessage());
}
}
private PduBase n(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
String f = pduBase.f();
if (TextUtils.isEmpty(f)) {
return ACSIITextPdu.a("RET_FILE_RM:ERR_FAILED:SRC_IS_INVALID");
}
File file = new File(f);
if (!file.exists()) {
return ACSIITextPdu.a("RET_FILE_RM:ERR_FAILED:SRC_NOT_EXISTS");
}
if (!file.isDirectory()) {
if (!file.canWrite()) {
return ACSIITextPdu.a("RET_FILE_RM:ERR_FAILED:SRC_NOT_BE_WRITE");
}
boolean delete = file.delete();
if (delete) {
a(this.f, f);
}
return ACSIITextPdu.a("RET_FILE_RM:" + (delete ? "OK:" : "ERR_FAILED:SRC_NOT_BE_WRITE"));
}
if (!file.canRead()) {
return ACSIITextPdu.a("RET_FILE_RM:ERR_FAILED:SRC_NOT_BE_READ");
}
if (!file.canWrite()) {
return ACSIITextPdu.a("RET_FILE_RM:ERR_FAILED:SRC_NOT_BE_WRITE");
}
aVar.a(ACSIITextPdu.a("RET_FILE_RM:STARTING:"));
a(file, aVar);
return ACSIITextPdu.a("RET_FILE_RM:OK:");
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_RM:ERR_FAILED:" + e.getClass().getSimpleName() + " " + e.getMessage());
}
}
private PduBase o(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
ACSIITextPdu a2;
try {
String f = pduBase.f();
if (TextUtils.isEmpty(f)) {
a2 = ACSIITextPdu.a("RET_FILE_MKDIRS:ERR_FAILED:DST_IS_INVALID");
} else {
File file = new File(f);
if (file.exists()) {
a2 = ACSIITextPdu.a("RET_FILE_MKDIRS:ERR_FAILED:DST_HAS_EXISTS");
} else {
File a3 = a(file);
a2 = (!a3.exists() || a3.canWrite()) ? file.mkdirs() ? ACSIITextPdu.a("RET_FILE_MKDIRS:OK:") : ACSIITextPdu.a("RET_FILE_MKDIRS:ERR_FAILED:") : ACSIITextPdu.a("RET_FILE_MKDIRS:ERR_FAILED:SRC_NOT_BE_WRITE");
}
}
return a2;
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_MKDIRS:ERR_FAILED:" + e.getClass().getSimpleName() + " " + e.getMessage());
}
}
private PduBase p(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
String[] d = pduBase.d();
String str = null;
if (d != null && d.length > 0) {
str = d[0];
}
if (TextUtils.isEmpty(str)) {
throw new w("SRC_IS_INVALID");
}
File file = new File(str);
if (!file.exists()) {
throw new w("SRC_NOT_EXISTS");
}
if (!file.isDirectory()) {
throw new w("SRC_IS_FILE");
}
boolean equalsIgnoreCase = (d == null || d.length <= 1) ? false : "1".equalsIgnoreCase(d[1]);
File[] listFiles = file.listFiles();
if (listFiles == null || listFiles.length <= 0) {
throw new w("ERR_NOT_FOUND:");
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new GZIPOutputStream(byteArrayOutputStream));
for (File file2 : listFiles) {
outputStreamWriter.write(com.qihoo360.mobilesafe.businesscard.c.a.a.a(file2, equalsIgnoreCase).a());
outputStreamWriter.flush();
}
outputStreamWriter.close();
return new InputStreamPdu("RET_FILE_LIST:OK:", new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
} catch (Exception e) {
return ACSIITextPdu.a("RET_FILE_LIST:ERR_FAILED:" + e.getMessage());
}
}
private PduBase q(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
PduBase aCSIITextPdu;
try {
String f = pduBase.f();
if (TextUtils.isEmpty(f)) {
aCSIITextPdu = new ACSIITextPdu("RET_DOWNLOAD_FILE:ERR_NOT_FOUND:");
} else {
File file = new File(f);
aCSIITextPdu = !file.exists() ? new ACSIITextPdu("RET_DOWNLOAD_FILE:ERR_NOT_FOUND:") : !file.isFile() ? new ACSIITextPdu("RET_DOWNLOAD_FILE:RET_ERROR_FILE_IS_DIR:") : !file.canRead() ? new ACSIITextPdu("RET_DOWNLOAD_FILE:RET_ERROR_FILE_DIR_CAN_NOT_BE_READ:") : file.length() >= 0 ? new FilePdu("RET_DOWNLOAD_FILE:OK:", file) : new ACSIITextPdu("RET_DOWNLOAD_FILE:ERR_NOT_FOUND:");
}
return aCSIITextPdu;
} catch (Exception e) {
if (d) {
Log.e("FileHandle", "doDownloadFile>get error:" + e.getMessage());
}
return new ACSIITextPdu("RET_DOWNLOAD_FILE:ERR_FAILED:" + e.getMessage());
}
}
private PduBase r(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
try {
String[] d = pduBase.d();
String str = d.length >= 1 ? d[0] : null;
String str2 = d.length >= 2 ? d[1] : null;
if (TextUtils.isEmpty(str2)) {
throw new w("The key must not be null");
}
String str3 = str2 + aVar.e();
if (TextUtils.isEmpty(str)) {
throw new w("The path must not be null");
}
File file = new File(str);
if (!file.exists()) {
return new ACSIITextPdu("RET_DOWNLOAD_FILE_ENCRYPT:ERR_NOT_FOUND:");
}
if (!file.isFile()) {
return new ACSIITextPdu("RET_DOWNLOAD_FILE_ENCRYPT:RET_ERROR_FILE_IS_DIR:");
}
if (!file.canRead()) {
return new ACSIITextPdu("RET_DOWNLOAD_FILE_ENCRYPT:RET_ERROR_FILE_DIR_CAN_NOT_BE_READ:");
}
if (file.length() >= 0) {
return new InputStreamPdu("RET_DOWNLOAD_FILE_ENCRYPT:OK:", new BufferedInputStream(new com.qihoo360.mobilesafe.util.w(new BufferedInputStream(new FileInputStream(file)), com.qihoo360.mobilesafe.util.aj.d(str3))));
}
return new ACSIITextPdu("RET_DOWNLOAD_FILE_ENCRYPT:ERR_NOT_FOUND:");
} catch (Exception e) {
if (d) {
Log.e("FileHandle", "doDownloadFileEncrypt>get error:" + e.getMessage());
}
return new ACSIITextPdu("RET_DOWNLOAD_FILE_ENCRYPT:ERR_FAILED:" + e.getMessage());
}
}
private PduBase s(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
BufferedOutputStream bufferedOutputStream;
com.qihoo360.mobilesafe.util.g gVar = null;
String[] d = pduBase.d();
String str = d.length >= 1 ? d[0] : null;
if (TextUtils.isEmpty(str)) {
throw new w("The path must not be null");
}
boolean equalsIgnoreCase = d.length >= 2 ? "1".equalsIgnoreCase(d[1]) : false;
File file = new File(str);
if (equalsIgnoreCase && file.exists() && file.isFile()) {
file.delete();
}
String str2 = d.length >= 3 ? d[2] : null;
if (TextUtils.isEmpty(str2)) {
throw new w("The key must not be null");
}
String str3 = str2 + aVar.e();
ACSIITextPdu aCSIITextPdu = new ACSIITextPdu("RET_BLOCKED_UPLOAD_FILE_ENCRYPT:STARTING:");
aVar.a(aCSIITextPdu);
try {
try {
file.getParentFile().mkdirs();
BufferedOutputStream bufferedOutputStream2 = new BufferedOutputStream(new FileOutputStream(file));
while (true) {
try {
try {
String e = aVar.i().e();
if ("CMD_BLOCKED_UPLOAD_FILE_ENCRYPT_OK".equalsIgnoreCase(e)) {
if (d.length > 4) {
try {
String str4 = new String(Base64.decodeBase64(d[4].getBytes()));
a(d[0], str4);
com.qihoo360.mobilesafe.util.h.a("FileHandle", "json:", str4);
} catch (Exception e2) {
}
}
com.qihoo360.mobilesafe.util.r.b(this.f, str, null);
ACSIITextPdu aCSIITextPdu2 = new ACSIITextPdu("RET_BLOCKED_UPLOAD_FILE_ENCRYPT:FINISHED:");
if (bufferedOutputStream2 != 0) {
try {
bufferedOutputStream2.close();
} catch (IOException e3) {
}
}
return aCSIITextPdu2;
}
if (!"CMD_BLOCKED_UPLOAD_FILE_ENCRYPT_DATA".equalsIgnoreCase(e)) {
throw new w("Unsupported Command: " + e);
}
gVar = aVar.a(gVar);
bufferedOutputStream2.write(com.qihoo360.mobilesafe.util.aj.b(str3, gVar.f5649a, gVar.f5650b, gVar.c));
} catch (Exception e4) {
e = e4;
throw new w("Unknown Error", e);
}
} catch (FileNotFoundException e5) {
e = e5;
gVar = bufferedOutputStream2;
try {
throw new w("Create File Error", e);
} catch (Throwable th) {
th = th;
bufferedOutputStream = gVar;
if (bufferedOutputStream != 0) {
}
throw th;
}
} catch (IOException e6) {
e = e6;
if (file != null) {
file.delete();
}
throw new w("Read From Session Error, Partial File Deleted", e);
}
}
} catch (Throwable th2) {
th = th2;
bufferedOutputStream = aCSIITextPdu;
if (bufferedOutputStream != 0) {
try {
bufferedOutputStream.close();
} catch (IOException e7) {
}
}
throw th;
}
} catch (FileNotFoundException e8) {
e = e8;
} catch (IOException e9) {
e = e9;
} catch (Exception e10) {
e = e10;
} catch (Throwable th3) {
th = th3;
bufferedOutputStream = 0;
if (bufferedOutputStream != 0) {
}
throw th;
}
}
private PduBase t(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
long j;
bd bdVar;
long j2;
bb a2 = MobileSafeApplication.l().j().a();
String[] d = pduBase.d();
AtomicReference atomicReference = new AtomicReference();
String str = d.length >= 1 ? d[0] : null;
if (TextUtils.isEmpty(str)) {
throw new w("The path must not be null");
}
String str2 = str + ".temp";
File file = new File(str2);
File file2 = new File(str);
long parseInt = d.length >= 2 ? Integer.parseInt(d[1]) : 0L;
if (d.length >= 3) {
atomicReference.set(d[2]);
}
if (TextUtils.isEmpty((CharSequence) atomicReference.get())) {
throw new w("The file md5 must not be null");
}
String str3 = d.length >= 4 ? d[3] : null;
PduBase a3 = a("RET_BLOCKED_UPLOAD_FILE:", file, parseInt, true);
if (a3 != null) {
return a3;
}
bd bdVar2 = (bd) a2.a().get(atomicReference.get());
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "doBlockedUploadFile.obj = " + bdVar2, new Object[0]);
}
if (bdVar2 == null || !((bdVar2.f && file2.exists() && file2.lastModified() == bdVar2.d && file2.length() == bdVar2.c) || (!bdVar2.f && file.exists() && file.lastModified() == bdVar2.d && file.length() == bdVar2.c))) {
a2.a().remove(atomicReference.get());
bd bdVar3 = new bd();
file.delete();
j = 0;
bdVar = bdVar3;
} else {
a2.a(bdVar2.e);
j = bdVar2.c;
bdVar = bdVar2;
}
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "doBlockedUploadFile.path = " + str2 + ", file.length() = " + file.length() + ", fileLen = " + parseInt + " , fileKey = " + ((String) atomicReference.get()) + ", json = " + str3 + ", index = " + j, new Object[0]);
}
aVar.a(new ACSIITextPdu("RET_BLOCKED_UPLOAD_FILE:OK:" + j));
try {
try {
file.getParentFile().mkdirs();
com.qihoo360.mobilesafe.util.g gVar = null;
while (true) {
j2 = j;
if (j2 >= parseInt) {
break;
}
int i = (int) (65536 + j2 <= parseInt ? 65536L : parseInt - j2);
com.qihoo360.mobilesafe.util.g a4 = aVar.a(gVar, i);
boolean a5 = com.qihoo.appstore.utils.ao.a(file, a4.f5649a, j2, i);
if (a5) {
j = i + j2;
bdVar.f5486a = (String) atomicReference.get();
bdVar.f5487b = str2;
bdVar.c = j;
bdVar.d = file.lastModified();
a2.a().put(bdVar.f5486a, bdVar);
} else {
j = j2;
}
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "doBlockedUploadFile.isWrite = " + a5 + ", index = " + j, new Object[0]);
}
gVar = a4;
}
a2.a(bdVar.e);
a2.a(bdVar.e, 300000L);
if (j2 != parseInt) {
throw new w("index != fileDataLength");
}
String str4 = new String(str2);
if (str2.endsWith(".temp")) {
String substring = str4.substring(0, str4.length() - ".temp".length());
boolean a6 = com.qihoo.appstore.utils.ao.a(substring, str2);
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "doBlockedUploadFile renameResult = " + a6, new Object[0]);
}
bd bdVar4 = (bd) a2.a().get(bdVar.f5486a);
bdVar4.f = true;
bdVar4.d = new File(substring).lastModified();
str4 = substring;
}
String e = aVar.i().e();
if (!"CMD_BLOCKED_UPLOAD_FILE_OK".equalsIgnoreCase(e)) {
throw new w("Unsupported Command: " + e);
}
if (!TextUtils.isEmpty(str3)) {
try {
a(str4, new String(Base64.decodeBase64(str3.getBytes())));
} catch (Exception e2) {
}
}
com.qihoo360.mobilesafe.util.r.b(this.f, str4, null);
return new ACSIITextPdu("RET_BLOCKED_UPLOAD_FILE:OK:");
} catch (Exception e3) {
throw new w("Unknown Error", e3);
}
} catch (FileNotFoundException e4) {
throw new w("Create File Error", e4);
} catch (IOException e5) {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", e5, "doBlockedUploadFile.IOException.obj = " + bdVar + ", mUploadFileIndexs = " + a2.a(), new Object[0]);
}
a2.a(bdVar.e);
a2.a(bdVar.e, 300000L);
return null;
}
}
private PduBase u(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
bb a2 = MobileSafeApplication.l().j().a();
String[] d = pduBase.d();
String str = d.length >= 1 ? d[0] : null;
if (TextUtils.isEmpty(str)) {
throw new w("The path must not be null");
}
File file = new File(str);
String str2 = d.length >= 2 ? d[1] : null;
if (TextUtils.isEmpty(str2)) {
throw new w("The file md5 must not be null");
}
boolean z = file.exists() && a2.a().containsKey(str2);
if (com.qihoo360.mobilesafe.a.a.f5313a) {
com.qihoo360.mobilesafe.util.h.a("FileHandle", "doCheckFileCanBreakUpload.path = " + str + ", file.length() = " + file.length() + ", fileKey = " + str2 + ", getUploadFileIndexs = " + a2.a() + ", isCan = " + z, new Object[0]);
}
return new ACSIITextPdu("RET_CHECK_FILE_CAN_BREAK_UPLOAD:" + (z ? "OK:" : "ERR_FAILED:") + 0L);
}
public PduBase a(PduBase pduBase, com.qihoo360.mobilesafe.pcdaemon.service.a aVar) {
PduBase r;
PduBase q;
PduBase h;
PduBase f;
PduBase e;
PduBase g;
PduBase i;
PduBase j;
PduBase k;
PduBase l;
PduBase m;
PduBase n;
PduBase o;
PduBase p;
short s = pduBase.c;
String e2 = pduBase.e();
if (s != 1) {
return ACSIITextPdu.a("ERR_FAILED:This cmd is not be support");
}
if ("CMD_FILE_LIST".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_LIST") {
p = p(pduBase, aVar);
}
return p;
}
if ("CMD_FILE_MKDIRS".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_MKDIRS") {
o = o(pduBase, aVar);
}
return o;
}
if ("CMD_FILE_RM".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_RM") {
n = n(pduBase, aVar);
}
return n;
}
if ("CMD_FILE_MV".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_MV") {
m = m(pduBase, aVar);
}
return m;
}
if ("CMD_FILE_CP".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_CP") {
l = l(pduBase, aVar);
}
return l;
}
if ("CMD_FILE_RENAME".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_RENAME") {
k = k(pduBase, aVar);
}
return k;
}
if ("CMD_FILE_EXISTS".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_EXISTS") {
j = j(pduBase, aVar);
}
return j;
}
if ("CMD_FILE_INFO".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_INFO") {
i = i(pduBase, aVar);
}
return i;
}
if ("CMD_FILE_BEGIN".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_BEGIN") {
g = g(pduBase, aVar);
}
return g;
}
if ("CMD_MOVE_FILE".equals(e2)) {
synchronized ("CMD_MOVE_FILE") {
e = e(pduBase, aVar);
}
return e;
}
if ("CMD_DELETE_FILE".equals(e2)) {
synchronized ("CMD_DELETE_FILE") {
f = f(pduBase, aVar);
}
return f;
}
if ("CMD_FILE_CHMOD".equalsIgnoreCase(e2)) {
synchronized ("CMD_FILE_CHMOD") {
h = h(pduBase, aVar);
}
return h;
}
if ("CMD_DOWNLOAD_FILE".equals(e2)) {
synchronized ("CMD_DOWNLOAD_FILE") {
q = q(pduBase, aVar);
}
return q;
}
if (!"CMD_DOWNLOAD_FILE_ENCRYPT".equals(e2)) {
return "CMD_UPLOAD_FILE".equals(e2) ? new ah(this, false).a(pduBase, aVar) : "CMD_UPLOAD_FILE_ENCRYPT".equalsIgnoreCase(e2) ? new ah(this, true).a(pduBase, aVar) : "CMD_BLOCKED_DOWNLOAD_FILE_ENCRYPT".equalsIgnoreCase(e2) ? new ag(this, null).a(pduBase, aVar) : "CMD_BLOCKED_UPLOAD_FILE_ENCRYPT".equalsIgnoreCase(e2) ? s(pduBase, aVar) : "CMD_BLOCKED_UPLOAD_FILE".equalsIgnoreCase(e2) ? t(pduBase, aVar) : "CMD_FILE_GET_APKMD5".equalsIgnoreCase(e2) ? c(pduBase, aVar) : "CMD_FILE_MERGE_APK".equalsIgnoreCase(e2) ? d(pduBase, aVar) : "CMD_PUSH_DOWNLOAD_FILE".equalsIgnoreCase(e2) ? b(pduBase, aVar) : "CMD_CHECK_FILE_CAN_BREAK_UPLOAD".equalsIgnoreCase(e2) ? u(pduBase, aVar) : ACSIITextPdu.a("ERR_FAILED:This cmd is not be support");
}
synchronized ("CMD_DOWNLOAD_FILE_ENCRYPT") {
r = r(pduBase, aVar);
}
return r;
}
public PduBase a(String str, File file, long j, boolean z) {
File parentFile = file.getParentFile();
if ((!z && file.exists()) || (z && file.length() == j)) {
return new ACSIITextPdu(str + "RET_ERROR_FILE_HAS_EXISTS:" + file.length() + ":");
}
if (file.isDirectory()) {
return new ACSIITextPdu(str + "RET_ERROR_FILE_IS_DIR:");
}
if (!parentFile.exists() && !parentFile.mkdirs()) {
return new ACSIITextPdu(str + "RET_ERROR_FILE_CAN_NOT_MKDIR:");
}
if (parentFile.exists() && !parentFile.canWrite()) {
return new ACSIITextPdu(str + "RET_ERROR_FILE_DIR_CAN_NOT_BE_WRITE:");
}
StatFs statFs = new StatFs(file.getParent());
if (statFs.getAvailableBlocks() * statFs.getBlockSize() <= j) {
return new ACSIITextPdu(str + "RET_ERROR_FILE_NO_SPACE:");
}
return null;
}
public boolean a(String str) {
return "CMD_FILE_LIST".equalsIgnoreCase(str) || "CMD_FILE_MKDIRS".equalsIgnoreCase(str) || "CMD_FILE_RM".equalsIgnoreCase(str) || "CMD_FILE_MV".equalsIgnoreCase(str) || "CMD_FILE_CP".equalsIgnoreCase(str) || "CMD_FILE_RENAME".equalsIgnoreCase(str) || "CMD_FILE_EXISTS".equalsIgnoreCase(str) || "CMD_FILE_INFO".equalsIgnoreCase(str) || "CMD_FILE_BEGIN".equalsIgnoreCase(str) || "CMD_MOVE_FILE".equalsIgnoreCase(str) || "CMD_DELETE_FILE".equalsIgnoreCase(str) || "CMD_DOWNLOAD_FILE".equalsIgnoreCase(str) || "CMD_UPLOAD_FILE".equalsIgnoreCase(str) || "CMD_DOWNLOAD_FILE_ENCRYPT".equalsIgnoreCase(str) || "CMD_UPLOAD_FILE_ENCRYPT".equalsIgnoreCase(str) || "CMD_BLOCKED_DOWNLOAD_FILE_ENCRYPT".equalsIgnoreCase(str) || "CMD_BLOCKED_UPLOAD_FILE_ENCRYPT".equalsIgnoreCase(str) || "CMD_BLOCKED_UPLOAD_FILE".equalsIgnoreCase(str) || "CMD_FILE_GET_APKMD5".equalsIgnoreCase(str) || "CMD_FILE_MERGE_APK".equalsIgnoreCase(str) || "CMD_PUSH_DOWNLOAD_FILE".equalsIgnoreCase(str) || "CMD_CHECK_FILE_CAN_BREAK_UPLOAD".equalsIgnoreCase(str);
}
}