[tor-commits] [orbot/master] Battery permissions on v3 services

n8fr8 at torproject.org n8fr8 at torproject.org
Wed Dec 22 21:55:06 UTC 2021


commit 85dba3bf440f68ba1036dda596f4adceea1b5d94
Author: bim <dsnake at protonmail.com>
Date:   Sat Nov 28 12:46:28 2020 -0500

    Battery permissions on v3 services
---
 .../android/ui/v3onionservice/OnionServicesActivity.java    | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java b/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java
index ba06b7c0..64a014e4 100644
--- a/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java
@@ -26,6 +26,7 @@ import org.torproject.android.core.DiskUtils;
 import org.torproject.android.core.LocaleHelper;
 import org.torproject.android.ui.hiddenservices.backup.BackupUtils;
 import org.torproject.android.ui.hiddenservices.backup.ZipUtilities;
+import org.torproject.android.ui.hiddenservices.permissions.PermissionManager;
 
 import java.io.File;
 
@@ -161,8 +162,16 @@ public class OnionServicesActivity extends AppCompatActivity {
 
         @Override
         public void onChange(boolean selfChange) {
-            mAdapter.changeCursor(mContentResolver.query(OnionServiceContentProvider.CONTENT_URI, OnionServiceContentProvider.PROJECTION, BASE_WHERE_SELECTION_CLAUSE + '1', null, null));
-            // todo battery optimization stuff if lollipop or higher and running onion services
+            filterServices(radioShowUserServices.isChecked()); // updates adapter
+            if (!PermissionManager.isLollipopOrHigher()) return;
+            Cursor activeServices = mContentResolver.query(OnionServiceContentProvider.CONTENT_URI, OnionServiceContentProvider.PROJECTION,
+                    OnionServiceContentProvider.OnionService.ENABLED + "=1", null, null);
+            if (activeServices == null) return;
+            if (activeServices.getCount() > 0)
+                PermissionManager.requestBatteryPermissions(OnionServicesActivity.this, getApplicationContext());
+            else
+                PermissionManager.requestDropBatteryPermissions(OnionServicesActivity.this, getApplicationContext());
+            activeServices.close();
         }
     }
 





More information about the tor-commits mailing list