360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0

以下内容为反编译后的 a.java 源代码,内容仅作参考


package com.qihoo.appstore.f;

import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.text.TextUtils;
import com.qihoo.appstore.AppStoreApplication;
import com.qihoo.appstore.resource.app.App;
import com.qihoo.appstore.resource.ring.Ring;
import com.qihoo.appstore.resource.wallpaper.Wallpaper;
import com.qihoo.appstore.utils.Cdo;
import com.qihoo.appstore.utils.UpdateManager;
import com.qihoo.freewifi.push.FreeWifiSDK;
import com.qihoo.speedometer.Config;
import com.qihoo.speedometer.TraceFileUtil;
import com.qihoo.speedometer.TrafficTrace;
import com.qihoo.speedometer.util.PhoneUtils;
import com.qihoo360.mobilesafe.util.PatchUtil;
import java.io.File;
import org.json.JSONObject;

public class a implements com.qihoo.appstore.e.b.n {
    public static int DEBUG_FOR_CHOOSE_EXTSDCARD_DIR = -1;
    private static final String TAG = "BaseResourceDownloadThreadDelegate";
    private boolean haveSendLog;
    private boolean isMobileNet = false;
    private long mBeginSize;
    private String mDeletePathOnExit;
    private long upperFileSizeAllowDownloadNoWifi;
    private PowerManager.WakeLock wakeLock;

