mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
fix crash (by inspection) with complete parcel save
I wasn't saving/restoring params[] Object array with DlgState, and under circumstances I can't reproduce that could cause a null object dereference I was via the Play store. So added a test case that failed for DlgState instances that have non-null params arrays, and fixed that.
This commit is contained in:
parent
ca93f808f3
commit
e2c46963d8
3 changed files with 77 additions and 3 deletions
|
@ -23,11 +23,18 @@ package org.eehouse.android.xw4;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
|
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
public class DlgState implements Parcelable {
|
public class DlgState implements Parcelable {
|
||||||
|
private static final String TAG = DlgState.class.getSimpleName();
|
||||||
private static final String BUNDLE_KEY = "bk";
|
private static final String BUNDLE_KEY = "bk";
|
||||||
|
|
||||||
public DlgID m_id;
|
public DlgID m_id;
|
||||||
|
@ -66,12 +73,57 @@ public class DlgState implements Parcelable {
|
||||||
public DlgState setTitle( int id )
|
public DlgState setTitle( int id )
|
||||||
{ m_titleId = id; return this; }
|
{ m_titleId = id; return this; }
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public String toString()
|
||||||
|
// {
|
||||||
|
// String params = "";
|
||||||
|
// if ( null != m_params ) {
|
||||||
|
// List<String> strs = new ArrayList<>();
|
||||||
|
// for (Object obj : m_params) {
|
||||||
|
// strs.add(String.format("%s", obj));
|
||||||
|
// }
|
||||||
|
// params = TextUtils.join( ",", strs );
|
||||||
|
// }
|
||||||
|
// return String.format("[msg: %s; key: %s; action: %s; pair %s: na: %s; pos: %d; neg: %d; title: %d; params: %s]",
|
||||||
|
// m_msg, m_prefsKey, m_action, m_pair, m_onNAChecked,
|
||||||
|
// m_posButton, m_negButton, m_titleId, params );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// I only need this if BuildConfig.DEBUG is true...
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object it)
|
||||||
|
{
|
||||||
|
boolean result;
|
||||||
|
if ( BuildConfig.DEBUG ) {
|
||||||
|
result = it != null && it instanceof DlgState;
|
||||||
|
if ( result ) {
|
||||||
|
DlgState other = (DlgState)it;
|
||||||
|
result = other != null
|
||||||
|
&& m_id.equals(other.m_id)
|
||||||
|
&& m_msg.equals(other.m_msg)
|
||||||
|
&& m_posButton == other.m_posButton
|
||||||
|
&& m_negButton == other.m_negButton
|
||||||
|
&& m_action == other.m_action
|
||||||
|
&& ((null == m_pair) ? (null == other.m_pair) : m_pair.equals(other.m_pair))
|
||||||
|
&& m_prefsKey == other.m_prefsKey
|
||||||
|
&& Arrays.deepEquals( m_params, other.m_params )
|
||||||
|
&& m_onNAChecked == other.m_onNAChecked
|
||||||
|
&& m_titleId == other.m_titleId;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = super.equals( it );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundle toBundle()
|
public Bundle toBundle()
|
||||||
{
|
{
|
||||||
|
testCanParcelize();
|
||||||
|
|
||||||
Bundle result = new Bundle();
|
Bundle result = new Bundle();
|
||||||
result.putParcelable( BUNDLE_KEY, this );
|
result.putParcelable( BUNDLE_KEY, this );
|
||||||
return result;
|
return result;
|
||||||
|
@ -82,7 +134,8 @@ public class DlgState implements Parcelable {
|
||||||
return (DlgState)bundle.getParcelable( BUNDLE_KEY );
|
return (DlgState)bundle.getParcelable( BUNDLE_KEY );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToParcel( Parcel out, int flags ) {
|
public void writeToParcel( Parcel out, int flags )
|
||||||
|
{
|
||||||
out.writeInt( m_id.ordinal() );
|
out.writeInt( m_id.ordinal() );
|
||||||
out.writeInt( m_posButton );
|
out.writeInt( m_posButton );
|
||||||
out.writeInt( m_negButton );
|
out.writeInt( m_negButton );
|
||||||
|
@ -91,6 +144,21 @@ public class DlgState implements Parcelable {
|
||||||
out.writeInt( null == m_onNAChecked ? -1 : m_onNAChecked.ordinal() );
|
out.writeInt( null == m_onNAChecked ? -1 : m_onNAChecked.ordinal() );
|
||||||
out.writeInt( m_titleId );
|
out.writeInt( m_titleId );
|
||||||
out.writeString( m_msg );
|
out.writeString( m_msg );
|
||||||
|
out.writeSerializable( m_params );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testCanParcelize()
|
||||||
|
{
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
Parcel parcel = Parcel.obtain();
|
||||||
|
writeToParcel(parcel, 0);
|
||||||
|
|
||||||
|
parcel.setDataPosition(0);
|
||||||
|
|
||||||
|
DlgState newState = DlgState.CREATOR.createFromParcel(parcel);
|
||||||
|
Assert.assertFalse(newState == this);
|
||||||
|
Assert.assertTrue(this.equals(newState));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<DlgState> CREATOR
|
public static final Parcelable.Creator<DlgState> CREATOR
|
||||||
|
@ -106,13 +174,17 @@ public class DlgState implements Parcelable {
|
||||||
Action onNA = 0 > tmp ? null : Action.values()[tmp];
|
Action onNA = 0 > tmp ? null : Action.values()[tmp];
|
||||||
int titleId = in.readInt();
|
int titleId = in.readInt();
|
||||||
String msg = in.readString();
|
String msg = in.readString();
|
||||||
|
Object[] params = (Object[])in.readSerializable();
|
||||||
DlgState state = new DlgState(id)
|
DlgState state = new DlgState(id)
|
||||||
.setMsg( msg )
|
.setMsg( msg )
|
||||||
.setPosButton( posButton )
|
.setPosButton( posButton )
|
||||||
.setNegButton( negButton )
|
.setNegButton( negButton )
|
||||||
.setAction( action )
|
.setAction( action )
|
||||||
.setPrefsKey( prefsKey )
|
.setPrefsKey( prefsKey )
|
||||||
.setOnNA( onNA );
|
.setOnNA( onNA )
|
||||||
|
.setTitle(titleId)
|
||||||
|
.setParams(params)
|
||||||
|
;
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2455,8 +2455,8 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
|
|
||||||
private void doOpenGame( Object[] params )
|
private void doOpenGame( Object[] params )
|
||||||
{
|
{
|
||||||
GameSummary summary = (GameSummary)params[1];
|
|
||||||
final long rowid = (Long)params[0];
|
final long rowid = (Long)params[0];
|
||||||
|
GameSummary summary = (GameSummary)params[1];
|
||||||
|
|
||||||
if ( summary.conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
if ( summary.conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
||||||
&& summary.roomName.length() == 0 ) {
|
&& summary.roomName.length() == 0 ) {
|
||||||
|
|
|
@ -26,6 +26,8 @@ import android.content.Intent;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
class HostDelegate extends DelegateBase {
|
class HostDelegate extends DelegateBase {
|
||||||
private static final String ACTION = "ACTION";
|
private static final String ACTION = "ACTION";
|
||||||
private static final String IS_POS_BUTTON = "POS_BUTTON";
|
private static final String IS_POS_BUTTON = "POS_BUTTON";
|
||||||
|
|
Loading…
Add table
Reference in a new issue