aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFil <fil.bergamo@riseup.net>2017-08-25 16:52:27 +0200
committerFil <fil.bergamo@riseup.net>2017-08-25 16:52:27 +0200
commita62493964ab7ac492f307a6e3011567225b42e05 (patch)
treec6762ff060b66b9c75d580c63545fe69f0a99ec5
parent5b71fe514e7650b392a01cc2c4398a68062b32cb (diff)
downloadRepWifiApp-a62493964ab7ac492f307a6e3011567225b42e05.tar.gz
RepWifiApp-a62493964ab7ac492f307a6e3011567225b42e05.tar.bz2
RepWifiApp-a62493964ab7ac492f307a6e3011567225b42e05.zip
new version v0.5 - add various featuresv0.5
This commit introduces a version change, with various new features added, together with a lot of graphical restyling. Changes include: * removed dependency on prebuilt android-support-v4.jar * introduced support for hidden networks * introduced auto-connect feature when plugging the dongle * introduced top-bar notifications about connection state * made major graphic improvements * introduced DNS settings available to the user (uses the gateway if DNS is left blak) * app loaded at system startup * dropped support for Replicant 4.2
-rw-r--r--app/AndroidManifest.xml37
-rw-r--r--app/gen/fil/libre/repwifiapp/R.java177
-rw-r--r--app/previews.xml13
-rw-r--r--app/res/drawable-hdpi/ic_launcher.pngbin4669 -> 0 bytes
-rw-r--r--app/res/drawable-hdpi/ic_launcher2.pngbin2326 -> 0 bytes
-rw-r--r--app/res/drawable-hdpi/ic_launcher_tris.pngbin2229 -> 0 bytes
-rw-r--r--app/res/drawable-hdpi/ic_stat_discon.pngbin0 -> 908 bytes
-rw-r--r--app/res/drawable-hdpi/ic_stat_repwifi.pngbin0 -> 774 bytes
-rw-r--r--app/res/drawable-mdpi/ic_launcher.pngbin2884 -> 0 bytes
-rw-r--r--app/res/drawable-mdpi/ic_launcher2.pngbin1540 -> 0 bytes
-rw-r--r--app/res/drawable-mdpi/ic_launcher_tris.pngbin1507 -> 0 bytes
-rw-r--r--app/res/drawable-mdpi/ic_stat_discon.pngbin0 -> 588 bytes
-rw-r--r--app/res/drawable-mdpi/ic_stat_repwifi.pngbin0 -> 522 bytes
-rw-r--r--app/res/drawable-xhdpi/ic_launcher.pngbin6144 -> 0 bytes
-rw-r--r--app/res/drawable-xhdpi/ic_launcher2.pngbin3083 -> 0 bytes
-rw-r--r--app/res/drawable-xhdpi/ic_launcher_tris.pngbin2925 -> 0 bytes
-rw-r--r--app/res/drawable-xhdpi/ic_stat_discon.pngbin0 -> 1302 bytes
-rw-r--r--app/res/drawable-xhdpi/ic_stat_repwifi.pngbin0 -> 1005 bytes
-rw-r--r--app/res/drawable-xxhdpi/ic_launcher.pngbin9506 -> 0 bytes
-rw-r--r--app/res/drawable-xxhdpi/ic_launcher2.pngbin4723 -> 0 bytes
-rw-r--r--app/res/drawable-xxhdpi/ic_launcher_tris.pngbin4465 -> 0 bytes
-rw-r--r--app/res/drawable/button_bg.xml13
-rw-r--r--app/res/drawable/button_bg_pressed.xml13
-rw-r--r--app/res/drawable/checkmark.xml29
-rw-r--r--app/res/drawable/checkmark_frame.xml25
-rw-r--r--app/res/drawable/divider_shape.xml13
-rw-r--r--app/res/drawable/radio_button.xml15
-rw-r--r--app/res/drawable/radio_frame.xml30
-rw-r--r--app/res/drawable/repwifi_button.xml7
-rw-r--r--app/res/drawable/repwifi_checkbox.xml10
-rw-r--r--app/res/drawable/repwifi_progbar.xml19
-rw-r--r--app/res/drawable/repwifi_radiobutton.xml13
-rw-r--r--app/res/drawable/rw_prog_0.pngbin0 -> 35735 bytes
-rw-r--r--app/res/drawable/rw_prog_1.pngbin0 -> 21565 bytes
-rw-r--r--app/res/drawable/rw_prog_2.pngbin0 -> 24459 bytes
-rw-r--r--app/res/drawable/rw_prog_3.pngbin0 -> 29342 bytes
-rw-r--r--app/res/layout/activity_credits.xml11
-rw-r--r--app/res/layout/activity_input_password.xml58
-rw-r--r--app/res/layout/activity_input_ssid.xml85
-rw-r--r--app/res/layout/activity_long_task.xml38
-rw-r--r--app/res/layout/activity_main.xml119
-rw-r--r--app/res/layout/activity_network_details.xml29
-rw-r--r--app/res/layout/activity_select_network.xml92
-rw-r--r--app/res/layout/activity_settings.xml13
-rw-r--r--app/res/layout/activity_show_status.xml30
-rw-r--r--app/res/menu/activity_input_ssid.xml9
-rw-r--r--app/res/menu/activity_main.xml20
-rw-r--r--app/res/values/array.xml19
-rw-r--r--app/res/values/colors.xml7
-rw-r--r--app/res/values/strings.xml15
-rw-r--r--app/res/values/styles.xml54
-rw-r--r--app/res/xml/debug_settings.xml18
-rw-r--r--app/res/xml/general_settings.xml52
-rw-r--r--app/res/xml/settings.xml12
-rw-r--r--app/res/xml/settings_headers.xml17
-rw-r--r--app/src/fil/libre/repwifiapp/ActivityLauncher.java143
-rw-r--r--app/src/fil/libre/repwifiapp/Commons.java479
-rw-r--r--app/src/fil/libre/repwifiapp/RepWifiIntentReceiver.java43
-rw-r--r--app/src/fil/libre/repwifiapp/activities/CreditsActivity.java40
-rw-r--r--app/src/fil/libre/repwifiapp/activities/InputPasswordActivity.java149
-rw-r--r--app/src/fil/libre/repwifiapp/activities/InputSsidActivity.java115
-rw-r--r--app/src/fil/libre/repwifiapp/activities/LongTaskActivity.java240
-rw-r--r--app/src/fil/libre/repwifiapp/activities/MainActivity.java858
-rw-r--r--app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java49
-rw-r--r--app/src/fil/libre/repwifiapp/activities/NetworkDetailsActivity.java220
-rw-r--r--app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java341
-rw-r--r--app/src/fil/libre/repwifiapp/activities/SettingsActivity.java106
-rw-r--r--app/src/fil/libre/repwifiapp/activities/ShowStatusActivity.java195
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java359
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/ConnectionStatus.java153
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/Engine.java859
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/Engine4p2.java131
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/Engine6p0.java715
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/IEngine.java39
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/NetworkButton.java26
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/NetworkManager.java546
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/RootCommand.java150
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/ShellCommand.java150
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/Utils.java332
79 files changed, 4281 insertions, 3269 deletions
diff --git a/app/AndroidManifest.xml b/app/AndroidManifest.xml
index 908cdc5..891cca9 100644
--- a/app/AndroidManifest.xml
+++ b/app/AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fil.libre.repwifiapp"
- android:versionCode="1"
- android:versionName="0.0.9(1)" >
+ android:versionCode="3"
+ android:versionName="0.5" >
<uses-sdk
android:minSdkVersion="17"
@@ -11,15 +11,44 @@
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_bis"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
+ <receiver
+ android:name="fil.libre.repwifiapp.RepWifiIntentReceiver"
+ android:enabled="true"
+ android:exported="true"
+ android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.intent.action.REBOOT" />
+ </intent-filter>
+ </receiver>
+
+ <!--
+ <receiver
+ android:name="fil.libre.repwifiapp.RepWifiIntentReceiver"
+ android:description="@string/receiver_description"
+ android:enabled="true"
+ android:exported="false"
+ android:icon="@drawable/ic_launcher2"
+ android:label="RepWifiIntentReceiver" >
+ <intent-filter>
+ <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
+ <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
+ </intent-filter>
+ </receiver>
+ -->
+
<activity
android:name="fil.libre.repwifiapp.activities.MainActivity"
android:label="@string/app_name"
+ android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -54,6 +83,10 @@
android:name="fil.libre.repwifiapp.activities.SettingsActivity"
android:label="@string/title_activity_settings" >
</activity>
+ <activity
+ android:name="fil.libre.repwifiapp.activities.InputSsidActivity"
+ android:label="@string/title_activity_input_ssid" >
+ </activity>
</application>
</manifest> \ No newline at end of file
diff --git a/app/gen/fil/libre/repwifiapp/R.java b/app/gen/fil/libre/repwifiapp/R.java
index be4d006..581ff29 100644
--- a/app/gen/fil/libre/repwifiapp/R.java
+++ b/app/gen/fil/libre/repwifiapp/R.java
@@ -19,120 +19,163 @@ public final class R {
public static final class attr {
}
public static final class color {
+ public static final int Anthracite=0x7f060006;
public static final int ThemeDark=0x7f060001;
+ public static final int ThemeDarkSecondary=0x7f060002;
public static final int ThemeLight=0x7f060000;
- public static final int White=0x7f060003;
- public static final int black=0x7f060002;
+ public static final int Transparent=0x7f060005;
+ public static final int White=0x7f060004;
+ public static final int black=0x7f060003;
}
public static final class drawable {
- public static final int ic_launcher=0x7f020000;
- public static final int ic_launcher2=0x7f020001;
- public static final int ic_launcher_bis=0x7f020002;
- public static final int ic_launcher_tris=0x7f020003;
+ public static final int button_bg=0x7f020000;
+ public static final int button_bg_pressed=0x7f020001;
+ public static final int checkmark=0x7f020002;
+ public static final int checkmark_frame=0x7f020003;
+ public static final int divider_shape=0x7f020004;
+ public static final int ic_launcher_bis=0x7f020005;
+ public static final int ic_stat_discon=0x7f020006;
+ public static final int ic_stat_repwifi=0x7f020007;
+ public static final int radio_button=0x7f020008;
+ public static final int radio_frame=0x7f020009;
+ public static final int repwifi_button=0x7f02000a;
+ public static final int repwifi_checkbox=0x7f02000b;
+ public static final int repwifi_progbar=0x7f02000c;
+ public static final int repwifi_radiobutton=0x7f02000d;
+ public static final int rw_prog_0=0x7f02000e;
+ public static final int rw_prog_1=0x7f02000f;
+ public static final int rw_prog_2=0x7f020010;
+ public static final int rw_prog_3=0x7f020011;
}
public static final class id {
- public static final int btn_back=0x7f0a0017;
- public static final int btn_delete=0x7f0a000f;
- public static final int btn_disconnect=0x7f0a0016;
- public static final int btn_manage_nets=0x7f0a000b;
- public static final int btn_rescan=0x7f0a0012;
- public static final int btn_scan=0x7f0a000a;
+ public static final int btn_back=0x7f0a001d;
+ public static final int btn_delete=0x7f0a0015;
+ public static final int btn_disconnect=0x7f0a001c;
+ public static final int btn_hidden_ssid=0x7f0a0010;
+ public static final int btn_manage_nets=0x7f0a0011;
+ public static final int btn_next_hidden_ssid=0x7f0a000a;
+ public static final int btn_rescan=0x7f0a0018;
+ public static final int btn_scan=0x7f0a000f;
+ public static final int btn_select_hidden_ssid=0x7f0a0006;
public static final int chk_show_pass=0x7f0a0004;
- public static final int chk_show_pass_details=0x7f0a000e;
- public static final int img_logo=0x7f0a000c;
- public static final int layout=0x7f0a0006;
- public static final int layout_selnets=0x7f0a0010;
+ public static final int chk_show_pass_details=0x7f0a0014;
+ public static final int img_logo=0x7f0a0012;
+ public static final int layout=0x7f0a000b;
+ public static final int layout_selnets=0x7f0a0016;
+ public static final int line=0x7f0a0007;
public static final int login_form=0x7f0a0001;
- public static final int menu_config=0x7f0a001a;
- public static final int menu_credits=0x7f0a0019;
- public static final int pref_debug_prio=0x7f0a0018;
- public static final int progbar=0x7f0a0007;
- public static final int scrollview=0x7f0a0013;
+ public static final int menu_config=0x7f0a0025;
+ public static final int menu_credits=0x7f0a0026;
+ public static final int menu_settings=0x7f0a0024;
+ public static final int pref_autoconnect=0x7f0a0021;
+ public static final int pref_autostart=0x7f0a0023;
+ public static final int pref_debug_prio=0x7f0a001e;
+ public static final int pref_dns1=0x7f0a001f;
+ public static final int pref_dns2=0x7f0a0020;
+ public static final int pref_progbar=0x7f0a0022;
+ public static final int progbar=0x7f0a000c;
+ public static final int scrollview=0x7f0a0019;
public static final int sign_in_button=0x7f0a0005;
- public static final int table_networks=0x7f0a0014;
+ public static final int table_networks=0x7f0a001a;
public static final int txt_credits=0x7f0a0000;
public static final int txt_insert_pass=0x7f0a0002;
- public static final int txt_main=0x7f0a0009;
- public static final int txt_msg=0x7f0a0008;
- public static final int txt_net_details=0x7f0a000d;
+ public static final int txt_insert_ssid=0x7f0a0008;
+ public static final int txt_main=0x7f0a000e;
+ public static final int txt_msg=0x7f0a000d;
+ public static final int txt_net_details=0x7f0a0013;
public static final int txt_password=0x7f0a0003;
- public static final int txt_selnets=0x7f0a0011;
- public static final int txt_status=0x7f0a0015;
+ public static final int txt_selnets=0x7f0a0017;
+ public static final int txt_ssid=0x7f0a0009;
+ public static final int txt_status=0x7f0a001b;
}
public static final class layout {
public static final int activity_credits=0x7f030000;
public static final int activity_input_password=0x7f030001;
- public static final int activity_long_task=0x7f030002;
- public static final int activity_main=0x7f030003;
- public static final int activity_network_details=0x7f030004;
- public static final int activity_select_network=0x7f030005;
- public static final int activity_show_status=0x7f030006;
+ public static final int activity_input_ssid=0x7f030002;
+ public static final int activity_long_task=0x7f030003;
+ public static final int activity_main=0x7f030004;
+ public static final int activity_network_details=0x7f030005;
+ public static final int activity_select_network=0x7f030006;
+ public static final int activity_settings=0x7f030007;
+ public static final int activity_show_status=0x7f030008;
}
public static final class menu {
- public static final int activity_main=0x7f090000;
+ public static final int activity_input_ssid=0x7f090000;
+ public static final int activity_main=0x7f090001;
}
public static final class string {
- public static final int action_sign_in_register=0x7f07001f;
- public static final int action_sign_in_short=0x7f070020;
+ public static final int action_sign_in_register=0x7f07002a;
+ public static final int action_sign_in_short=0x7f07002b;
public static final int app_name=0x7f070000;
public static final int back_main=0x7f07000b;
public static final int button_text_next=0x7f070005;
+ public static final int confirm_kill_backend=0x7f070025;
+ public static final int confirm_reset_settings=0x7f070024;
+ public static final int connect_hidden=0x7f07001c;
public static final int credit_text=0x7f070013;
public static final int delete=0x7f070010;
public static final int disconnect=0x7f07000c;
- public static final int error_field_required=0x7f070026;
- public static final int error_incorrect_password=0x7f070025;
- public static final int error_invalid_email=0x7f070023;
- public static final int error_invalid_password=0x7f070024;
+ public static final int dns1_default=0x7f070021;
+ public static final int dns2_default=0x7f070022;
+ public static final int error_field_required=0x7f070031;
+ public static final int error_incorrect_password=0x7f070030;
+ public static final int error_invalid_email=0x7f07002e;
+ public static final int error_invalid_password=0x7f07002f;
public static final int force_disconnect=0x7f07000d;
public static final int hello_world=0x7f070009;
+ public static final int input_ssid=0x7f07001d;
public static final int insert_nets_password=0x7f070006;
- public static final int login_progress_signing_in=0x7f070022;
+ public static final int login_progress_signing_in=0x7f07002d;
public static final int manage_networks=0x7f070011;
public static final int menu_config=0x7f070014;
public static final int menu_credits=0x7f070001;
- public static final int menu_forgot_password=0x7f070021;
+ public static final int menu_forgot_password=0x7f07002c;
+ public static final int menu_settings=0x7f07001f;
public static final int msg_confirm_delete_network=0x7f070016;
public static final int msg_interface_not_found=0x7f070015;
public static final int msg_root_denied=0x7f07001b;
public static final int msg_root_disabled=0x7f07001a;
public static final int no=0x7f070018;
- public static final int pref_default_display_name=0x7f07002c;
- public static final int pref_description_social_recommendations=0x7f07002a;
+ public static final int pref_default_display_name=0x7f070037;
+ public static final int pref_description_social_recommendations=0x7f070035;
/** Example settings for Data & Sync
*/
- public static final int pref_header_data_sync=0x7f07002e;
+ public static final int pref_header_data_sync=0x7f070039;
/** Strings related to Settings
Example General settings
*/
- public static final int pref_header_general=0x7f070028;
+ public static final int pref_header_general=0x7f070033;
/** Example settings for Notifications
*/
- public static final int pref_header_notifications=0x7f070031;
- public static final int pref_ringtone_silent=0x7f070034;
- public static final int pref_title_add_friends_to_messages=0x7f07002d;
- public static final int pref_title_display_name=0x7f07002b;
- public static final int pref_title_new_message_notifications=0x7f070032;
- public static final int pref_title_ringtone=0x7f070033;
- public static final int pref_title_social_recommendations=0x7f070029;
- public static final int pref_title_sync_frequency=0x7f07002f;
- public static final int pref_title_system_sync_settings=0x7f070030;
- public static final int pref_title_vibrate=0x7f070035;
+ public static final int pref_header_notifications=0x7f07003c;
+ public static final int pref_ringtone_silent=0x7f07003f;
+ public static final int pref_title_add_friends_to_messages=0x7f070038;
+ public static final int pref_title_display_name=0x7f070036;
+ public static final int pref_title_new_message_notifications=0x7f07003d;
+ public static final int pref_title_ringtone=0x7f07003e;
+ public static final int pref_title_social_recommendations=0x7f070034;
+ public static final int pref_title_sync_frequency=0x7f07003a;
+ public static final int pref_title_system_sync_settings=0x7f07003b;
+ public static final int pref_title_vibrate=0x7f070040;
/** Strings related to login
*/
- public static final int prompt_email=0x7f07001d;
- public static final int prompt_password=0x7f07001e;
+ public static final int prompt_email=0x7f070028;
+ public static final int prompt_password=0x7f070029;
+ public static final int receiver_description=0x7f070023;
public static final int rescan=0x7f070004;
public static final int retry=0x7f070019;
public static final int scan_networks=0x7f070002;
+ public static final int select_saved_net=0x7f070020;
public static final int show_password=0x7f070007;
+ public static final int summary_kill_backend=0x7f070026;
public static final int title_activity_connect=0x7f070008;
public static final int title_activity_credits=0x7f070012;
- public static final int title_activity_input_password=0x7f07001c;
+ public static final int title_activity_input_password=0x7f070027;
+ public static final int title_activity_input_ssid=0x7f07001e;
public static final int title_activity_long_task=0x7f07000e;
public static final int title_activity_manage_networks=0x7f07000f;
public static final int title_activity_select_network=0x7f070003;
- public static final int title_activity_settings=0x7f070027;
+ public static final int title_activity_settings=0x7f070032;
public static final int title_activity_show_status=0x7f07000a;
public static final int yes=0x7f070017;
}
@@ -160,13 +203,21 @@ public final class R {
*/
public static final int AppBaseTheme=0x7f080000;
/** Application theme.
- All customizations that are NOT specific to a particular API-level can go here.
*/
public static final int AppTheme=0x7f080001;
- public static final int LoginFormContainer=0x7f080002;
+ public static final int LoginFormContainer=0x7f080008;
+ public static final int RepWifi_BorderlessButton=0x7f080005;
+ public static final int RepWifi_ButtonBar_AlertDialog=0x7f080006;
+ public static final int TextAppearanceMenu=0x7f080002;
+ /** dialog theme
+ */
+ public static final int Theme_RepWifiDialogTheme=0x7f080007;
+ public static final int Theme_SettingsTheme=0x7f080003;
+ public static final int listViewPrefs=0x7f080004;
}
public static final class xml {
- public static final int settings=0x7f040000;
- public static final int settings_headers=0x7f040001;
+ public static final int debug_settings=0x7f040000;
+ public static final int general_settings=0x7f040001;
+ public static final int settings_headers=0x7f040002;
}
}
diff --git a/app/previews.xml b/app/previews.xml
index daf3adb..7726db7 100644
--- a/app/previews.xml
+++ b/app/previews.xml
@@ -9,6 +9,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -17,6 +18,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -25,6 +27,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -33,6 +36,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -41,6 +45,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -49,6 +54,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -57,6 +63,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -65,6 +72,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -73,6 +81,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -81,6 +90,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -89,6 +99,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -97,6 +108,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
config="layout-sw320dp-w320dp-h533dp-normal-long-port-notnight-hdpi-finger-keyssoft-nokeys-navexposed-trackball-800x480-v17"
@@ -105,6 +117,7 @@
target="Android 4.2.2"
theme="@style/AppTheme" >
</preview>
+
<preview
name="Config1"
activity="com.example.repwifiapp.CreditsActivity"
diff --git a/app/res/drawable-hdpi/ic_launcher.png b/app/res/drawable-hdpi/ic_launcher.png
deleted file mode 100644
index 50093ae..0000000
--- a/app/res/drawable-hdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-hdpi/ic_launcher2.png b/app/res/drawable-hdpi/ic_launcher2.png
deleted file mode 100644
index 78d26b2..0000000
--- a/app/res/drawable-hdpi/ic_launcher2.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-hdpi/ic_launcher_tris.png b/app/res/drawable-hdpi/ic_launcher_tris.png
deleted file mode 100644
index ddaa253..0000000
--- a/app/res/drawable-hdpi/ic_launcher_tris.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-hdpi/ic_stat_discon.png b/app/res/drawable-hdpi/ic_stat_discon.png
new file mode 100644
index 0000000..f92319a
--- /dev/null
+++ b/app/res/drawable-hdpi/ic_stat_discon.png
Binary files differ
diff --git a/app/res/drawable-hdpi/ic_stat_repwifi.png b/app/res/drawable-hdpi/ic_stat_repwifi.png
new file mode 100644
index 0000000..1de8885
--- /dev/null
+++ b/app/res/drawable-hdpi/ic_stat_repwifi.png
Binary files differ
diff --git a/app/res/drawable-mdpi/ic_launcher.png b/app/res/drawable-mdpi/ic_launcher.png
deleted file mode 100644
index e2fe865..0000000
--- a/app/res/drawable-mdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-mdpi/ic_launcher2.png b/app/res/drawable-mdpi/ic_launcher2.png
deleted file mode 100644
index 4a61a75..0000000
--- a/app/res/drawable-mdpi/ic_launcher2.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-mdpi/ic_launcher_tris.png b/app/res/drawable-mdpi/ic_launcher_tris.png
deleted file mode 100644
index 935010c..0000000
--- a/app/res/drawable-mdpi/ic_launcher_tris.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-mdpi/ic_stat_discon.png b/app/res/drawable-mdpi/ic_stat_discon.png
new file mode 100644
index 0000000..a8c3bf6
--- /dev/null
+++ b/app/res/drawable-mdpi/ic_stat_discon.png
Binary files differ
diff --git a/app/res/drawable-mdpi/ic_stat_repwifi.png b/app/res/drawable-mdpi/ic_stat_repwifi.png
new file mode 100644
index 0000000..9ecece8
--- /dev/null
+++ b/app/res/drawable-mdpi/ic_stat_repwifi.png
Binary files differ
diff --git a/app/res/drawable-xhdpi/ic_launcher.png b/app/res/drawable-xhdpi/ic_launcher.png
deleted file mode 100644
index 71ed985..0000000
--- a/app/res/drawable-xhdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-xhdpi/ic_launcher2.png b/app/res/drawable-xhdpi/ic_launcher2.png
deleted file mode 100644
index 01fc7ef..0000000
--- a/app/res/drawable-xhdpi/ic_launcher2.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-xhdpi/ic_launcher_tris.png b/app/res/drawable-xhdpi/ic_launcher_tris.png
deleted file mode 100644
index 5992ef4..0000000
--- a/app/res/drawable-xhdpi/ic_launcher_tris.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-xhdpi/ic_stat_discon.png b/app/res/drawable-xhdpi/ic_stat_discon.png
new file mode 100644
index 0000000..2500cd6
--- /dev/null
+++ b/app/res/drawable-xhdpi/ic_stat_discon.png
Binary files differ
diff --git a/app/res/drawable-xhdpi/ic_stat_repwifi.png b/app/res/drawable-xhdpi/ic_stat_repwifi.png
new file mode 100644
index 0000000..93f6876
--- /dev/null
+++ b/app/res/drawable-xhdpi/ic_stat_repwifi.png
Binary files differ
diff --git a/app/res/drawable-xxhdpi/ic_launcher.png b/app/res/drawable-xxhdpi/ic_launcher.png
deleted file mode 100644
index 5545989..0000000
--- a/app/res/drawable-xxhdpi/ic_launcher.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-xxhdpi/ic_launcher2.png b/app/res/drawable-xxhdpi/ic_launcher2.png
deleted file mode 100644
index aaf68c6..0000000
--- a/app/res/drawable-xxhdpi/ic_launcher2.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable-xxhdpi/ic_launcher_tris.png b/app/res/drawable-xxhdpi/ic_launcher_tris.png
deleted file mode 100644
index 0bf88f3..0000000
--- a/app/res/drawable-xxhdpi/ic_launcher_tris.png
+++ /dev/null
Binary files differ
diff --git a/app/res/drawable/button_bg.xml b/app/res/drawable/button_bg.xml
new file mode 100644
index 0000000..5523e98
--- /dev/null
+++ b/app/res/drawable/button_bg.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle" >
+
+ <solid android:color="@color/ThemeDark" />
+
+ <corners android:radius="3dp" />
+
+ <stroke
+ android:width="2dp"
+ android:color="@color/ThemeLight" />
+
+</shape> \ No newline at end of file
diff --git a/app/res/drawable/button_bg_pressed.xml b/app/res/drawable/button_bg_pressed.xml
new file mode 100644
index 0000000..6e4e953
--- /dev/null
+++ b/app/res/drawable/button_bg_pressed.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle" >
+
+ <solid android:color="@color/ThemeLight" />
+
+ <corners android:radius="3dp" />
+
+ <stroke
+ android:width="2dp"
+ android:color="@color/ThemeDark" />
+
+</shape> \ No newline at end of file
diff --git a/app/res/drawable/checkmark.xml b/app/res/drawable/checkmark.xml
new file mode 100644
index 0000000..9bcf74e
--- /dev/null
+++ b/app/res/drawable/checkmark.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:drawable="@drawable/checkmark_frame">
+
+ </item>
+ <item
+ android:height="3dp"
+ android:top="11dp"
+ android:left="7dp"
+ android:width="10dp">
+ <rotate android:fromDegrees="45" >
+ <shape android:shape="rectangle" >
+ <solid android:color="@color/ThemeLight" />
+ </shape>
+ </rotate>
+ </item>
+ <item
+ android:height="3dp"
+ android:left="12dp"
+ android:top="10dp"
+ android:width="15dp">
+ <rotate android:fromDegrees="-50" >
+ <shape android:shape="rectangle" >
+ <solid android:color="@color/ThemeLight" />
+ </shape>
+ </rotate>
+ </item>
+
+</layer-list> \ No newline at end of file
diff --git a/app/res/drawable/checkmark_frame.xml b/app/res/drawable/checkmark_frame.xml
new file mode 100644
index 0000000..1d5cb45
--- /dev/null
+++ b/app/res/drawable/checkmark_frame.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item
+ android:height="20dp"
+ android:width="20dp"
+ android:top="5dp"
+ android:left="5dp">
+ <shape android:shape="rectangle" >
+ <solid android:color="@android:color/transparent" />
+
+ <stroke
+ android:width="2dp"
+ android:color="@color/ThemeDark" />
+ </shape>
+ </item>
+ <item
+ android:height="30dp"
+ android:width="30dp">
+ <shape android:shape="rectangle" >
+ <solid android:color="@android:color/transparent" />
+ </shape>
+ </item>
+
+</layer-list> \ No newline at end of file
diff --git a/app/res/drawable/divider_shape.xml b/app/res/drawable/divider_shape.xml
new file mode 100644
index 0000000..23d0a16
--- /dev/null
+++ b/app/res/drawable/divider_shape.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle" >
+
+ <solid android:color="@color/ThemeDark" />
+
+ <corners android:radius="2dp" />
+
+ <stroke
+ android:width="1dp"
+ android:color="@color/ThemeLight" />
+
+</shape> \ No newline at end of file
diff --git a/app/res/drawable/radio_button.xml b/app/res/drawable/radio_button.xml
new file mode 100644
index 0000000..ec611f0
--- /dev/null
+++ b/app/res/drawable/radio_button.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:drawable="@drawable/radio_frame">
+
+ </item>
+ <item
+ android:height="13dp"
+ android:width="13dp"
+ android:left="6dp"
+ android:top="6dp">
+ <shape android:shape="oval" >
+ <solid android:color="@color/ThemeDark" />
+ </shape>
+ </item>
+</layer-list> \ No newline at end of file
diff --git a/app/res/drawable/radio_frame.xml b/app/res/drawable/radio_frame.xml
new file mode 100644
index 0000000..de69091
--- /dev/null
+++ b/app/res/drawable/radio_frame.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item
+ android:height="25dp"
+ android:width="25dp">
+ <shape android:shape="oval" >
+ <gradient
+ android:angle="45"
+ android:endColor="#101010"
+ android:startColor="#585858"
+ android:type="linear" >
+ </gradient>
+ </shape>
+ </item>
+
+ <item
+ android:height="20dp"
+ android:left="2.5dp"
+ android:top="2.5dp"
+ android:width="20dp">
+ <shape android:shape="oval" >
+ <solid android:color="@android:color/black" />
+
+ <stroke
+ android:width="1dp"
+ android:color="@color/ThemeDark" />
+ </shape>
+ </item>
+
+</layer-list> \ No newline at end of file
diff --git a/app/res/drawable/repwifi_button.xml b/app/res/drawable/repwifi_button.xml
new file mode 100644
index 0000000..263ee14
--- /dev/null
+++ b/app/res/drawable/repwifi_button.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:drawable="@drawable/button_bg_pressed"
+ android:state_pressed="true"/>
+
+ <item android:drawable="@drawable/button_bg"/>
+</selector> \ No newline at end of file
diff --git a/app/res/drawable/repwifi_checkbox.xml b/app/res/drawable/repwifi_checkbox.xml
new file mode 100644
index 0000000..afe3b7f
--- /dev/null
+++ b/app/res/drawable/repwifi_checkbox.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item android:drawable="@drawable/checkmark"
+ android:state_checked="true"/>
+
+ <item android:drawable="@drawable/checkmark_frame"
+ android:state_checked="false" />
+
+</selector> \ No newline at end of file
diff --git a/app/res/drawable/repwifi_progbar.xml b/app/res/drawable/repwifi_progbar.xml
new file mode 100644
index 0000000..1b05913
--- /dev/null
+++ b/app/res/drawable/repwifi_progbar.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
+ android:oneshot="false" >
+
+ <item android:duration="300">
+ <bitmap android:src="@drawable/rw_prog_1" />
+ </item>
+ <item android:duration="300">
+ <bitmap android:src="@drawable/rw_prog_2" />
+ </item>
+ <item android:duration="300">
+ <bitmap android:src="@drawable/rw_prog_3" />
+ </item>
+ <item android:duration="300">
+ <bitmap android:src="@drawable/rw_prog_0" />
+ </item>
+
+</animation-list> \ No newline at end of file
diff --git a/app/res/drawable/repwifi_radiobutton.xml b/app/res/drawable/repwifi_radiobutton.xml
new file mode 100644
index 0000000..053e100
--- /dev/null
+++ b/app/res/drawable/repwifi_radiobutton.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item android:drawable="@drawable/radio_button"
+ android:state_checked="true"/>
+
+ <item android:drawable="@drawable/radio_button"
+ android:state_pressed="true"/>
+
+ <item android:drawable="@drawable/radio_frame"
+ android:state_checked="false" />
+
+</selector> \ No newline at end of file
diff --git a/app/res/drawable/rw_prog_0.png b/app/res/drawable/rw_prog_0.png
new file mode 100644
index 0000000..b2f15ea
--- /dev/null
+++ b/app/res/drawable/rw_prog_0.png
Binary files differ
diff --git a/app/res/drawable/rw_prog_1.png b/app/res/drawable/rw_prog_1.png
new file mode 100644
index 0000000..0db5a6f
--- /dev/null
+++ b/app/res/drawable/rw_prog_1.png
Binary files differ
diff --git a/app/res/drawable/rw_prog_2.png b/app/res/drawable/rw_prog_2.png
new file mode 100644
index 0000000..3389b47
--- /dev/null
+++ b/app/res/drawable/rw_prog_2.png
Binary files differ
diff --git a/app/res/drawable/rw_prog_3.png b/app/res/drawable/rw_prog_3.png
new file mode 100644
index 0000000..155a2de
--- /dev/null
+++ b/app/res/drawable/rw_prog_3.png
Binary files differ
diff --git a/app/res/layout/activity_credits.xml b/app/res/layout/activity_credits.xml
index 871536c..04280d4 100644
--- a/app/res/layout/activity_credits.xml
+++ b/app/res/layout/activity_credits.xml
@@ -1,17 +1,16 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:background="@color/ThemeDark">
+ android:background="@color/ThemeDark"
+ android:orientation="vertical" >
- <TextView
+ <TextView
android:id="@+id/txt_credits"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
+ android:scrollbars="vertical"
android:textColor="@color/ThemeLight"
android:textColorLink="@color/ThemeLight"
- android:textSize="7pt"
- android:scrollbars = "vertical" />
-
+ android:textSize="7pt" />
</LinearLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_input_password.xml b/app/res/layout/activity_input_password.xml
index a024879..14dd78a 100644
--- a/app/res/layout/activity_input_password.xml
+++ b/app/res/layout/activity_input_password.xml
@@ -2,63 +2,63 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context=".InputPasswordActivity" >
-
-
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background = "@color/black" >
+ android:background="@color/black" >
<LinearLayout
style="@style/LoginFormContainer"
- android:orientation="vertical"
- android:background="@color/black"
android:layout_width="match_parent"
- android:layout_height="wrap_content" >
-
- <TextView
+ android:layout_height="wrap_content"
+ android:background="@color/black"
+ android:orientation="vertical" >
+
+ <TextView
android:id="@+id/txt_insert_pass"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textCursorDrawable="@null"
- android:textColor="@color/ThemeLight"
- android:textSize="10pt"
- android:layout_marginBottom="10dp"
- android:background="@color/black"
- android:maxLines = "10"
- android:text="@string/insert_nets_password" />
-
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="10dp"
+ android:background="@color/black"
+ android:maxLines="10"
+ android:text="@string/insert_nets_password"
+ android:textColor="@color/ThemeLight"
+ android:textSize="10pt" />
+
<EditText
android:id="@+id/txt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
+ android:maxLines="1"
+ android:singleLine="true"
android:textColor="@color/ThemeLight"
+ android:background="@drawable/button_bg"
+ android:textCursorDrawable="@null"
android:textSize="10pt"
- android:maxLines="1"
- android:singleLine="true" />
-
- <CheckBox
+ android:padding="5dp" />
+
+ <CheckBox
android:id="@+id/chk_show_pass"
- android:textColor="@color/ThemeLight"
- android:text="@string/show_password"
android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
+ android:layout_height="wrap_content"
+ android:text="@string/show_password"
+ android:textColor="@color/ThemeLight"
+ android:textSize="9pt" />
+
<Button
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:background="@color/ThemeDark"
- android:textColor="@color/ThemeLight"
android:layout_gravity="right"
android:layout_marginTop="16dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="onBtnNextClick"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:text="@string/button_text_next"
- android:onClick="onBtnNextClick" />
-
+ android:textColor="@color/ThemeLight" />
</LinearLayout>
</ScrollView>
diff --git a/app/res/layout/activity_input_ssid.xml b/app/res/layout/activity_input_ssid.xml
new file mode 100644
index 0000000..aa7e8f3
--- /dev/null
+++ b/app/res/layout/activity_input_ssid.xml
@@ -0,0 +1,85 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/black"
+ android:padding="20dp"
+ tools:context=".InputSsidActivity" >
+
+ <!-- -->
+
+ <Button
+ android:id="@+id/btn_select_hidden_ssid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="32dp"
+ android:layout_marginTop="16dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="onBtnSelectClick"
+ android:paddingLeft="32dp"
+ android:paddingRight="32dp"
+ android:text="@string/select_saved_net"
+ android:textColor="@color/ThemeLight" />
+
+ <View
+ android:id="@+id/line"
+ android:layout_width="match_parent"
+ android:layout_height="2dp"
+ android:layout_below="@id/btn_select_hidden_ssid"
+ android:layout_marginBottom="20dp"
+ android:layout_marginTop="20dp"
+ android:background="@color/ThemeLight" />
+
+ <TextView
+ android:id="@+id/txt_insert_ssid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/line"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="10dp"
+ android:background="@color/black"
+ android:maxLines="1"
+ android:text="@string/input_ssid"
+ android:textColor="@color/ThemeLight"
+ android:textSize="9pt" />
+
+ <EditText
+ android:id="@+id/txt_ssid"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/txt_insert_ssid"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="30dp"
+ android:background="@drawable/button_bg"
+ android:inputType="text"
+ android:maxLines="1"
+ android:singleLine="true"
+ android:textColor="@color/ThemeLight"
+ android:textCursorDrawable="@null"
+ android:padding="5dp"
+ android:textSize="10pt" />
+
+ <LinearLayout
+ style="@style/LoginFormContainer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/txt_ssid"
+ android:background="@color/black"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/btn_next_hidden_ssid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:layout_marginTop="16dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="onBtnNextClick"
+ android:paddingLeft="32dp"
+ android:paddingRight="32dp"
+ android:text="@string/button_text_next"
+ android:textColor="@color/ThemeLight" />
+ </LinearLayout>
+
+</RelativeLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_long_task.xml b/app/res/layout/activity_long_task.xml
index 769144e..a17ba32 100644
--- a/app/res/layout/activity_long_task.xml
+++ b/app/res/layout/activity_long_task.xml
@@ -3,23 +3,25 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" >
-
- <ProgressBar
- android:id="@+id/progbar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true" />
-
- <TextView
- android:id="@+id/txt_msg"
+
+ <ProgressBar
+ android:id="@+id/progbar"
+ style="?android:attr/progressBarStyleLarge"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
+ android:indeterminateDrawable="@drawable/repwifi_progbar" />
+
+ <TextView
+ android:id="@+id/txt_msg"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:layout_below="@id/progbar"
- android:padding="10dp"
- android:textColor="@color/ThemeLight" />
-
-
+ android:layout_height="wrap_content"
+ android:layout_below="@id/progbar"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
+ android:padding="10dp"
+ android:textColor="@color/ThemeLight" />
+
</RelativeLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_main.xml b/app/res/layout/activity_main.xml
index 3818751..b9359ba 100644
--- a/app/res/layout/activity_main.xml
+++ b/app/res/layout/activity_main.xml
@@ -1,57 +1,70 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:padding="15dp"
- android:background="@color/black" >
+ android:background="@color/black"
+ android:padding="15dp" >
+
+ <TextView
+ android:id="@+id/txt_main"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="10dp"
+ android:layout_marginTop="10dp"
+ android:background="@color/black"
+ android:maxLines="10"
+ android:text=""
+ android:textColor="@color/ThemeLight" />
+
+ <Button
+ android:id="@+id/btn_scan"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="20dp"
+ android:layout_marginTop="15dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="btnScanClick"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/scan_networks"
+ android:textColor="@color/ThemeLight" />
+
+ <Button
+ android:id="@+id/btn_hidden_ssid"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/btn_scan"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="20dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="btnHiddenClick"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/connect_hidden"
+ android:textColor="@color/ThemeLight" />
- <TextView
- android:id="@+id/txt_main"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/black"
- android:maxLines = "10"
- android:layout_marginTop="10dp"
- android:layout_marginBottom="10dp"
- android:text="" />
-
- <Button
- android:id="@+id/btn_scan"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:layout_centerHorizontal="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/ThemeDark"
- android:text="@string/scan_networks"
- android:onClick="btnScanClick"
- android:layout_marginTop="15dp"
- android:layout_marginBottom="20dp" />
-
- <Button
- android:id="@+id/btn_manage_nets"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/btn_scan"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:layout_centerHorizontal="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/ThemeDark"
- android:text="@string/manage_networks"
- android:onClick="btnManageClick"
- android:layout_marginBottom="20dp" />
-
- <ImageView
- android:id="@+id/img_logo"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_centerHorizontal="true"
- android:layout_below="@id/btn_manage_nets"
- android:layout_margin="20dp" >
-
- </ImageView>
-
- </RelativeLayout> \ No newline at end of file
+ <Button
+ android:id="@+id/btn_manage_nets"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/btn_hidden_ssid"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="20dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="btnManageClick"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/manage_networks"
+ android:textColor="@color/ThemeLight" />
+
+ <ImageView
+ android:id="@+id/img_logo"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_below="@id/btn_manage_nets"
+ android:layout_centerHorizontal="true"
+ android:layout_margin="20dp" >
+ </ImageView>
+
+</RelativeLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_network_details.xml b/app/res/layout/activity_network_details.xml
index a36c957..6442585 100644
--- a/app/res/layout/activity_network_details.xml
+++ b/app/res/layout/activity_network_details.xml
@@ -2,8 +2,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:padding="15dp"
android:background="@color/black"
+ android:padding="15dp"
tools:context=".NetworkDetailsActivity" >
<TextView
@@ -11,28 +11,29 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
+ android:background="@color/black"
android:textColor="@color/ThemeLight"
- android:textSize="7pt"
- android:background="@color/black" />
-
+ android:textSize="7pt" />
+
<CheckBox
android:id="@+id/chk_show_pass_details"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
android:layout_below="@id/txt_net_details"
+ android:text="@string/show_password"
android:textColor="@color/ThemeLight"
- android:text="@string/show_password"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- <Button
+ android:textSize="10pt" />
+
+ <Button
android:id="@+id/btn_delete"
- android:layout_below="@id/chk_show_pass_details"
- android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_below="@id/chk_show_pass_details"
android:layout_centerHorizontal="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/ThemeDark"
+ android:layout_marginTop="15dp"
+ android:background="@drawable/repwifi_button"
+ android:onClick="btnDeleteClick"
android:text="@string/delete"
- android:onClick="btnDeleteClick" />
+ android:textColor="@color/ThemeLight" />
</RelativeLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_select_network.xml b/app/res/layout/activity_select_network.xml
index 2dd7958..d1c0be5 100644
--- a/app/res/layout/activity_select_network.xml
+++ b/app/res/layout/activity_select_network.xml
@@ -3,56 +3,54 @@
android:id="@+id/layout_selnets"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:background="@color/black"
android:padding="15dp"
- tools:context=".SelectNetworkActivity"
- android:background="@color/black" >
-
- <TextView
- android:id="@+id/txt_selnets"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:textColor="@color/ThemeLight"
- android:textSize="10pt"
- android:maxLines = "5"
- android:scrollbars = "vertical"
- android:layout_marginBottom="10dp" />
-
+ tools:context=".SelectNetworkActivity" >
+
+ <TextView
+ android:id="@+id/txt_selnets"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="10dp"
+ android:maxLines="5"
+ android:scrollbars="vertical"
+ android:textColor="@color/ThemeLight"
+ android:textSize="10pt" />
+
<Button
- android:id="@+id/btn_rescan"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txt_selnets"
- android:paddingLeft="10dp"
- android:paddingRight="10dp"
- android:layout_centerHorizontal="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/ThemeDark"
- android:text="@string/rescan"
- android:onClick="btnScanClick" />
+ android:id="@+id/btn_rescan"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/txt_selnets"
+ android:layout_centerHorizontal="true"
+ android:background="@drawable/repwifi_button"
+ android:onClick="btnScanClick"
+ android:paddingLeft="10dp"
+ android:paddingRight="10dp"
+ android:text="@string/rescan"
+ android:textColor="@color/ThemeLight" />
- <ScrollView
- android:id="@+id/scrollview"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_below="@id/btn_rescan"
- android:layout_centerHorizontal="true"
- android:scrollbars="vertical"
- android:fillViewport="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/White" >
+ <ScrollView
+ android:id="@+id/scrollview"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_below="@id/btn_rescan"
+ android:layout_centerHorizontal="true"
+ android:background="@color/black"
+ android:fillViewport="true"
+ android:scrollbars="vertical"
+ android:textColor="@color/ThemeLight" >
- <TableLayout
- android:id="@+id/table_networks"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="fill_horizontal"
- android:isScrollContainer="true"
- android:textColor="@color/ThemeLight"
- android:background="@color/black" >
- </TableLayout>
-
-
- </ScrollView>
+ <TableLayout
+ android:id="@+id/table_networks"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="fill_horizontal"
+ android:background="@color/black"
+ android:isScrollContainer="true"
+ android:textColor="@color/ThemeLight" >
+ </TableLayout>
+ </ScrollView>
</RelativeLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_settings.xml b/app/res/layout/activity_settings.xml
new file mode 100644
index 0000000..a887096
--- /dev/null
+++ b/app/res/layout/activity_settings.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/black" >
+
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/black" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/app/res/layout/activity_show_status.xml b/app/res/layout/activity_show_status.xml
index 9f7e584..5afc596 100644
--- a/app/res/layout/activity_show_status.xml
+++ b/app/res/layout/activity_show_status.xml
@@ -2,8 +2,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:padding="15dp"
android:background="@color/black"
+ android:padding="15dp"
tools:context=".ShowStatusActivity" >
<TextView
@@ -13,31 +13,31 @@
android:layout_centerHorizontal="true"
android:background="@color/black"
android:textColor="@color/ThemeLight" />
-
- <Button
+
+ <Button
android:id="@+id/btn_disconnect"
- android:background="@color/ThemeDark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true"
android:layout_below="@id/txt_status"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
android:layout_marginTop="10dp"
- android:textColor="@color/ThemeLight"
+ android:background="@drawable/repwifi_button"
+ android:onClick="onBtnDisconnectClick"
android:text="@string/disconnect"
- android:onClick="onBtnDisconnectClick"/>
-
- <Button
+ android:textColor="@color/ThemeLight" />
+
+ <Button
android:id="@+id/btn_back"
- android:background="@color/ThemeDark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true"
android:layout_below="@id/txt_status"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
android:layout_marginTop="10dp"
- android:textColor="@color/ThemeLight"
+ android:background="@drawable/repwifi_button"
+ android:onClick="onBtnMainClick"
android:text="@string/back_main"
- android:onClick="onBtnMainClick"/>
+ android:textColor="@color/ThemeLight" />
</RelativeLayout> \ No newline at end of file
diff --git a/app/res/menu/activity_input_ssid.xml b/app/res/menu/activity_input_ssid.xml
new file mode 100644
index 0000000..77f358b
--- /dev/null
+++ b/app/res/menu/activity_input_ssid.xml
@@ -0,0 +1,9 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <item
+ android:id="@+id/menu_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never"
+ android:title="@string/menu_settings"/>
+
+</menu> \ No newline at end of file
diff --git a/app/res/menu/activity_main.xml b/app/res/menu/activity_main.xml
index 7855b0d..e9a1624 100644
--- a/app/res/menu/activity_main.xml
+++ b/app/res/menu/activity_main.xml
@@ -1,15 +1,19 @@
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ android:divider="@drawable/divider_shape"
+ android:dividerHeight="2pt"
+ android:textColor="@color/ThemeLight" >
<item
- android:id="@+id/menu_credits"
- android:orderInCategory="100"
+ android:id="@+id/menu_config"
+ android:orderInCategory="1"
android:showAsAction="never"
- android:title="@string/menu_credits" />
-
+ android:textColor="@color/ThemeLight"
+ android:title="@string/menu_config"/>
<item
- android:id="@+id/menu_config"
- android:orderInCategory="100"
+ android:id="@+id/menu_credits"
+ android:orderInCategory="2"
android:showAsAction="never"
- android:title="@string/menu_config" />
+ android:textColor="@color/ThemeLight"
+ android:title="@string/menu_credits"/>
</menu> \ No newline at end of file
diff --git a/app/res/values/array.xml b/app/res/values/array.xml
index ac6da05..c8c4d9b 100644
--- a/app/res/values/array.xml
+++ b/app/res/values/array.xml
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
+
<string-array name="debug_priority_names">
- <item >Log everything</item>
- <item >Log medium priority events</item>
- <item >Log high priority events only</item>
- <item >Logging disabled</item>
+ <item>Log everything</item>
+ <item>Log medium priority events</item>
+ <item>Log high priority events only</item>
+ <item>Logging disabled</item>
</string-array>
<string-array name="debug_priority">
- <item >0</item>
- <item >1</item>
- <item >2</item>
- <item >3</item>
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
</string-array>
-
+
</resources> \ No newline at end of file
diff --git a/app/res/values/colors.xml b/app/res/values/colors.xml
index 22767c8..f637c6a 100644
--- a/app/res/values/colors.xml
+++ b/app/res/values/colors.xml
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
-<resources>
+<resources>
+
<color name="ThemeLight">#FFA500</color>
<color name="ThemeDark">#5F021F</color>
+ <color name="ThemeDarkSecondary">#5f0230</color>
<color name="black">#000000</color>
<color name="White">#FFFFFF</color>
+ <color name="Transparent">#00000000</color>
+ <color name="Anthracite">#181818</color>
+
</resources> \ No newline at end of file
diff --git a/app/res/values/strings.xml b/app/res/values/strings.xml
index 0771c3e..dccbe44 100644
--- a/app/res/values/strings.xml
+++ b/app/res/values/strings.xml
@@ -20,14 +20,25 @@
<string name="delete">Delete network info</string>
<string name="manage_networks">Manage Networks</string>
<string name="title_activity_credits">Credits</string>
- <string name="credit_text">Copyright 2017 Filippo \&quot;Fil\&quot; Bergamo&lt;br/&gt;&lt;br/&gt;This app is Free Software.&lt;br/&gt;It\'s licensed under the terms of &lt;a href=&quot;https://www.gnu.org/licenses/gpl.txt&quot;&gt;GPL v3&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;This app is developed as a contribution to &lt;br/&gt;&lt;a href=&quot;http://www.replicant.us&quot;&gt;The Replicant Project&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;&lt;u&gt;&lt;big&gt;Thank GNUs:&lt;/big&gt;&lt;/u&gt;&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Tibi \&quot;tct\&quot; Turbureanu&lt;/b&gt;&lt;br/&gt;for having done the initial job of porting libre WiFi to Replicant 4.2.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Wolfgang Wiedmeyer&lt;/b&gt;&lt;br/&gt;for porting libre WiFi to Replicant 6.0 and for helping with the scripts.&lt;br/&gt;&lt;br/&gt;To report on bugs, request features, or any help request, please refer to:&lt;br/&gt;&lt;a href=&quot;http://redmine.replicant.us/projects/replicant/boards&quot;&gt;Replicant\'s Forum&lt;/a&gt;&lt;br/&gt;</string>
+ <string name="credit_text">Copyright 2017 Filippo \&quot;Fil\&quot; Bergamo&lt;br/&gt;&lt;br/&gt;This app is Free Software.&lt;br/&gt;It\'s licensed under the terms of &lt;a href=&quot;https://www.gnu.org/licenses/gpl.txt&quot;&gt;GPL v3&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;This app is developed as a contribution to &lt;br/&gt;&lt;a href=&quot;http://www.replicant.us&quot;&gt;The Replicant Project&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;&lt;u&gt;&lt;big&gt;Thank GNUs:&lt;/big&gt;&lt;/u&gt;&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Tiberiu - Technoethical&lt;/b&gt;&lt;br/&gt;for having done the initial job of porting libre WiFi to Replicant 4.2.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Wolfgang Wiedmeyer&lt;/b&gt;&lt;br/&gt;for porting libre WiFi to Replicant 6.0 and for helping with the scripts.&lt;br/&gt;&lt;br/&gt;To report on bugs, request features, or any help request, please refer to:&lt;br/&gt;&lt;a href=&quot;http://redmine.replicant.us/projects/replicant/boards&quot;&gt;Replicant\'s Forum&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Source code is hosted at: &lt;br/&gt;&lt;a href=&quot;https://git.replicant.us/contrib/Fil/RepWifiApp/&quot;&gt;https://git.replicant.us/contrib/Fil/RepWifiApp/&lt;/a&gt;&lt;br/&gt;</string>
<string name="menu_config">Settings</string>
- <string name="msg_interface_not_found">External WiFi adapter not found!\nPlease plug in a supported WiFi adapter and retry.</string>
+ <string name="msg_interface_not_found">WiFi adapter not found!\nPlease plug in a supported WiFi adapter and retry.</string>
<string name="msg_confirm_delete_network">Are you sure you want to delete this network?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="retry">Retry</string>
<string name="msg_root_disabled">Root access is disabled.\n\nSeems like root access is disabled on this device.\nRepWifi needs root access in order to work.\nPlease, enable root access for applications in:\nSettings > Developer options > Root access > "Apps only"\nWhen done so, restart RepWifi and grant the permission to use root, if asked.</string>
<string name="msg_root_denied">Root access denied.\nSeems like you denied root access to RepWifi.\nRepWifi needs root access in order to work.\nPlease, restart the application, and grant RepWifi the permission to use root, when asked.</string>
+ <string name="connect_hidden">Connect to Hidden Network</string>
+ <string name="input_ssid">Or.. Insert Network\'s name (SSID)</string>
+ <string name="title_activity_input_ssid">Insert Network\'s Name</string>
+ <string name="menu_settings">Settings</string>
+ <string name="select_saved_net">Use Saved Network</string>
+ <string name="dns1_default">185.121.177.177</string>
+ <string name="dns2_default">169.239.202.202</string>
+ <string name="receiver_description">RepWifi\'s listener for startup event. Provides auto-start and notification features to RepWifi.</string>
+ <string name="confirm_reset_settings">Are you sure you want to reset all settings to default?</string>
+ <string name="confirm_kill_backend">Are you sure you want to kill the back-end processes?</string>
+ <string name="summary_kill_backend">Sometimes back-end programs get stuck in inconsistent states.\nClicking this button restores normal behaviour by killing running instances of wpa_supplicant and dhcpcd."</string>
</resources> \ No newline at end of file
diff --git a/app/res/values/styles.xml b/app/res/values/styles.xml
index c414ecc..18e186b 100644
--- a/app/res/values/styles.xml
+++ b/app/res/values/styles.xml
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
-<resources>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
- <style name="AppBaseTheme" parent="android:Theme.Light">
+ <style name="AppBaseTheme" parent="android:Theme.Holo">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
@@ -15,7 +15,57 @@
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
+ <item name="android:itemBackground">@color/Anthracite</item>
+ <item name="android:actionMenuTextColor">@color/ThemeLight</item>
+ <item name="android:itemTextAppearance">@style/TextAppearanceMenu</item>
+ <item name="android:listChoiceIndicatorMultiple">@drawable/repwifi_checkbox</item>
+ <item name="android:listDivider">@color/ThemeDark</item>
+ <item name="android:dividerHeight">1dp</item>
+ </style>
+
+ <style name="TextAppearanceMenu">
+ <item name="android:textColor">@color/ThemeLight</item>
+ </style>
+
+ <style name="Theme.SettingsTheme" parent="@style/AppTheme"> <!-- "@android:style/Theme.Holo" -->
+ <item name="android:windowBackground">@color/Anthracite</item>
+ <item name="android:textColor">@color/ThemeLight</item>
+ <item name="android:textColorSecondary">@android:color/white</item>
+ <item name="android:alertDialogTheme">@style/Theme.RepWifiDialogTheme</item>
+ <item name="android:listChoiceIndicatorMultiple">@drawable/repwifi_checkbox</item>
</style>
+ <style name="listViewPrefs" parent="@android:style/Widget.ListView">
+ <item name="android:background">@color/Anthracite</item>
+ <item name="android:textColor">@color/ThemeLight</item>
+ <item name="android:cacheColorHint">@color/Anthracite</item>
+ </style>
+
+ <style name="RepWifi.BorderlessButton" parent="@android:style/Widget.Holo.Button.Borderless">
+ <item name="android:textColor">@color/ThemeLight</item>
+ <item name="android:background">@drawable/repwifi_button</item>
+ </style>
+
+ <style name="RepWifi.ButtonBar.AlertDialog" parent="@android:style/Holo.ButtonBar.AlertDialog">
+ <item name="android:textColor">@color/ThemeLight</item>
+ <item name="android:background">@color/ThemeDark</item>
+ </style>
+
+ <!-- dialog theme -->
+ <style name="Theme.RepWifiDialogTheme" parent="@android:style/Theme.Holo.Dialog">
+ <item name="android:textColor">@color/ThemeLight</item>
+ <item name="android:textColorPrimary">@color/ThemeLight</item>
+ <item name="android:textColorSecondary">@color/ThemeDark</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:borderlessButtonStyle">@style/RepWifi.BorderlessButton</item>
+ <item name="android:buttonStyle">@style/RepWifi.BorderlessButton</item>
+ <item name="android:buttonBarStyle">@style/RepWifi.ButtonBar.AlertDialog</item>
+ <item name="android:listViewStyle">@style/listViewPrefs</item>
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:listChoiceIndicatorSingle">@drawable/repwifi_radiobutton</item>
+ </style>
+
+
</resources> \ No newline at end of file
diff --git a/app/res/xml/debug_settings.xml b/app/res/xml/debug_settings.xml
new file mode 100644
index 0000000..8aa09f4
--- /dev/null
+++ b/app/res/xml/debug_settings.xml
@@ -0,0 +1,18 @@
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <ListPreference
+ android:id="@+id/pref_debug_prio"
+ android:defaultValue="3"
+ android:entries="@array/debug_priority_names"
+ android:entryValues="@array/debug_priority"
+ android:key="debug_priority"
+ android:title="Log priority"
+ android:divider="@drawable/divider_shape" />
+
+ <Preference android:title="Reset back-end engine"
+ android:key="pref_kill_backend"
+ android:summary="@string/summary_kill_backend"
+ android:background="@drawable/button_bg"
+ android:textColor="@color/ThemeLight" />
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/app/res/xml/general_settings.xml b/app/res/xml/general_settings.xml
new file mode 100644
index 0000000..d836b67
--- /dev/null
+++ b/app/res/xml/general_settings.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <EditTextPreference
+ android:id="@+id/pref_dns1"
+ android:defaultValue="@string/dns1_default"
+ android:key="dns1"
+ android:summary="Set the IPv4 address of the primary DNS server.\nIf left blank, RepWifi will try to use the default gateway as a DNS resolver."
+ android:title="DNS server #1"
+ android:textColor="@color/ThemeLight"
+ android:background="@color/ThemeDark"
+ android:padding="5dp"/>
+
+
+ <EditTextPreference
+ android:id="@+id/pref_dns2"
+ android:defaultValue="@string/dns2_default"
+ android:key="dns2"
+ android:summary="Set the IPv4 address of the secondary DNS server.\nIf the primary address is blank, this will be ignored."
+ android:title="DNS server #2"
+ android:textColor="@color/ThemeLight"
+ android:background="@color/ThemeDark"
+ android:padding="5dp"/>
+
+ <CheckBoxPreference
+ android:id="@+id/pref_autoconnect"
+ android:defaultValue="false"
+ android:key="enable_autoconnect"
+ android:summary="When the WiFi dongle is attached, RepWifi connects automatically to reachable known networks.\n(Experimental)."
+ android:title="Enable Autoconnect" />
+
+ <CheckBoxPreference
+ android:id="@+id/pref_progbar"
+ android:defaultValue="true"
+ android:key="enable_progbar"
+ android:summary="Show an animated progress bar while doing long background tasks.\nKeep it disabled to (hopefully) save some extra power for the WiFi dongle."
+ android:title="Animated progress bar" />
+
+ <CheckBoxPreference
+ android:id="@+id/pref_autostart"
+ android:defaultValue="false"
+ android:key="enable_autostart"
+ android:summary="If checked, RepWifi is started automatically on system's startup."
+ android:title="Enable Start at Boot" />
+
+ <Preference android:title="Restore Defaults"
+ android:key="pref_restore_default"
+ android:summary="click to restore default settings\n(then return to main screen to apply the reset)"
+ android:background="@drawable/button_bg"
+ android:textColor="@color/ThemeLight" />
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/app/res/xml/settings.xml b/app/res/xml/settings.xml
deleted file mode 100644
index f53f00f..0000000
--- a/app/res/xml/settings.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-
- <ListPreference
- android:key="debug_priority"
- android:title="Log priority"
- android:id="@+id/pref_debug_prio"
- android:entries="@array/debug_priority_names"
- android:entryValues="@array/debug_priority"
- android:defaultValue="3" />
-
-
-</PreferenceScreen> \ No newline at end of file
diff --git a/app/res/xml/settings_headers.xml b/app/res/xml/settings_headers.xml
index d2212da..50f7436 100644
--- a/app/res/xml/settings_headers.xml
+++ b/app/res/xml/settings_headers.xml
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
+<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
-<preference-headers
- xmlns:android="http://schemas.android.com/apk/res/android">
-
- <header
- android:fragment="fil.libre.repwifiapp.activities.SettingsActivity$RepWifiFragment"
- android:title="Debug"
- android:summary="set debugging variables" />
+ <header
+ android:fragment="fil.libre.repwifiapp.activities.SettingsActivity$GeneralSettingFragment"
+ android:summary="set general options"
+ android:title="Options" />
+
+ <header
+ android:fragment="fil.libre.repwifiapp.activities.SettingsActivity$DebugSettingFragment"
+ android:summary="set advanced options and debug variables"
+ android:title="Advanced &amp; Debug" />
</preference-headers> \ No newline at end of file
diff --git a/app/src/fil/libre/repwifiapp/ActivityLauncher.java b/app/src/fil/libre/repwifiapp/ActivityLauncher.java
new file mode 100644
index 0000000..00a8d50
--- /dev/null
+++ b/app/src/fil/libre/repwifiapp/ActivityLauncher.java
@@ -0,0 +1,143 @@
+package fil.libre.repwifiapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.widget.Toast;
+import fil.libre.repwifiapp.activities.InputPasswordActivity;
+import fil.libre.repwifiapp.activities.InputSsidActivity;
+import fil.libre.repwifiapp.activities.LongTaskActivity;
+import fil.libre.repwifiapp.activities.NetworkDetailsActivity;
+import fil.libre.repwifiapp.activities.SelectNetworkActivity;
+import fil.libre.repwifiapp.activities.ShowStatusActivity;
+import fil.libre.repwifiapp.helpers.AccessPointInfo;
+import fil.libre.repwifiapp.helpers.ConnectionStatus;
+import fil.libre.repwifiapp.helpers.NetworkManager;
+
+public class ActivityLauncher {
+
+ // ------------- Activity Interaction -----------------
+ public static final String EXTRA_APINFO = "ExAPInfo";
+ public static final String EXTRA_APINFO_ARR = "ExAPInfoArr";
+ public static final String EXTRA_CONSTATUS = "ExConSts";
+ public static final String EXTRA_BOOLEAN = "ExBool";
+ public static final String EXTRA_REQCODE = "ExReqCode";
+ public static final String EXTRA_RESCAN = "ExRescan";
+ public static final String EXTRA_DELETE = "ExDelete";
+
+ public class RequestCode {
+
+ public static final int NONE = 0;
+ public static final int SELECT_CONN = 1;
+ public static final int PASS_INPUT = 2;
+ public static final int STATUS_SHOW = 3;
+ public static final int STATUS_GET = 4;
+ public static final int CONNECT = 5;
+ public static final int NETWORKS_GET = 6;
+ public static final int SELECT_DETAILS = 7;
+ public static final int DETAILS_SHOW = 8;
+ public static final int NETWORK_DELETE = 9;
+ public static final int CONNECT_HIDDEN = 10;
+ public static final int USB_ATTACHED = 11;
+ public static final int USB_DETACHED = 12;
+
+ }
+
+ // ----------------------------------------------------
+
+ private Activity currentContext;
+
+ public ActivityLauncher(Activity caller) {
+ this.currentContext = caller;
+ }
+
+ public void launchLongTaskActivityDebug() {
+
+ Intent intent = new Intent(currentContext, LongTaskActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.putExtra(ActivityLauncher.EXTRA_REQCODE, RequestCode.NONE);
+ currentContext.startActivityForResult(intent, RequestCode.NONE);
+ }
+
+ public void launchLongTaskActivityConnect(AccessPointInfo info) {
+
+ Intent intent = new Intent(currentContext, LongTaskActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.putExtra(ActivityLauncher.EXTRA_REQCODE, RequestCode.CONNECT);
+ intent.putExtra(ActivityLauncher.EXTRA_APINFO, info);
+ currentContext.startActivityForResult(intent, RequestCode.CONNECT);
+ }
+
+ public void launchLongTaskActivityScan() {
+
+ Intent intent = new Intent(currentContext, LongTaskActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.putExtra(ActivityLauncher.EXTRA_REQCODE, RequestCode.NETWORKS_GET);
+ currentContext.startActivityForResult(intent, RequestCode.NETWORKS_GET);
+ }
+
+ public void launchPasswordActivity(AccessPointInfo info) {
+
+ Intent intent = new Intent();
+ // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.setClass(currentContext, InputPasswordActivity.class);
+ intent.putExtra(EXTRA_APINFO, info);
+ currentContext.startActivityForResult(intent, RequestCode.PASS_INPUT);
+ }
+
+ public void launchStatusActivity(ConnectionStatus status) {
+
+ Intent intent = new Intent();
+ intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.putExtra(EXTRA_CONSTATUS, status);
+ intent.setClass(currentContext, ShowStatusActivity.class);
+ currentContext.startActivityForResult(intent, RequestCode.STATUS_SHOW);
+
+ }
+
+ public void launchSelectActivity(AccessPointInfo[] nets, boolean forConnection,
+ boolean fromStorage) {
+
+ if (fromStorage) {
+ NetworkManager manager = new NetworkManager(Commons.getNetworkStorageFile());
+ nets = manager.getKnownNetworks();
+
+ if (nets == null || nets.length == 0) {
+ Toast toast = Toast.makeText(currentContext, "No saved network", Toast.LENGTH_LONG);
+ toast.show();
+ return;
+ }
+ }
+
+ Intent intent = new Intent(currentContext, SelectNetworkActivity.class);
+ // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.putExtra(EXTRA_APINFO_ARR, nets);
+
+ if (forConnection) {
+ intent.putExtra(EXTRA_REQCODE, RequestCode.SELECT_CONN);
+ currentContext.startActivityForResult(intent, RequestCode.SELECT_CONN);
+ } else {
+ intent.putExtra(EXTRA_REQCODE, RequestCode.SELECT_DETAILS);
+ currentContext.startActivityForResult(intent, RequestCode.SELECT_DETAILS);
+ }
+
+ }
+
+ public void launchDetailsActivity(AccessPointInfo info) {
+
+ Intent intent = new Intent(currentContext, NetworkDetailsActivity.class);
+ // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.putExtra(EXTRA_APINFO, info);
+ currentContext.startActivityForResult(intent, RequestCode.DETAILS_SHOW);
+
+ }
+
+ public void launchInputSsidActivity() {
+
+ Intent intent = new Intent();
+ // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ intent.setClass(currentContext, InputSsidActivity.class);
+ currentContext.startActivityForResult(intent, RequestCode.CONNECT_HIDDEN);
+
+ }
+
+}
diff --git a/app/src/fil/libre/repwifiapp/Commons.java b/app/src/fil/libre/repwifiapp/Commons.java
index f938310..200381f 100644
--- a/app/src/fil/libre/repwifiapp/Commons.java
+++ b/app/src/fil/libre/repwifiapp/Commons.java
@@ -20,180 +20,329 @@
package fil.libre.repwifiapp;
+import android.app.AlertDialog;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
-
-import fil.libre.repwifiapp.helpers.Engine4p2;
+import fil.libre.repwifiapp.activities.MainActivity;
+import fil.libre.repwifiapp.helpers.ConnectionStatus;
import fil.libre.repwifiapp.helpers.Engine6p0;
import fil.libre.repwifiapp.helpers.IEngine;
import fil.libre.repwifiapp.helpers.NetworkManager;
import fil.libre.repwifiapp.helpers.Utils;
+public abstract class Commons {
+ private static Context currentContext;
-public abstract class Commons {
+ public Context getContext() {
+ return currentContext;
+ }
+
+ // ------------- Enviromnet 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 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 -----------------------
+ public static IEngine connectionEngine = null;
+ public static NetworkManager storage = null;
+ // ----------------------------------------------------
+
+ // ------------- Shared Resources ---------------------
+ public static int colorThemeDark;
+ public static int colorThemeLight;
+ public static int colorBlack;
+ public static String dns1Default = "";
+ public static String dns2Default = "";
+
+ private static final int NOTIFICATION_ID = 1;
+
+ public static void updateNotification(Context context) {
+
+ ConnectionStatus status = connectionEngine.getConnectionStatus();
+
+ Notification.Builder builder = new Notification.Builder(context);
+
+ Intent intent = new Intent(context, MainActivity.class);
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ builder.setContentIntent(pendingIntent);
+
+ int iconId = R.drawable.ic_stat_discon;
+ String msg = "RepWifi";
+ if (status != null) {
+ if (status.isConnected()) {
+ iconId = R.drawable.ic_stat_repwifi;
+ msg += " - " + status.SSID;
+ } else {
+ msg += " - " + status.status;
+ }
+
+ }
+
+ builder.setSmallIcon(iconId);
+
+ builder.setContentTitle(msg);
+ builder.setContentText("Touch to open.");
+
+ Notification n = builder.build();
+ n.flags |= Notification.FLAG_NO_CLEAR;
+
+ NotificationManager notificationManager = (NotificationManager) context
+ .getSystemService(Service.NOTIFICATION_SERVICE);
+ notificationManager.notify(NOTIFICATION_ID, n);
+
+ }
+
+ public static void showMessage(String msg) {
+ showMessage(msg, currentContext);
+ }
+
+ public static void showMessage(String msg, Context context) {
+
+ 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.setCancelable(false);
+ AlertDialog diag = dlgAlert.create();
+
+ diag.show();
+
+ }
+
+ public static void resetSettingsDefault(Context context, boolean silent) {
+
+ if (silent) {
+ Editor e = getSettings().edit();
+ e.clear();
+ e.commit();
+ } else {
+
+ String msg = context.getString(R.string.confirm_reset_settings);
+ AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context,
+ R.style.Theme_RepWifiDialogTheme);
+ dlgAlert.setMessage(msg);
+ dlgAlert.setPositiveButton(context.getString(android.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ resetSettingsDefault(null, true);
+ return;
+ }
+ });
+ dlgAlert.setNegativeButton(context.getString(android.R.string.cancel),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ return;
+ }
+ });
+
+ dlgAlert.setCancelable(false);
+ AlertDialog diag = dlgAlert.create();
+
+ diag.show();
+
+ return;
+ }
+
+ }
+
+ public static void killBackEnd(Context context, boolean silent) {
+
+ if (silent) {
+
+ if (connectionEngine != null) {
+ connectionEngine.killBackEndProcesses();
+ }
+
+ } else {
+
+ String msg = context.getString(R.string.confirm_kill_backend);
+ AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context,
+ R.style.Theme_RepWifiDialogTheme);
+ dlgAlert.setMessage(msg);
+ dlgAlert.setPositiveButton(context.getString(android.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ killBackEnd(null, true);
+ return;
+ }
+ });
+ dlgAlert.setNegativeButton(context.getString(android.R.string.cancel),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ return;
+ }
+ });
+
+ dlgAlert.setCancelable(false);
+ AlertDialog diag = dlgAlert.create();
+
+ diag.show();
+ return;
+
+ }
+
+ }
+
+ public static int getLogPriority() {
+
+ SharedPreferences sets = getSettings();
+ return Integer.parseInt(sets.getString("debug_priority", "3"));
+
+ }
+
+ public static boolean isProgbarEnabled() {
+ return getSettings().getBoolean("enable_progbar", true);
+ }
+
+ public static boolean isAutoConnectEnabled() {
+ return getSettings().getBoolean("enable_autoconnect", false);
+ }
+
+ public static String[] getDnss() {
+
+ String dns1 = getSettings().getString("dns1", dns1Default);
+ String dns2 = getSettings().getString("dns2", dns2Default);
+
+ if (dns1 == null || dns1.isEmpty()) {
+ return null;
+ }
+
+ return new String[] { dns1, dns2 };
+
+ }
+
+ public static SharedPreferences getSettings() {
+
+ return PreferenceManager.getDefaultSharedPreferences(currentContext);
+
+ }
+
+ // ----------------------------------------------------
+
+ // ----------------- 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) {
+
+ currentContext = context;
+
+ try {
+
+ colorThemeDark = currentContext.getResources().getColor(R.color.ThemeDark);
+ colorThemeLight = currentContext.getResources().getColor(R.color.ThemeLight);
+ colorBlack = currentContext.getResources().getColor(R.color.black);
+ APP_DATA_FOLDER = currentContext.getExternalFilesDir(null).getAbsolutePath();
+ dns1Default = currentContext.getResources().getString(R.string.dns1_default);
+ dns2Default = currentContext.getResources().getString(R.string.dns2_default);
+
+ initEngine();
+ initNetworkStorage();
+
+ return true;
+
+ } catch (Exception e) {
+ Utils.logError("Error initializing common resources.", e);
+ return false;
+ }
+ }
+
+ private static void initEngine() throws Exception {
+
+ connectionEngine = new Engine6p0();
+
+ 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!");
+ }
+
+ }
+
+ private static void initNetworkStorage() throws Exception {
+
+ Commons.storage = new NetworkManager(getNetworkStorageFile());
+
+ }
+ // --------------------------------------------------------------
- private static Context currentContext;
- public Context getContext(){
- return currentContext;
- }
-
- //------------- Enviromnet Constants ----------------------------------------
- public static final int EXCOD_ROOT_DISABLED = 255;
- public static final int EXCOD_ROOT_DENIED = 1;
- 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 -----------------------
- public static IEngine connectionEngine = null;
- public static NetworkManager storage = null;
- //----------------------------------------------------
-
-
- //------------- Shared Resources ---------------------
- public static int colorThemeDark;
- public static int colorThemeLight;
- public static int colorBlack;
-
- public static int getLogPriority(){
-
- SharedPreferences sets = getSettings();
- return Integer.parseInt(sets.getString("debug_priority","3"));
-
- }
-
- public static SharedPreferences getSettings(){
-
- return PreferenceManager.getDefaultSharedPreferences(currentContext);
-
- }
- //----------------------------------------------------
-
-
- //------------- Activity Interaction -----------------
- public static final String EXTRA_APINFO = "ExAPInfo";
- public static final String EXTRA_APINFO_ARR = "ExAPInfoArr";
- public static final String EXTRA_CONSTATUS = "ExConSts";
- public static final String EXTRA_BOOLEAN = "ExBool";
- public static final String EXTRA_REQCODE = "ExReqCode";
- public static final String EXTRA_RESCAN = "ExRescan";
- public static final String EXTRA_DELETE = "ExDelete";
-
- public class RequestCode{
-
- public static final int NONE = 0;
- public static final int SELECT_CONN = 1;
- public static final int PASS_INPUT = 2;
- public static final int STATUS_SHOW = 3;
- public static final int STATUS_GET = 4;
- public static final int CONNECT = 5;
- public static final int NETWORKS_GET = 6;
- public static final int SELECT_DETAILS = 7;
- public static final int DETAILS_SHOW = 8;
- public static final int NETWORK_DELETE = 9;
-
- }
- //----------------------------------------------------
-
-
- //----------------- 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 getScriptScan(){
- return APP_DATA_FOLDER + "/scan.sh";
- }
-
- public static String getScriptScanRes(){
- return APP_DATA_FOLDER + "/get_scan_results.sh";
- }
-
- public static String getScriptDhcpcd(){
- return APP_DATA_FOLDER + "/run_dhcpcd.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){
-
- currentContext = context;
-
- try {
-
- colorThemeDark = currentContext.getResources().getColor(R.color.ThemeDark);
- colorThemeLight = currentContext.getResources().getColor(R.color.ThemeLight);
- colorBlack = currentContext.getResources().getColor(R.color.black);
- APP_DATA_FOLDER = currentContext.getExternalFilesDir(null).getAbsolutePath();
-
- initEngine();
- initNetworkStorage();
-
- return true;
-
- } catch (Exception e) {
- Utils.logError("Error initializing common resources.",e);
- return false;
- }
- }
-
- private static void initEngine() throws Exception{
-
- String vers = android.os.Build.VERSION.RELEASE;
-
- if (vers.startsWith(Commons.v4p2)){
- Commons.connectionEngine = new Engine4p2();
- }
- else if(vers.startsWith(Commons.v6p0)){
- Commons.connectionEngine = new Engine6p0();
- }
- else{
- throw new Exception("System version not recognized!");
- }
-
- }
-
- private static void initNetworkStorage() throws Exception{
-
- Commons.storage = new NetworkManager(getNetworkStorageFile());
-
- }
- //--------------------------------------------------------------
-
-
}
diff --git a/app/src/fil/libre/repwifiapp/RepWifiIntentReceiver.java b/app/src/fil/libre/repwifiapp/RepWifiIntentReceiver.java
new file mode 100644
index 0000000..3f507ec
--- /dev/null
+++ b/app/src/fil/libre/repwifiapp/RepWifiIntentReceiver.java
@@ -0,0 +1,43 @@
+package fil.libre.repwifiapp;
+
+import fil.libre.repwifiapp.ActivityLauncher.RequestCode;
+import fil.libre.repwifiapp.activities.MainActivity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+public class RepWifiIntentReceiver extends BroadcastReceiver {
+
+ public void onReceive(Context context, Intent intent) {
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context
+ .getApplicationContext());
+ if (!prefs.getBoolean("enable_autostart", false)) {
+ Log.d("RepWifi", "autostart is false");
+ return;
+ }
+
+ Log.d("RepWifi", "Autostart is true");
+ String a = intent.getAction();
+
+ if (a.equals(Intent.ACTION_BOOT_COMPLETED) || a.equals(Intent.ACTION_REBOOT)) {
+ launchRepWifiMainActivity(context, RequestCode.NONE);
+ }
+
+ }
+
+ private void launchRepWifiMainActivity(Context context, int reqCode) {
+
+ Intent intent = new Intent(context, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ if (reqCode >= 0) {
+ intent.putExtra(ActivityLauncher.EXTRA_REQCODE, reqCode);
+ }
+ context.startActivity(intent);
+
+ }
+}
diff --git a/app/src/fil/libre/repwifiapp/activities/CreditsActivity.java b/app/src/fil/libre/repwifiapp/activities/CreditsActivity.java
index 4a0cb4c..80c15e6 100644
--- a/app/src/fil/libre/repwifiapp/activities/CreditsActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/CreditsActivity.java
@@ -21,7 +21,6 @@
package fil.libre.repwifiapp.activities;
import fil.libre.repwifiapp.R;
-
import android.os.Bundle;
import android.app.Activity;
import android.text.Html;
@@ -32,25 +31,24 @@ import android.widget.TextView;
public class CreditsActivity extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_credits);
-
- String content = getResources().getString(R.string.credit_text);
- TextView tv = (TextView)findViewById(R.id.txt_credits);
- tv.setMovementMethod(new ScrollingMovementMethod());
- tv.setText(Html.fromHtml(content));
- tv.setMovementMethod(LinkMovementMethod.getInstance());
-
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- //getMenuInflater().inflate(R.menu.activity_credits, menu);
- return true;
- }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_credits);
+
+ String content = getResources().getString(R.string.credit_text);
+ TextView tv = (TextView) findViewById(R.id.txt_credits);
+ tv.setMovementMethod(new ScrollingMovementMethod());
+ tv.setText(Html.fromHtml(content));
+ tv.setMovementMethod(LinkMovementMethod.getInstance());
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ // getMenuInflater().inflate(R.menu.activity_credits, menu);
+ return true;
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/activities/InputPasswordActivity.java b/app/src/fil/libre/repwifiapp/activities/InputPasswordActivity.java
index 239c082..6f04d1c 100644
--- a/app/src/fil/libre/repwifiapp/activities/InputPasswordActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/InputPasswordActivity.java
@@ -20,11 +20,10 @@
package fil.libre.repwifiapp.activities;
-
+import fil.libre.repwifiapp.ActivityLauncher;
import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
import fil.libre.repwifiapp.helpers.AccessPointInfo;
-
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@@ -37,79 +36,79 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;
+public class InputPasswordActivity extends Activity implements OnCheckedChangeListener {
+
+ AccessPointInfo apinfo = null;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ setContentView(R.layout.activity_input_password);
+
+ CheckBox c = (CheckBox) findViewById(R.id.chk_show_pass);
+ c.setOnCheckedChangeListener(this);
+
+ setTitle("Input password");
+
+ TextView v = (TextView) findViewById(R.id.txt_insert_pass);
+
+ // get the network to set password to:
+ this.apinfo = (AccessPointInfo) getIntent().getSerializableExtra(
+ ActivityLauncher.EXTRA_APINFO);
+ v.append(" " + apinfo.getSsid());
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // disable menu
+ return true;
+ }
+
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+
+ if (buttonView == findViewById(R.id.chk_show_pass)) {
+ chkShowPassChanged();
+ }
+
+ }
+
+ public void onBtnNextClick(View v) {
+
+ EditText txpass = (EditText) findViewById(R.id.txt_password);
+ String pass = txpass.getText().toString();
+
+ if (pass.length() == 0) {
+ Commons.showMessage("Password can't be empty!", this);
+ }
+
+ this.apinfo.setPassword(pass);
+
+ Intent intent = new Intent();
+ intent.putExtra(ActivityLauncher.EXTRA_APINFO, this.apinfo);
+ setResult(RESULT_OK, intent);
+
+ finish();
+
+ }
+
+ public void chkShowPassChanged() {
+
+ CheckBox c = (CheckBox) findViewById(R.id.chk_show_pass);
+ EditText txtPass = (EditText) findViewById(R.id.txt_password);
+
+ if (c.isChecked()) {
+ txtPass.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ txtPass.setSelection(txtPass.getText().length());
+
+ } else {
+ txtPass.setInputType(129);
+ txtPass.setSelection(txtPass.getText().length());
+
+ }
-public class InputPasswordActivity extends Activity implements OnCheckedChangeListener{
-
- AccessPointInfo apinfo = null;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- setContentView(R.layout.activity_input_password);
-
- CheckBox c = (CheckBox)findViewById(R.id.chk_show_pass);
- c.setOnCheckedChangeListener(this);
-
- setTitle("Input password");
-
- TextView v = (TextView)findViewById(R.id.txt_insert_pass);
-
- //get the network to set password to:
- this.apinfo = (AccessPointInfo)getIntent().getSerializableExtra(Commons.EXTRA_APINFO);
- v.append(" " + apinfo.getSSID());
-
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- //disable menu
- return true;
- }
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-
- if(buttonView == findViewById(R.id.chk_show_pass)){
- chkShowPassChanged();
- }
-
- }
-
- public void onBtnNextClick(View v){
-
- EditText txpass = (EditText)findViewById(R.id.txt_password);
- String pass = txpass.getText().toString();
-
- if (pass.length()>0){
-
- this.apinfo.setPassword(pass);
-
- Intent intent = new Intent();
- intent.putExtra(Commons.EXTRA_APINFO, this.apinfo);
- setResult(RESULT_OK, intent);
-
- finish();
-
- }
-
- }
-
- public void chkShowPassChanged(){
-
- CheckBox c = (CheckBox)findViewById(R.id.chk_show_pass);
- EditText txtPass = (EditText)findViewById(R.id.txt_password);
-
- if (c.isChecked()){
- txtPass.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
- txtPass.setSelection(txtPass.getText().length());
-
- }else{
- txtPass.setInputType(129);
- txtPass.setSelection(txtPass.getText().length());
-
- }
-
- }
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/activities/InputSsidActivity.java b/app/src/fil/libre/repwifiapp/activities/InputSsidActivity.java
new file mode 100644
index 0000000..4f3f74c
--- /dev/null
+++ b/app/src/fil/libre/repwifiapp/activities/InputSsidActivity.java
@@ -0,0 +1,115 @@
+//
+// Copyright 2017 Filippo "Fil" Bergamo <fil.bergamo@riseup.net>
+//
+// This file is part of RepWifiApp.
+//
+// RepWifiApp is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// RepWifiApp is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with RepWifiApp. If not, see <http://www.gnu.org/licenses/>.
+//
+// ********************************************************************
+
+package fil.libre.repwifiapp.activities;
+
+import fil.libre.repwifiapp.ActivityLauncher;
+import fil.libre.repwifiapp.ActivityLauncher.RequestCode;
+import fil.libre.repwifiapp.Commons;
+import fil.libre.repwifiapp.R;
+import fil.libre.repwifiapp.helpers.AccessPointInfo;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.View;
+import android.widget.EditText;
+
+public class InputSsidActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ setContentView(R.layout.activity_input_ssid);
+ setTitle("Insert Network's parameters");
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // disable menu
+ return true;
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+
+ if (intent == null) {
+ return;
+ }
+
+ if (resultCode != RESULT_OK) {
+ return;
+ }
+
+ switch (requestCode) {
+
+ case RequestCode.SELECT_CONN:
+
+ if (intent.hasExtra(ActivityLauncher.EXTRA_APINFO)) {
+ Bundle xtras = intent.getExtras();
+ AccessPointInfo i = (AccessPointInfo) xtras
+ .getSerializable(ActivityLauncher.EXTRA_APINFO);
+ returnAccessPointInfo(i);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ public void onBtnNextClick(View v) {
+
+ EditText txssid = (EditText) findViewById(R.id.txt_ssid);
+ String ssid = txssid.getText().toString();
+
+ if (ssid.length() == 0) {
+ Commons.showMessage("Network name can't be empty!", this);
+ return;
+ }
+
+ AccessPointInfo apinfo = new AccessPointInfo(ssid, Commons.BSSID_NOT_AVAILABLE, "WPA2",
+ null, null);
+
+ returnAccessPointInfo(apinfo);
+
+ }
+
+ public void onBtnSelectClick(View v) {
+ ActivityLauncher launcher = new ActivityLauncher(this);
+ launcher.launchSelectActivity(null, true, true);
+ }
+
+ private void returnAccessPointInfo(AccessPointInfo apinfo) {
+
+ apinfo.setHidden(true);
+
+ Intent intent = new Intent();
+ intent.putExtra(ActivityLauncher.EXTRA_APINFO, apinfo);
+ setResult(RESULT_OK, intent);
+
+ finish();
+ }
+
+} \ No newline at end of file
diff --git a/app/src/fil/libre/repwifiapp/activities/LongTaskActivity.java b/app/src/fil/libre/repwifiapp/activities/LongTaskActivity.java
index 63063d8..e0b4184 100644
--- a/app/src/fil/libre/repwifiapp/activities/LongTaskActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/LongTaskActivity.java
@@ -1,176 +1,184 @@
package fil.libre.repwifiapp.activities;
-
+import fil.libre.repwifiapp.ActivityLauncher;
import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
import fil.libre.repwifiapp.helpers.AccessPointInfo;
import fil.libre.repwifiapp.helpers.ConnectionStatus;
import fil.libre.repwifiapp.helpers.Utils;
-
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
+import android.view.View;
+import android.widget.ProgressBar;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;
public class LongTaskActivity extends Activity {
+ private class Task extends AsyncTask<Object, Object, Object> {
+
+ private int REQ_CODE;
+
+ public Task(int reqCode, Object input) {
+ this.REQ_CODE = reqCode;
+ }
+
+ @Override
+ protected Object doInBackground(Object... params) {
+
+ Object ret = null;
+
+ switch (this.REQ_CODE) {
+
+ case ActivityLauncher.RequestCode.CONNECT:
+
+ ret = Commons.connectionEngine.connect((AccessPointInfo) params[0]);
+ break;
+
+ case ActivityLauncher.RequestCode.NETWORKS_GET:
+
+ ret = Commons.connectionEngine.getAvailableNetworks();
+ break;
+
+ case ActivityLauncher.RequestCode.STATUS_GET:
+
+ ret = Commons.connectionEngine.getConnectionStatus();
+ break;
+
+ default:
- private class Task extends AsyncTask<Object, Object, Object>{
+ break;
- private int REQ_CODE;
+ }
- public Task(int reqCode, Object input){
- this.REQ_CODE = reqCode;
- }
+ return ret;
- @Override
- protected Object doInBackground(Object... params) {
+ }
- Object ret = null;
+ @Override
+ protected void onPostExecute(Object result) {
+ taskCompleted(result, this.REQ_CODE);
+ }
- switch (this.REQ_CODE){
+ }
- case Commons.RequestCode.CONNECT:
+ private AccessPointInfo currentNetwork = null;
- ret = Commons.connectionEngine.connect((AccessPointInfo)params[0]);
- break;
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_long_task);
- case Commons.RequestCode.NETWORKS_GET:
+ toggleProgbar(Commons.isProgbarEnabled());
+ startTask();
- ret = Commons.connectionEngine.getAvailableNetworks();
- break;
+ }
- case Commons.RequestCode.STATUS_GET:
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return true;
+ }
- ret = Commons.connectionEngine.getConnectionStatus();
- break;
+ private void startTask() {
- default:
+ // retrieve the request code:
+ Intent intent = getIntent();
+ if (!intent.hasExtra(ActivityLauncher.EXTRA_REQCODE)) {
+ this.setResult(RESULT_CANCELED);
+ finish();
+ }
- break;
+ Object input = null;
+ int reqCode = intent.getExtras().getInt(ActivityLauncher.EXTRA_REQCODE);
- }
+ switch (reqCode) {
- return ret;
+ case ActivityLauncher.RequestCode.CONNECT:
+ // Extract AccessPointInfo
+ input = intent.getExtras().getSerializable(ActivityLauncher.EXTRA_APINFO);
+ currentNetwork = (AccessPointInfo) input;
+ setTitle("Connecting to " + currentNetwork.getSsid() + "...");
+ setMessage("Connecting to " + currentNetwork.getSsid() + "...");
+ break;
- }
+ case ActivityLauncher.RequestCode.NETWORKS_GET:
+ setTitle("Scanning...");
+ setMessage("Scanning for Networks...");
- @Override
- protected void onPostExecute(Object result) {
- taskCompleted(result, this.REQ_CODE);
- }
+ case ActivityLauncher.RequestCode.STATUS_GET:
+ setTitle("Checking status...");
+ setMessage("Checking status...");
- }
+ default:
+ setTitle("Please wait...");
+ setMessage("Please wait...");
+ break;
+ }
- private AccessPointInfo currentNetwork = null;
-
- @Override
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_long_task);
-
- startTask();
+ Task task = new Task(reqCode, input);
+ task.execute(input);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu){
- return true;
- }
+ }
- private void startTask() {
+ private void taskCompleted(Object result, int reqCode) {
- //retrieve the request code:
- Intent intent = getIntent();
- if (! intent.hasExtra(Commons.EXTRA_REQCODE)){
- this.setResult(RESULT_CANCELED);
- finish();
- }
+ Utils.logDebug("Finished long task reqCode: " + reqCode, 1);
- Object input = null;
- int reqCode = intent.getExtras().getInt(Commons.EXTRA_REQCODE);
-
- switch (reqCode) {
-
- case Commons.RequestCode.CONNECT:
- setTitle("Connecting...");
- setMessage("Connecting...");
-
- //Extract AccessPointInfo
- input = intent.getExtras().getSerializable(Commons.EXTRA_APINFO);
- currentNetwork = (AccessPointInfo)input;
- break;
-
- case Commons.RequestCode.NETWORKS_GET:
- setTitle("Scanning...");
- setMessage("Scanning for Networks...");
-
- case Commons.RequestCode.STATUS_GET:
- setTitle("Checking status...");
- setMessage("Checking status...");
+ // Return to caller:
+ Intent intent = this.getIntent();
- default:
- setTitle("Please wait...");
- setMessage("Please wait...");
- break;
- }
-
- Task task = new Task(reqCode, input);
- task.execute(input);
+ switch (reqCode) {
- }
+ case ActivityLauncher.RequestCode.CONNECT:
- private void taskCompleted(Object result, int reqCode){
+ intent.putExtra(ActivityLauncher.EXTRA_BOOLEAN, (Boolean) result);
+ intent.putExtra(ActivityLauncher.EXTRA_APINFO, this.currentNetwork);
+ break;
- Utils.logDebug("Finished long task reqCode: "+ reqCode,1);
-
- //Return to caller:
- Intent intent = this.getIntent();
+ case ActivityLauncher.RequestCode.NETWORKS_GET:
+ intent.putExtra(ActivityLauncher.EXTRA_APINFO_ARR, (AccessPointInfo[]) result);
+ break;
- switch (reqCode){
+ case ActivityLauncher.RequestCode.STATUS_GET:
- case Commons.RequestCode.CONNECT:
+ intent.putExtra(ActivityLauncher.EXTRA_CONSTATUS, (ConnectionStatus) result);
+ break;
- intent.putExtra(Commons.EXTRA_BOOLEAN, (Boolean)result);
- intent.putExtra(Commons.EXTRA_APINFO, this.currentNetwork);
- break;
+ default:
- case Commons.RequestCode.NETWORKS_GET:
+ Utils.logDebug("Task terminating in null: ", 1);
+ break;
- intent.putExtra(Commons.EXTRA_APINFO_ARR, (AccessPointInfo[])result);
- break;
+ }
- case Commons.RequestCode.STATUS_GET:
+ this.setResult(RESULT_OK, intent);
+ finish();
- intent.putExtra(Commons.EXTRA_CONSTATUS, (ConnectionStatus)result);
- break;
+ }
- default:
+ private void setMessage(String msg) {
+ TextView txt = (TextView) findViewById(R.id.txt_msg);
+ txt.setText(msg);
+ }
- Utils.logDebug("Task terminating in null: ",1);
- break;
+ private void toggleProgbar(boolean enable) {
- }
+ ProgressBar pb = (ProgressBar) findViewById(R.id.progbar);
- this.setResult(RESULT_OK, intent);
- finish();
-
- }
-
-
- private void setMessage(String msg) {
- TextView txt = (TextView)findViewById(R.id.txt_msg);
- txt.setText(msg);
- }
-
- @Override
- public void onBackPressed() {
- //suppress back button
- }
+ if (enable) {
+ pb.setVisibility(View.VISIBLE);
+ } else {
+ pb.setVisibility(View.INVISIBLE);
+ }
+ }
+ @Override
+ public void onBackPressed() {
+ // suppress back button
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/activities/MainActivity.java b/app/src/fil/libre/repwifiapp/activities/MainActivity.java
index aa179fb..6e667bf 100644
--- a/app/src/fil/libre/repwifiapp/activities/MainActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/MainActivity.java
@@ -21,447 +21,447 @@
package fil.libre.repwifiapp.activities;
import java.io.IOException;
+import java.net.SocketException;
+import fil.libre.repwifiapp.ActivityLauncher;
import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
-import fil.libre.repwifiapp.Commons.RequestCode;
+import fil.libre.repwifiapp.ActivityLauncher.RequestCode;
import fil.libre.repwifiapp.helpers.AccessPointInfo;
import fil.libre.repwifiapp.helpers.ConnectionStatus;
import fil.libre.repwifiapp.helpers.NetworkManager;
import fil.libre.repwifiapp.helpers.RootCommand;
import fil.libre.repwifiapp.helpers.Utils;
import android.os.Bundle;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
-import android.view.Menu;
-import android.view.MenuItem;
+import android.hardware.usb.UsbManager;
+import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
-public class MainActivity extends Activity{
-
- private AlertDialog diag;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- if(! Commons.init(this)){
- Utils.logDebug("Failed to initialize Commons. Aborting.");
- finish();
- return;
- }
-
- setImage();
-
- //checkConnectionStatus();
-
- }
-
- @Override
- public void onStart(){
- super.onStart();
- Utils.logDebug("Main onStart()");
-
- checkConditions();
-
- ConnectionStatus status = Commons.connectionEngine.getConnectionStatus();
- if (status != null && status.isConnected()){
- Utils.logDebug("Main about to launch status activity...");
- launchStatusActivity(status);
- }
-
- Utils.logDebug("Main onStart() returning.");
-
- }
-
- @Override
- public void onStop(){
- super.onStop();
-
- if (this.diag != null){
- this.diag.dismiss();
- }
-
- }
-
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.activity_main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.menu_credits:
- launchCreditsActivity();
- break;
-
- case R.id.menu_config:
- launchSettingsActivity();
- break;
-
- default:
- break;
- }
-
- return true;
- }
-
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent intent){
-
- Utils.logDebug("Main onActivityResult(): ",1);
-
- if (intent == null){
- return;
- }
-
- if (resultCode != RESULT_OK){
- return;
- }
-
- AccessPointInfo i = null;
- if (intent.hasExtra(Commons.EXTRA_APINFO)){
- i = (AccessPointInfo)intent.getExtras().getSerializable(Commons.EXTRA_APINFO);
- }
-
- switch (requestCode) {
-
- case RequestCode.PASS_INPUT:
- handleResultSetPass(i);
- break;
-
- case RequestCode.SELECT_CONN:
- boolean rescan = intent.getExtras().getBoolean(Commons.EXTRA_RESCAN);
- handleResultSelect(i, rescan);
- break;
-
- case RequestCode.CONNECT:
- boolean conres = intent.getExtras().getBoolean(Commons.EXTRA_BOOLEAN);
- handleFinishedConnecting(conres, i);
- break;
-
- case RequestCode.STATUS_GET:
- ConnectionStatus status = (ConnectionStatus)intent.getExtras().getSerializable(Commons.EXTRA_CONSTATUS);
- handleResultGetStatus(status);
- break;
-
- case RequestCode.NETWORKS_GET:
- AccessPointInfo[] nets = (AccessPointInfo[])intent.getExtras().getSerializable(Commons.EXTRA_APINFO_ARR);
- launchSelectActivity(nets, true);
-
- case RequestCode.STATUS_SHOW:
- //do nothing
- break;
-
- case RequestCode.SELECT_DETAILS:
- launchDetailsActivity(i);
- break;
-
- case RequestCode.DETAILS_SHOW:
- boolean del = intent.getExtras().getBoolean(Commons.EXTRA_DELETE);
- if (del){ deleteNetwork(i); }
- break;
-
- default:
-
- break;
-
- }
-
-
- }
-
- private void setImage(){
-
- ImageView img = (ImageView)findViewById(R.id.img_logo);
-
- try {
- Drawable d = Drawable.createFromStream(getAssets().open("repwifi-logo-0.png"),null);
- img.setImageDrawable(d);
- } catch (IOException e) {
- Utils.logError("Error while loading logo image",e);
- }
-
- }
-
-
- private void handleResultSelect(AccessPointInfo i, boolean rescan){
-
- if (rescan){
-
- doScan();
-
- }else if (i != null){
-
- if (i.needsPassword()){
-
- //try to fetch network's password from storage
- AccessPointInfo fromStorage = Commons.storage.getSavedNetwork(i);
- if (fromStorage == null){
-
- launchPasswordActivity(i);
- return;
-
- }else{
- //use fetched network
- i = fromStorage;
- }
-
- }
-
- connectToNetwork(i);
- }
-
- }
-
- private void handleResultSetPass(AccessPointInfo i){
- connectToNetwork(i);
- }
-
- private void handleResultGetStatus(ConnectionStatus status){
- if (status != null && status.isConnected()){
- launchStatusActivity(status);
- }
- }
-
- private void handleFinishedConnecting(boolean connectionResult, AccessPointInfo info){
-
- if(connectionResult && info.needsPassword()){
-
- //Save network
- if (Commons.storage.save(info)){
- Toast toast2 = Toast.makeText(getApplicationContext(), "Network Saved!",Toast.LENGTH_LONG);
- toast2.show();
-
- }else {
- Toast toast2 = Toast.makeText(getApplicationContext(), "FAILED to save network!",Toast.LENGTH_LONG);
- toast2.show();
- }
-
- checkConnectionStatus();
-
- }else{
- //alert that connection failed
- Toast toast = Toast.makeText(getApplicationContext(), "FAILED to connect!", Toast.LENGTH_LONG);
- toast.show();
- }
- }
-
- private void launchPasswordActivity(AccessPointInfo info){
-
- Intent intent = new Intent();
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.setClass(getApplicationContext(), InputPasswordActivity.class);
- intent.putExtra(Commons.EXTRA_APINFO, info);
-
- startActivityForResult(intent, RequestCode.PASS_INPUT);
-
- }
-
- private void launchStatusActivity(ConnectionStatus status){
-
- Intent intent = new Intent();
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.putExtra(Commons.EXTRA_CONSTATUS, status);
- intent.setClass(getApplicationContext(), ShowStatusActivity.class);
- startActivityForResult(intent, RequestCode.STATUS_SHOW);
-
- }
-
- private void launchSelectActivity(AccessPointInfo[] nets,boolean forConnection){
-
- Intent intent = new Intent(this, SelectNetworkActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.putExtra(Commons.EXTRA_APINFO_ARR, nets);
-
- if (forConnection){
- intent.putExtra(Commons.EXTRA_REQCODE, RequestCode.SELECT_CONN);
- startActivityForResult(intent, RequestCode.SELECT_CONN);
- }
- else{
- intent.putExtra(Commons.EXTRA_REQCODE, RequestCode.SELECT_DETAILS);
- startActivityForResult(intent, RequestCode.SELECT_DETAILS);
- }
-
- }
-
- private void launchDetailsActivity(AccessPointInfo info){
-
- Intent intent = new Intent(this, NetworkDetailsActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.putExtra(Commons.EXTRA_APINFO, info);
- startActivityForResult(intent, RequestCode.DETAILS_SHOW);
-
- }
-
- private void launchCreditsActivity(){
- Intent intent = new Intent(this, CreditsActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- startActivityForResult(intent, RequestCode.NONE);
- }
-
- private void launchSettingsActivity() {
- Intent intent = new Intent(this, SettingsActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- startActivity(intent);
- }
-
- private void deleteNetwork(AccessPointInfo info){
-
- NetworkManager manager = new NetworkManager(Commons.getNetworkStorageFile());
- String msg = "";
- if (manager.remove(info)){
- msg = "Network info deleted!";
- }else{
- msg = "FAILED to delete network info!";
- }
-
- Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
- toast.show();
-
- }
-
- private void connectToNetwork(AccessPointInfo info){
-
- Intent intent = new Intent(this, LongTaskActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.putExtra(Commons.EXTRA_REQCODE, RequestCode.CONNECT);
- intent.putExtra(Commons.EXTRA_APINFO, info);
- startActivityForResult(intent, RequestCode.CONNECT);
-
- }
-
- private void checkConnectionStatus(){
-
- Intent intent = new Intent(this, LongTaskActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.putExtra(Commons.EXTRA_REQCODE, RequestCode.STATUS_GET);
- startActivityForResult(intent, RequestCode.STATUS_GET);
-
- }
-
- private boolean checkConditions(){
- return (checkRootEnabled() && checkInterface());
- }
-
- private boolean checkInterface(){
-
- boolean res = Commons.connectionEngine.isInterfaceAvailable(Commons.INTERFACE_NAME);
-
- if(res == false ){
- String msg = getResources().getString(R.string.msg_interface_not_found);
- showMessage(msg);
- }
-
- return res;
-
- }
-
- private boolean checkRootEnabled(){
-
- boolean result = false;
- String msg = "Unknown Root error";
- RootCommand su = new RootCommand(null);
-
- int excode = -1;
-
- try {
- excode = su.execute();
- } catch (Exception e) {
- Utils.logError("Error while trying to get first Super User access.",e);
- excode = -1;
- result = false;
- }
-
- switch (excode) {
- case 0:
- result = true;
- break;
-
- case Commons.EXCOD_ROOT_DENIED:
- result = false;
- msg = getResources().getString(R.string.msg_root_denied);
- break;
-
- case Commons.EXCOD_ROOT_DISABLED:
- result = false;
- msg = getResources().getString(R.string.msg_root_disabled);
- break;
-
- default:
- result = false;
- msg = "Unknown Root error.\nExit code " + excode;
- break;
- }
-
- if (!result){
- showMessage(msg);
- }
-
- return result;
-
- }
-
- private void doScan(){
-
- if (!checkConditions()){
- return;
- }
-
- Intent intent = new Intent(this, LongTaskActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.putExtra(Commons.EXTRA_REQCODE, RequestCode.NETWORKS_GET);
- startActivityForResult(intent, RequestCode.NETWORKS_GET);
-
- }
-
- public void btnScanClick(View v){
-
- doScan();
-
- }
-
- public void btnManageClick(View v){
-
- NetworkManager manager = new NetworkManager(Commons.getNetworkStorageFile());
- AccessPointInfo[] infos = manager.getKnownNetworks();
-
- if (infos == null || infos.length == 0){
- Toast toast = Toast.makeText(this, "No saved network", Toast.LENGTH_LONG);
- toast.show();
- }
- else{
- launchSelectActivity(infos, false);
- }
-
- }
-
- private void showMessage(String msg){
-
- AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
- dlgAlert.setMessage(msg);
- dlgAlert.setPositiveButton("OK",new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int whichButton) {
- return;
- }
- });
-
- dlgAlert.setCancelable(false);
- this.diag = dlgAlert.create();
- this.diag.show();
-
- }
-
+public class MainActivity extends MenuEnabledActivity {
+
+ private ActivityLauncher launcher = new ActivityLauncher(this);
+ private BroadcastReceiver detachReceiver;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ if (!Commons.init(this)) {
+ Utils.logDebug("Failed to initialize Commons. Aborting.");
+ finish();
+ return;
+ }
+
+ setImage();
+ setUsbDeviceMonitor();
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ Utils.logDebug("Main onStart()");
+
+ Commons.updateNotification(this);
+
+ if (handleIntent()) {
+ // app called for a specific intent.
+ // avoid any other task.
+ Log.d("RepWifi", "handleIntent returned true");
+ return;
+ }
+
+ checkConditions();
+
+ ConnectionStatus status = Commons.connectionEngine.getConnectionStatus();
+ if (status != null && status.isConnected()) {
+ Utils.logDebug("Main about to launch status activity...");
+ launcher.launchStatusActivity(status);
+ }
+
+ Utils.logDebug("Main onStart() returning.");
+
+ }
+
+ private boolean handleIntent() {
+
+ Intent i = getIntent();
+ if (i != null && i.hasExtra(ActivityLauncher.EXTRA_REQCODE)) {
+
+ switch (i.getIntExtra(ActivityLauncher.EXTRA_REQCODE, -1)) {
+
+ case RequestCode.NONE:
+ moveTaskToBack(true);
+
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+
+ } else {
+ // no intent to handle.
+ return false;
+ }
+
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+
+ Utils.logDebug("Main onActivityResult(): ", 1);
+
+ if (intent == null) {
+ return;
+ }
+
+ if (resultCode != RESULT_OK) {
+ return;
+ }
+
+ AccessPointInfo i = null;
+ if (intent.hasExtra(ActivityLauncher.EXTRA_APINFO)) {
+ Bundle xtras = intent.getExtras();
+ i = (AccessPointInfo) xtras.getSerializable(ActivityLauncher.EXTRA_APINFO);
+ }
+
+ switch (requestCode) {
+
+ case RequestCode.PASS_INPUT:
+ handleResultSetPass(i);
+ break;
+
+ case RequestCode.SELECT_CONN:
+ boolean rescan = intent.getExtras().getBoolean(ActivityLauncher.EXTRA_RESCAN);
+ handleResultSelect(i, rescan);
+ break;
+
+ case RequestCode.CONNECT:
+ boolean conres = intent.getExtras().getBoolean(ActivityLauncher.EXTRA_BOOLEAN);
+ handleFinishedConnecting(conres, i);
+ break;
+
+ case RequestCode.STATUS_GET:
+ ConnectionStatus status = (ConnectionStatus) intent.getExtras().getSerializable(
+ ActivityLauncher.EXTRA_CONSTATUS);
+ handleResultGetStatus(status);
+ break;
+
+ case RequestCode.NETWORKS_GET:
+ AccessPointInfo[] nets = (AccessPointInfo[]) intent.getExtras().getSerializable(
+ ActivityLauncher.EXTRA_APINFO_ARR);
+ launcher.launchSelectActivity(nets, true, false);
+
+ case RequestCode.STATUS_SHOW:
+ // do nothing
+ break;
+
+ case RequestCode.SELECT_DETAILS:
+ launcher.launchDetailsActivity(i);
+ break;
+
+ case RequestCode.DETAILS_SHOW:
+ boolean del = intent.getExtras().getBoolean(ActivityLauncher.EXTRA_DELETE);
+ if (del) {
+ deleteNetwork(i);
+ }
+ break;
+
+ case RequestCode.CONNECT_HIDDEN:
+
+ if (i != null) {
+ handleResultSelect(i, false);
+ }
+ break;
+
+ default:
+
+ break;
+
+ }
+
+ }
+
+ private void setImage() {
+
+ ImageView img = (ImageView) findViewById(R.id.img_logo);
+
+ try {
+ Drawable d = Drawable.createFromStream(getAssets().open("repwifi-logo-0.png"), null);
+ img.setImageDrawable(d);
+ } catch (IOException e) {
+ Utils.logError("Error while loading logo image", e);
+ }
+
+ }
+
+ private void setUsbDeviceMonitor() {
+ detachReceiver = new BroadcastReceiver() {
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
+ handleUsbEvent(true);
+ } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
+ handleUsbEvent(false);
+ }
+ }
+ };
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+ registerReceiver(detachReceiver, filter);
+
+ IntentFilter filt2 = new IntentFilter();
+ filt2.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+ registerReceiver(detachReceiver, filt2);
+ }
+
+ private boolean checkConditions() {
+ return (checkRootEnabled() && checkInterface(true));
+ }
+
+ private boolean checkInterface(boolean alert) {
+
+ boolean res = false;
+ String msg = "";
+
+ try {
+ res = Commons.connectionEngine.isInterfaceAvailable(Commons.INTERFACE_NAME);
+ } catch (SocketException e) {
+ Utils.logError("SocketException during isInterfaceAvailable()", e);
+ msg = "Error while retrieving interface list!";
+ res = false;
+ }
+
+ if (res == false && alert) {
+ msg = getResources().getString(R.string.msg_interface_not_found);
+ Commons.showMessage(msg, this);
+ }
+
+ return res;
+
+ }
+
+ private boolean checkRootEnabled() {
+
+ boolean result = false;
+ String msg = "Unknown Root error";
+ RootCommand su = new RootCommand(null);
+
+ int excode = -1;
+
+ try {
+ excode = su.execute();
+ } catch (Exception e) {
+ Utils.logError("Error while trying to get first Super User access.", e);
+ excode = -1;
+ result = false;
+ }
+
+ switch (excode) {
+ case 0:
+ result = true;
+ break;
+
+ case Commons.EXCOD_ROOT_DENIED:
+ result = false;
+ msg = getResources().getString(R.string.msg_root_denied);
+ break;
+
+ case Commons.EXCOD_ROOT_DISABLED:
+ result = false;
+ msg = getResources().getString(R.string.msg_root_disabled);
+ break;
+
+ default:
+ result = false;
+ msg = "Unknown Root error.\nExit code " + excode;
+ break;
+ }
+
+ if (!result) {
+ Commons.showMessage(msg, this);
+ }
+
+ return result;
+
+ }
+
+ private void handleResultSelect(AccessPointInfo i, boolean rescan) {
+
+ if (rescan) {
+
+ doScan();
+
+ } else if (i != null) {
+
+ if (i.needsPassword()) {
+
+ // try to fetch network's password from storage
+ AccessPointInfo fromStorage = Commons.storage.getSavedNetwork(i);
+ if (fromStorage == null) {
+
+ launcher.launchPasswordActivity(i);
+ return;
+
+ } else {
+ // use fetched network
+ i = fromStorage;
+ }
+
+ }
+
+ launcher.launchLongTaskActivityConnect(i);
+ }
+
+ }
+
+ private void handleResultSetPass(AccessPointInfo i) {
+ launcher.launchLongTaskActivityConnect(i);
+ }
+
+ private void handleResultGetStatus(ConnectionStatus status) {
+ if (status != null && status.isConnected()) {
+ launcher.launchStatusActivity(status);
+ }
+ }
+
+ private void handleFinishedConnecting(boolean connectionResult, AccessPointInfo info) {
+
+ if (connectionResult && info.needsPassword()) {
+
+ ConnectionStatus status = Commons.connectionEngine.getConnectionStatus();
+ if (status != null) {
+ // update APinfo with the right BSSID
+ info.setBssid(status.BSSID);
+ }
+
+ // Save network
+ if (Commons.storage.save(info)) {
+ Toast toast2 = Toast.makeText(getApplicationContext(), "Network Saved!",
+ Toast.LENGTH_LONG);
+ toast2.show();
+
+ } else {
+ Toast toast2 = Toast.makeText(getApplicationContext(), "FAILED to save network!",
+ Toast.LENGTH_LONG);
+ toast2.show();
+ }
+
+ // show status
+ launcher.launchStatusActivity(status);
+
+ } else {
+ // alert that connection failed
+ Toast toast = Toast.makeText(getApplicationContext(), "FAILED to connect!",
+ Toast.LENGTH_LONG);
+ toast.show();
+ }
+ }
+
+ private void deleteNetwork(AccessPointInfo info) {
+
+ NetworkManager manager = new NetworkManager(Commons.getNetworkStorageFile());
+ String msg = "";
+ if (manager.remove(info)) {
+ msg = "Network info deleted!";
+ } else {
+ msg = "FAILED to delete network info!";
+ }
+
+ Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
+ toast.show();
+
+ }
+
+ private void handleUsbEvent(boolean detached) {
+
+ if (detached && !checkInterface(false)) {
+ // device disconnected, update the status bar:
+ Commons.updateNotification(this);
+
+ } else if (Commons.isAutoConnectEnabled()) {
+
+ try {
+
+ // waits for a maximum of WAIT_ON_USB_ATTACHED milliseconds
+ // to let the interface being registered.
+ int msWaited = 0;
+ while (msWaited < Commons.WAIT_ON_USB_ATTACHED) {
+
+ Thread.sleep(100);
+ msWaited += 100;
+
+ if (checkInterface(false)) {
+ autoConnect();
+ return;
+ }
+ }
+
+ } catch (InterruptedException e) {
+ // ignores and exits;
+ return;
+ }
+
+ }
+
+ }
+
+ private void autoConnect() {
+
+ try {
+
+ AccessPointInfo[] nets = Commons.connectionEngine.getAvailableNetworks();
+ if (nets == null || nets.length == 0) {
+ return;
+ }
+
+ for (AccessPointInfo i : nets) {
+
+ if (Commons.storage.isKnown(i)) {
+ launcher.launchLongTaskActivityConnect(i);
+ return;
+ }
+
+ }
+
+ // if no network is known, shows available networks to the user.
+ launcher.launchSelectActivity(nets, true, false);
+
+ } catch (Exception e) {
+ Utils.logError("Error while autoconnecting", e);
+ Commons.showMessage("An error occured while trying to auto-connect", this);
+ }
+
+ }
+
+ private void doScan() {
+ if (checkConditions()) {
+ launcher.launchLongTaskActivityScan();
+ }
+ }
+
+ public void btnScanClick(View v) {
+ doScan();
+ }
+
+ public void btnHiddenClick(View v) {
+
+ if (checkConditions()) {
+ launcher.launchInputSsidActivity();
+ }
+
+ }
+
+ public void btnManageClick(View v) {
+ launcher.launchSelectActivity(null, false, true);
+ }
+
}
diff --git a/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java b/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java
new file mode 100644
index 0000000..0edfcf0
--- /dev/null
+++ b/app/src/fil/libre/repwifiapp/activities/MenuEnabledActivity.java
@@ -0,0 +1,49 @@
+package fil.libre.repwifiapp.activities;
+
+import fil.libre.repwifiapp.R;
+import android.app.Activity;
+import android.content.Intent;
+import android.view.Menu;
+import android.view.MenuItem;
+
+public class MenuEnabledActivity extends Activity {
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.activity_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle item selection
+ int id = item.getItemId();
+ switch (id) {
+ case R.id.menu_credits:
+ launchCreditsActivity();
+ break;
+
+ case R.id.menu_config:
+ launchSettingsActivity();
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+ }
+
+ private void launchCreditsActivity() {
+ Intent intent = new Intent(this, CreditsActivity.class);
+ // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ startActivity(intent);
+ }
+
+ private void launchSettingsActivity() {
+ Intent intent = new Intent(this, SettingsActivity.class);
+ // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ startActivity(intent);
+ }
+}
diff --git a/app/src/fil/libre/repwifiapp/activities/NetworkDetailsActivity.java b/app/src/fil/libre/repwifiapp/activities/NetworkDetailsActivity.java
index 6d7ed56..325d546 100644
--- a/app/src/fil/libre/repwifiapp/activities/NetworkDetailsActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/NetworkDetailsActivity.java
@@ -21,12 +21,9 @@
package fil.libre.repwifiapp.activities;
import java.util.Date;
-
-
-import fil.libre.repwifiapp.Commons;
+import fil.libre.repwifiapp.ActivityLauncher;
import fil.libre.repwifiapp.R;
import fil.libre.repwifiapp.helpers.AccessPointInfo;
-
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
@@ -42,111 +39,112 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
public class NetworkDetailsActivity extends Activity implements OnCheckedChangeListener {
- private AccessPointInfo currentNetwor;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_network_details);
-
- CheckBox c = (CheckBox)findViewById(R.id.chk_show_pass_details);
- c.setOnCheckedChangeListener(this);
-
- Intent intent = getIntent();
- if (! intent.hasExtra(Commons.EXTRA_APINFO)){
- this.setResult(RESULT_CANCELED);
- this.finish();
- return;
- }
-
- this.currentNetwor = (AccessPointInfo)intent.getExtras().getSerializable(Commons.EXTRA_APINFO);
- if (this.currentNetwor == null){
- this.setResult(RESULT_CANCELED);
- this.finish();
- return;
- }
-
- loadNetwork(false);
-
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- //getMenuInflater().inflate(R.menu.activity_manage_networks, menu);
- return true;
- }
-
- private void loadNetwork(boolean showPassword){
-
- setTitle(this.currentNetwor.getSSID());
-
- TextView v = (TextView)findViewById(R.id.txt_net_details);
- v.setText("SSID: " + this.currentNetwor.getSSID());
- v.append("\nBSSID: " + this.currentNetwor.getBSSID());
-
- long lastused = this.currentNetwor.getLastTimeUsed();
-
- if (lastused > 0){
- Date ts = new Date(lastused);
- String formstring = "dd-MMM-yyyy kk:mm:ss";
- v.append("\nLast Used: " + DateFormat.format(formstring, ts));
- }
-
- if (showPassword){
- v.append("\n\nPassword:\n" + this.currentNetwor.getPassword());
- }
- else{
- v.append("\n\n\n");
- }
-
- }
-
- public void btnDeleteClick(View v){
-
- String msg = getResources().getString(R.string.msg_confirm_delete_network);
- String yes = getResources().getString(R.string.yes);
- String no = getResources().getString(R.string.no);
-
- AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
- dlgAlert.setMessage(msg);
- dlgAlert.setPositiveButton(yes,new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int whichButton) {
- returnResult(true);
- }
- });
- dlgAlert.setNegativeButton(no,new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int whichButton) {
- return;
- }
- });
-
- dlgAlert.setCancelable(true);
- dlgAlert.create().show();
-
- }
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-
- if (buttonView == findViewById(R.id.chk_show_pass_details)){
- loadNetwork(isChecked);
- }
-
- }
-
- private void returnResult(boolean delete){
-
- Intent i = new Intent();
- i.putExtra(Commons.EXTRA_DELETE, delete);
- i.putExtra(Commons.EXTRA_APINFO, this.currentNetwor);
- this.setResult(RESULT_OK,i);
- finish();
-
- }
-
-
-
+ private AccessPointInfo currentNetwork;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_network_details);
+
+ CheckBox c = (CheckBox) findViewById(R.id.chk_show_pass_details);
+ c.setOnCheckedChangeListener(this);
+
+ Intent intent = getIntent();
+ if (!intent.hasExtra(ActivityLauncher.EXTRA_APINFO)) {
+ this.setResult(RESULT_CANCELED);
+ this.finish();
+ return;
+ }
+
+ this.currentNetwork = (AccessPointInfo) intent.getExtras().getSerializable(
+ ActivityLauncher.EXTRA_APINFO);
+ if (this.currentNetwork == null) {
+ this.setResult(RESULT_CANCELED);
+ this.finish();
+ return;
+ }
+
+ loadNetwork(false);
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ // getMenuInflater().inflate(R.menu.activity_manage_networks, menu);
+ return true;
+ }
+
+ private void loadNetwork(boolean showPassword) {
+
+ setTitle(this.currentNetwork.getSsid());
+
+ TextView v = (TextView) findViewById(R.id.txt_net_details);
+ v.setText("SSID: " + this.currentNetwork.getSsid());
+ v.append("\nBSSID: " + this.currentNetwork.getBssid());
+
+ long lastused = this.currentNetwork.getLastTimeUsed();
+
+ if (lastused > 0) {
+ Date ts = new Date(lastused);
+ String formstring = "dd-MMM-yyyy kk:mm:ss";
+ v.append("\nLast Used: " + DateFormat.format(formstring, ts));
+ }
+
+ if (showPassword) {
+ v.append("\n\nPassword:\n" + this.currentNetwork.getPassword());
+ } else {
+ v.append("\n\n\n");
+ }
+
+ }
+
+ public void btnDeleteClick(View v) {
+
+ String msg = getResources().getString(R.string.msg_confirm_delete_network);
+ String yes = getResources().getString(R.string.yes);
+ String no = getResources().getString(R.string.no);
+
+ AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this,
+ R.style.Theme_RepWifiDialogTheme);
+ dlgAlert.setMessage(msg);
+ dlgAlert.setPositiveButton(yes, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ returnResult(true);
+ }
+ });
+ dlgAlert.setNegativeButton(no, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ return;
+ }
+ });
+
+ dlgAlert.setCancelable(true);
+ dlgAlert.create().show();
+
+ }
+
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+
+ if (buttonView == findViewById(R.id.chk_show_pass_details)) {
+ loadNetwork(isChecked);
+ }
+
+ }
+
+ private void returnResult(boolean delete) {
+
+ Intent i = new Intent();
+ i.putExtra(ActivityLauncher.EXTRA_DELETE, delete);
+ i.putExtra(ActivityLauncher.EXTRA_APINFO, this.currentNetwork);
+ this.setResult(RESULT_OK, i);
+ finish();
+
+ }
+
}
diff --git a/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java b/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java
index 9b07246..341fb68 100644
--- a/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/SelectNetworkActivity.java
@@ -20,6 +20,7 @@
package fil.libre.repwifiapp.activities;
+import fil.libre.repwifiapp.ActivityLauncher;
import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
import fil.libre.repwifiapp.helpers.AccessPointInfo;
@@ -40,178 +41,180 @@ import android.widget.TextView;
public class SelectNetworkActivity extends Activity implements OnClickListener {
- private AccessPointInfo[] aps;
-
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_select_network);
-
- setTitle("Select network");
-
- getNetworks();
-
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- //Suppress menu button
- return true;
- }
-
- private void writeOut(String msg) {
-
- TextView v = (TextView)findViewById(R.id.txt_selnets);
- v.setText(msg);
-
- }
-
- private void getNetworks(){
-
- Intent intent = getIntent();
- if(! intent.hasExtra(Commons.EXTRA_APINFO_ARR)){
- this.setResult(RESULT_CANCELED);
- finish();
- return;
- }
- AccessPointInfo[] nets = (AccessPointInfo[])intent.getExtras().getSerializable(Commons.EXTRA_APINFO_ARR);
- if (nets == null){
- this.setResult(RESULT_CANCELED);
- finish();
- return;
- }
-
- int reqCode = intent.getExtras().getInt(Commons.EXTRA_REQCODE);
-
- this.aps = nets;
-
- if (reqCode == Commons.RequestCode.SELECT_CONN){
- showNetworksForConnection(nets);
- }
- else{
- showNetworksForManagement(nets);
- }
-
- }
-
- public void btnScanClick(View v){
- returnResults(null, true);
- }
-
- @Override
+ private AccessPointInfo[] aps;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_select_network);
+
+ setTitle("Select network");
+
+ getNetworks();
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Suppress menu button
+ return true;
+ }
+
+ private void writeOut(String msg) {
+
+ TextView v = (TextView) findViewById(R.id.txt_selnets);
+ v.setText(msg);
+
+ }
+
+ private void getNetworks() {
+
+ Intent intent = getIntent();
+ if (!intent.hasExtra(ActivityLauncher.EXTRA_APINFO_ARR)) {
+ this.setResult(RESULT_CANCELED);
+ finish();
+ return;
+ }
+ AccessPointInfo[] nets = (AccessPointInfo[]) intent.getExtras().getSerializable(
+ ActivityLauncher.EXTRA_APINFO_ARR);
+ if (nets == null) {
+ this.setResult(RESULT_CANCELED);
+ finish();
+ return;
+ }
+
+ int reqCode = intent.getExtras().getInt(ActivityLauncher.EXTRA_REQCODE);
+
+ this.aps = nets;
+
+ if (reqCode == ActivityLauncher.RequestCode.SELECT_CONN) {
+ showNetworksForConnection(nets);
+ } else {
+ showNetworksForManagement(nets);
+ }
+
+ }
+
+ public void btnScanClick(View v) {
+ returnResults(null, true);
+ }
+
+ @Override
public void onClick(View v) {
- if (v instanceof NetworkButton){
- networkNameClick((NetworkButton)v);
- }
+ if (v instanceof NetworkButton) {
+ networkNameClick((NetworkButton) v);
+ }
+
+ }
+
+ public void networkNameClick(NetworkButton b) {
+
+ for (AccessPointInfo i : this.aps) {
+
+ if (i.getBssid().equals(b.getNetworkBSSID())) {
+
+ returnResults(i, false);
+
+ }
+
+ }
+ }
+
+ private void returnResults(AccessPointInfo i, boolean rescan) {
+
+ Intent intent = new Intent();
+ intent.putExtra(ActivityLauncher.EXTRA_APINFO, i);
+ intent.putExtra(ActivityLauncher.EXTRA_RESCAN, rescan);
+ setResult(RESULT_OK, intent);
+ finish();
+
+ }
+
+ private void showNetworksForConnection(AccessPointInfo[] info) {
+
+ if (info == null) {
+ Utils.logError("Unable to retrieve network list!");
+ writeOut("Unable to retrieve network list!");
+ return;
+ }
+
+ if (info.length == 0) {
+ writeOut("No network found.");
+ toggleBtnRescan(true);
+ return;
+ }
+
+ writeOut("Select the network you want to connect to:");
+ toggleBtnRescan(false);
+
+ for (AccessPointInfo i : info) {
+
+ addButtonForNetwork(i);
+
+ }
+
+ }
+
+ private void showNetworksForManagement(AccessPointInfo[] info) {
+
+ if (info == null || info.length == 0) {
+ return;
+ }
+
+ writeOut("Select network info to manage:");
+ toggleBtnRescan(false);
+
+ for (AccessPointInfo i : info) {
+
+ addButtonForNetwork(i);
+
+ }
+
+ }
+
+ private void toggleBtnRescan(boolean enable) {
+
+ Button b = (Button) findViewById(R.id.btn_rescan);
+ if (enable) {
+ b.setVisibility(View.VISIBLE);
+ } else {
+ b.setVisibility(View.INVISIBLE);
+ }
+ }
+
+ private void addButtonForNetwork(AccessPointInfo info) {
+
+ TableLayout s = (TableLayout) findViewById(R.id.table_networks);
+ TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
+ LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+ TableRow row = new TableRow(this);
+ TableRow.LayoutParams rowParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
+ LayoutParams.WRAP_CONTENT);
+ rowParams.gravity = Gravity.FILL_HORIZONTAL;
+ row.setPadding(10, 10, 10, 10);
+ row.setLayoutParams(rowParams);
+ row.setGravity(Gravity.FILL_HORIZONTAL);
+ row.setLayoutParams(rowParams);
+
+ NetworkButton button = new NetworkButton(this, info.getBssid());
+
+ TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
+ LayoutParams.WRAP_CONTENT);
+ button.setLayoutParams(params);
+ button.setBackground(getResources().getDrawable(R.drawable.repwifi_button));
+ button.setTextColor(Commons.colorThemeLight);
+ button.setTextSize(20);
+ button.setPadding(25, 10, 25, 10);
+ button.setGravity(Gravity.CENTER_HORIZONTAL);
+ button.setText(info.getSsid(20));
+ button.setOnClickListener(this);
+
+ row.addView(button, params);
+ row.setGravity(Gravity.CENTER_HORIZONTAL);
+ s.addView(row, tableParams);
+ s.setGravity(Gravity.FILL_HORIZONTAL);
}
-
- public void networkNameClick(NetworkButton b){
-
- for(AccessPointInfo i : this.aps){
-
- if (i.getBSSID().equals(b.getNetworkBSSID())){
-
- returnResults(i,false);
-
- }
-
- }
- }
-
- private void returnResults(AccessPointInfo i, boolean rescan){
-
- Intent intent = new Intent();
- intent.putExtra(Commons.EXTRA_APINFO, i);
- intent.putExtra(Commons.EXTRA_RESCAN, rescan);
- setResult(RESULT_OK, intent);
- finish();
-
- }
-
- private void showNetworksForConnection(AccessPointInfo[] info) {
-
- if (info == null){
- Utils.logError("Unable to retrieve network list!");
- writeOut("Unable to retrieve network list!");
- return;
- }
-
- if (info.length == 0){
- writeOut("No network found.");
- toggleBtnRescan(true);
- return;
- }
-
- writeOut("Select the network you want to connect to:");
- toggleBtnRescan(false);
-
- for (AccessPointInfo i : info){
-
- addButtonForNetwork(i);
-
- }
-
- }
-
- private void showNetworksForManagement(AccessPointInfo[] info){
-
- if (info == null || info.length == 0){
- return;
- }
-
- writeOut("Select network info to manage:");
- toggleBtnRescan(false);
-
- for (AccessPointInfo i : info){
-
- addButtonForNetwork(i);
-
- }
-
- }
-
- private void toggleBtnRescan(boolean enable) {
-
- Button b = (Button)findViewById(R.id.btn_rescan);
- if (enable){
- b.setVisibility(View.VISIBLE);
- }
- else{
- b.setVisibility(View.INVISIBLE);
- }
- }
-
- private void addButtonForNetwork(AccessPointInfo info){
-
- TableLayout s = (TableLayout)findViewById(R.id.table_networks);
- TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- TableRow row = new TableRow(this);
- TableRow.LayoutParams rowParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- rowParams.gravity = Gravity.FILL_HORIZONTAL;
- row.setPadding(10, 10, 10, 10);
- row.setLayoutParams(rowParams);
- row.setGravity(Gravity.FILL_HORIZONTAL);
- row.setLayoutParams(rowParams);
-
- NetworkButton button = new NetworkButton(this, info.getBSSID());
-
- TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- button.setLayoutParams(params);
- button.setBackgroundColor(Commons.colorThemeDark);
- button.setTextColor(Commons.colorThemeLight);
- button.setTextSize(20);
- button.setPadding(10, 10, 10, 10);
- button.setGravity(Gravity.CENTER_HORIZONTAL);
- button.setText(info.getSSID());
- button.setOnClickListener(this);
-
- row.addView(button,params);
- s.addView(row,tableParams);
- s.setGravity(Gravity.FILL_HORIZONTAL);
-
- }
}
diff --git a/app/src/fil/libre/repwifiapp/activities/SettingsActivity.java b/app/src/fil/libre/repwifiapp/activities/SettingsActivity.java
index 90629e3..6f14748 100644
--- a/app/src/fil/libre/repwifiapp/activities/SettingsActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/SettingsActivity.java
@@ -1,35 +1,101 @@
package fil.libre.repwifiapp.activities;
+import org.apache.http.conn.util.InetAddressUtils;
import java.util.List;
-
+import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
-
public class SettingsActivity extends PreferenceActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- }
-
- @Override
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(R.style.Theme_SettingsTheme);
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.settings_headers, target);
}
-
-
- public static class RepWifiFragment extends PreferenceFragment {
-
- @Override
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.settings);
- }
-
- }
+
+ public static class DebugSettingFragment extends PreferenceFragment {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.debug_settings);
+
+ setConfirmKillBackend();
+
+ }
+
+ private void setConfirmKillBackend() {
+
+ Preference pref = getPreferenceScreen().findPreference("pref_kill_backend");
+ pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference p) {
+ Commons.killBackEnd(getActivity(), false);
+ return true;
+ }
+ });
+
+ }
+
+ }
+
+ public static class GeneralSettingFragment extends PreferenceFragment {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.general_settings);
+
+ setValidationListener("dns1");
+ setValidationListener("dns2");
+ setConfirmRestore();
+
+ }
+
+ private void setValidationListener(String prefName) {
+ EditTextPreference edit_Pref = (EditTextPreference) getPreferenceScreen()
+ .findPreference(prefName);
+
+ edit_Pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ // put validation here..
+ if (((String) newValue).isEmpty()
+ || InetAddressUtils.isIPv4Address((String) newValue)) {
+ return true;
+ } else {
+ Commons.showMessage("ERROR:\nWrong IP format!", getActivity());
+ return false;
+ }
+ }
+ });
+ }
+
+ private void setConfirmRestore() {
+
+ Preference pref = getPreferenceScreen().findPreference("pref_restore_default");
+ pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference p) {
+ Commons.resetSettingsDefault(getActivity(), false);
+ return true;
+ }
+ });
+
+ }
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/activities/ShowStatusActivity.java b/app/src/fil/libre/repwifiapp/activities/ShowStatusActivity.java
index 2674737..0fb8992 100644
--- a/app/src/fil/libre/repwifiapp/activities/ShowStatusActivity.java
+++ b/app/src/fil/libre/repwifiapp/activities/ShowStatusActivity.java
@@ -18,114 +18,113 @@
//
// ********************************************************************
-
-
package fil.libre.repwifiapp.activities;
-
+import fil.libre.repwifiapp.ActivityLauncher;
import fil.libre.repwifiapp.Commons;
import fil.libre.repwifiapp.R;
import fil.libre.repwifiapp.helpers.ConnectionStatus;
import fil.libre.repwifiapp.helpers.Utils;
-
import android.os.Bundle;
-import android.app.Activity;
-import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
-public class ShowStatusActivity extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_show_status);
- showStatus();
-
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- //getMenuInflater().inflate(R.menu.activity_show_status, menu);
- return true;
- }
-
- @Override
- public void onRestart(){
- super.onRestart();
- showStatus();
- }
-
- private void setMessage(String msg){
- TextView view = (TextView)findViewById(R.id.txt_status);
- view.setText(msg);
- }
-
- private void showStatus(){
-
- ConnectionStatus status = Commons.connectionEngine.getConnectionStatus();
- if (status == null){
- this.finish();
-
- }else if (status.isConnected()){
- Utils.logDebug("StatusActivity isConnected,showing buttons");
- setMessage("Connected to " + status.SSID + "\n\n" + "IP Address: " + status.IP + "\n");
- toggleBtnDisconnect(true);
-
-
- }else{
- Utils.logDebug("StatusActivity status Else");
- setMessage("Status:\n" + status.status);
- toggleBtnDisconnect(false);
-
- }
- }
-
- private void toggleBtnDisconnect(boolean enable){
-
- Button b = (Button)findViewById(R.id.btn_disconnect);
- Button bk = (Button)findViewById(R.id.btn_back);
- b.setEnabled(enable);
- bk.setEnabled(! enable);
-
- if (enable){
- b.setVisibility(View.VISIBLE);
- bk.setVisibility(View.INVISIBLE);
- }else{
- b.setVisibility(View.INVISIBLE);
- bk.setVisibility(View.VISIBLE);
- }
-
- }
-
- public void onBtnDisconnectClick(View v){
-
- boolean res = Commons.connectionEngine.disconnect();
- String msg = "";
- if (res){
- msg = "Disconnected.";
- }
- else{
- msg = "FAILED to disconnect!";
- }
-
- Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
- toast.show();
-
- showStatus();
-
- }
-
- public void onBtnMainClick(View v){
- finish();
- }
-
- @Override
- public void onBackPressed() {
- moveTaskToBack(true);
- }
-
+public class ShowStatusActivity extends MenuEnabledActivity {
+
+ private ConnectionStatus status;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_show_status);
+
+ if (getIntent().hasExtra(ActivityLauncher.EXTRA_CONSTATUS)) {
+ this.status = (ConnectionStatus) getIntent().getSerializableExtra(
+ ActivityLauncher.EXTRA_CONSTATUS);
+ }
+
+ showStatus(false);
+
+ }
+
+ @Override
+ public void onRestart() {
+ super.onRestart();
+ showStatus(true);
+ }
+
+ private void setMessage(String msg) {
+ TextView view = (TextView) findViewById(R.id.txt_status);
+ view.setText(msg);
+ }
+
+ private void showStatus(boolean refresh) {
+
+ if (refresh || status == null) {
+ this.status = Commons.connectionEngine.getConnectionStatus();
+ }
+
+ if (status == null) {
+ this.finish();
+
+ } else if (this.status.isConnected()) {
+ Utils.logDebug("StatusActivity isConnected,showing buttons");
+ setMessage("Connected to " + status.SSID + "\n\n" + "IP Address: " + status.IP + "\n");
+ toggleBtnDisconnect(true);
+
+ } else {
+ Utils.logDebug("StatusActivity status Else");
+ setMessage("Status:\n" + status.status);
+ toggleBtnDisconnect(false);
+ }
+
+ Commons.updateNotification(this);
+
+ }
+
+ private void toggleBtnDisconnect(boolean enable) {
+
+ Button b = (Button) findViewById(R.id.btn_disconnect);
+ Button bk = (Button) findViewById(R.id.btn_back);
+ b.setEnabled(enable);
+ bk.setEnabled(!enable);
+
+ if (enable) {
+ b.setVisibility(View.VISIBLE);
+ bk.setVisibility(View.INVISIBLE);
+ } else {
+ b.setVisibility(View.INVISIBLE);
+ bk.setVisibility(View.VISIBLE);
+ }
+
+ }
+
+ public void onBtnDisconnectClick(View v) {
+
+ boolean res = Commons.connectionEngine.disconnect();
+ String msg = "";
+ if (res) {
+ msg = "Disconnected.";
+ } else {
+ msg = "FAILED to disconnect!";
+ }
+
+ Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
+ toast.show();
+
+ showStatus(true);
+
+ }
+
+ public void onBtnMainClick(View v) {
+ finish();
+ }
+
+ @Override
+ public void onBackPressed() {
+ moveTaskToBack(true);
+ }
+
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java b/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java
index 65c8b24..d6e2eb3 100644
--- a/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java
+++ b/app/src/fil/libre/repwifiapp/helpers/AccessPointInfo.java
@@ -24,173 +24,202 @@ import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-
import fil.libre.repwifiapp.Commons;
+public class AccessPointInfo implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private static final int MAX_SSID_LENGTH = 32;
+
+ private String _ssid;
+ private String _bssid;
+ private String _auth;
+ private String _level;
+ private String _freq;
+ private String _password;
+ private boolean _isHidden = false;
+ private long _lastTimeUsed;
+
+ public AccessPointInfo(String ssid, String bssid, String authType, String level, String freq) {
+
+ this._ssid = ssid;
+ this._bssid = bssid;
+ this._auth = authType;
+ this._level = level;
+ this._freq = freq;
+
+ }
+
+ public String getSsid() {
+ return this._ssid;
+ }
+
+ public String getSsid(int maxLength) {
+ String txt = getSsid();
+ if (maxLength > 4 && txt.length() > maxLength) {
+ txt = txt.substring(0, maxLength - 3) + "...";
+ }
+ return txt;
+ }
+
+ public void setHidden(boolean hidden) {
+ this._isHidden = hidden;
+ }
+
+ public boolean isHidden() {
+ return this._isHidden;
+ }
+
+ public String getBssid() {
+ return this._bssid;
+ }
+
+ public void setBssid(String bssid) {
+ this._bssid = bssid;
+ }
+
+ public String getAuthType() {
+ return this._auth;
+ }
+
+ public String getSignlalStrength() {
+ return this._level;
+ }
+
+ public String getFrequency() {
+ return this._freq;
+ }
+
+ public long getLastTimeUsed() {
+ return this._lastTimeUsed;
+ }
+
+ public void setLastTimeUsed(long timeStampInMillis) {
+ this._lastTimeUsed = timeStampInMillis;
+ }
+
+ public boolean isOlderThan(int days) {
+
+ if (this._lastTimeUsed == 0) {
+ return false;
+ }
+
+ long timeDiff = System.currentTimeMillis() - this._lastTimeUsed;
+ long spanMillis = Utils.daysToMilliseconds(days);
+
+ if (timeDiff > spanMillis) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ public String getPassword() {
+ return this._password;
+ }
+
+ public void setPassword(String password) {
+ this._password = password;
+ }
+
+ public boolean needsPassword() {
+
+ if ((this._auth == null) || (this._auth.equals(""))) {
+ // TODO
+ // check if default behavior should be with or without password,
+ // when no auth info is available.
+ return false;
+ }
+
+ if (this._auth.contains("WPA2") || this._auth.contains("WPA")) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ protected static AccessPointInfo parseLine(String line) {
+
+ try {
+
+ String[] params = line.split("\t");
+ if (params.length != 5) {
+ return null;
+ }
+
+ String bssid = params[0];
+ String freq = params[1];
+ String level = params[2];
+ String auth = params[3];
+ String ssid = params[4];
+
+ if (ssid.length() == 0 || ssid.length() > MAX_SSID_LENGTH) {
+ // invalid SSID.
+ return null;
+ }
+
+ AccessPointInfo info = new AccessPointInfo(ssid, bssid, auth, level, freq);
+ return info;
+
+ } catch (Exception e) {
+ Utils.logError("Error while parsing line: " + line, e);
+ return null;
+ }
+
+ }
+
+ public static AccessPointInfo[] parseScanResult(String scanResultFile) {
+
+ try {
+
+ Utils.logDebug("AccesPointInfo trying to parse file: " + scanResultFile);
+
+ File f = new File(scanResultFile);
+ if (!f.exists()) {
+ Utils.logError("AccessPointInfo.parseScanResult(): The provided scan result file doesn't exist");
+ return null;
+ }
+
+ String[] lines = Utils.readFileLines(scanResultFile);
+ List<AccessPointInfo> nets = new ArrayList<AccessPointInfo>();
+
+ if (lines == null) {
+ return null;
+ }
+
+ for (String l : lines) {
+ if (l.startsWith(Commons.SCAN_FILE_HDR)) {
+ // strip off the header
+ continue;
+ }
+
+ if (l.trim().equals("")) {
+ // empty line, skip.
+ continue;
+ }
+
+ // try to parse line into network info
+ AccessPointInfo info = AccessPointInfo.parseLine(l);
+ if (info == null) {
+ Utils.logError("Failed to parse line into AccessPointInfo: " + l);
+ continue;
+ }
+
+ nets.add(info);
+
+ }
+
+ AccessPointInfo[] a = new AccessPointInfo[nets.size()];
+ a = nets.toArray(a);
+ return a;
+
+ } catch (Exception e) {
+ Utils.logError("Error while parsing scan results in class AccessPointInfo", e);
+ return null;
+ }
-public class AccessPointInfo implements Serializable{
-
- private static final long serialVersionUID = 1L;
-
- private String _ssid;
- private String _bssid;
- private String _auth;
- private String _level;
- private String _freq;
- private String _password;
- private long _lastTimeUsed;
-
- public AccessPointInfo(String ssid, String bssid, String authType, String level, String freq){
-
- this._ssid = ssid;
- this._bssid = bssid;
- this._auth = authType;
- this._level = level;
- this._freq = freq;
-
- }
-
- public String getSSID(){
- return this._ssid;
- }
-
- public String getBSSID(){
- return this._bssid;
- }
-
- public String getAuthType(){
- return this._auth;
- }
-
- public String getSignlalStrength(){
- return this._level;
- }
-
- public String getFrequency(){
- return this._freq;
- }
-
- public long getLastTimeUsed(){
- return this._lastTimeUsed;
- }
-
- public void setLastTimeUsed(long timeStampInMillis){
- this._lastTimeUsed = timeStampInMillis;
- }
-
- public boolean isOlderThan(int days){
-
- if (this._lastTimeUsed == 0){
- return false;
- }
-
- long timeDiff = System.currentTimeMillis() - this._lastTimeUsed;
- long spanMillis = Utils.daysToMilliseconds(days);
-
- if (timeDiff > spanMillis){
- return true;
- }else{
- return false;
- }
-
-
- }
-
- public String getPassword(){
- return this._password;
- }
-
- public void setPassword(String password){
- this._password = password;
- }
-
- public boolean needsPassword(){
-
- if ( (this._auth == null) || (this._auth.equals("")) ){
- //TODO
- //check if default behavior should be with or without password,
- //when no auth info is available.
- return false;
- }
-
- if (this._auth.contains("WPA2") || this._auth.contains("WPA")){
- return true;
- }
- else {
- return false;
- }
-
- }
-
- protected static AccessPointInfo parseLine(String line){
-
- try{
-
- String[] params = line.split("\t");
- if (params.length != 5){
- return null;
- }
-
- String bssid = params[0];
- String freq = params[1];
- String level = params[2];
- String auth = params[3];
- String ssid = params [4];
-
- AccessPointInfo info = new AccessPointInfo(ssid, bssid, auth, level, freq);
- return info;
-
- }catch (Exception e){
- Utils.logError("Error while parsing line: " + line, e);
- return null;
- }
-
- }
-
- public static AccessPointInfo[] parseScanResult(String scanResultFile){
-
- try {
-
- File f = new File(scanResultFile);
- if (! f.exists()){
- Utils.logError("AccessPointInfo.parseScanResult(): The provided scan result file doesn't exist");
- return null;
- }
-
- String[] lines = Utils.readFileLines(Commons.getScanFile());
- List<AccessPointInfo> nets = new ArrayList<AccessPointInfo>();
-
- for(String l : lines){
- if (l.startsWith(Commons.SCAN_FILE_HDR)){
- //strip off the header
- continue;
- }
-
- if (l.trim().equals("")){
- //empty line, skip.
- continue;
- }
-
- //try to parse line into network info
- AccessPointInfo info = AccessPointInfo.parseLine(l);
- if (info == null){
- Utils.logError("Failed to parse line into AccessPointInfo: " + l);
- continue;
- }
-
- nets.add(info);
-
- }
-
- AccessPointInfo[] a = new AccessPointInfo[nets.size()];
- a = nets.toArray(a);
- return a;
-
- } catch (Exception e) {
- Utils.logError("Error while parsing scan results in class AccessPointInfo",e);
- return null;
- }
-
- }
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/ConnectionStatus.java b/app/src/fil/libre/repwifiapp/helpers/ConnectionStatus.java
index f7cb8d7..c26dae9 100644
--- a/app/src/fil/libre/repwifiapp/helpers/ConnectionStatus.java
+++ b/app/src/fil/libre/repwifiapp/helpers/ConnectionStatus.java
@@ -22,85 +22,82 @@ package fil.libre.repwifiapp.helpers;
import java.io.Serializable;
-public class ConnectionStatus implements Serializable{
+public class ConnectionStatus implements Serializable {
- /**
+ /**
*
*/
- private static final long serialVersionUID = 1L;
- public static final String STATUS_CONNECTED = "COMPLETED";
- public static final String STATUS_INACTIVE = "INACTIVE";
- public static final String STATUS_DISCONNECTED = "DISCONNECTED";
- public static final String STATUS_UNDEFINED = "UNDEFINED";
-
- public String status;
- public String SSID;
- public String BSSID;
- public String IP;
-
- private static final String F_SEP = "=";
- private static final String KeyStatus = "wpa_state";
- private static final String KeySSID = "ssid";
- private static final String KeyBSSID = "bssid";
- private static final String KeyIP = "ip_address";
-
- public static ConnectionStatus parseWpaCliOutput(String wpaCliOutput){
-
- if (wpaCliOutput == null){
- return null;
- }
-
- if (wpaCliOutput.trim().length() == 0){
- return null;
- }
-
- String[] lines = wpaCliOutput.split("\n");
-
- ConnectionStatus s = new ConnectionStatus();
- for(String line : lines){
-
- if (line.trim().equals("")){
- continue;
- }
-
- String[] fields = line.split(F_SEP);
- if(fields.length < 2){
- continue;
- }
-
- String key = fields[0];
- String val = fields[1];
-
- if (key.equals(KeyBSSID)){
- s.BSSID = val;
- }
- else if (key.equals(KeySSID)){
- s.SSID = val;
- }
- else if (key.equals(KeyStatus)){
- s.status = val;
- }
- else if (key.equals(KeyIP)){
- s.IP = val;
- }
-
- }
-
- return s;
-
- }
-
- public boolean isConnected(){
-
- if (this.status == null){
- return false;
- }
-
- if (this.status.equals(STATUS_CONNECTED)){
- return true;
- }else{
- return false;
- }
- }
-
+ private static final long serialVersionUID = 1L;
+ public static final String STATUS_CONNECTED = "COMPLETED";
+ public static final String STATUS_INACTIVE = "INACTIVE";
+ public static final String STATUS_DISCONNECTED = "DISCONNECTED";
+ public static final String STATUS_UNDEFINED = "UNDEFINED";
+
+ public String status;
+ public String SSID;
+ public String BSSID;
+ public String IP;
+
+ private static final String F_SEP = "=";
+ private static final String KeyStatus = "wpa_state";
+ private static final String KeySSID = "ssid";
+ private static final String KeyBSSID = "bssid";
+ private static final String KeyIP = "ip_address";
+
+ public static ConnectionStatus parseWpaCliOutput(String wpaCliOutput) {
+
+ if (wpaCliOutput == null) {
+ return null;
+ }
+
+ if (wpaCliOutput.trim().length() == 0) {
+ return null;
+ }
+
+ String[] lines = wpaCliOutput.split("\n");
+
+ ConnectionStatus s = new ConnectionStatus();
+ for (String line : lines) {
+
+ if (line.trim().equals("")) {
+ continue;
+ }
+
+ String[] fields = line.split(F_SEP);
+ if (fields.length < 2) {
+ continue;
+ }
+
+ String key = fields[0];
+ String val = fields[1];
+
+ if (key.equals(KeyBSSID)) {
+ s.BSSID = val;
+ } else if (key.equals(KeySSID)) {
+ s.SSID = val;
+ } else if (key.equals(KeyStatus)) {
+ s.status = val;
+ } else if (key.equals(KeyIP)) {
+ s.IP = val;
+ }
+
+ }
+
+ return s;
+
+ }
+
+ public boolean isConnected() {
+
+ if (this.status == null) {
+ return false;
+ }
+
+ if (this.status.equals(STATUS_CONNECTED)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/Engine.java b/app/src/fil/libre/repwifiapp/helpers/Engine.java
index 5a2f2b2..68d8745 100644
--- a/app/src/fil/libre/repwifiapp/helpers/Engine.java
+++ b/app/src/fil/libre/repwifiapp/helpers/Engine.java
@@ -20,449 +20,450 @@
package fil.libre.repwifiapp.helpers;
+import java.net.NetworkInterface;
+import java.net.SocketException;
import java.util.ArrayList;
+import java.util.Enumeration;
import fil.libre.repwifiapp.Commons;
+public abstract class Engine implements IEngine {
-public abstract class Engine implements IEngine{
-
- public static final String DNS1 = "193.183.98.154";
- public static final String DNS2 = "87.98.175.85";
-
- protected String getCmdWpaSup(){
- return "wpa_supplicant -B -dd -i" + Commons.INTERFACE_NAME + " -C\"" +Commons.SOCKET_DIR + "\" -P\"" + Commons.PID_FILE + "\"";
- }
-
- protected String getCmdWpaCli() {
- return "wpa_cli -p" + Commons.SOCKET_DIR + " -P" + Commons.PID_FILE + " -i" + Commons.INTERFACE_NAME;
- }
-
- protected abstract String getCmdWpaStart();
-
- public boolean deleteFileIfExists(String filePath){
-
- if (filePath == null){
- return false;
- }
-
- if (filePath.contains("*")){
- //it's safer to reject bulk rm'ing
- return false;
- }
-
- if (filePath.contains(" -r ")){
- //only file rm'ing acceppted
- return false;
- }
-
- //needs root (it only gets used by the 4p2 engine, working in /data/misc/wifi)
- return executeRootCmd("if [ -e \""+ filePath + "\" ]; then rm \"" + filePath + "\"; fi");
-
- }
-
- public boolean chmodFile(String filePath, String mod){
- //needs root (chmod)
- return executeRootCmd("chmod " + mod + " \"" + filePath + "\"");
- }
-
- @Override
- public boolean killPreviousConnections() {
-
- //needs root (for killall)
-
- Utils.logDebug("killing wpa_supplicant..:");
- if (executeRootCmd("killall -SIGINT wpa_supplicant")){
- Utils.logDebug("Killed wpa_supplicant");
- }else{
- Utils.logDebug("Wpa_supplicant NOT killed.");
- }
-
- Utils.logDebug("killing dhcpcd..");
- if (executeRootCmd("killall -SIGINT dhcpcd")){
- Utils.logDebug("Killed dhcpcd");
- }else{
- Utils.logDebug("dhcpcd NOT killed.");
- }
-
-
- return true;
-
- }
-
- @Override
- public boolean clearWorkingDir(){
-
- //needs root (to work within /data/misc/wifi)
-
- Utils.logDebug("clearWorkingDir():");
-
- if (executeRootCmd("rm -r " + Commons.SOCKET_DIR)){
- Utils.logDebug("removed socket dir");
- }
-
- if (executeRootCmd("rm " + Commons.ENTROPY_FILE)){
- Utils.logDebug("removed entropy file");
- }
-
- if (executeRootCmd("rm " + Commons.PID_FILE)){
- Utils.logDebug("removed pidfile");
- }
-
- if (executeRootCmd("rm " + Commons.SOFTAP_FILE)){
- Utils.logDebug("removed softap file");
- }
-
- if (executeRootCmd("rm " + Commons.WPA_CONF)){
- Utils.logDebug("removed wpa conf file");
- }
-
- if (executeRootCmd("rm " + Commons.P2P_CONF)){
- Utils.logDebug("removed p2p conf file");
- }
-
-
- return true;
-
- }
-
- @Override
- public boolean startWpaSupplicant(){
-
- Utils.logDebug("startWpaSupplicant():");
-
- //needs root (for wpa_supplicant)
- if (executeRootCmd(getCmdWpaSup())){
- return true;
- }else{
- Utils.logDebug("Failed to start wpa");
- return false;
- }
-
- }
-
- @Override
- public AccessPointInfo[] getAvailableNetworks(){
-
- Utils.logDebug("getAvailableNetworks():");
-
- killPreviousConnections();
-
- //is it really necessary??? --- Fil
- if (! clearWorkingDir()){
- Utils.logError("Failed clearing dir");
- return null;
- }
-
- if (! startWpaSupplicant()){
- Utils.logError("Failed starting wpa_supplicant");
- return null;
- }
-
- if (! createScanScripts()){
- Utils.logError("Failed creating scripts");
- return null;
- }
-
- if (! scanNetworks()){
- Utils.logError("failed scanning networks");
- return null;
- }
-
- if (!getScanResults()){
- Utils.logError("failed getting scan results");
- return null;
- }
-
- //chmod 664 scan_file to make it readable
- if (!chmodFile(Commons.getScanFile(), "664")){
- Utils.logError("failed chmodding scan_file");
- return null;
- }
-
- AccessPointInfo[] a = AccessPointInfo.parseScanResult(Commons.getScanFile());
- if (a == null){
- Utils.logError("Unable to parse scan file into AccessPointInfo array");
- }
-
- return a;
-
- }
-
- @Override
- public abstract boolean connect(AccessPointInfo info);
-
- @Override
- public boolean disconnect(){
-
- //needs root (for wpa_cli)
-
- if (! isWpaSupplicantRunning()){
- return true;
- }
-
- try {
-
- RootCommand su = new RootCommand(getCmdWpaCli() + " disconnect");
- if (su.execute() == 0){
- String out = su.getOutput();
- if (out != null && out.trim().replace("\n", "").equals("OK")){
- return true;
- }else {
- return false;
- }
- }
- else{
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while enabling network", e);
- return false;
- }
- }
-
- /***
- * returns null if unable to determine connection status for any reason.
- */
- @Override
- public ConnectionStatus getConnectionStatus(){
-
- Utils.logDebug("called getConnecitonStatus()");
- if (! isWpaSupplicantRunning()){
- //wpa_supplicant is not running.
- //unable to determin status.
- Utils.logDebug("wpa not running, cannot get connection status.");
- return null;
-
- }
-
- try {
-
- RootCommand su = new RootCommand(getCmdWpaCli() + " status");
- if(su.execute() == 0){
- String out = su.getOutput();
- if (out == null || out.trim().equals("")){
- return null;
- }
- else {
- return ConnectionStatus.parseWpaCliOutput(out);
- }
- }
- else {
- return null;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while executing wpa_cli status", e);
- return null;
- }
-
- }
-
- @Override
- public boolean isInterfaceAvailable(String ifaceName){
-
- String[]ifaces = getAvailableInterfaces();
- if(ifaces == null || ifaces.length == 0){
- return false;
- }
-
- for(String name : ifaces){
- if (name.equals(ifaceName)){
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public String[] getAvailableInterfaces(){
-
- try {
-
- ShellCommand cmd = new ShellCommand("ip link");
- if (cmd.execute() == 0){
-
- String out = cmd.getOutput();
- if (out == null || out.contains("\n") == false){
- Utils.logDebug("No out from ip link");
- return null;
- }
-
- ArrayList<String> list = new ArrayList<String>();
-
- String[] lines = out.split("\n");
- for (String l : lines){
-
- String[] fields = l.split(":");
- if (fields.length != 3){
- continue;
- }
-
- String interfName = fields[1].trim();
- list.add(interfName);
-
- }
-
- String[] retArr = new String[list.size()];
- retArr = list.toArray(retArr);
-
- return retArr;
-
- }
- else{
- return null;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while querying ip link", e);
- return null;
- }
-
- }
-
- public boolean runDhcpcd(){
-
- //needs root
- return executeRootCmd("dhcpcd " + Commons.INTERFACE_NAME);
-
- }
-
- public boolean interfaceUp(){
- //needs root (tested)
- return executeRootCmd("ifconfig " + Commons.INTERFACE_NAME + " up");
- }
-
- protected boolean executeCmd(String cmd){
-
- try {
-
- ShellCommand c = new ShellCommand(cmd);
- if ( c.execute() == 0){
- return true;
- }else {
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error executing \"" + cmd + "\"",e);
- return false;
- }
-
- }
-
- protected boolean executeRootCmd(String cmd){
-
- try {
-
- RootCommand c = new RootCommand(cmd);
- if ( c.execute() == 0){
- return true;
- }else {
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error executing \"" + cmd + "\"",e);
- return false;
- }
- }
-
- protected boolean isWpaSupplicantRunning(){
-
- boolean retval = false;
-
- try {
-
- RootCommand su = new RootCommand("pidof wpa_supplicant");
- if (su.execute() == 0){
-
- if (su.getOutput().trim().equals("")){
- retval = false;
- }else{
- retval = true;
- }
-
- }else {
- retval = false;
- }
-
-
- } catch (Exception e) {
- Utils.logError("Exception during isWpaSupplicantRunning()",e);
- retval = false;
- }
-
- return retval;
-
- }
-
- protected boolean scanNetworks(){
-
- //needs root (for wpa_supplicant and wpa_cli)
- return executeRootCmd("bash " + Commons.getScriptScan());
-
- }
-
- protected boolean getScanResults(){
-
- //needs root (for wpa_supplicant and wpa_cli)
- return executeRootCmd("bash " + Commons.getScriptScanRes());
-
- }
-
- protected boolean createScanScripts(){
-
- try {
-
- String scan = getCmdWpaCli() + " scan\n" +
- "if [ $? -ne 0 ]; then\n" +
- "exit 1\n" +
- "fi\n" +
- "sleep 2s\n";
-
- String scanRes = "if [ -e \"" + Commons.getScanFile() + "\" ]; then\n" +
- " rm \"" + Commons.getScanFile() + "\"\n" +
- "fi\n" +
- getCmdWpaCli() + " scan_results > \""+ Commons.getScanFile() + "\"\n" +
- "if [ $? -ne 0 ]; then\n" +
- " exit 1\n" +
- "fi\n" +
- "sleep 1s\n";
+ protected String getCmdWpaSup() {
+ return "wpa_supplicant -B -dd -i" + Commons.INTERFACE_NAME + " -C" + Commons.SOCKET_DIR
+ + " -P" + Commons.PID_FILE + " -I" + Commons.OVERLAY_FILE + " -e"
+ + Commons.ENTROPY_FILE;
+ }
-
- if (! Utils.writeFile(Commons.getScriptScan(),scan,true) ){
+ protected String getCmdWpaCli() {
+ return "wpa_cli -p" + Commons.SOCKET_DIR + " -P" + Commons.PID_FILE + " -i"
+ + Commons.INTERFACE_NAME;
+ }
- Exception e = Utils.getLastException();
- if (e != null){
- Utils.logError("Error while writing scan script.",e);
- }
+ protected abstract String getCmdWpaStart();
- return false;
- }
+ public boolean deleteFileIfExists(String filePath) {
-
- if (! Utils.writeFile(Commons.getScriptScanRes(),scanRes,true) ){
+ if (filePath == null) {
+ return false;
+ }
- Exception e = Utils.getLastException();
- if (e != null){
- Utils.logError("Error while writing getScanResults script.",e);
- }
+ if (filePath.contains("*")) {
+ // it's safer to reject bulk rm'ing
+ return false;
+ }
- return false;
- }
+ if (filePath.contains(" -r ")) {
+ // only file rm'ing acceppted
+ return false;
+ }
+ // needs root (it only gets used by the 4p2 engine, working in
+ // /data/misc/wifi)
+ return executeRootCmd("if [ -e \"" + filePath + "\" ]; then rm \"" + filePath + "\"; fi");
- return true;
+ }
- } catch (Exception e) {
+ public boolean chmodFile(String filePath, String mod) {
+ // needs root (chmod)
+ return executeRootCmd("chmod " + mod + " \"" + filePath + "\"");
+ }
- Utils.logError("Error while creating the scanning script.",e);
- return false;
- }
+ @Override
+ public boolean killBackEndProcesses() {
- }
-
+ // needs root (for killall)
+
+ Utils.logDebug("killing wpa_supplicant..:");
+ if (executeRootCmd("killall -SIGINT wpa_supplicant")) {
+ Utils.logDebug("Killed wpa_supplicant");
+ } else {
+ Utils.logDebug("Wpa_supplicant NOT killed.");
+ }
+
+ Utils.logDebug("killing dhcpcd..");
+ if (executeRootCmd("killall -SIGINT dhcpcd")) {
+ Utils.logDebug("Killed dhcpcd");
+ } else {
+ Utils.logDebug("dhcpcd NOT killed.");
+ }
+
+ return true;
+
+ }
+
+ @Override
+ public boolean clearWorkingDir() {
+
+ // needs root (to work within /data/misc/wifi)
+
+ Utils.logDebug("clearWorkingDir():");
+
+ if (executeRootCmd("rm -r " + Commons.SOCKET_DIR)) {
+ Utils.logDebug("removed socket dir");
+ }
+
+ if (executeRootCmd("rm " + Commons.ENTROPY_FILE)) {
+ Utils.logDebug("removed entropy file");
+ }
+
+ if (executeRootCmd("rm " + Commons.PID_FILE)) {
+ Utils.logDebug("removed pidfile");
+ }
+
+ if (executeRootCmd("rm " + Commons.SOFTAP_FILE)) {
+ Utils.logDebug("removed softap file");
+ }
+
+ if (executeRootCmd("rm " + Commons.WPA_CONF)) {
+ Utils.logDebug("removed wpa conf file");
+ }
+
+ if (executeRootCmd("rm " + Commons.P2P_CONF)) {
+ Utils.logDebug("removed p2p conf file");
+ }
+
+ return true;
+
+ }
+
+ @Override
+ public boolean startWpaSupplicant() {
+
+ Utils.logDebug("startWpaSupplicant():");
+
+ // needs root (for wpa_supplicant)
+ if (executeRootCmd(getCmdWpaSup())) {
+ return true;
+ } else {
+ Utils.logDebug("Failed to start wpa");
+ return false;
+ }
+
+ }
+
+ @Override
+ public AccessPointInfo[] getAvailableNetworks() {
+
+ Utils.logDebug("getAvailableNetworks():");
+
+ // killPreviousConnections();
+
+ // Is it really necessary???
+ // seems that clearing /data/misc/wifi is NOT necessary
+ // so, commented out - Fil 2017-03-24
+ /*
+ * if (! clearWorkingDir()){ Utils.logError("Failed clearing dir");
+ * return null; }
+ */
+
+ if (!startWpaSupplicant()) {
+ Utils.logError("Failed starting wpa_supplicant");
+ return null;
+ }
+
+ if (!createScanScripts()) {
+ Utils.logError("Failed creating scripts");
+ return null;
+ }
+
+ if (!scanNetworks()) {
+ Utils.logError("failed scanning networks");
+ return null;
+ }
+
+ if (!getScanResults()) {
+ Utils.logError("failed getting scan results");
+ return null;
+ }
+
+ // chmod 664 scan_file to make it readable
+ /*
+ * if (!chmodFile(Commons.getScanFile(), "664")){
+ * Utils.logError("failed chmodding scan_file"); return null; }
+ */
+
+ AccessPointInfo[] a = AccessPointInfo.parseScanResult(Commons.getScanFile());
+ if (a == null) {
+ Utils.logError("Unable to parse scan file into AccessPointInfo array");
+ return a;
+ }
+
+ Utils.logDebug("# of APs found: " + a.length);
+
+ return a;
+
+ }
+
+ @Override
+ public abstract boolean connect(AccessPointInfo info);
+
+ @Override
+ public boolean disconnect() {
+
+ // needs root (for wpa_cli)
+
+ if (!isWpaSupplicantRunning()) {
+ return true;
+ }
+
+ try {
+
+ RootCommand su = new RootCommand(getCmdWpaCli() + " disconnect");
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out != null && out.trim().replace("\n", "").equals("OK")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while enabling network", e);
+ return false;
+ }
+ }
+
+ /***
+ * returns null if unable to determine connection status for any reason.
+ */
+ @Override
+ public ConnectionStatus getConnectionStatus() {
+
+ Utils.logDebug("called getConnecitonStatus()");
+ if (!isWpaSupplicantRunning()) {
+ // wpa_supplicant is not running.
+ // unable to determin status.
+ Utils.logDebug("wpa not running, cannot get connection status.");
+ return null;
+
+ }
+
+ try {
+
+ RootCommand su = new RootCommand(getCmdWpaCli() + " status");
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out == null || out.trim().equals("")) {
+ return null;
+ } else {
+ return ConnectionStatus.parseWpaCliOutput(out);
+ }
+ } else {
+ return null;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while executing wpa_cli status", e);
+ return null;
+ }
+
+ }
+
+ @Override
+ public boolean isInterfaceAvailable(String ifaceName) throws SocketException {
+
+ /*
+ * String[]ifaces = getAvailableInterfaces(); if(ifaces == null ||
+ * ifaces.length == 0){ return false; }
+ *
+ * for(String name : ifaces){
+ *
+ * if (name.equals(ifaceName)){ return true; } }
+ *
+ * return false;
+ */
+
+ Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
+ while (interfaces.hasMoreElements()) {
+ NetworkInterface nif = interfaces.nextElement();
+ String nm = nif.getName();
+ if (nm.equals(ifaceName)) {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
+ @Override
+ public String[] getAvailableInterfaces() {
+
+ try {
+
+ // No need for root for "ip link"
+ // tested 2017-03-24 - Fil
+ ShellCommand cmd = new ShellCommand("ip link");
+ if (cmd.execute() == 0) {
+
+ String out = cmd.getOutput();
+ if (out == null || out.contains("\n") == false) {
+ Utils.logDebug("No out from ip link");
+ return null;
+ }
+
+ ArrayList<String> list = new ArrayList<String>();
+
+ String[] lines = out.split("\n");
+ for (String l : lines) {
+
+ String[] fields = l.split(":");
+ if (fields.length != 3) {
+ continue;
+ }
+
+ String interfName = fields[1].trim();
+ list.add(interfName);
+
+ }
+
+ String[] retArr = new String[list.size()];
+ retArr = list.toArray(retArr);
+
+ return retArr;
+
+ } else {
+ return null;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while querying ip link", e);
+ return null;
+ }
+
+ }
+
+ public boolean runDhcpcd() {
+
+ // needs root
+ return executeRootCmd("dhcpcd " + Commons.INTERFACE_NAME);
+
+ }
+
+ public boolean interfaceUp() {
+ // needs root (tested)
+ return executeRootCmd("ifconfig " + Commons.INTERFACE_NAME + " up");
+ }
+
+ /*
+ * protected boolean executeCmd(String cmd){
+ *
+ * try {
+ *
+ * ShellCommand c = new ShellCommand(cmd); if ( c.execute() == 0){ return
+ * true; }else { return false; }
+ *
+ * } catch (Exception e) { Utils.logError("Error executing \"" + cmd +
+ * "\"",e); return false; }
+ *
+ * }
+ */
+
+ protected boolean executeRootCmd(String cmd) {
+
+ try {
+
+ RootCommand c = new RootCommand(cmd);
+ if (c.execute() == 0) {
+ return true;
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error executing \"" + cmd + "\"", e);
+ return false;
+ }
+ }
+
+ protected boolean isWpaSupplicantRunning() {
+
+ boolean retval = false;
+
+ try {
+
+ RootCommand su = new RootCommand("pidof wpa_supplicant");
+ if (su.execute() == 0) {
+
+ if (su.getOutput().trim().equals("")) {
+ retval = false;
+ } else {
+ retval = true;
+ }
+
+ } else {
+ retval = false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Exception during isWpaSupplicantRunning()", e);
+ retval = false;
+ }
+
+ return retval;
+
+ }
+
+ protected boolean scanNetworks() {
+
+ // needs root (for wpa_supplicant and wpa_cli)
+ return executeRootCmd("bash " + Commons.getScriptScan());
+
+ }
+
+ protected boolean getScanResults() {
+
+ // needs root (for wpa_supplicant and wpa_cli)
+ boolean res = executeRootCmd("bash " + Commons.getScriptScanRes());
+ if (!res) {
+ return false;
+ }
+ return res;
+
+ }
+
+ protected boolean createScanScripts() {
+
+ try {
+
+ String scan = getCmdWpaCli() + " scan\n" + "if [ $? -ne 0 ]; then\n" + "exit 1\n"
+ + "fi\n" + "sleep 2s\n";
+
+ String scanRes = "if [ -e \"" + Commons.getScanFile() + "\" ]; then\n" + " rm \""
+ + Commons.getScanFile() + "\"\n" + "fi\n" + getCmdWpaCli()
+ + " scan_results > \"" + Commons.getScanFile() + "\"\n"
+ + "if [ $? -ne 0 ]; then\n" + " exit 1\n" + "fi\n";
+
+ if (!Utils.writeFile(Commons.getScriptScan(), scan, true)) {
+
+ Exception e = Utils.getLastException();
+ if (e != null) {
+ Utils.logError("Error while writing scan script.", e);
+ }
+
+ return false;
+ }
+
+ if (!Utils.writeFile(Commons.getScriptScanRes(), scanRes, true)) {
+
+ Exception e = Utils.getLastException();
+ if (e != null) {
+ Utils.logError("Error while writing getScanResults script.", e);
+ }
+
+ return false;
+ }
+
+ return true;
+
+ } catch (Exception e) {
+
+ Utils.logError("Error while creating the scanning script.", e);
+ return false;
+ }
+
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/Engine4p2.java b/app/src/fil/libre/repwifiapp/helpers/Engine4p2.java
deleted file mode 100644
index 12d8da8..0000000
--- a/app/src/fil/libre/repwifiapp/helpers/Engine4p2.java
+++ /dev/null
@@ -1,131 +0,0 @@
-//
-// Copyright 2017 Filippo "Fil" Bergamo <fil.bergamo@riseup.net>
-//
-// This file is part of RepWifiApp.
-//
-// RepWifiApp is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// RepWifiApp is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with RepWifiApp. If not, see <http://www.gnu.org/licenses/>.
-//
-// ********************************************************************
-
-package fil.libre.repwifiapp.helpers;
-
-import fil.libre.repwifiapp.Commons;
-
-
-public class Engine4p2 extends Engine{
-
- @Override
- protected String getCmdWpaStart(){
- return "wpa_supplicant -B -dd -i" + Commons.INTERFACE_NAME + " -C\"" + Commons.SOCKET_DIR + "\" -c\"" + Commons.WPA_CONF + "\" -P\"" + Commons.PID_FILE + "\"";
- }
-
- public boolean loadModules(){
- try {
- //TODO
- //implement kernel modules loading
- return true;
- } catch (Exception e) {
- Utils.logError("Error while loading kernel modules",e);
- return false;
- }
- }
-
- @Override
- public boolean connect(AccessPointInfo info){
-
- killPreviousConnections();
-
- if (info == null){
- Utils.logDebug("Engine's connect() received a null AccessPointInfo");
- return false;
- }
-
- if (! createConfigFile(info)){
- return false;
- }
-
- //launch wpa_supplicant specifying our custom configuration and the socket file
- if (! executeRootCmd(getCmdWpaStart())){
- Utils.logError("wpa_supplicant connection command failed.");
- return false;
- }
-
- //negotiate DHCP lease
- if (!runDhcpcd()){
- return false;
- }
-
- //set DNS's
- if (! executeRootCmd("setprop net.dns1 " + DNS1)){
- Utils.logError("setting dns1 failed");
- return false;
- }
-
- if (! executeRootCmd("setprop net.dns2 " + DNS2)){
- Utils.logError("setting dns2 failed");
- return false;
- }
-
- //TODO
- //implement wpa_cli command to query wpa_supplicant's state
- //in order to confirm that connection was successful.
-
- return true;
-
- }
-
- private boolean createConfigFile(AccessPointInfo info){
-
- try {
-
- if (! deleteFileIfExists(Commons.WPA_CONF)){
- Utils.logError("Unable to remove wpa_supplicant.conf before writing it.");
- return false;
- }
-
- String configText = "ctrl_interface=DIR=" + Commons.SOCKET_DIR + "\n" +
- "update_config=1\n" +
- "network={\n"+
- " ssid=\"" + info.getSSID() + "\"\n";
-
- if (info.needsPassword()){
- configText += " psk=\""+ info.getPassword() + "\"\n";
- }else {
- configText += " key_mgmt=NONE\n";
- }
-
- configText += "}\n";
-
- if ( ! Utils.writeFile(Commons.WPA_CONF, configText, true) ){
- Utils.logError("Unable to write wpa_supplicant.conf file!");
- return false;
- }
-
- //chmod wpa_supplicant.conf, in order to make it accessible
- if(chmodFile(Commons.WPA_CONF, "666")){
- return true;
- }else {
- Utils.logError("Unable to chmod wpa_supplicant.conf");
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while creating wpa_supplicant.conf",e);
- return false;
- }
-
- }
-
-
-}
diff --git a/app/src/fil/libre/repwifiapp/helpers/Engine6p0.java b/app/src/fil/libre/repwifiapp/helpers/Engine6p0.java
index 9cbfeaf..d4ff0f7 100644
--- a/app/src/fil/libre/repwifiapp/helpers/Engine6p0.java
+++ b/app/src/fil/libre/repwifiapp/helpers/Engine6p0.java
@@ -20,352 +20,377 @@
package fil.libre.repwifiapp.helpers;
+import org.apache.http.conn.util.InetAddressUtils;
import fil.libre.repwifiapp.Commons;
+public class Engine6p0 extends Engine {
+
+ @Override
+ protected String getCmdWpaStart() {
+ return "wpa_supplicant -B -dd -i" + Commons.INTERFACE_NAME + " -C" + Commons.SOCKET_DIR
+ + " -P" + Commons.PID_FILE + " -I" + Commons.OVERLAY_FILE + " -e"
+ + Commons.ENTROPY_FILE;
+ }
+
+ @Override
+ public boolean connect(AccessPointInfo info) {
+
+ killBackEndProcesses();
+
+ if (info == null) {
+ Utils.logDebug("Engine's connect() received a null AccessPointInfo");
+ return false;
+ }
+
+ // clear any previously set network
+ if (!destroyNetwork()) {
+ Utils.logDebug("Unable to ndc destroy network");
+ return false;
+ }
+
+ // clear interface's ip
+ if (!clearAddrs()) {
+ Utils.logDebug("Unable to ndc clearaddrs");
+ return false;
+ }
+
+ // bring up interface
+ if (!interfaceUp()) {
+ Utils.logDebug("Unable to bring up interface.");
+ return false;
+ }
+
+ // launch wpa_supplicant specifying our custom configuration and the
+ // socket file
+ if (!executeRootCmd(getCmdWpaStart())) {
+ Utils.logDebug("Unable to run wpa start");
+ return false;
+ }
+
+ // create new network and get network id
+ String netID = createNetworkGetId();
+ if (netID == null) {
+ Utils.logDebug("Unable to fetch network id");
+ return false;
+ }
+
+ // set network SSID
+ if (!setNetworkSSID(info.getSsid(), netID)) {
+ Utils.logDebug("Failed to set network ssid");
+ return false;
+ }
+
+ if (info.isHidden() && !setNetworkScanSSID(netID)) {
+ Utils.logDebug("Failed to set scan_ssid 1 for hidden network.");
+ return false;
+ }
+
+ // set password (if any)
+ if (!setNetworkPSK(info, netID)) {
+ Utils.logDebug("Failed to set network psk");
+ return false;
+ }
+
+ // select the network we just created
+ if (!selectNetwork(netID)) {
+ Utils.logDebug("Unable to wpa_cli select network");
+ return false;
+ }
+
+ // enable the newtork
+ if (!enableNetwork(netID)) {
+ Utils.logDebug("Unable to wpa_cli enable_newtork");
+ return false;
+ }
+
+ // try to reassociate to Access Point
+ /*
+ * if (! reassociate()){
+ * Utils.logDebug("Unable to wpa_cli reassociate"); return false; }
+ */
+
+ // get DHCP
+ Utils.logDebug("Attempt to run dhcpcd..");
+ if (!runDhcpcd()) {
+ Utils.logDebug("Failed to run dhcpcd");
+ return false;
+ }
+
+ // try to fetch gateway
+ String gw = getGateway();
+ if (gw == null || gw.trim().length() < 7) {
+ // failed to get gateway
+ Utils.logDebug("Failed to get gateway");
+ return false;
+ }
+
+ if (!executeRootCmd("ndc network create 1")) {
+ Utils.logDebug("Failed to wpa_cli network create 1 ");
+ return false;
+ }
+
+ if (!executeRootCmd("ndc network interface add 1 " + Commons.INTERFACE_NAME)) {
+ Utils.logDebug("Failed to add interface.");
+ return false;
+ }
+
+ // set route to gateway for all traffic
+ if (!executeRootCmd("ndc network route add 1 " + Commons.INTERFACE_NAME + " 0.0.0.0/0 "
+ + gw)) {
+ Utils.logDebug("Failed to add route to gateway");
+ return false;
+ }
+
+ if (!setDns(Commons.getDnss(), gw)) {
+ Utils.logDebug("Failed to set DNS");
+ return false;
+ }
+
+ // use network
+ if (!executeRootCmd("ndc network default set 1")) {
+ Utils.logDebug("Failed to set network as default");
+ return false;
+ }
+
+ return true;
+
+ }
+
+ private String createNetworkGetId() {
+
+ try {
+
+ RootCommand su = new RootCommand(getCmdWpaCli() + " add_network");
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out == null || out.trim().equals("")) {
+ return null;
+ } else {
+ return out.replace("\n", "");
+ }
+ } else {
+ return null;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while creating network", e);
+ return null;
+ }
+
+ }
+
+ private boolean destroyNetwork() {
+ // needs root (tested)
+ return executeRootCmd("ndc network destroy 1");
+ }
+
+ private boolean setNetworkSSID(String ssid, String networkID) {
+
+ try {
+
+ // needs root (wpa_cli)
+ RootCommand su = new RootCommand(getCmdWpaCli() + " set_network " + networkID
+ + " ssid '\"" + ssid + "\"'");
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out != null && out.trim().replace("\n", "").equals("OK")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while setting network SSID", e);
+ return false;
+ }
+
+ }
+
+ private boolean setNetworkPSK(AccessPointInfo info, String networkID) {
+
+ try {
+
+ // needs root (wpa_cli)
+
+ String cmdSetPass = null;
+ if (info.needsPassword()) {
+ cmdSetPass = getCmdWpaCli() + " set_network " + networkID + " psk '\""
+ + info.getPassword() + "\"'";
+ } else {
+ cmdSetPass = getCmdWpaCli() + " set_network " + networkID + " key_mgmt NONE";
+ }
+
+ RootCommand su = new RootCommand(cmdSetPass);
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out != null && out.trim().replace("\n", "").equals("OK")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while setting network PSK", e);
+ return false;
+ }
+
+ }
+
+ private boolean setNetworkScanSSID(String networkID) {
+
+ try {
+
+ // needs root (wpa_cli)
+ RootCommand su = new RootCommand(getCmdWpaCli() + " set_network " + networkID
+ + " scan_ssid 1");
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out != null && out.trim().replace("\n", "").equals("OK")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while setting network SSID", e);
+ return false;
+ }
+ }
+
+ private boolean selectNetwork(String networkID) {
+
+ try {
+
+ // needs root (wpa_cli)
+ RootCommand su = new RootCommand(getCmdWpaCli() + " select_network " + networkID);
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out != null && out.trim().replace("\n", "").equals("OK")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while selecting network", e);
+ return false;
+ }
+
+ }
+
+ private boolean enableNetwork(String networkID) {
+
+ try {
+
+ // needs root (wpa_cli)
+
+ RootCommand su = new RootCommand(getCmdWpaCli() + " enable_network " + networkID);
+ if (su.execute() == 0) {
+ String out = su.getOutput();
+ if (out != null && out.trim().replace("\n", "").equals("OK")) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ } catch (Exception e) {
+ Utils.logError("Error while enabling network", e);
+ return false;
+ }
+
+ }
+
+ private boolean setDns(String[] dnss, String gateway) {
+
+ if (dnss == null || dnss.length == 0) {
+ // the DNS setting has been left blank
+ // try to use the gateway as dns
+
+ if (gateway == null || gateway.length() == 0) {
+ // no possible DNS.
+ return false;
+ }
+
+ dnss = new String[] { gateway, gateway };
+
+ }
+
+ if (!InetAddressUtils.isIPv4Address(dnss[0])) {
+ // invalid ip can't proceed.
+ return false;
+ }
+
+ String cmd = "ndc resolver setnetdns 1 " + dnss[0];
+
+ if (dnss.length > 1 && InetAddressUtils.isIPv4Address(dnss[1])) {
+ cmd += " " + dnss[1];
+ } else {
+ cmd += " " + dnss[0];
+ }
+
+ return executeRootCmd(cmd);
+ }
+
+ private String getGateway() {
+
+ try {
+
+ // doesn't need root (tested)
+ RootCommand cmd = new RootCommand("ip route show dev " + Commons.INTERFACE_NAME);
+ if (cmd.execute() != 0) {
+ Utils.logDebug("command failed show route");
+ return null;
+ }
+
+ // read command output
+ String out = cmd.getOutput();
+ if (out == null) {
+ return null;
+ }
+
+ String[] lines = out.split("\n");
+
+ for (String l : lines) {
+
+ if (l.contains("default via")) {
+
+ String[] f = l.split(" ");
+ if (f.length > 2) {
+
+ // found route's address:
+ return f[2];
+
+ }
+ }
+ }
+
+ return null;
+
+ } catch (Exception e) {
+ Utils.logError("Error while trying to fetch route", e);
+ return null;
+ }
+
+ }
+
+ private boolean clearAddrs() {
+ // needs root (tested)
+ return executeRootCmd("ndc interface clearaddrs " + Commons.INTERFACE_NAME);
+ }
-public class Engine6p0 extends Engine{
-
- @Override
- protected String getCmdWpaStart(){
- return "wpa_supplicant -B -dd -i" + Commons.INTERFACE_NAME + " -C" + Commons.SOCKET_DIR + " -P" + Commons.PID_FILE + " -I" + Commons.OVERLAY_FILE + " -e" + Commons.ENTROPY_FILE;
- }
-
- @Override
- public boolean connect(AccessPointInfo info){
-
- killPreviousConnections();
-
- if (info == null){
- Utils.logDebug("Engine's connect() received a null AccessPointInfo");
- return false;
- }
-
- //clear any previously set network
- if (! destroyNetwork()){
- Utils.logDebug("Unable to ndc destroy network");
- return false;
- }
-
- //clear interface's ip
- if (! clearAddrs()){
- Utils.logDebug("Unable to ndc clearaddrs");
- return false;
- }
-
- //bring up interface
- if(! interfaceUp()){
- Utils.logDebug("Unable to bring up interface.");
- return false;
- }
-
- //launch wpa_supplicant specifying our custom configuration and the socket file
- if (! executeRootCmd(getCmdWpaStart())){
- Utils.logDebug("Unable to run wpa start");
- return false;
- }
-
- //create new network and get network id
- String netID = createNetworkGetId();
- if (netID == null){
- Utils.logDebug("Unable to fetch network id");
- return false;
- }
-
- //set network SSID
- if (! setNetworkSSID(info.getSSID(), netID)){
- Utils.logDebug("Failed to set network ssid");
- return false;
- }
-
- //set password (if any)
- if(! setNetworkPSK(info, netID)){
- Utils.logDebug("Failed to set network psk");
- return false;
- }
-
- // select the network we just created
- if (! selectNetwork(netID)){
- Utils.logDebug("Unable to wpa_cli select network");
- return false;
- }
-
- //enable the newtork
- if (! enableNetwork(netID)){
- Utils.logDebug("Unable to wpa_cli enable_newtork");
- return false;
- }
-
- //try to reassociate to Access Point
- if (! reassociate()){
- Utils.logDebug("Unable to wpa_cli reassociate");
- return false;
- }
-
- //get DHCP
- Utils.logDebug("Attempt to run dhcpcd..");
- if (!runDhcpcd()){
- Utils.logDebug("Failed to run dhcpcd");
- return false;
- }
-
- //try to fetch gateway
- String gw = getGateway();
- if (gw == null || gw.trim().length() < 7){
- //failed to get gateway
- Utils.logDebug("Failed to get gateway");
- return false;
- }
-
- if (! executeRootCmd("ndc network create 1")){
- Utils.logDebug("Failed to wpa_cli network create 1 ");
- return false;
- }
-
- if (! executeRootCmd("ndc network interface add 1 " + Commons.INTERFACE_NAME)){
- Utils.logDebug("Failed to add interface.");
- return false;
- }
-
- // set route to gateway for all traffic
- if (! executeRootCmd("ndc network route add 1 " + Commons.INTERFACE_NAME + " 0.0.0.0/0 " + gw)){
- Utils.logDebug("Failed to add route to gateway");
- return false;
- }
-
- //set DNS
- if (! executeRootCmd("ndc resolver setnetdns 1 " + " " + DNS1 + " " + DNS2)){
- Utils.logDebug("Failed to set DNS");
- return false;
- }
-
- //use network
- if (! executeRootCmd("ndc network default set 1")){
- Utils.logDebug("Failed to set network as default");
- return false;
- }
-
- //TODO
- //implement wpa_cli query for status
- //in order to be sure that connection is extablished
-
- return true;
-
-
-
- }
-
- private String createNetworkGetId(){
-
- try {
-
- RootCommand su = new RootCommand(getCmdWpaCli() + " add_network");
- if(su.execute() == 0){
- String out = su.getOutput();
- if (out == null || out.trim().equals("")){
- return null;
- }
- else {
- return out.replace("\n", "");
- }
- }
- else {
- return null;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while creating network", e);
- return null;
- }
-
- }
-
- private boolean destroyNetwork(){
- //needs root (tested)
- return executeRootCmd("ndc network destroy 1");
- }
-
- private boolean setNetworkSSID(String ssid, String networkID){
-
- try {
-
- //needs root (wpa_cli)
- RootCommand su = new RootCommand(getCmdWpaCli() + " set_network " + networkID + " ssid '\"" + ssid + "\"'" );
- if (su.execute() == 0){
- String out = su.getOutput();
- if (out != null && out.trim().replace("\n", "").equals("OK")){
- return true;
- }else {
- return false;
- }
- }
- else{
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while setting network SSID", e);
- return false;
- }
-
- }
-
- private boolean setNetworkPSK(AccessPointInfo info, String networkID){
-
- try {
-
- //needs root (wpa_cli)
-
- String cmdSetPass = null;
- if (info.needsPassword()){
- cmdSetPass = getCmdWpaCli() + " set_network " + networkID + " psk '\"" + info.getPassword() + "\"'";
- }
- else{
- cmdSetPass = getCmdWpaCli() + " set_network " + networkID + " key_mgmt NONE";
- }
-
- RootCommand su = new RootCommand(cmdSetPass);
- if (su.execute() == 0){
- String out = su.getOutput();
- if (out != null && out.trim().replace("\n", "").equals("OK")){
- return true;
- }else {
- return false;
- }
- }
- else{
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while setting network PSK", e);
- return false;
- }
-
-
- }
-
- private boolean selectNetwork(String networkID){
-
- try {
-
- //needs root (wpa_cli)
- RootCommand su = new RootCommand(getCmdWpaCli() + " select_network " + networkID);
- if (su.execute() == 0){
- String out = su.getOutput();
- if (out != null && out.trim().replace("\n", "").equals("OK")){
- return true;
- }else {
- return false;
- }
- }
- else{
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while selecting network", e);
- return false;
- }
-
- }
-
- private boolean enableNetwork(String networkID){
-
- try {
-
- //needs root (wpa_cli)
-
- RootCommand su = new RootCommand(getCmdWpaCli() + " enable_network " + networkID);
- if (su.execute() == 0){
- String out = su.getOutput();
- if (out != null && out.trim().replace("\n", "").equals("OK")){
- return true;
- }else {
- return false;
- }
- }
- else{
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while enabling network", e);
- return false;
- }
-
- }
-
- private boolean reassociate(){
-
- try {
-
- //needs root (wpa_cli)
-
- RootCommand su = new RootCommand(getCmdWpaCli() + " reassociate");
- if (su.execute() == 0){
- String out = su.getOutput();
- if (out != null && out.trim().replace("\n", "").equals("OK")){
- return true;
- }else {
- return false;
- }
- }
- else{
- return false;
- }
-
- } catch (Exception e) {
- Utils.logError("Error while reassociating network", e);
- return false;
- }
-
- }
-
- private String getGateway(){
-
- try {
-
- //doesn't need root (tested)
- ShellCommand cmd = new ShellCommand("ip route show dev " + Commons.INTERFACE_NAME);
- if (cmd.execute() != 0){
- Utils.logDebug("command failed show route");
- return null;
- }
-
- //read command output
- String out = cmd.getOutput();
- if (out == null){
- return null;
- }
-
- String[] lines = out.split("\n");
-
- for (String l : lines){
-
- if (l.contains("default via")){
-
- String[] f = l.split(" ");
- if (f.length > 2){
-
- //found route's address:
- return f[2];
-
- }
- }
- }
-
- return null;
-
- } catch (Exception e) {
- Utils.logError("Error while trying to fetch route",e);
- return null;
- }
-
- }
-
- private boolean clearAddrs(){
- //needs root (tested)
- return executeRootCmd("ndc interface clearaddrs " + Commons.INTERFACE_NAME);
- }
-
} \ No newline at end of file
diff --git a/app/src/fil/libre/repwifiapp/helpers/IEngine.java b/app/src/fil/libre/repwifiapp/helpers/IEngine.java
index 1e33f1c..037cf62 100644
--- a/app/src/fil/libre/repwifiapp/helpers/IEngine.java
+++ b/app/src/fil/libre/repwifiapp/helpers/IEngine.java
@@ -20,25 +20,26 @@
package fil.libre.repwifiapp.helpers;
+import java.net.SocketException;
public interface IEngine {
-
- public boolean startWpaSupplicant();
-
- public boolean killPreviousConnections();
-
- public boolean clearWorkingDir();
-
- public AccessPointInfo[] getAvailableNetworks();
-
- public boolean connect(AccessPointInfo info);
-
- public boolean disconnect();
-
- public ConnectionStatus getConnectionStatus();
-
- public boolean isInterfaceAvailable(String ifaceName);
-
- public String[] getAvailableInterfaces();
-
+
+ public boolean startWpaSupplicant();
+
+ public boolean killBackEndProcesses();
+
+ public boolean clearWorkingDir();
+
+ public AccessPointInfo[] getAvailableNetworks();
+
+ public boolean connect(AccessPointInfo info);
+
+ public boolean disconnect();
+
+ public ConnectionStatus getConnectionStatus();
+
+ public boolean isInterfaceAvailable(String ifaceName) throws SocketException;
+
+ public String[] getAvailableInterfaces();
+
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/NetworkButton.java b/app/src/fil/libre/repwifiapp/helpers/NetworkButton.java
index 9a7c523..7d0bdf9 100644
--- a/app/src/fil/libre/repwifiapp/helpers/NetworkButton.java
+++ b/app/src/fil/libre/repwifiapp/helpers/NetworkButton.java
@@ -23,19 +23,17 @@ package fil.libre.repwifiapp.helpers;
import android.content.Context;
import android.widget.Button;
-public class NetworkButton extends Button{
+public class NetworkButton extends Button {
+
+ private String _bssid = "";
+
+ public NetworkButton(Context context, String networkBSSID) {
+ super(context);
+ this._bssid = networkBSSID;
+ }
+
+ public String getNetworkBSSID() {
+ return this._bssid;
+ }
- private String _bssid = "";
-
- public NetworkButton(Context context, String networkBSSID){
- super(context);
- this._bssid = networkBSSID;
- }
-
- public String getNetworkBSSID(){
- return this._bssid;
- }
-
-
-
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/NetworkManager.java b/app/src/fil/libre/repwifiapp/helpers/NetworkManager.java
index 33acbb7..db27f7e 100644
--- a/app/src/fil/libre/repwifiapp/helpers/NetworkManager.java
+++ b/app/src/fil/libre/repwifiapp/helpers/NetworkManager.java
@@ -25,272 +25,282 @@ import java.util.ArrayList;
public class NetworkManager {
- private static final String F_SEP = "\t";
- private static final int NET_MAX_AGE = 365; //Expressed in days
-
- private String _knownNetworksFile = null;
-
- public NetworkManager(String networksFilePath){
- this._knownNetworksFile = networksFilePath;
- }
-
- private AccessPointInfo searchInFile(AccessPointInfo i){
-
- if (i == null){
- return null;
- }
-
- String bssid = i.getBSSID();
- String ssid = i.getSSID();
-
- if (bssid == null || ssid == null || bssid.trim().equals("") || ssid.trim().equals("")){
- return null;
- }
-
- AccessPointInfo ret = null;
- AccessPointInfo[] list = getKnownNetworks();
-
- if (list == null){
- return null;
- }
-
- for(AccessPointInfo toTest : list){
-
- // try to match both bssid and ssid.
- // if bssid doesn't match, but ssid does,
- // then the network is a candidate.
- // if no bssid equality is found,
- // then return the best match (only ssid), if any
- if (toTest.getSSID().equals(ssid)){
-
- if (toTest.getBSSID().equals(bssid)){
- i.setPassword(toTest.getPassword());
- return i;
-
- }else{
- i.setPassword(toTest.getPassword());
- ret = i;
- }
-
- }
-
- }
-
- return ret;
-
- }
-
- private boolean saveOrRemove(AccessPointInfo info, boolean save){
-
- String iText = InfoToString(info);
- if (iText == null){
- return false;
- }
-
- AccessPointInfo[] existingNets = getKnownNetworks();
-
- ArrayList<AccessPointInfo> newlist = new ArrayList<AccessPointInfo>();
-
- if (existingNets == null || existingNets.length == 0){
- //no existing storage yet, create it
-
- if (save){
- //set timestamp
- info.setLastTimeUsed(System.currentTimeMillis());
- newlist.add(info);
- AccessPointInfo[] newContents = new AccessPointInfo[newlist.size()];
- newContents = newlist.toArray(newContents);
-
- return saveList(newContents);
-
- }else{
- //nothing to do, return
- return true;
- }
-
- }
-
-
- if (save){
- //add the updated info to the storage
- info.setLastTimeUsed(System.currentTimeMillis());
- newlist.add(info);
- }
-
- for(AccessPointInfo old : existingNets){
-
- if (old == null){
- //error while loading from file. skip.
- continue;
- }
-
- // keep network only if it's not older than the max age for a network
- else if (old.isOlderThan(NET_MAX_AGE)){
- //skip it
- continue;
- }
-
- else if (old.getBSSID().equals(info.getBSSID()) && old.getSSID().equals(info.getSSID())){
- //found previously saved entry for the same network we are managing
- //skip it
- continue;
- }
-
- else{
- //old network info that can be kept in the storage
- newlist.add(old);
- }
-
- }
-
-
- AccessPointInfo[] newContents = new AccessPointInfo[newlist.size()];
- newContents = newlist.toArray(newContents);
-
- return saveList(newContents);
-
- }
-
- private AccessPointInfo getFromString(String savedString){
-
- if (savedString == null || savedString.trim().equals("")) {
- return null;
- }
-
- String[] fields = savedString.split(F_SEP);
-
- if (fields.length != 4 ){
- return null;
- }
-
- String bssid = fields[0];
- String ssid = fields[1];
- String pass = fields[2];
- String lastUsed = fields[3];
-
- long lastusedmillis = 0;
- try {
- lastusedmillis = Long.parseLong(lastUsed);
- } catch (NumberFormatException e) {
- //invalid format
- Utils.logError("Invalid time format in network manager \""+lastUsed +"\". Network BSSID: " + bssid, e);
- }
-
- if (bssid.trim().equals("") || ssid.trim().equals("") || pass.trim().equals("")){
- return null;
- }
-
- AccessPointInfo i = new AccessPointInfo(ssid, bssid, null, null, null);
- i.setPassword(pass);
- i.setLastTimeUsed(lastusedmillis);
-
- return i;
-
- }
-
- private String InfoToString(AccessPointInfo info){
-
- if (info == null){
- return null;
- }
-
- String bssid = info.getBSSID();
- String ssid = info.getSSID();
- String pass = info.getPassword();
- String tsLastUsed = "" + info.getLastTimeUsed();
-
- if (bssid == null || bssid.trim().equals("")){
- return null;
- }
-
- if (ssid == null || ssid.trim().equals("")){
- return null;
- }
-
- if (pass == null || pass.trim().equals("")){
- return null;
- }
-
- String iText = info.getBSSID() + F_SEP + info.getSSID() + F_SEP + info.getPassword() + F_SEP + tsLastUsed;
- return iText;
-
- }
-
- private boolean saveList(AccessPointInfo[] list){
-
- if (list == null){
- return false;
- }
-
- String[] lines = new String[list.length];
-
- for (int i = 0; i<list.length; i++){
-
- String storeString = InfoToString(list[i]);
- if (storeString == null){
- return false;
- }
- lines[i] = storeString;
-
- }
-
- return Utils.writeFileLines(this._knownNetworksFile,lines, true);
-
- }
-
- public AccessPointInfo[] getKnownNetworks(){
-
- ArrayList<AccessPointInfo> list = new ArrayList<AccessPointInfo>();
-
- File f = new File(this._knownNetworksFile);
- if (! f.exists()){
- return null;
- }
-
- String[] lines = Utils.readFileLines(_knownNetworksFile);
- if (lines == null || lines.length == 0){
- return null;
- }
-
- for(String l : lines){
-
- AccessPointInfo info = getFromString(l);
- if (info != null){
- list.add(info);
- }
-
- }
-
- AccessPointInfo[] ret = new AccessPointInfo[list.size()];
- ret = list.toArray(ret);
-
- return ret;
-
- }
-
- public boolean isKnown(AccessPointInfo info){
-
- AccessPointInfo i = searchInFile(info);
- if (i == null){
- return false;
- }else {
- return true;
- }
-
- }
-
- public boolean save(AccessPointInfo info){
- return saveOrRemove(info, true);
- }
-
- public boolean remove(AccessPointInfo info){
- return saveOrRemove(info, false);
- }
-
- public AccessPointInfo getSavedNetwork(AccessPointInfo i){
- return searchInFile(i);
- }
-
-
-
+ private static final String F_SEP = "\t";
+ private static final int NET_MAX_AGE = 365; // Expressed in days
+
+ private String _knownNetworksFile = null;
+
+ public NetworkManager(String networksFilePath) {
+ this._knownNetworksFile = networksFilePath;
+ }
+
+ private AccessPointInfo searchInFile(AccessPointInfo i) {
+
+ if (i == null) {
+ return null;
+ }
+
+ String bssid = i.getBssid();
+ String ssid = i.getSsid();
+
+ if (bssid == null || ssid == null || bssid.trim().equals("") || ssid.trim().equals("")) {
+ return null;
+ }
+
+ AccessPointInfo ret = null;
+ AccessPointInfo[] list = getKnownNetworks();
+
+ if (list == null) {
+ return null;
+ }
+
+ for (AccessPointInfo toTest : list) {
+
+ // try to match both bssid and ssid.
+ // if bssid doesn't match, but ssid does,
+ // then the network is a candidate.
+ // if no bssid equality is found,
+ // then return the best match (only ssid), if any
+ if (toTest.getSsid().equals(ssid)) {
+
+ if (toTest.getBssid().equals(bssid)) {
+ i.setPassword(toTest.getPassword());
+ return i;
+
+ } else {
+ i.setPassword(toTest.getPassword());
+ ret = i;
+ }
+
+ }
+
+ }
+
+ return ret;
+
+ }
+
+ private boolean saveOrRemove(AccessPointInfo info, boolean save) {
+
+ String iText = InfoToString(info);
+ if (iText == null) {
+ return false;
+ }
+
+ AccessPointInfo[] existingNets = getKnownNetworks();
+
+ ArrayList<AccessPointInfo> newlist = new ArrayList<AccessPointInfo>();
+
+ if (existingNets == null || existingNets.length == 0) {
+ // no existing storage yet, create it
+
+ if (save) {
+ // set timestamp
+ info.setLastTimeUsed(System.currentTimeMillis());
+ newlist.add(info);
+ AccessPointInfo[] newContents = new AccessPointInfo[newlist.size()];
+ newContents = newlist.toArray(newContents);
+
+ return saveList(newContents);
+
+ } else {
+ // nothing to do, return
+ return true;
+ }
+
+ }
+
+ if (save) {
+ // add the updated info to the storage
+ info.setLastTimeUsed(System.currentTimeMillis());
+ newlist.add(info);
+ }
+
+ for (AccessPointInfo old : existingNets) {
+
+ if (old == null) {
+ // error while loading from file. skip.
+ continue;
+ }
+
+ // keep network only if it's not older than the max age for a
+ // network
+ else if (old.isOlderThan(NET_MAX_AGE)) {
+ // skip it
+ continue;
+ }
+
+ else if (old.getBssid().equals(info.getBssid()) && old.getSsid().equals(info.getSsid())) {
+ // found previously saved entry for the same network we are
+ // managing
+ // skip it
+ continue;
+ }
+
+ else {
+ // old network info that can be kept in the storage
+ newlist.add(old);
+ }
+
+ }
+
+ AccessPointInfo[] newContents = new AccessPointInfo[newlist.size()];
+ newContents = newlist.toArray(newContents);
+
+ return saveList(newContents);
+
+ }
+
+ private AccessPointInfo getFromString(String savedString) {
+
+ if (savedString == null || savedString.trim().equals("")) {
+ return null;
+ }
+
+ String[] fields = savedString.split(F_SEP);
+
+ if (fields.length < 4) {
+ return null;
+ }
+
+ String bssid = fields[0];
+ String ssid = fields[1];
+ String pass = fields[2];
+ String lastUsed = fields[3];
+ String auth = null;
+
+ if (fields.length > 4) {
+ auth = fields[4];
+ }
+
+ long lastusedmillis = 0;
+ try {
+ lastusedmillis = Long.parseLong(lastUsed);
+ } catch (NumberFormatException e) {
+ // invalid format
+ Utils.logError("Invalid time format in network manager \"" + lastUsed
+ + "\". Network BSSID: " + bssid, e);
+ }
+
+ if (bssid.trim().equals("") || ssid.trim().equals("") || pass.trim().equals("")) {
+ return null;
+ }
+
+ AccessPointInfo i = new AccessPointInfo(ssid, bssid, auth, null, null);
+ i.setPassword(pass);
+ i.setLastTimeUsed(lastusedmillis);
+
+ return i;
+
+ }
+
+ private String InfoToString(AccessPointInfo info) {
+
+ if (info == null) {
+ return null;
+ }
+
+ String bssid = info.getBssid();
+ String ssid = info.getSsid();
+ String pass = info.getPassword();
+ String tsLastUsed = "" + info.getLastTimeUsed();
+ String auth = info.getAuthType();
+
+ if (bssid == null || bssid.trim().equals("")) {
+ return null;
+ }
+
+ if (ssid == null || ssid.trim().equals("")) {
+ return null;
+ }
+
+ if (pass == null || pass.trim().equals("")) {
+ return null;
+ }
+
+ if (auth == null) {
+ auth = "";
+ }
+
+ String iText = info.getBssid() + F_SEP + info.getSsid() + F_SEP + info.getPassword()
+ + F_SEP + tsLastUsed + F_SEP + auth;
+ return iText;
+
+ }
+
+ private boolean saveList(AccessPointInfo[] list) {
+
+ if (list == null) {
+ return false;
+ }
+
+ String[] lines = new String[list.length];
+
+ for (int i = 0; i < list.length; i++) {
+
+ String storeString = InfoToString(list[i]);
+ if (storeString == null) {
+ return false;
+ }
+ lines[i] = storeString;
+
+ }
+
+ return Utils.writeFileLines(this._knownNetworksFile, lines, true);
+
+ }
+
+ public AccessPointInfo[] getKnownNetworks() {
+
+ ArrayList<AccessPointInfo> list = new ArrayList<AccessPointInfo>();
+
+ File f = new File(this._knownNetworksFile);
+ if (!f.exists()) {
+ return null;
+ }
+
+ String[] lines = Utils.readFileLines(_knownNetworksFile);
+ if (lines == null || lines.length == 0) {
+ return null;
+ }
+
+ for (String l : lines) {
+
+ AccessPointInfo info = getFromString(l);
+ if (info != null) {
+ list.add(info);
+ }
+
+ }
+
+ AccessPointInfo[] ret = new AccessPointInfo[list.size()];
+ ret = list.toArray(ret);
+
+ return ret;
+
+ }
+
+ public boolean isKnown(AccessPointInfo info) {
+
+ AccessPointInfo i = searchInFile(info);
+ if (i == null) {
+ return false;
+ } else {
+ return true;
+ }
+
+ }
+
+ public boolean save(AccessPointInfo info) {
+ return saveOrRemove(info, true);
+ }
+
+ public boolean remove(AccessPointInfo info) {
+ return saveOrRemove(info, false);
+ }
+
+ public AccessPointInfo getSavedNetwork(AccessPointInfo i) {
+ return searchInFile(i);
+ }
+
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/RootCommand.java b/app/src/fil/libre/repwifiapp/helpers/RootCommand.java
index bcb6d0f..9d9f7d3 100644
--- a/app/src/fil/libre/repwifiapp/helpers/RootCommand.java
+++ b/app/src/fil/libre/repwifiapp/helpers/RootCommand.java
@@ -19,91 +19,75 @@
// ********************************************************************
package fil.libre.repwifiapp.helpers;
-import java.io.BufferedReader;
+
import java.io.DataOutputStream;
import java.io.InputStream;
-import java.io.InputStreamReader;
-
import fil.libre.repwifiapp.Commons;
-public class RootCommand {
-
- private String _cmdOut = "";
- private String _cmdTxt = "";
-
- public RootCommand(String commandText){
- this._cmdTxt = commandText;
- }
-
- public int execute() throws Exception{
- return execute(0);
- }
-
- public int execute(int sleepSecsAfterCmd) throws Exception{
-
- Process su = Runtime.getRuntime().exec("su");
-
- DataOutputStream stdin = new DataOutputStream(su.getOutputStream());
- InputStream os = su.getInputStream();
- BufferedReader stdOut = new BufferedReader(new InputStreamReader(os));
- InputStream es = su.getErrorStream();
- BufferedReader stdError = new BufferedReader(new InputStreamReader(es));
-
- if ( this._cmdTxt != null ){
-
- Utils.logDebug("SU:EXEC: " + this._cmdTxt);
-
- this._cmdTxt += " > " + Commons.getTempOutFile();
-
- stdin.writeBytes(this._cmdTxt + "\n");
- stdin.flush();
- }
-
- /* if (sleepSecsAfterCmd > 0){
- Thread.sleep(sleepSecsAfterCmd * 1000);
- }*/
-
- StringBuilder sb = new StringBuilder();
- String s = null;
-
- while ( (es.available() > 0) && (s = stdError.readLine()) != null) {
- sb.append(s + "\n");
- }
-
- while ( (os.available() > 0) && (s = stdOut.readLine()) != null) {
- sb.append(s + "\n");
- }
-
- this._cmdOut = sb.toString();
-
- stdin.writeBytes("exit\n");
- stdin.flush();
-
- int res = su.waitFor();
-
- Utils.logDebug("OUT: " + getOutput());
-
- return res;
-
- }
-
- public String getOutput(){
-
- String[] lastOut = Utils.readFileLines(Commons.getTempOutFile());
- if (lastOut == null){
- return this._cmdOut;
- }
-
- String fout = "";
-
- for (String s : lastOut){
- fout += s + "\n";
- }
-
- return fout;
-
- }
-
-
-
+public class RootCommand extends ShellCommand {
+
+ public RootCommand(String commandText) {
+ super(commandText);
+ this._cmdTxt = commandText;
+ }
+
+ @Override
+ public int execute() throws Exception {
+
+ Process su = Runtime.getRuntime().exec("su");
+
+ DataOutputStream stdin = new DataOutputStream(su.getOutputStream());
+ InputStream os = su.getInputStream();
+ InputStream es = su.getErrorStream();
+
+ if (this._cmdTxt != null) {
+
+ Utils.logDebug("SU:EXEC: " + this._cmdTxt);
+
+ this._cmdTxt += " > " + Commons.getTempOutFile();
+
+ stdin.writeBytes(this._cmdTxt + "\n");
+ stdin.flush();
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(getStringFromStream(es));
+ sb.append(getStringFromStream(os));
+
+ this._cmdOut = sb.toString();
+
+ stdin.writeBytes("exit\n");
+ stdin.flush();
+
+ int res = su.waitFor();
+
+ // re-read the output, in case it was empty when first tried
+ sb.append(getStringFromStream(es));
+ sb.append(getStringFromStream(os));
+
+ Utils.logDebug("OUT: " + getOutput());
+
+ return res;
+
+ }
+
+ @Override
+ public String getOutput() {
+
+ String[] lastOut = Utils.readFileLines(Commons.getTempOutFile());
+ if (lastOut == null) {
+ return this._cmdOut;
+ }
+
+ String fout = "";
+
+ for (String s : lastOut) {
+ fout += s + "\n";
+ }
+
+ return fout;
+
+ }
+
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java b/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
index e2004a7..fbeb719 100644
--- a/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
+++ b/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
@@ -4,82 +4,78 @@ import java.io.IOException;
import java.io.InputStream;
public class ShellCommand {
-
- private String _cmdOut = "";
- private String _cmdTxt = "";
-
- public ShellCommand(String commandText){
- this._cmdTxt = commandText;
- }
-
-
- public int execute() throws Exception{
-
- if ( this._cmdTxt == null ){
- return -9;
- }
-
- Utils.logDebug("EXEC: " + this._cmdTxt);
-
- Process cmd = Runtime.getRuntime().exec(this._cmdTxt);
-
- InputStream os = cmd.getInputStream();
- InputStream es = cmd.getErrorStream();
-
- StringBuilder sb = new StringBuilder();
-
- sb.append(getStringFromStream(es));
- sb.append(getStringFromStream(os));
-
- int res = cmd.waitFor();
-
- //re-read the output, in case it was empty when first tried
- sb.append(getStringFromStream(es));
- sb.append(getStringFromStream(os));
-
- this._cmdOut = sb.toString();
-
- Utils.logDebug("EXITCODE: " + res);
- Utils.logDebug("OUT: " + getOutput());
-
- return res;
-
- }
-
- private String getStringFromStream(InputStream s) throws IOException{
-
- StringBuilder sb = new StringBuilder();
- while ( (s.available() > 0) ) {
- int b = s.read();
- if (b>=0){
- sb.append((char)b);
- }else{
- break;
- }
- }
-
- return sb.toString();
-
- }
-
-
- public String getOutput(){
-
- return this._cmdOut;
-
- /*String[] lastOut = Utils.readFileLines(Commons.getTempOutFile());
- if (lastOut == null){
- return this._cmdOut;
- }
-
- String fout = "";
-
- for (String s : lastOut){
- fout += s + "\n";
- }
-
- return fout;*/
-
- }
+
+ protected String _cmdOut = "";
+ protected String _cmdTxt = "";
+
+ public ShellCommand(String commandText) {
+ this._cmdTxt = commandText;
+ }
+
+ public int execute() throws Exception {
+
+ if (this._cmdTxt == null) {
+ return -9;
+ }
+
+ Utils.logDebug("EXEC: " + this._cmdTxt);
+
+ Process cmd = Runtime.getRuntime().exec(this._cmdTxt);
+
+ InputStream os = cmd.getInputStream();
+ InputStream es = cmd.getErrorStream();
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(getStringFromStream(es));
+ sb.append(getStringFromStream(os));
+
+ int res = cmd.waitFor();
+
+ // re-read the output, in case it was empty when first tried
+ sb.append(getStringFromStream(es));
+ sb.append(getStringFromStream(os));
+
+ this._cmdOut = sb.toString();
+
+ Utils.logDebug("EXITCODE: " + res);
+ Utils.logDebug("OUT: " + getOutput());
+
+ return res;
+
+ }
+
+ protected String getStringFromStream(InputStream s) throws IOException {
+
+ StringBuilder sb = new StringBuilder();
+ while ((s.available() > 0)) {
+ int b = s.read();
+ if (b >= 0) {
+ sb.append((char) b);
+ } else {
+ break;
+ }
+ }
+
+ return sb.toString();
+
+ }
+
+ public String getOutput() {
+
+ return this._cmdOut;
+
+ /*
+ * String[] lastOut = Utils.readFileLines(Commons.getTempOutFile()); if
+ * (lastOut == null){ return this._cmdOut; }
+ *
+ * String fout = "";
+ *
+ * for (String s : lastOut){ fout += s + "\n"; }
+ *
+ * return fout;
+ */
+
+ }
}
diff --git a/app/src/fil/libre/repwifiapp/helpers/Utils.java b/app/src/fil/libre/repwifiapp/helpers/Utils.java
index d30eb2e..8cd90bf 100644
--- a/app/src/fil/libre/repwifiapp/helpers/Utils.java
+++ b/app/src/fil/libre/repwifiapp/helpers/Utils.java
@@ -32,175 +32,171 @@ import android.util.Log;
public class Utils {
- private static final long MILLIS_IN_DAY = 86400000;
-
- public static final String APP_NAME = "RepWifi";
-
- private static Exception _lastException = null;
-
- public static Exception getLastException(){
- return _lastException;
- }
-
- public static void logError(String msg, Exception e){
- Log.e(APP_NAME,msg,e);
- }
-
- public static void logError(String msg){
- Log.e(APP_NAME,msg);
- }
-
- public static void logDebug(String msg){
- logDebug(msg,0);
- }
-
- public static void logDebug(String msg, int level){
-
- if (level < Commons.getLogPriority()){
- return;
- }
-
- Log.d(APP_NAME,msg);
- }
-
-
- public static boolean writeFile(String filePath, String text, boolean overwrite){
-
- FileWriter writer = null;
- boolean retval = false;
-
- try {
-
- writer = new FileWriter(filePath, (! overwrite));
- writer.write(text);
-
- retval = true;
-
- } catch (Exception e) {
- _lastException = e;
- retval = false;
- }
- finally{
-
- if (writer != null){
- try {
- writer.close();
- } catch (IOException e) {
- logError("error while closing filewriter",e);
- }
- }
-
- }
-
- return retval;
-
- }
-
- public static boolean writeFileLines(String filePath, String[] lines, boolean overwrite){
-
- if (lines == null){
- return false;
- }
-
- FileWriter writer = null;
- boolean retval = false;
-
- try {
-
- writer = new FileWriter(filePath, (! overwrite));
-
- if (lines.length == 0){
- writer.write("");
- }
-
- for(String l : lines){
- writer.write(l + "\n");
- }
-
- retval = true;
-
- } catch (Exception e) {
- _lastException = e;
- retval = false;
- }
- finally{
-
- if (writer != null){
- try {
- writer.close();
- } catch (IOException e) {
- logError("error while closing filewriter",e);
- }
- }
-
- }
-
- return retval;
-
- }
-
- public static String[] readFileLines(String filePath){
-
- if (filePath == null){
- return null;
- }
-
- File f = new File(filePath);
- if (! f.exists()){
- logError("File doesn't exist: " + filePath);
- return null;
- }
-
- FileReader fr = null;
+ private static final long MILLIS_IN_DAY = 86400000;
+
+ public static final String APP_NAME = "RepWifi";
+
+ private static Exception _lastException = null;
+
+ public static Exception getLastException() {
+ return _lastException;
+ }
+
+ public static void logError(String msg, Exception e) {
+ Log.e(APP_NAME, msg, e);
+ }
+
+ public static void logError(String msg) {
+ Log.e(APP_NAME, msg);
+ }
+
+ public static void logDebug(String msg) {
+ logDebug(msg, 0);
+ }
+
+ public static void logDebug(String msg, int level) {
+
+ if (level < Commons.getLogPriority()) {
+ return;
+ }
+
+ Log.d(APP_NAME, msg);
+ }
+
+ public static boolean writeFile(String filePath, String text, boolean overwrite) {
+
+ FileWriter writer = null;
+ boolean retval = false;
+
+ try {
+
+ writer = new FileWriter(filePath, (!overwrite));
+ writer.write(text);
+
+ retval = true;
+
+ } catch (Exception e) {
+ _lastException = e;
+ retval = false;
+ } finally {
+
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ logError("error while closing filewriter", e);
+ }
+ }
+
+ }
+
+ return retval;
+
+ }
+
+ public static boolean writeFileLines(String filePath, String[] lines, boolean overwrite) {
+
+ if (lines == null) {
+ return false;
+ }
+
+ FileWriter writer = null;
+ boolean retval = false;
+
+ try {
+
+ writer = new FileWriter(filePath, (!overwrite));
+
+ if (lines.length == 0) {
+ writer.write("");
+ }
+
+ for (String l : lines) {
+ writer.write(l + "\n");
+ }
+
+ retval = true;
+
+ } catch (Exception e) {
+ _lastException = e;
+ retval = false;
+ } finally {
+
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ logError("error while closing filewriter", e);
+ }
+ }
+
+ }
+
+ return retval;
+
+ }
+
+ public static String[] readFileLines(String filePath) {
+
+ if (filePath == null) {
+ return null;
+ }
+
+ File f = new File(filePath);
+ if (!f.exists()) {
+ logError("File doesn't exist: " + filePath);
+ return null;
+ }
+
+ FileReader fr = null;
BufferedReader bufr = null;
-
+
List<String> lines = new ArrayList<String>();
String[] ret = null;
-
- try {
-
- fr = new FileReader(filePath);
- bufr = new BufferedReader(fr);
- String line ="";
-
- while((line = bufr.readLine()) != null){
- lines.add(line);
- }
-
- String[] ar = new String[lines.size()];
- ret = lines.toArray(ar);
-
- } catch (Exception e) {
- logError("Error while reading file " + filePath,e);
- ret = null;
- }
- finally{
- try {
- if (bufr != null){
- bufr.close();
- }
- } catch (IOException ex) {
- logError("error while closing filereader",ex);
- }
- try {
- if (fr != null){
- fr.close();
- }
- }catch(IOException exc){
- logError("error while closing filereader",exc);
- }
- }
-
- return ret;
-
- }
-
- public static long daysToMilliseconds(int days){
- return (days * MILLIS_IN_DAY);
- }
-
- public static long millisecondsToDays(long milliseconds){
- return (milliseconds / MILLIS_IN_DAY);
- }
-
+
+ try {
+
+ fr = new FileReader(filePath);
+ bufr = new BufferedReader(fr);
+ String line = "";
+
+ while ((line = bufr.readLine()) != null) {
+ lines.add(line);
+ }
+
+ String[] ar = new String[lines.size()];
+ ret = lines.toArray(ar);
+
+ } catch (Exception e) {
+ logError("Error while reading file " + filePath, e);
+ ret = null;
+ } finally {
+ try {
+ if (bufr != null) {
+ bufr.close();
+ }
+ } catch (IOException ex) {
+ logError("error while closing filereader", ex);
+ }
+ try {
+ if (fr != null) {
+ fr.close();
+ }
+ } catch (IOException exc) {
+ logError("error while closing filereader", exc);
+ }
+ }
+
+ return ret;
+
+ }
+
+ public static long daysToMilliseconds(int days) {
+ return (days * MILLIS_IN_DAY);
+ }
+
+ public static long millisecondsToDays(long milliseconds) {
+ return (milliseconds / MILLIS_IN_DAY);
+ }
+
}