mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-17 18:12:01 +01:00
run update checks off a timer that adds a random element to its
interval; move update check URL into a debug pref.
This commit is contained in:
parent
6bdec885b1
commit
5584a66043
6 changed files with 63 additions and 4 deletions
|
@ -94,6 +94,12 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name="UpdateCheckReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name="DispatchNotify"
|
||||
>
|
||||
<intent-filter>
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
<string name="key_relay_host">key_relay_host</string>
|
||||
<string name="key_redir_host">key_redir_host</string>
|
||||
<string name="key_relay_port">key_relay_port2</string>
|
||||
<string name="key_update_url">key_update_url</string>
|
||||
<string name="key_proxy_port">key_proxy_port</string>
|
||||
<string name="key_sms_port">key_sms_port</string>
|
||||
<string name="key_dict_host">key_dict_host3</string>
|
||||
|
@ -97,6 +98,8 @@
|
|||
<!-- <string name="default_host">10.0.2.2</string> -->
|
||||
<string name="dict_url">http://eehouse.org/and_wordlists</string>
|
||||
<string name="game_url_pathf">//%1$s/newgame.php</string>
|
||||
<string name="expl_update_url">Update checks URL</string>
|
||||
<string name="default_update_url">http://eehouse.org/xw4/info.py</string>
|
||||
|
||||
<!-- Debugging stuff. No point in localizing it. -->
|
||||
<string name="advanced">For debugging</string>
|
||||
|
|
|
@ -316,5 +316,13 @@
|
|||
android:title="@string/dict_host"
|
||||
android:defaultValue="@string/dict_url"
|
||||
/>
|
||||
|
||||
<org.eehouse.android.xw4.XWEditTextPreference
|
||||
android:key="@string/key_update_url"
|
||||
android:title="@string/expl_update_url"
|
||||
android:defaultValue="@string/default_update_url"
|
||||
/>
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -20,12 +20,15 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.SystemClock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -45,10 +48,40 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
|
||||
public static final String NEW_DICT_URL = "NEW_DICT_URL";
|
||||
public static final String NEW_DICT_LOC = "NEW_DICT_LOC";
|
||||
|
||||
// every hourish for now; later should be more like weekly
|
||||
private static final long INTERVAL_MILLIS = 1000 * 60 * 60;
|
||||
|
||||
@Override
|
||||
public void onReceive( Context context, Intent intent )
|
||||
{
|
||||
DbgUtils.logf( "UpdateCheckReceiver.onReceive()" );
|
||||
if ( null != intent && null != intent.getAction()
|
||||
&& intent.getAction().equals( Intent.ACTION_BOOT_COMPLETED ) ) {
|
||||
restartTimer( context );
|
||||
} else {
|
||||
checkVersions( context );
|
||||
restartTimer( context );
|
||||
}
|
||||
}
|
||||
|
||||
public static void restartTimer( Context context )
|
||||
{
|
||||
AlarmManager am =
|
||||
(AlarmManager)context.getSystemService( Context.ALARM_SERVICE );
|
||||
|
||||
Intent intent = new Intent( context, UpdateCheckReceiver.class );
|
||||
PendingIntent pi = PendingIntent.getBroadcast( context, 0, intent, 0 );
|
||||
am.cancel( pi );
|
||||
|
||||
long interval_millis = (INTERVAL_MILLIS / 2)
|
||||
+ Math.abs(Utils.nextRandomInt() % INTERVAL_MILLIS);
|
||||
DbgUtils.logf( "restartTimer: using interval %d (from %d)", interval_millis,
|
||||
INTERVAL_MILLIS );
|
||||
long first_millis = SystemClock.elapsedRealtime() + interval_millis;
|
||||
am.setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||
first_millis, // first firing
|
||||
interval_millis, pi );
|
||||
}
|
||||
|
||||
public static void checkVersions( Context context )
|
||||
|
@ -63,7 +96,7 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
try {
|
||||
int versionCode = pm.getPackageInfo( packageName, 0 ).versionCode;
|
||||
|
||||
HttpPost post = makePost( "curVersion" );
|
||||
HttpPost post = makePost( context, "curVersion" );
|
||||
|
||||
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
|
||||
nvp.add(new BasicNameValuePair( "name", packageName ) );
|
||||
|
@ -127,9 +160,12 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static HttpPost makePost( String proc )
|
||||
private static HttpPost makePost( Context context, String proc )
|
||||
{
|
||||
return new HttpPost("http://www.eehouse.org/xw4/info.py/" + proc);
|
||||
String url = String.format( "%s/%s",
|
||||
XWPrefs.getDefaultUpdateUrl( context ),
|
||||
proc );
|
||||
return new HttpPost( url );
|
||||
}
|
||||
|
||||
private static String runPost( HttpPost post, List<NameValuePair> nvp )
|
||||
|
@ -162,7 +198,7 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
{
|
||||
int lang = DictLangCache.getDictLangCode( context, dal );
|
||||
String langStr = DictLangCache.getLangName( context, lang );
|
||||
HttpPost post = makePost( "dictVersion" );
|
||||
HttpPost post = makePost( context, "dictVersion" );
|
||||
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
|
||||
nvp.add( new BasicNameValuePair( "name", dal.name ) );
|
||||
nvp.add( new BasicNameValuePair( "lang", langStr ) );
|
||||
|
|
|
@ -51,6 +51,7 @@ public class XWApp extends Application {
|
|||
ConnStatusHandler.loadState( this );
|
||||
|
||||
RelayReceiver.RestartTimer( this );
|
||||
UpdateCheckReceiver.restartTimer( this );
|
||||
BTService.startService( this );
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,11 @@ public class XWPrefs {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String getDefaultUpdateUrl( Context context )
|
||||
{
|
||||
return getPrefsString( context, R.string.key_update_url );
|
||||
}
|
||||
|
||||
public static int getDefaultProxyPort( Context context )
|
||||
{
|
||||
String val = getPrefsString( context, R.string.key_proxy_port );
|
||||
|
|
Loading…
Reference in a new issue