简书链接:QQ语音782的语音红包触发run方法逻辑
文章字数:843,阅读全文大约需要3分钟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
package defpackage;

import android.os.Build;
import android.os.Build.VERSION;
import android.os.Process;
import android.os.SystemClock;
import com.tencent.mobileqq.ptt.processor.IPttProcessor;
import com.tencent.mobileqq.ptt.processor.IPttProcessor.ProcessData;
import com.tencent.mobileqq.ptt.processor.IPttProcessorListener;
import com.tencent.mobileqq.transfile.PttInfoCollector;
import com.tencent.mobileqq.utils.AudioHelper;
import com.tencent.mobileqq.utils.AudioUtil;
import com.tencent.mobileqq.utils.QQRecorder;
import com.tencent.mobileqq.utils.QQRecorder.RecordNoPermissonException;
import com.tencent.mobileqq.utils.WechatNsWrapper;
import com.tencent.qphone.base.util.QLog;
import java.util.HashMap;

/* compiled from: ProGuard */
public class ammg extends Thread implements IPttProcessorListener {
int a = 0;
long f0a = 0;
final /* synthetic */ QQRecorder f1a;
public String f2a;
public volatile boolean f3a = true;
public volatile boolean b = true;
private boolean c;

public ammg(QQRecorder qQRecorder) {
this.f1a = qQRecorder;
}

public void run() {
while (this.b) {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "RecordThread : begin run");
}
this.f3a = true;
this.c = false;
a(this.f2a);
if (this.b) {
long uptimeMillis = SystemClock.uptimeMillis();
synchronized (this.f1a) {
this.f1a.wait((long) QQRecorder.a);
}
if (SystemClock.uptimeMillis() - uptimeMillis < ((long) QQRecorder.a)) {
continue;
} else {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "RecordThread more than maxtime release");
}
synchronized (this) {
this.b = false;
}
try {
a();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
a();
}

private void a(String str) {
long j;
int read;
Throwable th;
Object obj;
HashMap hashMap;
int i;
StringBuilder stringBuilder;
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "RecordThread doRecord: " + this);
}
long j2 = 0;
long j3 = 0;
int i2 = 0;
double d = 0.0d;
long currentTimeMillis = System.currentTimeMillis();
long j4 = 0;
long j5 = 0;
int i3 = 0;
long j6 = 0;
int i4 = 250;
Process.setThreadPriority(-19);
AudioUtil.a(QQRecorder.a(this.f1a), true);
HashMap hashMap2;
int i5;
StringBuilder stringBuilder2;
try {
int a;
if (QQRecorder.a(this.f1a) != null) {
QQRecorder.a(this.f1a).a(str, this.f1a.a);
}
byte[] bArr = new byte[QQRecorder.b(this.f1a)];
QQRecorder.a(this.f1a);
if (QQRecorder.a(this.f1a) != null) {
i4 = QQRecorder.a(this.f1a).a();
if (i4 <= 0) {
i4 = 250;
}
i4 = QQRecorder.a(i4);
}
if (QLog.isDevelopLevel()) {
QLog.d("QQRecorder", 4, "PTT onRecordReady cost : " + (SystemClock.uptimeMillis() - PttInfoCollector.a));
}
QQRecorder.b(this.f1a);
QQRecorder.a(this.f1a).a(this);
Thread.sleep(200);
int b = (QQRecorder.b(this.f1a.a.a) / 1000) * i4;
int i6 = 0;
while (i6 < b) {
i4 = QQRecorder.b(this.f1a);
if (QQRecorder.b(this.f1a) > b - i6) {
i4 = b - i6;
}
QQRecorder.a(this.f1a).read(bArr, 0, i4);
i6 = i4 + i6;
}
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "MyThread abandonBuf, abandonSize:" + i6 + " abandonBufLen:" + b);
}
if (QQRecorder.a(this.f1a) != null) {
a = QQRecorder.a(this.f1a).a(this.f2a, this.f1a.a);
} else {
a = -1;
}
if (QLog.isDevelopLevel()) {
QLog.d("QQRecorder", 4, "PTT onBeginReceiveData cost : " + (SystemClock.uptimeMillis() - PttInfoCollector.a));
}
long currentTimeMillis2 = System.currentTimeMillis();
int i7 = 0;
i6 = 0;
long j7 = 0;
Object obj2 = null;
long j8 = 0;
j2 = 0;
double d2 = 0.0d;
while (this.f3a && !this.c) {
try {
if (System.currentTimeMillis() - currentTimeMillis2 > 1000 && r16 == null) {
obj2 = 1;
if (j7 == 0 || i3 == 0) {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "record abnormal: data size = " + j7 + ", max volume = " + i3);
}
throw new RecordNoPermissonException("no permission");
}
}
Object obj3 = obj2;
if (System.currentTimeMillis() - currentTimeMillis2 > 1000 && r4 == 0) {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "check 1000ms max volume, volume: " + this.a);
}
if (this.a <= 0 || this.a >= 500) {
i7 = 2;
} else {
i7 = 1;
}
if (QQRecorder.a(this.f1a) != null) {
QQRecorder.a(this.f1a).a(i7);
}
}
j = j8 + 1;
try {
read = QQRecorder.a(this.f1a).read(bArr, 0, QQRecorder.b(this.f1a));
if (read <= 0) {
try {
Thread.sleep(10);
obj2 = obj3;
i6 = read;
j8 = j;
} catch (Throwable th2) {
th = th2;
j3 = j7;
i2 = read;
d = d2;
obj = null;
}
} else {
j3 = 1 + j5;
long j9 = j7 + ((long) read);
try {
int a2 = (int) AudioHelper.a(QQRecorder.a(this.f1a), bArr, read, 1.0f);
int max = Math.max(i3, a2);
j7 = j6 + ((long) a2);
try {
ProcessData a3 = QQRecorder.a(this.f1a).a(bArr, 0, read);
PttInfoCollector.b();
d2 += QQRecorder.a((long) read, this.f1a.a.a);
if (!(QQRecorder.a(this.f1a) == null || a3 == null)) {
QQRecorder.a(this.f1a).a(str, a3.a, a3.a, QQRecorder.c(this.f1a), d2, this.f1a.a);
}
if (a3 != null) {
j6 = ((long) a3.a) + j2;
} else {
j6 = j2;
}
if (i7 == 1) {
try {
if (this.a > 500) {
i7 = 2;
if (QQRecorder.a(this.f1a) != null) {
QQRecorder.a(this.f1a).a(2);
}
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "volume state changed, normal volume: " + this.a);
}
}
} catch (Throwable th3) {
th = th3;
i3 = max;
j5 = j3;
j2 = j6;
j6 = j7;
d = d2;
j3 = j9;
i2 = i6;
obj = null;
}
}
if (a != -1 && d2 >= ((double) a)) {
this.c = true;
}
i3 = max;
j5 = j3;
j2 = j6;
j6 = j7;
obj2 = obj3;
j8 = j;
j7 = j9;
} catch (Throwable th4) {
th = th4;
j6 = j7;
i3 = max;
j5 = j3;
d = d2;
i2 = i6;
j3 = j9;
obj = null;
}
} catch (Throwable th5) {
th = th5;
j5 = j3;
d = d2;
i2 = i6;
obj = null;
j3 = j9;
}
}
} catch (Throwable th6) {
th = th6;
d = d2;
j3 = j7;
i2 = i6;
obj = null;
}
} catch (Throwable th7) {
th = th7;
j3 = j7;
j = j8;
i2 = i6;
d = d2;
obj = null;
}
}
if (QQRecorder.a(this.f1a) != null) {
QQRecorder.a(this.f1a).a(str, this.f1a.a, d2);
if (!(this.f1a.a == null || QQRecorder.d(this.f1a) == -1)) {
this.f1a.a.setMode(0);
}
}
if (QQRecorder.a(this.f1a) != null && QQRecorder.a(this.f1a).getState() == 1) {
QQRecorder.a(this.f1a).stop();
}
try {
QQRecorder.c(this.f1a);
} catch (Throwable th8) {
th8.printStackTrace();
}
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "MyThread end: " + this);
QLog.d("QQRecorder", 2, "read times = " + j8 + " orginal data size = " + j7 + "arm data size = " + j2 + " error code = " + i6);
}
AudioUtil.a(QQRecorder.a(this.f1a), false);
if ((j2 < 512 || d2 < 1000.0d) && System.currentTimeMillis() - currentTimeMillis > 1000) {//如果arm大小小于512 ,或者读取时间小于1000但是总时长间隔超过了1000.那么就研究你触摸了多久。
try {
hashMap2 = new HashMap();
hashMap2.put("exceptionType", "1");
hashMap2.put("osVersion", VERSION.SDK_INT + "");
hashMap2.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
hashMap2.put("dataSize", j7 + "");
hashMap2.put("maxVolume", i3 + "");
hashMap2.put("readTime", d2 + "");
hashMap2.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
QQRecorder.a("actPttRecordException", false, hashMap2);
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "report exception(short record) | exception type = 1 | dataSize = " + j7 + " | amrSize = " + j2 + " | readTime = " + d2 + " | toucTime = " + (System.currentTimeMillis() - currentTimeMillis));
}
} catch (Throwable th82) {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "Report exception error.", th82);
}
}
}
try {
hashMap2 = new HashMap();
hashMap2.put("osVersion", VERSION.SDK_INT + "");
hashMap2.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
hashMap2.put("dataSize", j7 + "");
hashMap2.put("pttDuration", d2 + "");
hashMap2.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
hashMap2.put("maxVolume", i3 + "");
hashMap2.put("amrMaxVolume", this.a + "");
read = (int) (j5 == 0 ? -1 : j6 / j5);
if (j5 == 0) {
j6 = -1;
} else {
j6 = this.f0a / j5;
}
i5 = (int) j6;
hashMap2.put("averageVolume", read + "");
hashMap2.put("amrAverageVolume", i5 + "");
QQRecorder.a("actPttRecordVolume", true, hashMap2);
if (QLog.isColorLevel()) {
stringBuilder2 = new StringBuilder();
stringBuilder2.append("report record detail | maxVolume = ").append(i3);
stringBuilder2.append(" | averageVolume = ").append(read);
stringBuilder2.append(" | amrMaxVolume = ").append(i5);
stringBuilder2.append(" | amrAverage = ").append(i5);
stringBuilder2.append(" | dataSize = ").append(j7);
stringBuilder2.append(" | amrSize = ").append(j2);
stringBuilder2.append(" | pttDuration = ").append(d2);
stringBuilder2.append(" | touchTime = ").append(System.currentTimeMillis() - currentTimeMillis);
QLog.d("QQRecorder", 2, stringBuilder2.toString());
}
} catch (Throwable th822) {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "Report record error.", th822);
}
}
} catch (Throwable th9) {
th822 = th9;
j = 0;
j2 = 0;
obj = null;
if (QQRecorder.a(this.f1a) != null && QQRecorder.a(this.f1a).getState() == 1) {
QQRecorder.a(this.f1a).stop();
}
QQRecorder.c(this.f1a);
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "MyThread end: " + this);
QLog.d("QQRecorder", 2, "read times = " + j + " orginal data size = " + j3 + "arm data size = " + j2 + " error code = " + i2);
}
AudioUtil.a(QQRecorder.a(this.f1a), false);
if ((j2 < 512 || d < 1000.0d) && r10 == null && System.currentTimeMillis() - currentTimeMillis > 1000) {
hashMap = new HashMap();
hashMap.put("exceptionType", "1");
hashMap.put("osVersion", VERSION.SDK_INT + "");
hashMap.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
hashMap.put("dataSize", j3 + "");
hashMap.put("maxVolume", i3 + "");
hashMap.put("readTime", d + "");
hashMap.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
QQRecorder.a("actPttRecordException", false, hashMap);
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "report exception(short record) | exception type = 1 | dataSize = " + j3 + " | amrSize = " + j2 + " | readTime = " + d + " | toucTime = " + (System.currentTimeMillis() - currentTimeMillis));
}
}
hashMap = new HashMap();
hashMap.put("osVersion", VERSION.SDK_INT + "");
hashMap.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
hashMap.put("dataSize", j3 + "");
hashMap.put("pttDuration", d + "");
hashMap.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
hashMap.put("maxVolume", i3 + "");
hashMap.put("amrMaxVolume", this.a + "");
if (j5 != 0) {
}
i = (int) (j5 != 0 ? j6 / j5 : -1);
if (j5 != 0) {
j6 = -1;
} else {
j6 = this.f0a / j5;
}
i5 = (int) j6;
hashMap.put("averageVolume", i + "");
hashMap.put("amrAverageVolume", i5 + "");
QQRecorder.a("actPttRecordVolume", true, hashMap);
if (QLog.isColorLevel()) {
stringBuilder = new StringBuilder();
stringBuilder.append("report record detail | maxVolume = ").append(i3);
stringBuilder.append(" | averageVolume = ").append(i);
stringBuilder.append(" | amrMaxVolume = ").append(i5);
stringBuilder.append(" | amrAverage = ").append(i5);
stringBuilder.append(" | dataSize = ").append(j3);
stringBuilder.append(" | amrSize = ").append(j2);
stringBuilder.append(" | pttDuration = ").append(d);
stringBuilder.append(" | touchTime = ").append(System.currentTimeMillis() - currentTimeMillis);
QLog.d("QQRecorder", 2, stringBuilder.toString());
}
throw th822;
}
}

public void a(IPttProcessor iPttProcessor, ProcessData processData) {
if ((iPttProcessor instanceof WechatNsWrapper) && QQRecorder.a(this.f1a) != null) {
QQRecorder.a(this.f1a).b(iPttProcessor, processData);
}
}

public void b(IPttProcessor iPttProcessor, ProcessData processData) {
if (iPttProcessor instanceof WechatNsWrapper) {
QQRecorder.b(this.f1a, (int) AudioHelper.a(QQRecorder.a(this.f1a), processData.a, processData.a, 1.0f));
this.a = Math.max(this.a, QQRecorder.c(this.f1a));
this.f0a += (long) QQRecorder.c(this.f1a);
if (QQRecorder.a(this.f1a) != null) {
QQRecorder.a(this.f1a).a(iPttProcessor, processData);
}
}
}

public boolean m0a() {
return this.b || QQRecorder.a(this.f1a) != null;
}

public void a() {
if (QQRecorder.a(this.f1a) != null) {
if (QLog.isColorLevel()) {
QLog.d("QQRecorder", 2, "releaseRecorder");
}
QQRecorder.a(this.f1a).release();
QQRecorder.a(this.f1a, null);
}
}
}