[tor-commits] [snowflake-mobile/master] Added permissions and registered the service

cohosh at torproject.org cohosh at torproject.org
Fri Jun 5 17:49:16 UTC 2020


commit 712dbdd579266bbcfc1389de15cdb5cc2aa8df87
Author: Hashik Donthineni <HashikDonthineni at gmail.com>
Date:   Fri Jun 5 03:39:51 2020 +0530

    Added permissions and registered the service
---
 app/src/main/AndroidManifest.xml                             | 12 ++++++++++++
 .../java/org/torproject/snowflake/MyPersistentService.java   | 11 ++++++++---
 app/src/main/res/values/strings.xml                          |  2 +-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9e4b070..7728955 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,12 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="org.torproject.snowflake">
 
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+
     <application
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
@@ -9,6 +15,12 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
+
+        <service
+            android:name="org.torproject.snowflake.MyPersistentService"
+            android:enabled="true"
+            android:exported="false" />
+
         <activity android:name=".MainActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index 5d6c03e..bdb2e54 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -29,12 +29,17 @@ public class MyPersistentService extends Service {
         super.onCreate();
         Log.d(TAG, "onCreate: Service Created");
 
-        sharedPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE);
-        sharedPreferencesHelper(ForegroundServiceConstants.SERVICE_RUNNING);
+        sharedPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE); //Assigning the shared preferences
+        sharedPreferencesHelper(ForegroundServiceConstants.SERVICE_RUNNING); //Editing the shared preferences
         Notification notification = createPersistentNotification(false, null);
         startForeground(ForegroundServiceConstants.DEF_NOTIFICATION_ID, notification);
     }
 
+    /**
+     * Helper function to edit shared preference file.
+     *
+     * @param setState State from ForegroundServiceConstants
+     */
     private void sharedPreferencesHelper(final int setState) {
         Log.d(TAG, "sharedPreferencesHelper: Setting Shared Preference Running To: " + setState);
         SharedPreferences.Editor editor = sharedPreferences.edit();
@@ -51,7 +56,7 @@ public class MyPersistentService extends Service {
      * Create a new persistent notification
      *
      * @param isUpdate is this new notification an update to current one?
-     * @param update String that is to be updated will current. Send "null" if isUpdate is false.
+     * @param update   String that is to be updated will current. Send "null" if isUpdate is false.
      * @return New Notification with given parameters.
      */
     private Notification createPersistentNotification(final boolean isUpdate, final String update) {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7448d1e..d737520 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">TestFlake</string>
+    <string name="app_name">Snowflake</string>
     <string name="sharedpreference_file">org.torproject.snowflake.snowflake_preferences</string>
     <string name="is_service_running_bool">is_service_running</string>
     <string name="not_channel_desc">This Channel should not be muted. The Android system will consider Snowflake not import and will kill the service if it\'s muted.</string>





More information about the tor-commits mailing list