Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
e1e9372c
Commit
e1e9372c
authored
Oct 20, 2020
by
Sylvain Berfini
🐮
Browse files
Ensure Service is started when a call is received or is initiated
parent
4db329c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
+34
-2
wrappers/java/classes/org/linphone/core/tools/service/CoreManager.java
.../classes/org/linphone/core/tools/service/CoreManager.java
+34
-2
No files found.
wrappers/java/classes/org/linphone/core/tools/service/CoreManager.java
View file @
e1e9372c
...
...
@@ -20,6 +20,8 @@
package
org.linphone.core.tools.service
;
import
android.app.Application
;
import
android.app.ActivityManager
;
import
android.app.ActivityManager.RunningServiceInfo
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
...
...
@@ -145,6 +147,22 @@ public class CoreManager {
}
mListener
=
new
CoreListenerStub
()
{
@Override
public
void
onFirstCallStarted
(
Core
core
)
{
Log
.
i
(
"[Core Manager] First call started"
);
// Ensure Service is running. It will take care by itself to start as foreground.
if
(!
isServiceRunning
())
{
Log
.
w
(
"[Core Manager] Service isn't running, let's start it"
);
try
{
startService
();
}
catch
(
IllegalStateException
ise
)
{
Log
.
w
(
"[Core Manager] Failed to start service: "
,
ise
);
}
}
else
{
Log
.
i
(
"[Core Manager] Service appears to be running, everything is fine"
);
}
}
@Override
public
void
onLastCallEnded
(
Core
core
)
{
Log
.
i
(
"[Core Manager] Last call ended"
);
...
...
@@ -187,8 +205,7 @@ public class CoreManager {
try
{
mServiceClass
=
getServiceClass
();
if
(
mServiceClass
==
null
)
mServiceClass
=
CoreService
.
class
;
mContext
.
startService
(
new
Intent
().
setClass
(
mContext
,
mServiceClass
));
Log
.
i
(
"[Core Manager] Starting service "
,
mServiceClass
.
getName
());
//startService();
}
catch
(
IllegalStateException
ise
)
{
Log
.
w
(
"[Core Manager] Failed to start service: "
,
ise
);
// On Android > 8, if app in background, startService will trigger an IllegalStateException when called from background
...
...
@@ -291,6 +308,21 @@ public class CoreManager {
return
null
;
}
private
void
startService
()
{
mContext
.
startService
(
new
Intent
().
setClass
(
mContext
,
mServiceClass
));
Log
.
i
(
"[Core Manager] Starting service "
,
mServiceClass
.
getName
());
}
private
boolean
isServiceRunning
()
{
ActivityManager
manager
=
(
ActivityManager
)
mContext
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
for
(
RunningServiceInfo
service
:
manager
.
getRunningServices
(
Integer
.
MAX_VALUE
))
{
if
(
mServiceClass
.
getName
().
equals
(
service
.
service
.
getClassName
()))
{
return
true
;
}
}
return
false
;
}
private
boolean
isAndroidXMediaAvailable
()
{
boolean
available
=
false
;
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment