first add sdk

This commit is contained in:
jialexd 2019-04-02 16:34:25 +08:00
commit f91efd1250
3915 changed files with 1291882 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,6 @@
The exe file is used to send image to device based on socket by OTA function.
Command :
DownloadServer "PORT" "FILE_PATH"
You can edit start.bat to change port and file path.

3
tools/DownloadServer/start.bat Executable file
View file

@ -0,0 +1,3 @@
@echo off
DownloadServer 8082 ota.bin
set /p DUMMY=Press Enter to Continue ...

View file

@ -0,0 +1,13 @@
Use the combine tool to generate the alc5680 firmware upgrade file.
This tool will add extra information to the binary.It will include the checksum,file length and version.
Step1.
Copy the alc5680 firmware to this folder and cheange the filename to All_in_one.dat
Step2
Execute the alc_fw_upgrade.bat and it will generate the alc_fw_upgrade.bin file.
How to upgrade the file, please reference the UM151 document.

View file

@ -0,0 +1 @@
START .\alc_fw_upgrade.exe All_in_one.dat alc_fw_upgrade.bin

Binary file not shown.

144
tools/autopatch/auto_patch.bat Executable file
View file

@ -0,0 +1,144 @@
@echo off
setlocal enableDelayedExpansion
REM patch files to sdk (for customer)
REM Owen Chiu
echo ... patch files to sdk ...
set FILE_LIST=patch_list
set SDK_PATH=..\..
set UNZIP_PATH=unzip_tmp
echo Please drag in the patch file you want to use:
set /p PATCH_PATH=
if NOT "%PATCH_PATH:~-4%" == ".zip" (
echo Not zip file
pause
exit /b
)
if exist %UNZIP_PATH% rmdir %UNZIP_PATH% /s/q
mkdir %UNZIP_PATH%
call :getFileName %PATCH_PATH:~0,-4% PATCH_NAME
REM unzip patch file
echo Unzip %PATCH_NAME%
call :genUnzipScript
CScript _unzip.vbs %PATCH_PATH% %UNZIP_PATH%
if NOT exist %UNZIP_PATH%\%FILE_LIST% (
echo patch_list not included in the patch file, cannot use auto patch
if exist %UNZIP_PATH% rmdir %UNZIP_PATH% /s/q
del _unzip.vbs /q
pause
exit /b
)
for /f "skip=1 delims=" %%i in (%UNZIP_PATH%\%FILE_LIST%) do (
set line=%%i
if "!line:~-1!" == "\" (
REM is directory
call :getFileName !line:~0,-1! DIR_NAME
xcopy "%UNZIP_PATH%\!DIR_NAME!\*.*" "%SDK_PATH%\%%i" /e/y
) else (
REM is file
call :getFileName !line! FILE_NAME
call :getPrefix %%i PREFIX_PATH
xcopy "%UNZIP_PATH%\!FILE_NAME!" "%SDK_PATH%\!PREFIX_PATH!\" /y
)
)
if exist %UNZIP_PATH% rmdir %UNZIP_PATH% /s/q
del _unzip.vbs /q
echo.
echo Patch %PATCH_NAME% done
pause
exit /b
:genUnzipScript
echo Set objArgs = WScript.Arguments > _unzip.vbs
echo ZipFile=objArgs(0) >> _unzip.vbs
echo ExtractTo=objArgs(1)>> _unzip.vbs
echo Set fso = CreateObject("Scripting.FileSystemObject") >> _unzip.vbs
echo If NOT fso.FolderExists(ExtractTo) Then >> _unzip.vbs
echo fso.CreateFolder(ExtractTo) >> _unzip.vbs
echo End If >> _unzip.vbs
echo set objShell = CreateObject("Shell.Application") >> _unzip.vbs
echo set FilesInZip=objShell.NameSpace(ZipFile).items >> _unzip.vbs
echo objShell.NameSpace(fso.GetAbsolutePathName(ExtractTo)).CopyHere(FilesInZip) >> _unzip.vbs
echo Set fso = Nothing >> _unzip.vbs
echo Set objShell = Nothing >> _unzip.vbs
goto :eof
:getPrefix
set str=%1
call :lastindexof "%str%" "\"
set /a lastindex=!errorlevel!
set %2=!str:~0,%lastindex%!
goto :eof
:getFileName
set str=%1
call :lastindexof "%str%" "\"
set /a lastindex=!errorlevel!+1
set %2=!str:~%lastindex%!
goto :eof
:lastindexof [%1 - string ; %2 - find last index of ; %3 - if defined will store the result in variable with same name]
setlocal enableDelayedExpansion
set "str=%~1"
set "splitter=%~2"
set LF=^
REM ** Two empty lines are required
echo off
for %%L in ("!LF!") DO (
for /f "delims=" %%R in ("!splitter!") do (
set "var=!str:%%R=%%L!"
)
)
for /f delims^=^" %%P in ("!var!") DO (
set "last_part=%%~P"
)
if "!last_part!" equ "" if "%~3" NEQ "" (
echo "not contained" >2
endlocal
set %~3=-1
exit
) else (
echo "not contained" >2
endlocal
echo -1
)
setlocal DisableDelayedExpansion
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
set $strLen=for /L %%n in (1 1 2) do if %%n==2 (%\n%
for /F "tokens=1,2 delims=, " %%1 in ("!argv!") do (%\n%
set "str=A!%%~2!"%\n%
set "len=0"%\n%
for /l %%A in (12,-1,0) do (%\n%
set /a "len|=1<<%%A"%\n%
for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A"%\n%
)%\n%
for %%v in (!len!) do endlocal^&if "%%~b" neq "" (set "%%~1=%%v") else echo %%v%\n%
) %\n%
) ELSE setlocal enableDelayedExpansion ^& set argv=,
%$strlen% strlen,str
%$strlen% plen,last_part
%$strlen% slen,splitter
set /a lio=strlen-plen-slen
REM endlocal & if "%~3" NEQ "" (set %~3=%lio%) else echo %lio%
exit /b %lio%

View file

@ -0,0 +1,68 @@
#include "autoconf.h"
#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B)
#include <flash/stm32_flash.h>
#if defined(STM32F2XX)
#include <stm32f2xx_flash.h>
#elif defined(STM32F4XX)
#include <stm32f4xx_flash.h>
#elif defined(STM32f1xx)
#include <stm32f10x_flash.h>
#endif
#include "cloud_updater.h"
#else
#include "flash_api.h"
#include "device_lock.h"
#endif
#define BUF_LEN 512
#define CONFIG_MD5_USE_SSL
#ifdef CONFIG_MD5_USE_SSL
#include "md5.h"
#define file_md5_context md5_context
#define file_md5_init(ctx) md5_init(ctx)
#define file_md5_starts(ctx) md5_starts(ctx)
#define file_md5_update(ctx, input, len) md5_update(ctx, input, len)
#define file_md5_finish(ctx, output) md5_finish(ctx, output)
#define file_md5_free(ctx) md5_free(ctx)
#else
#include "rom_md5.h"
#define file_md5_context md5_ctx
#define file_md5_init(ctx) rt_md5_init(ctx)
#define file_md5_starts(ctx)
#define file_md5_update(ctx, input, len) rt_md5_append(ctx, input, len)
#define file_md5_finish(ctx, output) rt_md5_final(output, ctx)
#define file_md5_free(ctx)
#endif
int file_check_sum(uint32_t addr, uint32_t image_len, u8* check_sum)
{
int ret = -1 ;
flash_t flash;
file_md5_context md5;
unsigned char buf[BUF_LEN];
uint32_t read_addr = addr;
int len = 0;
file_md5_init(&md5);
file_md5_starts(&md5);
while(len < image_len){
if ((image_len-len) >= BUF_LEN){
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash, read_addr, BUF_LEN, buf);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
file_md5_update(&md5, buf, BUF_LEN);
}else{
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash, read_addr, (image_len-len), buf);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
file_md5_update(&md5, buf, (image_len-len));
}
len += BUF_LEN;
read_addr = read_addr + BUF_LEN;
}
file_md5_finish(&md5, check_sum);
file_md5_free(&md5);
}

BIN
tools/iperf.exe Executable file

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,70 @@
ChangeLog
----------------------------------------------------------------
2017/07/18 (v3.0.4)
-Support new AP profile command at configured state
2017/02/22 (v3.0.3)
-Refined soft AP SSID
2016/10/06 (v3.0.2)
-Refined soft AP SSID
2016/08/30 (v3.0.1)
-Refined security with soft AP
2016/08/10 (v3.0.0)
-Refined simple config flow with soft AP
2016/05/23
-Refined simple config flow with PIN code
2016/05/03
-Refined simple config flow
2016/02/22
- Support multiple device
- Scan flow refined after configuration
2016/01/21
- Connection issue fixed when AP is hidden SSID
2016/01/10
- Fixed ssid is empty when AP is hidden SSID
2015/11/11
- Refined wifi connection
2015/09/25
- Refined SimpleConfig ap list and wifi connection
2015/08/15 (v2.0.0)
- Refined simple config
2015/07/23
- device type : 0xff00~0xffff for customer
2015/04/22
- Show one AP of the same SSID multiple APs on AP List by site survey
2015/02/11
- Bug fixed: Reconnection WiFi AP issue.
- Bug fixed: Type transformation for Encryption WiFi profile.
- Re-fine time interval(ms) between sending two packets
2014/10/20
- Re-fine configure flow when DUT receives first UDP packet.
2014/10/01
- Refined if the profile length>127, configure will fail issue.
2014/08/13
- Add Hidden SSID Support
2014/08/04
- Re-fine configure flow
- Re-fine control flow
- Re-fine discovery flow
- Add descriptions of the delay about sending packet
2014/06/19 (v1.0.0)
- Initial Release

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SimpleConfigWizard_R3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

View file

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rtk.simpleconfig_wizard"
android:versionCode="1"
android:versionName="3.0.4.20170718"
android:installLocation="auto">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<!-- wifi usage -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<!-- Camera usage -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<!-- file and SD Card usage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.rtk.simpleconfig_wizard.MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.wifi.connection.MainActivity"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:noHistory="true">
<intent-filter>
<category android:name="android.intent.category.INFO" />
</intent-filter>
<intent-filter>
<action android:name="com.wifi.connection.CONNECT_OR_EDIT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.zxing.activity.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="InflateParams">
<ignore path="src/com/rtk/simpleconfig_wizard/MainActivity.java" />
</issue>
</lint>

View file

@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View file

@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-19

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="45"
android:startColor="#FFFFFF"
android:centerColor="#CCCCCC"
android:endColor="#999999"/>
<!--gradient
android:startColor="#7faacaFF"
android:endColor="#FF80B3FF"
android:gradientRadius="100"
android:type="radial"/-->
<stroke
android:width="2dp"
android:color="#dcdcdc" />
<corners android:radius="5dp" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid android:color="#aaaaaa" />
<stroke
android:width="1dp"
android:color="#666666" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#aaaaaa"
android:endColor="#666666"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#666666" />
<corners
android:radius="4dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

