Merge remote-tracking branch 'origin/android_translate' into android_translate

This commit is contained in:
Weblate 2017-02-19 06:39:12 +01:00
commit 380ae5bf1f
18 changed files with 138 additions and 37 deletions

View file

@ -36,7 +36,6 @@ android {
// FIX ME
variant.buildConfigField "String", "STRINGS_HASH", "\"00000\""
variant.buildConfigField "boolean", "WIDIR_ENABLED", "false"
def senderID = System.getenv("GCM_SENDER_ID")
variant.buildConfigField "String", "GCM_SENDER_ID", "\"$senderID\""
@ -53,6 +52,7 @@ android {
resValue "string", "app_name", "CrossWords"
resValue "string", "nbs_port", "3344"
resValue "string", "invite_prefix", "/and/"
buildConfigField "boolean", "WIDIR_ENABLED", "false"
}
xw4dbg {
dimension "variant"
@ -61,6 +61,7 @@ android {
resValue "string", "app_name", "CrossDbg"
resValue "string", "nbs_port", "3345"
resValue "string", "invite_prefix", "/anddbg/"
buildConfigField "boolean", "WIDIR_ENABLED", "true"
}
// WARNING: "all" breaks things. Seems to be a keyword. Need
@ -94,6 +95,16 @@ android {
storePassword "notReal"
keyPassword "notReal"
}
debug {
def path = System.getenv("DEBUG_KEYSTORE_PATH")
if (! path) {
path = "./debug.keystore"
}
storeFile file(path)
keyAlias "androiddebugkey"
storePassword "android"
keyPassword "android"
}
}
buildTypes {

View file

@ -124,7 +124,7 @@ public class ConnViaViewLayout extends LinearLayout {
enabled = RelayService.relayEnabled( context );
break;
case COMMS_CONN_P2P:
enabled = WiDirService.supported();
enabled = WiDirService.enabled();
break;
default:
Assert.fail();

View file

@ -510,7 +510,7 @@ public class DlgDelegate {
if ( (XWApp.SMS_INVITE_ENABLED && Utils.deviceSupportsSMS( m_activity ))
|| XWPrefs.getNFCToSelfEnabled( m_activity )
|| NFCUtils.nfcAvail( m_activity )[0]
|| WiDirService.supported()
|| WiDirService.enabled()
|| BTService.BTAvailable() ) {
DlgState state = new DlgState( DlgID.INVITE_CHOICES_THEN )
.setAction( action )
@ -755,7 +755,7 @@ public class DlgDelegate {
items.add( getString( R.string.invite_choice_relay ) );
means.add( DlgClickNotify.InviteMeans.RELAY );
}
if ( WiDirService.supported() ) {
if ( WiDirService.enabled() ) {
items.add( getString( R.string.invite_choice_p2p ) );
means.add( DlgClickNotify.InviteMeans.WIFIDIRECT );
}

View file

@ -350,5 +350,9 @@ public class PrefsDelegate extends DelegateBase
if ( Perms23.haveNativePerms() ) {
hideOne( R.string.key_enable_sms, R.string.key_network_behavior );
}
if ( ! BuildConfig.WIDIR_ENABLED ) {
hideOne( R.string.key_enable_p2p, R.string.key_network_behavior );
}
}
}

View file

@ -45,6 +45,7 @@ import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest;
import android.net.wifi.p2p.nsd.WifiP2pUpnpServiceInfo;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import java.io.IOException;
import java.net.InetAddress;
@ -77,6 +78,7 @@ public class WiDirService extends XWService {
private static final String SERVICE_NAME = "srvc_" + BuildConfig.FLAVOR;
private static final String SERVICE_REG_TYPE = "_presence._tcp";
private static final int OWNER_PORT = 5432;
private static final String PEERS_LIST_KEY = TAG + ".peers_key";
private enum P2PAction { _NONE,
GOT_MSG,
@ -96,6 +98,7 @@ public class WiDirService extends XWService {
private static final String KEY_MAP = "map";
private static final String KEY_RETADDR = "raddr";
private static boolean s_enabled = false;
private static Channel sChannel;
private static ServiceDiscoverer s_discoverer;
private static IntentFilter sIntentFilter;
@ -119,6 +122,7 @@ public class WiDirService extends XWService {
private static String sDeviceName;
private static Set<DevSetListener> s_devListeners
= new HashSet<DevSetListener>();
private static Set<String> s_peersSet;
private P2pMsgSink m_sink;
@ -137,7 +141,7 @@ public class WiDirService extends XWService {
{
int result;
if ( BuildConfig.WIDIR_ENABLED && null != intent ) {
if ( enabled() && null != intent ) {
result = Service.START_STICKY;
int ordinal = intent.getIntExtra( KEY_CMD, -1 );
@ -181,6 +185,20 @@ public class WiDirService extends XWService {
public static void init( Context context )
{
DbgUtils.logd( TAG, "init()" );
s_enabled = XWPrefs.getPrefsBoolean( context, R.string.key_enable_p2p,
false );
Assert.assertNull( s_peersSet );
s_peersSet = new HashSet<String>();
String peers = DBUtils.getStringFor( context, PEERS_LIST_KEY, null );
if ( null != peers ) {
String[] macs = TextUtils.split( peers, "," );
for ( String mac : macs ) {
s_peersSet.add( mac );
}
}
DbgUtils.logd( TAG, "loaded saved peers: %s", s_peersSet.toString() );
try {
ChannelListener listener = new ChannelListener() {
@Override
@ -190,7 +208,7 @@ public class WiDirService extends XWService {
};
sChannel = getMgr().initialize( context, Looper.getMainLooper(),
listener );
s_discoverer = new ServiceDiscoverer( sChannel );
s_discoverer = new ServiceDiscoverer();
sHavePermission = true;
} catch ( NoClassDefFoundError ndf ) { // old os version
sHavePermission = false;
@ -202,22 +220,28 @@ public class WiDirService extends XWService {
public static void reset( Context context )
{
// Put experimental stuff here that might help get a connection
if ( null != s_discoverer ) {
s_discoverer.restart();
}
}
public static boolean supported()
public static boolean enabled()
{
return BuildConfig.WIDIR_ENABLED;
boolean result = BuildConfig.WIDIR_ENABLED && s_enabled;
return result;
}
public static boolean connecting() {
return supported()
public static boolean connecting()
{
return enabled()
&& 0 < sSocketWrapMap.size()
&& sSocketWrapMap.values().iterator().next().isConnected();
}
public static String getMyMacAddress( Context context )
{
if ( BuildConfig.WIDIR_ENABLED ) {
if ( enabled() ) {
if ( null == sMacAddress && null != context ) {
sMacAddress = DBUtils.getStringFor( context, MAC_ADDR_KEY, null );
}
@ -230,10 +254,16 @@ public class WiDirService extends XWService {
public static String formatNetStateInfo()
{
String connectState = "";
if ( null != s_discoverer ) {
connectState = s_discoverer.stateToString();
}
String map = mapToString( copyUserMap() );
return String.format( "role: %s; map: %s nThreads: %d",
sAmGroupOwner ? "owner" : "guest", map,
Thread.activeCount() );
connectState += String.format( "; role: %s; map: %s nThreads: %d",
sAmGroupOwner ? "owner" : "guest", map,
Thread.activeCount() );
return connectState;
}
private static String getMyMacAddress() { return getMyMacAddress(null); }
@ -306,7 +336,7 @@ public class WiDirService extends XWService {
public static void activityResumed( Activity activity )
{
if ( BuildConfig.WIDIR_ENABLED && sHavePermission ) {
if ( enabled() && sHavePermission ) {
if ( initListeners( activity ) ) {
activity.registerReceiver( sReceiver, sIntentFilter );
DbgUtils.logd( TAG, "activityResumed() done" );
@ -317,7 +347,7 @@ public class WiDirService extends XWService {
public static void activityPaused( Activity activity )
{
if ( BuildConfig.WIDIR_ENABLED && sHavePermission ) {
if ( enabled() && sHavePermission ) {
Assert.assertNotNull( sReceiver );
// No idea why I'm seeing this exception...
try {
@ -346,7 +376,7 @@ public class WiDirService extends XWService {
private static boolean initListeners( final Context context )
{
boolean succeeded = false;
if ( BuildConfig.WIDIR_ENABLED ) {
if ( enabled() ) {
if ( null == sIface ) {
try {
WifiP2pManager mgr = getMgr();
@ -447,10 +477,13 @@ public class WiDirService extends XWService {
// See: http://stackoverflow.com/questions/26300889/wifi-p2p-service-discovery-works-intermittently
private static class ServiceDiscoverer implements Runnable, ActionListener {
private State m_curState = State.START;
private State m_lastGoodState = State.START;
private State m_lastBadState = State.START;
private Channel m_channel;
private Handler m_handler;
private WifiP2pManager m_mgr;
private int[] m_failures;
private boolean m_lastSucceeded;
enum State {
START,
@ -463,13 +496,21 @@ public class WiDirService extends XWService {
DONE,
}
public ServiceDiscoverer( Channel channel )
public ServiceDiscoverer()
{
m_mgr = getMgr();
m_channel = sChannel;
m_handler = new Handler();
}
public String stateToString()
{
return String.format("last good: %s(%d); last bad: %s(%d); success last: %b",
m_lastGoodState.toString(), m_lastGoodState.ordinal(),
m_lastBadState.toString(), m_lastBadState.ordinal(),
m_lastSucceeded );
}
public void restart()
{
m_curState = State.START;
@ -487,6 +528,8 @@ public class WiDirService extends XWService {
// ActionListener interface
@Override
public void onSuccess() {
m_lastSucceeded = true;
m_lastGoodState = m_curState;
DbgUtils.logd( TAG, "onSuccess(): state %s done",
m_curState.toString() );
m_curState = State.values()[m_curState.ordinal() + 1];
@ -495,6 +538,9 @@ public class WiDirService extends XWService {
@Override
public void onFailure( int code ) {
m_lastSucceeded = false;
m_lastBadState = m_curState;
int count = ++m_failures[m_curState.ordinal()];
String codeStr = null;
switch ( code ) {
@ -568,8 +614,10 @@ public class WiDirService extends XWService {
break;
case DONE:
m_curState = State.START;
schedule( /*5 * */ 60 );
DbgUtils.logd( TAG, "machine done; should I try connecting to: %s?",
s_peersSet.toString() );
// m_curState = State.START;
// schedule( /*5 * */ 60 );
break;
default:
@ -594,7 +642,7 @@ public class WiDirService extends XWService {
private static void setDiscoveryListeners( WifiP2pManager mgr )
{
if ( BuildConfig.WIDIR_ENABLED ) {
if ( enabled() ) {
DnsSdServiceResponseListener srl = new DnsSdServiceResponseListener() {
@Override
public void onDnsSdServiceAvailable(String instanceName,
@ -922,9 +970,12 @@ public class WiDirService extends XWService {
boolean forwarded = false;
String destAddr = packet.getString( KEY_DEST );
if ( null != destAddr && 0 < destAddr.length() ) {
Assert.assertFalse( destAddr.equals( sMacAddress ) );
forwardPacket( bytes, destAddr );
forwarded = true;
forwarded = destAddr.equals( sMacAddress );
if ( forwarded ) {
forwardPacket( bytes, destAddr );
} else {
DbgUtils.logd( TAG, "addr mismatch: %s vs %s", destAddr, sMacAddress );
}
}
return forwarded;
}
@ -1011,6 +1062,22 @@ public class WiDirService extends XWService {
return wrap;
}
private static void updatePeersList( WifiP2pDeviceList peerList )
{
Set<String> newSet = new HashSet<String>();
for ( WifiP2pDevice device : peerList.getDeviceList() ) {
String macAddress = device.deviceAddress;
newSet.add( macAddress );
}
DbgUtils.logd( TAG, "updatePeersList(): old set: %s; new set: %s",
s_peersSet.toString(), newSet.toString() );
s_peersSet = newSet;
DBUtils.setStringFor( XWApp.getContext(), PEERS_LIST_KEY,
TextUtils.join( ",", s_peersSet ) );
}
private static class WFDBroadcastReceiver extends BroadcastReceiver
implements WifiP2pManager.ConnectionInfoListener,
WifiP2pManager.PeerListListener {
@ -1025,7 +1092,7 @@ public class WiDirService extends XWService {
@Override
public void onReceive( Context context, Intent intent ) {
if ( BuildConfig.WIDIR_ENABLED ) {
if ( enabled() ) {
String action = intent.getAction();
DbgUtils.logd( TAG, "got intent: " + intent.toString() );
@ -1115,6 +1182,8 @@ public class WiDirService extends XWService {
DbgUtils.logd( TAG, "got list of %d peers",
peerList.getDeviceList().size() );
updatePeersList( peerList );
for ( WifiP2pDevice device : peerList.getDeviceList() ) {
// DbgUtils.logd( TAG, "not connecting to: %s", device.toString() );
tryConnect( device );

View file

@ -123,7 +123,7 @@ public class CommsAddrRec {
if ( Utils.isGSMPhone( context ) ) {
supported.add( CommsConnType.COMMS_CONN_SMS );
}
if ( WiDirService.supported() ) {
if ( WiDirService.enabled() ) {
supported.add( CommsConnType.COMMS_CONN_P2P );
}
return supported;

View file

@ -60,6 +60,7 @@
<string name="key_disable_relay">key_disable_relay</string>
<string name="key_notify_vibrate">key_notify_vibrate</string>
<string name="key_enable_sms">key_enable_sms</string>
<string name="key_enable_p2p">key_enable_p2p</string>
<string name="key_network_behavior">key_network_behavior</string>
<string name="key_keep_screenon">key_keep_screenon</string>
<string name="key_thumbsize">key_thumbsize3</string>

View file

@ -2081,6 +2081,9 @@
<!-- -->
<string name="enable_sms_summary">Only if you have unlimited texting!</string>
<string name="title_enable_p2p">Enable WiFi Direct</string>
<string name="summary_enable_p2p">Experimental, uses lots of battery</string>
<!-- -->
<string name="confirm_sms_title">Confirm your SMS plan</string>
<!-- -->

View file

@ -325,6 +325,11 @@
android:summary="@string/notify_other_summary"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_enable_p2p"
android:title="@string/title_enable_p2p"
android:summary="@string/summary_enable_p2p"
android:defaultValue="false"
/>
<PreferenceScreen android:title="@string/network_advanced_title"
android:summary="@string/network_advanced_summary"

View file

@ -20,6 +20,7 @@
#include "xportwrapper.h"
#include "andutils.h"
#include "dbgutil.h"
#include "paths.h"
typedef struct _AndTransportProcs {
@ -145,7 +146,7 @@ and_xport_sendNoConn( const XP_U8* buf, XP_U16 len, const XP_UCHAR* msgNo,
jbytes, jMsgNo, jRelayID );
deleteLocalRefs( env, jbytes, jRelayID, jMsgNo, DELETE_NO_REF );
}
LOG_RETURNF( "%d", result );
LOG_RETURNF( "%s", boolToStr(result) );
return result;
}

View file

@ -1,4 +1,4 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/* -*- compile-command: "find-and-gradle.sh installXw4Debug"; -*- */
/*
* Copyright © 2009 - 2014 by Eric House (xwords@eehouse.org). All rights
* reserved.
@ -29,6 +29,7 @@
#include "board.h"
#include "mempool.h"
#include "strutils.h"
#include "dbgutil.h"
#include "dictnry.h"
#include "dictiter.h"
#include "dictmgr.h"
@ -1507,7 +1508,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1initClientConnection
stream_setOnCloseProc( stream, and_send_on_close );
result = server_initClientConnection( state->game.server, stream );
XWJNI_END();
LOG_RETURNF( "%d", result );
LOG_RETURNF( "%s", boolToStr(result) );
return result;
}

View file

@ -30,6 +30,7 @@
#include "memstream.h"
#include "xwrelay.h"
#include "strutils.h"
#include "dbgutil.h"
#define HEARTBEAT_NONE 0
@ -1812,7 +1813,7 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
XP_LOGF( "%s: dropping relay msg with cmd %d", __func__, (XP_U16)cmd );
}
LOG_RETURNF( "%d", consumed );
LOG_RETURNF( "%s", boolToStr(consumed) );
return consumed;
} /* relayPreProcess */
#endif
@ -1893,7 +1894,7 @@ preProcess( CommsCtxt* comms, const CommsAddrRec* useAddr,
XP_ASSERT(0);
break;
}
LOG_RETURNF( "%d", consumed );
LOG_RETURNF( "%s", boolToStr(consumed) );
return consumed;
} /* preProcess */
@ -1981,6 +1982,7 @@ getRecordFor( CommsCtxt* comms, const CommsAddrRec* addr,
static XP_Bool
checkChannelNo( CommsCtxt* comms, XP_PlayerAddr* channelNoP )
{
XP_Bool success = XP_TRUE;
XP_PlayerAddr channelNo = *channelNoP;
if ( 0 == (channelNo & CHANNEL_MASK) ) {
channelNo |= ++comms->nextChannelNo;
@ -1990,7 +1992,8 @@ checkChannelNo( CommsCtxt* comms, XP_PlayerAddr* channelNoP )
comms->nextChannelNo = channelNo;
}
*channelNoP = channelNo;
return XP_TRUE; /* for now */
LOG_RETURNF( "%s", boolToStr(success) );
return success;
}
/* An initial message comes only from a client to a server, and from the

View file

@ -37,6 +37,7 @@ void dbg_logstream( const XWStreamCtxt* stream, const char* func, int line );
# define XP_LOGSTREAM( s )
# endif
#define boolToStr(b) ((b)?"true" : "false")
# ifdef DEBUG
# define DIRTY_SLOT XP_Bool _isDirty;

View file

@ -23,6 +23,7 @@
#include "nli.h"
#include "comms.h"
#include "strutils.h"
#include "dbgutil.h"
void
nli_init( NetLaunchInfo* nli, const CurGameInfo* gi, const CommsAddrRec* addr,
@ -135,7 +136,7 @@ nli_makeFromStream( NetLaunchInfo* nli, XWStreamCtxt* stream )
nli->osVers = stream_getU32( stream );
}
}
LOG_RETURNF( "%d", success );
LOG_RETURNF( "%s", boolToStr(success) );
return success;
}

View file

@ -55,6 +55,7 @@
#include "game.h"
#include "movestak.h"
#include "strutils.h"
#include "dbgutil.h"
#include "gtkask.h"
#include "gtkinvit.h"
#include "gtkaskm.h"
@ -2819,7 +2820,7 @@ makeNewGame( GtkGameGlobals* globals )
gi->dictName, XP_TRUE );
gi->dictLang = dict_getLangCode( cGlobals->dict );
}
LOG_RETURNF( "%d", success );
LOG_RETURNF( "%s", boolToStr(success) );
return success;
}

View file

@ -68,6 +68,7 @@
#include "model.h"
#include "util.h"
#include "strutils.h"
#include "dbgutil.h"
#include "dictiter.h"
/* #include "commgr.h" */
/* #include "compipe.h" */
@ -1052,7 +1053,7 @@ send_or_close( CommonGlobals* cGlobals, const XP_U8* buf, size_t len )
g_slist_free( cGlobals->packetQueue );
cGlobals->packetQueue = NULL;
}
LOG_RETURNF( "%d", success );
LOG_RETURNF( "%s", boolToStr(success) );
return success;
}
@ -2664,4 +2665,3 @@ main( int argc, char** argv )
XP_LOGF( "%s exiting main, returning %d", argv[0], result );
return result;
} /* main */

View file

@ -195,7 +195,7 @@ remembered( const LinUDPStuff* stuff, int sock )
known = XP_TRUE;
}
}
LOG_RETURNF( "%d", (int)known );
LOG_RETURNF( "%s", boolToStr(known) );
return known;
}