    private String genNewSavePath(com.qihoo.appstore.e.b.h hVar) {
        f fVar = (f) hVar;
        String str = null;
        try {
            String aI = fVar.v instanceof com.qihoo.appstore.resource.a ? ((com.qihoo.appstore.resource.a) fVar.v).aI() : fVar.g();
            if (fVar.v instanceof Ring) {
                str = ((Ring) fVar.v).aM();
            } else if (fVar.v instanceof Wallpaper) {
                str = ((Wallpaper) fVar.v).aH();
            }
            if (!TextUtils.isEmpty(aI) && aI.startsWith("/")) {
                return aI;
            }
            boolean z = fVar.v.Z() <= 20971520 || com.qihoo.appstore.utils.f.t();
            if (DEBUG_FOR_CHOOSE_EXTSDCARD_DIR == 1) {
                z = false;
            }
            String parentPathForResource = getParentPathForResource(AppStoreApplication.d(), fVar.v, null, fVar.e(), z);
            boolean z2 = fVar.v instanceof App;
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                com.qihoo.appstore.utils.bk.b(TAG, "chooseFullPath1");
            }
            String a2 = com.qihoo.appstore.e.d.d.a(fVar.v, AppStoreApplication.d(), parentPathForResource, fVar.f(), fVar.f, null, null, null, fVar.q, fVar.e(), z2, z, str);
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                com.qihoo.appstore.utils.bk.b(TAG, "chooseFullPath1: " + a2);
            }
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                com.qihoo.appstore.utils.bk.b(TAG, "expect ExtName: " + str);
            }
            if (TextUtils.isEmpty(str)) {
                return a2;
            }
            int lastIndexOf = a2.lastIndexOf(TraceFileUtil.FILE_EXTENSION_SEPARATOR);
            if (lastIndexOf != -1) {
                return !str.equalsIgnoreCase(a2.substring(lastIndexOf + 1)) ? a2.substring(0, lastIndexOf + 1) + str : a2;
            }
            return a2 + TraceFileUtil.FILE_EXTENSION_SEPARATOR + str;
        } catch (com.qihoo.appstore.e.d.e e) {
            throw new com.qihoo.appstore.e.b.r(e.f1483a, e.f1484b);
        }
    }

    private String getPDownUrl(f fVar) {
        try {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                com.qihoo.appstore.utils.bk.b("PDOWN", "getPDownUrl for " + fVar.f());
            }
            App app = (App) fVar.v;
            if ("360market".equals(fVar.v.U()) && !app.bC()) {
                String b2 = com.qihoo.appstore.http.h.a().b(com.qihoo.appstore.r.g.a("http://openbox.mobilem.360.cn/mintf/getAppInfo?pnames=" + fVar.v.W(), (String) null, true));
                if (com.qihoo360.mobilesafe.a.a.f5313a) {
                    com.qihoo.appstore.utils.bk.b("PDOWN", "FetchPDown: " + b2);
                }
                String string = new JSONObject(b2).getJSONObject("data").getJSONObject(fVar.v.W()).getString("pdown_url");
                if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                    return string;
                }
                com.qihoo.appstore.utils.bk.b("PDOWN", "PDownUrl: " + string);
                return string;
            }
            return null;
        } catch (Exception e) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                com.qihoo.appstore.utils.bk.b("PDOWN", "FetchPDown: " + e.toString());
            }
            return null;
        }
    }

    public static String getParentPathForResource(Context context, com.qihoo.appstore.e.a.b bVar, String str, long j, boolean z) {
        if (str == null) {
            str = Config.INVALID_IP;
        }
        if ((bVar instanceof App) || "application/vnd.android.package-archive".equals(str)) {
            File file = new File(com.qihoo.appstore.e.d.d.a(context, j, z) + "/360Download");
            if (file.exists() || !com.qihoo.appstore.e.d.d.a(context, file)) {
                return "360Download";
            }
            file.mkdirs();
            com.qihoo.appstore.e.d.n.b(file);
            return "360Download";
        }
        if ((bVar instanceof Ring) || str.startsWith("audio/")) {
            return "xiami".equalsIgnoreCase(bVar.ap()) ? com.qihoo.appstore.l.b.a.g : com.qihoo.appstore.l.b.a.f1823a;
        }
        if ((bVar instanceof com.qihoo.appstore.resource.d) || str.startsWith("video/")) {
            return "kumi".equalsIgnoreCase(bVar.ap()) ? com.qihoo.appstore.l.b.a.h : com.qihoo.appstore.l.b.a.e;
        }
        if ((bVar instanceof Wallpaper) || str.startsWith("image/")) {
            return bVar.am() ? !TextUtils.isEmpty(bVar.S()) ? bVar.S() : com.qihoo.appstore.l.b.a.c : com.qihoo.appstore.l.b.a.f1824b;
        }
        if (bVar instanceof com.qihoo.appstore.resource.b) {
            return "mosc".equalsIgnoreCase(bVar.ap()) ? com.qihoo.appstore.l.b.a.i : "xtdm".equalsIgnoreCase(bVar.ap()) ? com.qihoo.appstore.l.b.a.j : com.qihoo.appstore.l.b.a.d;
        }
        return "mosc".equalsIgnoreCase(bVar.ap()) ? com.qihoo.appstore.l.b.a.i : "360Download";
    }

    private boolean mergeApp(com.qihoo.appstore.e.b.h hVar) {
        f fVar = (f) hVar;
        App app = (App) fVar.v;
        File file = new File(fVar.g());
        String str = file.getParent() + "/merged_" + file.getName() + ".apk";
        com.qihoo.appstore.utils.bk.c("merge", "begin " + app.S() + "|" + app.d(AppStoreApplication.d()) + "--->" + str);
        boolean z = PatchUtil.patch(0, app.S(), app.d(AppStoreApplication.d()), str) == 0;
        com.qihoo.appstore.utils.bk.c("merge", "end " + app.S() + "|" + app.d(AppStoreApplication.d()) + "--->" + str);
        this.mDeletePathOnExit = app.S();
        if (z) {
            app.j(str);
        }
        return z;
    }

    private void sendLogRequest(f fVar) {
        if (this.haveSendLog) {
            return;
        }
        this.haveSendLog = true;
        try {
            if (com.qihoo.appstore.r.a.a()) {
                com.qihoo.appstore.utils.aj.a().execute(new b(this, fVar, com.qihoo.appstore.r.g.a(fVar.f().trim().replaceAll(" ", "%20"), fVar.v, 0)));
            }
        } catch (Exception e) {
        }
    }

    @Override
    public String chooseSavePath(com.qihoo.appstore.e.b.h hVar) {
        f fVar = (f) hVar;
        String genNewSavePath = genNewSavePath(fVar);
        String g = fVar.g();
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            com.qihoo.appstore.utils.bk.b(TAG, "SavePath: " + genNewSavePath);
        }
        fVar.a(genNewSavePath);
        if (!TextUtils.isEmpty(genNewSavePath) && !genNewSavePath.equalsIgnoreCase(g)) {
            g.a(fVar);
        }
        return genNewSavePath;
    }

    public String[] getIpListByHostName(String str) {
        return com.qihoo.appstore.utils.f.j(str);
    }

    @Override
    public String getPDownUrl(com.qihoo.appstore.e.b.h hVar) {
        String f;
        f fVar = (f) hVar;
        if ((fVar.v instanceof App) && com.qihoo.appstore.utils.f.J() && com.qihoo.appstore.utils.f.H() && !fVar.v.ax() && com.qihoo.express.mini.c.i.c() && ((f = fVar.f()) == null || !f.startsWith("pdown"))) {
            String pDownUrl = getPDownUrl(fVar);
            if (!TextUtils.isEmpty(pDownUrl) && pDownUrl.contains(f)) {
                return pDownUrl;
            }
        }
        return null;
    }

    @Override
    public String getUserAgent(com.qihoo.appstore.e.b.h hVar, String str) {
        String str2 = hVar.j;
        if (str2 == null) {
            str2 = "Mozilla/5.0 (Linux; Android 4.1.1; Nexus S 4G Build/JRO03C) AppleWebKit/537.9 (KHTML, like Gecko) Chrome/23.0.1260.0 Mobile Safari/537.9, 360appstore";
        }
        return com.qihoo.appstore.e.b.o.a(str, str2);
    }

    @Override
    public boolean onCurrentNetworkChanged(com.qihoo.appstore.e.b.h hVar, int i) {
        f fVar = (f) hVar;
        com.qihoo.appstore.e.a.b bVar = fVar.v;
        if ((!bVar.J() || bVar.y()) && (i == 2 || PhoneUtils.c(AppStoreApplication.d()))) {
            fVar.a(1);
            return false;
        }
        if (i == 2) {
            if (this.upperFileSizeAllowDownloadNoWifi != -1 && !bVar.B() && bVar.Z() > this.upperFileSizeAllowDownloadNoWifi) {
                bVar.M();
                fVar.a(1);
                return false;
            }
            if (bVar.Y && bVar.am()) {
                bVar.M();
                bVar.Y = false;
                fVar.a(1);
                return false;
            }
        }
        return true;
    }

    @Override
    public void onDownloadSucceed(com.qihoo.appstore.e.b.h hVar, String str) {
        f fVar = (f) hVar;
        if (fVar.v instanceof App) {
            App app = (App) fVar.v;
            if (app.bC()) {
                fVar.b(197);
                onStatusChanged(fVar, false);
                if (!mergeApp(fVar)) {
                    throw new com.qihoo.appstore.e.b.r(493, "merge apk failed");
                }
                com.qihoo.express.mini.c.a.a().a(app.bw() - app.bA());
                app.b(app.bw());
                app.q(app.bx());
                app.P(Config.INVALID_IP);
                app.h(0L);
            }
            if (fVar.v.af().startsWith("http:") && fVar.v.ay()) {
                fVar.b(198);
                onStatusChanged(fVar, false);
                app.aW = com.qihoo.appstore.e.d.f.a(new File(fVar.g()));
                if (!app.bf().equalsIgnoreCase(app.aW)) {
                    app.a("mdr", app.bf());
                    app.a("mdc", app.aW);
                    app.b(4);
                }
                if (com.qihoo360.mobilesafe.a.a.f5313a) {
                    com.qihoo.appstore.utils.bk.b(TAG, "CalcMd5: " + app.aW + " , " + app.bf());
                }
            }
        }
        if (fVar.v instanceof com.qihoo.appstore.resource.a) {
            com.qihoo.appstore.resource.a aVar = (com.qihoo.appstore.resource.a) fVar.v;
            if (!str.equalsIgnoreCase(aVar.aI())) {
                if (!new File(aVar.S()).renameTo(new File(aVar.aI()))) {
                    throw new com.qihoo.appstore.e.b.r(492, str);
                }
                aVar.j(aVar.aI());
            }
            if (str.endsWith(".zip")) {
                Cdo.a(aVar.aI());
            }
        }
        if (fVar.v instanceof App) {
            try {
                UpdateManager.a(AppStoreApplication.d(), (App) fVar.v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (((fVar.v instanceof App) || (fVar.v instanceof com.qihoo.appstore.resource.a)) && fVar.h()) {
            com.qihoo.appstore.e.d.n.b(new File(fVar.g()));
        }
        try {
            if (fVar.g().endsWith(".xebk")) {
                File file = new File(new File(fVar.g()).getParent() + "/360mobilese_android_novel");
                if (!file.exists()) {
                    file.createNewFile();
                }
            }
        } catch (Exception e2) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                e2.printStackTrace();
            }
        }
        fVar.b(Config.HTTP_STATUS_OK);
        if (!fVar.a().equals("com.qihoo.freewifi_a") || AppStoreApplication.d() == null) {
            return;
        }
        Intent intent = new Intent();
        intent.setAction(FreeWifiSDK.FREEWIFI_APK_DOWNLOADED);
        intent.putExtra("path", fVar.g());
        AppStoreApplication.d().sendBroadcast(intent);
    }

    @Override
    public void onExit(com.qihoo.appstore.e.b.h hVar) {
        try {
            if (this.wakeLock != null) {
                this.wakeLock.release();
                this.wakeLock = null;
            }
        } catch (Exception e) {
        }
        if (this.mDeletePathOnExit != null) {
            new File(this.mDeletePathOnExit).delete();
        }
        if (hVar != null && this.isMobileNet) {
            TrafficTrace.a(hVar.f(), hVar.d() - this.mBeginSize);
        }
        g.a((f) hVar);
    }

    @Override
    public void onInit(com.qihoo.appstore.e.b.h hVar) {
        f fVar = (f) hVar;
        this.mDeletePathOnExit = null;
        fVar.s = 0;
        fVar.v.d();
        this.mBeginSize = fVar.d();
        fVar.l = System.currentTimeMillis();
        this.upperFileSizeAllowDownloadNoWifi = com.qihoo.appstore.utils.de.q(AppStoreApplication.d());
        this.isMobileNet = TrafficTrace.d();
    }

    @Override
    public int onProgressChanged(com.qihoo.appstore.e.b.h hVar, long j, long j2) {
        return 0;
    }

    @Override
    public void onSaveLog(com.qihoo.appstore.e.b.h hVar, int i, String str, String str2, String str3, String str4, String str5) {
        f fVar = (f) hVar;
        try {
            if (fVar.v.y()) {
                return;
            }
            fVar.n = str;
            long d = fVar.d() - this.mBeginSize;
            if (d < 0) {
                d = fVar.d();
            }
            if (com.qihoo.appstore.utils.de.o(AppStoreApplication.d()).booleanValue()) {
                fVar.u = new c(this, i, d, fVar, str, str4, str2, str3, str5);
            }
        } catch (Throwable th) {
        }
    }

    @Override
    public boolean onServerResponsed(com.qihoo.appstore.e.b.h hVar, String str, long j) {
        boolean z;
        f fVar = (f) hVar;
        if (j == -1) {
            return true;
        }
        if (fVar.v.y() || fVar.o || !fVar.v.az() || j == fVar.e()) {
            z = true;
        } else {
            z = false;
            fVar.v.b(1);
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                com.qihoo.appstore.utils.bk.b(TAG, "need Use TFW retry, content-length = " + j + " , real-length = " + fVar.e());
            }
        }
        if (z && fVar.b() != 1) {
            fVar.b(j);
        }
        return z;
    }

    @Override
    public void onStartDownload(com.qihoo.appstore.e.b.h hVar) {
        f fVar = (f) hVar;
        try {
            if (fVar.v.J()) {
                this.wakeLock = ((PowerManager) AppStoreApplication.d().getSystemService("power")).newWakeLock(1, TAG);
                this.wakeLock.acquire();
            }
        } catch (Exception e) {
        }
        sendLogRequest(fVar);
    }

    @Override
    public void onStatusChanged(com.qihoo.appstore.e.b.h hVar, boolean z) {
    }
}