From 0f3b91bf4b42f8432c7a2a0a13be7f9f4c3a2295 Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 01:06:41 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC1.6.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index cecbca9..0720d77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { minSdkVersion 14 targetSdkVersion 27 versionCode 11 - versionName '1.6.4' + versionName '1.6.5' } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 From 6383d57b72196bf84a119476242992575f4a5e3d Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 01:15:01 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=B0=83=E6=95=B4utm=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 61c5b13..ad41dd4 100644 --- a/Readme.md +++ b/Readme.md @@ -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 \ No newline at end of file From 70778ebbd0fd43d8f5a8ec9e283f1c6324931d97 Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 01:31:44 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=80=E6=B3=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/net/loveyu/wifipwd/Action.java | 10 +++--- .../java/net/loveyu/wifipwd/ListMsgData.java | 2 +- .../java/net/loveyu/wifipwd/MainActivity.java | 31 +++++++++---------- .../java/net/loveyu/wifipwd/MsgHandle.java | 2 +- .../wifipwd/PasswordSortComparator.java | 2 +- .../java/net/loveyu/wifipwd/ReadWpaCfg.java | 16 +++++----- .../java/net/loveyu/wifipwd/WifiAdapter.java | 9 +++--- .../java/net/loveyu/wifipwd/readRunnable.java | 2 +- 8 files changed, 36 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/net/loveyu/wifipwd/Action.java b/app/src/main/java/net/loveyu/wifipwd/Action.java index a145559..75db648 100644 --- a/app/src/main/java/net/loveyu/wifipwd/Action.java +++ b/app/src/main/java/net/loveyu/wifipwd/Action.java @@ -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", @@ -43,14 +43,14 @@ public ArrayList> 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(); @@ -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(); } diff --git a/app/src/main/java/net/loveyu/wifipwd/ListMsgData.java b/app/src/main/java/net/loveyu/wifipwd/ListMsgData.java index d3d15e7..a9e5906 100644 --- a/app/src/main/java/net/loveyu/wifipwd/ListMsgData.java +++ b/app/src/main/java/net/loveyu/wifipwd/ListMsgData.java @@ -7,7 +7,7 @@ public class ListMsgData { public boolean is_refresh; public boolean show_notify; public ArrayList> list; - public ListMsgData(boolean is_refresh, ArrayList> list,boolean show_notify) { + ListMsgData(boolean is_refresh, ArrayList> list, boolean show_notify) { this.is_refresh = is_refresh; this.show_notify = show_notify; this.list = list; diff --git a/app/src/main/java/net/loveyu/wifipwd/MainActivity.java b/app/src/main/java/net/loveyu/wifipwd/MainActivity.java index acdd882..6ccbd03 100644 --- a/app/src/main/java/net/loveyu/wifipwd/MainActivity.java +++ b/app/src/main/java/net/loveyu/wifipwd/MainActivity.java @@ -36,8 +36,6 @@ public class MainActivity extends Activity { private WifiAdapter wifiAdapter = null; - private Action ac; - private ListView lv; private int log = 0; @@ -48,7 +46,7 @@ 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); if (ac.check_root()) { setContentView(R.layout.activity_main); @@ -61,7 +59,7 @@ protected void onCreate(Bundle savedInstanceState) { public void setList(ArrayList> 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 { @@ -72,15 +70,10 @@ public void setList(ArrayList> 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); } @@ -165,15 +158,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 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; @@ -217,7 +216,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); diff --git a/app/src/main/java/net/loveyu/wifipwd/MsgHandle.java b/app/src/main/java/net/loveyu/wifipwd/MsgHandle.java index ec926e0..951b3dc 100644 --- a/app/src/main/java/net/loveyu/wifipwd/MsgHandle.java +++ b/app/src/main/java/net/loveyu/wifipwd/MsgHandle.java @@ -5,7 +5,7 @@ public class MsgHandle extends Handler { - public MainActivity mainActivity; + private MainActivity mainActivity; public Action ac; public final static int WpListUpdate = 1; diff --git a/app/src/main/java/net/loveyu/wifipwd/PasswordSortComparator.java b/app/src/main/java/net/loveyu/wifipwd/PasswordSortComparator.java index 8797f76..6bf1ae1 100644 --- a/app/src/main/java/net/loveyu/wifipwd/PasswordSortComparator.java +++ b/app/src/main/java/net/loveyu/wifipwd/PasswordSortComparator.java @@ -10,7 +10,7 @@ public class PasswordSortComparator implements Comparator> { private String currentSSID; - public PasswordSortComparator(String currentSSID) { + PasswordSortComparator(String currentSSID) { this.currentSSID = currentSSID; } diff --git a/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java b/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java index 70a417b..618b383 100644 --- a/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java +++ b/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java @@ -32,13 +32,13 @@ * Created by loveyu on 2016/1/31. */ public class ReadWpaCfg { - ArrayList> list; + private ArrayList> 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>(); + list = new ArrayList<>(); this.wpa_config_path = wpa_supplicant_path; this.WifiConfigStore_path = WifiConfigStorePath; } @@ -187,7 +187,7 @@ private void read_wpa_config() { } private void parse(String content) { - Pattern pattern = Pattern.compile("network=\\{\\n([\\s\\S]+?)\\n\\}"); + Pattern pattern = Pattern.compile("network=\\{\\n([\\s\\S]+?)\\n}"); Matcher matcher = pattern.matcher(content); while (matcher.find()) { add(matcher.group()); @@ -197,7 +197,7 @@ private void parse(String content) { private void add(String content) { content = content.substring(9, content.length() - 2); String[] list = content.split("\\n"); - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); String k, v; for (String info : list) { int index = info.indexOf("="); @@ -228,7 +228,7 @@ private void add_kv(String ssid, String psk) { if (ssid == null || psk == null || "".equals(ssid) || psk.equals("")) { return; } - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); if (ssid.charAt(0) == '"') { ssid = ssid.substring(1, ssid.length() - 1); @@ -254,7 +254,7 @@ private void add_kv(String ssid, String psk) { * @return 返回完整的数据列表 */ public ArrayList> getPasswordList(Context context) { - ArrayList> rt = new ArrayList>(); + ArrayList> rt = new ArrayList<>(); for (Map map : this.list) { if (map.containsKey("psk") && map.containsKey("ssid")) { rt.add(map); @@ -284,8 +284,8 @@ private ArrayList> sortPasswordList(ArrayList> list; - public WifiAdapter(Context context, ArrayList> list) { + WifiAdapter(Context context, ArrayList> list) { super(); this.context = context; this.list = list; @@ -43,8 +42,8 @@ public View getView(int position, View convertView, ViewGroup parent) { } else { convertView = View.inflate(context, R.layout.wifi_item, null); holder = new ViewHolder(); - holder.ssid = (TextView) convertView.findViewById(R.id.textView_i_ssid); - holder.pwd = (TextView) convertView.findViewById(R.id.textView_i_pwd); + holder.ssid = convertView.findViewById(R.id.textView_i_ssid); + holder.pwd = convertView.findViewById(R.id.textView_i_pwd); convertView.setTag(holder); } holder.ssid.setText(obj.get("ssid")); diff --git a/app/src/main/java/net/loveyu/wifipwd/readRunnable.java b/app/src/main/java/net/loveyu/wifipwd/readRunnable.java index 52cb494..504ffa6 100644 --- a/app/src/main/java/net/loveyu/wifipwd/readRunnable.java +++ b/app/src/main/java/net/loveyu/wifipwd/readRunnable.java @@ -10,7 +10,7 @@ public class readRunnable implements Runnable { private boolean is_refresh; private boolean show_notify; - public readRunnable(MsgHandle handle, boolean is_refresh, boolean show_notify) { + readRunnable(MsgHandle handle, boolean is_refresh, boolean show_notify) { this.handle = handle; this.is_refresh = is_refresh; this.show_notify = show_notify; From 43bcd87addaaa1573fa4d8fc5f35ba50e85321ae Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 01:37:15 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E8=B0=83=E6=95=B41.6.5=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E4=B8=BA12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 0720d77..6bd1d10 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { applicationId "net.loveyu.wifipwd" minSdkVersion 14 targetSdkVersion 27 - versionCode 11 + versionCode 12 versionName '1.6.5' } compileOptions { From 538205a923334a5d925525303738d375aff370ba Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 02:51:12 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E9=9D=9EUTF8=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/net/loveyu/wifipwd/ReadWpaCfg.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java b/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java index 618b383..288f994 100644 --- a/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java +++ b/app/src/main/java/net/loveyu/wifipwd/ReadWpaCfg.java @@ -187,7 +187,7 @@ private void read_wpa_config() { } private void parse(String content) { - Pattern pattern = Pattern.compile("network=\\{\\n([\\s\\S]+?)\\n}"); + Pattern pattern = Pattern.compile("network=\\{\\n([\\s\\S]+?)\\n\\}"); Matcher matcher = pattern.matcher(content); while (matcher.find()) { add(matcher.group()); @@ -200,6 +200,7 @@ private void add(String content) { HashMap 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); @@ -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; + } } From 69bc427c32ed9bd79cf8104bc1545770be4aacb2 Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 03:38:50 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=B8=AD=E6=96=87ID=E6=98=BE=E7=A4=BA=E4=B9=B1=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 + .../net/loveyu/wifipwd/DeviceUuidFactory.java | 41 ++++++++++ .../java/net/loveyu/wifipwd/MainActivity.java | 5 +- .../main/java/net/loveyu/wifipwd/Report.java | 77 +++++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/net/loveyu/wifipwd/DeviceUuidFactory.java create mode 100644 app/src/main/java/net/loveyu/wifipwd/Report.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98ce911..cfd0435 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,8 @@ + + > li) { @@ -183,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); diff --git a/app/src/main/java/net/loveyu/wifipwd/Report.java b/app/src/main/java/net/loveyu/wifipwd/Report.java new file mode 100644 index 0000000..577ffef --- /dev/null +++ b/app/src/main/java/net/loveyu/wifipwd/Report.java @@ -0,0 +1,77 @@ +package net.loveyu.wifipwd; + +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.os.Build; +import android.util.DisplayMetrics; + +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.UUID; + +import static java.net.Proxy.Type.HTTP; + +public class Report implements Runnable { + private MainActivity context; + private String check_update_url; + private boolean hasRoot; + + Report(MainActivity context, String check_update_url, boolean hasRoot) { + this.context = context; + this.check_update_url = check_update_url; + this.hasRoot = hasRoot; + } + + @Override + public void run() { + try { + PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); + String update_url = check_update_url + "?version=" + pi.versionName; + + URL url = new URL(update_url); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + + conn.setRequestMethod("POST"); + conn.setReadTimeout(5000); + conn.setConnectTimeout(5000); + conn.setDoOutput(true); + conn.setDoInput(true); + conn.setUseCaches(false); + + DisplayMetrics dm = context.getResources().getDisplayMetrics(); + + String data = "uid=" + URLEncoder.encode(getUid().toString(), "UTF-8") + + "&version=" + URLEncoder.encode(pi.versionName, "UTF-8") + + "&version_code=" + pi.versionCode + + "&phone=" + URLEncoder.encode(android.os.Build.BRAND, "UTF-8") + + "&phone_model=" + URLEncoder.encode(android.os.Build.MODEL, "UTF-8") + + "&width=" + dm.widthPixels + + "&height=" + dm.heightPixels + + "&android=" + android.os.Build.VERSION.RELEASE + + "&android_sdk=" + Build.VERSION.SDK_INT + + "&has_root=" + (hasRoot ? 1 : 0); + + //获取输出流 + OutputStream out = conn.getOutputStream(); + out.write(data.getBytes()); + out.flush(); + + conn.getResponseCode(); + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /** + * 获取机器唯一ID + * + * @return 唯一UUID + */ + private UUID getUid() { + DeviceUuidFactory unid = new DeviceUuidFactory(this.context); + return unid.getDeviceUuid(); + } +} \ No newline at end of file From 75cac71e86c1a40695f1ebf49e68312e9d5190b3 Mon Sep 17 00:00:00 2001 From: loveyu Date: Sat, 14 Jul 2018 04:22:32 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20gradle=20=E4=B8=BA3.1.?= =?UTF-8?q?3=20=E5=92=8Cjava=20=E5=88=B01.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.iml | 18 ++++-------------- build.gradle | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/app.iml b/app/app.iml index 7b863ff..44da0b0 100644 --- a/app/app.iml +++ b/app/app.iml @@ -23,8 +23,8 @@ - - + + @@ -87,28 +87,18 @@ - - + - - - - - - - - + - - diff --git a/build.gradle b/build.gradle index dfadd5e..cf8d333 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0-alpha05' + classpath 'com.android.tools.build:gradle:3.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files