From 50b4846d4386e11e7b2e47dff262a827afe70a35 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 19 Jul 2016 13:11:27 +0200 Subject: [PATCH] Fix crash when receving a push notification after killing the service --- src/org/linphone/LinphonePreferences.java | 13 ++++++++----- src/org/linphone/gcm/GCMService.java | 22 ++++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/org/linphone/LinphonePreferences.java b/src/org/linphone/LinphonePreferences.java index 52f44440c..582d4733b 100644 --- a/src/org/linphone/LinphonePreferences.java +++ b/src/org/linphone/LinphonePreferences.java @@ -52,6 +52,7 @@ public class LinphonePreferences { private static final int LINPHONE_CORE_RANDOM_PORT = -1; private static LinphonePreferences instance; private Context mContext; + private String basePath; public static final synchronized LinphonePreferences instance() { if (instance == null) { @@ -66,6 +67,7 @@ public class LinphonePreferences { public void setContext(Context c) { mContext = c; + basePath = mContext.getFilesDir().getAbsolutePath(); } private String getString(int key) { @@ -90,10 +92,10 @@ public class LinphonePreferences { } if (!LinphoneManager.isInstanciated()) { - File linphonerc = new File(mContext.getFilesDir().getAbsolutePath() + "/.linphonerc"); + File linphonerc = new File(basePath + "/.linphonerc"); if (linphonerc.exists()) { return LinphoneCoreFactory.instance().createLpConfig(linphonerc.getAbsolutePath()); - } else { + } else if (mContext != null) { InputStream inputStream = mContext.getResources().openRawResource(R.raw.linphonerc_default); InputStreamReader inputreader = new InputStreamReader(inputStream); BufferedReader buffreader = new BufferedReader(inputreader); @@ -105,13 +107,14 @@ public class LinphonePreferences { text.append('\n'); } } catch (IOException ioe) { - + Log.e(ioe); } return LinphoneCoreFactory.instance().createLpConfigFromString(text.toString()); } + } else { + return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile); } - - return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile); + return null; } public void removePreviousVersionAuthInfoRemoval() { diff --git a/src/org/linphone/gcm/GCMService.java b/src/org/linphone/gcm/GCMService.java index 7d6c24936..42803cf92 100644 --- a/src/org/linphone/gcm/GCMService.java +++ b/src/org/linphone/gcm/GCMService.java @@ -43,19 +43,22 @@ public class GCMService extends GCMBaseIntentService { } - @Override - protected void onError(Context context, String errorId) { + private void initLogger(Context context) { + LinphonePreferences.instance().setContext(context); boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled(); LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled); LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name)); + } + + @Override + protected void onError(Context context, String errorId) { + initLogger(context); Log.e("Error while registering push notification : " + errorId); } @Override protected void onMessage(Context context, Intent intent) { - boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled(); - LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled); - LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name)); + initLogger(context); Log.d("Push notification received"); if (!LinphoneService.isReady()) { @@ -70,15 +73,12 @@ public class GCMService extends GCMBaseIntentService { } } }); - } } @Override protected void onRegistered(Context context, String regId) { - boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled(); - LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled); - LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name)); + initLogger(context); Log.d("Registered push notification : " + regId); LinphonePreferences.instance().setPushNotificationRegistrationID(regId); @@ -86,9 +86,7 @@ public class GCMService extends GCMBaseIntentService { @Override protected void onUnregistered(Context context, String regId) { - boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled(); - LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled); - LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name)); + initLogger(context); Log.w("Unregistered push notification : " + regId); LinphonePreferences.instance().setPushNotificationRegistrationID(null);