prevent loading of WiDirService on older android

On 2.3 anyway there's a java.lang.VerifyError trying to load that
class. So wrap the loading in a new class that catches the error and
sets a boolean so subsequent calls don't need it. There are other calls
that could load the class, but they may not be reachable. To be tested.
This commit is contained in:
Eric House 2017-02-08 06:33:06 -08:00
parent afb0c1d3ee
commit b1f095b56e
6 changed files with 66 additions and 7 deletions

View file

@ -124,7 +124,7 @@ public class ConnViaViewLayout extends LinearLayout {
enabled = RelayService.relayEnabled( context );
break;
case COMMS_CONN_P2P:
enabled = WiDirService.enabled();
enabled = WiDirWrapper.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.enabled()
|| WiDirWrapper.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.enabled() ) {
if ( WiDirWrapper.enabled() ) {
items.add( getString( R.string.invite_choice_p2p ) );
means.add( DlgClickNotify.InviteMeans.WIFIDIRECT );
}

View file

@ -0,0 +1,58 @@
/* -*- compile-command: "find-and-gradle.sh installXw4Debug"; -*- */
/*
* Copyright 2017 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.app.Activity;
import android.content.Context;
// On older Android we can't load the class WiDirService. So do it with
// try/catch here
public class WiDirWrapper {
private static boolean s_working = false;
public static void init( Context context )
{
try {
WiDirService.init( context );
s_working = true;
} catch ( java.lang.VerifyError err ) {
}
}
public static boolean enabled()
{
return s_working && WiDirService.enabled();
}
public static void activityResumed( Activity activity )
{
if ( s_working ) {
WiDirService.activityResumed( activity );
}
}
public static void activityPaused( Activity activity )
{
if ( s_working ) {
WiDirService.activityPaused( activity );
}
}
}

View file

@ -74,7 +74,7 @@ public class XWActivity extends FragmentActivity implements Delegator {
}
m_dlgt.onPause();
super.onPause();
WiDirService.activityPaused( this );
WiDirWrapper.activityPaused( this );
}
@Override
@ -84,7 +84,7 @@ public class XWActivity extends FragmentActivity implements Delegator {
DbgUtils.logi( TAG, "onResume(this=%H)", this );
}
super.onResume();
WiDirService.activityResumed( this );
WiDirWrapper.activityResumed( this );
m_dlgt.onResume();
}

View file

@ -91,7 +91,7 @@ public class XWApp extends Application {
BTService.startService( this );
RelayService.startService( this );
GCMIntentService.init( this );
WiDirService.init( this );
WiDirWrapper.init( this );
}
// This is called on emulator only, but good for ensuring no memory leaks

View file

@ -27,6 +27,7 @@ import junit.framework.Assert;
import org.eehouse.android.xw4.BTService;
import org.eehouse.android.xw4.WiDirService;
import org.eehouse.android.xw4.WiDirWrapper;
import org.eehouse.android.xw4.DbgUtils;
import org.eehouse.android.xw4.GameUtils;
import org.eehouse.android.xw4.R;
@ -123,7 +124,7 @@ public class CommsAddrRec {
if ( Utils.isGSMPhone( context ) ) {
supported.add( CommsConnType.COMMS_CONN_SMS );
}
if ( WiDirService.enabled() ) {
if ( WiDirWrapper.enabled() ) {
supported.add( CommsConnType.COMMS_CONN_P2P );
}
return supported;