Fix crash when receving a push notification after killing the service

This commit is contained in:
Sylvain Berfini 2016-07-19 13:11:27 +02:00
parent eee44f8b29
commit 50b4846d43
2 changed files with 18 additions and 17 deletions

View file

@ -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() {

View file

@ -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);