New user-agent

This commit is contained in:
Sylvain Berfini 2018-10-27 10:29:21 +02:00
parent d3fc819cf6
commit 531e50fc66
2 changed files with 27 additions and 12 deletions

View file

@ -704,18 +704,14 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
mLc.setZrtpSecretsFile(basePath + "/zrtp_secrets"); mLc.setZrtpSecretsFile(basePath + "/zrtp_secrets");
try { String deviceName = LinphoneUtils.getDeviceName(mServiceContext);
String versionName = mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionName; String appName = mServiceContext.getResources().getString(R.string.user_agent);
if (versionName == null) { String androidVersion = BuildConfig.VERSION_NAME;
versionName = String.valueOf(mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionCode); String coreVersion = mLc.getVersion();
} else { String userAgent = deviceName + " " + appName + "/" + androidVersion + " LinphoneCore";
//Api to check version can't use version code mLc.setUserAgent(userAgent, coreVersion);
mLc.checkForUpdate(versionName);
} mLc.checkForUpdate(androidVersion);
mLc.setUserAgent(mServiceContext.getResources().getString(R.string.user_agent), versionName);
} catch (NameNotFoundException e) {
Log.e(e, "cannot get version name");
}
mLc.setChatDatabasePath(mChatDatabaseFile); mLc.setChatDatabasePath(mChatDatabaseFile);
mLc.setCallLogsDatabasePath(mCallLogDatabaseFile); mLc.setCallLogsDatabasePath(mCallLogDatabaseFile);

View file

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
@ -35,6 +36,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.provider.Settings;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
@ -98,6 +100,23 @@ public final class LinphoneUtils {
} }
public static String getDeviceName(Context context) {
String name = null;
if (Build.VERSION.SDK_INT > 17) {
name = Settings.Global.getString(context.getContentResolver(), Settings.Global.DEVICE_NAME);
}
if (name == null) {
name = BluetoothAdapter.getDefaultAdapter().getName();
}
if (name == null) {
name = Settings.Secure.getString(context.getContentResolver(), "bluetooth_name");
}
if (name == null) {
name = Build.MANUFACTURER + " " + Build.MODEL;
}
return name;
}
public static void initLoggingService(boolean isDebugEnabled, String appName) { public static void initLoggingService(boolean isDebugEnabled, String appName) {
if (!LinphonePreferences.instance().useJavaLogger()) { if (!LinphonePreferences.instance().useJavaLogger()) {
Factory.instance().enableLogCollection(LogCollectionState.Enabled); Factory.instance().enableLogCollection(LogCollectionState.Enabled);