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");
try {
String versionName = mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionName;
if (versionName == null) {
versionName = String.valueOf(mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionCode);
} else {
//Api to check version can't use version code
mLc.checkForUpdate(versionName);
}
mLc.setUserAgent(mServiceContext.getResources().getString(R.string.user_agent), versionName);
} catch (NameNotFoundException e) {
Log.e(e, "cannot get version name");
}
String deviceName = LinphoneUtils.getDeviceName(mServiceContext);
String appName = mServiceContext.getResources().getString(R.string.user_agent);
String androidVersion = BuildConfig.VERSION_NAME;
String coreVersion = mLc.getVersion();
String userAgent = deviceName + " " + appName + "/" + androidVersion + " LinphoneCore";
mLc.setUserAgent(userAgent, coreVersion);
mLc.checkForUpdate(androidVersion);
mLc.setChatDatabasePath(mChatDatabaseFile);
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.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
@ -35,6 +36,7 @@ import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.Spanned;
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) {
if (!LinphonePreferences.instance().useJavaLogger()) {
Factory.instance().enableLogCollection(LogCollectionState.Enabled);