remove GCM -- crashes when invoked from server!

Once built for SDK 26 the old GCM support code crashes as it's calling
startService() from background. Duh! Will have to bring in Firebase's
replacement at some point. For now if I'm to release it has to be
without GCM.
This commit is contained in:
Eric House 2019-01-15 13:56:31 -08:00
parent 43b979ff46
commit e61d7a5629
9 changed files with 19 additions and 282 deletions

View file

@ -2,7 +2,6 @@ def INITIAL_CLIENT_VERS = 8
def VERSION_CODE_BASE = 137 def VERSION_CODE_BASE = 137
def VERSION_NAME = '4.4.141' def VERSION_NAME = '4.4.141'
def FABRIC_API_KEY = System.getenv("FABRIC_API_KEY") def FABRIC_API_KEY = System.getenv("FABRIC_API_KEY")
def GCM_SENDER_ID = System.getenv("GCM_SENDER_ID")
def BUILD_INFO_NAME = "build-info.txt" def BUILD_INFO_NAME = "build-info.txt"
boolean forFDroid = hasProperty('forFDroid') boolean forFDroid = hasProperty('forFDroid')
@ -69,6 +68,7 @@ android {
buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\"" buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\""
buildConfigField "boolean", "IS_TAGGED_BUILD", "${CURTAG}" == '' ? "false" : "true" buildConfigField "boolean", "IS_TAGGED_BUILD", "${CURTAG}" == '' ? "false" : "true"
resValue "string", "invite_prefix", "/and/" resValue "string", "invite_prefix", "/and/"
buildConfigField "String", "GCM_SENDER_ID", "\"\""
} }
xw4 { xw4 {
@ -79,8 +79,6 @@ android {
resValue "string", "nbs_port", "3344" resValue "string", "nbs_port", "3344"
buildConfigField "boolean", "WIDIR_ENABLED", "false" buildConfigField "boolean", "WIDIR_ENABLED", "false"
buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "false" buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "false"
buildConfigField "String", "GCM_SENDER_ID", "\"$GCM_SENDER_ID\""
} }
xw4fdroid { xw4fdroid {
@ -91,8 +89,6 @@ android {
resValue "string", "nbs_port", "3344" resValue "string", "nbs_port", "3344"
buildConfigField "boolean", "WIDIR_ENABLED", "false" buildConfigField "boolean", "WIDIR_ENABLED", "false"
buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "false" buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "false"
buildConfigField "String", "GCM_SENDER_ID", "\"\""
} }
xw4d { xw4d {
dimension "variant" dimension "variant"
@ -102,8 +98,6 @@ android {
resValue "string", "nbs_port", "3345" resValue "string", "nbs_port", "3345"
buildConfigField "boolean", "WIDIR_ENABLED", "true" buildConfigField "boolean", "WIDIR_ENABLED", "true"
buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "true" buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "true"
buildConfigField "String", "GCM_SENDER_ID", "\"\""
} }
// WARNING: "all" breaks things. Seems to be a keyword. Need // WARNING: "all" breaks things. Seems to be a keyword. Need
@ -205,9 +199,6 @@ ext {
} }
dependencies { dependencies {
// Look into replacing this with a fetch too PENDING
xw4Implementation files('../libs/gcm.jar')
implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION" implementation "com.android.support:support-v4:$SUPPORT_LIB_VERSION"
implementation "com.android.support:support-compat:$SUPPORT_LIB_VERSION" implementation "com.android.support:support-compat:$SUPPORT_LIB_VERSION"

View file

@ -120,24 +120,25 @@ public class DevID {
public static String getGCMDevID( Context context ) public static String getGCMDevID( Context context )
{ {
int curVers = Utils.getAppVersion( context ); return "";
int storedVers = DBUtils.getIntFor( context, GCM_REGVERS_KEY, 0 ); // int curVers = Utils.getAppVersion( context );
// TRANSITIONAL // int storedVers = DBUtils.getIntFor( context, GCM_REGVERS_KEY, 0 );
if ( 0 == storedVers ) { // // TRANSITIONAL
storedVers = XWPrefs.getPrefsInt( context, // if ( 0 == storedVers ) {
R.string.key_gcmvers_regid, 0 ); // storedVers = XWPrefs.getPrefsInt( context,
if ( 0 != storedVers ) { // R.string.key_gcmvers_regid, 0 );
DBUtils.setIntFor( context, GCM_REGVERS_KEY, storedVers ); // if ( 0 != storedVers ) {
} // DBUtils.setIntFor( context, GCM_REGVERS_KEY, storedVers );
} // }
// }
String result; // String result;
if ( 0 != storedVers && storedVers < curVers ) { // if ( 0 != storedVers && storedVers < curVers ) {
result = ""; // Don't trust what registrar has // result = ""; // Don't trust what registrar has
} else { // } else {
result = GCMStub.getRegistrationId( context ); // result = GCMStub.getRegistrationId( context );
} // }
return result; // return result;
} }
public static void clearGCMDevID( Context context ) public static void clearGCMDevID( Context context )

View file

@ -90,7 +90,6 @@ public class XWApp extends Application implements LifecycleObserver {
UpdateCheckReceiver.restartTimer( this ); UpdateCheckReceiver.restartTimer( this );
RelayService.startService( this ); RelayService.startService( this );
GCMIntentService.init( this );
WiDirWrapper.init( this ); WiDirWrapper.init( this );
} }

View file

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.eehouse.android.xw4"
>
<!-- GCM stuff -->
<permission android:name="${APP_ID}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${APP_ID}.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${APP_ID}" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>

View file

@ -1,166 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh insXw4Deb"; -*- */
/*
* Copyright 2012 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.Application;
import android.content.Context;
import android.content.Intent;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gcm.GCMRegistrar;
import org.json.JSONArray;
public class GCMIntentService extends GCMBaseIntentService {
private static final String TAG = GCMIntentService.class.getSimpleName();
private Boolean m_toastGCM;
public GCMIntentService()
{
super( BuildConfig.GCM_SENDER_ID );
Assert.assertTrue( BuildConfig.GCM_SENDER_ID.length() > 0 );
}
@Override
protected void onError( Context context, String error )
{
Log.d( TAG, "onError(%s)", error );
}
@Override
protected void onRegistered( Context context, String regId )
{
Log.d( TAG, "onRegistered(%s)", regId );
DevID.setGCMDevID( context, regId );
notifyRelayService( context, true );
}
@Override
protected void onUnregistered( Context context, String regId )
{
Log.d( TAG, "onUnregistered(%s)", regId );
DevID.clearGCMDevID( context );
RelayService.devIDChanged();
notifyRelayService( context, false );
}
@Override
protected void onMessage( Context context, Intent intent )
{
Log.d( TAG, "onMessage()" );
if ( XWPrefs.getIgnoreGCM( context ) ) {
String logMsg = "received GCM but ignoring it";
Log.d( TAG, logMsg );
DbgUtils.showf( context, logMsg );
} else {
boolean toastGCM = XWPrefs.getToastGCM( context );
notifyRelayService( context, true );
String value = intent.getStringExtra( "checkUpdates" );
if ( null != value && Boolean.parseBoolean( value ) ) {
UpdateCheckReceiver.checkVersions( context, true );
}
value = intent.getStringExtra( "getMoves" );
if ( null != value && Boolean.parseBoolean( value ) ) {
RelayService.timerFired( context );
if ( toastGCM ) {
DbgUtils.showf( context, "%s.onMessage(): got 'getMoves'",
TAG );
}
}
value = intent.getStringExtra( "msgs64" );
if ( null != value ) {
String connname = intent.getStringExtra( "connname" );
try {
JSONArray msgs64 = new JSONArray( value );
String[] strs64 = new String[msgs64.length()];
if ( toastGCM ) {
DbgUtils.showf( context, "%s.onMessage(): got %d msgs",
TAG, strs64.length );
}
for ( int ii = 0; ii < strs64.length; ++ii ) {
strs64[ii] = msgs64.optString(ii);
}
if ( null == connname ) {
RelayService.processDevMsgs( context, strs64 );
} else {
RelayService.processGameMsgs( context, connname, strs64 );
}
} catch (org.json.JSONException jse ) {
Log.ex( TAG, jse );
Assert.assertFalse( BuildConfig.DEBUG );
}
}
value = intent.getStringExtra( "msg" );
if ( null != value ) {
String title = intent.getStringExtra( "title" );
if ( null != title ) {
String teaser = intent.getStringExtra( "teaser" );
if ( null == teaser ) {
teaser = value;
}
Intent alertIntent = GamesListDelegate
.makeAlertIntent( this, value );
int code = value.hashCode() ^ title.hashCode();
Utils.postNotification( context, alertIntent, title,
teaser, code );
}
}
}
}
public static void init( Application app )
{
if ( 0 < BuildConfig.GCM_SENDER_ID.length() ) {
int sdkVersion = Integer.valueOf( android.os.Build.VERSION.SDK );
if ( 8 <= sdkVersion ) {
try {
GCMRegistrar.checkDevice( app );
// GCMRegistrar.checkManifest( app );
String regId = DevID.getGCMDevID( app );
if ( regId.equals("") ) {
GCMRegistrar.register( app, BuildConfig.GCM_SENDER_ID );
}
} catch ( UnsupportedOperationException uoe ) {
Log.w( TAG, "Device can't do GCM." );
} catch ( Exception whatever ) {
// funky devices could do anything
Log.ex( TAG, whatever );
}
}
}
}
private void notifyRelayService( Context context, boolean working )
{
if ( !XWPrefs.getIgnoreGCM( context ) ) {
RelayService.gcmConfirmed( context, working );
}
}
}

View file

@ -1,32 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh insXw4Deb"; -*- */
/*
* Copyright 2010 - 2015 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.content.Context;
import com.google.android.gcm.GCMRegistrar;
class GCMStub {
public static String getRegistrationId( Context context )
{
return GCMRegistrar.getRegistrationId( context );
}
}

View file

@ -1,29 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh insXw4dDeb"; -*- */
/*
* 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.content.Context;
class GCMStub {
public static String getRegistrationId( Context context )
{
return "";
}
}

View file

@ -1 +0,0 @@
../../../../../../xw4d/java/org/eehouse/android/xw4/GCMStub.java

Binary file not shown.