View file

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/layer1_linear1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="#cccccc"
android:layout_weight="1">
<TextView
android:id="@+id/textDeviceTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:layout_weight="5"
android:text=" Configured Device"
android:textColor="#000000"
android:textSize="25dip"/>
<ImageButton
android:id="@+id/btn_scanDevices"
android:contentDescription="@string/app_name"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:scaleType="fitCenter"
android:text="Scan Configured Devices"
android:background="@drawable/btn_new_device"
style="@style/ButtonText"
android:src="@drawable/refresh"
android:adjustViewBounds="true"
android:padding="8dp"
android:onClick="ScanDevices_OnClick"/>
<ImageButton
android:id="@+id/btn_info"
android:contentDescription="@string/app_name"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:scaleType="fitCenter"
android:text="Scan Configured Devices"
android:background="@drawable/btn_new_device"
style="@style/ButtonText"
android:src="@drawable/info"
android:adjustViewBounds="true"
android:padding="8dp"
android:onClick="About_OnClick"/>
</LinearLayout>
<ScrollView
android:id="@+id/layer1_linear2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:background="@drawable/background_scrollview">
<LinearLayout
android:id="@+id/layer2_linear1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/layer1_linear3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<LinearLayout
android:id="@+id/layer2_linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="4">
<Button
android:id="@+id/btn_configNewDevice"
android:contentDescription="@string/app_name"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Configure New Device"
android:textColor="#ffffff"
android:background="@drawable/btn_new_device"
style="@style/ButtonText"
android:onClick="configNewDevice_OnClick"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5sp"
android:id="@+id/add_network_dialog"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="SSID Name: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10sp"
/>
<EditText android:id="@+id/network_name_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="Encryption: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10sp"
/>
<Spinner
android:id="@+id/encrypt_type"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="Password: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10sp"/>
<EditText
android:id="@+id/id_ap_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background_normal"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:inputType="textPassword"
android:textSize="20dp"/>
</LinearLayout>
<CheckBox
android:id="@+id/checkBox_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Password" />
<!-- CheckBox android:id="@+id/is_hidden_ssid"
style="@style/textAppearanceBaseContent"
android:text="Is Hidden SSID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/-->
</LinearLayout>

View file

@ -0,0 +1,178 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Wifi Connector
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5sp"
>
<LinearLayout android:id="@+id/Status"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="@string/wifi_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/Status_TextView"
style="@style/textAppearanceBaseContent"
android:text="@string/status_connected"
android:paddingLeft = "5sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout android:id="@+id/Speed"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="@string/wifi_link_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/LinkSpeed_TextView"
style="@style/textAppearanceBaseContent"
android:text="54Mbps"
android:paddingLeft = "5sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="@string/signal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/SignalStrength_TextView"
style="@style/textAppearanceBaseContent"
android:text="Poor"
android:paddingLeft = "5sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="@string/security"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/Security_TextView"
style="@style/textAppearanceBaseContent"
android:text="WEP"
android:paddingLeft = "5sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout android:id="@+id/IPAddress"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/textAppearanceBaseContent"
android:text="@string/ip_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/IPAddress_TextView"
style="@style/textAppearanceBaseContent"
android:text="192.168.0.1"
android:paddingLeft = "5sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout android:id="@+id/Password"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/Password_TextView"
style="@style/textAppearanceBaseContent"
android:text="@string/please_type_passphrase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10sp"
/>
<com.wifi.connection.ChangingAwareEditText android:id="@+id/Password_EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text|textPassword"/>
<CheckBox android:id="@+id/ShowPassword_CheckBox"
style="@style/textAppearanceBaseContent"
android:text="@string/wifi_show_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,6 @@
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@android:drawable/divider_horizontal_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/dummy_content_description"
android:scaleType="fitXY"/>

View file

@ -0,0 +1,62 @@
<?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="wrap_content"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="4"
android:orientation="horizontal"
android:background="#ffffff">
<!-- ImageView
android:id="@+id/icon_sub"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="2dp"
android:src="@drawable/settings_icon"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" >
</ImageView-->
<TextView
android:id="@+id/customtitlebar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="#33b5e5"
android:text="Select Number of Devices to be configured"
android:padding="1dp"
android:layout_alignParentTop="true"
android:gravity="center_vertical"/>
</LinearLayout>
<ImageButton
android:id="@+id/btn_pincode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:contentDescription="@string/app_name"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:padding="1dp"
android:src="@drawable/pin_code_enable"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#33b5e5"
android:layout_below="@id/icon"><!-- This is line below the title -->
</ImageView>
</LinearLayout>

View file

@ -0,0 +1,52 @@
<?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:orientation="horizontal">
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView android:src="@drawable/ic_dialog_icon"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|left"
android:padding="3dp"
android:id="@+id/img">
</ImageView>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="0dp"
android:layout_height="60dp"
android:orientation="vertical"
android:layout_weight="9">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize = "25dp"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="2"></TextView>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<TextView android:id="@+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize = "15dp"
android:textColor="#3333ff"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="1"></TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,26 @@
<?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:orientation="horizontal">
<ImageButton
android:id="@+id/btn_scan"
android:contentDescription="@string/app_name"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/qrcode_img"
android:onClick="qrcode_onclick"/>
<EditText
android:id="@+id/id_ap_password"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="5"
android:background="@android:drawable/editbox_background_normal"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:textSize="20dp"/>
</LinearLayout>

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#525f67">
<LinearLayout
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="4"
android:orientation="vertical"
android:background="#525f67">
<ImageView
android:id="@+id/icon_sub"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="2dp"
android:src="@drawable/settings_icon"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" >
</ImageView>
<TextView
android:id="@+id/customtitlebar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="#ffffff"
android:text="Connect to home AP"
android:padding="3px"
android:textStyle="bold"
android:layout_toRightOf="@id/icon_sub"
android:layout_alignParentTop="true"
android:gravity="center_vertical"/>
</RelativeLayout>
<ImageButton
android:id="@+id/addNewNetworkBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:contentDescription="@string/app_name"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:padding="2dp"
android:onClick="addNewNetwork_OnClick"
android:src="@drawable/add_icon"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#ff0000"
android:layout_below="@id/icon"><!-- This is line below the title -->
</ImageView>
</RelativeLayout>

View file

@ -0,0 +1,52 @@
<?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:orientation="horizontal">
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#cce5ff">
<ImageView android:src="@drawable/ic_dialog_icon"
android:layout_alignParentLeft="true"
android:layout_height="35dp"
android:layout_width="35dp"
android:layout_gravity="center_vertical|left"
android:padding="3dp"
android:id="@+id/img">
</ImageView>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="0dp"
android:layout_height="60dp"
android:orientation="vertical"
android:layout_weight="9">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize = "25dp"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="2"></TextView>
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<TextView android:id="@+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize = "15dp"
android:textColor="#3333ff"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="1"></TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,53 @@
<?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:orientation="horizontal">
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#999999">
<ImageView android:src="@drawable/ic_dialog_icon"
android:layout_alignParentLeft="true"
android:layout_height="35dp"
android:layout_width="35dp"
android:layout_gravity="center_vertical|left"
android:padding="3dp"
android:id="@+id/img">
</ImageView>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="0dp"
android:layout_height="60dp"
android:orientation="vertical"
android:layout_weight="9">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize = "25dp"
android:textColor="#0B0B0D"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="2"></TextView>
<LinearLayout android:id="@+id/linearLayout_confirm"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<TextView android:id="@+id/info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize = "15dp"
android:textColor="#CBCBCB"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="1"></TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,21 @@
<?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:orientation="vertical">
<EditText
android:id="@+id/id_device_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background_normal"
android:padding="5dp"
android:singleLine="true"
android:textColor="#999999"
android:textSize="14dip"/>
</LinearLayout>

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Wifi Connector
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/title_view" />
<ScrollView
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/content_bk" >
</ScrollView>
<include layout="@layout/buttons_view_divider"/>
<LinearLayout
android:id="@+id/buttons_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/buttons_view_bk"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="5sp" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/preview_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.zxing.view.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="@drawable/navbar"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:textColor="@android:color/white"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/qrcode_title" />
<Button
android:id="@+id/btn_cancel_scan"
android:layout_width="248dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="75dp"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/qrcode_cancel" />
</RelativeLayout>
</FrameLayout>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_dialog_icon"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:textColor="@android:color/primary_text_dark"
android:textSize="20sp"
android:padding="10dp" />

View file

@ -0,0 +1,24 @@
<?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:orientation="vertical">
<EditText
android:id="@+id/id_ap_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background_normal"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:inputType="textPassword"
android:textSize="20dp"/>
<CheckBox
android:id="@+id/checkBox_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Password" />
</LinearLayout>

View file

@ -0,0 +1,34 @@
<?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:orientation="vertical">
<EditText
android:id="@+id/id_new_ap_ssid"
android:hint="SSID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background_normal"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:textSize="20dp"/>
<EditText
android:id="@+id/id_new_ap_password"
android:hint="Password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background_normal"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:inputType="textPassword"
android:textSize="20dp"/>
<CheckBox
android:id="@+id/checkBox_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Password" />
</LinearLayout>

View file

@ -0,0 +1,54 @@
<?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:orientation="horizontal">
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
android:layout_alignParentLeft="true"
android:layout_height="35dp"
android:layout_width="35dp"
android:layout_gravity="center_vertical|left"
android:padding="3dp"
android:id="@+id/signalImg">
</ImageView>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="0dp"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_weight="9">
<TextView android:id="@+id/title_aplist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize = "20dp"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:layout_weight="6"></TextView>
<TextView android:id="@+id/info_aplist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize = "15dp"
android:textColor="#3333ff"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|left"
android:layout_weight="1"></TextView>
<RadioGroup
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:gravity="center_vertical|left"
android:text="" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>

View file

@ -0,0 +1,8 @@
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>

View file

@ -0,0 +1,9 @@
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>
</resources>

View file

@ -0,0 +1,11 @@
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

View file

@ -0,0 +1,12 @@
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="buttons_view_bk">@android:color/darker_gray</color>
<color name="content_bk">@android:color/background_light</color>
<color name="bg_color">#EDEDED</color>
<color name="contents_text">#ff000000</color>
<color name="encode_view">#ffffffff</color>
<color name="help_button_view">#ffcccccc</color>
<color name="help_view">#ff404040</color>
<color name="possible_result_points">#c0ffff00</color>
<color name="result_image_border">#ffffffff</color>
<color name="result_minor_text">#ffc0c0c0</color>
<color name="result_points">#c000ff00</color>
<color name="result_text">#ffffffff</color>
<color name="result_view">#b0000000</color>
<color name="sbc_header_text">#ff808080</color>
<color name="sbc_header_view">#ffffffff</color>
<color name="sbc_list_item">#fffff0e0</color>
<color name="sbc_layout_view">#ffffffff</color>
<color name="sbc_page_number_text">#ff000000</color>
<color name="sbc_snippet_text">#ff4b4b4b</color>
<color name="share_text">#ff000000</color>
<color name="share_view">#ffffffff</color>
<color name="status_view">#50000000</color>
<color name="status_text">#ffffffff</color>
<color name="transparent">#00000000</color>
<color name="viewfinder_frame">#ff000000</color>
<color name="viewfinder_laser">#ffff0000</color>
<color name="viewfinder_mask">#60000000</color>
<color name="header">#58567D</color>
<color name="grgray">#686868</color>
<color name="color_tiffany">#82D9D0</color>
</resources>

View file

@ -0,0 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2008 ZXing authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- Messages IDs -->
<item type="id" name="auto_focus"/>
<item type="id" name="decode"/>
<item type="id" name="decode_failed"/>
<item type="id" name="decode_succeeded"/>
<item type="id" name="encode_failed"/>
<item type="id" name="encode_succeeded"/>
<item type="id" name="launch_product_query"/>
<item type="id" name="quit"/>
<item type="id" name="restart_preview"/>
<item type="id" name="return_scan_result"/>
<item type="id" name="search_book_contents_failed"/>
<item type="id" name="search_book_contents_succeeded"/>
</resources>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Simple Config Wizard</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="ap_connected">connected</string>
<string name="ap_unconnected"></string>
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<!-- item name="android:textSize">30dp</item-->
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
</style>
</resources>

View file

