aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/fil/libre/repwifiapp/Commons.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/fil/libre/repwifiapp/Commons.java')
-rw-r--r--app/src/fil/libre/repwifiapp/Commons.java134
1 files changed, 60 insertions, 74 deletions
diff --git a/app/src/fil/libre/repwifiapp/Commons.java b/app/src/fil/libre/repwifiapp/Commons.java
index 200381f..1603a76 100644
--- a/app/src/fil/libre/repwifiapp/Commons.java
+++ b/app/src/fil/libre/repwifiapp/Commons.java
@@ -20,6 +20,12 @@
package fil.libre.repwifiapp;
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
@@ -30,39 +36,33 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
+import android.os.Environment;
import android.preference.PreferenceManager;
import fil.libre.repwifiapp.activities.MainActivity;
import fil.libre.repwifiapp.helpers.ConnectionStatus;
+import fil.libre.repwifiapp.helpers.Engine;
import fil.libre.repwifiapp.helpers.Engine6p0;
import fil.libre.repwifiapp.helpers.IEngine;
import fil.libre.repwifiapp.helpers.NetworkManager;
import fil.libre.repwifiapp.helpers.Utils;
+import fil.libre.repwifiapp.helpers.WpaCli;
+import fil.libre.repwifiapp.helpers.WpaSupplicant;
public abstract class Commons {
private static Context currentContext;
- public Context getContext() {
+ public static Context getContext() {
return currentContext;
}
- // ------------- Enviromnet Constants -----------------
+ // ------------- Environment Constants -----------------
public static final int EXCOD_ROOT_DISABLED = 255;
public static final int EXCOD_ROOT_DENIED = 1;
public static final int WAIT_ON_USB_ATTACHED = 1500;
+ public static final int WAIT_FOR_GATEWAY = 4000;
public static final String BSSID_NOT_AVAILABLE = "[BSSID-NOT-AVAILABLE]";
- public static final String v4p2 = "4.2";
public static final String v6p0 = "6.0";
- public static final String SCAN_FILE_HDR = "bssid / frequency / signal level / flags / ssid";
- public static final String INTERFACE_NAME = "wlan0";
- public static final String WORKDIR = "/data/misc/wifi";
- public static final String PID_FILE = WORKDIR + "/pidfile";
- public static final String SOCKET_DIR = WORKDIR + "/sockets/";
- public static final String SOFTAP_FILE = WORKDIR + "/softap.conf";
- public static final String P2P_CONF = WORKDIR + "/p2p_supplicant.conf";
- public static final String WPA_CONF = WORKDIR + "/wpa_supplicant.conf";
- public static final String ENTROPY_FILE = WORKDIR + "/entropy.bin";
- public static final String OVERLAY_FILE = "/system/etc/wifi/wpa_supplicant_overlay.conf";
// ---------------------------------------------
// ------------- Shared Engines -----------------------
@@ -76,12 +76,45 @@ public abstract class Commons {
public static int colorBlack;
public static String dns1Default = "";
public static String dns2Default = "";
+ private static String APP_DATA_FOLDER;
+ public static String msgNoSavedNetwork;
+
+ public static String getNetworkStorageFile() {
+ if (APP_DATA_FOLDER == null) {
+ return null;
+ } else {
+ return APP_DATA_FOLDER + "/repwifi_storage.conf";
+ }
+ }
+
+ @SuppressLint("SimpleDateFormat")
+ public static String getLogDumpFile() {
+
+ File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
+ if (f == null || !f.exists()) {
+ return null;
+ }
+
+ String basefolder;
+ try {
+ basefolder = f.getCanonicalPath();
+ } catch (Exception e) {
+ Utils.logError("Exception while resolving canonical path for log dump file.", e);
+ return null;
+ }
+
+ DateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss", Locale.getDefault());
+ String ts = dateFormat.format(Calendar.getInstance().getTime());
+ return basefolder + "/repwifi_log_dump." + ts + ".log";
+ }
+
+ // --------------------------------------------------------
private static final int NOTIFICATION_ID = 1;
public static void updateNotification(Context context) {
- ConnectionStatus status = connectionEngine.getConnectionStatus();
+ ConnectionStatus status = WpaCli.getConnectionStatus();
Notification.Builder builder = new Notification.Builder(context);
@@ -104,7 +137,7 @@ public abstract class Commons {
builder.setSmallIcon(iconId);
builder.setContentTitle(msg);
- builder.setContentText("Touch to open.");
+ builder.setContentText(currentContext.getString(R.string.msg_touch_open));
Notification n = builder.build();
n.flags |= Notification.FLAG_NO_CLEAR;
@@ -124,12 +157,13 @@ public abstract class Commons {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context,
R.style.Theme_RepWifiDialogTheme);
dlgAlert.setMessage(msg);
- dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int whichButton) {
- return;
- }
- });
+ dlgAlert.setPositiveButton(currentContext.getString(android.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ return;
+ }
+ });
dlgAlert.setCancelable(false);
AlertDialog diag = dlgAlert.create();
@@ -180,9 +214,8 @@ public abstract class Commons {
if (silent) {
- if (connectionEngine != null) {
- connectionEngine.killBackEndProcesses();
- }
+ Engine.killDhcpcd();
+ WpaSupplicant.kill();
} else {
@@ -252,55 +285,6 @@ public abstract class Commons {
// ----------------------------------------------------
- // ----------------- Application Files --------------------
- private static String APP_DATA_FOLDER;
-
- public static String getNetworkStorageFile() {
- if (APP_DATA_FOLDER == null) {
- return null;
- } else {
- return APP_DATA_FOLDER + "/repwifi_storage.conf";
- }
- }
-
- public static String getTempFile() {
- return APP_DATA_FOLDER + "/file.tmp";
- }
-
- public static String getScriptScan() {
- return APP_DATA_FOLDER + "/scan_app.sh";
- }
-
- public static String getScriptScanRes() {
- return APP_DATA_FOLDER + "/get_scan_results_app.sh";
- }
-
- public static String getScriptDhcpcd() {
- return APP_DATA_FOLDER + "/run_dhcpcd.sh";
- }
-
- public static String getOldSelectScript() {
- return WORKDIR + "/select_network.sh";
- }
-
- public static String getScanFile() {
- return APP_DATA_FOLDER + "/scanres.txt";
- }
-
- public static String getStatusFile() {
- return APP_DATA_FOLDER + "/tmpStatus";
- }
-
- public static String getGwFile() {
- return APP_DATA_FOLDER + "/gw.txt";
- }
-
- public static String getTempOutFile() {
- return APP_DATA_FOLDER + "/tmpout.txt";
- }
-
- // --------------------------------------------------------
-
// ----------- Initialization methods ---------------------------
public static boolean init(Context context) {
@@ -310,6 +294,8 @@ public abstract class Commons {
colorThemeDark = currentContext.getResources().getColor(R.color.ThemeDark);
colorThemeLight = currentContext.getResources().getColor(R.color.ThemeLight);
+ msgNoSavedNetwork = currentContext.getResources().getString(
+ R.string.msg_no_saved_network);
colorBlack = currentContext.getResources().getColor(R.color.black);
APP_DATA_FOLDER = currentContext.getExternalFilesDir(null).getAbsolutePath();
dns1Default = currentContext.getResources().getString(R.string.dns1_default);
@@ -333,7 +319,7 @@ public abstract class Commons {
String vers = android.os.Build.VERSION.RELEASE;
if (!vers.startsWith(Commons.v6p0)) {
- showMessage("UNSUPPORTED OS VERSION\nThe current version of Replicant is not supported by RepWifi.\nPlease upgrade to the latest version as soon as possible!");
+ showMessage(currentContext.getString(R.string.msg_os_unsupported));
}
}