diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/AndroidManifest.xml | 41 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/Config.java | 2 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java | 43 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/UpdaterWebService.java | 91 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java | 197 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 3 | ||||
-rw-r--r-- | src/main/res/layout/activity_updater.xml | 19 | ||||
-rw-r--r-- | src/main/res/menu/conversations.xml | 5 | ||||
-rw-r--r-- | src/main/res/menu/menu_updater.xml | 7 | ||||
-rw-r--r-- | src/main/res/values-de/strings.xml | 8 | ||||
-rw-r--r-- | src/main/res/values-w820dp/dimens.xml | 6 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 8 |
12 files changed, 417 insertions, 13 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 89ea620a2..0d14448e8 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> -<manifest - package="eu.siacs.conversations" - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools"> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="eu.siacs.conversations" > <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> @@ -14,8 +13,9 @@ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.NFC" /> - - <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /> + <uses-permission + android:name="android.permission.READ_PHONE_STATE" + tools:node="remove" /> <application android:allowBackup="true" @@ -47,8 +47,8 @@ <activity android:name=".ui.StartConversationActivity" android:configChanges="orientation|screenSize" - android:launchMode="singleTask" - android:label="@string/title_activity_start_conversation" > + android:label="@string/title_activity_start_conversation" + android:launchMode="singleTask" > <intent-filter> <action android:name="android.intent.action.SENDTO" /> @@ -82,9 +82,9 @@ <activity android:name=".ui.BlocklistActivity" android:label="@string/title_activity_block_list" /> - <activity - android:name=".ui.ChangePasswordActivity" - android:label="@string/change_password_on_server" /> + <activity + android:name=".ui.ChangePasswordActivity" + android:label="@string/change_password_on_server" /> <activity android:name=".ui.ManageAccountActivity" android:configChanges="orientation|screenSize" @@ -136,11 +136,11 @@ <activity android:name=".ui.TrustKeysActivity" android:label="@string/trust_omemo_fingerprints" - android:windowSoftInputMode="stateAlwaysHidden"/> + android:windowSoftInputMode="stateAlwaysHidden" /> <activity android:name="de.duenndns.ssl.MemorizingActivity" android:theme="@style/ConversationsTheme" - tools:replace="android:theme"/> + tools:replace="android:theme" /> <activity android:name=".ui.AboutActivity" android:label="@string/title_activity_about" @@ -149,6 +149,21 @@ android:name="android.support.PARENT_ACTIVITY" android:value="eu.siacs.conversations.ui.SettingsActivity" /> </activity> + <activity + android:name=".ui.UpdaterActivity" + android:label="@string/title_activity_updater" > + </activity> + + <service + android:name=".services.UpdaterWebService" + android:enabled="true" + android:exported="true" > + </service> + <service + android:name=".services.CheckAppVersionService" + android:enabled="true" + android:exported="true" > + </service> </application> </manifest> diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 7ac870459..e5e15edd7 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -54,6 +54,8 @@ public final class Config { public static final ChatState DEFAULT_CHATSTATE = ChatState.ACTIVE; public static final int TYPING_TIMEOUT = 5; + public static final String UPDATE_URL = "http://xmpp.pix-art.de/update/"; + public static final String ENABLED_CIPHERS[] = { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA384", diff --git a/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java b/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java new file mode 100644 index 000000000..0fffb8a78 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/services/CheckAppVersionService.java @@ -0,0 +1,43 @@ +package eu.siacs.conversations.services; + +import com.google.gson.JsonObject; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CheckAppVersionService extends HttpServlet { + private static final long serialVersionUID = 1L; + + public CheckAppVersionService() { + super(); + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request,response); + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + //send a JSON response with the app Version and file URI + JsonObject myObj = new JsonObject(); + myObj.addProperty("success", true); + myObj.addProperty("latestVersionCode", 2); + myObj.addProperty("latestVersion", "1.0.0"); + myObj.addProperty("appURI", ""); + out.println(myObj.toString()); + out.close(); + + + } + +}
\ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java new file mode 100644 index 000000000..1001562dc --- /dev/null +++ b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java @@ -0,0 +1,91 @@ +package eu.siacs.conversations.services; + +import android.app.IntentService; +import android.content.Intent; +import android.util.Log; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.StatusLine; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.params.ConnManagerParams; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +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"; + + private String URL = null; + private static final int REGISTRATION_TIMEOUT = 3 * 1000; + private static final int WAIT_TIMEOUT = 30 * 1000; + + public UpdaterWebService() { + super("UpdaterWebService"); + } + + @Override + protected void onHandleIntent(Intent intent) { + + String requestString = intent.getStringExtra(REQUEST_STRING); + Log.v(LOG_TAG, requestString); + String responseMessage = ""; + + try { + + URL = requestString; + HttpClient httpclient = new DefaultHttpClient(); + HttpParams params = httpclient.getParams(); + + HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT); + HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT); + ConnManagerParams.setTimeout(params, WAIT_TIMEOUT); + + HttpGet httpGet = new HttpGet(URL); + HttpResponse response = httpclient.execute(httpGet); + + StatusLine statusLine = response.getStatusLine(); + if(statusLine.getStatusCode() == HttpStatus.SC_OK){ + ByteArrayOutputStream out = new ByteArrayOutputStream(); + response.getEntity().writeTo(out); + out.close(); + responseMessage = out.toString(); + } + + else{ + Log.w("HTTP1:",statusLine.getReasonPhrase()); + response.getEntity().getContent().close(); + throw new IOException(statusLine.getReasonPhrase()); + } + + } catch (ClientProtocolException e) { + Log.w("HTTP2:",e ); + responseMessage = e.getMessage(); + } catch (IOException e) { + Log.w("HTTP3:",e ); + responseMessage = e.getMessage(); + }catch (Exception e) { + Log.w("HTTP4:",e ); + responseMessage = e.getMessage(); + } + + + Intent broadcastIntent = new Intent(); + broadcastIntent.setAction(MyWebReceiver.PROCESS_RESPONSE); + broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); + broadcastIntent.putExtra(RESPONSE_MESSAGE, responseMessage); + sendBroadcast(broadcastIntent); + + } + +}
\ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java new file mode 100644 index 000000000..9260ee186 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java @@ -0,0 +1,197 @@ +package eu.siacs.conversations.ui; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.DownloadManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.Uri; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.services.UpdaterWebService; + +public class UpdaterActivity extends Activity { + + private static final String LOG_TAG = Config.LOGTAG + "AppUpgrade"; + private MyWebReceiver receiver; + private int versionCode = 0; + String appURI = ""; + + private DownloadManager downloadManager; + private long downloadReference; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_updater); + + //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 + String version = pInfo.versionName; + //get the app version Code for checking + versionCode = pInfo.versionCode; + //display the current version in a TextView + TextView currentversionText = (TextView) findViewById(R.id.current_versionName); + currentversionText.setText(getText(R.string.current_version) + version); + + //Broadcast receiver for our Web Request + IntentFilter filter = new IntentFilter(MyWebReceiver.PROCESS_RESPONSE); + filter.addCategory(Intent.CATEGORY_DEFAULT); + receiver = new MyWebReceiver(); + registerReceiver(receiver, filter); + + //Broadcast receiver for the download manager + filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); + registerReceiver(downloadReceiver, filter); + + //check of internet is available before making a web service request + if(isNetworkAvailable(this)){ + Intent msgIntent = new Intent(this, UpdaterWebService.class); + msgIntent.putExtra(UpdaterWebService.REQUEST_STRING, Config.UPDATE_URL); + startService(msgIntent); + } + + } + + /*@Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.activity_main, menu); + return true; + } +*/ + @Override + public void onDestroy() { + //unregister your receivers + this.unregisterReceiver(receiver); + this.unregisterReceiver(downloadReceiver); + super.onDestroy(); + } + + //check for internet connection + private boolean isNetworkAvailable(Context context) { + ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null) { + NetworkInfo[] info = connectivity.getAllNetworkInfo(); + if (info != null) { + for (int i = 0; i < info.length; i++) { + Log.v(LOG_TAG, String.valueOf(i)); + if (info[i].getState() == NetworkInfo.State.CONNECTED) { + Log.v(LOG_TAG, "connected!"); + return true; + } + } + } + } + return false; + } + + //broadcast receiver to get notification when the web request finishes + public class MyWebReceiver extends BroadcastReceiver { + + public static final String PROCESS_RESPONSE = "eu.siacs.conversations.intent.action.PROCESS_RESPONSE"; + + @Override + public void onReceive(Context context, Intent intent) { + + String reponseMessage = intent.getStringExtra(UpdaterWebService.RESPONSE_MESSAGE); + Log.v(LOG_TAG, 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){ + //get the latest version from the JSON string + int latestVersionCode = responseObj.getInt("latestVersionCode"); + String latestVersion = responseObj.getString("latestVersion"); + //display the new version in a TextView + TextView versionText = (TextView) findViewById(R.id.versionName); + versionText.setText(getText(R.string.new_version) + latestVersion); + //get the lastest application URI from the JSON string + appURI = responseObj.getString("appURI"); + //check if we need to upgrade? + if(latestVersionCode > versionCode){ + //oh yeah we do need an upgrade, let the user know send an alert message + AlertDialog.Builder builder = new AlertDialog.Builder(UpdaterActivity.this); + builder.setMessage(R.string.update_available) + .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() { + //if the user agrees to upgrade + public void onClick(DialogInterface dialog, int id) { + //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,"MyAndroidApp.apk"); + downloadReference = downloadManager.enqueue(request); + } + }) + .setNegativeButton(R.string.remind_later, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + } + }); + //show the alert message + builder.create().show(); + } + + } + } catch (JSONException e) { + e.printStackTrace(); + } + + } + + } + + //broadcast receiver to get notification about ongoing downloads + private BroadcastReceiver downloadReceiver = new BroadcastReceiver() { + + @Override + 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){ + + Log.v(LOG_TAG, "Downloading of the new app version complete"); + //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 diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index aa5812b6a..3d4371129 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -330,6 +330,9 @@ public abstract class XmppActivity extends Activity { case R.id.action_settings: startActivity(new Intent(this, SettingsActivity.class)); break; + case R.id.action_check_updates: + startActivity(new Intent(this, UpdaterActivity.class)); + break; case R.id.action_accounts: startActivity(new Intent(this, ManageAccountActivity.class)); break; diff --git a/src/main/res/layout/activity_updater.xml b/src/main/res/layout/activity_updater.xml new file mode 100644 index 000000000..b8da14415 --- /dev/null +++ b/src/main/res/layout/activity_updater.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="eu.siacs.conversations.ui.UpdaterActivity"> + + <TextView android:id="@+id/current_versionName" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" android:layout_marginTop="16dp" + android:text="Current" android:textAppearance="?android:attr/textAppearanceMedium" + android:textStyle="bold" /> + + <TextView android:id="@+id/versionName" android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="New" android:textAppearance="?android:attr/textAppearanceMedium" + android:textStyle="bold" + android:layout_below="@+id/current_versionName" /> + +</RelativeLayout> diff --git a/src/main/res/menu/conversations.xml b/src/main/res/menu/conversations.xml index 866bb85f8..47214a6b7 100644 --- a/src/main/res/menu/conversations.xml +++ b/src/main/res/menu/conversations.xml @@ -67,5 +67,10 @@ android:orderInCategory="100" android:showAsAction="never" android:title="@string/action_settings"/> + <item + android:id="@+id/action_check_updates" + android:orderInCategory="100" + android:showAsAction="never" + android:title="@string/action_check_update"/> </menu>
\ No newline at end of file diff --git a/src/main/res/menu/menu_updater.xml b/src/main/res/menu/menu_updater.xml new file mode 100644 index 000000000..f52657372 --- /dev/null +++ b/src/main/res/menu/menu_updater.xml @@ -0,0 +1,7 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + tools:context="eu.siacs.conversations.ui.UpdaterActivity"> + <item android:id="@+id/action_settings" android:title="@string/action_settings" + android:orderInCategory="100" app:showAsAction="never" /> +</menu> diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index b6e345dfb..dd796042f 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -482,4 +482,12 @@ <string name="download_failed_could_not_connect">Download fehlgeschlagen: keine Verbindung zum Host</string> <string name="pref_use_white_background">Weißen Hintergrund benutzen</string> <string name="pref_use_white_background_summary">Empfangene Nachrichten als schwarzen Text auf weißem Hintergrund anzeigen</string> + <string name="account_status_dns_timeout">Zeitüberschreibung beim DNS</string> + <string name="action_check_update">Auf Updates prüfen</string> + <string name="current_version">Installierte Version:</string> + <string name="new_version">Neue Version: </string> + <string name="remind_later">später</string> + <string name="title_activity_updater">Update Dienst</string> + <string name="update">Aktualisieren</string> + <string name="update_available">Eine neuere Version von Conversations ist verfügbar. Jetzt aktualisieren?</string> </resources> diff --git a/src/main/res/values-w820dp/dimens.xml b/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 000000000..63fc81644 --- /dev/null +++ b/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ +<resources> + <!-- Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 5fe6bde54..8ca3cec86 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -515,4 +515,12 @@ <string name="pref_use_white_background">Use white background</string> <string name="pref_use_white_background_summary">Show received messages as black text on a white background</string> <string name="account_status_dns_timeout">Timeout in DNS</string> + + <string name="action_check_update">Check for Updates</string> + <string name="title_activity_updater">Update Service</string> + <string name="update_available">There is newer version of this application available. Upgrade now?</string> + <string name="remind_later">later</string> + <string name="update">Update</string> + <string name="new_version">New version:</string> + <string name="current_version">installed version:</string> </resources> |