@ -0,0 +1,97 @@
<resources>
<!--
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">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<string name="toastFailed">Failed!</string>
<string name="buttonOp">More&#8230;</string>
<!-- For Simple Config Layout Interface -->
<string name="wifi_scan">Wi-Fi Network</string>
<string name="pin_text">PIN</string>
<string name="qrcode_desc">QRCode</string>
<string name="qrcode_title">QRCode Scan</string>
<string name="qrcode_cancel">Cancel</string>
<string name="start_config">Start</string>
<string name="stop_config">Press to Stop</string>
<!-- For Simple Control Layout Interface -->
<string name="dev_discovery">Connected Device</string>
<string name="rename_dev">Rename Device</string>
<string name="del_prof">Remove Device</string>
<!-- Button label to connect to a wifi network-->
<string name="connect">Connect</string>
<string name="cancel">Cancel</string>
<!-- !!!!!!!! vpn_connect_toTitle of VPN connect dialog -->
<string name="wifi_connect_to">Connect to %s</string>
<!-- Wi-Fi IP address label -->
<string name="ip_address">IP address</string>
<!-- Label for the signal strength -->
<string name="signal">Signal strength</string>
<!-- Button caption to forget a wifi network -->
<string name="forget_network">Forget</string>
<!-- Label for status of connection -->
<string name="wifi_status">Status</string>
<!--Wi-Fi settings screen, summary text for network when connected -->
<string name="status_connected">Connected</string>
<string name="status_connecting">Connecting&#8230;</string>
<!-- Label for link speed (wifi) -->
<string name="wifi_link_speed">Speed</string>
<!-- Verbose wifi signal strength. This is the best out of 4 levels. -->
<string name="wifi_signal_3">Excellent</string>
<!-- Verbose wifi signal strength. This is the 2nd best out of 4 levels. -->
<string name="wifi_signal_2">Good</string>
<!-- Verbose wifi signal strength. This is the 3rd best out of 4 levels. -->
<string name="wifi_signal_1">Fair</string>
<!-- Verbose wifi signal strength. This is the worst out of 4 levels. -->
<string name="wifi_signal_0">Poor</string>
<!-- Label for the security of a wifi network -->
<string name="security">Security</string>
<!-- Value for the wifi security. This means no encryption. -->
<string name="wifi_security_open">Open</string>
<!-- Value for the wifi security -->
<string name="wifi_security_wep">WEP</string>
<!-- Value for the wifi security -->
<string name="wifi_security_wpa">WPA</string>
<!-- Value for the wifi security -->
<string name="wifi_security_wpa2">WPA2</string>
<!-- Value for the wifi security -->
<string name="wifi_security_wpa_eap">WPA-EAP</string>
<!-- Value for the wifi security -->
<string name="wifi_security_ieee8021x">IEEE8021X</string>
<string name="please_type_passphrase">Wireless password</string>
<string name="wifi_show_password">Show password.</string>
<string name="wifi_change_password">Change password</string>
<string name="button_change_password">Modify</string>
<!-- An edit field's grayed out value when it has not been modified -->
<string name="wifi_password_unchanged">(unchanged)</string>
<!-- Button caption to save a configuration wifi -->
<string name="wifi_save_config">Save</string>
<string name="adhoc_not_supported_yet">AdHoc is not supported by Android platform yet!</string>
<string name="dummy_content_description">""</string>
<style name="PlatformDialog" parent="android:Theme.Dialog"/>
<style name="textAppearanceBaseContent" parent="@android:style/TextAppearance.Small.Inverse" />
</resources>

View file

@ -0,0 +1,78 @@
package com.rtk.simpleconfig_wizard;
import java.security.MessageDigest;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AESCrypt {
// private static final String TAG = "AESCrypt";
public static String encrypt(String key, String cleartext) throws Exception {
byte[] md5Key = MD5(key.getBytes());
byte[] result = encrypt(md5Key, cleartext.getBytes());
return toHex(result);
}
public static String decrypt(String key, String encrypted) throws Exception {
byte[] md5Key = MD5(key.getBytes());
byte[] result = decrypt(md5Key, toByte(encrypted));
return new String(result);
}
public static byte[] MD5(byte[] key) throws Exception {
byte[] md5_digest = new byte[16];
MessageDigest mDigest;
mDigest = MessageDigest.getInstance("MD5");
mDigest.update(key, 0, key.length);
md5_digest = mDigest.digest();
// System.out.printf("MD5: ");
// for(int i=0; i<16; i++) {
// System.out.printf("%02x ", md5_digest[i]);
// }
// System.out.printf("\n");
return md5_digest;
}
public static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES/ECB/PKCS5Padding");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES/ECB/PKCS5Padding");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
public static byte[] toByte(String hexString) {
int len = hexString.length()/2;
byte[] result = new byte[len];
for (int i = 0; i < len; i++)
result[i] = Integer.valueOf(hexString.substring(2*i, 2*i+2), 16).byteValue();
return result;
}
public static String toHex(byte[] buf) {
if (buf == null)
return "";
StringBuffer result = new StringBuffer(2*buf.length);
for (int i = 0; i < buf.length; i++) {
appendHex(result, buf[i]);
}
return result.toString();
}
private final static String HEX = "0123456789ABCDEF";
private static void appendHex(StringBuffer sb, byte b) {
sb.append(HEX.charAt((b>>4)&0x0f)).append(HEX.charAt(b&0x0f));
}
}

View file

@ -0,0 +1,77 @@
package com.rtk.simpleconfig_wizard;
import android.graphics.drawable.Drawable;
public class ConfigurationDevice {
public static class DeviceInfo
{
private int aliveFlag;
private String name;
private String IP;
private String macAdrress;
private int securityType;
private Drawable img;
private boolean connectedflag;
public int getaliveFlag()
{
return this.aliveFlag;
}
public void setaliveFlag(int aliveFlag)
{
this.aliveFlag = aliveFlag;
}
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name= name;
}
public String getIP()
{
return this.IP;
}
public void setIP(String IP)
{
this.IP= IP;
}
public String getmacAdrress()
{
return this.macAdrress;
}
public void setmacAdrress(String macAdrress)
{
this.macAdrress= macAdrress;
}
public int getsecurityType()
{
return this.securityType;
}
public void setsecurityType(int securityType)
{
this.securityType= securityType;
}
public Drawable getimg()
{
return this.img;
}
public void setimg(Drawable img)
{
this.img= img;
}
public boolean getconnectedflag()
{
return this.connectedflag;
}
public void setconnectedflag(boolean connectedflag)
{
this.connectedflag= connectedflag;
}
}
}

View file

@ -0,0 +1,472 @@
package com.rtk.simpleconfig_wizard;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import android.os.Environment;
import android.util.Log;
public class FileOps {
private static final String TAG = "FileOps";
private String SDPATH = Environment.getExternalStorageDirectory()+"/";
//private String SDPATH = "/data/data/com.realtek.simpleconfig_wizard/files/";
private String CFGFOLDER = "rtk_sc_wizard/";
public static String SsidPasswdFile = "wizard1";
public static String CfgPinFile = "wizard2";
public static String CtlPinFile = "wizard3";
public static String PASSWD;
private boolean checkFileExists(String path) {
File file = new File(path);
return file.exists();
}
private boolean createDir(String dir) {
File dfile = new File(dir);
if(dfile.exists())
return true;
// Log.d(TAG, "createDir: " + dfile);
return dfile.mkdir();
}
private boolean createFile(String file) throws Exception
{
File ffile = new File(file);
// Log.d(TAG, "createFile: " + ffile);
return ffile.createNewFile();
}
// private boolean deleteFile(String file) throws Exception
// {
// File ffile = new File(file);
// Log.d(TAG, "createFile: " + ffile);
// return ffile.delete();
// }
public void SetKey(String key)
{
PASSWD = key;
// Log.d(TAG, "PASSWD: " + PASSWD);
}
public RandomAccessFile openFile(String filename) throws Exception
{
RandomAccessFile rf = null;
String dir = SDPATH + CFGFOLDER;
String file = dir + filename;
// Log.d(TAG, "openFile: " + file);
if(!checkFileExists(file)) {
if(!createDir(dir)) {
//Log.e(TAG, "Create Dir Error");
return null;
}
if(!createFile(file)) {
Log.e(TAG, "Create File Error");
return null;
}
}
rf = new RandomAccessFile(file, "rw");
return rf;
}
public void writeFile(RandomAccessFile rf, String str) throws Exception
{
if(rf==null) {
return;
}
String estr = AESCrypt.encrypt(PASSWD, str);
// Log.d(TAG, "estr: " + estr);
rf.writeBytes(estr);
}
public String readFile(RandomAccessFile rf) throws Exception
{
String str = null;
byte[] strbuf = null;
int len = 0 ;
if(rf==null) {
return null;
}
len = (int)rf.length();
if(len==0) {
return null;
}
strbuf = new byte[len];
rf.read(strbuf, 0, len);
// for(int i=0; i<strbuf.length; i++)
// Log.d(TAG, "" + strbuf[i]);
str = new String(strbuf);
// Log.d(TAG, "read str: " + str);
String dstr = AESCrypt.decrypt(PASSWD, str);
// Log.d(TAG, "decrypt str: " + dstr);
return dstr;
}
public void closeFile(RandomAccessFile rf) throws Exception
{
if(rf==null)
return;
rf.close();
}
public void ParseSsidPasswdFile(String ssid)
{
RandomAccessFile rf = null;
String str = null;
try {
rf = openFile(FileOps.SsidPasswdFile);
} catch (Exception e1) {
e1.printStackTrace();
Log.e(TAG, "Open File Error");
return;
}
try {
str = readFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Read File Error");
try {
rf.setLength(0);
} catch (IOException e1) {
e1.printStackTrace();
Log.e(TAG, "Set Length Error");
return;
}
return;
}
// Log.d(TAG, "Read: " + str);
SCCtlOps.StoredPasswd = new String();
if(str==null) {
//Log.e(TAG, "Null File");
} else {
String[] items = str.split("\\|");
for(int i=0; i<items.length; i++) {
// System.out.printf("items[%d]: %s\n", i, items[i]);
String[] subitems = items[i].split("\\:");
// for(int j=0; j<subitems.length; j++) {
// Log.d(TAG, String.format("subitems[%d]: %s\n", j, subitems[j]));
// }
// Log.d(TAG, String.format("Selected SSID: %s\n", ssid));
if(ssid.equals(subitems[0]) && !subitems[1].equals("null")) {
SCCtlOps.StoredPasswd += subitems[1];
// Log.d(TAG, "Find already existed SSID");
break;
}
}
}
try {
closeFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Close File Error");
}
}
public void UpdateSsidPasswdFile(boolean isOpenNetwork)
{
RandomAccessFile rf;
try {
rf = openFile(FileOps.SsidPasswdFile);
} catch (Exception e2) {
e2.printStackTrace();
Log.e(TAG, "Open File Error");
return;
}
long len=0;
boolean isOld = false;
String getstr = new String();
String setstr = new String();
try {
len = rf.length();
} catch (IOException e1) {
e1.printStackTrace();
Log.e(TAG, "Get Length Error");
return;
}
if(len>0) {
try {
getstr = readFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Read File Error");
return;
}
// Log.d(TAG, "getstr: " + getstr);
String[] items = getstr.split("\\|");
for(int i=0; i<items.length; i++) {
// System.out.printf("items[%d]: %s\n", i, items[i]);
String[] subitems = items[i].split("\\:");
// for(int j=0; j<subitems.length; j++) {
// System.out.printf("subitems[%d]: %s\n", j, subitems[j]);
// }
if(SCCtlOps.ConnectedSSID.equals(subitems[0])) {
isOld = true;
// Log.d(TAG, "Refresh old");
if(isOpenNetwork)
setstr += SCCtlOps.ConnectedSSID + ":null|";
else
setstr += SCCtlOps.ConnectedSSID + ":" + SCCtlOps.ConnectedPasswd + "|";
} else {
// Log.d(TAG, "Re-Add existed");
setstr += subitems[0] + ":" + subitems[1] + "|";
}
}
}
if(!isOld) {
// Log.d(TAG, "Add new");
if(isOpenNetwork)
setstr += SCCtlOps.ConnectedSSID + ":null|";
else
setstr += SCCtlOps.ConnectedSSID + ":" + SCCtlOps.ConnectedPasswd + "|";
}
// Log.d(TAG, "setstr: " + setstr);
try {
rf.seek(0); //re-write all info
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Re-Seek Error");
return;
}
try {
writeFile(rf, setstr);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Write File Error");
return;
}
try {
closeFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Close File Error");
return;
}
}
public String ParseCfgPinFile()
{
RandomAccessFile rf = null;
String getstr = null;
try {
rf = openFile(FileOps.CfgPinFile);
} catch (Exception e1) {
e1.printStackTrace();
Log.e(TAG, "Open File Error");
return null;
}
try {
getstr = readFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Read File Error");
try {
rf.setLength(0);
} catch (IOException e1) {
e1.printStackTrace();
Log.e(TAG, "Set Length Error");
return null;
}
return null;
}
// Log.d(TAG, "Read: " + getstr);
try {
closeFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Close File Error");
}
return getstr;
}
public void UpdateCfgPinFile(String pin)
{
RandomAccessFile rf;
try {
rf = openFile(FileOps.CfgPinFile);
} catch (Exception e2) {
e2.printStackTrace();
Log.e(TAG, "Open File Error");
return;
}
try {
writeFile(rf, pin);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Write File Error");
return;
}
try {
closeFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Close File Error");
return;
}
}
public String ParseCtlPinFile(String mac)
{
RandomAccessFile rf = null;
String getstr = null;
String pin = null;
try {
rf = openFile(FileOps.CtlPinFile);
} catch (Exception e1) {
e1.printStackTrace();
Log.e(TAG, "Open File Error");
return null;
}
try {
getstr = readFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Read File Error");
try {
rf.setLength(0);
} catch (IOException e1) {
e1.printStackTrace();
Log.e(TAG, "Set Length Error");
return null;
}
return null;
}
// Log.d(TAG, "Read: " + getstr);
if(getstr==null) {
//Log.e(TAG, "Null File");
} else {
String[] items = getstr.split("\\;");
for(int i=0; i<items.length; i++) {
// System.out.printf("items[%d]: %s\n", i, items[i]);
String[] subitems = items[i].split("\\|");
// for(int j=0; j<subitems.length; j++) {
// Log.d(TAG, String.format("subitems[%d]: %s\n", j, subitems[j]));
// }
// Log.d(TAG, String.format("Selected MAC: %s\n", mac));
if(mac.equals(subitems[0]) && !subitems[1].equals("null")) {
pin = subitems[1];
// Log.d(TAG, "Find PIN");
break;
}
}
}
try {
closeFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Close File Error");
}
return pin;
}
public void UpdateCtlPinFile(String mac, String pin)
{
RandomAccessFile rf;
try {
rf = openFile(FileOps.CtlPinFile);
} catch (Exception e2) {
e2.printStackTrace();
Log.e(TAG, "Open File Error");
return;
}
long len=0;
boolean isOld = false;
String getstr = new String();
String setstr = new String();
try {
len = rf.length();
} catch (IOException e1) {
e1.printStackTrace();
Log.e(TAG, "Get Length Error");
return;
}
if(len>0) {
try {
getstr = readFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Read File Error");
return;
}
// Log.d(TAG, "getstr: " + getstr);
String[] items = getstr.split("\\;");
for(int i=0; i<items.length; i++) {
// System.out.printf("items[%d]: %s\n", i, items[i]);
String[] subitems = items[i].split("\\|");
// for(int j=0; j<subitems.length; j++) {
// System.out.printf("subitems[%d]: %s\n", j, subitems[j]);
// }
if(mac.equals(subitems[0])) {
isOld = true;
// Log.d(TAG, "Refresh old");
setstr += subitems[0] + "|" + pin + ";";
} else {
// Log.d(TAG, "Re-Add existed");
setstr += subitems[0] + "|" + subitems[1] + ";";
}
}
}
if(!isOld) {
// Log.d(TAG, "Add new");
setstr += mac + "|" + pin + ";";
}
// Log.d(TAG, "setstr: " + setstr);
try {
rf.seek(0); //re-write all info
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Re-Seek Error");
return;
}
try {
writeFile(rf, setstr);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Write File Error");
return;
}
try {
closeFile(rf);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Close File Error");
return;
}
}
}

