WallPadiMAPUpgrade.java 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. package kr.co.icontrols.wallpadmain.util;
  2. import java.io.BufferedOutputStream;
  3. import java.io.DataOutputStream;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.FilenameFilter;
  7. import java.io.IOException;
  8. import java.net.Socket;
  9. import java.net.SocketException;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import kr.co.icontrols.v40ioctl.V40IOInterface;
  13. import kr.co.icontrols.wallpadmain.declare.Common;
  14. import kr.co.icontrols.wallpadsupport.Version;
  15. import org.apache.commons.net.ftp.FTP;
  16. import org.apache.commons.net.ftp.FTPClient;
  17. import org.w3c.dom.Document;
  18. import org.w3c.dom.NamedNodeMap;
  19. import org.w3c.dom.Node;
  20. import org.w3c.dom.NodeList;
  21. import android.content.Context;
  22. import android.content.Intent;
  23. import android.content.pm.PackageInfo;
  24. import android.os.Build;
  25. import android.os.Environment;
  26. import android.os.Handler;
  27. import android.os.Looper;
  28. import android.os.Message;
  29. import android.os.StatFs;
  30. import android.util.Log;
  31. import com.artncore.WallPadDataMgr.WallpadDeviceSet;
  32. import com.artncore.WallPadDataMgr.WallpadStatusData;
  33. import com.artncore.WallPadDataMgr.wallpaddbmgr.AddressSet;
  34. import com.artncore.commons.APIErrorCode;
  35. import com.artncore.commons.define;
  36. import com.util.LogUtil;
  37. import com.artncore.wallpadimap.WallPadiMAPClient;
  38. public class WallPadiMAPUpgrade {
  39. String TAG = "WallPadiMAPUpgrade";
  40. public static final int STATE_REPLY = 1;
  41. public static final int STATE_REQUEST = 2;
  42. public static final int STATE_DOWNLOADREPLY = 3;
  43. public static final int STATE_UPGRADE = 4;
  44. public static final int DOWNLOAD_SUCCESS_MSG = 100;
  45. public static final int DOWNLOAD_FAIL_MSG = 200;
  46. public static String DownloadLocation = "sdcard";
  47. public static final String APPDownloadLocation = "sdcard";
  48. public static final String EPICDownloadLocation = define.ALBUM_PICTURE_LOCATION;
  49. public static final String SVRDownloadLocation = "/storage/sdcard0/Bestin/DownloadAddservice";
  50. public class DownloadFileInfo {
  51. static final int TYPE_BSP = 1; //BSP
  52. static final int TYPE_APP = 2; //APP
  53. static final int TYPE_IMG = 3; //EPIC - 전자액자 사진
  54. static final int TYPE_SVR = 4; //부가서비스 - CCTV, 주차정보
  55. static final int TYPE_BSP_FAIL = 101;
  56. static final int TYPE_APP_FAIL = 102;
  57. static final int TYPE_IMG_FAIL = 103;
  58. static final int TYPE_SVR_FAIL = 104;
  59. public String filename;
  60. public int filesize;
  61. public int state = 0;
  62. public int type = 0;
  63. public long checkedtime = 0;
  64. public DownloadFileInfo(String fname, int size, int type) {
  65. filename = fname;
  66. filesize = size;
  67. this.type = type;
  68. checkedtime = 0;
  69. }
  70. }
  71. List<DownloadFileInfo> downloadfilelist = new ArrayList<DownloadFileInfo>();
  72. ftp_FileDownload filedownloader;
  73. public static boolean active = false;
  74. String FTPServer;
  75. APIErrorCode ErrorCode;
  76. String myDong;
  77. String myIP;
  78. String myHo;
  79. Socket receiveSocket;
  80. int currentState = 0;
  81. Document Docm;
  82. String upgradetype;
  83. String id;
  84. String passwd;
  85. String[] imglist;
  86. String[] imgpath;
  87. String Count;
  88. static int retrycnt = 0;
  89. SendiMAPreq SocClient;
  90. Context ThisCtx;
  91. String ProposeUpgrade;
  92. int retryDelay = 180000;
  93. public WallPadiMAPUpgrade(Context ctx, Document Docm, Socket soc) {
  94. ThisCtx = ctx;
  95. WallpadStatusData DBMGR;
  96. DBMGR = new WallpadStatusData(ctx);
  97. AddressSet addc = DBMGR.getAddressMGR();
  98. DBMGR.closeDB();
  99. myDong = addc.Dong;
  100. myIP = addc.IPAddress;
  101. myHo = addc.Ho;
  102. retrycnt = 0;
  103. this.Docm = Docm;
  104. String result_Str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"+
  105. "<imap ver = \"1.0\" address = \""+myIP+"\" sender = \""+myDong+"동 "+myHo+"호\">\r\n"+
  106. "<service type = \"reply\" name= \"upgrade\" result = \"ok\"/>\r\n</imap>\r\n";
  107. downloadfilelist.clear();
  108. DataOutputStream outstream;
  109. try {
  110. outstream = new DataOutputStream(soc.getOutputStream());
  111. byte[] outBF = result_Str.getBytes("euc-kr");
  112. outstream.write(outBF);
  113. outstream.flush();
  114. Thread.sleep(300);
  115. soc.close();
  116. WallPadiMAPUpgrade.active = true;
  117. } catch (RuntimeException re) {
  118. LogUtil.errorLogInfo("", TAG, re);
  119. WallPadiMAPUpgrade.active = false;
  120. return;
  121. }
  122. catch (Exception e) {
  123. Log.e(TAG, "[Exception] WallPadiMAPUpgrade(Context ctx, Document Docm, Socket soc)");
  124. //e.printStackTrace();
  125. LogUtil.errorLogInfo("", TAG, e);
  126. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  127. WallPadiMAPUpgrade.active = false;
  128. return;
  129. }
  130. }
  131. public void StartUpgrade() {
  132. int waittime = 200;
  133. NodeList itemsguide = Docm.getElementsByTagName("guidemap");
  134. Node item = itemsguide.item(0);
  135. active = true;
  136. if (item != null) {
  137. NamedNodeMap attrs = item.getAttributes();
  138. for (int j = 0; j < attrs.getLength(); j++) {
  139. Node attr = attrs.item(j);
  140. if (attr.getNodeName().equalsIgnoreCase("type")) upgradetype = attr.getNodeValue();
  141. else if (attr.getNodeName().equalsIgnoreCase("count")) {
  142. Count = attr.getNodeValue();
  143. int cnt = Integer.parseInt(Count);
  144. imglist = new String[cnt];
  145. imgpath = new String[cnt];
  146. }
  147. else if (attr.getNodeName().equalsIgnoreCase("user")) id = attr.getNodeValue();
  148. else if (attr.getNodeName().equalsIgnoreCase("passwd")) passwd = attr.getNodeValue();
  149. }
  150. }
  151. NodeList itemsImg = Docm.getElementsByTagName("img");
  152. for (int i = 0; i < itemsImg.getLength(); i++) {
  153. Node Img = itemsImg.item(i);
  154. NamedNodeMap attrs = Img.getAttributes();
  155. for (int j = 0; j < attrs.getLength(); j++) {
  156. Node attr = attrs.item(j);
  157. if (attr.getNodeName().equalsIgnoreCase("module")) {
  158. imglist[i] = attr.getNodeValue();
  159. }
  160. else if (attr.getNodeName().equalsIgnoreCase("path")) {
  161. imgpath[i] = attr.getNodeValue();
  162. }
  163. }
  164. }
  165. try { Thread.sleep(waittime);} catch (RuntimeException re) {
  166. LogUtil.errorLogInfo("", TAG, re);
  167. }
  168. catch (Exception e) {
  169. LogUtil.errorLogInfo("", TAG, e);
  170. }
  171. try {
  172. ProposeUpgrade = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"+
  173. "<imap ver = \"1.0\" address = \""+myIP+"\" sender = \""+myDong+"동 "+myHo+"호\">\r\n"+
  174. "<service type = \"request\" name= \"propose_upgrade\" >\r\n"+
  175. "<guidemap type = \"upgrade\" count = \""+imglist.length+"\" value = \"list\">\r\n";
  176. for (int i = 0; i < imglist.length; i++) {
  177. ProposeUpgrade += "<img module = \""+imglist[i]+"\" /> \r\n";
  178. }
  179. ProposeUpgrade += " </guidemap>\r\n</service>\r\n</imap>\r\n";
  180. SocClient = new SendiMAPreq();
  181. SocClient.setContext(ThisCtx);
  182. /*
  183. WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx);
  184. SocClient.SendXMLDoc(Wsdata.GetServerIP(), Wsdata.GetServerPort(), ProposeUpgrade, true);
  185. Wsdata.closeDB();
  186. */
  187. SocClient.SendXMLDoc(ProposeUpgrade, true);
  188. } catch (RuntimeException re) {
  189. LogUtil.errorLogInfo("", TAG, re);
  190. active = false;
  191. return;
  192. }
  193. catch (Exception e) {
  194. Log.e(TAG, "[Exception] StartUpgrade()");
  195. //e.printStackTrace();
  196. LogUtil.errorLogInfo("", TAG, e);
  197. active = false;
  198. return;
  199. }
  200. }
  201. public static final int MAX_UPGRADE_DOWNLOAD_RETRY = -3;
  202. public class SendiMAPreq extends WallPadiMAPClient {
  203. Handler resultProc = new Handler(Looper.getMainLooper()) {
  204. public void handleMessage(Message msg) {
  205. if (msg.what == DOWNLOAD_SUCCESS_MSG) {
  206. DownloadFileInfo finfo = downloadfilelist.get(msg.arg2);
  207. finfo.state = 1;
  208. downloadfilelist.set(msg.arg2, finfo);
  209. }
  210. else if (msg.what == DOWNLOAD_FAIL_MSG) {
  211. if (msg.arg2>=downloadfilelist.size() || downloadfilelist.size()==0) {
  212. active = false;
  213. return;
  214. }
  215. DownloadFileInfo finfo = downloadfilelist.get(msg.arg2);
  216. finfo.state = finfo.state - 1;
  217. downloadfilelist.set(msg.arg2, finfo);
  218. }
  219. else return;
  220. for (int i = 0; i < downloadfilelist.size(); i++) {
  221. Log.w(TAG, "[SendiMAPreq] downloadfilelist.get(" + i + ").filename = " + downloadfilelist.get(i).filename);
  222. }
  223. for (int i = 0; i < downloadfilelist.size(); i++) {
  224. DownloadFileInfo finfo = downloadfilelist.get(i);
  225. if (finfo.state > 0) continue;
  226. else {
  227. if (finfo.state < MAX_UPGRADE_DOWNLOAD_RETRY) {
  228. downloadfilelist.remove(i);
  229. i = 0;
  230. if (downloadfilelist.size() == 0) {
  231. Log.e(TAG,APIErrorCode.GetLogPrefix() + " Return setActive False");
  232. active = false;
  233. return;
  234. }
  235. continue;
  236. }
  237. Log.e(TAG, "[JEFFREY] ========== 1 ==========");
  238. checkMemorySize();
  239. if (startDownloadUpgradeTargetFile(i)) return;
  240. else {
  241. downloadfilelist.remove(i);
  242. i=0;
  243. }
  244. }
  245. }
  246. if (downloadfilelist.size() > 0) {
  247. DownloadFileInfo finfo;
  248. String Updatefilename=null;
  249. String UpdateAppfilename=null;
  250. String UpdateServicefileName = null;
  251. for (int i=0;i<downloadfilelist.size();i++) {
  252. finfo = downloadfilelist.get(i);
  253. if (finfo.type == DownloadFileInfo.TYPE_BSP) {
  254. String[] namelist = finfo.filename.split("/");
  255. Updatefilename = namelist[namelist.length - 1];
  256. String filepath = DownloadLocation + "/" + Updatefilename;
  257. Log.i(TAG, "[SendiMAPreq] filepath [" + filepath + "]");
  258. File check_file = new File(filepath);
  259. Log.i(TAG, "[SendiMAPreq] (TYPE_BSP) check update file size : downloaded file [" + check_file.length() + "], server file [" + finfo.filesize + "]");
  260. if (!check_file.exists() || check_file.length() != finfo.filesize) {
  261. if (check_file.exists()) Log.e(TAG, "UPDATE Check File size : " + check_file.length() + " (" + finfo.filesize + ")");
  262. else Log.e(TAG, "UPDATE Check File FileNotExist : " + filepath);
  263. Updatefilename = null;
  264. }
  265. } else if (finfo.type == DownloadFileInfo.TYPE_APP) {
  266. String[] namelist = finfo.filename.split("/");
  267. UpdateAppfilename = namelist[namelist.length - 1];
  268. String filepath = DownloadLocation + "/" + UpdateAppfilename;
  269. Log.i(TAG, "[SendiMAPreq] filepath [" + filepath + "]");
  270. File check_file = new File(filepath);
  271. Log.i(TAG, "[SendiMAPreq] (TYPE_APP) check update file size : downloaded file [" + check_file.length() + "], server file [" + finfo.filesize + "]");
  272. if (!check_file.exists() || check_file.length() != finfo.filesize) {
  273. if (check_file.exists()) Log.e(TAG, "UPDATE Check File size : " + check_file.length() + " (" + finfo.filesize + ")");
  274. else Log.e(TAG, "UPDATE Check File FileNotExist : " + filepath);
  275. UpdateAppfilename = null;
  276. }
  277. } else if (finfo.type == DownloadFileInfo.TYPE_IMG) {
  278. active = false;
  279. ProposeUpgrade = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
  280. "<imap ver = \"1.0\" address = \"" + myIP + "\" sender = \"" + myDong + "동 " + myHo + "호\">\r\n" +
  281. "<service type = \"request\" name= \"event_notify\">\r\n" +
  282. " <event> \"epic_completed\" </event>\r\n" +
  283. "</service>\r\n</imap>\r\n";
  284. WallPadiMAPClient notis = new WallPadiMAPClient();
  285. notis.setContext(ThisCtx);
  286. WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx);
  287. notis.SendXMLDoc(Wsdata.GetServerIP(), Wsdata.GetServerPort(), ProposeUpgrade, true);
  288. Wsdata.closeDB();
  289. } else if (finfo.type == DownloadFileInfo.TYPE_SVR) {
  290. Log.i(TAG, "Service upgrade file download =============> %%");
  291. // String[] namelist = finfo.filename.split("/");
  292. // UpdateServicefileName = namelist[namelist.length-1];
  293. // String filepath = SVRDownloadLocation+"/"+UpdateServicefileName;
  294. // File check_file = new File(filepath);
  295. // if (!check_file.exists() || check_file.length() != finfo.filesize)
  296. // {
  297. // if (check_file.exists()) Log.e("HIGH", "UPDATE Check File size : "+check_file.length()+" ("+finfo.filesize+")");
  298. // else Log.e("HIGH", "UPDATE Check File FileNotExist : "+filepath);
  299. // UpdateServicefileName = null;
  300. // }
  301. // else
  302. // {
  303. // // 서비스 파일이 다운로드가 완료되면 압축을 해제 하도록 한다.
  304. // }
  305. }
  306. }
  307. if (Updatefilename != null || UpdateAppfilename != null ) {
  308. if (Updatefilename == null) Updatefilename = "no";
  309. if (UpdateAppfilename == null) UpdateAppfilename = "no";
  310. //jglee - 여기서 거동 수상자 녹화가 진행되면 안되기 때문에 거동수상자 사용않람을 실행 해야 함
  311. //거동수상자 사용안함 설정
  312. Intent Newintent = new Intent();
  313. Newintent.setAction(Common.BR_RECORD_NOT_USE);
  314. ThisCtx.sendBroadcast(Newintent);
  315. //String SetPP = System.setProperty("persist.sys.update.ready", "1");
  316. // Log.e(TAG,APIErrorCode.GetLogPrefix()+" Before Call PowerManager ");
  317. // PowerManager pm = (PowerManager) ThisCtx.getSystemService(Context.POWER_SERVICE);
  318. // Log.d(TAG,APIErrorCode.GetLogPrefix()+" Create PowerManager "+pm.toString());
  319. // pm.userActivity(0, true);
  320. // Log.i(TAG,APIErrorCode.GetLogPrefix()+" after Call pm.userActivity ");
  321. //WallPadUpgradeLog("Set property ret "+SetPP);
  322. Log.w(TAG, "[SendiMAPreq] Updatefilename [" + Updatefilename+ "], UpdateAppfilename [" + UpdateAppfilename + "]");
  323. WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx);
  324. Wsdata.SetSystemUpdate(Updatefilename, UpdateAppfilename);
  325. Wsdata.closeDB();
  326. V40IOInterface mV40IOInterface = new V40IOInterface();
  327. mV40IOInterface.WpdInterfaceOpen();
  328. mV40IOInterface.LiveUpdate();
  329. mV40IOInterface.WpdInterfaceClose();
  330. active = true;
  331. }
  332. else {
  333. active = false;
  334. }
  335. return;
  336. }
  337. else {
  338. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  339. active = false;
  340. return;
  341. }
  342. }
  343. };
  344. protected void ProcComplite() {
  345. int item_cnt = SocClient.SetItem("service");
  346. String type;
  347. String fname;
  348. int fsize;
  349. DownloadFileInfo finfo;
  350. active = true;
  351. if (item_cnt > 0) {
  352. if (SocClient.GetAttributeVal(0, "result").equals("ok")) {
  353. item_cnt = SocClient.SetItem("guidemap");
  354. if (item_cnt > 0) {
  355. for (int i = 0; i < item_cnt; i++) {
  356. type = SocClient.GetAttributeVal(i, "type");
  357. fname = SocClient.GetAttributeVal(i, "fname");
  358. for (int j = 0; j < imgpath.length; j++) {
  359. String[] namelist = imgpath[j].split("/");
  360. if (fname.equals(namelist[namelist.length-1])) {
  361. fsize = Integer.parseInt(SocClient.GetAttributeVal(i, "fsize"));
  362. //int typeID = (type.equalsIgnoreCase("bsp")?DownloadFileInfo.TYPE_BSP:type.equalsIgnoreCase("app")?DownloadFileInfo.TYPE_APP:type.equalsIgnoreCase("epic")?DownloadFileInfo.TYPE_IMG:0);
  363. int typeID;
  364. if (type.equalsIgnoreCase("bsp") == true) {
  365. typeID = DownloadFileInfo.TYPE_BSP;
  366. }
  367. else if(type.equalsIgnoreCase("app") == true) {
  368. typeID = DownloadFileInfo.TYPE_APP;
  369. }
  370. else if(type.equalsIgnoreCase("additional") == true) {
  371. typeID = DownloadFileInfo.TYPE_SVR;
  372. }
  373. else if(type.equalsIgnoreCase("epic") == true) {
  374. typeID = DownloadFileInfo.TYPE_IMG;
  375. }
  376. else {
  377. typeID = 0;
  378. }
  379. finfo = new DownloadFileInfo(imgpath[j], fsize, typeID);
  380. downloadfilelist.add(finfo);
  381. break;
  382. }
  383. }
  384. }
  385. }
  386. if (downloadfilelist.size() > 0) {
  387. Log.e(TAG, "[JEFFREY] ========== 2 ==========");
  388. checkMemorySize();
  389. cleanSDRoot();
  390. checkMemorySize();
  391. for (int i = 0; i < downloadfilelist.size(); i++) {
  392. if (startDownloadUpgradeTargetFile(i)) return;
  393. else {
  394. downloadfilelist.remove(i);
  395. i=0;
  396. }
  397. }
  398. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  399. active = false;
  400. return;
  401. }
  402. else {
  403. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  404. active = false;
  405. return;
  406. }
  407. }
  408. else {
  409. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  410. active = false;
  411. return;
  412. }
  413. }
  414. else {
  415. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  416. active = false;
  417. }
  418. }
  419. protected boolean startDownloadUpgradeTargetFile(int seqnum) {
  420. if (seqnum >= downloadfilelist.size()) return false;
  421. DownloadFileInfo finfo = downloadfilelist.get(seqnum);
  422. String[] namelist = finfo.filename.split("/");
  423. if (checkDownloadFilename(namelist[namelist.length-1], finfo.type ) == false) {
  424. Log.e(TAG,APIErrorCode.GetLogPrefix()+"Start Download Check FileName is false return false");
  425. return false;
  426. }
  427. String strTargetFile = null;
  428. if (finfo.type == DownloadFileInfo.TYPE_BSP) strTargetFile = DownloadLocation + "/" + namelist[namelist.length-1];
  429. else if (finfo.type == DownloadFileInfo.TYPE_APP) strTargetFile = APPDownloadLocation + "/" + namelist[namelist.length-1];
  430. else if (finfo.type == DownloadFileInfo.TYPE_IMG) strTargetFile = EPICDownloadLocation + "/" + namelist[namelist.length-1];
  431. else if (finfo.type == DownloadFileInfo.TYPE_SVR) strTargetFile = SVRDownloadLocation + "/" + namelist[namelist.length-1];
  432. else return false;
  433. //Log.e(TAG, "startDownloadUpgradeTargetFile 1");
  434. File TargetFile = new File(strTargetFile);
  435. Log.i(TAG, "[startDownloadUpgradeTargetFile] strTargetFile [" + strTargetFile + "], TargetFile.length() [" + TargetFile.length() +"], finfo.filesize [" + finfo.filesize +"]");
  436. if (TargetFile.exists() && TargetFile.length() == finfo.filesize) {
  437. Message msg = resultProc.obtainMessage();
  438. msg.what = DOWNLOAD_SUCCESS_MSG;
  439. msg.arg1 = 1;
  440. msg.arg2 = seqnum;
  441. msg.obj = strTargetFile;
  442. resultProc.sendMessage(msg);
  443. return true;
  444. }
  445. Log.i(TAG, "[startDownloadUpgradeTargetFile] ftp_FileDownload will be started finfo.filename [" + finfo.filename + "]");
  446. filedownloader = new ftp_FileDownload(resultProc, finfo.filename, seqnum, strTargetFile);
  447. filedownloader.start();
  448. return true;
  449. }
  450. protected void ProcError() {
  451. Log.e(TAG,APIErrorCode.GetLogPrefix()+" Return setActive False");
  452. WallPadiMAPUpgrade.active = false;
  453. return;
  454. }
  455. }
  456. public static final String BSP_FILE_ID = "BSP";
  457. public static final String APP_FILE_ID = "APP";
  458. public static final String DEV_TCC8935_ARCH_ID = "8935";
  459. public static final String DEV_A20_ARCH_ID = "A20";
  460. public static final String DEV_V40_ARCH_ID = "V40"; // V40 플랫폼
  461. public static final String DEV_A40i_ARCH_ID = "A40i"; // A40i 플랫폼
  462. public static final String SA_DEV_ID = "IHN1020B-A"; // 일반 대외향
  463. public static final String SA_A20_DEV_ID = "IHN1030-D"; // 다담 일반 대외향
  464. public static final String SA_A20_DEV_ID_NEW = "IHN1030-A2"; // 다담 일반 대외향 - 신규 모델명
  465. public static final String SA_A20_C_DEV_ID = "IHN1020B-C"; // 다담 일반 대외향
  466. public static final String SA_A20_C_DEV_ID_NEW = "IHN1020B-A2"; // 다담 일반 대외향 - 신규 모델명
  467. public static final String LH_DEV_ID = "IHN1020SA-A"; // LH 향
  468. public static final String GLE_DEV_ID = "IHN1020GL"; // 현산향
  469. public static final String IHN_750_ID = "IHN750";
  470. public static final String IHN_750S_ID = "IHN750S";
  471. public static final String IHN_D101_ID = "IHND101"; // 조그월패드
  472. public static final String IHN_D101K_ID = "IHND101K"; // 카카오 조그월패드
  473. public static final String IHN_1010_ID = "IHN1010"; // 대외향 월패드
  474. public static final String IHN_1010GL_ID = "IHN1010GL"; // 연합사업지용 월패드
  475. public static final String IHN_T1010_ID = "IHNT1010"; // 힘찬건설향 월패드
  476. public static final String IHN_HS101_ID = "IHNHS101"; // 효성건설향 월패드
  477. public static final String IHN_1040_ID = "IHN1040"; // 보급형(엔트리급) 월패드
  478. public static final String IHN_1050_ID = "IHN1050"; // 대우건설향 월패드
  479. public static final String IHN_D101_I_ID = "IHND101-I"; // 조그월패드 (중국생산)
  480. public static final String IHN_D101K_I_ID = "IHND101K-I"; // 카카오 조그월패드 (중국생산)
  481. public static final String IHN_D101_I_OCF_ID = "IHND101-I-OCF"; // 조그월패드 (OCF 월패드, 중국생산)
  482. public static final String IHN_1010_I_ID = "IHN1010-I"; // 대외향 월패드 (중국생산)
  483. public static final String IHN_1010GL_I_ID = "IHN1010GL-I"; // 연합사업지용 월패드 (중국생산)
  484. public static final String IHN_1010GL_I_2443_ID = "IHN1010GL-I-2443"; // 현산향 2443 대체품 월패드 (중국생산)
  485. public static final String IHN_1010GL_I_6410_ID = "IHN1010GL-I-6410"; // 현산향 6410 대체품 월패드 (중국생산)
  486. public static final String IHN_1010_I_2443_ID = "IHN1010-I-2443"; // 대외향 2443 대체품 월패드 (중국생산)
  487. public static final String IHN_T1010_I_ID = "IHNT1010-I"; // 힘찬건설향 월패드 (중국생산)
  488. public static final String IHN_HS101_I_ID = "IHNHS101-I"; // 효성건설향 월패드 (중국생산)
  489. public static final String IHN_1030_I_ID = "IHN1030-I"; // 보급형(엔트리급) 월패드 (중국생산)
  490. public static final String IHN_1040_I_ID = "IHN1040-I"; // 보급형(엔트리급) 월패드 (중국생산)
  491. public static final String IHN_1050_I_ID = "IHN1050-I"; // 대우건설향 월패드 (중국생산)
  492. public static final String IHN_1050DW_I_ID = "IHN1050DW-I"; // 대우건설향 월패드 (중국생산)
  493. public static final String IHN_1020B_I_ID = "IHN1020B-I"; // IHN-1020B-A2 대체용 월패드 (중국생산)
  494. public static final String IHN_1303_I_ID = "IHN1303-I"; // 13.3인치 월패드 (중국생산)
  495. private boolean checkDownloadFilename(String filename, int type) {
  496. try {
  497. String[] astrFileName = filename.split("_");
  498. if (astrFileName != null) {
  499. for (int i = 0; i < astrFileName.length; i++) {
  500. Log.d( TAG , "[checkDownloadFilename] astrFileName[" + i + "] = " + astrFileName[i] );
  501. }
  502. }
  503. if (filename != null) Log.d( TAG , "[checkDownloadFilename] filename [" + filename + "], type [" + type + "]");
  504. else Log.d( TAG , "[checkDownloadFilename] filename [null] , type [" + type + "]");
  505. if (type == DownloadFileInfo.TYPE_BSP || type == DownloadFileInfo.TYPE_APP) {
  506. // check update option
  507. if (!checkUpdateOption(astrFileName[2])) {
  508. Log.w( TAG , "[checkDownloadFilename] Update option is not correct!!! astrFileName[2] : [" + astrFileName[2] + "]");
  509. return false;
  510. }
  511. // check & change update module name, if the module name contains "#". ("#" means it has update option)
  512. astrFileName[2] = changeUpdateModuleName(astrFileName[2]);
  513. if (type == DownloadFileInfo.TYPE_BSP && !astrFileName[0].equals(BSP_FILE_ID)) {
  514. Log.w( TAG , "[checkDownloadFilename] Filetype is not correct!! astrFileName[0] : [" + astrFileName[0] + "], type + [" + type + "]");
  515. return false;
  516. }
  517. if (type == DownloadFileInfo.TYPE_APP && !astrFileName[0].equals(APP_FILE_ID)) {
  518. Log.w( TAG , "[checkDownloadFilename] Filetype is not correct!! astrFileName[0] : [" + astrFileName[0] + "], type + [" + type + "]");
  519. return false;
  520. }
  521. if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101) {
  522. // V40 플랫폼 업그레이드
  523. 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)) {
  524. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  525. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  526. return false;
  527. }
  528. }
  529. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I) {
  530. // V40 플랫폼 업그레이드
  531. 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)) {
  532. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  533. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  534. return false;
  535. }
  536. }
  537. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101K) {
  538. // V40 플랫폼 업그레이드
  539. 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)) {
  540. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  541. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  542. return false;
  543. }
  544. }
  545. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I) {
  546. // V40 플랫폼 업그레이드
  547. 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)) {
  548. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  549. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  550. return false;
  551. }
  552. }
  553. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_OCF) {
  554. // V40 플랫폼 업그레이드
  555. 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)) {
  556. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  557. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  558. return false;
  559. }
  560. }
  561. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010) {
  562. // V40 플랫폼 업그레이드
  563. 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)) {
  564. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  565. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  566. return false;
  567. }
  568. }
  569. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010_I) {
  570. // V40 플랫폼 업그레이드
  571. 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)) {
  572. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  573. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  574. return false;
  575. }
  576. }
  577. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010_I_2443) {
  578. // V40 플랫폼 업그레이드
  579. 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)) {
  580. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  581. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  582. return false;
  583. }
  584. }
  585. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL) {
  586. // V40 플랫폼 업그레이드
  587. 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)) {
  588. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  589. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  590. return false;
  591. }
  592. }
  593. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I) {
  594. // V40 플랫폼 업그레이드
  595. 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)) {
  596. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  597. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  598. return false;
  599. }
  600. }
  601. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_2443) {
  602. // V40 플랫폼 업그레이드
  603. 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)) {
  604. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  605. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  606. return false;
  607. }
  608. }
  609. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_6410) {
  610. // V40 플랫폼 업그레이드
  611. 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)) {
  612. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  613. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  614. return false;
  615. }
  616. }
  617. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1030_I) {
  618. // V40 플랫폼 업그레이드
  619. 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)) {
  620. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  621. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  622. return false;
  623. }
  624. }
  625. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1040) {
  626. // V40 플랫폼 업그레이드
  627. 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)) {
  628. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  629. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  630. return false;
  631. }
  632. }
  633. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1040_I) {
  634. // V40 플랫폼 업그레이드
  635. 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)) {
  636. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  637. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  638. return false;
  639. }
  640. }
  641. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1050) {
  642. // V40 플랫폼 업그레이드
  643. 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)) {
  644. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  645. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  646. return false;
  647. }
  648. }
  649. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1050_I) {
  650. // V40 플랫폼 업그레이드
  651. 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)) {
  652. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  653. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  654. return false;
  655. }
  656. }
  657. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_T1010) {
  658. // V40 플랫폼 업그레이드
  659. 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)) {
  660. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  661. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  662. return false;
  663. }
  664. }
  665. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_T1010_I) {
  666. // V40 플랫폼 업그레이드
  667. 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)) {
  668. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  669. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  670. return false;
  671. }
  672. }
  673. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_HS101) {
  674. // V40 플랫폼 업그레이드
  675. 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)) {
  676. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  677. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  678. return false;
  679. }
  680. }
  681. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_HS101_I) {
  682. // V40 플랫폼 업그레이드
  683. 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)) {
  684. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  685. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  686. return false;
  687. }
  688. }
  689. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1050DW_I) {
  690. // V40 플랫폼 업그레이드
  691. 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)) {
  692. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  693. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  694. return false;
  695. }
  696. }
  697. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1020B_I) {
  698. // V40 플랫폼 업그레이드
  699. 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)) {
  700. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  701. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  702. return false;
  703. }
  704. }
  705. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1303_I) {
  706. // V40 플랫폼 업그레이드
  707. 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)) {
  708. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  709. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  710. return false;
  711. }
  712. }
  713. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_2443) {
  714. // V40 플랫폼 업그레이드
  715. 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)) {
  716. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  717. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  718. return false;
  719. }
  720. }
  721. else if(Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I_6410) {
  722. // V40 플랫폼 업그레이드
  723. 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)) {
  724. Log.d( TAG , "[checkDownloadFilename] astrFileName[1] : + " + astrFileName[1] + ", DEV_V40_ARCH_ID :" + DEV_V40_ARCH_ID);
  725. Log.d( TAG , "[checkDownloadFilename] astrFileName[3].length() : + " + astrFileName[3].length());
  726. return false;
  727. }
  728. }
  729. else {
  730. Log.d(TAG, "[checkDownloadFilename] model : " + Version.getModelType() + " , Build.MODEL :" + Build.MODEL );
  731. return false;
  732. }
  733. }
  734. else if (type == DownloadFileInfo.TYPE_IMG) return true;
  735. return true;
  736. } catch (RuntimeException re) {
  737. LogUtil.errorLogInfo("", TAG, re);
  738. return false;
  739. }
  740. catch (Exception e) {
  741. Log.e(TAG, "[Exception] checkDownloadFilename(String filename, int type)");
  742. //e.printStackTrace();
  743. LogUtil.errorLogInfo("", TAG, e);
  744. return false;
  745. }
  746. }
  747. /**
  748. * 플랫폼 ID에 업데이트 가능한 App 버전 존재 유무 확인
  749. * @param strValue - 다운로드할 파일의 모델명 (예. IHND101-I#APP#2020101501)
  750. * @return true: 업데이트 가능, false: 업데이트 불가
  751. */
  752. private boolean checkUpdateOption(String strValue) {
  753. if(strValue!=null)
  754. {
  755. try {
  756. Log.i(TAG, "[checkUpdateOption] strValue [" + strValue + "]");
  757. if (strValue.contains("#")) {
  758. String[] strParsed = strValue.split("#");
  759. String strModuleType = strParsed[1];
  760. String strVer = strParsed[2];
  761. // Log.i(TAG, "[checkUpdateOption] strModuleType [" + strModuleType + "], strVer [" + strVer + "]");
  762. return checkUpdatableModuleVer(strModuleType, strVer);
  763. }
  764. else return true;
  765. } catch (RuntimeException re) {
  766. LogUtil.errorLogInfo("", TAG, re);
  767. return false;
  768. }
  769. catch (Exception e) {
  770. Log.e(TAG, "[Exception] checkUpdateOption(String strValue)");
  771. //e.printStackTrace();
  772. LogUtil.errorLogInfo("", TAG, e);
  773. return false;
  774. }
  775. }
  776. else return false;
  777. }
  778. private boolean checkUpdatableModuleVer(String strModule, String strVer) {
  779. try {
  780. Log.i(TAG, "[checkUpdatableModuleVer] strModuleType [" + strModule + "], strVer [" + strVer + "]");
  781. if (strModule.equalsIgnoreCase(BSP_FILE_ID)) {
  782. int nCurrentVer = Integer.parseInt(Build.DISPLAY.replace(".", ""));
  783. int nMinVer = Integer.parseInt(strVer);
  784. Log.i(TAG, "[checkUpdatableModuleVer] BSP Ver. check -> nCurrentVer [" + nCurrentVer + "], nMinVer [" + nMinVer + "]");
  785. if (nCurrentVer >= nMinVer) {
  786. Log.w(TAG, "[checkUpdatableModuleVer] BSP update OK!! Current Ver. is bigger than minimum Ver!!");
  787. return true;
  788. }
  789. else {
  790. Log.w(TAG, "[checkUpdatableModuleVer] BSP update FAIL!! Current Ver. is smaller than minimum Ver!!");
  791. return false;
  792. }
  793. }
  794. else if (strModule.equalsIgnoreCase(APP_FILE_ID)) {
  795. int nCurrentVer = Integer.parseInt(getAppVersion().replace(".", ""));
  796. int nMinVer = Integer.parseInt(strVer);
  797. Log.i(TAG, "[checkUpdatableModuleVer] APP Ver. check -> nCurrentVer [" + nCurrentVer + "], nMinVer [" + nMinVer + "]");
  798. if (nCurrentVer >= nMinVer) {
  799. Log.w(TAG, "[checkUpdatableModuleVer] APP update OK!! Current Ver. is bigger than minimum Ver!!");
  800. return true;
  801. }
  802. else {
  803. Log.w(TAG, "[checkUpdatableModuleVer] APP update FAIL!! Current Ver. is smaller than minimum Ver!!");
  804. return false;
  805. }
  806. }
  807. else return false;
  808. } catch (RuntimeException re) {
  809. LogUtil.errorLogInfo("", TAG, re);
  810. return false;
  811. }
  812. catch (Exception e) {
  813. Log.e(TAG, "[Exception] checkUpdatableModuleVer(String strModule, String strVer)");
  814. //e.printStackTrace();
  815. LogUtil.errorLogInfo("", TAG, e);
  816. return false;
  817. }
  818. }
  819. private String changeUpdateModuleName(String strValue) {
  820. String strResult = "";
  821. if(strValue!=null)
  822. {
  823. try {
  824. Log.i(TAG, "[changeUpdateModuleName] strValue [" + strValue + "]");
  825. if (strValue.contains("#")) {
  826. String[] strParsed = strValue.split("#");
  827. strResult = strParsed[0];
  828. }
  829. else strResult = strValue;
  830. } catch (RuntimeException re) {
  831. LogUtil.errorLogInfo("", TAG, re);
  832. strResult = "Exception";
  833. }
  834. catch (Exception e) {
  835. Log.e(TAG, "[Exception] changeUpdateModuleName(String strValue)");
  836. //e.printStackTrace();
  837. LogUtil.errorLogInfo("", TAG, e);
  838. strResult = "Exception";
  839. }
  840. Log.i(TAG, "[changeUpdateModuleName] strResult [" + strResult + "]");
  841. }
  842. return strResult;
  843. }
  844. public String getAppVersion() {
  845. PackageInfo mPackageInfo = null;
  846. try {
  847. mPackageInfo = ThisCtx.getPackageManager().getPackageInfo(ThisCtx.getPackageName(), 0);
  848. }
  849. catch (RuntimeException re) {
  850. LogUtil.errorLogInfo("", TAG, re);
  851. }
  852. catch (Exception e) {
  853. Log.e(TAG, "[Exception] getAppVersion()");
  854. //e.printStackTrace();
  855. LogUtil.errorLogInfo("", TAG, e);
  856. }
  857. return mPackageInfo.versionName;
  858. }
  859. class ftp_FileDownloadWatcher extends Thread {
  860. String DownloadFile;
  861. long oldsize = 0;
  862. long size;
  863. Handler ExitHandle;
  864. File ProcF;
  865. int seqnum;
  866. public boolean onoff = false;
  867. public ftp_FileDownloadWatcher(String DownLoadFile, long size, Handler handle, int snum) {
  868. this.size = size;
  869. ExitHandle = handle;
  870. DownloadFile = DownLoadFile;
  871. seqnum = snum;
  872. }
  873. public void run() {
  874. long cursize;
  875. onoff = true;
  876. while (onoff) {
  877. try{Thread.sleep(1000);}
  878. catch (RuntimeException re) {
  879. LogUtil.errorLogInfo("", TAG, re);
  880. }
  881. catch (Exception e) {
  882. LogUtil.errorLogInfo("", TAG, e);
  883. }
  884. Log.e(TAG, "ftp_FileDownloadWatcher start!");
  885. if (ProcF == null) ProcF = new File(DownloadFile);
  886. if (!ProcF.exists()) return;
  887. cursize = ProcF.length();
  888. if (oldsize != cursize) oldsize = cursize;
  889. else {
  890. if (cursize >= size) return;
  891. if (filedownloader.isAlive()) filedownloader.interrupt();
  892. if (onoff != true) return;
  893. Message msg = ExitHandle.obtainMessage();
  894. msg.what = DOWNLOAD_FAIL_MSG;
  895. msg.arg1 = 0;
  896. msg.arg2 = seqnum;
  897. ExitHandle.sendMessage(msg);
  898. return;
  899. }
  900. }
  901. }
  902. }
  903. class ftp_FileDownload extends Thread {
  904. String ftpPATH;
  905. Handler handle;
  906. int Index;
  907. FTPClient f;
  908. //ftp_FileDownloadWatcher WatchThread;
  909. String localFile;
  910. int danjiserverType;
  911. boolean CompleteFlag = true; //event_notify 계속보내는 버그로 인하여 추가함
  912. public ftp_FileDownload(Handler handle, String path, int idx, String LocalFileName) {
  913. ftpPATH = path;
  914. Index = idx;
  915. this.handle = handle;
  916. //WatchThread = wat;
  917. localFile = LocalFileName;
  918. WallpadDeviceSet wallpadDeviceSet = new WallpadDeviceSet(ThisCtx);
  919. danjiserverType = wallpadDeviceSet.GetNewDanjiServer();
  920. wallpadDeviceSet.closeDB();
  921. }
  922. public void run() {
  923. Log.e(TAG, "[ftp_FileDownload.run()] ftp_FileDownload start! " + ftpPATH + "]");
  924. f = new FTPClient();
  925. f.setControlEncoding("euc-kr"); //한글이름의 파일은 FTP 다운로드가 안되기 때문에 인코딩 추가로 넣어줌
  926. f.setReceieveDataSocketBufferSize(1024*512);
  927. try {
  928. f.setReceiveBufferSize(1024*512);
  929. } catch (SocketException e1) {
  930. //e1.printStackTrace();
  931. LogUtil.errorLogInfo("", TAG, e1);
  932. //RetryHandler.sendEmptyMessageDelayed(0, retryDelay);
  933. ProcDownFail();
  934. return;
  935. }
  936. int recebf = f.getReceiveDataSocketBufferSize();
  937. FileOutputStream fos = null;
  938. BufferedOutputStream ffos = null;
  939. try {
  940. WallpadStatusData Wsdata = new WallpadStatusData(ThisCtx);
  941. FTPServer = Wsdata.GetFTPIP();
  942. Wsdata.closeDB();
  943. //여기서 ip정보를 변경해야 함
  944. if(danjiserverType == define.DanjiServer1 || danjiserverType == define.DanjiServer2)
  945. {
  946. f.connect(FTPServer);
  947. }
  948. else
  949. {
  950. f.connect(define.NewDanjiServerIP);
  951. }
  952. boolean ret = false;
  953. for(int i =0; i< 1; i++)
  954. ret = f.login(id, passwd);
  955. if (ret == false) {
  956. ProcDownFail();
  957. }
  958. String[] namelist = ftpPATH.split("/");
  959. String path = "";
  960. if (namelist.length > 2) {
  961. for (int i = 1; i < namelist.length - 1; i++) {
  962. path += "/"+namelist[i];
  963. }
  964. }
  965. Log.i(TAG, "[ftp_FileDownload] path [" + path+ "], localFile [" + localFile+ "]");
  966. ret = f.changeWorkingDirectory(path);
  967. if (ret == false) {
  968. ProcDownFail();
  969. }
  970. ret = f.setFileType(FTP.BINARY_FILE_TYPE);
  971. if (ret == false) {
  972. ProcDownFail();
  973. }
  974. File downloadfile = new File(localFile);
  975. if (downloadfile.exists()) FileDelete(downloadfile);//.delete();
  976. fos = new FileOutputStream(downloadfile);
  977. ffos = new BufferedOutputStream(fos);
  978. path = ftpPATH;
  979. boolean result;
  980. result = f.retrieveFile(path, ffos);
  981. ffos.flush();
  982. if (result == false) {
  983. ProcDownFail();
  984. }
  985. if (handle == null) Log.i(TAG, "[ftp_FileDownload.run()] handle is null!!");
  986. else Log.i(TAG, "[ftp_FileDownload.run()] handle is not null!!");
  987. Log.i(TAG, "[ftp_FileDownload.run()] CompleteFlag [" + CompleteFlag+ "]");
  988. if ((handle != null) && (CompleteFlag == true)) {
  989. // event_notify 계속보내는 버그로 인하여 추가함
  990. Message msg = handle.obtainMessage();
  991. msg.what = DOWNLOAD_SUCCESS_MSG;
  992. msg.arg1 = (result) ? 1 : 0;
  993. msg.arg2 = Index;
  994. msg.obj = localFile;
  995. handle.sendMessage(msg);
  996. }
  997. //WatchThread.onoff = false;
  998. } catch (RuntimeException re) {
  999. LogUtil.errorLogInfo("", TAG, re);
  1000. ProcDownFail();
  1001. }
  1002. catch (Exception e) {
  1003. Log.e(TAG, "[Exception] ftp_FileDownload.run() 1");
  1004. //e.printStackTrace();
  1005. LogUtil.errorLogInfo("", TAG, e);
  1006. ProcDownFail();
  1007. }
  1008. finally {
  1009. if(fos!=null) {
  1010. try {
  1011. fos.close();
  1012. } catch (IOException e) {
  1013. LogUtil.errorLogInfo("", TAG, e);
  1014. }
  1015. }
  1016. fos = null;
  1017. if(ffos!=null) {
  1018. try {
  1019. ffos.close();
  1020. } catch (IOException e) {
  1021. LogUtil.errorLogInfo("", TAG, e);
  1022. }
  1023. ffos = null;
  1024. }
  1025. }
  1026. try{
  1027. f.quit();
  1028. } catch (RuntimeException re) {
  1029. LogUtil.errorLogInfo("", TAG, re);
  1030. }
  1031. catch (Exception e) {
  1032. Log.e(TAG, "[Exception] ftp_FileDownload.run() 2");
  1033. //e.printStackTrace();
  1034. LogUtil.errorLogInfo("", TAG, e);
  1035. }
  1036. }
  1037. private void ProcDownFail() {
  1038. try {
  1039. Log.w(TAG, "[ProcDownFail] ========== Download failed ==========");
  1040. CompleteFlag = false; //event_notify 계속보내는 버그로 인하여 추가함
  1041. f.logout();
  1042. f.quit();
  1043. } catch (RuntimeException re) {
  1044. LogUtil.errorLogInfo("", TAG, re);
  1045. }
  1046. catch (Exception e) {
  1047. //e.printStackTrace();
  1048. LogUtil.errorLogInfo("", TAG, e);
  1049. }
  1050. //WatchThread.onoff = false;
  1051. Message msg = handle.obtainMessage();
  1052. msg.what = DOWNLOAD_FAIL_MSG;
  1053. msg.arg1 = 0;
  1054. msg.arg2 = Index;
  1055. msg.obj = ftpPATH;
  1056. handle.sendMessage(msg);
  1057. }
  1058. }
  1059. public boolean parseXML(String XMLDOC) {
  1060. return true;
  1061. }
  1062. static String PATH_LOCAL_ROOT = "/sdcard/";
  1063. public static String[] strUpgradeFileKeyword_ALL = { "_V40_", "_A40i_" };
  1064. public static String strUpgradeFileExtention = "zip";
  1065. public boolean cleanSDRoot() {
  1066. try {
  1067. Log.i(TAG, "[cleanSDRoot] =====START =====");
  1068. for (int i = 0; i < strUpgradeFileKeyword_ALL.length; i++) {
  1069. String[] DeleteFile = findDirectoryFiles(PATH_LOCAL_ROOT, strUpgradeFileKeyword_ALL[i], strUpgradeFileExtention);
  1070. if(DeleteFile!=null)
  1071. {
  1072. Log.i(TAG, "[cleanSDRoot] DeleteFile.length = " + DeleteFile.length);
  1073. File TargetFile;
  1074. for (int j = 0; j < DeleteFile.length; j++) {
  1075. TargetFile = new File(PATH_LOCAL_ROOT + DeleteFile[j]);
  1076. if (TargetFile.delete()) {
  1077. Log.i(TAG, "[cleanSDRoot] Success to delete!! TargetFile = " + TargetFile.getName());
  1078. }
  1079. else {
  1080. Log.i(TAG, "[cleanSDRoot] Fail to delete!! TargetFile = " + TargetFile.getName());
  1081. }
  1082. }
  1083. }
  1084. }
  1085. return true;
  1086. } catch (RuntimeException re) {
  1087. LogUtil.errorLogInfo("", TAG, re);
  1088. return false;
  1089. }
  1090. catch (Exception e) {
  1091. Log.e(TAG, "[Exception] cleanSDRoot()");
  1092. //e.printStackTrace();
  1093. LogUtil.errorLogInfo("", TAG, e);
  1094. return false;
  1095. }
  1096. }
  1097. public String[] findDirectoryFiles(String strDstDir, final String strKeyword, final String strExtention) {
  1098. try {
  1099. Log.i(TAG, "[findDirectoryFiles] strDstDir [" + strDstDir + "], strKeyword [" + strKeyword + "], strExtention [" + strExtention + "]");
  1100. String[] strResult = null;
  1101. if (strDstDir == null) return null;
  1102. File Directory = new File(strDstDir);
  1103. if (Directory.exists()) {
  1104. FilenameFilter mFilenameFilter = new FilenameFilter() {
  1105. @Override
  1106. public boolean accept(File dir, String filename) {
  1107. if (strKeyword != null && strExtention != null) {
  1108. return (filename.endsWith(strExtention) && filename.matches(".*" + strKeyword + ".*"));
  1109. }
  1110. else if (strKeyword != null && strExtention == null) {
  1111. return filename.matches(".*" + strKeyword + ".*");
  1112. }
  1113. else if (strKeyword == null && strExtention != null) {
  1114. return filename.endsWith(strExtention);
  1115. }
  1116. else if (strKeyword == null && strExtention == null) {
  1117. return true;
  1118. }
  1119. return false;
  1120. }
  1121. };
  1122. String[] mFiles = Directory.list(mFilenameFilter);
  1123. if(mFiles!=null)
  1124. {
  1125. Log.i(TAG, "[findDirectoryFiles] mFiles.length = " + mFiles.length);
  1126. strResult = new String[mFiles.length];
  1127. for (int i = 0; i < strResult.length; i++) {
  1128. strResult[i] = mFiles[i];
  1129. Log.i(TAG, "[findDirectoryFiles] strResult[" + i + "] = " + strResult[i]);
  1130. }
  1131. }
  1132. return strResult;
  1133. }
  1134. else {
  1135. Log.i(TAG, "[findDirectoryFiles] Directory is not exist!! [" + strDstDir + "]");
  1136. return null;
  1137. }
  1138. } catch (RuntimeException re) {
  1139. LogUtil.errorLogInfo("", TAG, re);
  1140. return null;
  1141. }
  1142. catch (Exception e) {
  1143. Log.e(TAG, "[Exception] findDirectoryFiles()");
  1144. //e.printStackTrace();
  1145. LogUtil.errorLogInfo("", TAG, e);
  1146. return null;
  1147. }
  1148. }
  1149. public void checkMemorySize() {
  1150. try {
  1151. String strInternalTotalMemorySize = formatSize(getTotalInternalMemorySize());
  1152. String strAvailableInternalMemorySize = formatSize(getAvailableInternalMemorySize());
  1153. String strExternalTotalMemorySize = formatSize(getTotalExternalMemorySize());
  1154. String strAvailableExternalMemorySize = formatSize(getAvailableExternalMemorySize());
  1155. Log.i(TAG, "[checkMemorySize] strInternalTotalMemorySize [" + strInternalTotalMemorySize + "], strAvailableInternalMemorySize [" + strAvailableInternalMemorySize + "]");
  1156. Log.i(TAG, "[checkMemorySize] strExternalTotalMemorySize [" + strExternalTotalMemorySize + "], strAvailableExternalMemorySize [" + strAvailableExternalMemorySize + "]");
  1157. } catch (RuntimeException re) {
  1158. LogUtil.errorLogInfo("", TAG, re);
  1159. }
  1160. catch (Exception e) {
  1161. Log.e(TAG, "[Exception] checkMemorySize()");
  1162. //e.printStackTrace();
  1163. LogUtil.errorLogInfo("", TAG, e);
  1164. }
  1165. }
  1166. /** 전체 내장 메모리 크기를 가져온다 */
  1167. private long getTotalInternalMemorySize() {
  1168. try {
  1169. File path = Environment.getDataDirectory();
  1170. StatFs stat = new StatFs(path.getPath());
  1171. long blockSize = stat.getBlockSize();
  1172. long totalBlocks = stat.getBlockCount();
  1173. return totalBlocks * blockSize;
  1174. } catch (RuntimeException re) {
  1175. LogUtil.errorLogInfo("", TAG, re);
  1176. return -99;
  1177. }
  1178. catch (Exception e) {
  1179. Log.e(TAG, "[Exception] getTotalInternalMemorySize()");
  1180. //e.printStackTrace();
  1181. LogUtil.errorLogInfo("", TAG, e);
  1182. return -99;
  1183. }
  1184. }
  1185. /** 사용가능한 내장 메모리 크기를 가져온다 */
  1186. private long getAvailableInternalMemorySize() {
  1187. try {
  1188. File path = Environment.getDataDirectory();
  1189. StatFs stat = new StatFs(path.getPath());
  1190. long blockSize = stat.getBlockSize();
  1191. long availableBlocks = stat.getAvailableBlocks();
  1192. return availableBlocks * blockSize;
  1193. } catch (RuntimeException re) {
  1194. LogUtil.errorLogInfo("", TAG, re);
  1195. return -99;
  1196. }
  1197. catch (Exception e) {
  1198. Log.e(TAG, "[Exception] getAvailableInternalMemorySize()");
  1199. //e.printStackTrace();
  1200. LogUtil.errorLogInfo("", TAG, e);
  1201. return -99;
  1202. }
  1203. }
  1204. /** 전체 외장 메모리 크기를 가져온다 */
  1205. private long getTotalExternalMemorySize() {
  1206. try {
  1207. if (isStorage(true) == true) {
  1208. File path = Environment.getExternalStorageDirectory();
  1209. StatFs stat = new StatFs(path.getPath());
  1210. long blockSize = stat.getBlockSize();
  1211. long totalBlocks = stat.getBlockCount();
  1212. return totalBlocks * blockSize;
  1213. } else {
  1214. return -1;
  1215. }
  1216. } catch (RuntimeException re) {
  1217. LogUtil.errorLogInfo("", TAG, re);
  1218. return -99;
  1219. }
  1220. catch (Exception e) {
  1221. Log.e(TAG, "[Exception] getTotalExternalMemorySize()");
  1222. //e.printStackTrace();
  1223. LogUtil.errorLogInfo("", TAG, e);
  1224. return -99;
  1225. }
  1226. }
  1227. /** 사용가능한 외장 메모리 크기를 가져온다 */
  1228. private long getAvailableExternalMemorySize() {
  1229. try {
  1230. if (isStorage(true) == true) {
  1231. File path = Environment.getExternalStorageDirectory();
  1232. StatFs stat = new StatFs(path.getPath());
  1233. long blockSize = stat.getBlockSize();
  1234. long availableBlocks = stat.getAvailableBlocks();
  1235. return availableBlocks * blockSize;
  1236. } else {
  1237. return -1;
  1238. }
  1239. } catch (RuntimeException re) {
  1240. LogUtil.errorLogInfo("", TAG, re);
  1241. return -99;
  1242. }
  1243. catch (Exception e) {
  1244. Log.e(TAG, "[Exception] getAvailableExternalMemorySize()");
  1245. //e.printStackTrace();
  1246. LogUtil.errorLogInfo("", TAG, e);
  1247. return -99;
  1248. }
  1249. }
  1250. /** 보기 좋게 MB,KB 단위로 축소시킨다 */
  1251. private String formatSize(long size) {
  1252. try {
  1253. String suffix = null;
  1254. if (size >= 1024) {
  1255. suffix = "KB";
  1256. size /= 1024;
  1257. if (size >= 1024) {
  1258. suffix = "MB";
  1259. size /= 1024;
  1260. }
  1261. }
  1262. StringBuilder resultBuffer = new StringBuilder(Long.toString(size));
  1263. int commaOffset = resultBuffer.length() - 3;
  1264. while (commaOffset > 0) {
  1265. resultBuffer.insert(commaOffset, ',');
  1266. commaOffset -= 3;
  1267. }
  1268. if (suffix != null) {
  1269. resultBuffer.append(suffix);
  1270. }
  1271. return resultBuffer.toString();
  1272. } catch (RuntimeException re) {
  1273. LogUtil.errorLogInfo("", TAG, re);
  1274. return null;
  1275. }
  1276. catch (Exception e) {
  1277. Log.e(TAG, "[Exception] formatSize(long size)");
  1278. //e.printStackTrace();
  1279. LogUtil.errorLogInfo("", TAG, e);
  1280. return null;
  1281. }
  1282. }
  1283. /** 외장메모리 sdcard 사용가능한지에 대한 여부 판단 */
  1284. private boolean isStorage(boolean requireWriteAccess) {
  1285. try {
  1286. String state = Environment.getExternalStorageState();
  1287. if (Environment.MEDIA_MOUNTED.equals(state)) {
  1288. return true;
  1289. } else if (!requireWriteAccess &&
  1290. Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
  1291. return true;
  1292. }
  1293. return false;
  1294. } catch (RuntimeException re) {
  1295. LogUtil.errorLogInfo("", TAG, re);
  1296. return false;
  1297. }
  1298. catch (Exception e) {
  1299. Log.e(TAG, "[Exception] isStorage(boolean requireWriteAccess)");
  1300. //e.printStackTrace();
  1301. LogUtil.errorLogInfo("", TAG, e);
  1302. return false;
  1303. }
  1304. }
  1305. private synchronized void FileDelete(File file)
  1306. {
  1307. if(file!=null && file.exists())
  1308. {
  1309. file.delete();
  1310. }
  1311. }
  1312. }