- fixed callee completion from contacts
- moved restoring of call and message history from baresip service to main activity - small cleanups
This commit is contained in:
+2
-3
@@ -3,13 +3,12 @@ apply plugin: 'kotlin-android'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion = 27
|
compileSdkVersion = 27
|
||||||
// buildToolsVersion '28.0.2'
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = 'com.tutpro.baresip'
|
applicationId = 'com.tutpro.baresip'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
versionCode = 28
|
versionCode = 29
|
||||||
versionName = '3.1.1'
|
versionName = '3.1.2'
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
cFlags '-DHAVE_INTTYPES_H'
|
cFlags '-DHAVE_INTTYPES_H'
|
||||||
|
|||||||
+27
-40
@@ -825,18 +825,6 @@ Java_com_tutpro_baresip_UserAgentKt_ua_1account(JNIEnv *env, jobject thiz, jstri
|
|||||||
return (*env)->NewStringUTF(env, acc_buf);
|
return (*env)->NewStringUTF(env, acc_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
|
||||||
Java_com_tutpro_baresip_UserAgentKt_ua_1aor(JNIEnv *env, jobject thiz, jstring javaUA)
|
|
||||||
{
|
|
||||||
const char *native_ua = (*env)->GetStringUTFChars(env, javaUA, 0);
|
|
||||||
struct ua *ua = (struct ua *)strtoul(native_ua, NULL, 10);
|
|
||||||
(*env)->ReleaseStringUTFChars(env, javaUA, native_ua);
|
|
||||||
if (ua)
|
|
||||||
return (*env)->NewStringUTF(env, ua_aor(ua));
|
|
||||||
else
|
|
||||||
return (*env)->NewStringUTF(env, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_com_tutpro_baresip_MainActivity_uag_1current_1set(JNIEnv *env, jobject thiz,
|
Java_com_tutpro_baresip_MainActivity_uag_1current_1set(JNIEnv *env, jobject thiz,
|
||||||
jstring javaUA)
|
jstring javaUA)
|
||||||
@@ -1081,34 +1069,6 @@ Java_com_tutpro_baresip_MainActivity_call_1notify_1sipfrag(JNIEnv *env, jobject
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_com_tutpro_baresip_ContactsActivity_00024Companion_contacts_1remove(JNIEnv *env, jobject thiz) {
|
|
||||||
struct le *le;
|
|
||||||
le = list_head(contact_list(baresip_contacts()));
|
|
||||||
while ((le = list_head(contact_list(baresip_contacts())))) {
|
|
||||||
struct contact *c = le->data;
|
|
||||||
contact_remove(baresip_contacts(), c);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
|
||||||
Java_com_tutpro_baresip_ContactsActivity_00024Companion_contact_1add(JNIEnv *env, jobject thiz,
|
|
||||||
jstring javaContact) {
|
|
||||||
struct pl pl_addr;
|
|
||||||
const struct list *lst;
|
|
||||||
struct le *le;
|
|
||||||
const char *native_contact = (*env)->GetStringUTFChars(env, javaContact, 0);
|
|
||||||
pl_set_str(&pl_addr, native_contact);
|
|
||||||
if (contact_add(baresip_contacts(), NULL, &pl_addr) != 0) {
|
|
||||||
LOGE("failed to add contact %s\n", native_contact);
|
|
||||||
} else {
|
|
||||||
LOGD("added contact %s\n", native_contact);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_com_tutpro_baresip_MainActivity_reload_1config(JNIEnv *env, jobject thiz) {
|
Java_com_tutpro_baresip_MainActivity_reload_1config(JNIEnv *env, jobject thiz) {
|
||||||
int err;
|
int err;
|
||||||
@@ -1159,3 +1119,30 @@ Java_com_tutpro_baresip_Api_audio_1codecs(JNIEnv *env, jobject thiz)
|
|||||||
return (*env)->NewStringUTF(env, codec_buf);
|
return (*env)->NewStringUTF(env, codec_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_tutpro_baresip_Api_contact_1add(JNIEnv *env, jobject thiz, jstring javaContact) {
|
||||||
|
struct pl pl_addr;
|
||||||
|
const struct list *lst;
|
||||||
|
struct le *le;
|
||||||
|
const char *native_contact = (*env)->GetStringUTFChars(env, javaContact, 0);
|
||||||
|
pl_set_str(&pl_addr, native_contact);
|
||||||
|
if (contact_add(baresip_contacts(), NULL, &pl_addr) != 0) {
|
||||||
|
LOGE("failed to add contact %s\n", native_contact);
|
||||||
|
} else {
|
||||||
|
LOGD("added contact %s\n", native_contact);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_com_tutpro_baresip_Api_contacts_1remove(JNIEnv *env, jobject thiz) {
|
||||||
|
struct le *le;
|
||||||
|
le = list_head(contact_list(baresip_contacts()));
|
||||||
|
while ((le = list_head(contact_list(baresip_contacts())))) {
|
||||||
|
struct contact *c = le->data;
|
||||||
|
contact_remove(baresip_contacts(), c);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,7 @@ object Api {
|
|||||||
external fun audio_codecs(): String
|
external fun audio_codecs(): String
|
||||||
external fun call_peeruri(callp: String): String
|
external fun call_peeruri(callp: String): String
|
||||||
external fun cmd_exec(cmd: String): Int
|
external fun cmd_exec(cmd: String): Int
|
||||||
|
external fun contact_add(contact: String)
|
||||||
|
external fun contacts_remove()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Baresip")
|
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.tutpro.baresip:wakelog")
|
||||||
|
|
||||||
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
@@ -145,38 +145,6 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file = File(path, "history")
|
|
||||||
if (file.exists()) {
|
|
||||||
try {
|
|
||||||
val fis = FileInputStream(file)
|
|
||||||
val ois = ObjectInputStream(fis)
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
MainActivity.history = ois.readObject() as ArrayList<CallHistory>
|
|
||||||
Log.d(LOG_TAG, "Restored History of ${MainActivity.history.size} entries")
|
|
||||||
ois.close()
|
|
||||||
fis.close()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.w(LOG_TAG, "InputStream exception: - " + e.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file = File(path, "messages")
|
|
||||||
if (file.exists()) {
|
|
||||||
try {
|
|
||||||
val fis = FileInputStream(file)
|
|
||||||
val ois = ObjectInputStream(fis)
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
MainActivity.messages = ois.readObject() as ArrayList<Message>
|
|
||||||
Log.d(LOG_TAG, "Restored ${MainActivity.messages.size} messages")
|
|
||||||
ois.close()
|
|
||||||
fis.close()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.w(LOG_TAG, "InputStream exception: - " + e.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ContactsActivity.generateContacts(path + "/contacts")
|
|
||||||
|
|
||||||
wl.acquire()
|
wl.acquire()
|
||||||
Thread(Runnable { baresipStart(path) }).start()
|
Thread(Runnable { baresipStart(path) }).start()
|
||||||
BaresipService.IS_SERVICE_RUNNING = true
|
BaresipService.IS_SERVICE_RUNNING = true
|
||||||
@@ -492,6 +460,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
Log.d(LOG_TAG, "Loading baresip library")
|
||||||
System.loadLibrary("baresip")
|
System.loadLibrary("baresip")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,4 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import android.view.MenuItem
|
|||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.io.ObjectInputStream
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -163,5 +165,23 @@ class CallsActivity : AppCompatActivity() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun restoreHistory(path: String) {
|
||||||
|
val file = File(path + "/history")
|
||||||
|
if (file.exists()) {
|
||||||
|
try {
|
||||||
|
val fis = FileInputStream(file)
|
||||||
|
val ois = ObjectInputStream(fis)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
MainActivity.history = ois.readObject() as ArrayList<CallHistory>
|
||||||
|
Log.d("Baresip", "Restored History of ${MainActivity.history.size} entries")
|
||||||
|
ois.close()
|
||||||
|
fis.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w("Baresip", "InputStream exception: - " + e.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,30 +91,30 @@ class ContactsActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
var contacts = ArrayList<Contact>()
|
var contacts = ArrayList<Contact>()
|
||||||
|
|
||||||
fun generateContacts(path: String) {
|
fun saveContacts() {
|
||||||
val content = Utils.getFileContents(File(path))
|
var contents = ""
|
||||||
contacts_remove()
|
for (c in contacts)
|
||||||
|
contents += "\"${c.name}\" ${c.uri}\n"
|
||||||
|
val path = MainActivity.filesPath + "/contacts"
|
||||||
|
Utils.putFileContents(File(path), contents)
|
||||||
|
Log.d("Baresip", "Saved contacts '${contents}' to '$path")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun restoreContacts(path: String) {
|
||||||
|
val content = Utils.getFileContents(File(path + "/contacts"))
|
||||||
|
Api.contacts_remove()
|
||||||
contacts.clear()
|
contacts.clear()
|
||||||
content.lines().forEach {
|
content.lines().forEach {
|
||||||
val parts = it.split("\"")
|
val parts = it.split("\"")
|
||||||
if (parts.size == 3) {
|
if (parts.size == 3) {
|
||||||
val name = parts[1]
|
val name = parts[1]
|
||||||
val uri = parts[2].trim()
|
val uri = parts[2].trim()
|
||||||
contact_add("\"$name\" $uri")
|
Api.contact_add("\"$name\" $uri")
|
||||||
contacts.add(Contact(name, uri))
|
contacts.add(Contact(name, uri))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveContacts() {
|
|
||||||
var contents = ""
|
|
||||||
for (c in contacts)
|
|
||||||
contents += "\"${c.name}\" ${c.uri}\n"
|
|
||||||
val path = MainActivity.filesPath + "/contacts"
|
|
||||||
Utils.putFileContents(File(path), contents)
|
|
||||||
Log.d("Baresip", "Saved contacts '${contents}' to '$path")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findContactURI(name: String): String {
|
fun findContactURI(name: String): String {
|
||||||
for (c in contacts)
|
for (c in contacts)
|
||||||
if (c.name == name)
|
if (c.name == name)
|
||||||
@@ -137,10 +137,5 @@ class ContactsActivity : AppCompatActivity() {
|
|||||||
return c.name
|
return c.name
|
||||||
return uri
|
return uri
|
||||||
}
|
}
|
||||||
|
|
||||||
external fun contacts_remove()
|
|
||||||
external fun contact_add(contact: String)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callUri.threshold = 2
|
||||||
|
ContactsActivity.restoreContacts(applicationContext.filesDir.path)
|
||||||
|
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||||
|
ContactsActivity.contacts.map{Contact -> Contact.name}))
|
||||||
|
|
||||||
securityButton.setOnClickListener {
|
securityButton.setOnClickListener {
|
||||||
when (securityButton.tag) {
|
when (securityButton.tag) {
|
||||||
"red" -> {
|
"red" -> {
|
||||||
@@ -318,6 +323,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
startActivityForResult(i, CONTACTS_CODE)
|
startActivityForResult(i, CONTACTS_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessagesActivity.restoreMessages(applicationContext.filesDir.path)
|
||||||
messagesButton.setOnClickListener {
|
messagesButton.setOnClickListener {
|
||||||
if (aorSpinner.selectedItemPosition >= 0) {
|
if (aorSpinner.selectedItemPosition >= 0) {
|
||||||
val i = Intent(this@MainActivity, MessagesActivity::class.java)
|
val i = Intent(this@MainActivity, MessagesActivity::class.java)
|
||||||
@@ -328,6 +334,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CallsActivity.restoreHistory(applicationContext.filesDir.path)
|
||||||
callsButton.setOnClickListener {
|
callsButton.setOnClickListener {
|
||||||
if (aorSpinner.selectedItemPosition >= 0) {
|
if (aorSpinner.selectedItemPosition >= 0) {
|
||||||
val i = Intent(this@MainActivity, CallsActivity::class.java)
|
val i = Intent(this@MainActivity, CallsActivity::class.java)
|
||||||
@@ -344,10 +351,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
startService(baresipService)
|
startService(baresipService)
|
||||||
}
|
}
|
||||||
|
|
||||||
callUri.threshold = 2
|
|
||||||
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
|
||||||
ContactsActivity.contacts.map { Contact -> Contact.name }))
|
|
||||||
|
|
||||||
if (intent.hasExtra("onStartup"))
|
if (intent.hasExtra("onStartup"))
|
||||||
moveTaskToBack(true)
|
moveTaskToBack(true)
|
||||||
|
|
||||||
@@ -833,7 +836,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
@@ -1148,4 +1150,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
const val ONE_CALL_ONLY = true
|
const val ONE_CALL_ONLY = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
Log.d("Baresip", "Loading baresip library")
|
||||||
|
System.loadLibrary("baresip")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ import android.widget.ImageButton
|
|||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.io.ObjectInputStream
|
||||||
import java.io.ObjectOutputStream
|
import java.io.ObjectOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -221,5 +223,22 @@ class MessagesActivity: AppCompatActivity() {
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun restoreMessages(path: String) {
|
||||||
|
val file = File(path, "messages")
|
||||||
|
if (file.exists()) {
|
||||||
|
try {
|
||||||
|
val fis = FileInputStream(file)
|
||||||
|
val ois = ObjectInputStream(fis)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
MainActivity.messages = ois.readObject() as ArrayList<Message>
|
||||||
|
Log.d("Baresip", "Restored ${MainActivity.messages.size} messages")
|
||||||
|
ois.close()
|
||||||
|
fis.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w("Baresip", "InputStream exception: - " + e.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,5 +58,4 @@ class UserAgent (val uap: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
external fun ua_account(ua: String): String
|
external fun ua_account(ua: String): String
|
||||||
external fun ua_aor(ua: String): String
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user