Fixed issue with default linphonerc when app is installed for the first time
This commit is contained in:
parent
f74f6e5911
commit
5aeebfeb72
4 changed files with 71 additions and 64 deletions
|
@ -41,9 +41,6 @@ import android.view.View;
|
|||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
|
@ -81,11 +78,7 @@ import org.linphone.utils.PushNotificationUtils;
|
|||
|
||||
/** Handles Linphone's Core lifecycle */
|
||||
public class LinphoneManager implements SensorEventListener {
|
||||
private final String mConfigFile;
|
||||
private final String mLPConfigXsd;
|
||||
private final String mBasePath;
|
||||
private final String mLinphoneFactoryConfigFile;
|
||||
private final String mLinphoneDynamicConfigFile, mDefaultDynamicConfigFile;
|
||||
private final String mRingSoundFile;
|
||||
private final String mCallLogDatabaseFile;
|
||||
private final String mFriendsDatabaseFile;
|
||||
|
@ -120,11 +113,6 @@ public class LinphoneManager implements SensorEventListener {
|
|||
mExited = false;
|
||||
mContext = c;
|
||||
mBasePath = c.getFilesDir().getAbsolutePath();
|
||||
mLPConfigXsd = mBasePath + "/lpconfig.xsd";
|
||||
mLinphoneFactoryConfigFile = mBasePath + "/linphonerc";
|
||||
mConfigFile = mBasePath + "/.linphonerc";
|
||||
mLinphoneDynamicConfigFile = mBasePath + "/linphone_assistant_create.rc";
|
||||
mDefaultDynamicConfigFile = mBasePath + "/default_assistant_create.rc";
|
||||
mCallLogDatabaseFile = mBasePath + "/linphone-log-history.db";
|
||||
mFriendsDatabaseFile = mBasePath + "/linphone-friends.db";
|
||||
mRingSoundFile = mBasePath + "/share/sounds/linphone/rings/notes_of_the_optimistic.mkv";
|
||||
|
@ -448,11 +436,12 @@ public class LinphoneManager implements SensorEventListener {
|
|||
|
||||
public synchronized void startLibLinphone(boolean isPush) {
|
||||
try {
|
||||
copyAssetsFromPackage();
|
||||
// traces alway start with traces enable to not missed first initialization
|
||||
mCore =
|
||||
Factory.instance()
|
||||
.createCore(mConfigFile, mLinphoneFactoryConfigFile, mContext);
|
||||
.createCore(
|
||||
mPrefs.getLinphoneDefaultConfig(),
|
||||
mPrefs.getLinphoneFactoryConfig(),
|
||||
mContext);
|
||||
mCore.addListener(mCoreListener);
|
||||
if (isPush) {
|
||||
Log.w(
|
||||
|
@ -664,38 +653,6 @@ public class LinphoneManager implements SensorEventListener {
|
|||
dialog.show();
|
||||
}
|
||||
|
||||
/* Assets stuff */
|
||||
|
||||
private void copyAssetsFromPackage() throws IOException {
|
||||
copyIfNotExist(R.raw.linphonerc_default, mConfigFile);
|
||||
copyFromPackage(R.raw.linphonerc_factory, new File(mLinphoneFactoryConfigFile).getName());
|
||||
copyIfNotExist(R.raw.lpconfig, mLPConfigXsd);
|
||||
copyFromPackage(
|
||||
R.raw.default_assistant_create, new File(mDefaultDynamicConfigFile).getName());
|
||||
copyFromPackage(
|
||||
R.raw.linphone_assistant_create, new File(mLinphoneDynamicConfigFile).getName());
|
||||
}
|
||||
|
||||
private void copyIfNotExist(int ressourceId, String target) throws IOException {
|
||||
File lFileToCopy = new File(target);
|
||||
if (!lFileToCopy.exists()) {
|
||||
copyFromPackage(ressourceId, lFileToCopy.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFromPackage(int ressourceId, String target) throws IOException {
|
||||
FileOutputStream lOutputStream = mContext.openFileOutput(target, 0);
|
||||
InputStream lInputStream = mContext.getResources().openRawResource(ressourceId);
|
||||
int readByte;
|
||||
byte[] buff = new byte[8048];
|
||||
while ((readByte = lInputStream.read(buff)) != -1) {
|
||||
lOutputStream.write(buff, 0, readByte);
|
||||
}
|
||||
lOutputStream.flush();
|
||||
lOutputStream.close();
|
||||
lInputStream.close();
|
||||
}
|
||||
|
||||
/* Presence stuff */
|
||||
|
||||
private boolean isPresenceModelActivitySet() {
|
||||
|
@ -871,18 +828,6 @@ public class LinphoneManager implements SensorEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
public String getDefaultDynamicConfigFile() {
|
||||
return mDefaultDynamicConfigFile;
|
||||
}
|
||||
|
||||
public String getLinphoneDynamicConfigFile() {
|
||||
return mLinphoneDynamicConfigFile;
|
||||
}
|
||||
|
||||
public String getConfigFile() {
|
||||
return mConfigFile;
|
||||
}
|
||||
|
||||
public boolean getCallGsmON() {
|
||||
return mCallGsmON;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public abstract class AssistantActivity extends LinphoneGenericActivity
|
|||
if (mAccountCreator == null) {
|
||||
String url = LinphonePreferences.instance().getXmlrpcUrl();
|
||||
Core core = LinphoneManager.getCore();
|
||||
core.loadConfigFromXml(LinphoneManager.getInstance().getDefaultDynamicConfigFile());
|
||||
core.loadConfigFromXml(LinphonePreferences.instance().getDefaultDynamicConfigFile());
|
||||
mAccountCreator = core.createAccountCreator(url);
|
||||
}
|
||||
}
|
||||
|
@ -103,14 +103,14 @@ public abstract class AssistantActivity extends LinphoneGenericActivity
|
|||
boolean useLinphoneDefaultValues =
|
||||
getString(R.string.default_domain).equals(mAccountCreator.getDomain());
|
||||
if (useLinphoneDefaultValues) {
|
||||
core.loadConfigFromXml(LinphoneManager.getInstance().getLinphoneDynamicConfigFile());
|
||||
core.loadConfigFromXml(LinphonePreferences.instance().getLinphoneDynamicConfigFile());
|
||||
}
|
||||
|
||||
ProxyConfig proxyConfig = mAccountCreator.configure();
|
||||
|
||||
if (useLinphoneDefaultValues) {
|
||||
// Restore default values
|
||||
core.loadConfigFromXml(LinphoneManager.getInstance().getDefaultDynamicConfigFile());
|
||||
core.loadConfigFromXml(LinphonePreferences.instance().getDefaultDynamicConfigFile());
|
||||
} else {
|
||||
// If this isn't a sip.linphone.org account, disable push notifications and enable
|
||||
// service notification, otherwise incoming calls won't work (most probably)
|
||||
|
|
|
@ -593,7 +593,7 @@ public class AccountSettingsFragment extends SettingsFragment {
|
|||
// Create a proxy config if there is none
|
||||
if (mProxyConfig == null) {
|
||||
// Ensure the default configuration is loaded first
|
||||
String defaultConfig = LinphoneManager.getInstance().getDefaultDynamicConfigFile();
|
||||
String defaultConfig = LinphonePreferences.instance().getDefaultDynamicConfigFile();
|
||||
core.loadConfigFromXml(defaultConfig);
|
||||
mProxyConfig = core.createProxyConfig();
|
||||
mAuthInfo = Factory.instance().createAuthInfo(null, null, null, null, null, null);
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.content.pm.PackageManager;
|
|||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -53,6 +54,12 @@ import org.linphone.utils.LinphoneUtils;
|
|||
|
||||
public class LinphonePreferences {
|
||||
private static final int LINPHONE_CORE_RANDOM_PORT = -1;
|
||||
private static final String LINPHONE_DEFAULT_RC = "/.linphonerc";
|
||||
private static final String LINPHONE_FACTORY_RC = "/linphonerc";
|
||||
private static final String LINPHONE_LPCONFIG_XSD = "/lpconfig.xsd";
|
||||
private static final String DEFAULT_ASSISTANT_RC = "/default_assistant_create.rc";
|
||||
private static final String LINPHONE_ASSISTANT_RC = "/linphone_assistant_create.rc";
|
||||
|
||||
private static LinphonePreferences sInstance;
|
||||
|
||||
private Context mContext;
|
||||
|
@ -77,6 +84,61 @@ public class LinphonePreferences {
|
|||
public void setContext(Context c) {
|
||||
mContext = c;
|
||||
mBasePath = mContext.getFilesDir().getAbsolutePath();
|
||||
try {
|
||||
copyAssetsFromPackage();
|
||||
} catch (IOException ioe) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Assets stuff */
|
||||
|
||||
private void copyAssetsFromPackage() throws IOException {
|
||||
copyIfNotExist(R.raw.linphonerc_default, getLinphoneDefaultConfig());
|
||||
copyFromPackage(R.raw.linphonerc_factory, new File(getLinphoneFactoryConfig()).getName());
|
||||
copyIfNotExist(R.raw.lpconfig, mBasePath + LINPHONE_LPCONFIG_XSD);
|
||||
copyFromPackage(
|
||||
R.raw.default_assistant_create,
|
||||
new File(mBasePath + DEFAULT_ASSISTANT_RC).getName());
|
||||
copyFromPackage(
|
||||
R.raw.linphone_assistant_create,
|
||||
new File(mBasePath + LINPHONE_ASSISTANT_RC).getName());
|
||||
}
|
||||
|
||||
private void copyIfNotExist(int ressourceId, String target) throws IOException {
|
||||
File lFileToCopy = new File(target);
|
||||
if (!lFileToCopy.exists()) {
|
||||
copyFromPackage(ressourceId, lFileToCopy.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFromPackage(int ressourceId, String target) throws IOException {
|
||||
FileOutputStream lOutputStream = mContext.openFileOutput(target, 0);
|
||||
InputStream lInputStream = mContext.getResources().openRawResource(ressourceId);
|
||||
int readByte;
|
||||
byte[] buff = new byte[8048];
|
||||
while ((readByte = lInputStream.read(buff)) != -1) {
|
||||
lOutputStream.write(buff, 0, readByte);
|
||||
}
|
||||
lOutputStream.flush();
|
||||
lOutputStream.close();
|
||||
lInputStream.close();
|
||||
}
|
||||
|
||||
public String getLinphoneDefaultConfig() {
|
||||
return mBasePath + LINPHONE_DEFAULT_RC;
|
||||
}
|
||||
|
||||
public String getLinphoneFactoryConfig() {
|
||||
return mBasePath + LINPHONE_FACTORY_RC;
|
||||
}
|
||||
|
||||
public String getDefaultDynamicConfigFile() {
|
||||
return mBasePath + DEFAULT_ASSISTANT_RC;
|
||||
}
|
||||
|
||||
public String getLinphoneDynamicConfigFile() {
|
||||
return mBasePath + LINPHONE_ASSISTANT_RC;
|
||||
}
|
||||
|
||||
private String getString(int key) {
|
||||
|
@ -121,7 +183,7 @@ public class LinphonePreferences {
|
|||
return Factory.instance().createConfigFromString(text.toString());
|
||||
}
|
||||
} else {
|
||||
return Factory.instance().createConfig(LinphoneManager.getInstance().getConfigFile());
|
||||
return Factory.instance().createConfig(getLinphoneDefaultConfig());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue