DownloadFileTask.java 14 KB
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
package net.hockeyapp.android.tasks;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Environment;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
import net.hockeyapp.android.R.string;
import net.hockeyapp.android.listeners.DownloadFileListener;

public class DownloadFileTask
  extends AsyncTask<Void, Integer, Long>
{
  protected static final int MAX_REDIRECTS = 6;
  private String a;
  protected Context mContext;
  protected String mFilePath;
  protected String mFilename;
  protected DownloadFileListener mNotifier;
  protected ProgressDialog mProgressDialog;
  protected String mUrlString;
  
  public DownloadFileTask(Context paramContext, String paramString, DownloadFileListener paramDownloadFileListener)
  {
    this.mContext = paramContext;
    this.mUrlString = paramString;
    this.mFilename = (UUID.randomUUID() + ".apk");
    this.mFilePath = (Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download");
    this.mNotifier = paramDownloadFileListener;
    this.a = null;
  }
  
  public void attach(Context paramContext)
  {
    this.mContext = paramContext;
  }
  
  protected URLConnection createConnection(URL paramURL, int paramInt)
    throws IOException
  {
    HttpURLConnection localHttpURLConnection = (HttpURLConnection)paramURL.openConnection();
    setConnectionProperties(localHttpURLConnection);
    int i = localHttpURLConnection.getResponseCode();
    if (((i != 301) && (i != 302) && (i != 303)) || (paramInt == 0)) {}
    URL localURL;
    do
    {
      return localHttpURLConnection;
      localURL = new URL(localHttpURLConnection.getHeaderField("Location"));
    } while (paramURL.getProtocol().equals(localURL.getProtocol()));
    localHttpURLConnection.disconnect();
    return createConnection(localURL, paramInt - 1);
  }
  
  public void detach()
  {
    this.mContext = null;
    this.mProgressDialog = null;
  }
  
  /* Error */
  protected Long doInBackground(Void... paramVarArgs)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 7
    //   3: aconst_null
    //   4: astore 8
    //   6: aload_0
    //   7: new 84	java/net/URL
    //   10: dup
    //   11: aload_0
    //   12: invokevirtual 130	net/hockeyapp/android/tasks/DownloadFileTask:getURLString	()Ljava/lang/String;
    //   15: invokespecial 107	java/net/URL:<init>	(Ljava/lang/String;)V
    //   18: bipush 6
    //   20: invokevirtual 121	net/hockeyapp/android/tasks/DownloadFileTask:createConnection	(Ljava/net/URL;I)Ljava/net/URLConnection;
    //   23: astore_1
    //   24: aload_1
    //   25: invokevirtual 135	java/net/URLConnection:connect	()V
    //   28: aload_1
    //   29: invokevirtual 138	java/net/URLConnection:getContentLength	()I
    //   32: istore_2
    //   33: aload_1
    //   34: invokevirtual 141	java/net/URLConnection:getContentType	()Ljava/lang/String;
    //   37: astore 6
    //   39: aload 6
    //   41: ifnull +24 -> 65
    //   44: aload 6
    //   46: ldc -113
    //   48: invokevirtual 147	java/lang/String:contains	(Ljava/lang/CharSequence;)Z
    //   51: ifeq +14 -> 65
    //   54: aload_0
    //   55: ldc -107
    //   57: putfield 75	net/hockeyapp/android/tasks/DownloadFileTask:a	Ljava/lang/String;
    //   60: lconst_0
    //   61: invokestatic 155	java/lang/Long:valueOf	(J)Ljava/lang/Long;
    //   64: areturn
    //   65: new 64	java/io/File
    //   68: dup
    //   69: aload_0
    //   70: getfield 71	net/hockeyapp/android/tasks/DownloadFileTask:mFilePath	Ljava/lang/String;
    //   73: invokespecial 156	java/io/File:<init>	(Ljava/lang/String;)V
    //   76: astore 6
    //   78: aload 6
    //   80: invokevirtual 160	java/io/File:mkdirs	()Z
    //   83: ifne +87 -> 170
    //   86: aload 6
    //   88: invokevirtual 163	java/io/File:exists	()Z
    //   91: ifne +79 -> 170
    //   94: new 82	java/io/IOException
    //   97: dup
    //   98: new 34	java/lang/StringBuilder
    //   101: dup
    //   102: ldc -91
    //   104: invokespecial 166	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   107: aload 6
    //   109: invokevirtual 67	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   112: invokevirtual 50	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   115: invokevirtual 54	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   118: invokespecial 167	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   121: athrow
    //   122: astore 7
    //   124: aconst_null
    //   125: astore_1
    //   126: aload 8
    //   128: astore 6
    //   130: aload 7
    //   132: invokevirtual 170	java/io/IOException:printStackTrace	()V
    //   135: lconst_0
    //   136: invokestatic 155	java/lang/Long:valueOf	(J)Ljava/lang/Long;
    //   139: astore 7
    //   141: aload 6
    //   143: ifnull +8 -> 151
    //   146: aload 6
    //   148: invokevirtual 175	java/io/OutputStream:close	()V
    //   151: aload_1
    //   152: ifnull +236 -> 388
    //   155: aload_1
    //   156: invokevirtual 178	java/io/InputStream:close	()V
    //   159: aload 7
    //   161: areturn
    //   162: astore_1
    //   163: aload_1
    //   164: invokevirtual 170	java/io/IOException:printStackTrace	()V
    //   167: aload 7
    //   169: areturn
    //   170: new 64	java/io/File
    //   173: dup
    //   174: aload 6
    //   176: aload_0
    //   177: getfield 56	net/hockeyapp/android/tasks/DownloadFileTask:mFilename	Ljava/lang/String;
    //   180: invokespecial 181	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   183: astore 9
    //   185: new 183	java/io/BufferedInputStream
    //   188: dup
    //   189: aload_1
    //   190: invokevirtual 187	java/net/URLConnection:getInputStream	()Ljava/io/InputStream;
    //   193: invokespecial 190	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   196: astore 6
    //   198: new 192	java/io/FileOutputStream
    //   201: dup
    //   202: aload 9
    //   204: invokespecial 195	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   207: astore_1
    //   208: sipush 1024
    //   211: newarray <illegal type>
    //   213: astore 7
    //   215: lconst_0
    //   216: lstore 4
    //   218: aload 6
    //   220: aload 7
    //   222: invokevirtual 199	java/io/InputStream:read	([B)I
    //   225: istore_3
    //   226: iload_3
    //   227: iconst_m1
    //   228: if_icmpeq +47 -> 275
    //   231: lload 4
    //   233: iload_3
    //   234: i2l
    //   235: ladd
    //   236: lstore 4
    //   238: aload_0
    //   239: iconst_1
    //   240: anewarray 201	java/lang/Integer
    //   243: dup
    //   244: iconst_0
    //   245: lload 4
    //   247: l2f
    //   248: ldc -54
    //   250: fmul
    //   251: iload_2
    //   252: i2f
    //   253: fdiv
    //   254: invokestatic 208	java/lang/Math:round	(F)I
    //   257: invokestatic 211	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   260: aastore
    //   261: invokevirtual 215	net/hockeyapp/android/tasks/DownloadFileTask:publishProgress	([Ljava/lang/Object;)V
    //   264: aload_1
    //   265: aload 7
    //   267: iconst_0
    //   268: iload_3
    //   269: invokevirtual 219	java/io/OutputStream:write	([BII)V
    //   272: goto -54 -> 218
    //   275: aload_1
    //   276: invokevirtual 222	java/io/OutputStream:flush	()V
    //   279: lload 4
    //   281: invokestatic 155	java/lang/Long:valueOf	(J)Ljava/lang/Long;
    //   284: astore 7
    //   286: aload_1
    //   287: invokevirtual 175	java/io/OutputStream:close	()V
    //   290: aload 6
    //   292: invokevirtual 178	java/io/InputStream:close	()V
    //   295: aload 7
    //   297: areturn
    //   298: astore_1
    //   299: aload_1
    //   300: invokevirtual 170	java/io/IOException:printStackTrace	()V
    //   303: aload 7
    //   305: areturn
    //   306: astore_1
    //   307: aconst_null
    //   308: astore 6
    //   310: aload 7
    //   312: ifnull +8 -> 320
    //   315: aload 7
    //   317: invokevirtual 175	java/io/OutputStream:close	()V
    //   320: aload 6
    //   322: ifnull +8 -> 330
    //   325: aload 6
    //   327: invokevirtual 178	java/io/InputStream:close	()V
    //   330: aload_1
    //   331: athrow
    //   332: astore 6
    //   334: aload 6
    //   336: invokevirtual 170	java/io/IOException:printStackTrace	()V
    //   339: goto -9 -> 330
    //   342: astore_1
    //   343: goto -33 -> 310
    //   346: astore 8
    //   348: aload_1
    //   349: astore 7
    //   351: aload 8
    //   353: astore_1
    //   354: goto -44 -> 310
    //   357: astore 7
    //   359: aload_1
    //   360: astore 8
    //   362: aload 7
    //   364: astore_1
    //   365: aload 6
    //   367: astore 7
    //   369: aload 8
    //   371: astore 6
    //   373: goto -63 -> 310
    //   376: astore 7
    //   378: aload 6
    //   380: astore_1
    //   381: aload 8
    //   383: astore 6
    //   385: goto -255 -> 130
    //   388: aload 7
    //   390: areturn
    //   391: astore 7
    //   393: aload 6
    //   395: astore 8
    //   397: aload_1
    //   398: astore 6
    //   400: aload 8
    //   402: astore_1
    //   403: goto -273 -> 130
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	406	0	this	DownloadFileTask
    //   0	406	1	paramVarArgs	Void[]
    //   32	220	2	i	int
    //   225	44	3	j	int
    //   216	64	4	l	long
    //   37	289	6	localObject1	Object
    //   332	34	6	localIOException1	IOException
    //   371	28	6	localObject2	Object
    //   1	1	7	localObject3	Object
    //   122	9	7	localIOException2	IOException
    //   139	211	7	localObject4	Object
    //   357	6	7	localObject5	Object
    //   367	1	7	localObject6	Object
    //   376	13	7	localIOException3	IOException
    //   391	1	7	localIOException4	IOException
    //   4	123	8	localObject7	Object
    //   346	6	8	localObject8	Object
    //   360	41	8	localObject9	Object
    //   183	20	9	localFile	File
    // Exception table:
    //   from	to	target	type
    //   6	39	122	java/io/IOException
    //   44	65	122	java/io/IOException
    //   65	122	122	java/io/IOException
    //   170	198	122	java/io/IOException
    //   146	151	162	java/io/IOException
    //   155	159	162	java/io/IOException
    //   286	295	298	java/io/IOException
    //   6	39	306	finally
    //   44	65	306	finally
    //   65	122	306	finally
    //   170	198	306	finally
    //   315	320	332	java/io/IOException
    //   325	330	332	java/io/IOException
    //   198	208	342	finally
    //   208	215	346	finally
    //   218	226	346	finally
    //   238	272	346	finally
    //   275	286	346	finally
    //   130	141	357	finally
    //   198	208	376	java/io/IOException
    //   208	215	391	java/io/IOException
    //   218	226	391	java/io/IOException
    //   238	272	391	java/io/IOException
    //   275	286	391	java/io/IOException
  }
  
  protected String getURLString()
  {
    return this.mUrlString + "&type=apk";
  }
  
  protected void onPostExecute(Long paramLong)
  {
    if (this.mProgressDialog != null) {}
    try
    {
      this.mProgressDialog.dismiss();
      if (paramLong.longValue() > 0L)
      {
        this.mNotifier.downloadSuccessful(this);
        paramLong = new Intent("android.intent.action.VIEW");
        paramLong.setDataAndType(Uri.fromFile(new File(this.mFilePath, this.mFilename)), "application/vnd.android.package-archive");
        paramLong.setFlags(268435456);
        this.mContext.startActivity(paramLong);
        return;
      }
    }
    catch (Exception localException)
    {
      try
      {
        AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.mContext);
        localBuilder.setTitle(R.string.hockeyapp_download_failed_dialog_title);
        if (this.a == null) {}
        for (paramLong = this.mContext.getString(R.string.hockeyapp_download_failed_dialog_message);; paramLong = this.a)
        {
          localBuilder.setMessage(paramLong);
          localBuilder.setNegativeButton(R.string.hockeyapp_download_failed_dialog_negative_button, new DialogInterface.OnClickListener()
          {
            public final void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
            {
              DownloadFileTask.this.mNotifier.downloadFailed(DownloadFileTask.this, Boolean.valueOf(false));
            }
          });
          localBuilder.setPositiveButton(R.string.hockeyapp_download_failed_dialog_positive_button, new DialogInterface.OnClickListener()
          {
            public final void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
            {
              DownloadFileTask.this.mNotifier.downloadFailed(DownloadFileTask.this, Boolean.valueOf(true));
            }
          });
          localBuilder.create().show();
          return;
        }
        localException = localException;
      }
      catch (Exception paramLong) {}
    }
  }
  
  protected void onProgressUpdate(Integer... paramVarArgs)
  {
    try
    {
      if (this.mProgressDialog == null)
      {
        this.mProgressDialog = new ProgressDialog(this.mContext);
        this.mProgressDialog.setProgressStyle(1);
        this.mProgressDialog.setMessage("Loading...");
        this.mProgressDialog.setCancelable(false);
        this.mProgressDialog.show();
      }
      this.mProgressDialog.setProgress(paramVarArgs[0].intValue());
      return;
    }
    catch (Exception paramVarArgs) {}
  }
  
  protected void setConnectionProperties(HttpURLConnection paramHttpURLConnection)
  {
    paramHttpURLConnection.addRequestProperty("User-Agent", "HockeySDK/Android");
    paramHttpURLConnection.setInstanceFollowRedirects(true);
    if (Build.VERSION.SDK_INT <= 9) {
      paramHttpURLConnection.setRequestProperty("connection", "close");
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/net/hockeyapp/android/tasks/DownloadFileTask.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */