[tor-commits] [orbot/master] ran lint to remove a lot of avoidable warnings

n8fr8 at torproject.org n8fr8 at torproject.org
Wed Oct 7 12:37:35 UTC 2020


commit 49da6819c5045bc3a263526bc14d58181ee6e3a5
Author: bim <dsnake at protonmail.com>
Date:   Tue Sep 15 22:36:13 2020 -0400

    ran lint to remove a lot of avoidable warnings
---
 .../org/torproject/android/OrbotMainActivity.java  | 14 ++--
 .../torproject/android/ui/AppManagerActivity.java  |  5 +-
 .../ui/hiddenservices/ClientCookiesActivity.java   |  2 +-
 .../ui/hiddenservices/HiddenServicesActivity.java  |  2 +-
 .../ui/hiddenservices/backup/BackupUtils.java      |  2 +-
 .../android/ui/hiddenservices/backup/ZipIt.java    |  2 +-
 .../permissions/PermissionManager.java             |  2 +-
 .../providers/CookieContentProvider.java           |  4 +-
 .../providers/HSContentProvider.java               |  4 +-
 .../ui/onboarding/BridgeWizardActivity.java        |  3 -
 .../res/layout/layout_client_cookie_list_item.xml  |  1 -
 app/src/main/res/menu/cookie_menu.xml              |  3 +-
 app/src/main/res/values/ic_launcher_background.xml |  2 -
 app/src/main/res/xml/hidden_services_paths.xml     |  2 +-
 .../torproject/android/service/OrbotService.java   | 76 +++++++++-------------
 .../android/service/TorEventHandler.java           | 57 +++++++---------
 .../android/service/util/CustomShell.java          |  4 +-
 .../android/service/util/ExternalIPFetcher.java    |  4 +-
 .../android/service/util/TCPSourceApp.java         |  3 -
 .../org/torproject/android/service/util/Utils.java | 11 ++--
 .../android/service/vpn/OrbotVpnManager.java       |  6 +-
 .../android/service/vpn/TorifiedApp.java           |  6 +-
 .../torproject/android/service/vpn/Tun2Socks.java  |  3 +-
 orbotservice/src/main/res/values/colors.xml        |  2 -
 24 files changed, 88 insertions(+), 132 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 2e7809f1..f336e8bf 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -163,12 +163,8 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
                     String log = (String) msg.obj;
 
                     if (torStatus == null && newTorStatus != null) //first time status
-                    {
                         findViewById(R.id.frameMain).setVisibility(View.VISIBLE);
-                        updateStatus(log, newTorStatus);
-
-                    } else
-                        updateStatus(log, newTorStatus);
+                    updateStatus(log, newTorStatus);
                     super.handleMessage(msg);
                     break;
             }
