QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

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


package com.tencent.qqmusic.mediaplayer.perf;

import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Xml;
import com.tencent.mtt.compliance.MethodDelegate;
import com.tencent.qqmusic.mediaplayer.AudioInformation;
import com.tencent.qqmusic.mediaplayer.util.Logger;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.xmlpull.v1.XmlSerializer;

public class PrefInfoCollector implements PlayerInfoCollector {
    private static final String ENCODING_UTF_8 = "utf-8";
    private static final String FILE_NAME = "pref_infos.xml";
    private static final String ROOT = "root";
    private static PrefInfoCollector instance;
    private HandlerThread mHandlerThread;
    private Handler mReportHandler;
    private FileOutputStream outputStream;
    private HashMap<String, Long> prefInfos;
    private String reportFilePath;
    private XmlSerializer xmlSerializer;
    private static final String TAG = PrefInfoCollector.class.getSimpleName();
    private static final String NAMESPACE = null;

    private PrefInfoCollector() {
        this.prefInfos = null;
        this.xmlSerializer = null;
        this.prefInfos = new HashMap<>();
        this.xmlSerializer = Xml.newSerializer();
    }

    public void createOutputs() {
        try {
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), FILE_NAME);
            if (file.exists()) {
                file.delete();
                file.createNewFile();
            }
            Logger.d(TAG, "setInstrumentation: outputFile: " + file);
            this.reportFilePath = file.getAbsolutePath();
            this.outputStream = new FileOutputStream(file);
            Logger.d(TAG, "setInstrumentation: outputFilepath: " + this.reportFilePath);
            try {
                this.xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
                this.xmlSerializer.setOutput(this.outputStream, "utf-8");
                this.xmlSerializer.startDocument("utf-8", true);
            } catch (IOException e) {
                Logger.e(TAG, "Unable to open serializer", e);
                throw new RuntimeException("Unable to open serializer: " + e.getMessage(), e);
            }
        } catch (FileNotFoundException e2) {
            Logger.e(TAG, "Unable to open report file: pref_infos.xml", e2);
            throw new RuntimeException("Unable to open report file: " + e2.getMessage(), e2);
        } catch (IOException e3) {
            Logger.e(TAG, "Unable to create report file: pref_infos.xml", e3);
            throw new RuntimeException("Unable to create report file: " + e3.getMessage(), e3);
        }
    }

    public static synchronized PrefInfoCollector getInstance() {
        PrefInfoCollector prefInfoCollector;
        synchronized (PrefInfoCollector.class) {
            if (instance == null) {
                instance = new PrefInfoCollector();
            }
            prefInfoCollector = instance;
        }
        return prefInfoCollector;
    }

    public void printPrefInfos(AudioInformation audioInformation) throws IOException {
        ArrayList<Map.Entry> arrayList = new ArrayList(this.prefInfos.entrySet());
        Collections.sort(arrayList, new Comparator<Map.Entry<String, Long>>() {
            @Override
            public int compare(Map.Entry<String, Long> entry, Map.Entry<String, Long> entry2) {
                if (entry.getKey().charAt(0) > entry2.getKey().charAt(0)) {
                    return 1;
                }
                return entry.getKey().charAt(0) == entry2.getKey().charAt(0) ? 0 : -1;
            }
        });
        if (arrayList.isEmpty()) {
            return;
        }
        this.xmlSerializer.startTag(NAMESPACE, "root");
        printProperty("device.manufacturer", Build.MANUFACTURER);
        printProperty("device.model", MethodDelegate.getModel());
        printProperty("device.apiLevel", String.valueOf(Build.VERSION.SDK_INT));
        printAudioInfomation(audioInformation);
        for (Map.Entry entry : arrayList) {
            long longValue = ((Long) entry.getValue()).longValue();
            printProperty((String) entry.getKey(), longValue + "");
        }
        this.xmlSerializer.endTag(NAMESPACE, "root");
        this.xmlSerializer.endDocument();
        this.xmlSerializer.flush();
    }

    private void printProperty(String str, String str2) throws IOException {
        this.xmlSerializer.startTag(NAMESPACE, str);
        this.xmlSerializer.text(str2);
        this.xmlSerializer.endTag(NAMESPACE, str);
    }

    public void upLoadByCommonPost() throws IOException {
        Logger.i(TAG, "upLoadByCommonPost");
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(" http://musict.proxy.music.qq.com/qmtm2/PlayPerformanceReport.fcg").openConnection();
        httpURLConnection.setDoInput(true);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setRequestMethod("POST");
        httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
        httpURLConnection.setRequestProperty("Charset", "UTF-8");
        httpURLConnection.setRequestProperty("Content-Type", "text/xml");
        DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
        FileInputStream fileInputStream = new FileInputStream(this.reportFilePath);
        byte[] bArr = new byte[8192];
        while (true) {
            int read = fileInputStream.read(bArr);
            if (read == -1) {
                fileInputStream.close();
                dataOutputStream.writeBytes("\r\n");
                dataOutputStream.flush();
                InputStream inputStream = httpURLConnection.getInputStream();
                String readLine = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")).readLine();
                Logger.i(TAG, "upload result:" + readLine);
                dataOutputStream.close();
                inputStream.close();
                return;
            }
            dataOutputStream.write(bArr, 0, read);
        }
    }

    public void printAudioInfomation(AudioInformation audioInformation) throws IOException {
        printProperty("audio.format", audioInformation.getAudioType() + "");
        printProperty("audio.sampleRate", audioInformation.getSampleRate() + "");
        printProperty("audio.PlaySample", audioInformation.getPlaySample() + "");
        printProperty("audio.bitDepth", audioInformation.getBitDepth() + "");
        printProperty("audio.channels", audioInformation.getChannels() + "");
        printProperty("audio.duration", audioInformation.getDuration() + "");
        printProperty("audio.bitRate", audioInformation.getBitrate() + "");
    }

    @Override
    public void putBoolean(String str, boolean z) {
    }

    @Override
    public void putInt(String str, int i) {
    }

    @Override
    public void putLong(String str, long j) {
        this.prefInfos.put(str, Long.valueOf(j));
    }

    @Override
    public void putString(String str, String str2) {
    }

    @Override
    public void putUri(String str, Uri uri) {
    }

    public void upLoadPrefInfos(final AudioInformation audioInformation) {
        HashMap<String, Long> hashMap = this.prefInfos;
        if (hashMap == null || hashMap.isEmpty()) {
            return;
        }
        if (this.mHandlerThread == null || this.mReportHandler == null) {
            this.mHandlerThread = new HandlerThread("PrefInfoCollector");
            this.mHandlerThread.start();
            this.mReportHandler = new Handler(this.mHandlerThread.getLooper());
        }
        this.mReportHandler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    PrefInfoCollector.this.createOutputs();
                    PrefInfoCollector.this.printPrefInfos(audioInformation);
                    PrefInfoCollector.this.upLoadByCommonPost();
                } catch (Exception e) {
                    Logger.e(PrefInfoCollector.TAG, e);
                }
            }
        });
    }
}