private int OnlineUpdateCheck(String content) { Utils.logger("d", "OnlineUpdateCheck", DEBUG_TAG); int res = 3; if (asyncAutoUpdate.isCancelled()) { Utils.logger("d", "asyncUpdate cancelled @ 'OnlineUpdateCheck' begin", DEBUG_TAG); return 3; } // match version name Pattern v_pattern = Pattern.compile("versionName=\\\"(.*)\\\""); Matcher v_matcher = v_pattern.matcher(content); if (v_matcher.find() && !asyncAutoUpdate.isCancelled()) { matchedVersion = v_matcher.group(1); Utils.logger("i", "_on-line version: " + matchedVersion, DEBUG_TAG); res = res - 1; } else { matchedVersion = "not_found"; Log.e(DEBUG_TAG, "_online version: not found!"); } // match changelog Pattern cl_pattern = Pattern.compile("<pre><code> v(.*?)</code></pre>", Pattern.DOTALL); Matcher cl_matcher = cl_pattern.matcher(content); if (cl_matcher.find() && !asyncAutoUpdate.isCancelled()) { matchedChangeLog = " v" + cl_matcher.group(1); Utils.logger("i", "_online changelog...", DEBUG_TAG); res = res - 1; } else { matchedChangeLog = "not_found"; Log.e(DEBUG_TAG, "_online changelog not found!"); } // match md5 // checksum: <code>d7ef1e4668b24517fb54231571b4a74f</code> dentex.youtube.downloader_v1.4 Pattern md5_pattern = Pattern.compile("checksum: <code>(.{32})</code> dentex.youtube.downloader_v"); Matcher md5_matcher = md5_pattern.matcher(content); if (md5_matcher.find() && !asyncAutoUpdate.isCancelled()) { matchedMd5 = md5_matcher.group(1); Utils.logger("i", "_online md5sum: " + matchedMd5, DEBUG_TAG); res = res - 1; } else { matchedMd5 = "not_found"; Log.e(DEBUG_TAG, "_online md5sum not found!"); } compRes = Utils.VersionComparator.compare(matchedVersion, currentVersion); Utils.logger( "d", "version comparison: " + matchedVersion + " " + compRes + " " + currentVersion, DEBUG_TAG); return res; }
@Override public void onCreate() { Utils.logger("d", "service created", DEBUG_TAG); BugSenseHandler.initAndStartSession(this, YTD.BugsenseApiKey); BugSenseHandler.leaveBreadcrumb("AutoUpgradeApkService_onCreate"); registerReceiver(apkReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); try { currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; Utils.logger("d", "current version: " + currentVersion, DEBUG_TAG); } catch (NameNotFoundException e) { Log.e(DEBUG_TAG, "version not read: " + e.getMessage()); currentVersion = "100"; } ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected() && matchedVersion != "n.a.") { try { // init version and changelog matchedChangeLog = null; matchedVersion = null; asyncAutoUpdate = new AsyncUpdate(); webPage = "http://sourceforge.net/projects/ytdownloader/files/"; asyncAutoUpdate.execute(webPage); } catch (NullPointerException e) { Log.e(DEBUG_TAG, "unable to retrieve update data."); } } else { Log.e(DEBUG_TAG, getString(R.string.no_net)); } }