if fake-radio pref has changed to make something (SMS) unsupported,

try to recover from that (otherwise impossible) change in phone
capability by checking when fetching pref if it's all still possible.
This commit is contained in:
Eric House 2015-02-17 06:52:00 -08:00
parent 4d9465a3e2
commit d97dd6aff1
3 changed files with 40 additions and 18 deletions

View file

@ -34,7 +34,6 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.loc.LocUtils;
public class ConnViaViewLayout extends LinearLayout {
private static CommsConnTypeSet s_supported;
private CommsConnTypeSet m_curSet;
public interface CheckEnabledWarner {
@ -56,6 +55,7 @@ public class ConnViaViewLayout extends LinearLayout {
SetEmptyWarner sew )
{
m_curSet = (CommsConnTypeSet)types.clone();
addConnections();
m_disabledWarner = cew;
@ -73,7 +73,7 @@ public class ConnViaViewLayout extends LinearLayout {
list.removeAllViews(); // in case being reused
Context context = getContext();
CommsConnTypeSet supported = getSupported( context );
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
for ( CommsConnType typ : supported.getTypes() ) {
LinearLayout item = (LinearLayout)
@ -117,20 +117,4 @@ public class ConnViaViewLayout extends LinearLayout {
m_disabledWarner.warnDisabled( typ );
}
}
private static CommsConnTypeSet getSupported( Context context )
{
if ( null == s_supported ) {
CommsConnTypeSet supported = new CommsConnTypeSet();
supported.add( CommsConnType.COMMS_CONN_RELAY );
if ( BTService.BTAvailable() ) {
supported.add( CommsConnType.COMMS_CONN_BT );
}
if ( Utils.isGSMPhone( context ) ) {
supported.add( CommsConnType.COMMS_CONN_SMS );
}
s_supported = supported;
}
return s_supported;
}
}

View file

@ -481,6 +481,14 @@ public class XWPrefs {
} else {
result = DBUtils.intToConnTypeSet( flags );
}
// Save it if changed
int siz = result.size();
CommsConnTypeSet.removeUnsupported( context, result );
if ( result.size() != siz ) {
setAddrTypes( context, result );
}
return result;
}

View file

@ -64,6 +64,36 @@ public class CommsAddrRec {
};
public static class CommsConnTypeSet extends HashSet<CommsConnType> {
private static CommsConnTypeSet s_supported;
public static CommsConnTypeSet getSupported( Context context )
{
if ( null == s_supported ) {
CommsConnTypeSet supported = new CommsConnTypeSet();
supported.add( CommsConnType.COMMS_CONN_RELAY );
if ( BTService.BTAvailable() ) {
supported.add( CommsConnType.COMMS_CONN_BT );
}
if ( Utils.isGSMPhone( context ) ) {
supported.add( CommsConnType.COMMS_CONN_SMS );
}
s_supported = supported;
}
return s_supported;
}
public static void removeUnsupported( Context context,
CommsConnTypeSet set )
{
// Remove anything no longer supported. This probably only
// happens when key_force_radio is being messed with
CommsConnTypeSet supported = getSupported( context );
for ( CommsConnType typ : set.getTypes() ) {
if ( ! supported.contains( typ ) ) {
set.remove( typ );
}
}
}
// Called from jni world, where making and using an iterator is too
// much trouble.