View file

@ -0,0 +1,622 @@
package com.rtk.simpleconfig_wizard;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import android.net.wifi.ScanResult;
import android.util.Log;
public class SCCtlOps {
private static final String TAG = "SCCtlOps";
public static boolean IsOpenNetwork = false; // Default has password, not open network
public static String ConnectedSSID; // Connected WIFI's SSID
public static String ConnectedBSSID; // Connected WIFI's BSSID
public static String ConnectedPasswd; // Connected WIFI's Password
public static String StoredPasswd;
public static boolean isHiddenSSID;
public static boolean addNewNetwork;
public static ScanResult reBuiltScanResult;
public static final int MAX_CLIENTS_NUM = 32;
public static final int MAX_CONFIG_NUM = 8;
public static boolean DiscoveredNew;
public static boolean SetAble = true;
/** For UDP Data Receive */
// public static byte[] RecvBuf = new byte[512];
/** UDP Payload Format Flag */
public static class Flag{
private Flag(){
}
/** Flag */
public static final int Version = (0x00<<6); // 2 bits
public static final int RequestFlag = (0<<5); // 1 bit
public static final int ResponseFlag = (1<<5);
/** Request */
public static final int Discover = 0x00; // 5 bits
public static final int SaveProf = 0x01;
public static final int DelProf = 0x02;
public static final int RenameDev = 0x03;
public static final int ReturnACK = 0x04;
public static final int NewAPReq = 0x07;
/** Response */
public static final int CfgSuccessACK = 0x00; // 5 bits
public static final int DiscoverACK = 0x01;
public static final int SaveProfACK = 0x02;
public static final int DelProfACK = 0x03;
public static final int RenameDevACK = 0x04;
public static final int CfgSuccessACKSendBack = 0x05;
public static final int CfgSuccessACKFinish = 0x06;
public static final int NewAPACK = 0X07;
}
/** Flag_Other */
public static class Flag_Other{
private Flag_Other(){
}
/** Site Survey */
public static final int SiteSurveyFinish = 0xF0;
}
/** UDP Payload Format ACK to Scan */
public static class ScanACK{
private ScanACK(){
}
/** MAC */
public static int MaxDevNum = 0;
public static byte[][] Mac = new byte[MAX_CLIENTS_NUM][6]; // Record the connected STA
/** Status */
public static byte[] Status = new byte[MAX_CLIENTS_NUM];
/** Device Type */
public static byte[][] Type = new byte[MAX_CLIENTS_NUM][2];
/** Device IP */
public static byte[][] IPBuf = new byte[MAX_CLIENTS_NUM][4];
public static String[] IP = new String[MAX_CLIENTS_NUM];
/** Device Name */
public static byte[][] NameBuf = new byte[MAX_CLIENTS_NUM][64];
public static String[] Name = new String[MAX_CLIENTS_NUM];
/** Use PIN or Not */
public static Boolean[] UsePin = new Boolean[MAX_CLIENTS_NUM];
}
/** DUT info at AP Mode*/
public static class SoftAPMode_Param{
private SoftAPMode_Param(){
}
/** MAC */
public static int CfgDUTNum= 0;
public static int MaxDUT_AP = 0;
public static String[] param_SSID = new String[MAX_CONFIG_NUM];
public static String[] param_BSSID = new String[MAX_CONFIG_NUM]; // Record the connected STA
}
public static byte[] rtk_sc_gen_digest(byte[] inputData)
{
try {
return AESCrypt.MD5(inputData);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void rtk_sc_control_reset()
{
ScanACK.MaxDevNum = 0;
Arrays.fill(ScanACK.Status, (byte)0);
for(int i=0; i<MAX_CLIENTS_NUM; i++) {
Arrays.fill(ScanACK.Mac[i], (byte)0);
Arrays.fill(ScanACK.Type[i], (byte)0);
Arrays.fill(ScanACK.IPBuf[i], (byte)0);
Arrays.fill(ScanACK.NameBuf[i], (byte)0);
}
ScanACK.IP = new String[MAX_CLIENTS_NUM];
ScanACK.Name = new String[MAX_CLIENTS_NUM];
}
public static byte[] rtk_sc_gen_discover_packet(String defaultPIN)
{
byte[] CmdBuf = new byte[92];
short PayloadLen = 0;
Arrays.fill(CmdBuf, (byte)0);
/** Flag */
CmdBuf[0] += Flag.Version;
CmdBuf[0] += Flag.RequestFlag;
CmdBuf[0] += Flag.Discover;
/** Encrypt Flag */
CmdBuf[3] = 0x01;
PayloadLen += 1;
/** Nonce */
if(CmdBuf[3] == 0x01) {
for(int i=0; i<64; i++) {
Random r = new Random();
CmdBuf[4+i] = (byte) (r.nextInt(256) + 1);
}
}
PayloadLen += 64;
/** Default PIN Digest */
byte[] inputData = new byte[64 + defaultPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(defaultPIN.getBytes(), 0, inputData, 64, defaultPIN.length());
byte[] digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** MAC Address */
PayloadLen += 6;
/** Device Type */
PayloadLen += 2;
/** Length */
byte[] buf = new byte[2];
buf[0] = (byte)((PayloadLen >> 8) & 0xff);
buf[1] = (byte)(PayloadLen & 0xff);
System.arraycopy(buf, 0, CmdBuf, 1, 2);
/*String dbgStr = new String();
for(int i=0; i<92; i++)
dbgStr += String.format("%02x ", CmdBuf[i]);
Log.d(TAG, "Client Discover Packet: " + dbgStr);*/
return CmdBuf;
}
public static byte[] rtk_sc_gen_control_newAP_packet(int flag, String defaultPIN, String inputPIN, String SSID, String pwd)
{
byte[] CmdBuf;
short PayloadLen = 0;
byte[] digest;
byte[] inputData;
byte[] ssidBuf = null;
byte[] pwdBuf = null;
try {
ssidBuf = SSID.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Get SSID bytes error");
e.printStackTrace();
return null;
}
try {
pwdBuf = pwd.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Get password bytes error");
e.printStackTrace();
return null;
}
CmdBuf = new byte[100+32+64];
Arrays.fill(CmdBuf, (byte)0);
/** Flag */
CmdBuf[0] += Flag.Version;
CmdBuf[0] += Flag.RequestFlag;
CmdBuf[0] += flag;
/** Encrypt Flag */
CmdBuf[3] = 0x01;
PayloadLen += 1;
/** Nonce */
if(CmdBuf[3] == 0x01) {
for(int i=0; i<64; i++) {
Random r = new Random();
CmdBuf[4+i] = (byte) (r.nextInt(256) + 1);
}
}
PayloadLen += 64;
/** Default PIN Digest */
// Log.d(TAG, "defaultPIN: " + defaultPIN);
inputData = new byte[64 + defaultPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(defaultPIN.getBytes(), 0, inputData, 64, defaultPIN.length());
digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** User Input PIN Digest */
// Log.d(TAG, "inputPIN: " + inputPIN);
inputData = new byte[64 + inputPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(inputPIN.getBytes(), 0, inputData, 64, inputPIN.length());
digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** SSID */
System.arraycopy(ssidBuf, 0, CmdBuf, PayloadLen+3, ssidBuf.length);
PayloadLen += 64;//ssidBuf.length;
/** Password*/
System.arraycopy(pwdBuf, 0, CmdBuf, PayloadLen+3, pwdBuf.length);
PayloadLen += 64;//pwdBuf.length;
/** Length */
byte[] buf = new byte[2];
buf[0] = (byte)((PayloadLen >> 8) & 0xff);
buf[1] = (byte)(PayloadLen & 0xff);
System.arraycopy(buf, 0, CmdBuf, 1, 2);
return CmdBuf;
}
public static byte[] rtk_sc_gen_control_packet(int flag, String defaultPIN, String inputPIN, String nameStr)
{
byte[] CmdBuf;
short PayloadLen = 0;
byte[] digest;
byte[] inputData;
byte[] nameBuf = null;
if(flag == Flag.RenameDev) {
// Log.d(TAG, "nameStr: " + nameStr);
try {
nameBuf = nameStr.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Get name bytes error");
e.printStackTrace();
return null;
}
CmdBuf = new byte[100+nameBuf.length];
} else {
CmdBuf = new byte[100];
}
Arrays.fill(CmdBuf, (byte)0);
/** Flag */
CmdBuf[0] += Flag.Version;
CmdBuf[0] += Flag.RequestFlag;
CmdBuf[0] += flag;
/** Encrypt Flag */
CmdBuf[3] = 0x01;
PayloadLen += 1;
/** Nonce */
if(CmdBuf[3] == 0x01) {
for(int i=0; i<64; i++) {
Random r = new Random();
CmdBuf[4+i] = (byte) (r.nextInt(256) + 1);
}
}
PayloadLen += 64;
/** Default PIN Digest */
// Log.d(TAG, "defaultPIN: " + defaultPIN);
inputData = new byte[64 + defaultPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(defaultPIN.getBytes(), 0, inputData, 64, defaultPIN.length());
digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** User Input PIN Digest */
// Log.d(TAG, "inputPIN: " + inputPIN);
inputData = new byte[64 + inputPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(inputPIN.getBytes(), 0, inputData, 64, inputPIN.length());
digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** Device Name */
if(flag == Flag.RenameDev) {
// String tmp = new String();
// for(int i=0; i<nameBuf.length; i++) {
// tmp += String.format("%02x ", nameBuf[i]);
// }
// Log.d(TAG, "nameBuf: " + tmp);
System.arraycopy(nameBuf, 0, CmdBuf, PayloadLen+3, nameBuf.length);
PayloadLen += nameBuf.length;
}
/** Length */
byte[] buf = new byte[2];
buf[0] = (byte)((PayloadLen >> 8) & 0xff);
buf[1] = (byte)(PayloadLen & 0xff);
System.arraycopy(buf, 0, CmdBuf, 1, 2);
return CmdBuf;
}
public static byte[] rtk_sc_gen_control_confirm_packet(int flag, String defaultPIN, String inputPIN)
{
byte[] CmdBuf;
short PayloadLen = 0;
byte[] digest;
byte[] inputData;
CmdBuf = new byte[101];
Arrays.fill(CmdBuf, (byte)0);
/** Flag */
CmdBuf[0] += Flag.Version;
CmdBuf[0] += Flag.RequestFlag;
CmdBuf[0] += Flag.ReturnACK;
/** Encrypt Flag */
CmdBuf[3] = 0x01;
PayloadLen += 1;
/** Nonce */
if(CmdBuf[3] == 0x01) {
for(int i=0; i<64; i++) {
Random r = new Random();
CmdBuf[4+i] = (byte) (r.nextInt(256) + 1);
}
}
PayloadLen += 64;
/** Default PIN Digest */
// Log.d(TAG, "defaultPIN: " + defaultPIN);
inputData = new byte[64 + defaultPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(defaultPIN.getBytes(), 0, inputData, 64, defaultPIN.length());
digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** User Input PIN Digest */
// Log.d(TAG, "inputPIN: " + inputPIN);
inputData = new byte[64 + inputPIN.length()];
System.arraycopy(CmdBuf, 4, inputData, 0, 64);
System.arraycopy(inputPIN.getBytes(), 0, inputData, 64, inputPIN.length());
digest = rtk_sc_gen_digest(inputData);
System.arraycopy(digest, 0, CmdBuf, PayloadLen+3, 16);
PayloadLen += 16;
/** Encrypt Flag */
CmdBuf[PayloadLen+3] += flag;
PayloadLen += 1;
/** Length */
byte[] buf = new byte[2];
buf[0] = (byte)((PayloadLen >> 8) & 0xff);
buf[1] = (byte)(PayloadLen & 0xff);
System.arraycopy(buf, 0, CmdBuf, 1, 2);
return CmdBuf;
}
public static int handle_discover_ack(byte[] recv_buf)
{
int length, equalCnt=0;
String dbgStr;
if(SetAble==false)
return -1;
DiscoveredNew = false;
// System.arraycopy(recv_buf, 0, RecvBuf, 0, recv_buf.length);
length = (recv_buf[1]<<8)&0xFF00 | (recv_buf[2])&0xFF;
// Log.d(TAG, String.format("length: 0x%02x", length));
if(length < 6) {
Log.e(TAG, "At least a mac\n");
return -1;
}
if(ScanACK.MaxDevNum > MAX_CLIENTS_NUM) {
Log.e(TAG, "The receive buf is full\n");
return -1;
}
/** Judge if it is the same MAC */
// Log.d(TAG, "Max Device Number: " + ScanACK.MaxDevNum);
if(ScanACK.MaxDevNum > 0) {/* Not the first time */
for(int j=0; j<ScanACK.MaxDevNum; j++) {
for(int i=0; i<6; i++) {
if(recv_buf[3+i] == ScanACK.Mac[j][i])
equalCnt++;
}
if(equalCnt == 6)
return -1; //find the same MAC
equalCnt = 0; //for the second judge(if has)
}
}
/** Not the same MAC */
System.arraycopy(recv_buf, 3, ScanACK.Mac[ScanACK.MaxDevNum], 0, 6);
dbgStr = new String();
for(int i=0; i<6; i++) {
dbgStr += String.format("%02x", ScanACK.Mac[ScanACK.MaxDevNum][i]);
if(i<5)
dbgStr += ":";
}
Log.i(TAG, "Discovered MAC: " + dbgStr);
/** Status */
if(length >= 7) {
ScanACK.Status[ScanACK.MaxDevNum] = recv_buf[9];
// Log.d(TAG, String.format("Status: %02x", ScanACK.Status[ScanACK.MaxDevNum]));
}
/** Device Type */
if(length >= 9) {
System.arraycopy(recv_buf, 10, ScanACK.Type[ScanACK.MaxDevNum], 0, 2);
// Log.d(TAG, String.format("Device Type: %02x %02x", ScanACK.DevType[ScanACK.MaxDevNum][0],
// ScanACK.DevType[ScanACK.MaxDevNum][1]));
}
/** Device IP */
if(length >= 13) {
System.arraycopy(recv_buf, 12, ScanACK.IPBuf[ScanACK.MaxDevNum], 0, 4);
ScanACK.IP[ScanACK.MaxDevNum] = String.format("%d.%d.%d.%d",
ScanACK.IPBuf[ScanACK.MaxDevNum][0]&0xff,
ScanACK.IPBuf[ScanACK.MaxDevNum][1]&0xff,
ScanACK.IPBuf[ScanACK.MaxDevNum][2]&0xff,
ScanACK.IPBuf[ScanACK.MaxDevNum][3]&0xff);
Log.i(TAG, "Device IP: " + ScanACK.IP[ScanACK.MaxDevNum]);
}
/** Device Name */
if(length >= 77) {
System.arraycopy(recv_buf, 16, ScanACK.NameBuf[ScanACK.MaxDevNum], 0, 64);
String name = null;
try {
name = new String(ScanACK.NameBuf[ScanACK.MaxDevNum], "UTF-8").trim();
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Get device name error");
e.printStackTrace();
}
if(name.length()>0)
ScanACK.Name[ScanACK.MaxDevNum] = name;
else
ScanACK.Name[ScanACK.MaxDevNum] = null;
Log.i(TAG, "Device Name: " + ScanACK.Name[ScanACK.MaxDevNum]);
}
/** Use PIN or Not */
if(length >= 78) {
ScanACK.UsePin[ScanACK.MaxDevNum] = (recv_buf[80]>0) ? true:false;
// Log.d(TAG, "UsePin: " + ScanACK.UsePin[ScanACK.MaxDevNum]);
}
ScanACK.MaxDevNum++;
DiscoveredNew = true;
return 0;
}
public static int rtk_sc_get_discovered_dev_num()
{
return ScanACK.MaxDevNum;
}
// public static void rtk_get_connected_dev_test1()
// {
// /** For test */
// byte[] tmp = {0x21,
// 00,0x2c,
// 00,0x18,(byte)0x95,0x61,(byte)0x89,0x75,
// 0x01,
// 00,0x01,
// (byte)0xc0,(byte)0xa8,0x01,(byte)0xdd,00,
// (byte)0xe7,(byte)0xa9,(byte)0xba,(byte)0xe8,(byte)0xb0,
// (byte)0x83,00,00,00,00,
// 00,00,00,00,00,
// 00,00,00,00,00,
// 00,00,00,00,00,
// 00,00};
// System.arraycopy(tmp, 0, RecvBuf, 0, tmp.length);
// handle_discover_ack();
// }
//
// public static void rtk_get_connected_dev_test2()
// {
// byte[] tmp = {0x21,
// 00,0x2c,
// 00,0x44,0x46,0x66,0x66,0x76,
// 0x02,
// 00,0x02,
// (byte)0xc0,(byte)0xa8,0x01,(byte)0xde,00,
// 0x54,0x56,00,00,00,
// 00,00,00,00,00,
// 00,00,00,00,00,
// 00,00,00,00,00,
// 00,00,00,00,00,
// 00,00};
// System.arraycopy(tmp, 0, RecvBuf, 0, tmp.length);
// handle_discover_ack();
// }
public static int rtk_sc_get_discovered_dev_info(List<HashMap<String, Object>> DevInfo)
{
int i;
String buf;
HashMap<String, Object> hmap;
SetAble = false;
// Log.d(TAG, "ScanACK.MaxDevNum: " + ScanACK.MaxDevNum);
for(int index=0; index<ScanACK.MaxDevNum; index++) {
buf = new String();
hmap = new HashMap<String, Object>();
for(i=0; i<6; i++) {
buf += String.format("%02x", ScanACK.Mac[index][i]);
if(i<5)
buf += ":";
}
// Log.d(TAG, "Mac: " + buf);
hmap.put("MAC", buf);
buf = new String();
switch(ScanACK.Status[index]) {
case 0x01:
buf = "Connected";
break;
case 0x02:
buf = "Profile saved";
break;
default:
buf = "Unkown status";
break;
}
// Log.d(TAG, "Status: " + buf);
hmap.put("Status", buf);
buf = new String();
int type = (int)( (ScanACK.Type[index][0]&0xff)<<8 ) + (int)(ScanACK.Type[index][1]&0xff);
switch(type) {
case 0x0000:
buf = "Any type";
break;
case 0x0001:
buf = "TV";
break;
case 0x0002:
buf = "Air conditioner";
break;
case 0x41F8://MultiRoomType=16888
buf = "Multi Room";
break;
case 0x41F9://MultiRoomType=16889
buf = "Multi_Media";
break;
default:
buf = "Unkown type";
break;
}
// Log.d(TAG, "DevType: " + buf);
hmap.put("Type", buf);
// Log.d(TAG, "IP: " + ScanACK.DevIP[index]);
hmap.put("IP", ScanACK.IP[index]);
// Log.d(TAG, "Name: " + ScanACK.DevName[index]);
hmap.put("Name", ScanACK.Name[index]);
// Log.d(TAG, "PIN: " + ScanACK.UsePin[index]);
hmap.put("PIN", ScanACK.UsePin[index]);
DevInfo.add(hmap);
}
SetAble = true;
return 0;
}
}

View file

@ -0,0 +1,116 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
public abstract class BaseContent implements Floating.Content, OnCheckedChangeListener {
protected final WifiManager mWifiManager;
protected final Floating mFloating;
protected final ScanResult mScanResult;
protected final String mScanResultSecurity;
protected final boolean mIsOpenNetwork ;
protected int mNumOpenNetworksKept;
protected View mView;
protected OnClickListener mCancelOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
mFloating.finish();
}
};
protected String getCancelString() {
return mFloating.getString(android.R.string.cancel);
}
private static final int[] SIGNAL_LEVEL = {R.string.wifi_signal_0, R.string.wifi_signal_1,
R.string.wifi_signal_2, R.string.wifi_signal_3};
public BaseContent(final Floating floating, final WifiManager wifiManager, final ScanResult scanResult) {
super();
mWifiManager = wifiManager;
mFloating = floating;
mScanResult = scanResult;
mScanResultSecurity = Wifi.ConfigSec.getScanResultSecurity(mScanResult);
mIsOpenNetwork = Wifi.ConfigSec.isOpenNetwork(mScanResultSecurity);
mView = View.inflate(mFloating, R.layout.base_content, null);
((TextView)mView.findViewById(R.id.SignalStrength_TextView)).setText(SIGNAL_LEVEL[WifiManager.calculateSignalLevel(mScanResult.level, SIGNAL_LEVEL.length)]);
final String rawSecurity = Wifi.ConfigSec.getDisplaySecirityString(mScanResult);
final String readableSecurity = Wifi.ConfigSec.isOpenNetwork(rawSecurity) ? mFloating.getString(R.string.wifi_security_open) : rawSecurity;
((TextView)mView.findViewById(R.id.Security_TextView)).setText(readableSecurity);
((CheckBox)mView.findViewById(R.id.ShowPassword_CheckBox)).setOnCheckedChangeListener(this);
mNumOpenNetworksKept = Settings.Secure.getInt(floating.getContentResolver(),
Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 10);
}
@Override
public View getView() {
return mView;
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
((EditText)mView.findViewById(R.id.Password_EditText)).setInputType(
InputType.TYPE_CLASS_TEXT |
(isChecked ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
:InputType.TYPE_TEXT_VARIATION_PASSWORD));
}
public OnClickListener mChangePasswordOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
changePassword();
}
};
public void changePassword() {
mFloating.setContent(new ChangePasswordContent(mFloating, mWifiManager, mScanResult));
}
}

View file

@ -0,0 +1,122 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ChangePasswordContent extends BaseContent {
private ChangingAwareEditText mPasswordEditText;
public ChangePasswordContent(Floating floating, WifiManager wifiManager,
ScanResult scanResult) {
super(floating, wifiManager, scanResult);
mView.findViewById(R.id.Status).setVisibility(View.GONE);
mView.findViewById(R.id.Speed).setVisibility(View.GONE);
mView.findViewById(R.id.IPAddress).setVisibility(View.GONE);
mPasswordEditText = ((ChangingAwareEditText)mView.findViewById(R.id.Password_EditText));
((TextView)mView.findViewById(R.id.Password_TextView)).setText(R.string.please_type_passphrase);
((EditText)mView.findViewById(R.id.Password_EditText)).setHint(R.string.wifi_password_unchanged);
}
@Override
public int getButtonCount() {
return 2;
}
@Override
public OnClickListener getButtonOnClickListener(int index) {
return mOnClickListeners[index];
}
@Override
public CharSequence getButtonText(int index) {
switch(index) {
case 0:
return mFloating.getString(R.string.wifi_save_config);
case 1:
return getCancelString();
default:
return null;
}
}
@Override
public CharSequence getTitle() {
return mScanResult.SSID;
}
private OnClickListener mSaveOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
if(mPasswordEditText.getChanged()) {
final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
boolean saveResult = false;
if(config != null) {
saveResult = Wifi.changePasswordAndConnect(mFloating, mWifiManager, config
, mPasswordEditText.getText().toString()
, mNumOpenNetworksKept);
}
if(!saveResult) {
Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
}
}
mFloating.finish();
}
};
OnClickListener mOnClickListeners[] = {mSaveOnClick, mCancelOnClick};
@Override
public boolean onContextItemSelected(MenuItem item) {
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
}
}

View file

@ -0,0 +1,47 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
public class ChangingAwareEditText extends EditText {
public ChangingAwareEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
private boolean mChanged = false;
public boolean getChanged() {
return mChanged;
}
protected void onTextChanged (CharSequence text, int start, int before, int after) {
mChanged = true;
}
}

View file

@ -0,0 +1,35 @@
package com.wifi.connection;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
public abstract class ConfigurationSecurities {
/**
* @return The security of a given {@link WifiConfiguration}.
*/
public abstract String getWifiConfigurationSecurity(WifiConfiguration wifiConfig);
/**
* @return The security of a given {@link ScanResult}.
*/
public abstract String getScanResultSecurity(ScanResult scanResult);
/**
* Fill in the security fields of WifiConfiguration config.
* @param config The object to fill.
* @param security If is OPEN, password is ignored.
* @param password Password of the network if security is not OPEN.
*/
public abstract void setupSecurity(WifiConfiguration config, String security, final String password);
public abstract void setupSecurity_directly(WifiConfiguration config, String security, final String password);
public abstract String getDisplaySecirityString(final ScanResult scanResult);
public abstract boolean isOpenNetwork(final String security);
public static ConfigurationSecurities newInstance() {
// System.out.printf("Version.SDK: %d\n", Version.SDK);
if(Version.SDK < 8) {
return new ConfigurationSecuritiesOld();
} else {
return new ConfigurationSecuritiesV8();
}
}
}

View file

@ -0,0 +1,233 @@
package com.wifi.connection;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.GroupCipher;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiConfiguration.PairwiseCipher;
import android.net.wifi.WifiConfiguration.Protocol;
import android.text.TextUtils;
import android.util.Log;
public class ConfigurationSecuritiesOld extends ConfigurationSecurities {
// Constants used for different security types
public static final String WPA2 = "WPA2";
public static final String WPA = "WPA";
public static final String WEP = "WEP";
public static final String OPEN = "Open";
// For EAP Enterprise fields
public static final String WPA_EAP = "WPA-EAP";
public static final String IEEE8021X = "IEEE8021X";
public static final String[] EAP_METHOD = { "PEAP", "TLS", "TTLS" };
public static final int WEP_PASSWORD_AUTO = 0;
public static final int WEP_PASSWORD_ASCII = 1;
public static final int WEP_PASSWORD_HEX = 2;
static final String[] SECURITY_MODES = { WEP, WPA, WPA2, WPA_EAP, IEEE8021X };
private static final String TAG = "ConfigurationSecuritiesOld";
@Override
public String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.NONE)) {
// If we never set group ciphers, wpa_supplicant puts all of them.
// For open, we don't set group ciphers.
// For WEP, we specifically only set WEP40 and WEP104, so CCMP
// and TKIP should not be there.
if (!wifiConfig.allowedGroupCiphers.get(GroupCipher.CCMP)
&&
(wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP40)
|| wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP104))) {
return WEP;
} else {
return OPEN;
}
} else if (wifiConfig.allowedProtocols.get(Protocol.RSN)) {
return WPA2;
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
return WPA_EAP;
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return IEEE8021X;
} else if (wifiConfig.allowedProtocols.get(Protocol.WPA)) {
return WPA;
} else {
Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open.");
return OPEN;
}
}
@Override
public String getScanResultSecurity(ScanResult scanResult) {
final String cap = scanResult.capabilities;
for (int i = SECURITY_MODES.length - 1; i >= 0; i--) {
if (cap.contains(SECURITY_MODES[i])) {
return SECURITY_MODES[i];
}
}
return OPEN;
}
@Override
public String getDisplaySecirityString(final ScanResult scanResult) {
return getScanResultSecurity(scanResult);
}
private static boolean isHexWepKey(String wepKey) {
final int len = wepKey.length();
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
if (len != 10 && len != 26 && len != 58) {
return false;
}
return isHex(wepKey);
}
private static boolean isHex(String key) {
for (int i = key.length() - 1; i >= 0; i--) {
final char c = key.charAt(i);
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
return false;
}
}
return true;
}
@Override
public void setupSecurity(WifiConfiguration config, String security, final String password) {
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
if (TextUtils.isEmpty(security)) {
security = OPEN;
Log.w(TAG, "Empty security, assuming open");
}
if (security.equals(WEP)) {
int wepPasswordType = WEP_PASSWORD_AUTO;
// If password is empty, it should be left untouched
if (!TextUtils.isEmpty(password)) {
if (wepPasswordType == WEP_PASSWORD_AUTO) {
if (isHexWepKey(password)) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = Wifi.convertToQuotedString(password);
}
} else {
config.wepKeys[0] = wepPasswordType == WEP_PASSWORD_ASCII
? Wifi.convertToQuotedString(password)
: password;
}
}
config.wepTxKeyIndex = 0;
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedGroupCiphers.set(GroupCipher.WEP40);
config.allowedGroupCiphers.set(GroupCipher.WEP104);
} else if (security.equals(WPA) || security.equals(WPA2)){
config.allowedGroupCiphers.set(GroupCipher.TKIP);
config.allowedGroupCiphers.set(GroupCipher.CCMP);
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
config.allowedProtocols.set(security.equals(WPA2) ? Protocol.RSN : Protocol.WPA);
// If password is empty, it should be left untouched
if (!TextUtils.isEmpty(password)) {
if (password.length() == 64 && isHex(password)) {
// Goes unquoted as hex
config.preSharedKey = password;
} else {
// Goes quoted as ASCII
config.preSharedKey = Wifi.convertToQuotedString(password);
}
}
} else if (security.equals(OPEN)) {
config.allowedKeyManagement.set(KeyMgmt.NONE);
} else if (security.equals(WPA_EAP) || security.equals(IEEE8021X)) {
config.allowedGroupCiphers.set(GroupCipher.TKIP);
config.allowedGroupCiphers.set(GroupCipher.CCMP);
if (security.equals(WPA_EAP)) {
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
} else {
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
}
if (!TextUtils.isEmpty(password)) {
config.preSharedKey = Wifi.convertToQuotedString(password);
}
}
}
@Override
public void setupSecurity_directly(WifiConfiguration config, String security, final String password) {
if (TextUtils.isEmpty(security)) {
security = OPEN;
Log.w(TAG, "Empty security, assuming open");
}
if (security.equals(WEP)) {
int wepPasswordType = WEP_PASSWORD_AUTO;
// If password is empty, it should be left untouched
if (!TextUtils.isEmpty(password)) {
if (wepPasswordType == WEP_PASSWORD_AUTO) {
if (isHexWepKey(password)) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = Wifi.convertToQuotedString(password);
}
} else {
config.wepKeys[0] = wepPasswordType == WEP_PASSWORD_ASCII
? Wifi.convertToQuotedString(password)
: password;
}
}
config.wepTxKeyIndex = 0;
} else if (security.equals(WPA) || security.equals(WPA2)){
// If password is empty, it should be left untouched
if (!TextUtils.isEmpty(password)) {
if (password.length() == 64 && isHex(password)) {
// Goes unquoted as hex
config.preSharedKey = password;
} else {
// Goes quoted as ASCII
config.preSharedKey = Wifi.convertToQuotedString(password);
}
}
} else if (security.equals(OPEN)) {
} else if (security.equals(WPA_EAP) || security.equals(IEEE8021X)) {
if (!TextUtils.isEmpty(password)) {
config.preSharedKey = Wifi.convertToQuotedString(password);
}
}
}
@Override
public boolean isOpenNetwork(String security) {
return OPEN.equals(security);
}
}

