TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c

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


package com.tencent.mobileqq.unifiedebug;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.ResultReceiver;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.tencent.common.app.AppInterface;
import com.tencent.mobileqq.app.IphoneTitleBarActivity;
import com.tencent.open.base.MD5Utils;
import com.tencent.qphone.base.util.QLog;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import mqq.app.MobileQQ;
public class SnapshotService extends IphoneTitleBarActivity {
    public static final int f94329a = 0;
    public static final String f33267a = "android.intent.action.ultimatesnapshot";
    private static boolean f33268a = false;
    public static final int f94330b = 1;
    private static String f33269b = "SnapshotService";
    public static final int f94331c = 2;
    private long f33270a;
    private RelativeLayout f33273a;
    private AppInterface f33274a;
    private Queue f33275a;
    private vjh f33276a;
    private vjh f33277b;
    public Handler f33272a = new Handler();
    private BroadcastReceiver f33271a = new vje(this);

    public static boolean m8952a() {
        return f33268a;
    }

    @Override
    public void doOnDestroy() {
        if (QLog.isColorLevel()) {
            QLog.i(f33269b, 2, "in onDestroy method()");
        }
        if (this.f33270a > 0) {
            unregisterReceiver(this.f33271a);
            f33268a = false;
        }
        this.f33272a.removeCallbacksAndMessages(null);
        this.f33275a.clear();
        super.doOnDestroy();
        if (this.f33276a != null) {
            this.f33276a.f78738a.c();
        }
        if (this.f33277b != null) {
            this.f33277b.f78738a.c();
        }
    }