@@ -327,8 +323,6 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
     private void doLayout() {
         setContentView(R.layout.layout_main);
 
-        setTitle(R.string.app_name);
-
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
 
@@ -1226,7 +1220,7 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
 
     @RequiresApi(api = Build.VERSION_CODES.KITKAT)
     private void exportTorData() {
-        File fileTorData = null;
+        File fileTorData;
         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
             fileTorData = new File(getDataDir(), DIRECTORY_TOR_DATA);
         } else {
@@ -1242,9 +1236,9 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
 
     public static class DataCount {
         // data uploaded
-        long Upload;
+        final long Upload;
         // data downloaded
-        long Download;
+        final long Download;
 
         DataCount(long Upload, long Download) {
             this.Upload = Upload;
diff --git a/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java b/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java
index 1871a061..aae3d72a 100644
--- a/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java
@@ -56,8 +56,7 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList
     // returns true if the given app is enabled and not orbot
     public static boolean includeAppInUi(ApplicationInfo applicationInfo) {
         if (!applicationInfo.enabled) return false;
-        if (BuildConfig.APPLICATION_ID.equals(applicationInfo.packageName)) return false;
-        return true;
+        return !BuildConfig.APPLICATION_ID.equals(applicationInfo.packageName);
     }
 
     protected void onCreate(Bundle savedInstanceState) {
@@ -296,7 +295,7 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList
 
         Editor edit = mPrefs.edit();
         edit.putString(PREFS_KEY_TORIFIED, tordApps.toString());
-        edit.commit();
+        edit.apply();
 
         setResult(RESULT_OK, response);
     }
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java
index c5f8a5e1..eca76b70 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/ClientCookiesActivity.java
@@ -125,7 +125,7 @@ public class ClientCookiesActivity extends AppCompatActivity {
 
     @Override
     public void onRequestPermissionsResult(int requestCode,
-                                           String permissions[], int[] grantResults) {
+                                           String[] permissions, int[] grantResults) {
         if (grantResults.length < 1
                 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
             return;
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java
index bfd29645..13fb70bd 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java
@@ -168,7 +168,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
 
     @Override
     public void onRequestPermissionsResult(int requestCode,
-                                           String permissions[], int[] grantResults) {
+                                           String[] permissions, int[] grantResults) {
         if (grantResults.length < 1
                 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
             return;
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
index 67918d13..45b07bf5 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
@@ -125,7 +125,7 @@ public class BackupUtils {
         }
 
         String zip_path = storage_path.getAbsolutePath() + "/hs" + port + ".zip";
-        String files[] = {hostnameFilePath, keyFilePath, configFilePath};
+        String[] files = {hostnameFilePath, keyFilePath, configFilePath};
 
         ZipIt zip = new ZipIt(files, zip_path);
 
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/ZipIt.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/ZipIt.java
index 4a42df1f..88f82c9e 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/ZipIt.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/ZipIt.java
@@ -33,7 +33,7 @@ public class ZipIt {
 
             ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
 
-            byte data[] = new byte[BUFFER];
+            byte[] data = new byte[BUFFER];
 
             for (String _file : _files) {
                 FileInputStream fi = new FileInputStream(_file);
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/permissions/PermissionManager.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/permissions/PermissionManager.java
index 95bacd59..af23919f 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/permissions/PermissionManager.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/permissions/PermissionManager.java
@@ -18,7 +18,7 @@ import androidx.fragment.app.FragmentActivity;
 import org.torproject.android.R;
 
 public class PermissionManager {
-    public static int VERY_LONG_LENGTH = 6000;
+    public static final int VERY_LONG_LENGTH = 6000;
 
     public static boolean isLollipopOrHigher() {
         return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/CookieContentProvider.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/CookieContentProvider.java
index 318e37af..26a6d9d6 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/CookieContentProvider.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/CookieContentProvider.java
@@ -99,7 +99,7 @@ public class CookieContentProvider extends ContentProvider {
 
         SQLiteDatabase db = mServervices.getWritableDatabase();
 
-        Integer rows = db.delete(HSDatabase.HS_CLIENT_COOKIE_TABLE_NAME, where, selectionArgs);
+        int rows = db.delete(HSDatabase.HS_CLIENT_COOKIE_TABLE_NAME, where, selectionArgs);
 
         mContext.getContentResolver().notifyChange(CONTENT_URI, null);
 
@@ -116,7 +116,7 @@ public class CookieContentProvider extends ContentProvider {
             where = "_id=" + uri.getLastPathSegment();
         }
 
-        Integer rows = db.update(HSDatabase.HS_CLIENT_COOKIE_TABLE_NAME, values, where, null);
+        int rows = db.update(HSDatabase.HS_CLIENT_COOKIE_TABLE_NAME, values, where, null);
         mContext.getContentResolver().notifyChange(CONTENT_URI, null);
 
         return rows;
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java
index 5cf20f8e..87cad0ad 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java
@@ -104,7 +104,7 @@ public class HSContentProvider extends ContentProvider {
 
         SQLiteDatabase db = mServervices.getWritableDatabase();
 
-        Integer rows = db.delete(HSDatabase.HS_DATA_TABLE_NAME, where, selectionArgs);
+        int rows = db.delete(HSDatabase.HS_DATA_TABLE_NAME, where, selectionArgs);
 
         mContext.getContentResolver().notifyChange(CONTENT_URI, null);
 
@@ -121,7 +121,7 @@ public class HSContentProvider extends ContentProvider {
             where = "_id=" + uri.getLastPathSegment();
         }
 
-        Integer rows = db.update(HSDatabase.HS_DATA_TABLE_NAME, values, where, null);
+        int rows = db.update(HSDatabase.HS_DATA_TABLE_NAME, values, where, null);
         mContext.getContentResolver().notifyChange(CONTENT_URI, null);
 
         return rows;
diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java
index 4ffb7d36..abc89ff2 100644
--- a/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/onboarding/BridgeWizardActivity.java
@@ -26,7 +26,6 @@ import java.io.InputStreamReader;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
-import java.util.ArrayList;
 import java.util.StringTokenizer;
 
 public class BridgeWizardActivity extends AppCompatActivity {
@@ -190,8 +189,6 @@ public class BridgeWizardActivity extends AppCompatActivity {
             hostTester.execute("meek.azureedge.net", "443");
         } else if (Prefs.getBridgesList().equals("obfs4")) {
 
-            ArrayList alBridges = new ArrayList<String>();
-
             try {
                 BufferedReader in =
                         new BufferedReader(new InputStreamReader(getResources().openRawResource(org.torproject.android.service.R.raw.bridges), "UTF-8"));
diff --git a/app/src/main/res/layout/layout_client_cookie_list_item.xml b/app/src/main/res/layout/layout_client_cookie_list_item.xml
index 80eefb94..1d5d1ccb 100644
--- a/app/src/main/res/layout/layout_client_cookie_list_item.xml
+++ b/app/src/main/res/layout/layout_client_cookie_list_item.xml
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal"
diff --git a/app/src/main/res/menu/cookie_menu.xml b/app/src/main/res/menu/cookie_menu.xml
index 78110252..3593f565 100644
--- a/app/src/main/res/menu/cookie_menu.xml
+++ b/app/src/main/res/menu/cookie_menu.xml
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item
         android:id="@+id/cookie_restore_backup"
diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml
deleted file mode 100644
index a6b3daec..00000000
--- a/app/src/main/res/values/ic_launcher_background.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources></resources>
\ No newline at end of file
diff --git a/app/src/main/res/xml/hidden_services_paths.xml b/app/src/main/res/xml/hidden_services_paths.xml
index 073732b6..22485918 100644
--- a/app/src/main/res/xml/hidden_services_paths.xml
+++ b/app/src/main/res/xml/hidden_services_paths.xml
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
-<paths xmlns:android="http://schemas.android.com/apk/res/android">
+<paths>
     <files-path name="hidden-services" path="hidden_services/" />
 </paths>
\ No newline at end of file
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
index c2a51326..820c84d6 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -209,17 +209,12 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
     @RequiresApi(api = Build.VERSION_CODES.O)
     private void createNotificationChannel() {
-        NotificationManager mNotificationManager =
-                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-// The id of the channel.
-
-// The user-visible name of the channel.
-        CharSequence name = getString(R.string.app_name);
-// The user-visible description of the channel.
-        String description = getString(R.string.app_description);
-        int importance = NotificationManager.IMPORTANCE_LOW;
-        NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
-// Configure the notification channel.
+        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+
+        CharSequence name = getString(R.string.app_name); // The user-visible name of the channel.
+        String description = getString(R.string.app_description); // The user-visible description of the channel.
+        NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, NotificationManager.IMPORTANCE_LOW);
+        // Configure the notification channel.
         mChannel.setDescription(description);
         mChannel.enableLights(false);
         mChannel.enableVibration(false);
@@ -378,7 +373,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
             if (conn != null)
                 conn.signal("HUP");
 
-            return;
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -535,10 +529,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
             prefs.edit().putString(PREF_BINARY_TOR_VERSION_INSTALLED, BINARY_TOR_VERSION).apply();
 
             fileTorRc = new File(appBinHome, "torrc");//installer.getTorrcFile();
-            if (!fileTorRc.exists())
-                return false;
-
-            return true;
+            return fileTorRc.exists();
         }
 
         return false;
@@ -677,7 +668,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
     }
 
-    public boolean updateTorConfigCustom(File fileTorRcCustom, String extraLines) throws IOException, FileNotFoundException, TimeoutException {
+    public boolean updateTorConfigCustom(File fileTorRcCustom, String extraLines) throws IOException, TimeoutException {
         FileWriter fos = new FileWriter(fileTorRcCustom, false);
         PrintWriter ps = new PrintWriter(fos);
         ps.print(extraLines);
@@ -757,7 +748,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
             //sendCallbackLogMessage(getString(R.string.status_starting_up));
             //logNotice(getString(R.string.status_starting_up));
 
-            ArrayList<String> customEnv = new ArrayList<String>();
+            ArrayList<String> customEnv = new ArrayList<>();
 
             if (Prefs.bridgesEnabled())
                 if (Prefs.useVpn() && !mIsLollipop) {
@@ -871,7 +862,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                 exitCode = exec(torCmdString, false);
             } catch (Exception e) {
                 logNotice("Tor was unable to start: " + e.getMessage());
-                result = false;
 
                 throw new Exception("Tor was unable to start: " + e.getMessage());
 
@@ -887,7 +877,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
             if (mLastProcessId == -1) {
                 logNotice(getString(R.string.couldn_t_start_tor_process_) + "; exit=" + exitCode);
-                result = false;
                 throw new Exception(getString(R.string.couldn_t_start_tor_process_) + "; exit=" + exitCode);
             } else {
 
@@ -904,7 +893,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
     }
 
     private int exec(String cmd, boolean wait) throws Exception {
-        HashMap<String, String> mapEnv = new HashMap();
+        HashMap<String, String> mapEnv = new HashMap<>();
         mapEnv.put("HOME", appBinHome.getAbsolutePath());
 
         CommandResult result = CustomShell.run("sh", wait, mapEnv, cmd);
@@ -984,11 +973,9 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                 //       conn.setEvents(Arrays.asList(new String[]{"DEBUG","STATUS_CLIENT","STATUS_GENERAL","BW"}));
 
                 if (Prefs.useDebugLogging())
-                    conn.setEvents(Arrays.asList(new String[]{
-                            "CIRC", "STREAM", "ORCONN", "BW", "INFO", "NOTICE", "WARN", "DEBUG", "ERR", "NEWDESC", "ADDRMAP"}));
+                    conn.setEvents(Arrays.asList("CIRC", "STREAM", "ORCONN", "BW", "INFO", "NOTICE", "WARN", "DEBUG", "ERR", "NEWDESC", "ADDRMAP"));
                 else
-                    conn.setEvents(Arrays.asList(new String[]{
-                            "CIRC", "STREAM", "ORCONN", "BW", "NOTICE", "ERR", "NEWDESC", "ADDRMAP"}));
+                    conn.setEvents(Arrays.asList("CIRC", "STREAM", "ORCONN", "BW", "NOTICE", "ERR", "NEWDESC", "ADDRMAP"));
 
                 //  sendCallbackLogMessage(getString(R.string.tor_process_starting) + ' ' + getString(R.string.tor_process_complete));
 
@@ -1060,7 +1047,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
                 //store last valid control port
                 SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext());
-                prefs.edit().putInt("controlport", result).commit();
+                prefs.edit().putInt("controlport", result).apply();
             } else {
                 debug("Control Port config file does not yet exist (waiting for tor): " + fileControlPort.getCanonicalPath());
             }
@@ -1090,8 +1077,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
     public String getInfo(String key) {
         try {
             if (conn != null) {
-                String m = conn.getInfo(key);
-                return m;
+                return conn.getInfo(key);
             }
         } catch (Exception ioe) {
             //    Log.e(TAG,"Unable to get Tor information",ioe);
@@ -1108,7 +1094,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                 List<ConfigEntry> listCe = conn.getConf(name);
 
                 Iterator<ConfigEntry> itCe = listCe.iterator();
-                ConfigEntry ce = null;
+                ConfigEntry ce;
 
 
                 while (itCe.hasNext()) {
@@ -1137,21 +1123,20 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
 
         if (configBuffer == null)
-            configBuffer = new ArrayList<String>();
+            configBuffer = new ArrayList<>();
 
         if (resetBuffer == null)
-            resetBuffer = new ArrayList<String>();
+            resetBuffer = new ArrayList<>();
 
         if (value == null || value.length() == 0) {
             resetBuffer.add(name + RESET_STRING);
 
         } else {
-            StringBuffer sbConf = new StringBuffer();
-            sbConf.append(name);
-            sbConf.append(' ');
-            sbConf.append(value);
 
-            configBuffer.add(sbConf.toString());
+            String sbConf = name +
+                    ' ' +
+                    value;
+            configBuffer.add(sbConf);
         }
 
         return false;
@@ -1394,7 +1379,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
                     String proxyType = "socks5";
                     extraLines.append(proxyType + "Proxy" + ' ' + OrbotVpnManager.sSocksProxyLocalhost + ':' + OrbotVpnManager.sSocksProxyServerPort).append('\n');
                 }
-                ;
 
             } else {
                 String proxyType = prefs.getString("pref_proxy_type", null);
@@ -1613,31 +1597,31 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
         switch (level) {
             case TRIM_MEMORY_BACKGROUND:
                 debug("trim memory requested: app in the background");
-                return;
+                break;
 
             case TRIM_MEMORY_COMPLETE:
                 debug("trim memory requested: cleanup all memory");
-                return;
+                break;
 
             case TRIM_MEMORY_MODERATE:
                 debug("trim memory requested: clean up some memory");
-                return;
+                break;
 
             case TRIM_MEMORY_RUNNING_CRITICAL:
                 debug("trim memory requested: memory on device is very low and critical");
-                return;
+                break;
 
             case TRIM_MEMORY_RUNNING_LOW:
                 debug("trim memory requested: memory on device is running low");
-                return;
+                break;
 
             case TRIM_MEMORY_RUNNING_MODERATE:
                 debug("trim memory requested: memory on device is moderate");
-                return;
+                break;
 
             case TRIM_MEMORY_UI_HIDDEN:
                 debug("trim memory requested: app is not showing UI anymore");
-                return;
+                break;
         }
     }
 
@@ -1665,7 +1649,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
 
             if (conn != null) {
                 try {
-                    ArrayList<String> resetBuffer = new ArrayList<String>();
+                    ArrayList<String> resetBuffer = new ArrayList<>();
                     resetBuffer.add("ExitNodes");
                     resetBuffer.add("StrictNodes");
                     conn.resetConf(resetBuffer);
@@ -1863,7 +1847,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
     }
 
     // for bridge loading from the assets default bridges.txt file
-    class Bridge {
+    static class Bridge {
         String type;
         String config;
     }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java
index f473f51a..bd8f2bc8 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java
@@ -24,8 +24,8 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
     private long lastWritten = -1;
     private long mTotalTrafficWritten = 0;
     private long mTotalTrafficRead = 0;
-    private NumberFormat mNumberFormat = null;
-    private HashMap<String, Node> hmBuiltNodes = new HashMap<String, Node>();
+    private NumberFormat mNumberFormat;
+    private HashMap<String, Node> hmBuiltNodes = new HashMap<>();
 
     public TorEventHandler(OrbotService service) {
         mService = service;
@@ -57,56 +57,49 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
     @Override
     public void orConnStatus(String status, String orName) {
 
-        StringBuilder sb = new StringBuilder();
-        sb.append("orConnStatus (");
-        sb.append(parseNodeName(orName));
-        sb.append("): ");
-        sb.append(status);
-
-        mService.debug(sb.toString());
+        String sb = "orConnStatus (" +
+                parseNodeName(orName) +
+                "): " +
+                status;
+        mService.debug(sb);
     }
 
     @Override
     public void streamStatus(String status, String streamID, String target) {
 
-        StringBuilder sb = new StringBuilder();
-        sb.append("StreamStatus (");
-        sb.append((streamID));
-        sb.append("): ");
-        sb.append(status);
-
-        mService.debug(sb.toString());
+        String sb = "StreamStatus (" +
+                (streamID) +
+                "): " +
+                status;
+        mService.debug(sb);
     }
 
     @Override
     public void unrecognized(String type, String msg) {
 
-        StringBuilder sb = new StringBuilder();
-        sb.append("Message (");
-        sb.append(type);
-        sb.append("): ");
-        sb.append(msg);
-
-        mService.logNotice(sb.toString());
+        String sb = "Message (" +
+                type +
+                "): " +
+                msg;
+        mService.logNotice(sb);
     }
 
     @Override
     public void bandwidthUsed(long read, long written) {
 
         if (lastWritten > BW_THRESDHOLD || lastRead > BW_THRESDHOLD) {
-            StringBuilder sb = new StringBuilder();
-            sb.append(formatCount(read));
-            sb.append(" \u2193");
-            sb.append(" / ");
-            sb.append(formatCount(written));
-            sb.append(" \u2191");
 
             int iconId = R.drawable.ic_stat_tor;
 
             if (read > 0 || written > 0)
                 iconId = R.drawable.ic_stat_tor_xfer;
 
-            mService.showToolbarNotification(sb.toString(), mService.getNotifyId(), iconId);
+            String sb = formatCount(read) +
+                    " \u2193" +
+                    " / " +
+                    formatCount(written) +
+                    " \u2191";
+            mService.showToolbarNotification(sb, mService.getNotifyId(), iconId);
 
             mTotalTrafficWritten += written;
             mTotalTrafficRead += read;
@@ -153,7 +146,7 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
             sb.append(": ");
 
             StringTokenizer st = new StringTokenizer(path, ",");
-            Node node = null;
+            Node node;
 
             boolean isFirstNode = true;
             int nodeCount = st.countTokens();
@@ -237,7 +230,7 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
             return node;
     }
 
-    public class Node {
+    public static class Node {
         public String status;
         public String id;
         public String name;
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java b/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java
index bddfab2c..8f50ccf2 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java
@@ -20,8 +20,8 @@ public class CustomShell extends Shell {
 
     @WorkerThread
     public static CommandResult run(@NonNull String shell, boolean waitFor, @Nullable Map<String, String> env, @NonNull String command) {
-        List<String> stdout = Collections.synchronizedList(new ArrayList<String>());
-        List<String> stderr = Collections.synchronizedList(new ArrayList<String>());
+        List<String> stdout = Collections.synchronizedList(new ArrayList<>());
+        List<String> stderr = Collections.synchronizedList(new ArrayList<>());
         int exitCode = -1;
 
         try {
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java b/orbotservice/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java
index 745307d9..957e1e65 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/ExternalIPFetcher.java
@@ -29,7 +29,7 @@ public class ExternalIPFetcher implements Runnable {
     public void run() {
         try {
 
-            URLConnection conn = null;
+            URLConnection conn;
 
             Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", mLocalHttpProxyPort));
             conn = new URL(ONIONOO_BASE_URL + mNode.id).openConnection(proxy);
@@ -45,7 +45,7 @@ public class ExternalIPFetcher implements Runnable {
             // getting JSON string from URL
 
             StringBuffer json = new StringBuffer();
-            String line = null;
+            String line;
 
             while ((line = reader.readLine()) != null)
                 json.append(line);
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/TCPSourceApp.java b/orbotservice/src/main/java/org/torproject/android/service/util/TCPSourceApp.java
index 1aa6445a..cb61a9c7 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/TCPSourceApp.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/TCPSourceApp.java
@@ -99,7 +99,6 @@ public class TCPSourceApp {
      * @return an AppDescriptor object, representing the found application; null
      * if no application could be found
      */
-    @SuppressWarnings("unused")
     public static AppDescriptor getApplicationInfo(Context context, String saddr, int sport, String daddr, int dport) {
 
         File tcp;
@@ -122,7 +121,6 @@ public class TCPSourceApp {
 
             tcp = new File(TCP_6_FILE_PATH);
             reader = new BufferedReader(new FileReader(tcp));
-            line = "";
             builder = new StringBuilder();
 
             while ((line = reader.readLine()) != null) {
@@ -171,7 +169,6 @@ public class TCPSourceApp {
         try {
             tcp = new File(TCP_4_FILE_PATH);
             reader = new BufferedReader(new FileReader(tcp));
-            line = "";
             builder = new StringBuilder();
 
             while ((line = reader.readLine()) != null) {
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/Utils.java b/orbotservice/src/main/java/org/torproject/android/service/util/Utils.java
index 64d912c1..2cb34389 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/Utils.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/Utils.java
@@ -47,7 +47,7 @@ public class Utils {
      * Load the log file text
      */
     public static String loadTextFile(String path) {
-        String line = null;
+        String line;
 
         StringBuffer out = new StringBuffer();
 
@@ -107,14 +107,14 @@ public class Utils {
 
         File sourceFile = new File(sourcePath);
         try {
-            BufferedInputStream origin = null;
+            BufferedInputStream origin;
             FileOutputStream dest = new FileOutputStream(toLocation);
             ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
                     dest));
             if (sourceFile.isDirectory()) {
                 zipSubFolder(out, sourceFile, sourceFile.getParent().length());
             } else {
-                byte data[] = new byte[BUFFER];
+                byte[] data = new byte[BUFFER];
                 FileInputStream fi = new FileInputStream(sourcePath);
                 origin = new BufferedInputStream(fi, BUFFER);
                 ZipEntry entry = new ZipEntry(getLastPathComponent(sourcePath));
@@ -150,7 +150,7 @@ public class Utils {
             if (file.isDirectory()) {
                 zipSubFolder(out, file, basePathLength);
             } else {
-                byte data[] = new byte[BUFFER];
+                byte[] data = new byte[BUFFER];
                 String unmodifiedFilePath = file.getPath();
                 String relativePath = unmodifiedFilePath
                         .substring(basePathLength);
@@ -178,7 +178,6 @@ public class Utils {
         String[] segments = filePath.split("/");
         if (segments.length == 0)
             return "";
-        String lastPathComponent = segments[segments.length - 1];
-        return lastPathComponent;
+        return segments[segments.length - 1];
     }
 }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
index 12c4162f..89e351c4 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
@@ -85,7 +85,7 @@ public class OrbotVpnManager implements Handler.Callback {
         Tun2Socks.init();
     }
 
-    public static File makePdnsdConf(Context context, File fileDir, String torDnsHost, int torDnsPort, String pdnsdHost, int pdnsdPort) throws FileNotFoundException, IOException {
+    public static File makePdnsdConf(Context context, File fileDir, String torDnsHost, int torDnsPort, String pdnsdHost, int pdnsdPort) throws IOException {
         String conf = String.format(context.getString(R.string.pdnsd_conf), torDnsHost, torDnsPort, fileDir.getCanonicalPath(), pdnsdHost, pdnsdPort);
 
         Log.d(TAG, "pdsnd conf:" + conf);
@@ -371,7 +371,7 @@ public class OrbotVpnManager implements Handler.Callback {
         if (proc.exitValue() != 0) {
             BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
 
-            String line = null;
+            String line;
             while ((line = br.readLine()) != null) {
                 Log.d(TAG, "pdnsd: " + line);
             }
@@ -382,7 +382,7 @@ public class OrbotVpnManager implements Handler.Callback {
 
     private boolean stopDns() {
         if (filePdnsPid != null && filePdnsPid.exists()) {
-            List<String> lines = null;
+            List<String> lines;
             try {
                 lines = IOUtils.readLines(new FileReader(filePdnsPid));
                 String dnsPid = lines.get(0);
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java
index 11171831..b7bc01e6 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java
@@ -52,12 +52,12 @@ public class TorifiedApp implements Comparable {
 
         Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
 
-        ArrayList<TorifiedApp> apps = new ArrayList<TorifiedApp>();
+        ArrayList<TorifiedApp> apps = new ArrayList<>();
 
-        ApplicationInfo aInfo = null;
+        ApplicationInfo aInfo;
 
         int appIdx = 0;
-        TorifiedApp app = null;
+        TorifiedApp app;
 
         while (itAppInfo.hasNext()) {
             aInfo = itAppInfo.next();
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java
index d6910138..05d84da4 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/Tun2Socks.java
@@ -40,7 +40,6 @@ public class Tun2Socks {
     private static final String TAG = Tun2Socks.class.getSimpleName();
     private static final boolean LOGD = true;
 
-    ;
     private static Thread mThread;
     private static ParcelFileDescriptor mVpnInterfaceFileDescriptor;
     private static int mVpnInterfaceMTU;
@@ -169,7 +168,7 @@ public class Tun2Socks {
         mAppUidBlacklist.remove(uid);
     }
 
-    public static interface IProtectSocket {
+    public interface IProtectSocket {
         boolean doVpnProtect(Socket socket);
 
         boolean doVpnProtect(DatagramSocket socket);
diff --git a/orbotservice/src/main/res/values/colors.xml b/orbotservice/src/main/res/values/colors.xml
deleted file mode 100644
index 81869efd..00000000
--- a/orbotservice/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-    <resources></resources>





More information about the tor-commits mailing list