View file

@ -0,0 +1,233 @@
package com.wifi.connection;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.GroupCipher;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiConfiguration.PairwiseCipher;
import android.os.Build;
import android.util.Log;
public class ConfigurationSecuritiesV8 extends ConfigurationSecurities {
static final int SECURITY_NONE = 0;
static final int SECURITY_WEP = 1;
static final int SECURITY_PSK = 2;
static final int SECURITY_EAP = 3;
enum PskType {
UNKNOWN,
WPA,
WPA2,
WPA_WPA2
}
private static final String TAG = "ConfigurationSecuritiesV14";
private static int getSecurity(WifiConfiguration config) {
if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
return SECURITY_PSK;
}
if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
return SECURITY_EAP;
}
return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}
private static int getSecurity(ScanResult result) {
if (result.capabilities.contains("WEP")) {
return SECURITY_WEP;
} else if (result.capabilities.contains("PSK")) {
return SECURITY_PSK;
} else if (result.capabilities.contains("EAP")) {
return SECURITY_EAP;
}
return SECURITY_NONE;
}
@Override
public String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
return String.valueOf(getSecurity(wifiConfig));
}
@Override
public String getScanResultSecurity(ScanResult scanResult) {
return String.valueOf(getSecurity(scanResult));
}
@Override
public void setupSecurity(WifiConfiguration config, String security, String password) {
if(Build.MANUFACTURER.equals("HUAWEI") && Build.MODEL.equals("NCE-AL00")||
Build.MANUFACTURER.equals("HUAWEI") && Build.MODEL.equals("NCE-AL10")){
}else{
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
}
final int sec = security == null ? SECURITY_NONE : Integer.valueOf(security);
final int passwordLen = password == null ? 0 : password.length();
switch (sec) {
case SECURITY_NONE:
config.allowedKeyManagement.set(KeyMgmt.NONE);
break;
case SECURITY_WEP:
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
if (passwordLen != 0) {
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
if ((passwordLen == 10 || passwordLen == 26 || passwordLen == 58) &&
password.matches("[0-9A-Fa-f]*")) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = '"' + password + '"';
}
}
break;
case SECURITY_PSK:
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
if (passwordLen != 0) {
if (password.matches("[0-9A-Fa-f]{64}")) {
config.preSharedKey = password;
} else {
config.preSharedKey = '"' + password + '"';
}
}
break;
case SECURITY_EAP:
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
// config.eap.setValue((String) mEapMethodSpinner.getSelectedItem());
//
// config.phase2.setValue((mPhase2Spinner.getSelectedItemPosition() == 0) ? "" :
// "auth=" + mPhase2Spinner.getSelectedItem());
// config.ca_cert.setValue((mEapCaCertSpinner.getSelectedItemPosition() == 0) ? "" :
// KEYSTORE_SPACE + Credentials.CA_CERTIFICATE +
// (String) mEapCaCertSpinner.getSelectedItem());
// config.client_cert.setValue((mEapUserCertSpinner.getSelectedItemPosition() == 0) ?
// "" : KEYSTORE_SPACE + Credentials.USER_CERTIFICATE +
// (String) mEapUserCertSpinner.getSelectedItem());
// config.private_key.setValue((mEapUserCertSpinner.getSelectedItemPosition() == 0) ?
// "" : KEYSTORE_SPACE + Credentials.USER_PRIVATE_KEY +
// (String) mEapUserCertSpinner.getSelectedItem());
// config.identity.setValue((mEapIdentityView.length() == 0) ? "" :
// mEapIdentityView.getText().toString());
// config.anonymous_identity.setValue((mEapAnonymousView.length() == 0) ? "" :
// mEapAnonymousView.getText().toString());
// if (mPasswordView.length() != 0) {
// config.password.setValue(mPasswordView.getText().toString());
// }
break;
default:
Log.e(TAG, "Invalid security type: " + sec);
}
// config.proxySettings = mProxySettings;
// config.ipAssignment = mIpAssignment;
// config.linkProperties = new LinkProperties(mLinkProperties);
}
@Override
public void setupSecurity_directly(WifiConfiguration config, String security, String password) {
final int sec = security == null ? SECURITY_NONE : Integer.valueOf(security);
final int passwordLen = password == null ? 0 : password.length();
switch (sec) {
case SECURITY_NONE:
break;
case SECURITY_WEP:
if (passwordLen != 0) {
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
if ((passwordLen == 10 || passwordLen == 26 || passwordLen == 58) &&
password.matches("[0-9A-Fa-f]*")) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = '"' + password + '"';
}
}
break;
case SECURITY_PSK:
if (passwordLen != 0) {
if (password.matches("[0-9A-Fa-f]{64}")) {
config.preSharedKey = password;
} else {
config.preSharedKey = '"' + password + '"';
}
}
break;
case SECURITY_EAP:
break;
default:
Log.e(TAG, "Invalid security type: " + sec);
}
// config.proxySettings = mProxySettings;
// config.ipAssignment = mIpAssignment;
// config.linkProperties = new LinkProperties(mLinkProperties);
}
private static PskType getPskType(ScanResult result) {
boolean wpa = result.capabilities.contains("WPA-PSK");
boolean wpa2 = result.capabilities.contains("WPA2-PSK");
if (wpa2 && wpa) {
return PskType.WPA_WPA2;
} else if (wpa2) {
return PskType.WPA2;
} else if (wpa) {
return PskType.WPA;
} else {
Log.w(TAG, "Received abnormal flag string: " + result.capabilities);
return PskType.UNKNOWN;
}
}
@Override
public String getDisplaySecirityString(final ScanResult scanResult) {
final int security = getSecurity(scanResult);
if(security == SECURITY_PSK) {
switch(getPskType(scanResult)) {
case WPA:
return "WPA";
case WPA_WPA2:
case WPA2:
return "WPA2";
default:
return "?";
}
} else {
switch(security) {
case SECURITY_NONE:
return "OPEN";
case SECURITY_WEP:
return "WEP";
case SECURITY_EAP:
return "EAP";
}
}
return "?";
}
@Override
public boolean isOpenNetwork(String security) {
return String.valueOf(SECURITY_NONE).equals(security);
}
}

