- 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:
@ -825,18 +825,6 @@ Java_com_tutpro_baresip_UserAgentKt_ua_1account(JNIEnv *env, jobject thiz, jstri
|
||||
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
|
||||
Java_com_tutpro_baresip_MainActivity_uag_1current_1set(JNIEnv *env, jobject thiz,
|
||||
jstring javaUA)
|
||||
@ -1081,34 +1069,6 @@ Java_com_tutpro_baresip_MainActivity_call_1notify_1sipfrag(JNIEnv *env, jobject
|
||||
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
|
||||
Java_com_tutpro_baresip_MainActivity_reload_1config(JNIEnv *env, jobject thiz) {
|
||||
int err;
|
||||
@ -1159,3 +1119,30 @@ Java_com_tutpro_baresip_Api_audio_1codecs(JNIEnv *env, jobject thiz)
|
||||
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 call_peeruri(callp: String): String
|
||||
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
|
||||
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) {
|
||||
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()
|
||||
Thread(Runnable { baresipStart(path) }).start()
|
||||
BaresipService.IS_SERVICE_RUNNING = true
|
||||
@ -492,6 +460,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
|
||||
init {
|
||||
Log.d(LOG_TAG, "Loading baresip library")
|
||||
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.ListView
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
@ -163,5 +165,23 @@ class CallsActivity : AppCompatActivity() {
|
||||
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>()
|
||||
|
||||
fun generateContacts(path: String) {
|
||||
val content = Utils.getFileContents(File(path))
|
||||
contacts_remove()
|
||||
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 restoreContacts(path: String) {
|
||||
val content = Utils.getFileContents(File(path + "/contacts"))
|
||||
Api.contacts_remove()
|
||||
contacts.clear()
|
||||
content.lines().forEach {
|
||||
val parts = it.split("\"")
|
||||
if (parts.size == 3) {
|
||||
val name = parts[1]
|
||||
val uri = parts[2].trim()
|
||||
contact_add("\"$name\" $uri")
|
||||
Api.contact_add("\"$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 {
|
||||
for (c in contacts)
|
||||
if (c.name == name)
|
||||
@ -137,10 +137,5 @@ class ContactsActivity : AppCompatActivity() {
|
||||
return c.name
|
||||
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 {
|
||||
when (securityButton.tag) {
|
||||
"red" -> {
|
||||
@ -318,6 +323,7 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivityForResult(i, CONTACTS_CODE)
|
||||
}
|
||||
|
||||
MessagesActivity.restoreMessages(applicationContext.filesDir.path)
|
||||
messagesButton.setOnClickListener {
|
||||
if (aorSpinner.selectedItemPosition >= 0) {
|
||||
val i = Intent(this@MainActivity, MessagesActivity::class.java)
|
||||
@ -328,6 +334,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
CallsActivity.restoreHistory(applicationContext.filesDir.path)
|
||||
callsButton.setOnClickListener {
|
||||
if (aorSpinner.selectedItemPosition >= 0) {
|
||||
val i = Intent(this@MainActivity, CallsActivity::class.java)
|
||||
@ -344,10 +351,6 @@ class MainActivity : AppCompatActivity() {
|
||||
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"))
|
||||
moveTaskToBack(true)
|
||||
|
||||
@ -833,7 +836,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
||||
when (requestCode) {
|
||||
@ -1148,4 +1150,9 @@ class MainActivity : AppCompatActivity() {
|
||||
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 java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.util.*
|
||||
|
||||
@ -221,5 +223,22 @@ class MessagesActivity: AppCompatActivity() {
|
||||
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_aor(ua: String): String
|
||||
|
||||
|
||||
Reference in New Issue
Block a user