1- package Localization ;
1+ package edu . fiu . adwise . fingerprint_localization . localization ;
22
33import android .util .Log ;
44
1414import edu .fiu .adwise .fingerprint_localization .structs .LocalizationResult ;
1515import edu .fiu .adwise .fingerprint_localization .structs .SendTrainingData ;
1616import edu .fiu .adwise .homomorphic_encryption .misc .HomomorphicException ;
17- import ui .MainActivity ;
18- import ui .TrainActivity ;
17+ import edu . fiu . adwise . fingerprint_localization . ui .MainActivity ;
18+ import edu . fiu . adwise . fingerprint_localization . ui .TrainActivity ;
1919
2020
21- import static ui .MainActivity .SQLDatabase ;
22- import static ui .MainActivity .portNumber ;
21+ import static edu . fiu . adwise . fingerprint_localization . ui .MainActivity .SQLDatabase ;
22+ import static edu . fiu . adwise . fingerprint_localization . ui .MainActivity .portNumber ;
2323import edu .fiu .adwise .fingerprint_localization .distance_computation .LOCALIZATION_SCHEME ;
2424
2525import edu .fiu .adwise .homomorphic_encryption .dgk .DGKOperations ;
3030import edu .fiu .adwise .homomorphic_encryption .paillier .PaillierPublicKey ;
3131import edu .fiu .adwise .homomorphic_encryption .socialistmillionaire .bob ;
3232
33- public class ClientThread implements Runnable
34- {
33+ public class ClientThread implements Runnable {
3534 private final static String TAG = "CLIENT_THREAD" ;
36-
37- private ObjectOutputStream toServer = null ;
38- private ObjectInputStream fromServer = null ;
39-
4035 //Pass Data back to class by reference...
4136 private background findMe ;
4237 private TrainActivity trainMe ;
4338 private background getColumns ;
44-
45- //Data Objects
46- private SendTrainingData sendTraining ; //Training Data
47- private SendLocalizationData transmission ; //For Encrypted Paillier/DGK Transmission
48-
39+ private SendTrainingData sendTraining ;
40+ private SendLocalizationData transmission ;
4941 // Have all Keys in case comparison is needed!!
5042 private final DGKPublicKey pubKey = KeyMaster .DGKpk ;
5143 private final DGKPrivateKey privKey = KeyMaster .DGKsk ;
5244 private final PaillierPublicKey pk = KeyMaster .pk ;
5345 private final PaillierPrivateKey sk = KeyMaster .sk ;
5446
5547 private final LOCALIZATION_SCHEME LOCALIZATIONSCHEME ;
56- private Socket clientSocket ;
57-
5848 // Get all currently trained points
5949 public ClientThread (TrainActivity trainActivity ) {
6050 this .LOCALIZATIONSCHEME = LOCALIZATION_SCHEME .from_int (-3 );
@@ -66,8 +56,7 @@ public ClientThread(TrainActivity trainActivity) {
6656 Purpose: Force mySQL Database to process data from
6757 training data.
6858 */
69- public ClientThread ()
70- {
59+ public ClientThread () {
7160 this .LOCALIZATIONSCHEME = LOCALIZATION_SCHEME .from_int (-2 );
7261 }
7362
@@ -93,12 +82,11 @@ public ClientThread (SendTrainingData in) {
9382
9483 public void run () {
9584 Object in ;
96- try
97- {
98- clientSocket = new Socket (SQLDatabase , portNumber );
99- // Prepare I/O Stream
100- this .toServer = new ObjectOutputStream (clientSocket .getOutputStream ());
101- this .fromServer = new ObjectInputStream (clientSocket .getInputStream ());
85+ try (
86+ Socket clientSocket = new Socket (SQLDatabase , portNumber );
87+ ObjectOutputStream toServer = new ObjectOutputStream (clientSocket .getOutputStream ());
88+ ObjectInputStream fromServer = new ObjectInputStream (clientSocket .getInputStream ())
89+ ) {
10290 Log .d (TAG , "I/O Streams set!" );
10391
10492 switch (LOCALIZATIONSCHEME ) {
@@ -110,16 +98,6 @@ public void run () {
11098 toServer .writeObject (KeyMaster .map_name );
11199 toServer .flush ();
112100
113- // Following this patch the server needs to know the Phone as well
114- if (MainActivity .multi_phone ) {
115- String [] phone_data = MainActivity .getPhoneData ();
116- for (String s : phone_data ) {
117- Log .d (TAG , s );
118- }
119- toServer .writeObject (phone_data );
120- toServer .flush ();
121- }
122-
123101 in = fromServer .readObject ();
124102 if (in instanceof Double []) {
125103 trainMe .existingX = (Double []) in ;
@@ -155,7 +133,6 @@ public void run () {
155133 break ;
156134 case GET_COLUMN :
157135 toServer .writeObject ("Get Lookup Columns" );
158-
159136 // Send the Map with all (x, y)
160137 toServer .writeObject (KeyMaster .map_name );
161138 toServer .flush ();
@@ -179,7 +156,6 @@ public void run () {
179156 MainActivity .bad_train .show ();
180157 }
181158 break ;
182-
183159 case PLAIN_MIN :
184160 case PLAIN_DMA :
185161 case PLAIN_MCA :
@@ -189,7 +165,7 @@ public void run () {
189165 case DGK_MIN :
190166 case DGK_MCA :
191167 case DGK_DMA :
192- localize ();
168+ localize (clientSocket , toServer , fromServer );
193169 break ;
194170 default :
195171 Log .d (TAG , "Error at Thread run: No Valid Object was sent here" );
@@ -209,7 +185,11 @@ public void run () {
209185 }
210186 }
211187
212- private void localize () throws IOException , ClassNotFoundException , HomomorphicException {
188+ private void localize (
189+ Socket clientSocket ,
190+ ObjectOutputStream toServer ,
191+ ObjectInputStream fromServer
192+ ) throws IOException , ClassNotFoundException , HomomorphicException {
213193 bob andrew ;
214194 BigInteger [] location ;
215195 BigInteger divisor ;
0 commit comments