commit d396351695b4e9f0d18fbe2e15149d7b657ba5c3 Author: n8fr8 nathan@guardianproject.info Date: Wed Jul 31 17:08:27 2019 -0400
keep apps around as static variable, enable user to refresh --- .../torproject/android/ui/AppManagerActivity.java | 53 ++++++++++++++++++---- app/src/main/res/menu/app_main.xml | 33 ++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 78 insertions(+), 9 deletions(-)
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 a8c7a180..f5970a25 100644 --- a/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java +++ b/app/src/main/java/org/torproject/android/ui/AppManagerActivity.java @@ -3,6 +3,8 @@
package org.torproject.android.ui;
+import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -11,10 +13,15 @@ import java.util.Iterator; import java.util.List; import java.util.StringTokenizer;
+import org.torproject.android.OrbotMainActivity; import org.torproject.android.service.OrbotConstants; import org.torproject.android.R; +import org.torproject.android.service.util.Prefs; import org.torproject.android.service.util.TorServiceUtils; import org.torproject.android.service.vpn.TorifiedApp; +import org.torproject.android.settings.SettingsPreferences; +import org.torproject.android.ui.hiddenservices.ClientCookiesActivity; +import org.torproject.android.ui.hiddenservices.HiddenServicesActivity;
import android.Manifest; import android.content.Intent; @@ -27,6 +34,8 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; @@ -39,6 +48,8 @@ import android.widget.ListAdapter; import android.widget.ProgressBar; import android.widget.TextView;
+import com.google.zxing.integration.android.IntentIntegrator; + import static org.torproject.android.service.vpn.VpnPrefs.PREFS_KEY_TORIFIED;
public class AppManagerActivity extends AppCompatActivity implements OnClickListener, OrbotConstants { @@ -60,14 +71,6 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList progressBar = findViewById(R.id.progressBar); }
- @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return super.onOptionsItemSelected(item); - }
@Override protected void onResume() { @@ -76,6 +79,36 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList reloadApps(); }
+ + /* + * Create the UI Options Menu (non-Javadoc) + * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu) + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.app_main, menu); + return true; + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + if (item.getItemId() == R.id.menu_refresh_apps) + { + mApps = null; + reloadApps(); + } + else if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + + return super.onOptionsItemSelected(item); + } + private void reloadApps () { new AsyncTask<Void, Void, Void>() { protected void onPreExecute() { @@ -96,7 +129,7 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList }
SharedPreferences mPrefs = null; - ArrayList<TorifiedApp> mApps = null; + static ArrayList<TorifiedApp> mApps = null;
private void loadApps (SharedPreferences prefs) { if (mApps == null) @@ -181,6 +214,7 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList public ArrayList<TorifiedApp> getApps(SharedPreferences prefs) {
String tordAppString = prefs.getString(PREFS_KEY_TORIFIED, ""); + String[] tordApps;
StringTokenizer st = new StringTokenizer(tordAppString,"|"); @@ -209,6 +243,7 @@ public class AppManagerActivity extends AppCompatActivity implements OnClickList if (!aInfo.enabled) continue; app = new TorifiedApp();
+ try { PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);
diff --git a/app/src/main/res/menu/app_main.xml b/app/src/main/res/menu/app_main.xml new file mode 100644 index 00000000..7f0e34d0 --- /dev/null +++ b/app/src/main/res/menu/app_main.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright (C) 2008 Esmertec AG. + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +--> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:yourapp="http://schemas.android.com/apk/res-auto" + > + + + <item android:id="@+id/menu_refresh_apps" + android:title="@string/refresh_apps" + android:icon="@drawable/ic_refresh_white_24dp" + yourapp:showAsAction="always" + /> + + + +</menu> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c86f0f0c..4400c048 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -254,4 +254,5 @@ <string name="user_services">User services</string> <string name="app_services">App services</string> <string name="default_socks_http">SOCKS: - HTTP: -</string> + <string name="refresh_apps">Refresh Apps</string> </resources>