From 057338fc3f63c8d6eefe4fb0c82e67af66a0887c Mon Sep 17 00:00:00 2001 From: bongtrop Date: Mon, 8 May 2023 18:08:29 +0700 Subject: [PATCH] Add support to Android version 13 and remove firebase and crashlytics --- app/build.gradle | 11 +- app/src/main/AndroidManifest.xml | 15 +- .../main/java/org/proxydroid/AppManager.java | 87 ++-- .../org/proxydroid/BypassListActivity.java | 295 ++++++------- .../ConnectivityBroadcastReceiver.java | 199 +++++---- .../java/org/proxydroid/DomainValidator.java | 6 +- .../java/org/proxydroid/FileArrayAdapter.java | 6 +- .../main/java/org/proxydroid/FileChooser.java | 9 +- .../org/proxydroid/InnerSocketBuilder.java | 2 +- app/src/main/java/org/proxydroid/Profile.java | 26 +- .../main/java/org/proxydroid/ProxyDroid.java | 391 +++++++----------- .../org/proxydroid/ProxyDroidApplication.java | 6 - .../org/proxydroid/ProxyDroidService.java | 140 +++---- .../proxydroid/ProxyDroidWidgetProvider.java | 17 +- 14 files changed, 521 insertions(+), 689 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e4ac84b..069c177 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,12 +3,13 @@ apply plugin: 'com.google.gms.google-services' apply plugin: 'io.fabric' android { - compileSdkVersion 29 - buildToolsVersion "29.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" + ndkVersion "20.0.5594570" defaultConfig { applicationId "org.proxydroid" minSdkVersion 16 - targetSdkVersion 29 + targetSdkVersion 33 versionCode 72 versionName "3.2.0" @@ -47,8 +48,4 @@ dependencies { implementation 'com.google.android.material:material:1.0.0' implementation 'com.googlecode.json-simple:json-simple:1.1.1' implementation 'org.mozilla:rhino:1.7.11' - implementation 'com.google.firebase:firebase-core:17.2.1' - implementation 'com.google.firebase:firebase-ads:18.3.0' - implementation 'com.google.firebase:firebase-analytics:17.2.1' - implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c87214c..a44cd47 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,11 +2,12 @@ + + - @@ -19,14 +20,10 @@ android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-9097031975646651~9376680322" /> - - + android:label="@string/app_name" + android:exported="true"> @@ -48,12 +45,12 @@ android:name=".ProxyDroidService" android:enabled="true" /> - + - + diff --git a/app/src/main/java/org/proxydroid/AppManager.java b/app/src/main/java/org/proxydroid/AppManager.java index 6c58d7d..6c21e49 100644 --- a/app/src/main/java/org/proxydroid/AppManager.java +++ b/app/src/main/java/org/proxydroid/AppManager.java @@ -39,9 +39,9 @@ import org.proxydroid.utils.ImageLoaderFactory; import java.util.Arrays; -import java.util.Comparator; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.StringTokenizer; import java.util.Vector; @@ -68,9 +68,9 @@ public class AppManager extends AppCompatActivity implements OnCheckedChangeList private boolean appsLoaded = false; - final Handler handler = new Handler() { + final Handler handler = new Handler(new Handler.Callback() { @Override - public void handleMessage(Message msg) { + public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_LOAD_START: pd = ProgressDialog.show(AppManager.this, "", @@ -88,7 +88,7 @@ public void handleMessage(Message msg) { public void onScrollStateChanged(AbsListView view, int scrollState) { visible = true; - if (scrollState == ListView.OnScrollListener.SCROLL_STATE_IDLE) { + if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { overlay.setVisibility(View.INVISIBLE); } } @@ -115,33 +115,24 @@ public void onScroll(AbsListView view, } break; } - super.handleMessage(msg); + return true; } - }; + }); @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - // app icon in action bar clicked; go home -// Intent intent = new Intent(this, ProxyDroid.class); -// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); -// startActivity(intent); + if (item.getItemId() == android.R.id.home) { finish(); return true; - default: - return super.onOptionsItemSelected(item); } + return super.onOptionsItemSelected(item); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - ((ProxyDroidApplication)getApplication()) - .firebaseAnalytics.setCurrentScreen(this, "app_manager", null); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); this.setContentView(R.layout.layout_apps); @@ -175,9 +166,7 @@ public void onDestroy() { @Override protected void onResume() { super.onResume(); - new Thread() { - @Override public void run() { handler.sendEmptyMessage(MSG_LOAD_START); @@ -189,24 +178,20 @@ public void run() { handler.sendEmptyMessage(MSG_LOAD_FINISH); } }.start(); - } private void loadApps() { getApps(this); - Arrays.sort(apps, new Comparator() { - @Override - public int compare(ProxyedApp o1, ProxyedApp o2) { - if (o1 == null || o2 == null || o1.getName() == null - || o2.getName() == null) - return 1; - if (o1.isProxyed() == o2.isProxyed()) - return o1.getName().compareTo(o2.getName()); - if (o1.isProxyed()) - return -1; + Arrays.sort(apps, (o1, o2) -> { + if (o1 == null || o2 == null || o1.getName() == null + || o2.getName() == null) return 1; - } + if (o1.isProxyed() == o2.isProxyed()) + return o1.getName().compareTo(o2.getName()); + if (o1.isProxyed()) + return -1; + return 1; }); final LayoutInflater inflater = getLayoutInflater(); @@ -303,11 +288,10 @@ public static ProxyedApp[] getProxyedApps(Context context, boolean self) { Iterator itAppInfo = lAppInfo.iterator(); - Vector vectorApps = new Vector(); + Vector vectorApps = new Vector<>(); - ApplicationInfo aInfo = null; + ApplicationInfo aInfo; - int appIdx = 0; while (itAppInfo.hasNext()) { aInfo = itAppInfo.next(); @@ -327,11 +311,7 @@ public static ProxyedApp[] getProxyedApps(Context context, boolean self) { && aInfo.packageName.equals("org.proxydroid")) { if (self) app.setProxyed(true); - } else if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) { - app.setProxyed(true); - } else { - app.setProxyed(false); - } + } else app.setProxyed(Arrays.binarySearch(tordApps, app.getUsername()) >= 0); if (app.isProxyed()) vectorApps.add(app); @@ -360,7 +340,7 @@ public void getApps(Context context) { Arrays.sort(tordApps); - Vector vectorApps = new Vector(); + Vector vectorApps = new Vector<>(); // else load the apps up PackageManager pMgr = context.getPackageManager(); @@ -369,7 +349,7 @@ public void getApps(Context context) { Iterator itAppInfo = lAppInfo.iterator(); - ApplicationInfo aInfo = null; + ApplicationInfo aInfo; while (itAppInfo.hasNext()) { aInfo = itAppInfo.next(); @@ -395,11 +375,7 @@ public void getApps(Context context) { tApp.setName(pMgr.getApplicationLabel(aInfo).toString()); // check if this application is allowed - if (Arrays.binarySearch(tordApps, tApp.getUsername()) >= 0) { - tApp.setProxyed(true); - } else { - tApp.setProxyed(false); - } + tApp.setProxyed(Arrays.binarySearch(tordApps, tApp.getUsername()) >= 0); vectorApps.add(tApp); } @@ -409,28 +385,25 @@ public void getApps(Context context) { } - public void saveAppSettings(Context context) { + public void saveAppSettings() { if (apps == null) return; SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this); - // final SharedPreferences prefs = - // context.getSharedPreferences(PREFS_KEY, 0); - StringBuilder tordApps = new StringBuilder(); - for (int i = 0; i < apps.length; i++) { - if (apps[i].isProxyed()) { - tordApps.append(apps[i].getUsername()); + for (ProxyedApp app : apps) { + if (app.isProxyed()) { + tordApps.append(app.getUsername()); tordApps.append("|"); } } Editor edit = prefs.edit(); edit.putString(PREFS_KEY_PROXYED, tordApps.toString()); - edit.commit(); + edit.apply(); } @@ -444,7 +417,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { app.setProxyed(isChecked); } - saveAppSettings(this); + saveAppSettings(); } @@ -459,7 +432,7 @@ public void onClick(View v) { cbox.setChecked(app.isProxyed()); } - saveAppSettings(this); + saveAppSettings(); } diff --git a/app/src/main/java/org/proxydroid/BypassListActivity.java b/app/src/main/java/org/proxydroid/BypassListActivity.java index 0321de7..b5b597a 100644 --- a/app/src/main/java/org/proxydroid/BypassListActivity.java +++ b/app/src/main/java/org/proxydroid/BypassListActivity.java @@ -77,6 +77,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Objects; public class BypassListActivity extends AppCompatActivity implements OnClickListener, OnItemClickListener, OnItemLongClickListener { @@ -91,13 +93,12 @@ public class BypassListActivity extends AppCompatActivity implements private static final int MSG_IMPORT_ADDR = 5; private static final int MSG_EXPORT_ADDR = 6; - private ListAdapter adapter; private ArrayList bypassList; - private Profile profile = new Profile(); + private final Profile profile = new Profile(); - final Handler handler = new Handler() { + final Handler handler = new Handler(new Handler.Callback() { @Override - public void handleMessage(Message msg) { + public boolean handleMessage(Message msg) { String addr; switch (msg.what) { case MSG_ERR_ADDR: @@ -106,13 +107,13 @@ public void handleMessage(Message msg) { break; case MSG_ADD_ADDR: if (msg.obj == null) - return; + return false; addr = (String) msg.obj; bypassList.add(addr); break; case MSG_EDIT_ADDR: if (msg.obj == null) - return; + return false; addr = (String) msg.obj; bypassList.set(msg.arg1, addr); break; @@ -122,51 +123,36 @@ public void handleMessage(Message msg) { case MSG_PRESET_ADDR: String[] list = Constraints.PRESETS[msg.arg1]; reset(list); - return; + return true; case MSG_EXPORT_ADDR: if (msg.obj == null) - return; + return false; Toast.makeText(BypassListActivity.this, getString(R.string.exporting) + " " + (String) msg.obj, Toast.LENGTH_LONG).show(); - return; + return true; } refreshList(); - super.handleMessage(msg); + return true; } - }; + }); @Override public void onClick(View arg0) { - switch (arg0.getId()) { - case R.id.addBypassAddr: - editAddr(MSG_ADD_ADDR, -1); - break; - case R.id.presetBypassAddr: - presetAddr(); - break; - case R.id.importBypassAddr: - importAddr(); - break; - case R.id.exportBypassAddr: - exportAddr(); - break; - } + int id = arg0.getId(); + if (id == R.id.addBypassAddr) editAddr(MSG_ADD_ADDR, -1); + else if (id == R.id.presetBypassAddr) presetAddr(); + else if (id == R.id.importBypassAddr) importAddr(); + else if (id == R.id.exportBypassAddr) exportAddr(); } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - // app icon in action bar clicked; go home -// Intent intent = new Intent(this, ProxyDroid.class); -// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); -// startActivity(intent); + if (item.getItemId() == android.R.id.home) { finish(); return true; - default: - return super.onOptionsItemSelected(item); } + return super.onOptionsItemSelected(item); } @Override @@ -174,7 +160,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); setContentView(R.layout.bypass_list); TextView addButton = (TextView) findViewById(R.id.addBypassAddr); @@ -209,33 +195,26 @@ private void presetAddr() { AlertDialog ad = new AlertDialog.Builder(this) .setTitle(R.string.preset_button) .setNegativeButton(R.string.alert_dialog_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { - /* User clicked Cancel so do some stuff */ - } + (dialog, whichButton) -> { + /* User clicked Cancel so do some stuff */ }) .setSingleChoiceItems(R.array.presets_list, -1, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int which) { - if (which >= 0 - && which < Constraints.PRESETS.length) { - Message msg = new Message(); - msg.what = MSG_PRESET_ADDR; - msg.arg1 = which; - handler.sendMessage(msg); - } - dialog.dismiss(); + (dialog, which) -> { + if (which >= 0 + && which < Constraints.PRESETS.length) { + Message msg = new Message(); + msg.what = MSG_PRESET_ADDR; + msg.arg1 = which; + handler.sendMessage(msg); } + dialog.dismiss(); }).create(); ad.show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constraints.IMPORT_REQUEST) { if (resultCode == RESULT_OK) { if (data == null) @@ -247,15 +226,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { final ProgressDialog pd = ProgressDialog.show(this, "", getString(R.string.importing), true, true); - final Handler h = new Handler() { - @Override - public void handleMessage(Message msg) { - refreshList(); - if (pd != null) { - pd.dismiss(); - } + final Handler h = new Handler(msg -> { + refreshList(); + if (pd != null) { + pd.dismiss(); } - }; + return true; + }); new Thread() { @Override @@ -303,67 +280,60 @@ private void exportAddr() { final EditText path = (EditText) textEntryView .findViewById(R.id.text_edit); - path.setText(Utils.getDataPath(this) + "/" + profile.getHost() + ".opt"); + String pathStr = Utils.getDataPath(this) + "/" + profile.getHost() + ".opt"; + path.setText(pathStr); AlertDialog ad = new AlertDialog.Builder(this) .setTitle(R.string.export_button) .setView(textEntryView) .setPositiveButton(R.string.alert_dialog_ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { - if (path.getText() == null - || path.getText().toString() == null) - dialog.dismiss(); - new Thread() { - @Override - public void run() { - - FileOutputStream output; - try { - File file = new File(path.getText() - .toString()); - if (!file.exists()) - file.createNewFile(); - - output = new FileOutputStream(file); - BufferedOutputStream bw = new BufferedOutputStream( - output); - for (String addr : bypassList) { - addr = Profile - .validateAddr(addr); - if (addr != null) - bw.write((addr + "\n") - .getBytes()); - } - - bw.flush(); - bw.close(); - output.flush(); - output.close(); - } catch (FileNotFoundException e) { - Log.e(TAG, "error to open file", e); - } catch (IOException e) { - Log.e(TAG, "error to write file", e); + (dialog, whichButton) -> { + if (path.getText() == null) { + dialog.dismiss(); + } + new Thread() { + @Override + public void run() { + + FileOutputStream output; + try { + File file = new File(path.getText() + .toString()); + if (!file.exists()) + file.createNewFile(); + + output = new FileOutputStream(file); + BufferedOutputStream bw = new BufferedOutputStream( + output); + for (String addr : bypassList) { + addr = Profile + .validateAddr(addr); + if (addr != null) + bw.write((addr + "\n") + .getBytes()); } - Message msg = new Message(); - msg.what = MSG_EXPORT_ADDR; - msg.obj = path.getText().toString(); - handler.sendMessage(msg); + bw.flush(); + bw.close(); + output.flush(); + output.close(); + } catch (FileNotFoundException e) { + Log.e(TAG, "error to open file", e); + } catch (IOException e) { + Log.e(TAG, "error to write file", e); } - }.start(); - } + Message msg = new Message(); + msg.what = MSG_EXPORT_ADDR; + msg.obj = path.getText().toString(); + handler.sendMessage(msg); + } + }.start(); + }) .setNegativeButton(R.string.alert_dialog_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { - /* User clicked cancel so do some stuff */ - } + (dialog, whichButton) -> { + /* User clicked cancel so do some stuff */ }).create(); ad.show(); } @@ -376,25 +346,17 @@ private void delAddr(final int idx) { .setTitle(addr) .setMessage(R.string.bypass_del_text) .setPositiveButton(R.string.alert_dialog_ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { - /* User clicked OK so do some stuff */ - Message msg = new Message(); - msg.what = MSG_DEL_ADDR; - msg.arg1 = idx; - msg.obj = addr; - handler.sendMessage(msg); - } + (dialog, whichButton) -> { + /* User clicked OK so do some stuff */ + Message msg = new Message(); + msg.what = MSG_DEL_ADDR; + msg.arg1 = idx; + msg.obj = addr; + handler.sendMessage(msg); }) .setNegativeButton(R.string.alert_dialog_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { - /* User clicked Cancel so do some stuff */ - } + (dialog, whichButton) -> { + /* User clicked Cancel so do some stuff */ }).create(); ad.show(); @@ -416,42 +378,34 @@ else if (msg == MSG_ADD_ADDR) .setTitle(R.string.bypass_edit_title) .setView(textEntryView) .setPositiveButton(R.string.alert_dialog_ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { - /* User clicked OK so do some stuff */ - - new Thread() { - @Override - public void run() { - EditText addrText = (EditText) textEntryView - .findViewById(R.id.text_edit); - String addr = addrText.getText() - .toString(); - addr = Profile.validateAddr(addr); - if (addr != null) { - Message m = new Message(); - m.what = msg; - m.arg1 = idx; - m.obj = addr; - handler.sendMessage(m); - } else { - handler.sendEmptyMessage(MSG_ERR_ADDR); - } + (dialog, whichButton) -> { + /* User clicked OK so do some stuff */ + + new Thread() { + @Override + public void run() { + EditText addrText1 = (EditText) textEntryView + .findViewById(R.id.text_edit); + String addr = addrText1.getText() + .toString(); + addr = Profile.validateAddr(addr); + if (addr != null) { + Message m = new Message(); + m.what = msg; + m.arg1 = idx; + m.obj = addr; + handler.sendMessage(m); + } else { + handler.sendEmptyMessage(MSG_ERR_ADDR); } - }.start(); + } + }.start(); - } }) .setNegativeButton(R.string.alert_dialog_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int whichButton) { + (dialog, whichButton) -> { - /* User clicked cancel so do some stuff */ - } + /* User clicked cancel so do some stuff */ }).create(); ad.show(); } @@ -461,15 +415,13 @@ private void reset(final String[] list) { final ProgressDialog pd = ProgressDialog.show(this, "", getString(R.string.reseting), true, true); - final Handler h = new Handler() { - @Override - public void handleMessage(Message msg) { - refreshList(); - if (pd != null) { - pd.dismiss(); - } + final Handler h = new Handler(msg -> { + refreshList(); + if (pd != null) { + pd.dismiss(); } - }; + return true; + }); new Thread() { @Override @@ -499,16 +451,15 @@ private void refreshList() { } String[] addrs = Profile.decodeAddrs(profile.getBypassAddrs()); - bypassList = new ArrayList(); + bypassList = new ArrayList<>(); - for (String addr : addrs) { - bypassList.add(addr); - // Log.d(TAG, addr); - } + // Log.d(TAG, addr); + bypassList.addAll(Arrays.asList(addrs)); final LayoutInflater inflater = getLayoutInflater(); - adapter = new ArrayAdapter(this, R.layout.bypass_list_item, + // Inflate a new view + ListAdapter adapter = new ArrayAdapter(this, R.layout.bypass_list_item, R.id.bypasslistItemText, bypassList) { @Override public View getView(int position, View convertView, ViewGroup parent) { diff --git a/app/src/main/java/org/proxydroid/ConnectivityBroadcastReceiver.java b/app/src/main/java/org/proxydroid/ConnectivityBroadcastReceiver.java index 7b732b8..e0a2041 100644 --- a/app/src/main/java/org/proxydroid/ConnectivityBroadcastReceiver.java +++ b/app/src/main/java/org/proxydroid/ConnectivityBroadcastReceiver.java @@ -57,7 +57,7 @@ public class ConnectivityBroadcastReceiver extends BroadcastReceiver { - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); private static final String TAG = "ConnectivityBroadcastReceiver"; @@ -68,123 +68,120 @@ public void onReceive(final Context context, final Intent intent) { if (!intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) return; - mHandler.post(new Runnable() { - @Override - public void run() { + mHandler.post(() -> { - // only switching profiles when needed - ConnectivityManager manager = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo networkInfo = manager.getActiveNetworkInfo(); + // only switching profiles when needed + ConnectivityManager manager = (ConnectivityManager) context + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = manager.getActiveNetworkInfo(); - if (networkInfo != null) { - if (networkInfo.getState() == NetworkInfo.State.CONNECTING - || networkInfo.getState() == NetworkInfo.State.DISCONNECTING - || networkInfo.getState() == NetworkInfo.State.UNKNOWN) - return; - } else { - if (!Utils.isWorking()) return; + if (networkInfo != null) { + if (networkInfo.getState() == NetworkInfo.State.CONNECTING + || networkInfo.getState() == NetworkInfo.State.DISCONNECTING + || networkInfo.getState() == NetworkInfo.State.UNKNOWN) + return; + } else { + if (!Utils.isWorking()) return; + } + + SharedPreferences settings = PreferenceManager + .getDefaultSharedPreferences(context); + Profile mProfile = new Profile(); + mProfile.getProfile(settings); + + // Store current settings first + String oldProfile = settings.getString("profile", "1"); + Editor ed = settings.edit(); + ed.putString(oldProfile, mProfile.toString()); + ed.apply(); + + // Load all profiles + String[] profileValues = settings.getString("profileValues", "").split( + "\\|"); + String curSSID = null; + String lastSSID = settings.getString("lastSSID", "-1"); + boolean autoConnect = false; + + // Test on each profile + for (String profile : profileValues) { + String profileString = settings.getString(profile, ""); + mProfile.decodeJson(profileString); + curSSID = onlineSSID(context, mProfile.getSsid(), mProfile.getExcludedSsid()); + if (mProfile.isAutoConnect() && curSSID != null) { + // Enable auto connect + autoConnect = true; + + // XXX: Switch profile first + ed = settings.edit(); + ed.putString("profile", profile); + ed.apply(); + + // Then switch profile values + mProfile.setProfile(settings); + break; } + } - SharedPreferences settings = PreferenceManager - .getDefaultSharedPreferences(context); - Profile mProfile = new Profile(); - mProfile.getProfile(settings); - - // Store current settings first - String oldProfile = settings.getString("profile", "1"); - Editor ed = settings.edit(); - ed.putString(oldProfile, mProfile.toString()); - ed.commit(); - - // Load all profiles - String[] profileValues = settings.getString("profileValues", "").split( - "\\|"); - String curSSID = null; - String lastSSID = settings.getString("lastSSID", "-1"); - boolean autoConnect = false; - - // Test on each profile - for (String profile : profileValues) { - String profileString = settings.getString(profile, ""); - mProfile.decodeJson(profileString); - curSSID = onlineSSID(context, mProfile.getSsid(), mProfile.getExcludedSsid()); - if (mProfile.isAutoConnect() && curSSID != null) { - // Enable auto connect - autoConnect = true; - - // XXX: Switch profile first - ed = settings.edit(); - ed.putString("profile", profile); - ed.commit(); - - // Then switch profile values - mProfile.setProfile(settings); - break; + if (networkInfo == null) { + if (!lastSSID.equals(Constraints.ONLY_3G) + && !lastSSID.equals(Constraints.WIFI_AND_3G) + && !lastSSID.equals(Constraints.ONLY_WIFI)) { + if (Utils.isWorking()) { + context.stopService(new Intent(context, + ProxyDroidService.class)); } } - - if (networkInfo == null) { - if (!lastSSID.equals(Constraints.ONLY_3G) - && !lastSSID.equals(Constraints.WIFI_AND_3G) - && !lastSSID.equals(Constraints.ONLY_WIFI)) { - if (Utils.isWorking()) { - context.stopService(new Intent(context, - ProxyDroidService.class)); + } else { + // no network available now + if (networkInfo.getState() != NetworkInfo.State.CONNECTED) + return; + + if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + // if no last SSID, should give up here + if (!lastSSID.equals("-1")) { + // get WIFI info + WifiManager wm = (WifiManager) context.getApplicationContext() + .getSystemService(Context.WIFI_SERVICE); + WifiInfo wInfo = wm.getConnectionInfo(); + if (wInfo != null) { + // compare with the current SSID + String current = wInfo.getSSID(); + if (current != null) current = current.replace("\"", ""); + if (current != null && !current.equals(lastSSID)) { + // need to switch profile, so stop service first + if (Utils.isWorking()) + context.stopService(new Intent(context, + ProxyDroidService.class)); + } } } } else { - // no network available now - if (networkInfo.getState() != NetworkInfo.State.CONNECTED) - return; - - if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { - // if no last SSID, should give up here - if (!lastSSID.equals("-1")) { - // get WIFI info - WifiManager wm = (WifiManager) context - .getSystemService(Context.WIFI_SERVICE); - WifiInfo wInfo = wm.getConnectionInfo(); - if (wInfo != null) { - // compare with the current SSID - String current = wInfo.getSSID(); - if (current != null) current = current.replace("\"", ""); - if (current != null && !current.equals(lastSSID)) { - // need to switch profile, so stop service first - if (Utils.isWorking()) - context.stopService(new Intent(context, - ProxyDroidService.class)); - } - } - } - } else { - // still satisfy the last trigger - if (!lastSSID.equals(Constraints.ONLY_3G) - && !lastSSID.equals(Constraints.WIFI_AND_3G)) { - if (Utils.isWorking()) - context.stopService(new Intent(context, - ProxyDroidService.class)); - } + // still satisfy the last trigger + if (!lastSSID.equals(Constraints.ONLY_3G) + && !lastSSID.equals(Constraints.WIFI_AND_3G)) { + if (Utils.isWorking()) + context.stopService(new Intent(context, + ProxyDroidService.class)); } } + } - if (autoConnect) { - if (!Utils.isWorking()) { - ProxyDroidReceiver pdr = new ProxyDroidReceiver(); - ed = settings.edit(); - ed.putString("lastSSID", curSSID); - ed.commit(); - Utils.setConnecting(true); - pdr.onReceive(context, intent); - } + if (autoConnect) { + if (!Utils.isWorking()) { + ProxyDroidReceiver pdr = new ProxyDroidReceiver(); + ed = settings.edit(); + ed.putString("lastSSID", curSSID); + ed.apply(); + Utils.setConnecting(true); + pdr.onReceive(context, intent); } } }); } public String onlineSSID(Context context, String ssid, String excludedSsid) { - String ssids[] = ListPreferenceMultiSelect.parseStoredValue(ssid); - String excludedSsids[] = ListPreferenceMultiSelect.parseStoredValue(excludedSsid); + String[] ssids = ListPreferenceMultiSelect.parseStoredValue(ssid); + String[] excludedSsids = ListPreferenceMultiSelect.parseStoredValue(excludedSsid); if (ssids == null) return null; if (ssids.length < 1) @@ -203,7 +200,7 @@ public String onlineSSID(Context context, String ssid, String excludedSsid) { } return null; } - WifiManager wm = (WifiManager) context + WifiManager wm = (WifiManager) context.getApplicationContext() .getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wm.getConnectionInfo(); if (wInfo == null || wInfo.getSSID() == null) diff --git a/app/src/main/java/org/proxydroid/DomainValidator.java b/app/src/main/java/org/proxydroid/DomainValidator.java index 4f8e51a..9a67bd7 100644 --- a/app/src/main/java/org/proxydroid/DomainValidator.java +++ b/app/src/main/java/org/proxydroid/DomainValidator.java @@ -468,9 +468,9 @@ private String chompLeadingDot(String str) { "zw", // Zimbabwe }; - private static final List INFRASTRUCTURE_TLD_LIST = Arrays + private static final List INFRASTRUCTURE_TLD_LIST = Arrays .asList(INFRASTRUCTURE_TLDS); - private static final List GENERIC_TLD_LIST = Arrays.asList(GENERIC_TLDS); - private static final List COUNTRY_CODE_TLD_LIST = Arrays + private static final List GENERIC_TLD_LIST = Arrays.asList(GENERIC_TLDS); + private static final List COUNTRY_CODE_TLD_LIST = Arrays .asList(COUNTRY_CODE_TLDS); } diff --git a/app/src/main/java/org/proxydroid/FileArrayAdapter.java b/app/src/main/java/org/proxydroid/FileArrayAdapter.java index b7742c1..e1753e3 100644 --- a/app/src/main/java/org/proxydroid/FileArrayAdapter.java +++ b/app/src/main/java/org/proxydroid/FileArrayAdapter.java @@ -13,9 +13,9 @@ public class FileArrayAdapter extends ArrayAdapter