Code styling
This commit is contained in:
@@ -176,7 +176,8 @@ class BaresipService: Service() {
|
|||||||
val vibratorManager = getSystemService(VIBRATOR_MANAGER_SERVICE) as
|
val vibratorManager = getSystemService(VIBRATOR_MANAGER_SERVICE) as
|
||||||
VibratorManager
|
VibratorManager
|
||||||
vibratorManager.defaultVibrator
|
vibratorManager.defaultVibrator
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
getSystemService(VIBRATOR_SERVICE) as Vibrator
|
getSystemService(VIBRATOR_SERVICE) as Vibrator
|
||||||
}
|
}
|
||||||
@@ -253,9 +254,9 @@ class BaresipService: Service() {
|
|||||||
if ("android.net.wifi.WIFI_AP_STATE_CHANGED" == action) {
|
if ("android.net.wifi.WIFI_AP_STATE_CHANGED" == action) {
|
||||||
val state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0)
|
val state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0)
|
||||||
if (WifiManager.WIFI_STATE_ENABLED == state % 10) {
|
if (WifiManager.WIFI_STATE_ENABLED == state % 10) {
|
||||||
if (hotSpotIsEnabled) {
|
if (hotSpotIsEnabled)
|
||||||
Log.d(TAG, "HotSpot is still enabled")
|
Log.d(TAG, "HotSpot is still enabled")
|
||||||
} else {
|
else {
|
||||||
Log.d(TAG, "HotSpot is enabled")
|
Log.d(TAG, "HotSpot is enabled")
|
||||||
hotSpotIsEnabled = true
|
hotSpotIsEnabled = true
|
||||||
Timer().schedule(1000) {
|
Timer().schedule(1000) {
|
||||||
@@ -273,15 +274,16 @@ class BaresipService: Service() {
|
|||||||
Timer().schedule(2000) {
|
Timer().schedule(2000) {
|
||||||
updateNetwork()
|
updateNetwork()
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
Log.w(TAG, "Could not get hotspot addresses")
|
Log.w(TAG, "Could not get hotspot addresses")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
if (!hotSpotIsEnabled) {
|
if (!hotSpotIsEnabled)
|
||||||
Log.d(TAG, "HotSpot is still disabled")
|
Log.d(TAG, "HotSpot is still disabled")
|
||||||
} else {
|
else {
|
||||||
Log.d(TAG, "HotSpot is disabled")
|
Log.d(TAG, "HotSpot is disabled")
|
||||||
hotSpotIsEnabled = false
|
hotSpotIsEnabled = false
|
||||||
if (hotSpotAddresses.isNotEmpty()) {
|
if (hotSpotAddresses.isNotEmpty()) {
|
||||||
@@ -348,39 +350,38 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED -> {
|
BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED -> {
|
||||||
val state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE,
|
val state = intent.getIntExtra(
|
||||||
BluetoothHeadset.STATE_AUDIO_DISCONNECTED)
|
BluetoothHeadset.EXTRA_STATE,
|
||||||
|
BluetoothHeadset.STATE_AUDIO_DISCONNECTED
|
||||||
|
)
|
||||||
when (state) {
|
when (state) {
|
||||||
BluetoothHeadset.STATE_AUDIO_CONNECTED -> {
|
BluetoothHeadset.STATE_AUDIO_CONNECTED ->
|
||||||
Log.d(TAG, "Bluetooth headset audio is connected")
|
Log.d(TAG, "Bluetooth headset audio is connected")
|
||||||
}
|
BluetoothHeadset.STATE_AUDIO_DISCONNECTED ->
|
||||||
BluetoothHeadset.STATE_AUDIO_DISCONNECTED -> {
|
|
||||||
Log.d(TAG, "Bluetooth headset audio is disconnected")
|
Log.d(TAG, "Bluetooth headset audio is disconnected")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED -> {
|
AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED -> {
|
||||||
val state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,
|
val state = intent.getIntExtra(
|
||||||
AudioManager.SCO_AUDIO_STATE_DISCONNECTED)
|
AudioManager.EXTRA_SCO_AUDIO_STATE,
|
||||||
|
AudioManager.SCO_AUDIO_STATE_DISCONNECTED
|
||||||
|
)
|
||||||
when (state) {
|
when (state) {
|
||||||
AudioManager.SCO_AUDIO_STATE_CONNECTING -> {
|
AudioManager.SCO_AUDIO_STATE_CONNECTING ->
|
||||||
Log.d(TAG, "Bluetooth headset SCO is connecting")
|
Log.d(TAG, "Bluetooth headset SCO is connecting")
|
||||||
}
|
AudioManager.SCO_AUDIO_STATE_CONNECTED ->
|
||||||
AudioManager.SCO_AUDIO_STATE_CONNECTED -> {
|
|
||||||
Log.d(TAG, "Bluetooth headset SCO is connected")
|
Log.d(TAG, "Bluetooth headset SCO is connected")
|
||||||
}
|
|
||||||
AudioManager.SCO_AUDIO_STATE_DISCONNECTED -> {
|
AudioManager.SCO_AUDIO_STATE_DISCONNECTED -> {
|
||||||
Log.d(TAG, "Bluetooth headset SCO is disconnected")
|
Log.d(TAG, "Bluetooth headset SCO is disconnected")
|
||||||
resetCallVolume()
|
resetCallVolume()
|
||||||
}
|
}
|
||||||
AudioManager.SCO_AUDIO_STATE_ERROR -> {
|
AudioManager.SCO_AUDIO_STATE_ERROR ->
|
||||||
Log.d(TAG, "Bluetooth headset SCO state ERROR")
|
Log.d(TAG, "Bluetooth headset SCO state ERROR")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val bluetoothFilter = IntentFilter()
|
val bluetoothFilter = IntentFilter()
|
||||||
bluetoothFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)
|
bluetoothFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)
|
||||||
@@ -395,13 +396,13 @@ class BaresipService: Service() {
|
|||||||
bluetoothReceiverRegistered = true
|
bluetoothReceiverRegistered = true
|
||||||
|
|
||||||
telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
|
||||||
if (VERSION.SDK_INT >= 31) {
|
if (VERSION.SDK_INT >= 31)
|
||||||
telephonyCallback = object : TelephonyCallback(), TelephonyCallback.ServiceStateListener {
|
telephonyCallback = object : TelephonyCallback(), TelephonyCallback.ServiceStateListener {
|
||||||
override fun onServiceStateChanged(serviceState: ServiceState) {
|
override fun onServiceStateChanged(serviceState: ServiceState) {
|
||||||
updateMobileStatusFromServiceState(serviceState.state)
|
updateMobileStatusFromServiceState(serviceState.state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
phoneStateListener = object : PhoneStateListener() {
|
phoneStateListener = object : PhoneStateListener() {
|
||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
@@ -414,9 +415,10 @@ class BaresipService: Service() {
|
|||||||
proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
proximityWakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
||||||
"com.tutpro.baresip:proximity_wakelock")
|
"com.tutpro.baresip:proximity_wakelock")
|
||||||
|
|
||||||
wifiLock = if (VERSION.SDK_INT < 29)
|
wifiLock = if (VERSION.SDK_INT < 29) {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Baresip")
|
wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Baresip")
|
||||||
|
}
|
||||||
else
|
else
|
||||||
wm.createWifiLock(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "Baresip")
|
wm.createWifiLock(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "Baresip")
|
||||||
wifiLock.setReferenceCounted(false)
|
wifiLock.setReferenceCounted(false)
|
||||||
@@ -466,7 +468,8 @@ class BaresipService: Service() {
|
|||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
action = "Start"
|
action = "Start"
|
||||||
Log.d(TAG, "Received onStartCommand with null intent")
|
Log.d(TAG, "Received onStartCommand with null intent")
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Utils.dumpIntent(intent)
|
// Utils.dumpIntent(intent)
|
||||||
action = intent.action!!
|
action = intent.action!!
|
||||||
Log.d(TAG, "Received onStartCommand action $action")
|
Log.d(TAG, "Received onStartCommand action $action")
|
||||||
@@ -540,9 +543,9 @@ class BaresipService: Service() {
|
|||||||
Contact.contactsUpdate()
|
Contact.contactsUpdate()
|
||||||
|
|
||||||
val history = CallHistory.get()
|
val history = CallHistory.get()
|
||||||
if (history.isEmpty()) {
|
if (history.isEmpty())
|
||||||
CallHistoryNew.restore()
|
CallHistoryNew.restore()
|
||||||
} else {
|
else
|
||||||
for (old in history) {
|
for (old in history) {
|
||||||
val new = CallHistoryNew(old.aor, old.peerUri, old.direction)
|
val new = CallHistoryNew(old.aor, old.peerUri, old.direction)
|
||||||
new.stopTime = old.stopTime
|
new.stopTime = old.stopTime
|
||||||
@@ -550,7 +553,6 @@ class BaresipService: Service() {
|
|||||||
new.recording = old.recording
|
new.recording = old.recording
|
||||||
new.add()
|
new.add()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Blocked.restore()
|
Blocked.restore()
|
||||||
BlockRule.restore()
|
BlockRule.restore()
|
||||||
@@ -610,17 +612,14 @@ class BaresipService: Service() {
|
|||||||
toast(getString(R.string.no_aec), Toast.LENGTH_LONG)
|
toast(getString(R.string.no_aec), Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
|
|
||||||
"Notification Dismissed" -> {
|
"Notification Dismissed" ->
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
}
|
|
||||||
|
|
||||||
"Start Content Observer" -> {
|
"Start Content Observer" ->
|
||||||
registerAndroidContactsObserver()
|
registerAndroidContactsObserver()
|
||||||
}
|
|
||||||
|
|
||||||
"Stop Content Observer" -> {
|
"Stop Content Observer" ->
|
||||||
unRegisterAndroidContactsObserver()
|
unRegisterAndroidContactsObserver()
|
||||||
}
|
|
||||||
|
|
||||||
"Call Answer" -> {
|
"Call Answer" -> {
|
||||||
val callp = intent!!.getLongExtra("callp", 0L)
|
val callp = intent!!.getLongExtra("callp", 0L)
|
||||||
@@ -639,9 +638,9 @@ class BaresipService: Service() {
|
|||||||
nm.cancel(CALL_NOTIFICATION_ID)
|
nm.cancel(CALL_NOTIFICATION_ID)
|
||||||
stopRinging()
|
stopRinging()
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
if (call == null) {
|
if (call == null)
|
||||||
Log.w(TAG, "onStartCommand did not find call $callp")
|
Log.w(TAG, "onStartCommand did not find call $callp")
|
||||||
} else {
|
else {
|
||||||
val peerUri = call.peerUri
|
val peerUri = call.peerUri
|
||||||
val aor = call.ua.account.aor
|
val aor = call.ua.account.aor
|
||||||
Log.d(TAG, "Aor $aor rejected incoming call $callp from $peerUri")
|
Log.d(TAG, "Aor $aor rejected incoming call $callp from $peerUri")
|
||||||
@@ -733,18 +732,16 @@ class BaresipService: Service() {
|
|||||||
msg.direction = MESSAGE_UP_FAIL
|
msg.direction = MESSAGE_UP_FAIL
|
||||||
msg.responseReason = getString(R.string.message_failed)
|
msg.responseReason = getString(R.string.message_failed)
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
ua.account.unreadMessages = Message.unreadMessages(aor)
|
ua.account.unreadMessages = Message.unreadMessages(aor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
nm.cancel(MESSAGE_NOTIFICATION_ID)
|
nm.cancel(MESSAGE_NOTIFICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
"Update Notification" -> {
|
"Update Notification" ->
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
}
|
|
||||||
|
|
||||||
"Start Call" -> {
|
"Start Call" -> {
|
||||||
val uap = intent!!.getLongExtra("uap", 0L)
|
val uap = intent!!.getLongExtra("uap", 0L)
|
||||||
@@ -766,10 +763,9 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else ->
|
||||||
Log.e(TAG, "Unknown start action $action")
|
Log.e(TAG, "Unknown start action $action")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user