Fix crash when receving a push notification after killing the service
This commit is contained in:
parent
eee44f8b29
commit
50b4846d43
2 changed files with 18 additions and 17 deletions
|
@ -52,6 +52,7 @@ public class LinphonePreferences {
|
||||||
private static final int LINPHONE_CORE_RANDOM_PORT = -1;
|
private static final int LINPHONE_CORE_RANDOM_PORT = -1;
|
||||||
private static LinphonePreferences instance;
|
private static LinphonePreferences instance;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private String basePath;
|
||||||
|
|
||||||
public static final synchronized LinphonePreferences instance() {
|
public static final synchronized LinphonePreferences instance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
|
@ -66,6 +67,7 @@ public class LinphonePreferences {
|
||||||
|
|
||||||
public void setContext(Context c) {
|
public void setContext(Context c) {
|
||||||
mContext = c;
|
mContext = c;
|
||||||
|
basePath = mContext.getFilesDir().getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getString(int key) {
|
private String getString(int key) {
|
||||||
|
@ -90,10 +92,10 @@ public class LinphonePreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LinphoneManager.isInstanciated()) {
|
if (!LinphoneManager.isInstanciated()) {
|
||||||
File linphonerc = new File(mContext.getFilesDir().getAbsolutePath() + "/.linphonerc");
|
File linphonerc = new File(basePath + "/.linphonerc");
|
||||||
if (linphonerc.exists()) {
|
if (linphonerc.exists()) {
|
||||||
return LinphoneCoreFactory.instance().createLpConfig(linphonerc.getAbsolutePath());
|
return LinphoneCoreFactory.instance().createLpConfig(linphonerc.getAbsolutePath());
|
||||||
} else {
|
} else if (mContext != null) {
|
||||||
InputStream inputStream = mContext.getResources().openRawResource(R.raw.linphonerc_default);
|
InputStream inputStream = mContext.getResources().openRawResource(R.raw.linphonerc_default);
|
||||||
InputStreamReader inputreader = new InputStreamReader(inputStream);
|
InputStreamReader inputreader = new InputStreamReader(inputStream);
|
||||||
BufferedReader buffreader = new BufferedReader(inputreader);
|
BufferedReader buffreader = new BufferedReader(inputreader);
|
||||||
|
@ -105,13 +107,14 @@ public class LinphonePreferences {
|
||||||
text.append('\n');
|
text.append('\n');
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
Log.e(ioe);
|
||||||
}
|
}
|
||||||
return LinphoneCoreFactory.instance().createLpConfigFromString(text.toString());
|
return LinphoneCoreFactory.instance().createLpConfigFromString(text.toString());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePreviousVersionAuthInfoRemoval() {
|
public void removePreviousVersionAuthInfoRemoval() {
|
||||||
|
|
|
@ -43,19 +43,22 @@ public class GCMService extends GCMBaseIntentService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initLogger(Context context) {
|
||||||
protected void onError(Context context, String errorId) {
|
LinphonePreferences.instance().setContext(context);
|
||||||
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
|
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
|
||||||
LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled);
|
LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled);
|
||||||
LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name));
|
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);
|
Log.e("Error while registering push notification : " + errorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMessage(Context context, Intent intent) {
|
protected void onMessage(Context context, Intent intent) {
|
||||||
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
|
initLogger(context);
|
||||||
LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled);
|
|
||||||
LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name));
|
|
||||||
Log.d("Push notification received");
|
Log.d("Push notification received");
|
||||||
|
|
||||||
if (!LinphoneService.isReady()) {
|
if (!LinphoneService.isReady()) {
|
||||||
|
@ -70,15 +73,12 @@ public class GCMService extends GCMBaseIntentService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRegistered(Context context, String regId) {
|
protected void onRegistered(Context context, String regId) {
|
||||||
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
|
initLogger(context);
|
||||||
LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled);
|
|
||||||
LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name));
|
|
||||||
Log.d("Registered push notification : " + regId);
|
Log.d("Registered push notification : " + regId);
|
||||||
|
|
||||||
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
|
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
|
||||||
|
@ -86,9 +86,7 @@ public class GCMService extends GCMBaseIntentService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onUnregistered(Context context, String regId) {
|
protected void onUnregistered(Context context, String regId) {
|
||||||
boolean isDebugEnabled = LinphonePreferences.instance().isDebugEnabled();
|
initLogger(context);
|
||||||
LinphoneCoreFactory.instance().enableLogCollection(isDebugEnabled);
|
|
||||||
LinphoneCoreFactory.instance().setDebugMode(isDebugEnabled, context.getString(R.string.app_name));
|
|
||||||
Log.w("Unregistered push notification : " + regId);
|
Log.w("Unregistered push notification : " + regId);
|
||||||
|
|
||||||
LinphonePreferences.instance().setPushNotificationRegistrationID(null);
|
LinphonePreferences.instance().setPushNotificationRegistrationID(null);
|
||||||
|
|
Loading…
Reference in a new issue