major change: use service to run baresip

This commit is contained in:
Juha Heinanen
2018-06-21 19:31:45 +03:00
parent cc7f34bfdd
commit 4388c20ec9
9 changed files with 675 additions and 585 deletions
+24 -19
View File
@@ -4,13 +4,11 @@ import android.app.ActivityManager
import android.content.Context
import android.support.v7.app.AlertDialog
import android.util.Log
import android.net.ConnectivityManager
import java.io.*
import android.os.Build
import android.os.PowerManager
import android.app.KeyguardManager
import java.io.*
object Utils {
fun getFileContents(file: File): String {
@@ -56,6 +54,25 @@ object Utils {
}
fun copyAssetToFile(context: Context, asset: String, path: String) {
try {
val `is` = context.assets.open(asset)
val os = FileOutputStream(path)
val buffer = ByteArray(512)
var byteRead: Int = `is`.read(buffer)
while (byteRead != -1) {
os.write(buffer, 0, byteRead)
byteRead = `is`.read(buffer)
}
os.close()
`is`.close()
} catch (e: IOException) {
Log.e("Baresip", "Failed to read asset " + asset + ": " +
e.toString())
}
}
fun alertView(context: Context, title: String, message: String) {
// val alertDialog = AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert).create()
val alertDialog = AlertDialog.Builder(context).create()
@@ -142,22 +159,10 @@ object Utils {
return res
}
fun isConnected(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.activeNetworkInfo
if (activeNetwork != null && activeNetwork.isConnected) {
val networkType = activeNetwork.type
return networkType == ConnectivityManager.TYPE_WIFI || networkType == ConnectivityManager.TYPE_MOBILE
} else {
return false
}
}
fun foregrounded(): Boolean {
fun isVisible(): Boolean {
val appProcessInfo = ActivityManager.RunningAppProcessInfo()
ActivityManager.getMyMemoryState(appProcessInfo);
return ((appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) or
(appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE))
ActivityManager.getMyMemoryState(appProcessInfo)
return appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
}
fun isDeviceLocked(context: Context): Boolean {