    @Override
    public void doOnPause() {
        super.doOnPause();
        if (this.f33276a != null) {
            this.f33276a.f78738a.b();
        }
        if (this.f33277b != null) {
            this.f33277b.f78738a.b();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (this.f33276a != null) {
            this.f33276a.f78738a.a();
        }
        if (this.f33277b != null) {
            this.f33277b.f78738a.a();
        }
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f33273a = new RelativeLayout(this);
        this.f33274a = (AppInterface) MobileQQ.sMobileQQ.waitAppRuntime(null);
        if (this.f33274a == null) {
            if (QLog.isColorLevel()) {
                QLog.d(f33269b, 2, "app == null");
            }
            super.finish();
        }
        this.f33275a = new LinkedList();
        this.f33270a = getIntent().getLongExtra("id", -1L);
        if (this.f33270a > 0) {
            this.f33276a = new vjh(this);
            if (!a(getIntent(), this.f33276a)) {
                finish();
            }
            this.f33276a.f78738a = new vjg(getBaseContext(), this, this.f33274a);
            this.f33276a.f78738a.a(super.getIntent());
            this.f33273a.addView(this.f33276a.f78738a.f34524a, new ViewGroup.LayoutParams(-1, -1));
        } else {
            this.f33277b = new vjh(this);
            if (!a(getIntent(), this.f33277b)) {
                finish();
            }
            this.f33277b.f78738a = new vjg(getBaseContext(), this, this.f33274a);
            this.f33277b.f78738a.a(super.getIntent());
            this.f33273a.addView(this.f33277b.f78738a.f34524a, new ViewGroup.LayoutParams(-1, -1));
        }
        super.setContentView(this.f33273a);
        super.moveTaskToBack(true);
        if (QLog.isColorLevel()) {
            QLog.i(f33269b, 2, "new Command in onCreate");
        }
        if (this.f33270a > 0) {
            registerReceiver(this.f33271a, new IntentFilter(f33267a));
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "registered receiver: android.intent.action.ultimatesnapshot");
            }
            f33268a = true;
            this.f33276a.f78738a.a(this.f33276a.f78737a);
            if (!a(getIntent())) {
                finish();
                return;
            }
            return;
        }
        this.f33277b.f78738a.a(this.f33277b.f78737a);
        vjf vjfVar = new vjf();
        vjfVar.f78732a = getIntent().getLongExtra("seq", -1L);
        vjfVar.f78733a = getIntent().getStringExtra("seqKey");
        vjfVar.f110877b = getIntent().getIntExtra("maxSnapshotCount", 5);
        vjfVar.f110876a = 0;
        vjfVar.f78734a = new ArrayList();
        if (QLog.isColorLevel()) {
            QLog.i(f33269b, 2, "new Command seq=" + vjfVar.f78732a);
        }
        if (vjfVar.f78732a != -1) {
            a(vjfVar, this.f33277b);
        }
    }

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        moveTaskToBack(true);
        long longExtra = intent.getLongExtra("id", -1L);
        if (longExtra < 0) {
            if (this.f33277b == null) {
                this.f33277b = new vjh(this);
                this.f33277b.f78738a = new vjg(getBaseContext(), this, this.f33274a);
                this.f33277b.f78738a.a(super.getIntent());
                this.f33273a.addView(this.f33277b.f78738a.f34524a, new ViewGroup.LayoutParams(-1, -1));
            }
            a(intent, this.f33277b);
            vjf vjfVar = new vjf();
            vjfVar.f78732a = intent.getLongExtra("seq", -1L);
            vjfVar.f78733a = intent.getStringExtra("seqKey");
            vjfVar.f110877b = intent.getIntExtra("maxSnapshotCount", 5);
            vjfVar.f110876a = 0;
            vjfVar.f78734a = new ArrayList();
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "new Command in onNewIntent()");
                QLog.i(f33269b, 2, "new Command seq=" + vjfVar.f78732a);
            }
            if (vjfVar.f78732a != -1) {
                this.f33277b.f78738a.a(this.f33277b.f78737a);
                a(vjfVar, this.f33277b);
                return;
            }
            return;
        }
        if (this.f33276a == null) {
            this.f33276a = new vjh(this);
            this.f33276a.f78738a = new vjg(getBaseContext(), this, this.f33274a);
            this.f33276a.f78738a.a(super.getIntent());
            this.f33273a.addView(this.f33276a.f78738a.f34524a, new ViewGroup.LayoutParams(-1, -1));
        }
        switch (intent.getIntExtra("action", 2)) {
            case 0:
                if (longExtra == this.f33270a) {
                    if (QLog.isColorLevel()) {
                        QLog.i(f33269b, 2, "onNewIntent(), just snapshot for loaded url");
                    }
                    this.f33276a.f110878a = 1000L;
                    this.f33276a.f110879b = 1000L;
                    a(intent);
                    return;
                }
                return;
            case 1:
            default:
                return;
            case 2:
                if (QLog.isColorLevel()) {
                    QLog.i(f33269b, 2, "onNewIntent(), load url");
                }
                if (!f33268a) {
                    registerReceiver(this.f33271a, new IntentFilter(f33267a));
                    if (QLog.isColorLevel()) {
                        QLog.i(f33269b, 2, "registered receiver: android.intent.action.ultimatesnapshot");
                    }
                }
                f33268a = true;
                if (a(getIntent(), this.f33276a) && a(getIntent())) {
                    this.f33276a.f78738a.a(this.f33276a.f78737a);
                    this.f33270a = longExtra;
                    return;
                }
                return;
        }
    }

    private void a(vjh vjhVar) {
        if (QLog.isColorLevel()) {
            QLog.i(f33269b, 2, "mQueue size = " + this.f33275a.size());
        }
        vjf vjfVar = (vjf) this.f33275a.peek();
        if (vjfVar != null) {
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "current cmd=" + vjfVar.f78732a);
            }
            a(vjfVar, vjhVar);
        }
    }

    private void a(vjf vjfVar, vjh vjhVar) {
        this.f33272a.postDelayed(new vja(this, vjhVar, vjfVar), vjhVar.f110878a);
    }

    private void b(vjf vjfVar, vjh vjhVar) {
        long j;
        long j2;
        if (QLog.isColorLevel()) {
            String str = f33269b;
            StringBuilder append = new StringBuilder().append("finish once debug, webview id =");
            j2 = vjhVar.f110880c;
            QLog.i(str, 2, append.append(j2).append(", seq=").append(vjfVar.f78732a).toString());
        }
        if (vjhVar.f78735a != null) {
            Bundle bundle = new Bundle();
            bundle.putStringArrayList("snapshotPaths", vjfVar.f78734a);
            bundle.putLong("seq", vjfVar.f78732a);
            bundle.putString("seqKey", vjfVar.f78733a);
            ResultReceiver resultReceiver = vjhVar.f78735a;
            j = vjhVar.f110880c;
            resultReceiver.send(j > 0 ? 1 : 0, bundle);
        }
        synchronized (this.f33275a) {
            if (!this.f33275a.isEmpty()) {
                this.f33275a.remove();
            }
        }
        if (this.f33270a > 0) {
            a(vjhVar);
        } else {
            finish();
        }
    }

    public void c(vjf vjfVar, vjh vjhVar) {
        if (vjhVar.f78738a.f34524a.getWidth() <= 0 || vjhVar.f78738a.f34524a.getHeight() <= 0) {
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "webview width =" + vjhVar.f78738a.f34524a.getWidth() + ", height=" + vjhVar.f78738a.f34524a.getHeight());
            }
            if (this.f33270a > 0 && vjhVar.f78735a != null) {
                Bundle bundle = new Bundle();
                bundle.putString("debugUrl", vjhVar.f78737a);
                bundle.putInt("maxCount", vjfVar.f110877b);
                bundle.putLong("delay", vjhVar.f110878a);
                bundle.putLong("seq", vjfVar.f78732a);
                bundle.putString("seqKey", vjfVar.f78733a);
                vjhVar.f78735a.send(2, bundle);
                if (QLog.isColorLevel()) {
                    QLog.d(f33269b, 2, "WebView is invalid and send to restart alive webview.");
                }
            }
            finish();
            return;
        }
        Bitmap createBitmap = Bitmap.createBitmap(vjhVar.f78738a.f34524a.getWidth(), vjhVar.f78738a.f34524a.getHeight(), Bitmap.Config.ARGB_8888);
        if (vjhVar.f78738a.f34524a.getX5WebViewExtension() != null) {
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "start x5 snapshot");
            }
            a(createBitmap, vjfVar, vjhVar);
            return;
        }
        if (QLog.isColorLevel()) {
            QLog.i(f33269b, 2, "start webview snapshot");
        }
        vjhVar.f78738a.f34524a.draw(new Canvas(createBitmap));
        if (vjfVar.f110876a == 0) {
            vjfVar.f110876a++;
        } else {
            b(createBitmap, vjfVar, vjhVar);
        }
        d(vjfVar, vjhVar);
    }

    private void a(Bitmap bitmap, vjf vjfVar, vjh vjhVar) {
        boolean z = true;
        if (vjhVar == null || vjhVar.f78738a == null || vjhVar.f78738a.f34524a.getX5WebViewExtension() == null) {
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "snapshotVisibleWithBitmap: null");
                return;
            }
            return;
        }
        Class<?>[] interfaces = vjhVar.f78738a.f34524a.getX5WebViewExtension().getClass().getInterfaces();
        int length = interfaces.length;
        int i = 0;
        while (true) {
            if (i >= length) {
                z = false;
                break;
            }
            Class<?> cls = interfaces[i];
            if (!"com.tencent.smtt.export.internal.interfaces.IX5WebView".equals(cls.getName())) {
                i++;
            } else {
                try {
                    Method declaredMethod = cls.getDeclaredMethod("snapshotVisibleWithBitmap", Bitmap.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Float.TYPE, Float.TYPE, Runnable.class);
                    if (QLog.isColorLevel()) {
                        QLog.i(f33269b, 2, "call snapshotVisibleWithBitmap");
                    }
                    declaredMethod.invoke(vjhVar.f78738a.f34524a.getX5WebViewExtension(), bitmap, true, true, true, true, 1, 1, new vjb(this, bitmap, vjfVar, vjhVar));
                } catch (Exception e) {
                    if (QLog.isColorLevel()) {
                        QLog.i(f33269b, 2, "call snapshotVisibleWithBitmap failed: " + e.getMessage());
                    }
                    z = false;
                }
            }
        }
        if (!z) {
            if (vjhVar.f78735a != null) {
                Bundle bundle = new Bundle();
                bundle.putLong("seq", vjfVar.f78732a);
                vjhVar.f78735a.send(3, bundle);
            }
            finish();
        }
    }

    public void b(Bitmap bitmap, vjf vjfVar, vjh vjhVar) {
        try {
            File file = new File(Environment.getExternalStorageDirectory(), "/tencent/MobileQQ/unifiedebug");
            if (!file.exists()) {
                file.mkdirs();
            }
            StringBuilder append = new StringBuilder().append("/Snapshot_").append(vjhVar.f78739b).append("_");
            int i = vjfVar.f110876a;
            vjfVar.f110876a = i + 1;
            File file2 = new File(file, append.append(i).append(".png").toString());
            FileOutputStream fileOutputStream = new FileOutputStream(file2);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            bitmap.recycle();
            vjfVar.f78734a.add(file2.getAbsolutePath());
            if (QLog.isColorLevel()) {
                QLog.d(f33269b, 2, "saveSnapshotBitmap file path = " + file2.getAbsolutePath());
            }
        } catch (Exception e) {
            if (QLog.isColorLevel()) {
                QLog.e(f33269b, 2, e.getMessage());
            }
        }
    }

    public void d(vjf vjfVar, vjh vjhVar) {
        boolean pageDown;
        boolean z = vjhVar.f78738a.f34524a.getX5WebViewExtension() != null;
        if (z) {
            int height = vjhVar.f78738a.f34524a.getHeight();
            if (QLog.isColorLevel()) {
                QLog.i(f33269b, 2, "webview width =" + vjhVar.f78738a.f34524a.getWidth() + ", height=" + vjhVar.f78738a.f34524a.getHeight());
                QLog.i(f33269b, 2, "webview scroll height =" + height);
            }
            vjhVar.f78738a.f34524a.loadUrl("javascript:window.scrollBy(0, " + height + " / window.devicePixelRatio)");
            pageDown = false;
        } else {
            pageDown = vjhVar.f78738a.f34524a.pageDown(false);
        }
        boolean z2 = vjfVar.f110876a < (z ? vjfVar.f110877b : vjfVar.f110877b + 1);
        if (!z) {
            z2 = vjfVar.f110876a <= 1 || (pageDown && z2);
        }
        if (z2) {
            this.f33272a.postDelayed(new vjd(this, vjfVar, vjhVar), vjhVar.f110879b);
        } else {
            b(vjfVar, vjhVar);
        }
    }

    private boolean a(Intent intent, vjh vjhVar) {
        long j;
        vjhVar.f110880c = intent.getLongExtra("id", -1L);
        vjhVar.f78735a = (ResultReceiver) intent.getParcelableExtra("callback");
        vjhVar.f110878a = intent.getLongExtra("delay", 10000L);
        vjhVar.f110879b = 3000L;
        vjhVar.f78737a = intent.getStringExtra("debugUrl");
        if (TextUtils.isEmpty(vjhVar.f78737a)) {
            return false;
        }
        StringBuilder sb = new StringBuilder();
        j = vjhVar.f110880c;
        vjhVar.f78739b = sb.append(j).append(MD5Utils.d(vjhVar.f78737a)).toString();
        if (!vjhVar.f78737a.startsWith("http://")) {
            vjhVar.f78737a = "http://" + vjhVar.f78737a;
        }
        return true;
    }

    private boolean a(Intent intent) {
        vjf vjfVar = new vjf();
        vjfVar.f78732a = intent.getLongExtra("seq", -1L);
        vjfVar.f78733a = intent.getStringExtra("seqKey");
        vjfVar.f110877b = intent.getIntExtra("maxSnapshotCount", 5);
        vjfVar.f110876a = 0;
        vjfVar.f78734a = new ArrayList();
        if (QLog.isColorLevel()) {
            QLog.i(f33269b, 2, "new Command seq=" + vjfVar.f78732a);
        }
        if (vjfVar.f78732a == -1) {
            return false;
        }
        synchronized (this.f33275a) {
            if (this.f33275a.isEmpty()) {
                this.f33275a.offer(vjfVar);
                a(this.f33276a);
            } else {
                this.f33275a.offer(vjfVar);
            }
        }
        return true;
    }
}