View file

@ -0,0 +1,171 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class ConfiguredNetworkContent extends BaseContent {
public ConfiguredNetworkContent(Floating floating, WifiManager wifiManager,
ScanResult scanResult) {
super(floating, wifiManager, scanResult);
mView.findViewById(R.id.Status).setVisibility(View.GONE);
mView.findViewById(R.id.Speed).setVisibility(View.GONE);
mView.findViewById(R.id.IPAddress).setVisibility(View.GONE);
mView.findViewById(R.id.Password).setVisibility(View.GONE);
}
@Override
public int getButtonCount() {
return 3;
}
@Override
public OnClickListener getButtonOnClickListener(int index) {
switch(index) {
case 0:
return mConnectOnClick;
case 1:
if(mIsOpenNetwork) {
return mForgetOnClick;
} else {
return mOpOnClick;
}
case 2:
return mCancelOnClick;
default:
return null;
}
}
@Override
public CharSequence getButtonText(int index) {
switch(index) {
case 0:
return mFloating.getString(R.string.connect);
case 1:
if(mIsOpenNetwork) {
return mFloating.getString(R.string.forget_network);
} else {
return mFloating.getString(R.string.buttonOp);
}
case 2:
return getCancelString();
default:
return null;
}
}
@Override
public CharSequence getTitle() {
return mFloating.getString(R.string.wifi_connect_to, mScanResult.SSID);
}
private OnClickListener mConnectOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
boolean connResult = false;
if(config != null) {
connResult = Wifi.connectToConfiguredNetwork(mFloating, mWifiManager, config, false);
}
if(!connResult) {
Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
}
mFloating.finish();
}
};
private OnClickListener mOpOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
mFloating.registerForContextMenu(v);
mFloating.openContextMenu(v);
mFloating.unregisterForContextMenu(v);
}
};
private OnClickListener mForgetOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
forget();
}
};
private void forget() {
final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
boolean result = false;
if(config != null) {
result = mWifiManager.removeNetwork(config.networkId)
&& mWifiManager.saveConfiguration();
}
if(!result) {
Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
}
mFloating.finish();
}
private static final int MENU_FORGET = 0;
private static final int MENU_CHANGE_PASSWORD = 1;
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case MENU_FORGET:
forget();
break;
case MENU_CHANGE_PASSWORD:
changePassword();
break;
}
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, MENU_FORGET, Menu.NONE, R.string.forget_network);
menu.add(Menu.NONE, MENU_CHANGE_PASSWORD, Menu.NONE, R.string.wifi_change_password);
}
}

View file

@ -0,0 +1,163 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
public class CurrentNetworkContent extends BaseContent {
private static final String TAG = "CurrentNetworkContent";
public CurrentNetworkContent(Floating floating, WifiManager wifiManager,
ScanResult scanResult) {
super(floating, wifiManager, scanResult);
mView.findViewById(R.id.Status).setVisibility(View.GONE);
mView.findViewById(R.id.Speed).setVisibility(View.GONE);
mView.findViewById(R.id.IPAddress).setVisibility(View.GONE);
mView.findViewById(R.id.Password).setVisibility(View.GONE);
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
if(wifiInfo == null) {
Log.d(TAG, "Get WifiInfo Failed\n");
Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
} else {
Log.d(TAG, "Get WifiInfo Ok\n");
final SupplicantState state = wifiInfo.getSupplicantState();
final NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf(state);
if(detailedState == NetworkInfo.DetailedState.CONNECTED
|| (detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR && wifiInfo.getIpAddress() != 0)) {
mView.findViewById(R.id.Status).setVisibility(View.VISIBLE);
mView.findViewById(R.id.Speed).setVisibility(View.VISIBLE);
mView.findViewById(R.id.IPAddress).setVisibility(View.VISIBLE);
((TextView)mView.findViewById(R.id.Status_TextView)).setText(R.string.status_connected);
((TextView)mView.findViewById(R.id.LinkSpeed_TextView)).setText(wifiInfo.getLinkSpeed() + " " + WifiInfo.LINK_SPEED_UNITS);
((TextView)mView.findViewById(R.id.IPAddress_TextView)).setText(getIPAddress(wifiInfo.getIpAddress()));
} else if(detailedState == NetworkInfo.DetailedState.AUTHENTICATING
|| detailedState == NetworkInfo.DetailedState.CONNECTING
|| detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
mView.findViewById(R.id.Status).setVisibility(View.VISIBLE);
((TextView)mView.findViewById(R.id.Status_TextView)).setText(R.string.status_connecting);
}
}
}
@Override
public int getButtonCount() {
// No Modify button for open network.
return mIsOpenNetwork ? 2 : 3;
}
@Override
public OnClickListener getButtonOnClickListener(int index) {
if(mIsOpenNetwork && index == 1) {
// No Modify button for open network.
// index 1 is Cancel(index 2).
return mOnClickListeners[2];
}
return mOnClickListeners[index];
}
@Override
public CharSequence getButtonText(int index) {
switch(index) {
case 0:
return mFloating.getString(R.string.forget_network);
case 1:
if(mIsOpenNetwork) {
// No Modify button for open network.
// index 1 is Cancel.
return getCancelString();
}
return mFloating.getString(R.string.button_change_password);
case 2:
return getCancelString();
default:
return null;
}
}
@Override
public CharSequence getTitle() {
return mScanResult.SSID;
}
private OnClickListener mForgetOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
boolean result = false;
if(config != null) {
result = mWifiManager.removeNetwork(config.networkId)
&& mWifiManager.saveConfiguration();
}
if(!result) {
Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
}
mFloating.finish();
}
};
private OnClickListener mOnClickListeners[] = {mForgetOnClick, mChangePasswordOnClick, mCancelOnClick};
private String getIPAddress(int address) {
StringBuilder sb = new StringBuilder();
sb.append(address & 0x000000FF).append(".")
.append((address & 0x0000FF00) >> 8).append(".")
.append((address & 0x00FF0000) >> 16).append(".")
.append((address & 0xFF000000L) >> 24);
return sb.toString();
}
@Override
public boolean onContextItemSelected(MenuItem item) {
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
}
}

