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

[tor-commits] [orbot/master] Package name is saved for torified apps instead of "username". This is much more performant



commit c1fdff654b82d76c2abac479e7fa35542123ba2a
Author: bim <dsnake@xxxxxxxxxxxxxx>
Date:   Sat Aug 7 20:47:07 2021 -0400

    Package name is saved for torified apps instead of "username". This is much more performant
    than the last commit, but the UI will not immediately be updated if the user had older
    Orbot data saved (No "torification" is actually compromised though...)
---
 .../org/torproject/android/OrbotMainActivity.java  | 30 ++++++++++++----------
 .../torproject/android/ui/AppManagerActivity.java  |  6 ++---
 .../android/service/vpn/TorifiedApp.java           |  2 +-
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 0869d140..a54cbe0f 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -87,9 +87,12 @@ import java.net.URLDecoder;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.TreeMap;
 import java.util.stream.Collectors;
 
 import pl.bclogic.pulsator4droid.library.PulsatorLayout;
@@ -1115,35 +1118,36 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
             drawFullDeviceVpn();
         } else {
             PackageManager packageManager = getPackageManager();
+            String[] tordApps = tordAppString.split("\\|");
+            LinearLayout container = (LinearLayout) llBoxShortcuts.getChildAt(0);
             tvVpnAppStatus.setVisibility(View.GONE);
             llBoxShortcuts.setVisibility(View.VISIBLE);
-            LinearLayout container = (LinearLayout) llBoxShortcuts.getChildAt(0);
             container.removeAllViews();
-            List<TorifiedApp> apps = TorifiedApp.getApps(this, mPrefs);
-            TorifiedApp.sortAppsForTorifiedAndAbc(apps);
-            int appsAdded = 0;
-
-            for (TorifiedApp app : apps) {
-                if (!app.isTorified()) break;
+            Map<String, ImageView> icons = new TreeMap<>();
+            for (String tordApp : tordApps) {
                 try {
-                    String pkgId = app.getPackageName();
+                    packageManager.getPackageInfo(tordApp, 0);
                     ImageView iv = new ImageView(this);
+                    ApplicationInfo applicationInfo = packageManager.getApplicationInfo(tordApp, 0);
+                    iv.setImageDrawable(packageManager.getApplicationIcon(tordApp));
                     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                     params.setMargins(3, 3, 3, 3);
                     iv.setLayoutParams(params);
-                    iv.setImageDrawable(packageManager.getApplicationIcon(pkgId));
-                    iv.setOnClickListener(v -> openBrowser(URL_TOR_CHECK, false, pkgId));
-                    container.addView(iv);
-                    appsAdded++;
+                    iv.setOnClickListener(v -> openBrowser(URL_TOR_CHECK, false, tordApp));
+                    icons.put(packageManager.getApplicationLabel(applicationInfo).toString(), iv);
+
                 } catch (PackageManager.NameNotFoundException e) {
                     e.printStackTrace();
                 }
             }
-            if (appsAdded == 0) {
+            if (icons.size() == 0) {
                         /* if a user uninstalled or disabled all apps that were set on the device
                            then we want to have the no apps added view appear even though
                            the tordAppString variable is not empty */
                 drawFullDeviceVpn();
+            } else {
+                TreeMap<String, ImageView> sorted = new TreeMap<>(icons);
+                for (ImageView iv : sorted.values()) container.addView(iv);
             }
         }
 
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 ccc6aa97..156ccfce 100644
--- a/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java
@@ -248,7 +248,7 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList
 
 
             // check if this application is allowed
-            if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) {
+            if (Arrays.binarySearch(tordApps, app.getPackageName()) >= 0) {
                 app.setTorified(true);
             } else {
                 app.setTorified(false);
@@ -268,9 +268,9 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList
 
         for (TorifiedApp tApp : mApps) {
             if (tApp.isTorified()) {
-                tordApps.append(tApp.getUsername());
+                tordApps.append(tApp.getPackageName());
                 tordApps.append("|");
-                response.putExtra(tApp.getUsername(), true);
+                response.putExtra(tApp.getPackageName(), true);
             }
         }
 
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 dedf743e..2eabaa76 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
@@ -112,7 +112,7 @@ public class TorifiedApp implements Comparable {
             //app.setIcon(pMgr.getApplicationIcon(aInfo));
 
             // check if this application is allowed
-            if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) {
+            if (Arrays.binarySearch(tordApps, app.getPackageName()) >= 0) {
                 app.setTorified(true);
             } else {
                 app.setTorified(false);



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