[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake-mobile/master] Finally implemented the custom URLs in to the service



commit edaa544f29cbead7a8fc976fd958bccd57deedf9
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date:   Sun Jun 28 19:32:14 2020 +0530

    Finally implemented the custom URLs in to the service
---
 app/src/main/AndroidManifest.xml                   |  1 +
 .../torproject/snowflake/GlobalApplication.java    | 30 ++++++++++++++++++++++
 .../torproject/snowflake/MyPersistentService.java  |  5 +++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6b366fb..67e8537 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -9,6 +9,7 @@
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
 
     <application
+        android:name=".GlobalApplication"
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
diff --git a/app/src/main/java/org/torproject/snowflake/GlobalApplication.java b/app/src/main/java/org/torproject/snowflake/GlobalApplication.java
index 8ef1f16..b38393f 100644
--- a/app/src/main/java/org/torproject/snowflake/GlobalApplication.java
+++ b/app/src/main/java/org/torproject/snowflake/GlobalApplication.java
@@ -1,22 +1,45 @@
 package org.torproject.snowflake;
 
 import android.app.Application;
+import android.content.SharedPreferences;
+import android.util.Log;
+
+import org.torproject.snowflake.constants.SettingsConstants;
 
 import java.util.HashMap;
 import java.util.Map;
 
+import static android.content.ContentValues.TAG;
+import static androidx.preference.PreferenceManager.getDefaultSharedPreferences;
+
 public class GlobalApplication extends Application {
     private final static String BROKER_URL = "http://10.0.2.2:8080";; //10.0.2.2 is used to access computer's local host from Android Emulator.
     private final static String WEBSOCKET_URL = "wss://snowflake.freehaven.net:443";
+    private static SharedPreferences sharedPreferences;
 
     public static String getBrokerUrl() {
+        //Checking to see if the switch is turned on.
+        if (sharedPreferences.getBoolean(SettingsConstants.BROKER_SWITCH, false))
+            //Send the custom Broker URL, if the key is not found send default.
+            return sharedPreferences.getString(SettingsConstants.BROKER_ET, BROKER_URL);
         return BROKER_URL;
     }
 
     public static String getWebSocketUrl() {
+        //Checking to see if the switch is turned on.
+        if (sharedPreferences.getBoolean(SettingsConstants.RELAY_SWITCH, false))
+            //Send the custom Socket URL, if the key is not found send default.
+            return sharedPreferences.getString(SettingsConstants.RELAY_ET, WEBSOCKET_URL);
         return WEBSOCKET_URL;
     }
 
+    public static String getSTUN() {
+        //Checking to see if the switch is turned on.
+        if (sharedPreferences.getBoolean(SettingsConstants.STUN_SWITCH, false))
+            return sharedPreferences.getString(SettingsConstants.STUN_ET, null); //Send the custom STUN if it's turned on.
+        return null;
+    }
+
     public static Map<String, String> getHeadersMap() {
         HashMap<String, String> map = new HashMap<>();
         map.put("Content-type", "application/json");
@@ -24,4 +47,11 @@ public class GlobalApplication extends Application {
         map.put("Host", getBrokerUrl().replace("http://";, ""));
         return map;
     }
+
+    @Override
+    public void onCreate() {
+        Log.d(TAG, "onCreate: ");
+        super.onCreate();
+        sharedPreferences = getDefaultSharedPreferences(this);
+    }
 }
diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index 29fdad6..fe85bea 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -276,7 +276,10 @@ public class MyPersistentService extends Service {
     private PeerConnection createPeerConnection(PeerConnectionFactory factory) {
         Log.d(TAG, "createPeerConnection: Creating a new peer connection");
         List<PeerConnection.IceServer> iceServers = new LinkedList<>();
-//        iceServers.add(PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer()); To Add custom ICE servers.
+        if (GlobalApplication.getSTUN() != null) {
+            iceServers.add(PeerConnection.IceServer.builder(GlobalApplication.getSTUN())
+                    .createIceServer()); //Adding custom ICE server.
+        }
         PeerConnection.RTCConfiguration rtcConfiguration = new PeerConnection.RTCConfiguration(iceServers);
         PeerConnection.Observer pcObserver = new MyPeerConnectionObserver(TAG, new PeerConnectionObserverCallback() {
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits