Skip to content

Commit

Permalink
Merge pull request #2 from loveyu/1.6.5
Browse files Browse the repository at this point in the history
1.6.5
  • Loading branch information
loveyu authored Jul 13, 2018
2 parents 0c3c250 + 75cac71 commit cafabc1
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

软件需要Root权限,使用简单方便

详细介绍: https://www.loveyu.net/WifiPwd
详细介绍: [https://www.loveyu.net/WifiPwd](https://www.loveyu.net/WifiPwd?utm_source=github&utm_medium=code_share)

讨论交流: https://www.loveyu.org/3356.html
讨论交流: [https://www.loveyu.org/3356.html](https://www.loveyu.org/3356.html?utm_source=github&utm_medium=code_share)

Google Play 下载: https://play.google.com/store/apps/details?id=net.loveyu.wifipwd
18 changes: 4 additions & 14 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/intermediates/artifact_transform/javac/debug/classes" />
<output-test url="file://$MODULE_DIR$/build/intermediates/artifact_transform/javac/test/debug/classes" />
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
Expand Down Expand Up @@ -87,28 +87,18 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/artifact_transform" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-main-apk-res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "net.loveyu.wifipwd"
minSdkVersion 14
targetSdkVersion 27
versionCode 11
versionName '1.6.4'
versionCode 12
versionName '1.6.5'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/net/loveyu/wifipwd/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Action {

private ReadWpaCfg cfg;

public Action(Context context) {
Action(Context context) {
this.context = context;
this.cfg = new ReadWpaCfg(
"/data/misc/wifi/wpa_supplicant.conf",
Expand All @@ -43,14 +43,14 @@ public ArrayList<Map<String, String>> get_list(boolean force_refresh) {
}
}

public boolean run_cmd(String command) {
private boolean run_cmd() {
Process process = null;
DataOutputStream os = null;
int rt = 1;
int rt;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("system/bin/mount -o rw,remount -t rootfs /data" + "\n");
os.writeBytes("exit\n");
os.flush();
rt = process.waitFor();
Expand All @@ -74,7 +74,7 @@ public boolean run_cmd(String command) {
public boolean check_root() {
try {
try {
return run_cmd("system/bin/mount -o rw,remount -t rootfs /data");
return run_cmd();
} catch (Exception e) {
Toast.makeText(context, context.getString(R.string.can_not_root_permission) + ":" + e.getMessage(), Toast.LENGTH_LONG).show();
}
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/net/loveyu/wifipwd/DeviceUuidFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.loveyu.wifipwd;

import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;

import java.io.UnsupportedEncodingException;
import java.util.UUID;

public class DeviceUuidFactory {
private static final String PREFS_FILE = "device_id.xml";
private static final String PREFS_DEVICE_ID = "device_id";
private static volatile UUID uuid;

public DeviceUuidFactory(Context context) {
if (uuid == null) {
synchronized (DeviceUuidFactory.class) {
if (uuid == null) {
final SharedPreferences prefs = context
.getSharedPreferences(PREFS_FILE, 0);
final String id = prefs.getString(PREFS_DEVICE_ID, null);
if (id != null) {
// Use the ids previously computed and stored in the
// prefs file
uuid = UUID.fromString(id);
} else {
uuid = UUID.randomUUID();
// Write the value out to the prefs file
prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString()).apply();
}
}
}
}
}

public UUID getDeviceUuid() {
return uuid;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/net/loveyu/wifipwd/ListMsgData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ListMsgData {
public boolean is_refresh;
public boolean show_notify;
public ArrayList<Map<String, String>> list;
public ListMsgData(boolean is_refresh, ArrayList<Map<String, String>> list,boolean show_notify) {
ListMsgData(boolean is_refresh, ArrayList<Map<String, String>> list, boolean show_notify) {
this.is_refresh = is_refresh;
this.show_notify = show_notify;
this.list = list;
Expand Down
36 changes: 19 additions & 17 deletions app/src/main/java/net/loveyu/wifipwd/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class MainActivity extends Activity {

private WifiAdapter wifiAdapter = null;

private Action ac;

private ListView lv;

private int log = 0;
Expand All @@ -48,20 +46,23 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setLocale();
ac = new Action(this);
Action ac = new Action(this);
handler = new MsgHandle(this, ac);
boolean hasRoot = false;
if (ac.check_root()) {
hasRoot = true;
setContentView(R.layout.activity_main);
registerWifiChange();
handler.startReadList(false, false);
} else {
setContentView(R.layout.activity_no_root);
}
new Thread(new Report(this, "https://www.loveyu.net/Update/WifiPwd.php", hasRoot)).start();
}

public void setList(ArrayList<Map<String, String>> li) {
list = li;
TextView tv = (TextView) findViewById(R.id.textViewNotice);
TextView tv = findViewById(R.id.textViewNotice);
if (list == null) {
tv.setText(getString(R.string.read_wifi_list_error));
} else {
Expand All @@ -72,15 +73,10 @@ public void setList(ArrayList<Map<String, String>> li) {
if (list.size() == 0) {
tv.setText(getString(R.string.wifi_list_is_empty));
} else {
lv = (ListView) findViewById(R.id.listView);
lv = findViewById(R.id.listView);
lv.setAdapter(wifiAdapter);
registerForContextMenu(lv);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
view.showContextMenu();
}
});
lv.setOnItemClickListener((parent, view, position, id) -> view.showContextMenu());
String text = getString(R.string.wifi_list_number) + list.size();
tv.setText(text);
}
Expand Down Expand Up @@ -165,15 +161,21 @@ public boolean onContextItemSelected(MenuItem item) {
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
switch (item.getItemId()) {
case R.string.copy_password:
clipboardManager.setPrimaryClip(ClipData.newPlainText(null, list.get(indexListView).get("psk")));
if (clipboardManager != null) {
clipboardManager.setPrimaryClip(ClipData.newPlainText(null, list.get(indexListView).get("psk")));
}
break;
case R.string.copy_ssid:
clipboardManager.setPrimaryClip(ClipData.newPlainText(null, list.get(indexListView).get("ssid")));
if (clipboardManager != null) {
clipboardManager.setPrimaryClip(ClipData.newPlainText(null, list.get(indexListView).get("ssid")));
}
break;
case R.string.copy_ssid_and_password:
Map<String, String> s = list.get(indexListView);
clipboardManager.setPrimaryClip(ClipData.newPlainText(null,
getString(R.string.wifi_ssid) + s.get("ssid") + "\n" + getString(R.string.password) + s.get("psk")));
if (clipboardManager != null) {
clipboardManager.setPrimaryClip(ClipData.newPlainText(null,
getString(R.string.wifi_ssid) + s.get("ssid") + "\n" + getString(R.string.password) + s.get("psk")));
}
break;
default:
return false;
Expand All @@ -184,7 +186,7 @@ public boolean onContextItemSelected(MenuItem item) {

@Override
public boolean onMenuItemSelected(int aFeatureId, MenuItem aMenuItem) {
if (aFeatureId== Window.FEATURE_CONTEXT_MENU)
if (aFeatureId == Window.FEATURE_CONTEXT_MENU)
return onContextItemSelected(aMenuItem);
else
return super.onMenuItemSelected(aFeatureId, aMenuItem);
Expand Down Expand Up @@ -217,7 +219,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

public static String getAppVersionName(Context context) {
String versionName = "";
String versionName;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/net/loveyu/wifipwd/MsgHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class MsgHandle extends Handler {

public MainActivity mainActivity;
private MainActivity mainActivity;
public Action ac;

public final static int WpListUpdate = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PasswordSortComparator implements Comparator<Map<String, String>> {

private String currentSSID;

public PasswordSortComparator(String currentSSID) {
PasswordSortComparator(String currentSSID) {
this.currentSSID = currentSSID;
}

Expand Down
39 changes: 31 additions & 8 deletions app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
* Created by loveyu on 2016/1/31.
*/
public class ReadWpaCfg {
ArrayList<Map<String, String>> list;
private ArrayList<Map<String, String>> list;
private String wpa_config_path;
private String WifiConfigStore_path;
private boolean need_read_wap_config = false;

ReadWpaCfg(String wpa_supplicant_path, String WifiConfigStorePath) {
list = new ArrayList<Map<String, String>>();
list = new ArrayList<>();
this.wpa_config_path = wpa_supplicant_path;
this.WifiConfigStore_path = WifiConfigStorePath;
}
Expand Down Expand Up @@ -197,9 +197,10 @@ private void parse(String content) {
private void add(String content) {
content = content.substring(9, content.length() - 2);
String[] list = content.split("\\n");
HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, String> map = new HashMap<>();
String k, v;
for (String info : list) {
info = info.trim();
int index = info.indexOf("=");
if (index > -1) {
k = info.substring(0, index);
Expand Down Expand Up @@ -228,7 +229,7 @@ private void add_kv(String ssid, String psk) {
if (ssid == null || psk == null || "".equals(ssid) || psk.equals("")) {
return;
}
HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, String> map = new HashMap<>();

if (ssid.charAt(0) == '"') {
ssid = ssid.substring(1, ssid.length() - 1);
Expand All @@ -254,7 +255,7 @@ private void add_kv(String ssid, String psk) {
* @return 返回完整的数据列表
*/
public ArrayList<Map<String, String>> getPasswordList(Context context) {
ArrayList<Map<String, String>> rt = new ArrayList<Map<String, String>>();
ArrayList<Map<String, String>> rt = new ArrayList<>();
for (Map<String, String> map : this.list) {
if (map.containsKey("psk") && map.containsKey("ssid")) {
rt.add(map);
Expand Down Expand Up @@ -284,8 +285,8 @@ private ArrayList<Map<String, String>> sortPasswordList(ArrayList<Map<String, St
private String getCurrentSSID(Context context) {
try {
//读取当前链接的Wifi信息
WifiManager mWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (!mWifi.isWifiEnabled()) {
WifiManager mWifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (null == mWifi || !mWifi.isWifiEnabled()) {
//wifi 未启用
return "";
}
Expand Down Expand Up @@ -319,9 +320,31 @@ private static String convertUTF8ToString(String s) {
buffer[i] = (byte) Integer.parseInt(s.substring(start, start + 2), 16);
pos++;
}
return new String(buffer, 0, pos, "UTF-8");
//如果当前不是UTF8编码则改为GB18030编码,兼容GBK
return new String(buffer, 0, pos, isValidUtf8(buffer, total) ? "UTF-8" : "GB18030");
} catch (UnsupportedEncodingException e) {
return null;
}
}

/**
* 判断是否为UTF-8编码
*
* @param b 字节编码
* @param aMaxCount 最大数量
* @link https://blog.csdn.net/clbxp/article/details/6620388
*/
private static boolean isValidUtf8(byte[] b, int aMaxCount) {
int lLen = b.length, lCharCount = 0;
for (int i = 0; i < lLen && lCharCount < aMaxCount; ++lCharCount) {
byte lByte = b[i++];//to fast operation, ++ now, ready for the following for(;;)
if (lByte >= 0) continue;//>=0 is normal ascii
if (lByte < (byte) 0xc0 || lByte > (byte) 0xfd) return false;
int lCount = lByte > (byte) 0xfc ? 5 : lByte > (byte) 0xf8 ? 4
: lByte > (byte) 0xf0 ? 3 : lByte > (byte) 0xe0 ? 2 : 1;
if (i + lCount > lLen) return false;
for (int j = 0; j < lCount; ++j, ++i) if (b[i] >= (byte) 0xc0) return false;
}
return true;
}
}
Loading

0 comments on commit cafabc1

Please sign in to comment.