package com.enqualcomm.support.utils;
-import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.provider.Settings;
import android.widget.Toast;
+import com.enqualcomm.support.Config;
+import com.enqualcomm.support.CoreService;
+import com.enqualcomm.support.bean.Runtime;
+import com.enqualcomm.support.bean.VoiceContent;
+import com.enqualcomm.support.bean.voicePacket;
+import com.enqualcomm.support.service.Deliver;
+import com.ic.protocols.protocolAPIHelper;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
-
-import com.enqualcomm.support.Config;
-import com.enqualcomm.support.CoreService;
-import com.enqualcomm.support.bean.Runtime;
-import com.enqualcomm.support.bean.VoiceContent;
-import com.enqualcomm.support.bean.voicePacket;
-import com.enqualcomm.support.service.Deliver;
-import com.ic.protocols.protocolAPIHelper;
-
import static android.content.Context.CONNECTIVITY_SERVICE;
import static android.content.Context.WIFI_SERVICE;
import static chestnut.utils.FileUtils.closeIO;
import static chestnut.utils.StringUtils.isSpace;
public class Util {
- public static Charset UTF_16 = Charset.forName("UTF-16LE");
-
- public static Charset UTF_8 = Charset.forName("UTF-8");
-
- private static String FT6236U_upgrade_dev="/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftsfwupdate";
- private static String FT6236U_getver_dev="/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftstpfwver";
-
- public static void mSleep(int ms){
- try {
- Thread.yield();
- Thread.sleep(ms);
- }catch ( Exception e){
- ICLogger.e(e.getMessage(),e);
+ public static Charset UTF_16 = Charset.forName("UTF-16LE");
+
+ public static Charset UTF_8 = Charset.forName("UTF-8");
+
+ private static String FT6236U_upgrade_dev = "/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftsfwupdate";
+ private static String FT6236U_getver_dev = "/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftstpfwver";
+
+ public static void mSleep(int ms) {
+ try {
+ Thread.yield();
+ Thread.sleep(ms);
+ } catch (Exception e) {
+ ICLogger.e(e.getMessage(), e);
+ }
}
- }
- public static void SetRingMode(Context context,int mod,boolean vibmod){
- AudioManager am= (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
- int currentRingmod=am.getRingerMode();
- am.setRingerMode(mod);
- ICLogger.i("Current OldRingMod="+currentRingmod+", Set To RingMod="+mod+", check RingMod="+am.getRingerMode());
-
- int curretnVibmod=am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
-
- if(vibmod){
- Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING,1);
- am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
- am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
- } else {
- Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING,0);
- am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
- am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
+
+ public static void SetRingMode(Context context, int mod, boolean vibmod) {
+ AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ int currentRingmod = am.getRingerMode();
+ am.setRingerMode(mod);
+ ICLogger.i("Current OldRingMod=" + currentRingmod + ", Set To RingMod=" + mod + ", check RingMod=" + am.getRingerMode());
+
+ int curretnVibmod = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
+
+ if (vibmod) {
+ Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 1);
+ am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
+ am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
+ } else {
+ Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0);
+ am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
+ am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
+ }
+ ICLogger.i("Current OldVibRingMod=" + curretnVibmod + ", check VibRingMod=" + am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) + " , shoudl Vib " + am.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER));
+
}
- ICLogger.i("Current OldVibRingMod="+curretnVibmod+", check VibRingMod="+am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)+" , shoudl Vib "+am.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER));
-
- }
- public static void checkMesageNeedNotifi(String msg,Runtime runtime){
-
- if(msg!=null ) {
- //msg 格式 index,20201111182000,003f99302994
- String list[]= msg.split(",");
- if(list.length==3) {
- String index=list[0];
- String datetime=list[1];
- String txtmsg=list[2];
-
- long lasttime_inms=System.currentTimeMillis()-TimeUtil.parseDatetiime(datetime).getTime();
- ICLogger.i("有消息"+lasttime_inms/1000 +"秒未读!");
- if ((lasttime_inms>8*60*1000 && lasttime_inms<=13*60*1000) //在10分钟,20分钟时都提醒一次。
- ||(lasttime_inms>18*60*1000 && lasttime_inms<=23*60*1000))
- {
-
- if (!Config.custom_name.equals("VitracK") ){
- if(Config.protocol_no==Config.PROTOCOL_JIAI){
- txtmsg=Util.decodeUnicode2Utf8(txtmsg);
- }else {
- txtmsg = Util.UrlGB2312ToUTF8(txtmsg);
- }
- }
- if(Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN"))
- {
- runtime.setAlarmType(Runtime.AlarmType.ALARM_UNREADMSG);
- // Config.setLastUnReadMessage(CoreService.getInstance(),"");
- Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime));
- }
- runtime.getContextProxy().sendMsgBroadcast(txtmsg, 3); //msgType 3需要回复,0不需要回复
+ public static void checkMesageNeedNotifi(String msg, Runtime runtime) {
- //runtime.getContextProxy().sendMsgBroadcast(txtmsg, 0); //msgType 3需要回复,0不需要回复
+ if (msg != null) {
+ //msg 格式 index,20201111182000,003f99302994
+ String list[] = msg.split(",");
+ if (list.length == 3) {
+ String index = list[0];
+ String datetime = list[1];
+ String txtmsg = list[2];
+ long lasttime_inms = System.currentTimeMillis() - TimeUtil.parseDatetiime(datetime).getTime();
+ ICLogger.i("有消息" + lasttime_inms / 1000 + "秒未读!");
+ if ((lasttime_inms > 8 * 60 * 1000 && lasttime_inms <= 13 * 60 * 1000) //在10分钟,20分钟时都提醒一次。
+ || (lasttime_inms > 18 * 60 * 1000 && lasttime_inms <= 23 * 60 * 1000)) {
- }
+ if (!Config.custom_name.equals("VitracK")) {
+ if (Config.protocol_no == Config.PROTOCOL_JIAI) {
+ txtmsg = Util.decodeUnicode2Utf8(txtmsg);
+ } else {
+ txtmsg = Util.UrlGB2312ToUTF8(txtmsg);
+ }
+ }
+ if (Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN")) {
+ runtime.setAlarmType(Runtime.AlarmType.ALARM_UNREADMSG);
+ // Config.setLastUnReadMessage(CoreService.getInstance(),"");
+ Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime));
+ }
+ runtime.getContextProxy().sendMsgBroadcast(txtmsg, 3); //msgType 3需要回复,0不需要回复
- }else{
- ICLogger.i("UnreadMsg format error !");
- }
+ //runtime.getContextProxy().sendMsgBroadcast(txtmsg, 0); //msgType 3需要回复,0不需要回复
+
+
+ }
+
+
+ } else {
+ ICLogger.i("UnreadMsg format error !");
+ }
+ }
}
- }
-
- public static boolean installed(Context context,String appPackageName) {
- PackageManager packageManager = context.getPackageManager();// 获取packagemanager
- List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
- for (PackageInfo pkif : pinfo) {
- String pn = pkif.packageName;
- if (appPackageName.equals(pn)) {
- return true;
- }
+
+ public static boolean installed(Context context, String appPackageName) {
+ PackageManager packageManager = context.getPackageManager();// 获取packagemanager
+ List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
+ for (PackageInfo pkif : pinfo) {
+ String pn = pkif.packageName;
+ if (appPackageName.equals(pn)) {
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
- public static boolean is_FT6236U_upgrade_firmware_support(){
- boolean ret=getSystemProperties("product.tp.upgradeable").toLowerCase().equals("true");
- return ret;
- }
-
- public static boolean FT6236U_upgrade_firmware(){
- boolean ret=true;
- try {
- File nod=new File(FT6236U_upgrade_dev);
- ICLogger.i("can upgrade ? "+nod.exists()+" "+nod.canWrite()+"\n");
- FileOutputStream fos=new FileOutputStream(nod);
- fos.write(new byte[]{'1'});
- fos.close();
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- ret=false;
+
+ public static boolean is_FT6236U_upgrade_firmware_support() {
+ boolean ret = getSystemProperties("product.tp.upgradeable").toLowerCase().equals("true");
+ return ret;
}
- return ret;
- }
-
- public static String FT6236U_getVer(){
- String ret="not found";
- try {
- File nod=new File(FT6236U_getver_dev);
- FileInputStream fis=new FileInputStream(nod);
- byte buf[]=new byte[20];
- int bytes_readed=fis.read(buf,0,buf.length);
- fis.close();
- char charArray[]=new char[20];
- for (int i=0;i<bytes_readed;i++){
- charArray[i]=(char)buf[i];
- }
- ret=String.valueOf(charArray,0,bytes_readed);
- } catch (Exception e) {
- ICLogger.e(e.getMessage(),e);
- e.printStackTrace();
+
+ public static boolean FT6236U_upgrade_firmware() {
+ boolean ret = true;
+ try {
+ File nod = new File(FT6236U_upgrade_dev);
+ ICLogger.i("can upgrade ? " + nod.exists() + " " + nod.canWrite() + "\n");
+ FileOutputStream fos = new FileOutputStream(nod);
+ fos.write(new byte[]{'1'});
+ fos.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ ret = false;
+ }
+ return ret;
}
- return ret;
- }
- /**
- * 解析域名获取IP数组
- * @param host
- * @return
- */
- public static String parseHostGetIPAddress(String host) {
- StringBuilder serverip=new StringBuilder("");
- try {
-
-
- InetAddress[] inetAddressArr = InetAddress.getAllByName(host);
- if (inetAddressArr != null && inetAddressArr.length > 0) {
- String[] ipAddressArr = new String[inetAddressArr.length];
-
- for (int i = 0; i < inetAddressArr.length; i++) {
- String ip=inetAddressArr[i].getHostAddress();
- serverip.append( ip);
- ipAddressArr[i]=ip;
+ public static String FT6236U_getVer() {
+ String ret = "not found";
+ try {
+ File nod = new File(FT6236U_getver_dev);
+ FileInputStream fis = new FileInputStream(nod);
+ byte buf[] = new byte[20];
+ int bytes_readed = fis.read(buf, 0, buf.length);
+ fis.close();
+ char charArray[] = new char[20];
+ for (int i = 0; i < bytes_readed; i++) {
+ charArray[i] = (char) buf[i];
+ }
+ ret = String.valueOf(charArray, 0, bytes_readed);
+ } catch (Exception e) {
+ ICLogger.e(e.getMessage(), e);
+ e.printStackTrace();
}
- }
- } catch (Exception e) {
+
+ return ret;
+ }
+
+ /**
+ * 解析域名获取IP数组
+ *
+ * @param host
+ * @return
+ */
+ public static String parseHostGetIPAddress(String host) {
+ StringBuilder serverip = new StringBuilder("");
+ try {
+
+
+ InetAddress[] inetAddressArr = InetAddress.getAllByName(host);
+ if (inetAddressArr != null && inetAddressArr.length > 0) {
+ String[] ipAddressArr = new String[inetAddressArr.length];
+
+ for (int i = 0; i < inetAddressArr.length; i++) {
+ String ip = inetAddressArr[i].getHostAddress();
+ serverip.append(ip);
+ ipAddressArr[i] = ip;
+ }
+ }
+ } catch (Exception e) {
// e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- ICLogger.i("GetHostIpByName Failed " + host);
- return null;
+ ICLogger.e(e.getMessage(), e);
+ ICLogger.i("GetHostIpByName Failed " + host);
+ return null;
+ }
+ return serverip.toString();
}
- return serverip.toString();
- }
- /**
- *
- * 此函数专门给L02 协议使用 ,解析名字用
- * @param unicodestr
- * @return
- */
- public static String decodeUnicode2Utf8(String unicodestr) {
- int len = unicodestr.length();
- //由于协议中Unicode 都是不带\\u 字头的,和网络中常见的不同,直接4个字节代表一个unicode字。
- //如果不是4的整倍数,则证明字符串格式有误,取消转换
- if (len%4==0) {
- //先给每个unicode字符都加上\\u字头,然后再进行转换。
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < len; i += 4) {
- sb.append("\\u").append(unicodestr.substring(i, i + 4));
- }
- try {
- return decodeUnicode2Utf8Common(sb.toString());
- }catch (Exception e){
- ICLogger.e(e.getMessage(),e);
- return "";
- }
- }else{
- return "";
+
+ /**
+ * 此函数专门给L02 协议使用 ,解析名字用
+ *
+ * @param unicodestr
+ * @return
+ */
+ public static String decodeUnicode2Utf8(String unicodestr) {
+ int len = unicodestr.length();
+ //由于协议中Unicode 都是不带\\u 字头的,和网络中常见的不同,直接4个字节代表一个unicode字。
+ //如果不是4的整倍数,则证明字符串格式有误,取消转换
+ if (len % 4 == 0) {
+ //先给每个unicode字符都加上\\u字头,然后再进行转换。
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < len; i += 4) {
+ sb.append("\\u").append(unicodestr.substring(i, i + 4));
+ }
+ try {
+ return decodeUnicode2Utf8Common(sb.toString());
+ } catch (Exception e) {
+ ICLogger.e(e.getMessage(), e);
+ return "";
+ }
+ } else {
+ return "";
+ }
+
}
- }
-
- public static String decodeUnicode2Utf8Common(String unicodestr) {
- char aChar;
- int len = unicodestr.length();
- StringBuffer outBuffer = new StringBuffer(len);
- for (int x = 0; x < len; ) {
- aChar = unicodestr.charAt(x++);
- if (aChar == '\\') {
- aChar = unicodestr.charAt(x++);
- if (aChar == 'u') {
- // Read the xxxx
- int value = 0;
- for (int i = 0; i < 4; i++) {
- aChar = unicodestr.charAt(x++);
- switch (aChar) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- value = (value << 4) + aChar - '0';
- break;
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- value = (value << 4) + 10 + aChar - 'a';
- break;
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':
- value = (value << 4) + 10 + aChar - 'A';
- break;
- default:
- throw new IllegalArgumentException(
- "Malformed \\uxxxx encoding.");
- }
+ public static String decodeUnicode2Utf8Common(String unicodestr) {
+ char aChar;
+ int len = unicodestr.length();
+ StringBuffer outBuffer = new StringBuffer(len);
+ for (int x = 0; x < len; ) {
+ aChar = unicodestr.charAt(x++);
+ if (aChar == '\\') {
+ aChar = unicodestr.charAt(x++);
+ if (aChar == 'u') {
+ // Read the xxxx
+ int value = 0;
+ for (int i = 0; i < 4; i++) {
+ aChar = unicodestr.charAt(x++);
+ switch (aChar) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ value = (value << 4) + aChar - '0';
+ break;
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ value = (value << 4) + 10 + aChar - 'a';
+ break;
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ value = (value << 4) + 10 + aChar - 'A';
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Malformed \\uxxxx encoding.");
+ }
+
+ }
+ outBuffer.append((char) value);
+ } else {
+ if (aChar == 't')
+ aChar = '\t';
+ else if (aChar == 'r')
+ aChar = '\r';
+ else if (aChar == 'n')
+ aChar = '\n';
+ else if (aChar == 'f')
+ aChar = '\f';
+ outBuffer.append(aChar);
+ }
+ } else
+ outBuffer.append(aChar);
+ }
+ return outBuffer.toString();
+
- }
- outBuffer.append((char) value);
- } else {
- if (aChar == 't')
- aChar = '\t';
- else if (aChar == 'r')
- aChar = '\r';
- else if (aChar == 'n')
- aChar = '\n';
- else if (aChar == 'f')
- aChar = '\f';
- outBuffer.append(aChar);
- }
- } else
- outBuffer.append(aChar);
- }
- return outBuffer.toString();
-
-
- }
- public static String getSystemProperties(String prop){
-
- String str ="";
- Class clazz = null;
- try {
- clazz = Class.forName("android.os.SystemProperties");
- Method get=clazz.getMethod("get", new Class[] { String.class });
- str = (String)get.invoke(clazz, new Object[] { prop });
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
}
- return str;
- }
- public static String getSystemProperties(String prop,String defaultValue){
-
- String str =defaultValue;
- Class clazz = null;
- try {
- clazz = Class.forName("android.os.SystemProperties");
- Method get=clazz.getMethod("get", new Class[] { String.class });
- str = (String)get.invoke(clazz, new Object[] { prop });
- if(str==null || (str!=null && str.trim().isEmpty())){
- str=defaultValue;
- }
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+
+ public static String getSystemProperties(String prop) {
+
+ String str = "";
+ Class clazz = null;
+ try {
+ clazz = Class.forName("android.os.SystemProperties");
+ Method get = clazz.getMethod("get", new Class[]{String.class});
+ str = (String) get.invoke(clazz, new Object[]{prop});
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
+ return str;
}
- return str;
- }
- public static int getSystemPropertiesInt(String prop,int defaultValue){
-
- int ret=defaultValue;
- String str ="";
- Class clazz = null;
- try {
- clazz = Class.forName("android.os.SystemProperties");
- Method get=clazz.getMethod("get", new Class[] { String.class });
- str = (String)get.invoke(clazz, new Object[] { prop });
- if (str!=null && str.trim().length()>0 && isNumeric(str)){
- ret=Integer.parseInt(str);
- }
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+
+ public static String getSystemProperties(String prop, String defaultValue) {
+
+ String str = defaultValue;
+ Class clazz = null;
+ try {
+ clazz = Class.forName("android.os.SystemProperties");
+ Method get = clazz.getMethod("get", new Class[]{String.class});
+ str = (String) get.invoke(clazz, new Object[]{prop});
+ if (str == null || (str != null && str.trim().isEmpty())) {
+ str = defaultValue;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
+ return str;
}
- return ret;
- }
-
- public static boolean isNumeric(String str){
- Pattern pattern = Pattern.compile("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
- Matcher isNum = pattern.matcher(str);
- if( !isNum.matches() ){
- return false;
+
+ public static int getSystemPropertiesInt(String prop, int defaultValue) {
+
+ int ret = defaultValue;
+ String str = "";
+ Class clazz = null;
+ try {
+ clazz = Class.forName("android.os.SystemProperties");
+ Method get = clazz.getMethod("get", new Class[]{String.class});
+ str = (String) get.invoke(clazz, new Object[]{prop});
+ if (str != null && str.trim().length() > 0 && isNumeric(str)) {
+ ret = Integer.parseInt(str);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
+ return ret;
}
- return true;
- }
- static public void setSystemProperties(String key, int defaultValue) {
- String value = String.valueOf(defaultValue);
+ public static boolean isNumeric(String str) {
+ Pattern pattern = Pattern.compile("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
+ Matcher isNum = pattern.matcher(str);
+ if (!isNum.matches()) {
+ return false;
+ }
+ return true;
+ }
+
+ static public void setSystemProperties(String key, int defaultValue) {
- try {
+ String value = String.valueOf(defaultValue);
+
+ try {
- Class<?> c = Class.forName("android.os.SystemProperties");
+ Class<?> c = Class.forName("android.os.SystemProperties");
- Method set = c.getMethod("set", String.class, String.class );
+ Method set = c.getMethod("set", String.class, String.class);
- set.invoke(c, key, value );
+ set.invoke(c, key, value);
- } catch (Exception e) {
+ } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
}
- }
- static public void setSystemProperties(String key, String defaultValue) {
- String value = defaultValue;
+ static public void setSystemProperties(String key, String defaultValue) {
- try {
+ String value = defaultValue;
- Class<?> c = Class.forName("android.os.SystemProperties");
+ try {
- Method set = c.getMethod("set", String.class, String.class );
+ Class<?> c = Class.forName("android.os.SystemProperties");
- set.invoke(c, key, value );
+ Method set = c.getMethod("set", String.class, String.class);
- } catch (Exception e) {
+ set.invoke(c, key, value);
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
}
- }
- public static WifiConfiguration GetconfigWifiInfo(Context context, String ssid, String pwd, String encryptType) {
- WifiConfiguration wifiConfiguration=null;
- StringBuilder stringBuilder;
- WifiManager wifiManager = (WifiManager)context.getSystemService(WIFI_SERVICE);
- if (wifiManager != null && wifiManager.getConfiguredNetworks()!=null) {
- Iterator it = wifiManager.getConfiguredNetworks().iterator();
-
- while(it.hasNext()) {
- wifiConfiguration = (WifiConfiguration)it.next();
- if (wifiConfiguration != null) {
- String ssid_tmp = wifiConfiguration.SSID;
- stringBuilder= new StringBuilder();
- stringBuilder.append("\"");
- stringBuilder.append(ssid);
- stringBuilder.append("\"");
- if (ssid_tmp.equals(stringBuilder.toString())) {
- return wifiConfiguration;
+
+ public static WifiConfiguration GetconfigWifiInfo(Context context, String ssid, String pwd, String encryptType) {
+ WifiConfiguration wifiConfiguration = null;
+ StringBuilder stringBuilder;
+ WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE);
+ if (wifiManager != null && wifiManager.getConfiguredNetworks() != null) {
+ Iterator it = wifiManager.getConfiguredNetworks().iterator();
+
+ while (it.hasNext()) {
+ wifiConfiguration = (WifiConfiguration) it.next();
+ if (wifiConfiguration != null) {
+ String ssid_tmp = wifiConfiguration.SSID;
+ stringBuilder = new StringBuilder();
+ stringBuilder.append("\"");
+ stringBuilder.append(ssid);
+ stringBuilder.append("\"");
+ if (ssid_tmp.equals(stringBuilder.toString())) {
+ return wifiConfiguration;
+ }
+ }
}
- }
}
- }
+ WifiConfiguration retWiFiConfigration = wifiConfiguration;
+ if (retWiFiConfigration == null) {
+ retWiFiConfigration = new WifiConfiguration();
+ }
- WifiConfiguration retWiFiConfigration = wifiConfiguration;
- if (retWiFiConfigration == null) {
- retWiFiConfigration = new WifiConfiguration();
+ retWiFiConfigration.allowedAuthAlgorithms.clear();
+ retWiFiConfigration.allowedGroupCiphers.clear();
+ retWiFiConfigration.allowedKeyManagement.clear();
+ retWiFiConfigration.allowedPairwiseCiphers.clear();
+ retWiFiConfigration.allowedProtocols.clear();
+ stringBuilder = new StringBuilder();
+ stringBuilder.append("\"");
+ stringBuilder.append(ssid);
+ stringBuilder.append("\"");
+ retWiFiConfigration.SSID = stringBuilder.toString();
+ if ("none".equals(encryptType)) {
+ retWiFiConfigration.allowedKeyManagement.set(0);
+ } else if ("wep".equals(encryptType)) {
+ retWiFiConfigration.hiddenSSID = true;
+ stringBuilder = new StringBuilder();
+ stringBuilder.append("\"");
+ stringBuilder.append(pwd);
+ stringBuilder.append("\"");
+ retWiFiConfigration.wepKeys[0] = stringBuilder.toString();
+ retWiFiConfigration.allowedAuthAlgorithms.set(1);
+ retWiFiConfigration.allowedGroupCiphers.set(3);
+ retWiFiConfigration.allowedGroupCiphers.set(2);
+ retWiFiConfigration.allowedGroupCiphers.set(0);
+ retWiFiConfigration.allowedGroupCiphers.set(1);
+ retWiFiConfigration.allowedKeyManagement.set(0);
+ retWiFiConfigration.wepTxKeyIndex = 0;
+ } else if ("psk".equals(encryptType)) {
+ stringBuilder = new StringBuilder();
+ stringBuilder.append("\"");
+ stringBuilder.append(pwd);
+ stringBuilder.append("\"");
+ retWiFiConfigration.preSharedKey = stringBuilder.toString();
+ retWiFiConfigration.hiddenSSID = true;
+ retWiFiConfigration.allowedAuthAlgorithms.set(0);
+ retWiFiConfigration.allowedGroupCiphers.set(2);
+ retWiFiConfigration.allowedKeyManagement.set(1);
+ retWiFiConfigration.allowedPairwiseCiphers.set(1);
+ retWiFiConfigration.allowedGroupCiphers.set(3);
+ retWiFiConfigration.allowedPairwiseCiphers.set(2);
+ retWiFiConfigration.status = 2;
+ }
+
+ return retWiFiConfigration;
}
- retWiFiConfigration.allowedAuthAlgorithms.clear();
- retWiFiConfigration.allowedGroupCiphers.clear();
- retWiFiConfigration.allowedKeyManagement.clear();
- retWiFiConfigration.allowedPairwiseCiphers.clear();
- retWiFiConfigration.allowedProtocols.clear();
- stringBuilder = new StringBuilder();
- stringBuilder.append("\"");
- stringBuilder.append(ssid);
- stringBuilder.append("\"");
- retWiFiConfigration.SSID = stringBuilder.toString();
- if ("none".equals(encryptType)) {
- retWiFiConfigration.allowedKeyManagement.set(0);
- } else if ("wep".equals(encryptType)) {
- retWiFiConfigration.hiddenSSID = true;
- stringBuilder = new StringBuilder();
- stringBuilder.append("\"");
- stringBuilder.append(pwd);
- stringBuilder.append("\"");
- retWiFiConfigration.wepKeys[0] = stringBuilder.toString();
- retWiFiConfigration.allowedAuthAlgorithms.set(1);
- retWiFiConfigration.allowedGroupCiphers.set(3);
- retWiFiConfigration.allowedGroupCiphers.set(2);
- retWiFiConfigration.allowedGroupCiphers.set(0);
- retWiFiConfigration.allowedGroupCiphers.set(1);
- retWiFiConfigration.allowedKeyManagement.set(0);
- retWiFiConfigration.wepTxKeyIndex = 0;
- } else if ("psk".equals(encryptType)) {
- stringBuilder = new StringBuilder();
- stringBuilder.append("\"");
- stringBuilder.append(pwd);
- stringBuilder.append("\"");
- retWiFiConfigration.preSharedKey = stringBuilder.toString();
- retWiFiConfigration.hiddenSSID = true;
- retWiFiConfigration.allowedAuthAlgorithms.set(0);
- retWiFiConfigration.allowedGroupCiphers.set(2);
- retWiFiConfigration.allowedKeyManagement.set(1);
- retWiFiConfigration.allowedPairwiseCiphers.set(1);
- retWiFiConfigration.allowedGroupCiphers.set(3);
- retWiFiConfigration.allowedPairwiseCiphers.set(2);
- retWiFiConfigration.status = 2;
+ public static String byte2hex(byte[] var0) {
+ if (var0 == null) {
+ throw new IllegalArgumentException("Argument b ( byte array ) is null! ");
+ } else {
+ String var1 = "";
+
+ for (int var2 = 0; var2 < var0.length; ++var2) {
+ String var3 = Integer.toHexString(var0[var2] & 255);
+ StringBuilder var4;
+ if (var3.length() == 1) {
+ var4 = new StringBuilder();
+ var4.append(var1);
+ var4.append("0");
+ var4.append(var3);
+ var1 = var4.toString();
+ } else {
+ var4 = new StringBuilder();
+ var4.append(var1);
+ var4.append(var3);
+ var1 = var4.toString();
+ }
+ }
+
+ return var1.toUpperCase();
+ }
}
- return retWiFiConfigration;
- }
-
- public static String byte2hex(byte[] var0) {
- if (var0 == null) {
- throw new IllegalArgumentException("Argument b ( byte array ) is null! ");
- } else {
- String var1 = "";
-
- for(int var2 = 0; var2 < var0.length; ++var2) {
- String var3 = Integer.toHexString(var0[var2] & 255);
- StringBuilder var4;
- if (var3.length() == 1) {
- var4 = new StringBuilder();
- var4.append(var1);
- var4.append("0");
- var4.append(var3);
- var1 = var4.toString();
+ public static boolean checkNetwork(Context var0) {
+ NetworkInfo var2 = ((ConnectivityManager) var0.getSystemService(CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
+ boolean var1;
+ if (var2 != null && var2.isConnected()) {
+ var1 = true;
} else {
- var4 = new StringBuilder();
- var4.append(var1);
- var4.append(var3);
- var1 = var4.toString();
+ var1 = false;
}
- }
- return var1.toUpperCase();
- }
- }
-
- public static boolean checkNetwork(Context var0) {
- NetworkInfo var2 = ((ConnectivityManager)var0.getSystemService(CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
- boolean var1;
- if (var2 != null && var2.isConnected()) {
- var1 = true;
- } else {
- var1 = false;
+ return var1;
}
- return var1;
- }
-
- public static Method connectWifiByReflectMethod(Context var0, int var1) {
- WifiManager var2 = (WifiManager)var0.getSystemService(WIFI_SERVICE);
- Method[] var3;
- int var4;
- int var5;
- Method var6;
- Method var7;
- Class[] var8;
- Method var11;
- StringBuilder var12;
-
- ICLogger.i("connectWifiByReflectMethod road 1");
- var3 = var2.getClass().getDeclaredMethods();
- var4 = var3.length;
- var11 = null;
-
- for(var5 = 0; var5 < var4; var11 = var7) {
- var6 = var3[var5];
- var7 = var11;
- if ("connect".equalsIgnoreCase(var6.getName())) {
- var8 = var6.getParameterTypes();
- var7 = var11;
- if (var8 != null) {
+ public static Method connectWifiByReflectMethod(Context var0, int var1) {
+ WifiManager var2 = (WifiManager) var0.getSystemService(WIFI_SERVICE);
+ Method[] var3;
+ int var4;
+ int var5;
+ Method var6;
+ Method var7;
+ Class[] var8;
+ Method var11;
+ StringBuilder var12;
+
+ ICLogger.i("connectWifiByReflectMethod road 1");
+ var3 = var2.getClass().getDeclaredMethods();
+ var4 = var3.length;
+ var11 = null;
+
+ for (var5 = 0; var5 < var4; var11 = var7) {
+ var6 = var3[var5];
var7 = var11;
- if (var8.length > 0) {
- var7 = var11;
- if ("int".equalsIgnoreCase(var8[0].getName())) {
- var7 = var6;
- }
+ if ("connect".equalsIgnoreCase(var6.getName())) {
+ var8 = var6.getParameterTypes();
+ var7 = var11;
+ if (var8 != null) {
+ var7 = var11;
+ if (var8.length > 0) {
+ var7 = var11;
+ if ("int".equalsIgnoreCase(var8[0].getName())) {
+ var7 = var6;
+ }
+ }
+ }
}
- }
- }
-
- ++var5;
- }
- var7 = var11;
- if (var11 != null) {
- try {
- var11.invoke(var2, var1, null);
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- var12 = new StringBuilder();
- var12.append("connectWifiByReflectMethod Android ");
- var12.append(Build.VERSION.SDK_INT);
- var12.append(" error!");
- ICLogger.i(var12.toString());
- return null;
+ ++var5;
}
var7 = var11;
- }
-
- return var7;
- }
-
-
-
-
- public static int getDuration(String amrfilePath) {
- if (amrfilePath != null) {
- double d1;
- MediaPlayer mediaPlayer = new MediaPlayer();
- try {
- mediaPlayer.setDataSource(amrfilePath);
- mediaPlayer.prepare();
- int i = mediaPlayer.getDuration();
- d1 = i;
- mediaPlayer.release();
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- mediaPlayer.release();
- d1 = 1000.0D;
- } finally {}
- return (int)Math.ceil(d1 / 1000.0D);
- }
- double d = 1000.0D;
- return 0;
- }
-
- public static boolean LogfileExist(Runtime runtime,String logfilename){
- return new File(getLogfilePath(runtime,logfilename)).exists();
- }
- public static String getRecordfilePath(Runtime runtime,String recordfilename){
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(recordfilename);
- stringBuilder.append(".amr");
- File file = new File(runtime.getCacheDir(), stringBuilder.toString());
- return file.getAbsolutePath();
- }
-
- public static String getLogfilePath(Runtime runtime,String logfilename){
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(logfilename);
- stringBuilder.append(".txt");
- File file = new File(runtime.getCacheDir(), stringBuilder.toString());
- return file.getAbsolutePath();
- }
-
- public static void getDBFile() {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(StorageUtils.getExternalStorageLogDir());
- stringBuilder.append("/contacts.db");
- FileOutputUtil.copyFolder("/data/data/com.enqualcomm.support/databases", stringBuilder.toString());
- }
- private static int BUFFER_LEN=1024;
- /**
- * 压缩文件
- * @param srcFile 待压缩的源文件
- * @param rootPath 源文件的根路径
- * @param zos Zip输出流
- * @param comment 备注
- * @return 压缩成功返回true
- * @throws IOException
- */
- public static boolean zipFile(final File srcFile, String rootPath ,final ZipOutputStream zos ,final String comment) throws IOException {
- rootPath = rootPath + (isSpace(rootPath) ? "" : File.separator) + srcFile.getName();
-
- if (srcFile.isDirectory()) {
- File[] fileList = srcFile.listFiles();
- if (fileList == null || fileList.length <= 0) {
- ZipEntry entry = new ZipEntry(rootPath + '/');
- entry.setComment(comment);
- zos.putNextEntry(entry);
- zos.closeEntry();
- } else {
- for (File file : fileList) {
- if (!zipFile(file, rootPath, zos, comment)) return false;
- }
- }
- } else {
- InputStream is = null;
- try {
- is = new BufferedInputStream(new FileInputStream(srcFile));
- ZipEntry entry = new ZipEntry(rootPath);
- entry.setComment(comment);
- zos.putNextEntry(entry);
- byte buffer[] = new byte[BUFFER_LEN];
- int len;
- while ((len = is.read(buffer, 0, BUFFER_LEN)) != -1) {
- zos.write(buffer, 0, len);
+ if (var11 != null) {
+ try {
+ var11.invoke(var2, var1, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ var12 = new StringBuilder();
+ var12.append("connectWifiByReflectMethod Android ");
+ var12.append(Build.VERSION.SDK_INT);
+ var12.append(" error!");
+ ICLogger.i(var12.toString());
+ return null;
+ }
+
+ var7 = var11;
}
- zos.closeEntry();
- } finally {
- if(is!=null)
- closeIO(is);
- is=null;
- }
+
+ return var7;
}
- return true;
- }
- /**
- * Unzip the file by keyword.
- *
- * @param zipFile The ZIP file.
- * @param destDir The destination directory.
- * @param keyword The keyboard.
- * @return the unzipped files
- * @throws IOException if unzip unsuccessfully
- */
- public static List<File> unzipFileByKeyword(final File zipFile,final File destDir,final String keyword) throws IOException {
- if (zipFile == null || destDir == null) return null;
- List<File> files = new ArrayList<>();
- ZipFile zip = new ZipFile(zipFile);
- Enumeration<?> entries = zip.entries();
- try {
- if (isSpace(keyword)) {
- while (entries.hasMoreElements()) {
- ZipEntry entry = ((ZipEntry) entries.nextElement());
- String entryName = entry.getName();
- if (entryName.contains("../")) {
- ICLogger.log("ZipUtils", "it's dangerous!");//防止被利用漏洞恶意修改文件
- return files;
- }
- if (!unzipChildFile(destDir, files, zip, entry)) return files;
+
+
+ public static int getDuration(String amrfilePath) {
+ if (amrfilePath != null) {
+ double d1;
+ MediaPlayer mediaPlayer = new MediaPlayer();
+ try {
+ mediaPlayer.setDataSource(amrfilePath);
+ mediaPlayer.prepare();
+ int i = mediaPlayer.getDuration();
+ d1 = i;
+ mediaPlayer.release();
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ mediaPlayer.release();
+ d1 = 1000.0D;
+ } finally {
+ }
+ return (int) Math.ceil(d1 / 1000.0D);
}
- } else {
- while (entries.hasMoreElements()) {
- ZipEntry entry = ((ZipEntry) entries.nextElement());
- String entryName = entry.getName();
- if (entryName.contains("../")) {
- ICLogger.log("ZipUtils", "it's dangerous!");
- return files;
- }
- if (entryName.contains(keyword)) {
- if (!unzipChildFile(destDir, files, zip, entry)) return files;
- }
+ double d = 1000.0D;
+ return 0;
+ }
+
+ public static boolean LogfileExist(Runtime runtime, String logfilename) {
+ return new File(getLogfilePath(runtime, logfilename)).exists();
+ }
+
+ public static String getRecordfilePath(Runtime runtime, String recordfilename) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(recordfilename);
+ stringBuilder.append(".amr");
+ File file = new File(runtime.getCacheDir(), stringBuilder.toString());
+ return file.getAbsolutePath();
+ }
+
+ public static String getLogfilePath(Runtime runtime, String logfilename) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(logfilename);
+ stringBuilder.append(".txt");
+ File file = new File(runtime.getCacheDir(), stringBuilder.toString());
+ return file.getAbsolutePath();
+ }
+
+ public static void getDBFile() {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(StorageUtils.getExternalStorageLogDir());
+ stringBuilder.append("/contacts.db");
+ FileOutputUtil.copyFolder("/data/data/com.enqualcomm.support/databases", stringBuilder.toString());
+ }
+
+ private static int BUFFER_LEN = 1024;
+
+ /**
+ * 压缩文件
+ *
+ * @param srcFile 待压缩的源文件
+ * @param rootPath 源文件的根路径
+ * @param zos Zip输出流
+ * @param comment 备注
+ * @return 压缩成功返回true
+ * @throws IOException
+ */
+ public static boolean zipFile(final File srcFile, String rootPath, final ZipOutputStream zos, final String comment) throws IOException {
+ rootPath = rootPath + (isSpace(rootPath) ? "" : File.separator) + srcFile.getName();
+
+ if (srcFile.isDirectory()) {
+ File[] fileList = srcFile.listFiles();
+ if (fileList == null || fileList.length <= 0) {
+ ZipEntry entry = new ZipEntry(rootPath + '/');
+ entry.setComment(comment);
+ zos.putNextEntry(entry);
+ zos.closeEntry();
+ } else {
+ for (File file : fileList) {
+ if (!zipFile(file, rootPath, zos, comment)) return false;
+ }
+ }
+ } else {
+ InputStream is = null;
+ try {
+ is = new BufferedInputStream(new FileInputStream(srcFile));
+ ZipEntry entry = new ZipEntry(rootPath);
+ entry.setComment(comment);
+ zos.putNextEntry(entry);
+ byte buffer[] = new byte[BUFFER_LEN];
+ int len;
+ while ((len = is.read(buffer, 0, BUFFER_LEN)) != -1) {
+ zos.write(buffer, 0, len);
+ }
+ zos.closeEntry();
+ } finally {
+ if (is != null)
+ closeIO(is);
+ is = null;
+ }
}
- }
- } finally {
- zip.close();
+ return true;
}
- return files;
- }
-
- /***
- *
- * @param filename 输入SD卡中的文件或者目录的 相对路径
- * @return 压缩有的文件
- */
- public static String zipfiles(String filename){
- String zipfile=filename;
-
- try {
- String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath();
- File srcfile=new File(sdcard+"/"+filename);
- zipfile=sdcard+File.separator+srcfile.getName()+".zip";
- if (Util.zipFile(srcfile, "",
- new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32()))
- , filename)) {
- }
- }catch (Exception e){
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- zipfile="";
+
+ /**
+ * Unzip the file by keyword.
+ *
+ * @param zipFile The ZIP file.
+ * @param destDir The destination directory.
+ * @param keyword The keyboard.
+ * @return the unzipped files
+ * @throws IOException if unzip unsuccessfully
+ */
+ public static List<File> unzipFileByKeyword(final File zipFile, final File destDir, final String keyword) throws IOException {
+ if (zipFile == null || destDir == null) return null;
+ List<File> files = new ArrayList<>();
+ ZipFile zip = new ZipFile(zipFile);
+ Enumeration<?> entries = zip.entries();
+ try {
+ if (isSpace(keyword)) {
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = ((ZipEntry) entries.nextElement());
+ String entryName = entry.getName();
+ if (entryName.contains("../")) {
+ ICLogger.log("ZipUtils", "it's dangerous!");//防止被利用漏洞恶意修改文件
+ return files;
+ }
+ if (!unzipChildFile(destDir, files, zip, entry)) return files;
+ }
+ } else {
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = ((ZipEntry) entries.nextElement());
+ String entryName = entry.getName();
+ if (entryName.contains("../")) {
+ ICLogger.log("ZipUtils", "it's dangerous!");
+ return files;
+ }
+ if (entryName.contains(keyword)) {
+ if (!unzipChildFile(destDir, files, zip, entry)) return files;
+ }
+ }
+ }
+ } finally {
+ zip.close();
+ }
+ return files;
}
- return zipfile;
- }
-
- private static boolean unzipChildFile(final File destDir, final List<File> files, final ZipFile zip, final ZipEntry entry)
- throws IOException {
- File file = new File(destDir, entry.getName());
- files.add(file);
- if (entry.isDirectory()) {
- return createOrExistsDir(file);//创建文件夹
- } else {
- if (!createOrExistsFile(file)) return false;
- InputStream in = null;
- OutputStream out = null;
- try {
- in = new BufferedInputStream(zip.getInputStream(entry));
- out = new BufferedOutputStream(new FileOutputStream(file));
- byte buffer[] = new byte[BUFFER_LEN];
- int len;
- while ((len = in.read(buffer)) != -1) {
- out.write(buffer, 0, len);
+ /***
+ *
+ * @param filename 输入SD卡中的文件或者目录的 相对路径
+ * @return 压缩有的文件
+ */
+ public static String zipfiles(String filename) {
+ String zipfile = filename;
+
+ try {
+ String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();
+ File srcfile = new File(sdcard + "/" + filename);
+ zipfile = sdcard + File.separator + srcfile.getName() + ".zip";
+ if (Util.zipFile(srcfile, "",
+ new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile), new CRC32()))
+ , filename)) {
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ zipfile = "";
}
- } finally {
- if (in != null) {
- in.close();
+
+ return zipfile;
+ }
+
+ private static boolean unzipChildFile(final File destDir, final List<File> files, final ZipFile zip, final ZipEntry entry)
+ throws IOException {
+ File file = new File(destDir, entry.getName());
+ files.add(file);
+ if (entry.isDirectory()) {
+ return createOrExistsDir(file);//创建文件夹
+ } else {
+ if (!createOrExistsFile(file)) return false;
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = new BufferedInputStream(zip.getInputStream(entry));
+ out = new BufferedOutputStream(new FileOutputStream(file));
+ byte buffer[] = new byte[BUFFER_LEN];
+ int len;
+ while ((len = in.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ if (out != null) {
+ out.close();
+ }
+ }
}
- if (out != null) {
- out.close();
+ return true;
+ }
+
+ public static String getServerLogfilePath(String serverhost, String timefolder, String logfilename, Runtime runtime) {
+ StringBuilder urlbuilder = new StringBuilder();
+ String srvIP = serverhost;
+ if (SimSignalUtil.checkNet(runtime.getContextProxy().context)) {
+ srvIP = runtime.getDnsUtil().getServerIP_ByDNSCache("http://" + serverhost);
+ if (null == srvIP) {
+ srvIP = serverhost;
+ }
}
- }
+ urlbuilder.append("ftp://").append(srvIP).append("/")
+ .append("ftp/log/")
+ .append(DeviceInfoUtil.getModule()).append("/")
+ .append(DeviceInfoUtil.getSWVersionDisplayName()).append("/")
+ .append(CoreService.getInstance().getRuntime().IMEI()).append("/")
+ .append(timefolder);
+
+ return urlbuilder.toString();
+ }
+
+ public static boolean isConnectWifi(Context paramContext) {
+ ConnectivityManager connectivityManager = (ConnectivityManager) paramContext.getSystemService(CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
+ NetworkInfo.State state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
+ return (networkInfo != null && networkInfo.isAvailable() && state == NetworkInfo.State.CONNECTED);
+ }
+
+ public static boolean isWifiInIdle(Context paramContext) {
+ NetworkInfo.State state = ((ConnectivityManager) paramContext.getSystemService(CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("yls wifi=");
+ stringBuilder.append(state);
+ ICLogger.i(stringBuilder.toString());
+ return (state == NetworkInfo.State.DISCONNECTED);
+ }
+
+ public static boolean isWifiIsOpen(Context paramContext, Runtime paramRuntime) {
+ return paramRuntime.getContextProxy().getWifiManager().isWifiEnabled();
}
- return true;
- }
-
- public static String getServerLogfilePath(String serverhost,String timefolder,String logfilename ,Runtime runtime) {
- StringBuilder urlbuilder=new StringBuilder();
- String srvIP=serverhost;
- if (SimSignalUtil.checkNet(runtime.getContextProxy().context) ) {
- srvIP=runtime.getDnsUtil().getServerIP_ByDNSCache("http://"+serverhost);
- if (null == srvIP ) {
- srvIP=serverhost;
- }
+
+ public static void ShowToast(Runtime runtime, String msg) {
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ Handler handler = new Handler(Looper.getMainLooper());
+ handler.post(new Runnable() {
+
+ @Override
+ public void run() {
+ Toast.makeText(runtime.getContextProxy().context, msg, Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+ }).start();
}
- urlbuilder.append("ftp://").append(srvIP).append("/")
- .append("ftp/log/")
- .append(DeviceInfoUtil.getModule()).append("/")
- .append(DeviceInfoUtil.getSWVersionDisplayName()).append("/")
- .append(CoreService.getInstance().getRuntime().IMEI()).append("/")
- .append(timefolder);
-
- return urlbuilder.toString();
- }
- public static boolean isConnectWifi(Context paramContext) {
- ConnectivityManager connectivityManager = (ConnectivityManager)paramContext.getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- NetworkInfo.State state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
- return (networkInfo != null && networkInfo.isAvailable() && state == NetworkInfo.State.CONNECTED);
- }
-
- public static boolean isWifiInIdle(Context paramContext) {
- NetworkInfo.State state = ((ConnectivityManager)paramContext.getSystemService(CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append("yls wifi=");
- stringBuilder.append(state);
- ICLogger.i(stringBuilder.toString());
- return (state == NetworkInfo.State.DISCONNECTED);
- }
-
- public static boolean isWifiIsOpen(Context paramContext, Runtime paramRuntime) {
- return paramRuntime.getContextProxy().getWifiManager().isWifiEnabled();
- }
- public static void ShowToast(Runtime runtime,String msg) {
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- Handler handler = new Handler(Looper.getMainLooper());
- handler.post(new Runnable() {
-
- @Override
- public void run() {
- Toast.makeText(runtime.getContextProxy().context, msg, Toast.LENGTH_LONG).show();
- }
- });
- }
- }).start();
- }
-
- public static byte[] loadFile(File paramFile) {
+
+ public static byte[] loadFile(File paramFile) {
// if (paramFile != null && paramFile.exists())
// try {
// if (paramFile.getName().endsWith(".jpg")) {
// } catch (IOException paramFile) {
// paramFile.printStackTrace();
// }
- return null;
- }
-
- public static File makeDir(File paramFile, String paramString) {
- StringBuilder stringBuilder = new StringBuilder(Integer.toHexString(paramString.hashCode()));
-// for (byte b = 2; b < stringBuilder.length(); b += 3)
-// stringBuilder.insert(b, "/");
- paramFile = new File(paramFile, stringBuilder.toString());
- paramFile.mkdirs();
- return paramFile;
- }
-
- public static String saveFile(byte[] buf, int start, int size, File dir, String filename) {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(UUID.randomUUID().toString());
- stringBuilder.append("_");
- stringBuilder.append(filename);
- filename = stringBuilder.toString();
- File paramFile = makeDir(dir, filename); //建立以文件名Hash命名的路径
- try {
- paramFile = new File(paramFile, filename);//在路径下再建立文件
- FileOutputStream fos=new FileOutputStream(paramFile);
- fos.write(buf,start,size);
- fos.close();
- return paramFile.getAbsolutePath();
- } catch (IOException e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+ return null;
}
- return null;
- }
-
- public static ArrayList<byte[]> split(byte[] paramArrayOfByte, byte paramByte, int paramInt) {
- ArrayList arrayList = new ArrayList();
- int m = paramArrayOfByte.length;
- int k = paramInt;
- int j = paramInt;
- for (paramInt = k; j < m; paramInt = k) {
- k = paramInt;
- if (paramArrayOfByte[j] == paramByte) {
- k = j - paramInt;
- if (k != 0) {
- byte[] arrayOfByte = new byte[k];
- System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, k);
- arrayList.add(arrayOfByte);
- }
- k = j + 1;
- }
- j++;
- }
- int i = m - paramInt;
- if (i != 0) {
- byte[] arrayOfByte = new byte[i];
- System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, i);
- arrayList.add(arrayOfByte);
- }
- return arrayList;
- }
-
- public static ArrayList<byte[]> split(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) {
- ArrayList arrayList = new ArrayList();
- int k = paramArrayOfByte1.length;
- int m = paramArrayOfByte2.length;
- int i = 0;
- int j;
- int n;
- for (j = 0; i < k; j = n) {
-
- int i1;
- byte b = 0;
- while (true) {
- int bool = i + b;
- i1 = i;
- n = j;
- if (bool < k) {
- i1 = i;
- n = j;
- if (paramArrayOfByte1[bool] == paramArrayOfByte2[b]) {
- b = (byte)(b + 1);
-
- if (n == m) {
- n = i - j;
- if (n != 0) {
- byte[] arrayOfByte = new byte[n];
- System.arraycopy(paramArrayOfByte1, j, arrayOfByte, 0, n);
- arrayList.add(arrayOfByte);
- }
- i += m;
- n = i;
- i1 = i - 1;
- break;
- }
- continue;
- }
+
+ public static File makeDir(File paramFile, String paramString) {
+ StringBuilder stringBuilder = new StringBuilder(Integer.toHexString(paramString.hashCode()));
+ paramFile = new File(paramFile, stringBuilder.toString());
+ paramFile.mkdirs();
+ return paramFile;
+ }
+
+ public static String saveFile(byte[] buf, int start, int size, File dir, String filename) {
+
+ System.out.print("[");
+ for (byte b : buf) {
+ System.out.print(b + ",");
}
- break;
- }
- i = i1 + 1;
+ System.out.println("]");
+ System.out.println("-----after------");
+
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(UUID.randomUUID().toString());
+ stringBuilder.append("_");
+ stringBuilder.append(filename);
+ filename = stringBuilder.toString();
+ File paramFile = makeDir(dir, filename); //建立以文件名Hash命名的路径
+ try {
+ paramFile = new File(paramFile, filename);//在路径下再建立文件
+ FileOutputStream fos = new FileOutputStream(paramFile);
+ fos.write(buf, start, size);
+ fos.close();
+ return paramFile.getAbsolutePath();
+ } catch (IOException e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
+ return null;
}
- i = paramArrayOfByte1.length - j;
- if (i != 0) {
- paramArrayOfByte2 = new byte[i];
- System.arraycopy(paramArrayOfByte1, j, paramArrayOfByte2, 0, i);
- arrayList.add(paramArrayOfByte2);
+
+ public static ArrayList<byte[]> split(byte[] paramArrayOfByte, byte paramByte, int paramInt) {
+ ArrayList arrayList = new ArrayList();
+ int m = paramArrayOfByte.length;
+ int k = paramInt;
+ int j = paramInt;
+ for (paramInt = k; j < m; paramInt = k) {
+ k = paramInt;
+ if (paramArrayOfByte[j] == paramByte) {
+ k = j - paramInt;
+ if (k != 0) {
+ byte[] arrayOfByte = new byte[k];
+ System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, k);
+ arrayList.add(arrayOfByte);
+ }
+ k = j + 1;
+ }
+ j++;
+ }
+ int i = m - paramInt;
+ if (i != 0) {
+ byte[] arrayOfByte = new byte[i];
+ System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, i);
+ arrayList.add(arrayOfByte);
+ }
+ return arrayList;
}
- return arrayList;
- }
-
- public static byte[] subArray(byte[] paramArrayOfByte, int paramInt) {
- return subArray(paramArrayOfByte, paramInt, paramArrayOfByte.length);
- }
-
- public static byte[] subArray(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
- paramInt2 -= paramInt1;
- byte[] arrayOfByte = new byte[paramInt2];
- System.arraycopy(paramArrayOfByte, paramInt1, arrayOfByte, 0, paramInt2);
- return arrayOfByte;
- }
-
- public static void turnOffWifiForSleep(Context paramContext, Runtime paramRuntime) {
- paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(false);
- }
-
- public static void turnOnWifiForConnect(Context paramContext, Runtime paramRuntime) {
- paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(true);
- }
-
-
- public static boolean parseToVoicePacketSent(VoiceContent voiceContent){
-
- long filesize;
- File voicefile=new File(voiceContent.content);
- if (voicefile.exists()) {
- filesize = voicefile.length();
-
- int count= (int)(filesize/1024);
- if ((filesize%1024)>0)
- count++;
- ICLogger.i("File "+voiceContent.content+", size "+filesize+", count "+count + " filetype "+voiceContent.filetype + ", datatype "+voiceContent.datatype);
- voicePacket.getInstanceSent().clearPacket();
- voicePacket.getInstanceSent().setFileType(voiceContent.filetype,voiceContent.datatype);
- try {
- FileInputStream fis = new FileInputStream(voicefile);
- byte[] audiobuf = new byte[1024];
- for (int i = 0; i < count; i++) {
- int readbytes=fis.read(audiobuf,0,1024);
- voicePacket.getInstanceSent().appendVoice(voiceContent.contactNumber, "", count, i, readbytes, audiobuf);
+
+ public static ArrayList<byte[]> split(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) {
+ ArrayList arrayList = new ArrayList();
+ int k = paramArrayOfByte1.length;
+ int m = paramArrayOfByte2.length;
+ int i = 0;
+ int j;
+ int n;
+ for (j = 0; i < k; j = n) {
+
+ int i1;
+ byte b = 0;
+ while (true) {
+ int bool = i + b;
+ i1 = i;
+ n = j;
+ if (bool < k) {
+ i1 = i;
+ n = j;
+ if (paramArrayOfByte1[bool] == paramArrayOfByte2[b]) {
+ b = (byte) (b + 1);
+
+ if (n == m) {
+ n = i - j;
+ if (n != 0) {
+ byte[] arrayOfByte = new byte[n];
+ System.arraycopy(paramArrayOfByte1, j, arrayOfByte, 0, n);
+ arrayList.add(arrayOfByte);
+ }
+ i += m;
+ n = i;
+ i1 = i - 1;
+ break;
+ }
+ continue;
+ }
+ }
+ break;
+ }
+ i = i1 + 1;
}
- fis.close();
- voicePacket.getInstanceSent().setCurrentIndexToSent(0);
- voicePacket.getInstanceSent().setPacketTime(TimeUtil.getSystemTime3());
- return true;
- }catch (Exception e){
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- }
+ i = paramArrayOfByte1.length - j;
+ if (i != 0) {
+ paramArrayOfByte2 = new byte[i];
+ System.arraycopy(paramArrayOfByte1, j, paramArrayOfByte2, 0, i);
+ arrayList.add(paramArrayOfByte2);
+ }
+ return arrayList;
+ }
+ public static byte[] subArray(byte[] paramArrayOfByte, int paramInt) {
+ return subArray(paramArrayOfByte, paramInt, paramArrayOfByte.length);
}
- return false;
- }
-
-
- public static void reboot(Context context) {
- PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
- try {
- ICLogger.i("do reboot!");
- powerManager.reboot("remote reboot");
- ICLogger.i("命令重启");
- return;
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
- return;
+
+ public static byte[] subArray(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
+ paramInt2 -= paramInt1;
+ byte[] arrayOfByte = new byte[paramInt2];
+ System.arraycopy(paramArrayOfByte, paramInt1, arrayOfByte, 0, paramInt2);
+ return arrayOfByte;
}
- }
-
-
- public static void shutdown() {
- try {
- ICLogger.i("do shutdown!");
- //获得ServiceManager类
- Class ServiceManager = Class
- .forName("android.os.ServiceManager");
-
- //获得ServiceManager的getService方法
- Method getService = ServiceManager.getMethod("getService", java.lang.String.class);
-
- //调用getService获取RemoteService
- Object oRemoteService = getService.invoke(null, Context.POWER_SERVICE);
-
- //获得IPowerManager.Stub类
- Class cStub = Class
- .forName("android.os.IPowerManager$Stub");
- //获得asInterface方法
- Method asInterface = cStub.getMethod("asInterface", android.os.IBinder.class);
- //调用asInterface方法获取IPowerManager对象
- Object oIPowerManager = asInterface.invoke(null, oRemoteService);
- //获得shutdown()方法
- Method shutdown = oIPowerManager.getClass().getMethod("shutdown",boolean.class,boolean.class);
- //调用shutdown()方法
- shutdown.invoke(oIPowerManager,false,true);
-
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+
+ public static void turnOffWifiForSleep(Context paramContext, Runtime paramRuntime) {
+ paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(false);
}
- }
-
- public static final String ACTION_MASTER_CLEAR = "android.intent.action.MASTER_CLEAR";
- public static final String EXTRA_REASON = "android.intent.extra.REASON";
- public static final String EXTRA_WIPE_EXTERNAL_STORAGE = "android.intent.extra.WIPE_EXTERNAL_STORAGE";
-
- public static void doMasterClear(Context context) {
- ICLogger.i("do doMasterClear!");
- Intent intent = new Intent(ACTION_MASTER_CLEAR);
- intent.setPackage("android");
- intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
- intent.putExtra(EXTRA_REASON, "MasterClearConfirm");
- if (Environment.isExternalStorageRemovable()) {
- intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, true);
- }else
- {
- intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, false);
+
+ public static void turnOnWifiForConnect(Context paramContext, Runtime paramRuntime) {
+ paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(true);
}
- context.sendBroadcast(intent);
- }
+ /**
+ * 传入数据,然后做转换
+ *
+ * @param source 源数据
+ * @param isSend 是否要发送
+ * @return
+ */
+ public static byte[] fzdTransfer(byte[] source, boolean isSend) {
+ System.out.print("[");
+ for (byte b : source) {
+ System.out.print(b + ",");
+ }
+ System.out.println("]");
+ System.out.println("-----before------");
+ List<Byte> list = new ArrayList<>();
+ byte a = 0X7D;
+ if (isSend) {
+ //往外发的数据
+ // 0X7D --> 0X7D 0X01
+ // 0X5B --> 0X7D 0X02
+ // 0X5D --> 0X7D 0X03
+ // 0X2C --> 0X7D 0X04
+ // 0X2A --> 0X7D 0X05
+ for (byte value : source) {
+ if (value == 0x7d) {
+ list.add(a);
+ byte b = 0X01;
+ list.add(b);
+ } else if (value == 0x5b) {
+ list.add(a);
+ byte b = 0X02;
+ list.add(b);
+ } else if (value == 0x5d) {
+ list.add(a);
+ byte b = 0X03;
+ list.add(b);
+ } else if (value == 0x2c) {
+ list.add(a);
+ byte b = 0X04;
+ list.add(b);
+ } else if (value == 0x2a) {
+ list.add(a);
+ byte b = 0X05;
+ list.add(b);
+ } else {
+ list.add(value);
+ }
+ }
+ } else {
+ // 0X7D 0X01 --> 0X7D
+ // 0X7D 0X02 --> 0X5B
+ // 0X7D 0X03 --> 0X5D
+ // 0X7D 0X04 --> 0X2C
+ // 0X7D 0X05 --> 0X2A
+ for (int i = 0; i < source.length - 1; i += 2) {
+ //如果i是最后一位,那么直接添加完事
+ if (i == source.length - 1) {
+ list.add(source[i]);
+ } else if (source[i] == a && source[i + 1] == 0X01) {
+ byte b = 0X7D;
+ list.add(b);
+ } else if (source[i] == a && source[i + 1] == 0X02) {
+ byte b = 0X5B;
+ list.add(b);
+ } else if (source[i] == a && source[i + 1] == 0X03) {
+ byte b = 0X5D;
+ list.add(b);
+ } else if (source[i] == a && source[i + 1] == 0X04) {
+ byte b = 0X2C;
+ list.add(b);
+ } else if (source[i] == a && source[i + 1] == 0X05) {
+ byte b = 0X2A;
+ list.add(b);
+ } else {
+ list.add(source[i]);
+ list.add(source[i + 1]);
+ }
+ }
+ }
+ byte[] result = new byte[list.size()];
+ for (int i = 0; i < list.size(); i++) {
+ result[i] = list.get(i);
+ }
+ return result;
+ }
- public static String UrlGB2312ToUTF8(String url){
- String ret="";
- String src=url;
+ public static boolean parseToVoicePacketSent(VoiceContent voiceContent) {
+
+ long filesize;
+ File voicefile = new File(voiceContent.content);
+ if (voicefile.exists()) {
+ filesize = voicefile.length();
+
+ int count = (int) (filesize / 1024);
+ if ((filesize % 1024) > 0)
+ count++;
+ ICLogger.i("File " + voiceContent.content + ", size " + filesize + ", count " + count + " filetype " + voiceContent.filetype + ", datatype " + voiceContent.datatype);
+ voicePacket.getInstanceSent().clearPacket();
+ voicePacket.getInstanceSent().setFileType(voiceContent.filetype, voiceContent.datatype);
+ try {
+ FileInputStream fis = new FileInputStream(voicefile);
+ byte[] audiobuf = new byte[1024];
+ for (int i = 0; i < count; i++) {
+ int readbytes = fis.read(audiobuf, 0, 1024);
+ voicePacket.getInstanceSent().appendVoice(voiceContent.contactNumber, "", count, i, readbytes, audiobuf);
+ }
+ fis.close();
+ voicePacket.getInstanceSent().setCurrentIndexToSent(0);
+ voicePacket.getInstanceSent().setPacketTime(TimeUtil.getSystemTime3());
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
+ }
+ return false;
+ }
- if (!url.contains("%")){
- int len = url.length();
- //由于协议中GB2312 都是不带% 字头的,和网络中常见的不同,直接2个字节代表一个GB2312字。
- //如果不是2的整倍数,则证明字符串格式有误,取消转换
- if (len%2==0) {
- //先给每个unicode字符都加上\\u字头,然后再进行转换。
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < len; i += 2) {
- sb.append("%").append(url.substring(i, i + 2));
+ public static void reboot(Context context) {
+ PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ try {
+ ICLogger.i("do reboot!");
+ powerManager.reboot("remote reboot");
+ ICLogger.i("命令重启");
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ return;
}
- src=sb.toString();
- }else{
- return ret;
- }
}
- try {
- ret=java.net.URLDecoder.decode(src,"GB2312");
- } catch (Exception e) {
- e.printStackTrace();
- ICLogger.e(e.getMessage(),e);
+
+
+ public static void shutdown() {
+ try {
+ ICLogger.i("do shutdown!");
+ //获得ServiceManager类
+ Class ServiceManager = Class
+ .forName("android.os.ServiceManager");
+
+ //获得ServiceManager的getService方法
+ Method getService = ServiceManager.getMethod("getService", java.lang.String.class);
+
+ //调用getService获取RemoteService
+ Object oRemoteService = getService.invoke(null, Context.POWER_SERVICE);
+
+ //获得IPowerManager.Stub类
+ Class cStub = Class
+ .forName("android.os.IPowerManager$Stub");
+ //获得asInterface方法
+ Method asInterface = cStub.getMethod("asInterface", android.os.IBinder.class);
+ //调用asInterface方法获取IPowerManager对象
+ Object oIPowerManager = asInterface.invoke(null, oRemoteService);
+ //获得shutdown()方法
+ Method shutdown = oIPowerManager.getClass().getMethod("shutdown", boolean.class, boolean.class);
+ //调用shutdown()方法
+ shutdown.invoke(oIPowerManager, false, true);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
}
- return ret;
- }
- public static String UTF8ToUrlGB2312(String msg){
+ public static final String ACTION_MASTER_CLEAR = "android.intent.action.MASTER_CLEAR";
+ public static final String EXTRA_REASON = "android.intent.extra.REASON";
+ public static final String EXTRA_WIPE_EXTERNAL_STORAGE = "android.intent.extra.WIPE_EXTERNAL_STORAGE";
+
+ public static void doMasterClear(Context context) {
+ ICLogger.i("do doMasterClear!");
+ Intent intent = new Intent(ACTION_MASTER_CLEAR);
+ intent.setPackage("android");
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+ intent.putExtra(EXTRA_REASON, "MasterClearConfirm");
+ if (Environment.isExternalStorageRemovable()) {
+ intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, true);
+ } else {
+ intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, false);
+ }
+ context.sendBroadcast(intent);
+ }
- String ret="";
- try {
- ret=java.net.URLEncoder.encode(msg,"GB2312");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
+
+ public static String UrlGB2312ToUTF8(String url) {
+ String ret = "";
+ String src = url;
+
+
+ if (!url.contains("%")) {
+ int len = url.length();
+ //由于协议中GB2312 都是不带% 字头的,和网络中常见的不同,直接2个字节代表一个GB2312字。
+ //如果不是2的整倍数,则证明字符串格式有误,取消转换
+ if (len % 2 == 0) {
+ //先给每个unicode字符都加上\\u字头,然后再进行转换。
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < len; i += 2) {
+ sb.append("%").append(url.substring(i, i + 2));
+ }
+ src = sb.toString();
+ } else {
+ return ret;
+ }
+ }
+ try {
+ ret = java.net.URLDecoder.decode(src, "GB2312");
+ } catch (Exception e) {
+ e.printStackTrace();
+ ICLogger.e(e.getMessage(), e);
+ }
+ return ret;
}
- return ret;
- }
- public static String bytesToHexString(byte[] src) {
- StringBuilder stringBuilder = new StringBuilder("");
- if (src == null || src.length <= 0) {
- return null;
+ public static String UTF8ToUrlGB2312(String msg) {
+
+ String ret = "";
+ try {
+ ret = java.net.URLEncoder.encode(msg, "GB2312");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return ret;
}
- for (int i = 0; i < src.length; i++) {
- int v = src[i] & 0xFF;
- String hv = Integer.toHexString(v);
- if (hv.length() < 2) {
- stringBuilder.append(0);
- }
- stringBuilder.append(hv);
+
+ public static String bytesToHexString(byte[] src) {
+ StringBuilder stringBuilder = new StringBuilder("");
+ if (src == null || src.length <= 0) {
+ return null;
+ }
+ for (int i = 0; i < src.length; i++) {
+ int v = src[i] & 0xFF;
+ String hv = Integer.toHexString(v);
+ if (hv.length() < 2) {
+ stringBuilder.append(0);
+ }
+ stringBuilder.append(hv);
+ }
+ return stringBuilder.toString();
+ }
+
+ public static byte[] hexStringToBytes(String hexString) {
+ if (hexString == null || hexString.equals("")) {
+ return null;
+ }
+ hexString = hexString.toUpperCase();
+ int length = hexString.length() / 2;
+ char[] hexChars = hexString.toCharArray();
+ byte[] d = new byte[length];
+ for (int i = 0; i < length; i++) {
+ int pos = i * 2;
+ d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+ }
+ return d;
+ }
+
+ private static byte charToByte(char c) {
+ return (byte) "0123456789ABCDEF".indexOf(c);
}
- return stringBuilder.toString();
- }
- public static byte[] hexStringToBytes(String hexString) {
- if (hexString == null || hexString.equals("")) {
- return null;
+
+ public static int byteArray4ToInt(byte[] b) {
+ return b[3] & 0xFF |
+ (b[2] & 0xFF) << 8 |
+ (b[1] & 0xFF) << 16 |
+ (b[0] & 0xFF) << 24;
}
- hexString = hexString.toUpperCase();
- int length = hexString.length() / 2;
- char[] hexChars = hexString.toCharArray();
- byte[] d = new byte[length];
- for (int i = 0; i < length; i++) {
- int pos = i * 2;
- d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+
+ public static byte[] intToByteArray4(int a) {
+ return new byte[]{
+ (byte) ((a >> 24) & 0xFF),
+ (byte) ((a >> 16) & 0xFF),
+ (byte) ((a >> 8) & 0xFF),
+ (byte) (a & 0xFF)
+ };
}
- return d;
- }
- private static byte charToByte(char c) {
- return (byte) "0123456789ABCDEF".indexOf(c);
- }
-
- public static int byteArray4ToInt(byte[] b) {
- return b[3] & 0xFF |
- (b[2] & 0xFF) << 8 |
- (b[1] & 0xFF) << 16 |
- (b[0] & 0xFF) << 24;
- }
- public static byte[] intToByteArray4(int a) {
- return new byte[] {
- (byte) ((a >> 24) & 0xFF),
- (byte) ((a >> 16) & 0xFF),
- (byte) ((a >> 8) & 0xFF),
- (byte) (a & 0xFF)
- };
- }
-
- /**
- * 将字节数组转为long<br>
- * 如果input为null,或offset指定的剩余数组长度不足8字节则抛出异常
- * @param input
- * @param offset 起始偏移量
- * @param littleEndian 输入数组是否小端模式
- * @return
- */
- public static long longFrom8Bytes(byte[] input, int offset, boolean littleEndian){
- if(offset <0 || offset+8>input.length)
- throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long",offset));
- long value=0;
- for(int count=0;count<8;++count){
- int shift=(littleEndian?count:(7-count))<<3;
- value |=((long)0xff<< shift) & ((long)input[offset+count] << shift);
+
+ /**
+ * 将字节数组转为long<br>
+ * 如果input为null,或offset指定的剩余数组长度不足8字节则抛出异常
+ *
+ * @param input
+ * @param offset 起始偏移量
+ * @param littleEndian 输入数组是否小端模式
+ * @return
+ */
+ public static long longFrom8Bytes(byte[] input, int offset, boolean littleEndian) {
+ if (offset < 0 || offset + 8 > input.length)
+ throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long", offset));
+ long value = 0;
+ for (int count = 0; count < 8; ++count) {
+ int shift = (littleEndian ? count : (7 - count)) << 3;
+ value |= ((long) 0xff << shift) & ((long) input[offset + count] << shift);
+ }
+ return value;
}
- return value;
- }
-
- /**
- * 利用 {@link java.nio.ByteBuffer}实现byte[]转long
- * @param input
- * @param offset
- * @param littleEndian 输入数组是否小端模式
- * @return
- */
- public static long bytesToLong(byte[] input, int offset, boolean littleEndian) {
- if(offset <0 || offset+8>input.length)
- throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long",offset));
- ByteBuffer buffer = ByteBuffer.wrap(input,offset,8);
- if(littleEndian){
- // ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN)
- // ByteBuffer 默认为大端(BIG_ENDIAN)模式
- buffer.order(ByteOrder.LITTLE_ENDIAN);
+
+ /**
+ * 利用 {@link java.nio.ByteBuffer}实现byte[]转long
+ *
+ * @param input
+ * @param offset
+ * @param littleEndian 输入数组是否小端模式
+ * @return
+ */
+ public static long bytesToLong(byte[] input, int offset, boolean littleEndian) {
+ if (offset < 0 || offset + 8 > input.length)
+ throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long", offset));
+ ByteBuffer buffer = ByteBuffer.wrap(input, offset, 8);
+ if (littleEndian) {
+ // ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN)
+ // ByteBuffer 默认为大端(BIG_ENDIAN)模式
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
+ }
+ return buffer.getLong();
}
- return buffer.getLong();
- }
}