Revision 1fa125c2
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/network/RubikNetwork.java | ||
---|---|---|
36 | 36 |
import androidx.fragment.app.FragmentActivity; |
37 | 37 |
|
38 | 38 |
import org.distorted.library.main.DistortedLibrary; |
39 |
import org.distorted.objects.RubikObject; |
|
40 | 39 |
import org.distorted.objects.RubikObjectList; |
41 | 40 |
|
42 | 41 |
import static org.distorted.objects.RubikObjectList.MAX_LEVEL; |
... | ... | |
57 | 56 |
private static final int DOWNLOAD = 0; |
58 | 57 |
private static final int SUBMIT = 1; |
59 | 58 |
private static final int DEBUG = 2; |
60 |
private static final int IDLE = 3; |
|
59 |
private static final int SUSPICIOUS = 3; |
|
60 |
private static final int IDLE = 4; |
|
61 | 61 |
|
62 | 62 |
private static final int REND_ADRENO= 0; |
63 | 63 |
private static final int REND_MALI = 1; |
... | ... | |
110 | 110 |
private static int mMode = IDLE; |
111 | 111 |
private static Receiver mReceiver; |
112 | 112 |
private static String mVersion; |
113 |
private static String mDebug; |
|
113 | 114 |
private static int mNumObjects; |
114 | 115 |
|
115 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
387 | 388 |
} |
388 | 389 |
} |
389 | 390 |
|
391 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
392 |
|
|
393 |
private void sendSuspicious() |
|
394 |
{ |
|
395 |
String url = constructSuspiciousURL(); |
|
396 |
|
|
397 |
try |
|
398 |
{ |
|
399 |
java.net.URL connectURL = new URL(url); |
|
400 |
HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection(); |
|
401 |
|
|
402 |
conn.setDoInput(true); |
|
403 |
conn.setDoOutput(true); |
|
404 |
conn.setUseCaches(false); |
|
405 |
conn.setRequestMethod("GET"); |
|
406 |
conn.connect(); |
|
407 |
conn.getOutputStream().flush(); |
|
408 |
conn.getInputStream(); |
|
409 |
} |
|
410 |
catch( final Exception e ) |
|
411 |
{ |
|
412 |
// ignore |
|
413 |
} |
|
414 |
} |
|
415 |
|
|
390 | 416 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
391 | 417 |
|
392 | 418 |
private boolean network(String url) |
... | ... | |
439 | 465 |
return true; |
440 | 466 |
} |
441 | 467 |
|
468 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
469 |
|
|
470 |
private String constructSuspiciousURL() |
|
471 |
{ |
|
472 |
RubikScores scores = RubikScores.getInstance(); |
|
473 |
int deviceID= scores.getDeviceID(); |
|
474 |
String debug = URLencode(mDebug); |
|
475 |
|
|
476 |
String url="https://distorted.org/magic/cgi-bin/suspicious.cgi"; |
|
477 |
url += "?i="+deviceID+"&d="+debug; |
|
478 |
|
|
479 |
return url; |
|
480 |
} |
|
481 |
|
|
442 | 482 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
443 | 483 |
|
444 | 484 |
private String constructDebugURL() |
... | ... | |
460 | 500 |
return url; |
461 | 501 |
} |
462 | 502 |
|
463 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
464 |
|
|
465 |
private static String getObjectList() |
|
466 |
{ |
|
467 |
StringBuilder list = new StringBuilder(); |
|
468 |
|
|
469 |
for(int i=0; i<mNumObjects; i++) |
|
470 |
{ |
|
471 |
RubikObject object = RubikObjectList.getObject(i); |
|
472 |
|
|
473 |
if( object!=null ) |
|
474 |
{ |
|
475 |
if( i>0 ) list.append(','); |
|
476 |
list.append(object.getName()); |
|
477 |
} |
|
478 |
} |
|
479 |
|
|
480 |
return list.toString(); |
|
481 |
} |
|
482 |
|
|
483 | 503 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
484 | 504 |
|
485 | 505 |
private String constructDownloadURL() |
... | ... | |
552 | 572 |
if( mMode==SUBMIT ) |
553 | 573 |
{ |
554 | 574 |
mRunning = true; |
575 |
RubikScores scores = RubikScores.getInstance(); |
|
555 | 576 |
|
556 |
if( RubikScores.getInstance().thereAreUnsubmittedRecords() )
|
|
577 |
if( scores.thereAreUnsubmittedRecords() )
|
|
557 | 578 |
{ |
558 | 579 |
receiveValues = network(constructSubmitURL()); |
559 | 580 |
} |
... | ... | |
564 | 585 |
receiveValues = false; |
565 | 586 |
mRunning = false; |
566 | 587 |
} |
588 |
if( mMode==SUSPICIOUS ) |
|
589 |
{ |
|
590 |
sendSuspicious(); |
|
591 |
receiveValues = false; |
|
592 |
mRunning = false; |
|
593 |
} |
|
567 | 594 |
} |
568 | 595 |
catch( Exception e ) |
569 | 596 |
{ |
... | ... | |
656 | 683 |
{ |
657 | 684 |
start(null, act, DEBUG); |
658 | 685 |
} |
686 |
|
|
687 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
688 |
|
|
689 |
public void suspicious(AppCompatActivity act, String debug) |
|
690 |
{ |
|
691 |
mDebug = debug; |
|
692 |
start(null, act, SUSPICIOUS); |
|
693 |
} |
|
659 | 694 |
} |
Also available in: Unified diff
Add debugging for the case when people submit suspicious records.