Project

General

Profile

Download (22.2 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / network / RubikNetwork.java @ fcf7320f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.network;
21

    
22
import java.io.BufferedReader;
23
import java.io.InputStream;
24
import java.io.InputStreamReader;
25
import java.net.HttpURLConnection;
26
import java.net.URL;
27
import java.net.UnknownHostException;
28
import java.security.MessageDigest;
29
import java.security.NoSuchAlgorithmException;
30

    
31
import android.app.Activity;
32
import android.content.pm.PackageInfo;
33
import android.content.pm.PackageManager;
34

    
35
import androidx.appcompat.app.AppCompatActivity;
36
import androidx.fragment.app.FragmentActivity;
37

    
38
import org.distorted.library.main.DistortedLibrary;
39
import org.distorted.objectlib.json.JsonWriter;
40
import org.distorted.objects.RubikObjectList;
41

    
42
import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
public class RubikNetwork implements Runnable
47
  {
48
  public interface Receiver
49
    {
50
    void receive(String[][][] country, String[][][] name, float[][][] time);
51
    void message(String mess);
52
    void error(String error);
53
    }
54

    
55
  public static final int MAX_PLACES = 10;
56

    
57
  private static final int DOWNLOAD   = 0;
58
  private static final int SUBMIT     = 1;
59
  private static final int DEBUG      = 2;
60
  private static final int SUSPICIOUS = 3;
61
  private static final int IDLE       = 4;
62

    
63
  private static final int REND_ADRENO= 0;
64
  private static final int REND_MALI  = 1;
65
  private static final int REND_POWER = 2;
66
  private static final int REND_OTHER = 3;
67

    
68
  private final String[] hex = {
69
    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
70
    "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
71
    "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
72
    "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
73
    "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
74
    "%28", "%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f",
75
    "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
76
    "%38", "%39", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f",
77
    "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
78
    "%48", "%49", "%4a", "%4b", "%4c", "%4d", "%4e", "%4f",
79
    "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
80
    "%58", "%59", "%5a", "%5b", "%5c", "%5d", "%5e", "%5f",
81
    "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
82
    "%68", "%69", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f",
83
    "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
84
    "%78", "%79", "%7a", "%7b", "%7c", "%7d", "%7e", "%7f",
85
    "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
86
    "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
87
    "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
88
    "%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
89
    "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
90
    "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
91
    "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
92
    "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf",
93
    "%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7",
94
    "%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf",
95
    "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
96
    "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
97
    "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7",
98
    "%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef",
99
    "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
100
    "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
101
    };
102

    
103
  private static String[][][] mCountry;
104
  private static String[][][] mName;
105
  private static float[][][] mTime;
106
  private static int[][] mPlaces;
107

    
108
  private static RubikNetwork mThis;
109
  private static String mScores = "";
110
  private static boolean mRunning = false;
111
  private static int mMode = IDLE;
112
  private static Receiver mReceiver;
113
  private static String mVersion;
114
  private static String mDebug;
115
  private static int mNumObjects;
116
  private static RubikUpdates mUpdates;
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  private static void initializeStatics()
121
    {
122
    int newNum = RubikObjectList.getNumObjects();
123

    
124
    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][MAX_LEVEL][MAX_PLACES];
125
    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][MAX_LEVEL][MAX_PLACES];
126
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][MAX_LEVEL][MAX_PLACES];
127
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][MAX_LEVEL];
128

    
129
    if( mUpdates==null ) mUpdates = new RubikUpdates();
130

    
131
    mNumObjects = newNum;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  private static String computeHash(String stringToHash, byte[] salt)
137
    {
138
    String generatedPassword;
139

    
140
    try
141
      {
142
      MessageDigest md = MessageDigest.getInstance("MD5");
143
      md.update(salt);
144
      byte[] bytes = md.digest(stringToHash.getBytes());
145
      StringBuilder sb = new StringBuilder();
146

    
147
      for (byte aByte : bytes)
148
        {
149
        sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1));
150
        }
151

    
152
      generatedPassword = sb.toString();
