百度手机卫士 v8.1.5版本的 MD5 值为:15af71eae74e2f2b5b9f845fe77a4804

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


package dxoptimizer;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.SparseArray;
import com.dianxinos.optimizer.CommonIntentService;
import com.quickbird.mini.utils.Constants;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

public class bbk implements aml, hes, Runnable {
    private static bbk n;
    private static final Comparator o = new bbm();
    private static boolean p = false;
    private LocalServerSocket a;
    private LocalSocket b;
    private String c;
    private String d;
    private String f;
    private boolean g;
    private File i;
    private Context j;
    private HandlerThread l;
    private Handler q;
    private int e = -1;
    private boolean k = false;
    private String h = "1800";
    private ArrayList m = new ArrayList();

    private bbk(Context context) {
        this.j = context.getApplicationContext();
        this.i = new File(this.j.getFilesDir(), "daemon");
        heq.a(this.j).a(this);
        this.l = new HandlerThread("daemon");
        this.l.start();
        this.q = new bbl(this, this.l.getLooper());
    }

    @Override
    public void run() {
        BufferedReader bufferedReader;
        BufferedReader bufferedReader2 = null;
        if (this.k) {
            return;
        }
        synchronized (this) {
            if (!this.k) {
                b(true);
                this.f = haj.r(this.j);
                this.c = "s_dx_" + System.currentTimeMillis();
                try {
                    this.a = new LocalServerSocket(this.c);
                    if (i()) {
                        while (true) {
                            try {
                                this.q.sendMessageDelayed(this.q.obtainMessage(4097), 10000L);
                                this.b = this.a.accept();
                                this.q.removeMessages(4097);
                                this.q.sendMessageDelayed(this.q.obtainMessage(4098), Constants.MINUTE_MS);
                                d();
                                a('A');
                                InputStream inputStream = this.b.getInputStream();
                                if (inputStream != null) {
                                    try {
                                        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                                        while (true) {
                                            try {
                                                String readLine = bufferedReader.readLine();
                                                if (readLine == null) {
                                                    break;
                                                }
                                                int parseInt = Integer.parseInt(readLine);
                                                if (parseInt > 0) {
                                                    a(parseInt);
                                                }
                                            } catch (Exception e) {
                                                if (bufferedReader != null) {
                                                    hjo.a(bufferedReader);
                                                }
                                                Thread.sleep(com.baidu.location.h.e.kh);
                                                if (this.a != null) {
                                                }
                                            } catch (Throwable th) {
                                                bufferedReader2 = bufferedReader;
                                                th = th;
                                                if (bufferedReader2 != null) {
                                                    hjo.a(bufferedReader2);
                                                }
                                                throw th;
                                            }
                                        }
                                        if (bufferedReader != null) {
                                            hjo.a(bufferedReader);
                                        }
                                    } catch (Exception e2) {
                                        bufferedReader = null;
                                    } catch (Throwable th2) {
                                        th = th2;
                                    }
                                }
                                try {
                                    Thread.sleep(com.baidu.location.h.e.kh);
                                } catch (InterruptedException e3) {
                                }
                                if (this.a != null) {
                                    break;
                                } else {
                                    i();
                                }
                            } catch (Exception e4) {
                                try {
                                    this.a.close();
                                } catch (Exception e5) {
                                }
                                this.a = null;
                                b(false);
                            }
                        }
                        b(false);
                    } else {
                        try {
                            this.a.close();
                        } catch (Exception e6) {
                        }
                        this.a = null;
                        b(false);
                    }
                } catch (IOException e7) {
                    b(false);
                }
            }
        }
    }

    private synchronized void b(boolean z) {
        this.k = z;
    }

    private synchronized boolean a() {
        boolean z;
        if (!this.k) {
            z = d(this.j);
        }
        return z;
    }

    private void a(bbn bbnVar) {
        b(bbnVar);
        c();
    }

    private void c() {
        synchronized (this.m) {
            if (this.b == null) {
                this.m.clear();
                return;
            }
            if (this.m.size() > 0) {
                try {
                    OutputStream outputStream = this.b.getOutputStream();
                    Iterator it = this.m.iterator();
                    while (it.hasNext()) {
                        byte[] bytes = ((bbn) it.next()).toString().getBytes();
                        int length = (bytes.length + 2) | 32896;
                        outputStream.write(10);
                        outputStream.write(bytes);
                        outputStream.write(length >> 8);
                        outputStream.write(length);
                        outputStream.write(10);
                        outputStream.flush();
                    }
                } catch (Exception e) {
                    this.m.clear();
                }
            }
        }
    }

    private void b(bbn bbnVar) {
        synchronized (this.m) {
            this.m.add(bbnVar);
        }
    }

    private void a(char c) {
        a(new bbn(this, c, null, null));
    }

    private void a(int i, String str) {
        a(new bbn(this, 'P', String.valueOf(i), str));
    }

    private void a(SparseArray sparseArray) {
        int i = 0;
        while (true) {
            int i2 = i;
            if (i2 < sparseArray.size()) {
                b(new bbn(this, 'P', String.valueOf(sparseArray.keyAt(i2)), (String) sparseArray.valueAt(i2)));
                i = i2 + 1;
            } else {
                c();
                return;
            }
        }
    }

    private void d() {
        SparseArray sparseArray = new SparseArray();
        sparseArray.append(2, this.j.getPackageName() + "/" + CommonIntentService.class.getName());
        sparseArray.append(3, this.j.getApplicationInfo().dataDir);
        sparseArray.append(4, this.j.getApplicationInfo().sourceDir);
        sparseArray.append(5, String.valueOf(Build.VERSION.SDK_INT));
        sparseArray.append(6, "com.dianxinos.optimizer.action.LAUNCH_FROM_DAEMON");
        sparseArray.append(8, this.h);
        this.g = th.a((PowerManager) this.j.getSystemService("power"));
        String j = j();
        if (j != null) {
            sparseArray.append(7, j);
        }
        String k = k();
        if (k != null) {
            sparseArray.append(9, k);
            this.d = k;
        }
        a(sparseArray);
    }

    private void e() {
        String k = k();
        if (k != null) {
            a(9, k);
            this.d = k;
        }
    }

    private void f() {
        String j = j();
        if (j != null) {
            a(7, j);
        }
    }

    private void g() {
        if (this.b != null) {
            try {
                a('Z');
                this.b.close();
            } catch (Exception e) {
            }
            this.b = null;
        }
    }

    private File h() {
        InputStream inputStream;
        Throwable th;
        if (this.i.exists() ? (String.valueOf(this.i.lastModified()) + 4).equals(hcy.a().b(this.j, "daemon", "dm_file", (String) null)) : true) {
            try {
                String str = "daemon-arm";
                if (Build.CPU_ABI.equalsIgnoreCase("x86")) {
                    str = "daemon-x86";
                }
                inputStream = this.j.getAssets().open(str);
            } catch (IOException e) {
                inputStream = null;
            } catch (Throwable th2) {
                inputStream = null;
                th = th2;
            }
            try {
                hjo.a(inputStream, this.i);
                this.i.setExecutable(true);
                hjo.a((Closeable) inputStream);
                hcy.a().a(this.j, "daemon", "dm_file", String.valueOf(this.i.lastModified()) + 4);
            } catch (IOException e2) {
                hjo.a((Closeable) inputStream);
                return null;
            } catch (Throwable th3) {
                th = th3;
                hjo.a((Closeable) inputStream);
                throw th;
            }
        }
        return this.i;
    }

    private boolean i() {
        g();
        File h = h();
        if (h == null) {
            return false;
        }
        HashMap hashMap = new HashMap(System.getenv());
        hashMap.put("PATH", ".:" + ((String) hashMap.get("PATH")));
        hashMap.put("socket", this.c);
        String[] strArr = new String[hashMap.size()];
        int i = 0;
        for (String str : hashMap.keySet()) {
            strArr[i] = str + "=" + ((String) hashMap.get(str));
            i++;
        }
        try {
            return Runtime.getRuntime().exec(h.getName(), strArr, h.getParentFile()).waitFor() == 0;
        } catch (Exception e) {
            return false;
        }
    }

    private void a(int i) {
        hcy.a().a(this.j, "daemon", "dm_id", i);
    }

    private static boolean d(Context context) {
        BufferedReader bufferedReader;
        Throwable th;
        boolean z;
        int i;
        String str;
        boolean z2;
        BufferedReader bufferedReader2 = null;
        int b = hcy.a().b(context, "daemon", "dm_id", 0);
        if (b <= 0) {
            return false;
        }
        File file = new File(String.format("/proc/%d/status", Integer.valueOf(b)));
        if (!file.exists()) {
            return false;
        }
        int i2 = -1;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            i = 0;
            str = null;
            z2 = false;
            while (true) {
                try {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        break;
                    }
                    if (readLine.startsWith("Name:")) {
                        str = readLine.substring(5).trim();
                    } else if (readLine.startsWith("Pid:")) {
                        i = Integer.parseInt(readLine.substring(4).trim());
                    } else if (readLine.startsWith("Uid:")) {
                        i2 = Integer.parseInt(readLine.trim().split("\\s+")[1]);
                    } else if (readLine.startsWith("State:")) {
                        z2 = readLine.contains("(running)") || readLine.contains("(sleeping)");
                    }
                } catch (IOException e) {
                    z = z2;
                    bufferedReader2 = bufferedReader;
                    if (bufferedReader2 != null) {
                        hjo.a(bufferedReader2);
                        z2 = z;
                    } else {
                        z2 = z;
                    }
                    return i != b && "daemon".equals(str) && z2 && i2 == context.getApplicationInfo().uid;
                } catch (Throwable th2) {
                    th = th2;
                    if (bufferedReader != null) {
                        hjo.a(bufferedReader);
                    }
                    throw th;
                }
            }
            if (bufferedReader != null) {
                hjo.a(bufferedReader);
            }
        } catch (IOException e2) {
            z = false;
            i = 0;
            str = null;
        } catch (Throwable th3) {
            bufferedReader = null;
            th = th3;
        }
        return i != b && "daemon".equals(str) && z2 && i2 == context.getApplicationInfo().uid;
    }

    private String j() {
        if (TextUtils.isEmpty(this.f)) {
            this.f = hbe.f;
        }
        if (this.e < 0) {
            this.e = ayj.d(this.j);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(this.f);
        if (!this.f.contains("?")) {
            sb.append('?');
        } else if (!this.f.endsWith("?")) {
            sb.append("&");
        }
        sb.append("&n=").append(this.e).append("&son=").append(this.g).append("&mem=").append(hkb.a()[1]).append("&").append(xo.a(this.j));
        return sb.toString();
    }

    public static boolean b(ResolveInfo resolveInfo) {
        return (resolveInfo.activityInfo.applicationInfo.flags & 1) != 0;
    }

    private String k() {
        List<ResolveInfo> queryIntentActivities;
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.BROWSABLE");
        intent.setData(Uri.parse("http://www.baidu.com"));
        if (hly.a(this.j) == null || (queryIntentActivities = this.j.getPackageManager().queryIntentActivities(intent, 0)) == null || queryIntentActivities.size() <= 0) {
            return null;
        }
        Collections.sort(queryIntentActivities, o);
        return queryIntentActivities.get(0).activityInfo.packageName;
    }

    @Override
    public void a(String str, String str2) {
        try {
            if (!TextUtils.isEmpty(str2)) {
                this.f = new JSONObject(str2).optString("uninstallurl");
                f();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public static void a(Context context) {
        if (d(context)) {
            hnj.a(context).b("daemon", "daemon_st", (Number) 1);
        }
    }

    public static void b(Context context) {
        if (!"Xiaomi".equals(Build.BRAND)) {
            if (n == null) {
                n = new bbk(context);
                ami.a(haj.l, n);
            }
            if (!n.a()) {
                new Thread(n).start();
            }
        }
    }

    public static void c(Context context) {
        b(context);
        if (!p) {
            hnj.a(context).a("daemon", "daemon_lfd", (Number) 1);
        }
        p = true;
    }

    public static void a(Context context, String str, boolean z) {
        if (str != null && n != null) {
            if (!z && str.equals(n.d)) {
                n.e();
            }
            int a = ayj.a(str);
            if (a >= 0) {
                if (n.e < 0) {
                    n.e = ayj.d(context);
                } else {
                    n.e = (1 << a) ^ n.e;
                }
                n.f();
            }
        }
    }

    @Override
    public void a_(boolean z) {
        this.g = z;
        f();
    }

    @Override
    public void k_() {
    }

    public void l() {
        if (this.h != com.baidu.location.c.d.ai) {
            this.h = com.baidu.location.c.d.ai;
            a(8, this.h);
        }
    }

    public void m() {
        try {
            if (this.b == null || !this.b.isConnected()) {
                this.a.close();
            }
        } catch (Exception e) {
        }
    }
}