package kr.co.icontrols.wallpadmain.util; import java.io.BufferedOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.IOException; import java.net.Socket; import java.net.SocketException; import java.util.ArrayList; import java.util.List; import kr.co.icontrols.v40ioctl.V40IOInterface; import kr.co.icontrols.wallpadmain.declare.Common; import kr.co.icontrols.wallpadsupport.Version; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.StatFs; import android.util.Log; import com.artncore.WallPadDataMgr.WallpadDeviceSet; import com.artncore.WallPadDataMgr.WallpadStatusData; import com.artncore.WallPadDataMgr.wallpaddbmgr.AddressSet; import com.artncore.commons.APIErrorCode; import com.artncore.commons.define; import com.util.LogUtil; import com.artncore.wallpadimap.WallPadiMAPClient; public class WallPadiMAPUpgrade { String TAG = "WallPadiMAPUpgrade"; public static final int STATE_REPLY = 1; public static final int STATE_REQUEST = 2; public static final int STATE_DOWNLOADREPLY = 3; public static final int STATE_UPGRADE = 4; public static final int DOWNLOAD_SUCCESS_MSG = 100; public static final int DOWNLOAD_FAIL_MSG = 200; public static String DownloadLocation = "sdcard"; public static final String APPDownloadLocation = "sdcard"; public static final String EPICDownloadLocation = define.ALBUM_PICTURE_LOCATION; public static final String SVRDownloadLocation = "/storage/sdcard0/Bestin/DownloadAddservice"; public class DownloadFileInfo { static final int TYPE_BSP = 1; //BSP static final int TYPE_APP = 2; //APP static final int TYPE_IMG = 3; //EPIC - 전자액자 사진 static final int TYPE_SVR = 4; //부가서비스 - CCTV, 주차정보 static final int TYPE_BSP_FAIL = 101; static final int TYPE_APP_FAIL = 102; static final int TYPE_IMG_FAIL = 103; static final int TYPE_SVR_FAIL = 104; public String filename; public int filesize; public int state = 0; public int type = 0; public long checkedtime = 0; public DownloadFileInfo(String fname, int size, int type) { filename = fname; filesize = size; this.type = type; checkedtime = 0; } } List downloadfilelist = new ArrayList(); ftp_FileDownload filedownloader; public static boolean active = false; String FTPServer; APIErrorCode ErrorCode; String myDong; String myIP; String myHo; Socket receiveSocket; int currentState = 0; Document Docm; String upgradetype; String id; String passwd; String[] imglist; String[] imgpath; String Count; static int retrycnt = 0; SendiMAPreq SocClient; Context ThisCtx; String ProposeUpgrade; int retryDelay = 180000; public WallPadiMAPUpgrade(Context ctx, Document Docm, Socket soc) { ThisCtx = ctx; WallpadStatusData DBMGR; DBMGR = new WallpadStatusData(ctx); AddressSet addc = DBMGR.getAddressMGR(); DBMGR.closeDB(); myDong = addc.Dong; myIP = addc.IPAddress; myHo = addc.Ho; retrycnt = 0; this.Docm = Docm; String result_Str = "\r\n"+ "\r\n"+ "\r\n\r\n"; downloadfilelist.clear(); DataOutputStream outstream; try { outstream = new DataOutputStream(soc.getOutputStream()); byte[] outBF = result_Str.getBytes("euc-kr"); outstream.write(outBF); outstream.flush(); Thread.sleep(300); soc.close(); WallPadiMAPUpgrade.active = true; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); WallPadiMAPUpgrade.active = false; return; } catch (Exception e) { Log.e(TAG, "[Exception] WallPadiMAPUpgrade(Context ctx, Document Docm, Socket soc)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); WallPadiMAPUpgrade.active = false; return; } } public void StartUpgrade() { int waittime = 200; NodeList itemsguide = Docm.getElementsByTagName("guidemap"); Node item = itemsguide.item(0); active = true; if (item != null) { NamedNodeMap attrs = item.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); if (attr.getNodeName().equalsIgnoreCase("type")) upgradetype = attr.getNodeValue(); else if (attr.getNodeName().equalsIgnoreCase("count")) { Count = attr.getNodeValue(); int cnt = Integer.parseInt(Count); imglist = new String[cnt]; imgpath = new String[cnt]; } else if (attr.getNodeName().equalsIgnoreCase("user")) id = attr.getNodeValue(); else if (attr.getNodeName().equalsIgnoreCase("passwd")) passwd = attr.getNodeValue(); } } NodeList itemsImg = Docm.getElementsByTagName("img"); for (int i = 0; i < itemsImg.getLength(); i++) { Node Img = itemsImg.item(i); NamedNodeMap attrs = Img.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Node attr = attrs.item(j); if (attr.getNodeName().equalsIgnoreCase("module")) { imglist[i] = attr.getNodeValue(); } else if (attr.getNodeName().equalsIgnoreCase("path")) { imgpath[i] = attr.getNodeValue(); } } } try { Thread.sleep(waittime);} catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { LogUtil.errorLogInfo("", TAG, e); } try { ProposeUpgrade = "\r\n"+ "\r\n"+ "\r\n"+ "\r\n"; for (int i = 0; i < imglist.length; i++) { ProposeUpgrade += " \r\n"; } ProposeUpgrade += " \r\n\r\n\r\n"; SocClient = new SendiMAPreq(); SocClient.setContext(ThisCtx); /* WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx); SocClient.SendXMLDoc(Wsdata.GetServerIP(), Wsdata.GetServerPort(), ProposeUpgrade, true); Wsdata.closeDB(); */ SocClient.SendXMLDoc(ProposeUpgrade, true); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); active = false; return; } catch (Exception e) { Log.e(TAG, "[Exception] StartUpgrade()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); active = false; return; } } public static final int MAX_UPGRADE_DOWNLOAD_RETRY = -3; public class SendiMAPreq extends WallPadiMAPClient { Handler resultProc = new Handler(Looper.getMainLooper()) { public void handleMessage(Message msg) { if (msg.what == DOWNLOAD_SUCCESS_MSG) { DownloadFileInfo finfo = downloadfilelist.get(msg.arg2); finfo.state = 1; downloadfilelist.set(msg.arg2, finfo); } else if (msg.what == DOWNLOAD_FAIL_MSG) { if (msg.arg2>=downloadfilelist.size() || downloadfilelist.size()==0) { active = false; return; } DownloadFileInfo finfo = downloadfilelist.get(msg.arg2); finfo.state = finfo.state - 1; downloadfilelist.set(msg.arg2, finfo); } else return; for (int i = 0; i < downloadfilelist.size(); i++) { Log.w(TAG, "[SendiMAPreq] downloadfilelist.get(" + i + ").filename = " + downloadfilelist.get(i).filename); } for (int i = 0; i < downloadfilelist.size(); i++) { DownloadFileInfo finfo = downloadfilelist.get(i); if (finfo.state > 0) continue; else { if (finfo.state < MAX_UPGRADE_DOWNLOAD_RETRY) { downloadfilelist.remove(i); i = 0; if (downloadfilelist.size() == 0) { Log.e(TAG,APIErrorCode.GetLogPrefix() + " Return setActive False"); active = false; return; } continue; } Log.e(TAG, "[JEFFREY] ========== 1 =========="); checkMemorySize(); if (startDownloadUpgradeTargetFile(i)) return; else { downloadfilelist.remove(i); i=0; } } } if (downloadfilelist.size() > 0) { DownloadFileInfo finfo; String Updatefilename=null; String UpdateAppfilename=null; String UpdateServicefileName = null; for (int i=0;i\r\n" + "\r\n" + "\r\n" + " \"epic_completed\" \r\n" + "\r\n\r\n"; WallPadiMAPClient notis = new WallPadiMAPClient(); notis.setContext(ThisCtx); WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx); notis.SendXMLDoc(Wsdata.GetServerIP(), Wsdata.GetServerPort(), ProposeUpgrade, true); Wsdata.closeDB(); } else if (finfo.type == DownloadFileInfo.TYPE_SVR) { Log.i(TAG, "Service upgrade file download =============> %%"); // String[] namelist = finfo.filename.split("/"); // UpdateServicefileName = namelist[namelist.length-1]; // String filepath = SVRDownloadLocation+"/"+UpdateServicefileName; // File check_file = new File(filepath); // if (!check_file.exists() || check_file.length() != finfo.filesize) // { // if (check_file.exists()) Log.e("HIGH", "UPDATE Check File size : "+check_file.length()+" ("+finfo.filesize+")"); // else Log.e("HIGH", "UPDATE Check File FileNotExist : "+filepath); // UpdateServicefileName = null; // } // else // { // // 서비스 파일이 다운로드가 완료되면 압축을 해제 하도록 한다. // } } } if (Updatefilename != null || UpdateAppfilename != null ) { if (Updatefilename == null) Updatefilename = "no"; if (UpdateAppfilename == null) UpdateAppfilename = "no"; //jglee - 여기서 거동 수상자 녹화가 진행되면 안되기 때문에 거동수상자 사용않람을 실행 해야 함 //거동수상자 사용안함 설정 Intent Newintent = new Intent(); Newintent.setAction(Common.BR_RECORD_NOT_USE); ThisCtx.sendBroadcast(Newintent); //String SetPP = System.setProperty("persist.sys.update.ready", "1"); // Log.e(TAG,APIErrorCode.GetLogPrefix()+" Before Call PowerManager "); // PowerManager pm = (PowerManager) ThisCtx.getSystemService(Context.POWER_SERVICE); // Log.d(TAG,APIErrorCode.GetLogPrefix()+" Create PowerManager "+pm.toString()); // pm.userActivity(0, true); // Log.i(TAG,APIErrorCode.GetLogPrefix()+" after Call pm.userActivity "); //WallPadUpgradeLog("Set property ret "+SetPP); Log.w(TAG, "[SendiMAPreq] Updatefilename [" + Updatefilename+ "], UpdateAppfilename [" + UpdateAppfilename + "]"); WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx); Wsdata.SetSystemUpdate(Updatefilename, UpdateAppfilename); Wsdata.closeDB(); V40IOInterface mV40IOInterface = new V40IOInterface(); mV40IOInterface.WpdInterfaceOpen(); mV40IOInterface.LiveUpdate(); mV40IOInterface.WpdInterfaceClose(); active = true; } else { active = false; } return; } else { Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); active = false; return; } } }; protected void ProcComplite() { int item_cnt = SocClient.SetItem("service"); String type; String fname; int fsize; DownloadFileInfo finfo; active = true; if (item_cnt > 0) { if (SocClient.GetAttributeVal(0, "result").equals("ok")) { item_cnt = SocClient.SetItem("guidemap"); if (item_cnt > 0) { for (int i = 0; i < item_cnt; i++) { type = SocClient.GetAttributeVal(i, "type"); fname = SocClient.GetAttributeVal(i, "fname"); for (int j = 0; j < imgpath.length; j++) { String[] namelist = imgpath[j].split("/"); if (fname.equals(namelist[namelist.length-1])) { fsize = Integer.parseInt(SocClient.GetAttributeVal(i, "fsize")); //int typeID = (type.equalsIgnoreCase("bsp")?DownloadFileInfo.TYPE_BSP:type.equalsIgnoreCase("app")?DownloadFileInfo.TYPE_APP:type.equalsIgnoreCase("epic")?DownloadFileInfo.TYPE_IMG:0); int typeID; if (type.equalsIgnoreCase("bsp") == true) { typeID = DownloadFileInfo.TYPE_BSP; } else if(type.equalsIgnoreCase("app") == true) { typeID = DownloadFileInfo.TYPE_APP; } else if(type.equalsIgnoreCase("additional") == true) { typeID = DownloadFileInfo.TYPE_SVR; } else if(type.equalsIgnoreCase("epic") == true) { typeID = DownloadFileInfo.TYPE_IMG; } else { typeID = 0; } finfo = new DownloadFileInfo(imgpath[j], fsize, typeID); downloadfilelist.add(finfo); break; } } } } if (downloadfilelist.size() > 0) { Log.e(TAG, "[JEFFREY] ========== 2 =========="); checkMemorySize(); cleanSDRoot(); checkMemorySize(); for (int i = 0; i < downloadfilelist.size(); i++) { if (startDownloadUpgradeTargetFile(i)) return; else { downloadfilelist.remove(i); i=0; } } Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); active = false; return; } else { Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); active = false; return; } } else { Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); active = false; return; } } else { Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); active = false; } } protected boolean startDownloadUpgradeTargetFile(int seqnum) { if (seqnum >= downloadfilelist.size()) return false; DownloadFileInfo finfo = downloadfilelist.get(seqnum); String[] namelist = finfo.filename.split("/"); if (checkDownloadFilename(namelist[namelist.length-1], finfo.type ) == false) { Log.e(TAG,APIErrorCode.GetLogPrefix()+"Start Download Check FileName is false return false"); return false; } String strTargetFile = null; if (finfo.type == DownloadFileInfo.TYPE_BSP) strTargetFile = DownloadLocation + "/" + namelist[namelist.length-1]; else if (finfo.type == DownloadFileInfo.TYPE_APP) strTargetFile = APPDownloadLocation + "/" + namelist[namelist.length-1]; else if (finfo.type == DownloadFileInfo.TYPE_IMG) strTargetFile = EPICDownloadLocation + "/" + namelist[namelist.length-1]; else if (finfo.type == DownloadFileInfo.TYPE_SVR) strTargetFile = SVRDownloadLocation + "/" + namelist[namelist.length-1]; else return false; //Log.e(TAG, "startDownloadUpgradeTargetFile 1"); File TargetFile = new File(strTargetFile); Log.i(TAG, "[startDownloadUpgradeTargetFile] strTargetFile [" + strTargetFile + "], TargetFile.length() [" + TargetFile.length() +"], finfo.filesize [" + finfo.filesize +"]"); if (TargetFile.exists() && TargetFile.length() == finfo.filesize) { Message msg = resultProc.obtainMessage(); msg.what = DOWNLOAD_SUCCESS_MSG; msg.arg1 = 1; msg.arg2 = seqnum; msg.obj = strTargetFile; resultProc.sendMessage(msg); return true; } Log.i(TAG, "[startDownloadUpgradeTargetFile] ftp_FileDownload will be started finfo.filename [" + finfo.filename + "]"); filedownloader = new ftp_FileDownload(resultProc, finfo.filename, seqnum, strTargetFile); filedownloader.start(); return true; } protected void ProcError() { Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False"); WallPadiMAPUpgrade.active = false; return; } } public static final String BSP_FILE_ID = "BSP"; public static final String APP_FILE_ID = "APP"; public static final String DEV_TCC8935_ARCH_ID = "8935"; public static final String DEV_A20_ARCH_ID = "A20"; public static final String DEV_V40_ARCH_ID = "V40"; // V40 플랫폼 public static final String DEV_A40i_ARCH_ID = "A40i"; // A40i 플랫폼 public static final String SA_DEV_ID = "IHN1020B-A"; // 일반 대외향 public static final String SA_A20_DEV_ID = "IHN1030-D"; // 다담 일반 대외향 public static final String SA_A20_DEV_ID_NEW = "IHN1030-A2"; // 다담 일반 대외향 - 신규 모델명 public static final String SA_A20_C_DEV_ID = "IHN1020B-C"; // 다담 일반 대외향 public static final String SA_A20_C_DEV_ID_NEW = "IHN1020B-A2"; // 다담 일반 대외향 - 신규 모델명 public static final String LH_DEV_ID = "IHN1020SA-A"; // LH 향 public static final String GLE_DEV_ID = "IHN1020GL"; // 현산향 public static final String IHN_750_ID = "IHN750"; public static final String IHN_750S_ID = "IHN750S"; public static final String IHN_D101_ID = "IHND101"; // 조그월패드 public static final String IHN_D101K_ID = "IHND101K"; // 카카오 조그월패드 public static final String IHN_1010_ID = "IHN1010"; // 대외향 월패드 public static final String IHN_1010GL_ID = "IHN1010GL"; // 연합사업지용 월패드 public static final String IHN_T1010_ID = "IHNT1010"; // 힘찬건설향 월패드 public static final String IHN_HS101_ID = "IHNHS101"; // 효성건설향 월패드 public static final String IHN_1040_ID = "IHN1040"; // 보급형(엔트리급) 월패드 public static final String IHN_1050_ID = "IHN1050"; // 대우건설향 월패드 public static final String IHN_D101_I_ID = "IHND101-I"; // 조그월패드 (중국생산) public static final String IHN_D101K_I_ID = "IHND101K-I"; // 카카오 조그월패드 (중국생산) public static final String IHN_D101_I_OCF_ID = "IHND101-I-OCF"; // 조그월패드 (OCF 월패드, 중국생산) public static final String IHN_1010_I_ID = "IHN1010-I"; // 대외향 월패드 (중국생산) public static final String IHN_1010GL_I_ID = "IHN1010GL-I"; // 연합사업지용 월패드 (중국생산) public static final String IHN_1010GL_I_2443_ID = "IHN1010GL-I-2443"; // 현산향 2443 대체품 월패드 (중국생산) public static final String IHN_1010GL_I_6410_ID = "IHN1010GL-I-6410"; // 현산향 6410 대체품 월패드 (중국생산) public static final String IHN_1010_I_2443_ID = "IHN1010-I-2443"; // 대외향 2443 대체품 월패드 (중국생산) public static final String IHN_T1010_I_ID = "IHNT1010-I"; // 힘찬건설향 월패드 (중국생산) public static final String IHN_HS101_I_ID = "IHNHS101-I"; // 효성건설향 월패드 (중국생산) public static final String IHN_1030_I_ID = "IHN1030-I"; // 보급형(엔트리급) 월패드 (중국생산) public static final String IHN_1040_I_ID = "IHN1040-I"; // 보급형(엔트리급) 월패드 (중국생산) public static final String IHN_1050_I_ID = "IHN1050-I"; // 대우건설향 월패드 (중국생산) public static final String IHN_1050DW_I_ID = "IHN1050DW-I"; // 대우건설향 월패드 (중국생산) public static final String IHN_1020B_I_ID = "IHN1020B-I"; // IHN-1020B-A2 대체용 월패드 (중국생산) public static final String IHN_1303_I_ID = "IHN1303-I"; // 13.3인치 월패드 (중국생산) private boolean checkDownloadFilename(String filename, int type) { try { String[] astrFileName = filename.split("_"); if (astrFileName != null) { for (int i = 0; i < astrFileName.length; i++) { Log.d( TAG , "[checkDownloadFilename] astrFileName[" + i + "] = " + astrFileName[i] ); } } if (filename != null) Log.d( TAG , "[checkDownloadFilename] filename [" + filename + "], type [" + type + "]"); else Log.d( TAG , "[checkDownloadFilename] filename [null] , type [" + type + "]"); if (type == DownloadFileInfo.TYPE_BSP || type == DownloadFileInfo.TYPE_APP) { // check update option if (!checkUpdateOption(astrFileName[2])) { Log.w( TAG , "[checkDownloadFilename] Update option is not correct!!! astrFileName[2] : [" + astrFileName[2] + "]"); return false; } // check & change update module name, if the module name contains "#". ("#" means it has update option) astrFileName[2] = changeUpdateModuleName(astrFileName[2]); if (type == DownloadFileInfo.TYPE_BSP && !astrFileName[0].equals(BSP_FILE_ID)) { Log.w( TAG , "[checkDownloadFilename] Filetype is not correct!! astrFileName[0] : [" + astrFileName[0] + "], type + [" + type + "]"); return false; } if (type == DownloadFileInfo.TYPE_APP && !astrFileName[0].equals(APP_FILE_ID)) { Log.w( TAG , "[checkDownloadFilename] Filetype is not correct!! astrFileName[0] : [" + astrFileName[0] + "], type + [" + type + "]"); return false; } if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_D101_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_D101_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101K) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_D101K_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_D101K_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_OCF) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_D101_I_OCF_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010_I_2443) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010_I_2443_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010GL_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010GL_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_2443) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010GL_I_2443_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_6410) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010GL_I_6410_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1030_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1030_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1040) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1040_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1040_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1040_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1050) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1050_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1050_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1050_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_T1010) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_T1010_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_T1010_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_T1010_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_HS101) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_HS101_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_HS101_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_HS101_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1050DW_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1050DW_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1020B_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1020B_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1303_I) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1303_I_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_2443) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010GL_I_2443_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_6410) { // V40 플랫폼 업그레이드 if (!(astrFileName[1].equals(DEV_V40_ARCH_ID) || astrFileName[1].equals(DEV_A40i_ARCH_ID)) || !astrFileName[2].equals(IHN_1010GL_I_6410_ID) || (astrFileName[3].length() != 14)) { Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID); Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length()); return false; } } else { Log.d(TAG, "[checkDownloadFilename] model : " + Version.getModelType() + " , Build.MODEL :" + Build.MODEL ); return false; } } else if (type == DownloadFileInfo.TYPE_IMG) return true; return true; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] checkDownloadFilename(String filename, int type)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } /** * 플랫폼 ID에 업데이트 가능한 App 버전 존재 유무 확인 * @param strValue - 다운로드할 파일의 모델명 (예. IHND101-I#APP#2020101501) * @return true: 업데이트 가능, false: 업데이트 불가 */ private boolean checkUpdateOption(String strValue) { if(strValue!=null) { try { Log.i(TAG, "[checkUpdateOption] strValue [" + strValue + "]"); if (strValue.contains("#")) { String[] strParsed = strValue.split("#"); String strModuleType = strParsed[1]; String strVer = strParsed[2]; // Log.i(TAG, "[checkUpdateOption] strModuleType [" + strModuleType + "], strVer [" + strVer + "]"); return checkUpdatableModuleVer(strModuleType, strVer); } else return true; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] checkUpdateOption(String strValue)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } else return false; } private boolean checkUpdatableModuleVer(String strModule, String strVer) { try { Log.i(TAG, "[checkUpdatableModuleVer] strModuleType [" + strModule + "], strVer [" + strVer + "]"); if (strModule.equalsIgnoreCase(BSP_FILE_ID)) { int nCurrentVer = Integer.parseInt(Build.DISPLAY.replace(".", "")); int nMinVer = Integer.parseInt(strVer); Log.i(TAG, "[checkUpdatableModuleVer] BSP Ver. check -> nCurrentVer [" + nCurrentVer + "], nMinVer [" + nMinVer + "]"); if (nCurrentVer >= nMinVer) { Log.w(TAG, "[checkUpdatableModuleVer] BSP update OK!! Current Ver. is bigger than minimum Ver!!"); return true; } else { Log.w(TAG, "[checkUpdatableModuleVer] BSP update FAIL!! Current Ver. is smaller than minimum Ver!!"); return false; } } else if (strModule.equalsIgnoreCase(APP_FILE_ID)) { int nCurrentVer = Integer.parseInt(getAppVersion().replace(".", "")); int nMinVer = Integer.parseInt(strVer); Log.i(TAG, "[checkUpdatableModuleVer] APP Ver. check -> nCurrentVer [" + nCurrentVer + "], nMinVer [" + nMinVer + "]"); if (nCurrentVer >= nMinVer) { Log.w(TAG, "[checkUpdatableModuleVer] APP update OK!! Current Ver. is bigger than minimum Ver!!"); return true; } else { Log.w(TAG, "[checkUpdatableModuleVer] APP update FAIL!! Current Ver. is smaller than minimum Ver!!"); return false; } } else return false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] checkUpdatableModuleVer(String strModule, String strVer)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } private String changeUpdateModuleName(String strValue) { String strResult = ""; if(strValue!=null) { try { Log.i(TAG, "[changeUpdateModuleName] strValue [" + strValue + "]"); if (strValue.contains("#")) { String[] strParsed = strValue.split("#"); strResult = strParsed[0]; } else strResult = strValue; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); strResult = "Exception"; } catch (Exception e) { Log.e(TAG, "[Exception] changeUpdateModuleName(String strValue)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); strResult = "Exception"; } Log.i(TAG, "[changeUpdateModuleName] strResult [" + strResult + "]"); } return strResult; } public String getAppVersion() { PackageInfo mPackageInfo = null; try { mPackageInfo = ThisCtx.getPackageManager().getPackageInfo(ThisCtx.getPackageName(), 0); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] getAppVersion()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return mPackageInfo.versionName; } class ftp_FileDownloadWatcher extends Thread { String DownloadFile; long oldsize = 0; long size; Handler ExitHandle; File ProcF; int seqnum; public boolean onoff = false; public ftp_FileDownloadWatcher(String DownLoadFile, long size, Handler handle, int snum) { this.size = size; ExitHandle = handle; DownloadFile = DownLoadFile; seqnum = snum; } public void run() { long cursize; onoff = true; while (onoff) { try{Thread.sleep(1000);} catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { LogUtil.errorLogInfo("", TAG, e); } Log.e(TAG, "ftp_FileDownloadWatcher start!"); if (ProcF == null) ProcF = new File(DownloadFile); if (!ProcF.exists()) return; cursize = ProcF.length(); if (oldsize != cursize) oldsize = cursize; else { if (cursize >= size) return; if (filedownloader.isAlive()) filedownloader.interrupt(); if (onoff != true) return; Message msg = ExitHandle.obtainMessage(); msg.what = DOWNLOAD_FAIL_MSG; msg.arg1 = 0; msg.arg2 = seqnum; ExitHandle.sendMessage(msg); return; } } } } class ftp_FileDownload extends Thread { String ftpPATH; Handler handle; int Index; FTPClient f; //ftp_FileDownloadWatcher WatchThread; String localFile; int danjiserverType; boolean CompleteFlag = true; //event_notify 계속보내는 버그로 인하여 추가함 public ftp_FileDownload(Handler handle, String path, int idx, String LocalFileName) { ftpPATH = path; Index = idx; this.handle = handle; //WatchThread = wat; localFile = LocalFileName; WallpadDeviceSet wallpadDeviceSet = new WallpadDeviceSet(ThisCtx); danjiserverType = wallpadDeviceSet.GetNewDanjiServer(); wallpadDeviceSet.closeDB(); } public void run() { Log.e(TAG, "[ftp_FileDownload.run()] ftp_FileDownload start! " + ftpPATH + "]"); f = new FTPClient(); f.setControlEncoding("euc-kr"); //한글이름의 파일은 FTP 다운로드가 안되기 때문에 인코딩 추가로 넣어줌 f.setReceieveDataSocketBufferSize(1024*512); try { f.setReceiveBufferSize(1024*512); } catch (SocketException e1) { //e1.printStackTrace(); LogUtil.errorLogInfo("", TAG, e1); //RetryHandler.sendEmptyMessageDelayed(0, retryDelay); ProcDownFail(); return; } int recebf = f.getReceiveDataSocketBufferSize(); FileOutputStream fos = null; BufferedOutputStream ffos = null; try { WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx); FTPServer = Wsdata.GetFTPIP(); Wsdata.closeDB(); //여기서 ip정보를 변경해야 함 if(danjiserverType == define.DanjiServer1 || danjiserverType == define.DanjiServer2) { f.connect(FTPServer); } else { f.connect(define.NewDanjiServerIP); } boolean ret = false; for(int i =0; i< 1; i++) ret = f.login(id, passwd); if (ret == false) { ProcDownFail(); } String[] namelist = ftpPATH.split("/"); String path = ""; if (namelist.length > 2) { for (int i = 1; i < namelist.length - 1; i++) { path += "/"+namelist[i]; } } Log.i(TAG, "[ftp_FileDownload] path [" + path+ "], localFile [" + localFile+ "]"); ret = f.changeWorkingDirectory(path); if (ret == false) { ProcDownFail(); } ret = f.setFileType(FTP.BINARY_FILE_TYPE); if (ret == false) { ProcDownFail(); } File downloadfile = new File(localFile); if (downloadfile.exists()) FileDelete(downloadfile);//.delete(); fos = new FileOutputStream(downloadfile); ffos = new BufferedOutputStream(fos); path = ftpPATH; boolean result; result = f.retrieveFile(path, ffos); ffos.flush(); if (result == false) { ProcDownFail(); } if (handle == null) Log.i(TAG, "[ftp_FileDownload.run()] handle is null!!"); else Log.i(TAG, "[ftp_FileDownload.run()] handle is not null!!"); Log.i(TAG, "[ftp_FileDownload.run()] CompleteFlag [" + CompleteFlag+ "]"); if ((handle != null) && (CompleteFlag == true)) { // event_notify 계속보내는 버그로 인하여 추가함 Message msg = handle.obtainMessage(); msg.what = DOWNLOAD_SUCCESS_MSG; msg.arg1 = (result) ? 1 : 0; msg.arg2 = Index; msg.obj = localFile; handle.sendMessage(msg); } //WatchThread.onoff = false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); ProcDownFail(); } catch (Exception e) { Log.e(TAG, "[Exception] ftp_FileDownload.run() 1"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); ProcDownFail(); } finally { if(fos!=null) { try { fos.close(); } catch (IOException e) { LogUtil.errorLogInfo("", TAG, e); } } fos = null; if(ffos!=null) { try { ffos.close(); } catch (IOException e) { LogUtil.errorLogInfo("", TAG, e); } ffos = null; } } try{ f.quit(); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] ftp_FileDownload.run() 2"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void ProcDownFail() { try { Log.w(TAG, "[ProcDownFail] ========== Download failed =========="); CompleteFlag = false; //event_notify 계속보내는 버그로 인하여 추가함 f.logout(); f.quit(); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } //WatchThread.onoff = false; Message msg = handle.obtainMessage(); msg.what = DOWNLOAD_FAIL_MSG; msg.arg1 = 0; msg.arg2 = Index; msg.obj = ftpPATH; handle.sendMessage(msg); } } public boolean parseXML(String XMLDOC) { return true; } static String PATH_LOCAL_ROOT = "/sdcard/"; public static String[] strUpgradeFileKeyword_ALL = { "_V40_", "_A40i_" }; public static String strUpgradeFileExtention = "zip"; public boolean cleanSDRoot() { try { Log.i(TAG, "[cleanSDRoot] =====START ====="); for (int i = 0; i < strUpgradeFileKeyword_ALL.length; i++) { String[] DeleteFile = findDirectoryFiles(PATH_LOCAL_ROOT, strUpgradeFileKeyword_ALL[i], strUpgradeFileExtention); if(DeleteFile!=null) { Log.i(TAG, "[cleanSDRoot] DeleteFile.length = " + DeleteFile.length); File TargetFile; for (int j = 0; j < DeleteFile.length; j++) { TargetFile = new File(PATH_LOCAL_ROOT + DeleteFile[j]); if (TargetFile.delete()) { Log.i(TAG, "[cleanSDRoot] Success to delete!! TargetFile = " + TargetFile.getName()); } else { Log.i(TAG, "[cleanSDRoot] Fail to delete!! TargetFile = " + TargetFile.getName()); } } } } return true; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] cleanSDRoot()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } public String[] findDirectoryFiles(String strDstDir, final String strKeyword, final String strExtention) { try { Log.i(TAG, "[findDirectoryFiles] strDstDir [" + strDstDir + "], strKeyword [" + strKeyword + "], strExtention [" + strExtention + "]"); String[] strResult = null; if (strDstDir == null) return null; File Directory = new File(strDstDir); if (Directory.exists()) { FilenameFilter mFilenameFilter = new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (strKeyword != null && strExtention != null) { return (filename.endsWith(strExtention) && filename.matches(".*" + strKeyword + ".*")); } else if (strKeyword != null && strExtention == null) { return filename.matches(".*" + strKeyword + ".*"); } else if (strKeyword == null && strExtention != null) { return filename.endsWith(strExtention); } else if (strKeyword == null && strExtention == null) { return true; } return false; } }; String[] mFiles = Directory.list(mFilenameFilter); if(mFiles!=null) { Log.i(TAG, "[findDirectoryFiles] mFiles.length = " + mFiles.length); strResult = new String[mFiles.length]; for (int i = 0; i < strResult.length; i++) { strResult[i] = mFiles[i]; Log.i(TAG, "[findDirectoryFiles] strResult[" + i + "] = " + strResult[i]); } } return strResult; } else { Log.i(TAG, "[findDirectoryFiles] Directory is not exist!! [" + strDstDir + "]"); return null; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] findDirectoryFiles()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return null; } } public void checkMemorySize() { try { String strInternalTotalMemorySize = formatSize(getTotalInternalMemorySize()); String strAvailableInternalMemorySize = formatSize(getAvailableInternalMemorySize()); String strExternalTotalMemorySize = formatSize(getTotalExternalMemorySize()); String strAvailableExternalMemorySize = formatSize(getAvailableExternalMemorySize()); Log.i(TAG, "[checkMemorySize] strInternalTotalMemorySize [" + strInternalTotalMemorySize + "], strAvailableInternalMemorySize [" + strAvailableInternalMemorySize + "]"); Log.i(TAG, "[checkMemorySize] strExternalTotalMemorySize [" + strExternalTotalMemorySize + "], strAvailableExternalMemorySize [" + strAvailableExternalMemorySize + "]"); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] checkMemorySize()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } /** 전체 내장 메모리 크기를 가져온다 */ private long getTotalInternalMemorySize() { try { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return -99; } catch (Exception e) { Log.e(TAG, "[Exception] getTotalInternalMemorySize()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return -99; } } /** 사용가능한 내장 메모리 크기를 가져온다 */ private long getAvailableInternalMemorySize() { try { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return -99; } catch (Exception e) { Log.e(TAG, "[Exception] getAvailableInternalMemorySize()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return -99; } } /** 전체 외장 메모리 크기를 가져온다 */ private long getTotalExternalMemorySize() { try { if (isStorage(true) == true) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } else { return -1; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return -99; } catch (Exception e) { Log.e(TAG, "[Exception] getTotalExternalMemorySize()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return -99; } } /** 사용가능한 외장 메모리 크기를 가져온다 */ private long getAvailableExternalMemorySize() { try { if (isStorage(true) == true) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } else { return -1; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return -99; } catch (Exception e) { Log.e(TAG, "[Exception] getAvailableExternalMemorySize()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return -99; } } /** 보기 좋게 MB,KB 단위로 축소시킨다 */ private String formatSize(long size) { try { String suffix = null; if (size >= 1024) { suffix = "KB"; size /= 1024; if (size >= 1024) { suffix = "MB"; size /= 1024; } } StringBuilder resultBuffer = new StringBuilder(Long.toString(size)); int commaOffset = resultBuffer.length() - 3; while (commaOffset > 0) { resultBuffer.insert(commaOffset, ','); commaOffset -= 3; } if (suffix != null) { resultBuffer.append(suffix); } return resultBuffer.toString(); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] formatSize(long size)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return null; } } /** 외장메모리 sdcard 사용가능한지에 대한 여부 판단 */ private boolean isStorage(boolean requireWriteAccess) { try { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] isStorage(boolean requireWriteAccess)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } private synchronized void FileDelete(File file) { if(file!=null && file.exists()) { file.delete(); } } }