153
      }
154
    catch (NoSuchAlgorithmException e)
155
      {
156
      return "NoSuchAlgorithm";
157
      }
158

    
159
    return generatedPassword;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  private boolean fillValuesNormal()
165
    {
166
    int begin=-1 ,end, len = mScores.length();
167
    String row;
168

    
169
    if( len==0 )
170
      {
171
      if( mReceiver!=null ) mReceiver.error("1");
172
      return false;
173
      }
174
    else if( len<=2 )
175
      {
176
      if( mReceiver!=null ) mReceiver.error(mScores);
177
      return false;
178
      }
179

    
180
    for(int i=0; i<mNumObjects; i++)
181
      for(int j=0; j<MAX_LEVEL; j++)
182
        {
183
        mPlaces[i][j] = 0;
184
        }
185

    
186
    while( begin<len )
187
      {
188
      end = mScores.indexOf('\n', begin+1);
189
      if( end<0 ) end = len;
190

    
191
      try
192
        {
193
        row = mScores.substring(begin+1,end);
194
        fillRow(row);
195
        }
196
      catch(Exception ex)
197
        {
198
        // faulty row - ignore
199
        }
200

    
201
      begin = end;
202
      }
203

    
204
    return true;
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  private void fillRow(String row)
210
    {
211
    int s1 = row.indexOf(' ');
212
    int s2 = row.indexOf(' ',s1+1);
213
    int s3 = row.indexOf(' ',s2+1);
214
    int s4 = row.indexOf(' ',s3+1);
215
    int s5 = row.length();
216

    
217
    if( s5>s4 && s4>s3 && s3>s2 && s2>s1 && s1>0 )
218
      {
219
      int object = RubikObjectList.getOrdinal( row.substring(0,s1) );
220

    
221
      if( object>=0 && object<mNumObjects )
222
        {
223
        int level      = Integer.parseInt( row.substring(s1+1,s2) );
224
        String name    = row.substring(s2+1, s3);
225
        int time       = Integer.parseInt( row.substring(s3+1,s4) );
226
        String country = row.substring(s4+1, s5);
227

    
228
        if( country.equals("do") ) country = "dm"; // see RubikScores.setCountry()
229

    
230
        if(level>=0 && level<MAX_LEVEL)
231
          {
232
          int p = mPlaces[object][level];
233
          mPlaces[object][level]++;
234

    
235
          mCountry[object][level][p] = country;
236
          mName   [object][level][p] = name;
237
          mTime   [object][level][p] = ((float)(time/10))/100.0f;
238
          }
239
        }
240
      }
241
    else
242
      {
243
      tryDoCommand(row);
244
      }
245
    }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
  private void tryDoCommand(String row)
250
    {
251
    if( row.startsWith("comm") )
252
      {
253
      int colon = row.indexOf(':');
254

    
255
      if( colon>0 )
256
        {
257
        String commandNumber = row.substring(4,colon);
258
        int number;
259

    
260
        try
261
          {
262
          number = Integer.parseInt(commandNumber);
263
          }
264
        catch(NumberFormatException ex)
265
          {
266
          number=0;
267
          }
268

    
269
        if(number==1)
270
          {
271
          String country = row.substring(colon+1);
272
          RubikScores scores = RubikScores.getInstance();
273
          scores.setCountry(country);
274
          }
275
        }
276
      }
277
    }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
  private int getRendererType(String renderer)
282
    {
283
    if( renderer.contains("Adreno")  ) return REND_ADRENO;
284
    if( renderer.contains("Mali")    ) return REND_MALI;
285
    if( renderer.contains("PowerVR") ) return REND_POWER;
286

    
287
    return REND_OTHER;
288
    }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
  private String parseRenderer(final int type, String renderer)
293
    {
294
    if( type==REND_ADRENO || type==REND_POWER )
295
      {
296
      int lastSpace = renderer.lastIndexOf(' ');
297
      String ret = renderer.substring(lastSpace+1);
298
      return URLencode(ret);
299
      }
300

    
301
    if( type==REND_MALI )
302
      {
303
      int firstHyphen = renderer.indexOf('-');
304
      String ret = renderer.substring(firstHyphen+1);
305
      return URLencode(ret);
306
      }
307

    
308
    return "other";
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

    
313
  private String parseVersion(final int type, String version)
314
    {
315
    switch(type)
316
      {
317
      case REND_ADRENO: int aMonkey = version.indexOf('@');
318
                        int aDot = version.indexOf('.', aMonkey);
319
                        String ret1 = aDot>=3 ? version.substring(aDot-3,aDot) : "";
320
                        return URLencode(ret1);
321
      case REND_MALI  : int mV1 = version.indexOf("v1");
322
                        int mHyphen = version.indexOf('-', mV1);
323
                        String ret2 = mHyphen>mV1+3 && mV1>=0 ? version.substring(mV1+3,mHyphen) : "";
324
                        return URLencode(ret2);
325
      case REND_POWER : int pMonkey = version.indexOf('@');
326
                        int pSpace  = version.lastIndexOf(' ');
327
                        String ret3 = pSpace>=0 && pMonkey>pSpace+1 ? version.substring(pSpace+1,pMonkey) : "";
328
                        return URLencode(ret3);
329
      default         : return "";
330
      }
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  private String URLencode(String s)
336
    {
337
    StringBuilder sbuf = new StringBuilder();
338
    int len = s.length();
339

    
340
    for (int i = 0; i < len; i++)
341
      {
342
      int ch = s.charAt(i);
343

    
344
           if ('A' <= ch && ch <= 'Z') sbuf.append((char)ch);
345
      else if ('a' <= ch && ch <= 'z') sbuf.append((char)ch);
346
      else if ('0' <= ch && ch <= '9') sbuf.append((char)ch);
347
      else if (ch == ' '             ) sbuf.append('+');
348
      else if (ch == '-' || ch == '_'
349
            || ch == '.' || ch == '!'
350
            || ch == '~' || ch == '*'
351
            || ch == '\'' || ch == '('
352
            || ch == ')'             ) sbuf.append((char)ch);
353
      else if (ch <= 0x007f)           sbuf.append(hex[ch]);
354
      else if (ch <= 0x07FF)
355
        {
356
        sbuf.append(hex[0xc0 | (ch >> 6)]);
357
        sbuf.append(hex[0x80 | (ch & 0x3F)]);
358
        }
359
      else
360
        {
361
        sbuf.append(hex[0xe0 | (ch >> 12)]);
362
        sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]);
363
        sbuf.append(hex[0x80 | (ch & 0x3F)]);
364
        }
365
      }
366

    
367
    return sbuf.toString();
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  private void sendDebug()
373
    {
374
    String url = constructDebugURL();
375

    
376
    try
377
      {
378
      java.net.URL connectURL = new URL(url);
379
      HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
380

    
381
      conn.setDoInput(true);
382
      conn.setDoOutput(true);
383
      conn.setUseCaches(false);
384
      conn.setRequestMethod("GET");
385
      conn.connect();
386
      conn.getOutputStream().flush();
387

    
388
      InputStream is = conn.getInputStream();
389
      BufferedReader r = new BufferedReader(new InputStreamReader(is));
390
      StringBuilder answer = new StringBuilder();
391

    
392
      for (String line; (line = r.readLine()) != null; )
393
        {
394
        answer.append(line).append('\n');
395
        }
396

    
397
      String updates = answer.toString();
398
      mUpdates.parse(updates);
399
      }
400
    catch( final Exception e )
401
      {
402
      // ignore
403
      }
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  private void sendSuspicious()
409
    {
410
    String url = constructSuspiciousURL();
411

    
412
    try
413
      {
414
      java.net.URL connectURL = new URL(url);
415
      HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
416

    
417
      conn.setDoInput(true);
418
      conn.setDoOutput(true);
419
      conn.setUseCaches(false);
420
      conn.setRequestMethod("GET");
421
      conn.connect();
422
      conn.getOutputStream().flush();
423
      conn.getInputStream();
424
      }
425
    catch( final Exception e )
426
      {
427
      // ignore
428
      }
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

    
433
  private boolean network(String url)
434
    {
435
    try
436
      {
437
      java.net.URL connectURL = new URL(url);
438
      HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
439

    
440
      conn.setDoInput(true);
441
      conn.setDoOutput(true);
442
      conn.setUseCaches(false);
443
      conn.setRequestMethod("GET");
444
      conn.connect();
445
      conn.getOutputStream().flush();
446

    
447
      InputStream is = conn.getInputStream();
448
      BufferedReader r = new BufferedReader(new InputStreamReader(is));
449
      StringBuilder total = new StringBuilder();
450

    
451
      for (String line; (line = r.readLine()) != null; )
452
        {
453
        total.append(line).append('\n');
454
        }
455

    
456
      mScores = total.toString();
457
      }
458
    catch( final UnknownHostException e )
459
      {
460
      if( mReceiver!=null ) mReceiver.message("No access to Internet");
461
      return false;
462
      }
463
    catch( final SecurityException e )
464
      {
465
      if( mReceiver!=null ) mReceiver.message("Application not authorized to connect to the Internet");
466
      return false;
467
      }
468
    catch( final Exception e )
469
      {
470
      if( mReceiver!=null ) mReceiver.message(e.getMessage());
471
      return false;
472
      }
473

    
474
    if( mScores.length()==0 )
475
      {
476
      if( mReceiver!=null ) mReceiver.message("Failed to download scores");
477
      return false;
478
      }
479

    
480
    return true;
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
  private String constructSuspiciousURL()
486
    {
487
    RubikScores scores = RubikScores.getInstance();
488
    int deviceID= scores.getDeviceID();
489
    String debug = URLencode(mDebug);
490

    
491
    String url="https://distorted.org/magic/cgi-bin/suspicious.cgi";
492
    url += "?i="+deviceID+"&d="+debug;
493

    
494
    return url;
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  private String constructDebugURL()
500
    {
501
    RubikScores scores = RubikScores.getInstance();
502
    String name = URLencode(scores.getName());
503
    int numRuns = scores.getNumRuns();
504
    int numPlay = scores.getNumPlays();
505
    String country = scores.getCountry();
506
    String renderer = DistortedLibrary.getDriverRenderer();
507
    String version  = DistortedLibrary.getDriverVersion();
508
    int objectAPI   = JsonWriter.VERSION_OBJECT_MAJOR;
509
    int tutorialAPI = JsonWriter.VERSION_EXTRAS_MAJOR;
510

    
511
    renderer = URLencode(renderer);
512
    version  = URLencode(version);
513

    
514
    String url="https://distorted.org/magic/cgi-bin/debugs-new.cgi";
515
    url += "?n="+name+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion+"d";
516
    url += "&d="+renderer+"&v="+version+"&a="+objectAPI+"&b="+tutorialAPI;
517

    
518
    return url;
519
    }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

    
523
  private String constructDownloadURL()
524
    {
525
    RubikScores scores = RubikScores.getInstance();
526
    String name = URLencode(scores.getName());
527
    int numRuns = scores.getNumRuns();
528
    int numPlay = scores.getNumPlays();
529
    String country = scores.getCountry();
530

    
531
    String url="https://distorted.org/magic/cgi-bin/download.cgi";
532
    url += "?n="+name+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion;
533

    
534
    return url;
535
    }
536

    
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

    
539
  private String constructSubmitURL()
540
    {
541
    RubikScores scores = RubikScores.getInstance();
542
    String name = URLencode(scores.getName());
543
    String veri = scores.isVerified() ? "1" : "";
544
    int numRuns = scores.getNumRuns();
545
    int numPlay = scores.getNumPlays();
546
    int deviceID= scores.getDeviceID();
547
    String reclist = scores.getRecordList("&o=","&l=","&t=");
548
    String country = scores.getCountry();
549
    long epoch = System.currentTimeMillis();
550
    String salt = "cuboid";
551

    
552
    String renderer = DistortedLibrary.getDriverRenderer();
553
    String version  = DistortedLibrary.getDriverVersion();
554

    
555
    int type = getRendererType(renderer);
556
    renderer = parseRenderer(type,renderer);
557
    version  = parseVersion(type,version);
558

    
559
    String url1="https://distorted.org/magic/cgi-bin/submit.cgi";
560
    String url2 = "n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion;
561
    url2 += "&d="+renderer+"&s="+version+reclist+"&c="+country+"&f="+epoch;
562
    String hash = computeHash( url2, salt.getBytes() );
563

    
564
    return url1 + "?" + url2 + "&h=" + hash;
565
    }
566

    
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568

    
569
  private boolean gottaDownload()
570
    {
571
    return ((mScores.length()==0) && !mRunning);
572
    }
573

    
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575

    
576
  @Override
577
  public void run()
578
    {
579
    boolean receiveValues=true;
580

    
581
    initializeStatics();
582

    
583
    try
584
      {
585
      if( mMode==DOWNLOAD && gottaDownload() )
586
        {
587
        mRunning = true;
588
        receiveValues = network(constructDownloadURL());
589
        }
590
      if( mMode==SUBMIT )
591
        {
592
        mRunning = true;
593
        RubikScores scores = RubikScores.getInstance();
594

    
595
        if( scores.thereAreUnsubmittedRecords() )
596
          {
597
          receiveValues = network(constructSubmitURL());
598
          }
599
        }
600
      if( mMode==DEBUG )
601
        {
602
        sendDebug();
603
        receiveValues = false;
604
        mRunning = false;
605
        }
606
      if( mMode==SUSPICIOUS )
607
        {
608
        sendSuspicious();
609
        receiveValues = false;
610
        mRunning = false;
611
        }
612
      }
613
    catch( Exception e )
614
      {
615
      if( mReceiver!=null ) mReceiver.message("Exception downloading records: "+e.getMessage() );
616
      }
617

    
618
    if( mRunning )
619
      {
620
      receiveValues = fillValuesNormal();
621
      mRunning = false;
622
      }
623

    
624
    if( receiveValues )
625
      {
626
      if( mReceiver!=null ) mReceiver.receive(mCountry, mName, mTime);
627

    
628
      if( mMode==SUBMIT )
629
        {
630
        RubikScores.getInstance().successfulSubmit();
631
        }
632
      }
633
    }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636

    
637
  private RubikNetwork()
638
    {
639

    
640
    }
641

    
642
///////////////////////////////////////////////////////////////////////////////////////////////////
643
// PUBLIC API
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

    
646
  public static void onPause()
647
    {
648
    mRunning = false;
649
    }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652

    
653
  public static RubikNetwork getInstance()
654
    {
655
    if( mThis==null )
656
      {
657
      mThis = new RubikNetwork();
658
      }
659

    
660
    return mThis;
661
    }
662

    
663
///////////////////////////////////////////////////////////////////////////////////////////////////
664

    
665
  private void start(Receiver receiver, Activity act, int mode)
666
    {
667
    mReceiver = receiver;
668
    mMode     = mode;
669

    
670
    try
671
      {
672
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
673
      mVersion = pInfo.versionName;
674
      }
675
    catch (PackageManager.NameNotFoundException e)
676
      {
677
      mVersion = "0.9.2";
678
      }
679

    
680
    Thread networkThrd = new Thread(this);
681
    networkThrd.start();
682
    }
683

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685

    
686
  public void download(Receiver receiver, FragmentActivity act)
687
    {
688
    start(receiver, act, DOWNLOAD);
689
    }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
  public void submit(Receiver receiver, FragmentActivity act)
694
    {
695
    start(receiver, act, SUBMIT);
696
    }
697

    
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

    
700
  public void debug(AppCompatActivity act)
701
    {
702
    start(null, act, DEBUG);
703
    }
704

    
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706

    
707
  public void suspicious(AppCompatActivity act, String debug)
708
    {
709
    mDebug = debug;
710
    start(null, act, SUSPICIOUS);
711
    }
712
}
(1-1/3)