diff options
author | Christian S <christian@pix-art.de> | 2015-10-22 20:29:16 +0200 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-10-22 20:29:16 +0200 |
commit | 83ec2b12552b533a3b5cc7a7e8ec695d17bbf447 (patch) | |
tree | 58d12e5ff44e66f1987c13925495943367cb549c /src | |
parent | 2200ba240ad06096e49268309a5fa2cbc99ab147 (diff) |
bug fixed in updater
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/UpdaterWebService.java | 20 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java | 198 |
2 files changed, 110 insertions, 108 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java index 103270e9b..3ff6641aa 100644 --- a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java +++ b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java @@ -41,7 +41,7 @@ public class UpdaterWebService extends IntentService{ String requestString = intent.getStringExtra(REQUEST_STRING); Log.d(Config.LOGTAG, "AppUpdater: " + requestString); - String responseMessage = ""; + String responseMessage; PackageInfo pInfo = null; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); @@ -73,23 +73,21 @@ public class UpdaterWebService extends IntentService{ response.getEntity().writeTo(out); out.close(); responseMessage = out.toString(); - } - - else{ - Log.d(Config.LOGTAG, "AppUpdater: HTTP1:" + statusLine.getReasonPhrase()); + } else { + Log.e(Config.LOGTAG, "AppUpdater: HTTP1:" + statusLine.getReasonPhrase()); response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { - Log.d(Config.LOGTAG, "AppUpdater: HTTP2:" + e); - responseMessage = e.getMessage(); + Log.e(Config.LOGTAG, "AppUpdater: HTTP2:" + e); + responseMessage = ""; } catch (IOException e) { - Log.d(Config.LOGTAG, "AppUpdater: HTTP3:" + e); - responseMessage = e.getMessage(); + Log.e(Config.LOGTAG, "AppUpdater: HTTP3:" + e); + responseMessage = ""; }catch (Exception e) { - Log.d(Config.LOGTAG, "AppUpdater: HTTP4:" + e); - responseMessage = e.getMessage(); + Log.e(Config.LOGTAG, "AppUpdater: HTTP4:" + e); + responseMessage = ""; } diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java index 769451007..4dccdfe5b 100644 --- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java @@ -66,13 +66,13 @@ public class UpdaterActivity extends Activity { registerReceiver(downloadReceiver, filter); //check of internet is available before making a web service request - if(isNetworkAvailable(this)){ + if (isNetworkAvailable(this)) { Intent msgIntent = new Intent(this, UpdaterWebService.class); msgIntent.putExtra(UpdaterWebService.REQUEST_STRING, Config.UPDATE_URL); - + Toast.makeText(getApplicationContext(), - getText(R.string.checking_for_updates), - Toast.LENGTH_SHORT).show(); + getText(R.string.checking_for_updates), + Toast.LENGTH_SHORT).show(); startService(msgIntent); } } @@ -97,7 +97,7 @@ public class UpdaterActivity extends Activity { super.onRestoreInstanceState(savedInstanceState); } - //check for internet connection + //check for internet connection private boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { @@ -127,103 +127,107 @@ public class UpdaterActivity extends Activity { WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); String reponseMessage = intent.getStringExtra(UpdaterWebService.RESPONSE_MESSAGE); - Log.d(Config.LOGTAG, "AppUpdater: " + reponseMessage); - - //parse the JSON response - JSONObject responseObj; - try { - responseObj = new JSONObject(reponseMessage); - boolean success = responseObj.getBoolean("success"); - //if the reponse was successful check further - if(success){ - //Overall information about the contents of a package - //This corresponds to all of the information collected from AndroidManifest.xml. - PackageInfo pInfo = null; - try { - pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); - } - catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - //get the app version Name for display - final String versionName = pInfo.versionName; - final int versionCode = pInfo.versionCode; - //get the latest version from the JSON string - int latestVersionCode = responseObj.getInt("latestVersionCode"); - String latestVersion = responseObj.getString("latestVersion"); - String changelog = responseObj.getString("changelog"); - //get the lastest application URI from the JSON string - appURI = responseObj.getString("appURI"); - //check if we need to upgrade? - if(latestVersionCode > versionCode){ - Log.d(Config.LOGTAG, "AppUpdater: update available"); - //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(); + Log.d(Config.LOGTAG, "AppUpdater: Reponse: " + reponseMessage); + + if (reponseMessage == "" || reponseMessage.isEmpty() || reponseMessage == null) { + Toast.makeText(getApplicationContext(), + getText(R.string.failed), + Toast.LENGTH_LONG).show(); + Log.e(Config.LOGTAG, "AppUpdater: error connecting to server"); + UpdaterActivity.this.finish(); + } else { + Log.d(Config.LOGTAG, "AppUpdater: connecting to server"); + //parse the JSON reponse + JSONObject reponseObj; + + try { + //if the reponse was successful check further + reponseObj = new JSONObject(reponseMessage); + boolean success = reponseObj.getBoolean("success"); + if (success) { + //Overall information about the contents of a package + //This correponds to all of the information collected from AndroidManifest.xml. + PackageInfo pInfo = null; + try { + pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + //get the app version Name for display + final String versionName = pInfo.versionName; + final int versionCode = pInfo.versionCode; + //get the latest version from the JSON string + int latestVersionCode = reponseObj.getInt("latestVersionCode"); + String latestVersion = reponseObj.getString("latestVersion"); + String changelog = reponseObj.getString("changelog"); + //get the lastest application URI from the JSON string + appURI = reponseObj.getString("appURI"); + //check if we need to upgrade? + if (latestVersionCode > versionCode) { + Log.d(Config.LOGTAG, "AppUpdater: update available"); + //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(); + } } + //enable touch events + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); + + //oh yeah we do need an upgrade, let the user know send an alert message + AlertDialog.Builder builder = new AlertDialog.Builder(UpdaterActivity.this); + builder.setCancelable(false); + + String UpdateMessageInfo = getResources().getString(R.string.update_available); + builder.setMessage(String.format(UpdateMessageInfo, latestVersion, changelog, versionName)) + .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() { + //if the user agrees to upgrade + public void onClick(DialogInterface dialog, int id) { + //disable touch events + getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, + WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); + //start downloading the file using the download manager + downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); + Uri Download_Uri = Uri.parse(appURI); + DownloadManager.Request request = new DownloadManager.Request(Download_Uri); + request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); + request.setAllowedOverRoaming(false); + request.setTitle("Conversations Update"); + request.setDestinationInExternalFilesDir(UpdaterActivity.this, Environment.DIRECTORY_DOWNLOADS, "Conversations" + versionName + ".apk"); + downloadReference = downloadManager.enqueue(request); + Toast.makeText(getApplicationContext(), + getText(R.string.download_started), + Toast.LENGTH_LONG).show(); + } + }) + .setNegativeButton(R.string.remind_later, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + UpdaterActivity.this.finish(); + } + }); + //show the alert message + builder.create().show(); + } else { + Toast.makeText(getApplicationContext(), + getText(R.string.no_update_available), + Toast.LENGTH_SHORT).show(); + Log.d(Config.LOGTAG, "AppUpdater: no update available"); + UpdaterActivity.this.finish(); } - //enable touch events - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); - - //oh yeah we do need an upgrade, let the user know send an alert message - AlertDialog.Builder builder = new AlertDialog.Builder(UpdaterActivity.this); - builder.setCancelable(false); - - String UpdateMessageInfo = getResources().getString(R.string.update_available); - builder.setMessage(String.format(UpdateMessageInfo, latestVersion, changelog, versionName)) - .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() { - //if the user agrees to upgrade - public void onClick(DialogInterface dialog, int id) { - //disable touch events - getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, - WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); - //start downloading the file using the download manager - downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); - Uri Download_Uri = Uri.parse(appURI); - DownloadManager.Request request = new DownloadManager.Request(Download_Uri); - request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); - request.setAllowedOverRoaming(false); - request.setTitle("Conversations Update"); - request.setDestinationInExternalFilesDir(UpdaterActivity.this, Environment.DIRECTORY_DOWNLOADS, "Conversations" + versionName + ".apk"); - downloadReference = downloadManager.enqueue(request); - Toast.makeText(getApplicationContext(), - getText(R.string.download_started), - Toast.LENGTH_LONG).show(); - } - }) - .setNegativeButton(R.string.remind_later, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User cancelled the dialog - UpdaterActivity.this.finish(); - } - }); - //show the alert message - builder.create().show(); - } - else - { + } else { Toast.makeText(getApplicationContext(), - getText(R.string.no_update_available), - Toast.LENGTH_SHORT).show(); - Log.d(Config.LOGTAG, "AppUpdater: no update available"); + getText(R.string.failed), + Toast.LENGTH_LONG).show(); + Log.e(Config.LOGTAG, "AppUpdater: contact to server not successfull"); UpdaterActivity.this.finish(); } - - } else { - Toast.makeText(getApplicationContext(), - getText(R.string.failed), - Toast.LENGTH_LONG).show(); - Log.d(Config.LOGTAG, "AppUpdater: contact to server not successfull"); - UpdaterActivity.this.finish(); + } catch (JSONException e) { + e.printStackTrace(); } - } catch (JSONException e) { - e.printStackTrace(); } } @@ -237,7 +241,7 @@ public class UpdaterActivity extends Activity { public void onReceive(Context context, Intent intent) { //check if the broadcast message is for our Enqueued download long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); - if(downloadReference == referenceId){ + if (downloadReference == referenceId) { Log.d(Config.LOGTAG, "AppUpdater: Downloading of the new app version complete. Starting installation"); //start the installation of the latest version |