/docs/weixin_7.0.4_source/反编译源码/未反混淆/src/main/java/com/google/android/exoplayer2/h/s.java

https://github.com/HelloHuDi/AndroidReverseNotes · Java · 275 lines · 248 code · 27 blank · 0 comment · 41 complexity · 2f0194ae784b50c9c5dbd8e4b1233073 MD5 · raw file

  1. package com.google.android.exoplayer2.h;
  2. import android.annotation.SuppressLint;
  3. import android.os.Handler;
  4. import android.os.Looper;
  5. import android.os.Message;
  6. import android.os.SystemClock;
  7. import com.google.android.exoplayer2.i.t;
  8. import com.google.android.exoplayer2.i.v;
  9. import com.tencent.matrix.trace.core.AppMethodBeat;
  10. import java.io.IOException;
  11. import java.util.concurrent.ExecutorService;
  12. public final class s {
  13. IOException biw;
  14. final ExecutorService bqJ;
  15. b<? extends c> bqK;
  16. public interface a<T extends c> {
  17. int a(T t, long j, long j2, IOException iOException);
  18. void a(T t, long j, long j2);
  19. void a(T t, long j, long j2, boolean z);
  20. }
  21. @SuppressLint({"HandlerLeak"})
  22. final class b<T extends c> extends Handler implements Runnable {
  23. private final T bqL;
  24. private final a<T> bqM;
  25. public final int bqN;
  26. private final long bqO;
  27. private IOException bqP;
  28. private int bqQ;
  29. private volatile Thread bqR;
  30. private volatile boolean released;
  31. public b(Looper looper, T t, a<T> aVar, int i, long j) {
  32. super(looper);
  33. this.bqL = t;
  34. this.bqM = aVar;
  35. this.bqN = i;
  36. this.bqO = j;
  37. }
  38. public final void start(long j) {
  39. AppMethodBeat.i(95844);
  40. com.google.android.exoplayer2.i.a.checkState(s.this.bqK == null);
  41. s.this.bqK = this;
  42. if (j > 0) {
  43. sendEmptyMessageDelayed(0, j);
  44. AppMethodBeat.o(95844);
  45. return;
  46. }
  47. execute();
  48. AppMethodBeat.o(95844);
  49. }
  50. public final void cancel(boolean z) {
  51. AppMethodBeat.i(95845);
  52. this.released = z;
  53. this.bqP = null;
  54. if (hasMessages(0)) {
  55. removeMessages(0);
  56. if (!z) {
  57. sendEmptyMessage(1);
  58. }
  59. } else {
  60. this.bqL.se();
  61. if (this.bqR != null) {
  62. this.bqR.interrupt();
  63. }
  64. }
  65. if (z) {
  66. finish();
  67. long elapsedRealtime = SystemClock.elapsedRealtime();
  68. this.bqM.a(this.bqL, elapsedRealtime, elapsedRealtime - this.bqO, true);
  69. }
  70. AppMethodBeat.o(95845);
  71. }
  72. public final void run() {
  73. AppMethodBeat.i(95846);
  74. try {
  75. this.bqR = Thread.currentThread();
  76. if (!this.bqL.sf()) {
  77. t.beginSection("load:" + this.bqL.getClass().getSimpleName());
  78. this.bqL.sg();
  79. t.endSection();
  80. }
  81. if (!this.released) {
  82. sendEmptyMessage(2);
  83. }
  84. AppMethodBeat.o(95846);
  85. } catch (IOException e) {
  86. if (!this.released) {
  87. obtainMessage(3, e).sendToTarget();
  88. }
  89. AppMethodBeat.o(95846);
  90. } catch (InterruptedException e2) {
  91. com.google.android.exoplayer2.i.a.checkState(this.bqL.sf());
  92. if (!this.released) {
  93. sendEmptyMessage(2);
  94. }
  95. AppMethodBeat.o(95846);
  96. } catch (Exception e3) {
  97. if (!this.released) {
  98. obtainMessage(3, new f(e3)).sendToTarget();
  99. }
  100. AppMethodBeat.o(95846);
  101. } catch (OutOfMemoryError e4) {
  102. if (!this.released) {
  103. obtainMessage(3, new f(e4)).sendToTarget();
  104. }
  105. AppMethodBeat.o(95846);
  106. } catch (Error e5) {
  107. if (!this.released) {
  108. obtainMessage(4, e5).sendToTarget();
  109. }
  110. AppMethodBeat.o(95846);
  111. throw e5;
  112. } catch (Throwable th) {
  113. t.endSection();
  114. AppMethodBeat.o(95846);
  115. }
  116. }
  117. public final void handleMessage(Message message) {
  118. AppMethodBeat.i(95847);
  119. if (this.released) {
  120. AppMethodBeat.o(95847);
  121. } else if (message.what == 0) {
  122. execute();
  123. AppMethodBeat.o(95847);
  124. } else if (message.what == 4) {
  125. Error error = (Error) message.obj;
  126. AppMethodBeat.o(95847);
  127. throw error;
  128. } else {
  129. finish();
  130. long elapsedRealtime = SystemClock.elapsedRealtime();
  131. long j = elapsedRealtime - this.bqO;
  132. if (this.bqL.sf()) {
  133. this.bqM.a(this.bqL, elapsedRealtime, j, false);
  134. AppMethodBeat.o(95847);
  135. return;
  136. }
  137. switch (message.what) {
  138. case 1:
  139. this.bqM.a(this.bqL, elapsedRealtime, j, false);
  140. AppMethodBeat.o(95847);
  141. return;
  142. case 2:
  143. this.bqM.a(this.bqL, elapsedRealtime, j);
  144. AppMethodBeat.o(95847);
  145. return;
  146. case 3:
  147. this.bqP = (IOException) message.obj;
  148. int a = this.bqM.a(this.bqL, elapsedRealtime, j, this.bqP);
  149. if (a != 3) {
  150. if (a != 2) {
  151. if (a == 1) {
  152. a = 1;
  153. } else {
  154. a = this.bqQ + 1;
  155. }
  156. this.bqQ = a;
  157. start((long) Math.min((this.bqQ - 1) * 1000, 5000));
  158. break;
  159. }
  160. }
  161. s.this.biw = this.bqP;
  162. AppMethodBeat.o(95847);
  163. return;
  164. break;
  165. }
  166. AppMethodBeat.o(95847);
  167. }
  168. }
  169. private void execute() {
  170. AppMethodBeat.i(95848);
  171. this.bqP = null;
  172. s.this.bqJ.execute(s.this.bqK);
  173. AppMethodBeat.o(95848);
  174. }
  175. private void finish() {
  176. s.this.bqK = null;
  177. }
  178. }
  179. public interface c {
  180. void se();
  181. boolean sf();
  182. void sg();
  183. }
  184. public interface d {
  185. void rZ();
  186. }
  187. public static final class f extends IOException {
  188. public f(Throwable th) {
  189. super("Unexpected " + th.getClass().getSimpleName() + ": " + th.getMessage(), th);
  190. AppMethodBeat.i(95851);
  191. AppMethodBeat.o(95851);
  192. }
  193. }
  194. static final class e extends Handler implements Runnable {
  195. private final d bqT;
  196. public e(d dVar) {
  197. this.bqT = dVar;
  198. }
  199. public final void run() {
  200. AppMethodBeat.i(95849);
  201. sendEmptyMessage(0);
  202. AppMethodBeat.o(95849);
  203. }
  204. public final void handleMessage(Message message) {
  205. AppMethodBeat.i(95850);
  206. this.bqT.rZ();
  207. AppMethodBeat.o(95850);
  208. }
  209. }
  210. public s(String str) {
  211. AppMethodBeat.i(95852);
  212. this.bqJ = v.aO(str);
  213. AppMethodBeat.o(95852);
  214. }
  215. public final <T extends c> long a(T t, a<T> aVar, int i) {
  216. AppMethodBeat.i(95853);
  217. Looper myLooper = Looper.myLooper();
  218. com.google.android.exoplayer2.i.a.checkState(myLooper != null);
  219. long elapsedRealtime = SystemClock.elapsedRealtime();
  220. new b(myLooper, t, aVar, i, elapsedRealtime).start(0);
  221. AppMethodBeat.o(95853);
  222. return elapsedRealtime;
  223. }
  224. public final boolean isLoading() {
  225. return this.bqK != null;
  226. }
  227. public final void cancelLoading() {
  228. AppMethodBeat.i(95854);
  229. this.bqK.cancel(false);
  230. AppMethodBeat.o(95854);
  231. }
  232. public final boolean a(d dVar) {
  233. AppMethodBeat.i(95855);
  234. boolean z = false;
  235. if (this.bqK != null) {
  236. this.bqK.cancel(true);
  237. if (dVar != null) {
  238. this.bqJ.execute(new e(dVar));
  239. }
  240. } else if (dVar != null) {
  241. dVar.rZ();
  242. z = true;
  243. }
  244. this.bqJ.shutdown();
  245. AppMethodBeat.o(95855);
  246. return z;
  247. }
  248. }