- More work on asking passwords.
This commit is contained in:
@ -9,13 +9,14 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout.LayoutParams
|
||||
import android.widget.*
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_account.*
|
||||
|
||||
import com.tutpro.baresip.Account.Companion.checkAuthPass
|
||||
import com.tutpro.baresip.Account.Companion.checkAuthUser
|
||||
import com.tutpro.baresip.Account.Companion.checkDisplayName
|
||||
import com.tutpro.baresip.MainActivity.Companion.aorPasswords
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_account.*
|
||||
|
||||
class AccountActivity : AppCompatActivity() {
|
||||
|
||||
internal lateinit var acc: Account
|
||||
|
||||
@ -12,6 +12,8 @@ import android.widget.ArrayAdapter
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
|
||||
import com.tutpro.baresip.MainActivity.Companion.ACCOUNT_CODE
|
||||
|
||||
import java.util.*
|
||||
|
||||
class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<AccountRow>) :
|
||||
@ -30,7 +32,7 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<A
|
||||
val b = Bundle()
|
||||
b.putString("accp", UserAgent.uas()[position].account.accp)
|
||||
i.putExtras(b)
|
||||
(cxt as Activity).startActivity(i)
|
||||
(cxt as Activity).startActivityForResult(i, ACCOUNT_CODE)
|
||||
}
|
||||
val ua = UserAgent.uas()[position]
|
||||
val actionView = rowView.findViewById(R.id.action) as ImageButton
|
||||
|
||||
@ -12,6 +12,7 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.ViewGroup
|
||||
import android.widget.*
|
||||
|
||||
import com.tutpro.baresip.Account.Companion.checkAuthPass
|
||||
import com.tutpro.baresip.MainActivity.Companion.ACCOUNT_CODE
|
||||
import com.tutpro.baresip.MainActivity.Companion.aorPasswords
|
||||
@ -81,7 +82,8 @@ class AccountsActivity : AppCompatActivity() {
|
||||
val aor = Account.find(data!!.getStringExtra("accp"))!!.aor
|
||||
val ua = UserAgent.uas()[UserAgent.findAorIndex(aor)!!]
|
||||
if (aorPasswords.containsKey(aor) && aorPasswords[aor] == "")
|
||||
askPassword(String.format(getString(R.string.account_password), aor), ua)
|
||||
askPassword(String.format(getString(R.string.account_password),
|
||||
Utils.plainAor(aor)), ua)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,10 +112,7 @@ class AccountsActivity : AppCompatActivity() {
|
||||
String.format(getString(R.string.invalid_authentication_password), password))
|
||||
password = ""
|
||||
}
|
||||
aorPasswords[ua.account.aor] = password
|
||||
account_set_auth_pass(ua.account.accp, password)
|
||||
if (password != "")
|
||||
if (ua.account.regint > 0) Api.ua_register(ua.uap)
|
||||
setAuthPass(ua, password)
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
@ -123,15 +122,14 @@ class AccountsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
if (BaresipService.activities.indexOf("accounts") == -1) return true
|
||||
if (BaresipService.activities.indexOf("accounts") == -1)
|
||||
return true
|
||||
|
||||
when (item.itemId) {
|
||||
|
||||
R.id.help -> {
|
||||
Utils.alertView(this@AccountsActivity, getString(R.string.new_account),
|
||||
getString(R.string.accounts_help))
|
||||
}
|
||||
|
||||
android.R.id.home -> {
|
||||
BaresipService.activities.remove("accounts")
|
||||
val i = Intent()
|
||||
@ -139,25 +137,21 @@ class AccountsActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
||||
menuInflater.inflate(R.menu.accounts_menu, menu)
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
|
||||
BaresipService.activities.remove("accounts")
|
||||
val i = Intent()
|
||||
setResult(Activity.RESULT_OK, i)
|
||||
finish()
|
||||
super.onBackPressed()
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ -188,6 +182,17 @@ class AccountsActivity : AppCompatActivity() {
|
||||
return contents == null || contents.size == 0
|
||||
}
|
||||
|
||||
fun setAuthPass(ua: UserAgent, ap: String) {
|
||||
val acc = ua.account
|
||||
if (account_set_auth_pass(acc.accp, ap) == 0) {
|
||||
acc.authPass = account_auth_pass(acc.accp)
|
||||
aorPasswords[acc.aor] = ap
|
||||
if ((ap != "") && (acc.regint > 0))
|
||||
Api.ua_register(ua.uap)
|
||||
} else {
|
||||
Log.e("Baresip", "Setting of auth pass failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.Manifest
|
||||
import android.app.KeyguardManager
|
||||
import android.app.NotificationManager
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.*
|
||||
import android.content.*
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
@ -19,11 +16,12 @@ import android.text.method.HideReturnsTransformationMethod
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.widget.*
|
||||
import android.view.*
|
||||
import com.tutpro.baresip.Account.Companion.checkAuthPass
|
||||
|
||||
import java.io.File
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
import com.tutpro.baresip.Account.Companion.checkAuthPass
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
internal lateinit var layout: RelativeLayout
|
||||
@ -65,15 +63,8 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.d("Baresip", "Main created with action '$intentAction'")
|
||||
|
||||
kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
if (Build.VERSION.SDK_INT >= 27) {
|
||||
setShowWhenLocked(true)
|
||||
setTurnScreenOn(true)
|
||||
kgm.requestDismissKeyguard(this, null)
|
||||
} else {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
|
||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
|
||||
}
|
||||
dismissKeyguard()
|
||||
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES)
|
||||
|
||||
setContentView(R.layout.activity_main)
|
||||
@ -439,7 +430,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (File(filesDir.absolutePath + "/accounts").exists()) {
|
||||
val accounts = String(Utils.getFileContents(filesDir.absolutePath + "/accounts")!!,
|
||||
Charsets.UTF_8).lines().toMutableList()
|
||||
askAorPasswords(accounts)
|
||||
askPasswords(accounts)
|
||||
} else {
|
||||
// Baresip is started for the first time
|
||||
Utils.requestPermission(this, Manifest.permission.RECORD_AUDIO,
|
||||
@ -980,12 +971,8 @@ class MainActivity : AppCompatActivity() {
|
||||
if (password != "") backup(password)
|
||||
getString(R.string.decrypt_password) ->
|
||||
if (password != "") restore(password)
|
||||
else -> {
|
||||
aorPasswords[ua!!.account.aor] = password
|
||||
account_set_auth_pass(ua.account.accp, password)
|
||||
if (password != "")
|
||||
if (ua.account.regint > 0) Api.ua_register(ua.uap)
|
||||
}
|
||||
else ->
|
||||
AccountsActivity.setAuthPass(ua!!, password)
|
||||
}
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||
@ -994,7 +981,7 @@ class MainActivity : AppCompatActivity() {
|
||||
builder.show()
|
||||
}
|
||||
|
||||
private fun askAorPasswords(accounts: MutableList<String>) {
|
||||
private fun askPasswords(accounts: MutableList<String>) {
|
||||
if (accounts.isNotEmpty()) {
|
||||
val account = accounts.removeAt(0)
|
||||
val params = account.substringAfter(">")
|
||||
@ -1024,16 +1011,16 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
aorPasswords.put(aor, password)
|
||||
}
|
||||
askAorPasswords(accounts)
|
||||
askPasswords(accounts)
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
aorPasswords.put(aor, "")
|
||||
askAorPasswords(accounts)
|
||||
askPasswords(accounts)
|
||||
}
|
||||
builder.show()
|
||||
} else {
|
||||
askAorPasswords(accounts)
|
||||
askPasswords(accounts)
|
||||
}
|
||||
} else {
|
||||
startBaresip()
|
||||
@ -1120,18 +1107,20 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
aorSpinner.setSelection(-1)
|
||||
}
|
||||
baresipService.setAction("UpdateNotification")
|
||||
startService(baresipService)
|
||||
for (ua in UserAgent.uas()) updateIcons(ua.account)
|
||||
if (BaresipService.isServiceRunning) {
|
||||
baresipService.setAction("UpdateNotification")
|
||||
startService(baresipService)
|
||||
}
|
||||
}
|
||||
|
||||
ACCOUNT_CODE -> {
|
||||
val ua = UserAgent.uas()[aorSpinner.selectedItemPosition]
|
||||
val account = ua.account
|
||||
updateIcons(account)
|
||||
if (aorPasswords.containsKey(account.aor) && aorPasswords[account.aor] == "")
|
||||
askPassword(String.format(getString(R.string.account_password),
|
||||
Utils.plainAor(account.aor)), ua)
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
if (aorPasswords.containsKey(account.aor) && aorPasswords[account.aor] == "")
|
||||
askPassword(String.format(getString(R.string.account_password),
|
||||
Utils.plainAor(account.aor)), ua)
|
||||
}
|
||||
|
||||
CONTACTS_CODE -> {
|
||||
@ -1444,6 +1433,19 @@ class MainActivity : AppCompatActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun dismissKeyguard() {
|
||||
if (Build.VERSION.SDK_INT >= 27) {
|
||||
setShowWhenLocked(true)
|
||||
setTurnScreenOn(true)
|
||||
kgm.requestDismissKeyguard(this, null)
|
||||
} else {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
|
||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
|
||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
var visible = false
|
||||
|
||||
Reference in New Issue
Block a user