diff options
author | Christian S <christian@pix-art.de> | 2015-10-10 11:28:40 +0200 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-10-10 11:28:40 +0200 |
commit | 879d5ce16a05804526f0c72f8f25d4bfac097721 (patch) | |
tree | a65a982f75f8a0bc69da7d5e43676ad8303bebbf /src/main/java | |
parent | 113583c5edba8d879642bbff712d035dacee5de3 (diff) |
changed log outputs of updater and delete old...
...downloaded files before downloading update
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/UpdaterWebService.java | 17 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java | 29 |
2 files changed, 29 insertions, 17 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java index 1001562dc..faad2fd93 100644 --- a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java +++ b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java @@ -18,13 +18,12 @@ import org.apache.http.params.HttpParams; import java.io.ByteArrayOutputStream; import java.io.IOException; +import eu.siacs.conversations.Config; import eu.siacs.conversations.ui.UpdaterActivity.MyWebReceiver; public class UpdaterWebService extends IntentService{ - private static final String LOG_TAG = "MyWebService"; - public static final String REQUEST_STRING = "myRequest"; - public static final String RESPONSE_STRING = "myResponse"; - public static final String RESPONSE_MESSAGE = "myResponseMessage"; + public static final String REQUEST_STRING = ""; + public static final String RESPONSE_MESSAGE = ""; private String URL = null; private static final int REGISTRATION_TIMEOUT = 3 * 1000; @@ -38,7 +37,7 @@ public class UpdaterWebService extends IntentService{ protected void onHandleIntent(Intent intent) { String requestString = intent.getStringExtra(REQUEST_STRING); - Log.v(LOG_TAG, requestString); + Log.d(Config.LOGTAG, "AppUpdater: " + requestString); String responseMessage = ""; try { @@ -63,19 +62,19 @@ public class UpdaterWebService extends IntentService{ } else{ - Log.w("HTTP1:",statusLine.getReasonPhrase()); + Log.d(Config.LOGTAG, "AppUpdater: HTTP1:" + statusLine.getReasonPhrase()); response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { - Log.w("HTTP2:",e ); + Log.d(Config.LOGTAG, "AppUpdater: HTTP2:" + e); responseMessage = e.getMessage(); } catch (IOException e) { - Log.w("HTTP3:",e ); + Log.d(Config.LOGTAG, "AppUpdater: HTTP3:" + e); responseMessage = e.getMessage(); }catch (Exception e) { - Log.w("HTTP4:",e ); + Log.d(Config.LOGTAG, "AppUpdater: HTTP4:" + e); responseMessage = e.getMessage(); } diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java index 3df4dca75..7f721f0e6 100644 --- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java @@ -22,6 +22,8 @@ import android.widget.Toast; import org.json.JSONException; import org.json.JSONObject; +import java.io.File; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.services.UpdaterWebService; @@ -126,9 +128,9 @@ public class UpdaterActivity extends Activity { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { - Log.v(LOG_TAG, String.valueOf(i)); + Log.d(Config.LOGTAG, "AppUpdater: " + String.valueOf(i)); if (info[i].getState() == NetworkInfo.State.CONNECTED) { - Log.v(LOG_TAG, "connected!"); + Log.d(Config.LOGTAG, "AppUpdater: connected to update Server!"); return true; } } @@ -146,7 +148,7 @@ public class UpdaterActivity extends Activity { public void onReceive(Context context, Intent intent) { String reponseMessage = intent.getStringExtra(UpdaterWebService.RESPONSE_MESSAGE); - Log.v(LOG_TAG, reponseMessage); + Log.d(Config.LOGTAG, "AppUpdater: " + reponseMessage); //parse the JSON response JSONObject responseObj; @@ -179,6 +181,7 @@ public class UpdaterActivity extends Activity { appURI = responseObj.getString("appURI"); //check if we need to upgrade? if(latestVersionCode > versionCode){ + Log.d(Config.LOGTAG, "AppUpdater: update available"); //enable touch events getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); @@ -199,6 +202,18 @@ public class UpdaterActivity extends Activity { request.setAllowedOverRoaming(false); request.setTitle("Conversations Update"); request.setDestinationInExternalFilesDir(UpdaterActivity.this, Environment.DIRECTORY_DOWNLOADS, "Conversations.apk"); + //delete old downloaded version files + File dir = new File(getExternalFilesDir(null), Environment.DIRECTORY_DOWNLOADS); + Log.d(Config.LOGTAG, "AppUpdater - Delete old update files in: " + dir); + if (dir.isDirectory()) + { + String[] children = dir.list(); + for (int i = 0; i < children.length; i++) + { + new File(dir, children[i]).delete(); + } + } + downloadReference = downloadManager.enqueue(request); Toast.makeText(getApplicationContext(), getText(R.string.download_started), @@ -219,7 +234,7 @@ public class UpdaterActivity extends Activity { Toast.makeText(getApplicationContext(), getText(R.string.no_update_available), Toast.LENGTH_SHORT).show(); - + Log.d(Config.LOGTAG, "AppUpdater: no update available"); UpdaterActivity.this.finish(); } @@ -242,16 +257,14 @@ public class UpdaterActivity extends Activity { long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); if(downloadReference == referenceId){ - Log.v(LOG_TAG, "Downloading of the new app version complete"); + Log.d(Config.LOGTAG, "AppUpdater: Downloading of the new app version complete. Starting installation"); //start the installation of the latest version Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.setDataAndType(downloadManager.getUriForDownloadedFile(downloadReference), "application/vnd.android.package-archive"); installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(installIntent); - } } }; - -} +}
\ No newline at end of file |