View file

@ -0,0 +1,138 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
//import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;
/**
* A dialog-like floating activity
* @author Kevin Yuan
*
*/
public class Floating extends Activity {
// private static final String TAG = "Floating";
private static final int[] BUTTONS = {R.id.button1, R.id.button2, R.id.button3};
private View mView;
private ViewGroup mContentViewContainer;
private Content mContent;
@Override
public void onCreate(Bundle savedInstanceState) {
// It will not work if we setTheme here.
// Please add android:theme="@android:style/Theme.Dialog" to any descendant class in AndroidManifest.xml!
// See http://code.google.com/p/android/issues/detail?id=4394
setTheme(android.R.style.Theme_Dialog);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
mView = View.inflate(this, R.layout.floating, null);
final DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
mView.setMinimumWidth(Math.min(dm.widthPixels, dm.heightPixels) - 20);
setContentView(mView);
mContentViewContainer = (ViewGroup) mView.findViewById(R.id.content);
}
private void setDialogContentView(final View contentView) {
// Log.d(TAG, "setDialogContentView\n");
mContentViewContainer.removeAllViews();
//mContentViewContainer.addView(contentView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
/* FILL_PARENT is renamed MATCH_PARENT in API Level 8 and higher */
mContentViewContainer.addView(contentView, new LayoutParams(LayoutParams.MATCH_PARENT , LayoutParams.WRAP_CONTENT));
}
public void setContent(Content content) {
mContent = content;
refreshContent();
}
public void refreshContent() {
// Log.d(TAG, "refreshContent");
setDialogContentView(mContent.getView());
((TextView)findViewById(R.id.title)).setText(mContent.getTitle()); //getTitle
final int btnCount = mContent.getButtonCount();
if(btnCount > BUTTONS.length) {
throw new RuntimeException(String.format("%d exceeds maximum button count: %d!", btnCount, BUTTONS.length));
}
findViewById(R.id.buttons_view).setVisibility(btnCount > 0 ? View.VISIBLE : View.GONE);
for(int buttonId:BUTTONS) {
final Button btn = (Button) findViewById(buttonId);
btn.setOnClickListener(null);
btn.setVisibility(View.GONE);
}
for(int btnIndex = 0; btnIndex < btnCount; btnIndex++){
final Button btn = (Button)findViewById(BUTTONS[btnIndex]);
// Log.d(TAG, "getButtonText(" + btnIndex + "): " + mContent.getButtonText(btnIndex));
btn.setText(mContent.getButtonText(btnIndex));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(mContent.getButtonOnClickListener(btnIndex));
}
}
public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
if(mContent != null) {
mContent.onCreateContextMenu(menu, v, menuInfo);
}
}
public boolean onContextItemSelected (MenuItem item) {
if(mContent != null) {
return mContent.onContextItemSelected(item);
}
return false;
}
public interface Content {
CharSequence getTitle();
View getView();
int getButtonCount();
CharSequence getButtonText(int index);
OnClickListener getButtonOnClickListener(int index);
void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo);
boolean onContextItemSelected (MenuItem item);
}
}

View file

@ -0,0 +1,124 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import com.rtk.simpleconfig_wizard.SCCtlOps;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
//import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
//import android.util.Log;
import android.widget.Toast;
public class MainActivity extends Floating {
// private static final String TAG = "WifiMainActivity";
public static final String EXTRA_HOTSPOT = "com.wifi.connection.HOTSPOT";
private ScanResult mScanResult;
private Floating.Content mContent;
private WifiManager mWifiManager;
@Override
protected void onNewIntent (Intent intent) {
setIntent(intent);
// This activity has "singleInstance" launch mode.
// Update content to reflect the newest intent.
doNewIntent(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
doNewIntent(getIntent());
}
private boolean isAdHoc(final ScanResult scanResule) {
return scanResule.capabilities.indexOf("IBSS") != -1;
}
private void doNewIntent(final Intent intent) {
if(SCCtlOps.addNewNetwork)
mScanResult = SCCtlOps.reBuiltScanResult;
else
mScanResult = intent.getParcelableExtra(EXTRA_HOTSPOT);
// Log.i(TAG, "mScanResult: " + mScanResult);
// Log.d(TAG, "mScanResult.SSID: " + mScanResult.SSID);
// Log.d(TAG, "mScanResult.BSSID: " + mScanResult.BSSID);
// Log.d(TAG, "mScanResult.capabilities: " + mScanResult.capabilities);
// Log.d(TAG, "mScanResult.level: " + mScanResult.level);
// Log.d(TAG, "mScanResult.frequency: " + mScanResult.frequency);
if(mScanResult == null) {
Toast.makeText(this, "No data in Intent!", Toast.LENGTH_LONG).show();
finish();
return;
}
if(isAdHoc(mScanResult)) {
Toast.makeText(this, R.string.adhoc_not_supported_yet, Toast.LENGTH_LONG).show();
finish();
return;
}
final String security = Wifi.ConfigSec.getScanResultSecurity(mScanResult);
final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, security);
if(config != null) {
// Log.d(TAG, "Remove already configured network\n");
mWifiManager.removeNetwork(config.networkId);
}
// Log.d(TAG, "NewNetworkContent\n");
mContent = new NewNetworkContent(this, mWifiManager, mScanResult);
// if(config == null) {
// Log.d(TAG, "NewNetworkContent\n");
// mContent = new NewNetworkContent(this, mWifiManager, mScanResult);
// } else {
// final boolean isCurrentNetwork_ConfigurationStatus = config.status == WifiConfiguration.Status.CURRENT;
// final WifiInfo info = mWifiManager.getConnectionInfo();
// final boolean isCurrentNetwork_WifiInfo = info != null
// && android.text.TextUtils.equals(info.getSSID(), mScanResult.SSID)
// && android.text.TextUtils.equals(info.getBSSID(), mScanResult.BSSID);
// if(isCurrentNetwork_ConfigurationStatus || isCurrentNetwork_WifiInfo) {
// Log.d(TAG, "CurrentNetworkContent\n");
// mContent = new CurrentNetworkContent(this, mWifiManager, mScanResult);
// } else {
// Log.d(TAG, "ConfiguredNetworkContent\n");
// mContent = new ConfiguredNetworkContent(this, mWifiManager, mScanResult);
// }
// }
setContent(mContent);
}
}

View file

@ -0,0 +1,146 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import com.rtk.simpleconfig_wizard.R;
import com.rtk.simpleconfig_wizard.SCCtlOps;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
//import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
public class NewNetworkContent extends BaseContent {
// private static final String TAG = "NewNetworkContent";
private boolean mIsOpenNetwork = false;
public NewNetworkContent(final Floating floating, final WifiManager wifiManager, ScanResult scanResult) {
super(floating, wifiManager, scanResult);
mView.findViewById(R.id.Status).setVisibility(View.GONE);
mView.findViewById(R.id.Speed).setVisibility(View.GONE);
mView.findViewById(R.id.IPAddress).setVisibility(View.GONE);
if(Wifi.ConfigSec.isOpenNetwork(mScanResultSecurity)) {
mIsOpenNetwork = true;
mView.findViewById(R.id.Password).setVisibility(View.GONE);
} else {
((TextView)mView.findViewById(R.id.Password_TextView)).setText(R.string.please_type_passphrase);
((EditText)mView.findViewById(R.id.Password_EditText)).setText(SCCtlOps.StoredPasswd); //The last password hint
}
}
private OnClickListener mConnectOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
SCCtlOps.ConnectedSSID = mScanResult.SSID; // Store SSID
// Log.d(TAG, "SSID£º" + mScanResult.SSID);
boolean connResult = false;
if(mIsOpenNetwork) {
SCCtlOps.IsOpenNetwork = true;
connResult = Wifi.connectToNewNetwork(mFloating, mWifiManager, mScanResult, null, mNumOpenNetworksKept);
} else {
SCCtlOps.IsOpenNetwork = false;
String passwd = ((EditText)mView.findViewById(R.id.Password_EditText)).getText().toString();
connResult = Wifi.connectToNewNetwork(mFloating, mWifiManager, mScanResult
, passwd
, mNumOpenNetworksKept);
if(connResult) {
SCCtlOps.ConnectedPasswd = new String(passwd); // Store password
// Log.d(TAG, "Password£º" + passwd);
}
}
// if(!connResult) {
// Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
// }
mFloating.finish();
// /** Update SSID and password */
// if(connResult) {
// FileOps fileOps = new FileOps();
// fileOps.UpdateSsidPasswdFile(mIsOpenNetwork);
// }
}
};
private OnClickListener mOnClickListeners[] = {mConnectOnClick, mCancelOnClick};
@Override
public int getButtonCount() {
return 2;
}
@Override
public OnClickListener getButtonOnClickListener(int index) {
return mOnClickListeners[index];
}
@Override
public CharSequence getButtonText(int index) {
switch(index) {
case 0:
return mFloating.getText(R.string.connect);
case 1:
return mFloating.getText(R.string.cancel);
// return getCancelString();
default:
return null;
}
}
@Override
public CharSequence getTitle() {
return mFloating.getString(R.string.wifi_connect_to, mScanResult.SSID);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
}
}

View file

@ -0,0 +1,102 @@
/*
* Wifi Connecter
*
* Copyright (c) 20101 Kevin Yuan (farproc@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**/
package com.wifi.connection;
import java.util.List;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.IBinder;
public class ReenableAllApsWhenNetworkStateChanged {
public static void schedule(final Context ctx) {
ctx.startService(new Intent(ctx, BackgroundService.class));
}
private static void reenableAllAps(final Context ctx) {
final WifiManager wifiMgr = (WifiManager)ctx.getSystemService(Context.WIFI_SERVICE);
final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
if(configurations != null) {
for(final WifiConfiguration config:configurations) {
wifiMgr.enableNetwork(config.networkId, false);
}
}
}
public static class BackgroundService extends Service {
private boolean mReenabled;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if(WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
final NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
final NetworkInfo.DetailedState detailed = networkInfo.getDetailedState();
if(detailed != NetworkInfo.DetailedState.DISCONNECTED
&& detailed != NetworkInfo.DetailedState.DISCONNECTING
&& detailed != NetworkInfo.DetailedState.SCANNING) {
if(!mReenabled) {
mReenabled = true;
reenableAllAps(context);
stopSelf();
}
}
}
}
};
private IntentFilter mIntentFilter;
@Override
public IBinder onBind(Intent intent) {
return null; // We need not bind to it at all.
}
@Override
public void onCreate() {
super.onCreate();
mReenabled = false;
mIntentFilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
registerReceiver(mReceiver, mIntentFilter);
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(mReceiver);
}
}
}

View file

@ -0,0 +1,29 @@
package com.wifi.connection;
import java.lang.reflect.Field;
import android.os.Build.VERSION;;
/**
* Get Android version in different Android versions. :)
* @author yuanxiaohui
*
*/
public class Version {
public final static int SDK = get();
private static int get() {
final Class<VERSION> versionClass = VERSION.class;
try {
// First try to read the recommended field android.os.Build.VERSION.SDK_INT.
final Field sdkIntField = versionClass.getField("SDK_INT");
return sdkIntField.getInt(null);
//} catch (NoSuchFieldException e) {
// If SDK_INT does not exist, read the deprecated field SDK.
// return Integer.valueOf(VERSION.SDK);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

Some files were not shown because too many files have changed in this diff Show more