From 687400f91a633cecfc88d3569160554209faf386 Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Mon, 19 Sep 2011 21:42:57 -0700 Subject: [PATCH] use kalsms version code in http requests --- src/org/envaya/kalsms/App.java | 24 ++++++++++++++++++++++-- src/org/envaya/kalsms/task/HttpTask.java | 2 +- src/org/envaya/kalsms/ui/Help.java | 19 +++++-------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/org/envaya/kalsms/App.java b/src/org/envaya/kalsms/App.java index 4a2cb67..6f9057d 100755 --- a/src/org/envaya/kalsms/App.java +++ b/src/org/envaya/kalsms/App.java @@ -8,6 +8,8 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; @@ -23,7 +25,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.http.client.HttpClient; -import org.apache.http.conn.params.ConnManagerParams; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; @@ -96,6 +97,8 @@ public final class App extends Application { private SpannableStringBuilder displayedLog = new SpannableStringBuilder(); private long lastLogTime; + private PackageInfo packageInfo; + // list of package names (e.g. org.envaya.kalsms, or org.envaya.kalsms.packXX) // for this package and all expansion packs private List outgoingMessagePackages = new ArrayList(); @@ -119,6 +122,17 @@ public final class App extends Application { outgoingMessagePackages.add(getPackageName()); + try + { + packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); + } + catch (NameNotFoundException ex) + { + // should not happen + logError("Error finding package info", ex); + return; + } + updateExpansionPacks(); log(Html.fromHtml( @@ -136,7 +150,7 @@ public final class App extends Application { { log(" " + sender); } - } + } mmsObserver = new MmsObserver(this); mmsObserver.register(); @@ -150,6 +164,12 @@ public final class App extends Application { startService(new Intent(this, ForegroundService.class)); } + public PackageInfo getPackageInfo() + { + return packageInfo; + } + + public synchronized String chooseOutgoingSmsPackage() { outgoingMessageCount++; diff --git a/src/org/envaya/kalsms/task/HttpTask.java b/src/org/envaya/kalsms/task/HttpTask.java index e202c23..c0207e6 100755 --- a/src/org/envaya/kalsms/task/HttpTask.java +++ b/src/org/envaya/kalsms/task/HttpTask.java @@ -53,7 +53,7 @@ public class HttpTask extends AsyncTask { this.app = app; this.url = app.getServerUrl(); params = new ArrayList(Arrays.asList(paramsArr)); - params.add(new BasicNameValuePair("version", "2")); + params.add(new BasicNameValuePair("version", "" + app.getPackageInfo().versionCode)); params.add(new BasicNameValuePair("phone_number", app.getPhoneNumber())); } diff --git a/src/org/envaya/kalsms/ui/Help.java b/src/org/envaya/kalsms/ui/Help.java index f6db7e5..af758e2 100755 --- a/src/org/envaya/kalsms/ui/Help.java +++ b/src/org/envaya/kalsms/ui/Help.java @@ -1,10 +1,10 @@ package org.envaya.kalsms.ui; import android.app.Activity; -import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; import android.text.Html; import android.widget.TextView; +import org.envaya.kalsms.App; import org.envaya.kalsms.R; public class Help extends Activity { @@ -16,19 +16,10 @@ public class Help extends Activity { setContentView(R.layout.help); TextView help = (TextView) this.findViewById(R.id.help); - - String version; - - try - { - version = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; - } - catch (NameNotFoundException ex) - { - version = "(Unknown version)"; - } - - String html = "KalSMS " + version + "

" + + App app = (App)getApplication(); + + String html = "KalSMS " + app.getPackageInfo().versionName + "

" + "KalSMS is a SMS gateway.

" + "It forwards all incoming SMS messages received by this phone to a server on the internet, " + "and also sends outgoing SMS messages from that server to other phones.

"