Fetch contacts when service starts instead of waiting for main activity to be started, otherwise won't have any contact after auto start on boot
This commit is contained in:
parent
011ac4aa9f
commit
7f59bc2f95
4 changed files with 19 additions and 17 deletions
|
@ -191,15 +191,16 @@ public final class LinphoneService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
mNotificationManager = new NotificationsManager(this);
|
mNotificationManager = new NotificationsManager(this);
|
||||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)
|
|
||||||
&& intent != null
|
|
||||||
&& intent.getBooleanExtra("ForceStartForeground", false)) {
|
|
||||||
// We need to call this asap
|
|
||||||
mNotificationManager.startForeground();
|
|
||||||
}
|
|
||||||
|
|
||||||
mLinphoneManager = new LinphoneManager(this);
|
mLinphoneManager = new LinphoneManager(this);
|
||||||
sInstance = this; // sInstance is ready once linphone manager has been created
|
sInstance = this; // sInstance is ready once linphone manager has been created
|
||||||
|
if (Version.sdkAboveOrEqual(Version.API26_O_80)
|
||||||
|
&& intent != null
|
||||||
|
&& intent.getBooleanExtra("ForceStartForeground", false)) {
|
||||||
|
// We need to call this asap after the Service can be accessed through it's singleton
|
||||||
|
mNotificationManager.startForeground();
|
||||||
|
}
|
||||||
|
|
||||||
mLinphoneManager.startLibLinphone(isPush);
|
mLinphoneManager.startLibLinphone(isPush);
|
||||||
LinphoneManager.getCore().addListener(mListener);
|
LinphoneManager.getCore().addListener(mListener);
|
||||||
|
|
||||||
|
@ -212,6 +213,10 @@ public final class LinphoneService extends Service {
|
||||||
.registerContentObserver(
|
.registerContentObserver(
|
||||||
ContactsContract.Contacts.CONTENT_URI, true, mContactsManager);
|
ContactsContract.Contacts.CONTENT_URI, true, mContactsManager);
|
||||||
}
|
}
|
||||||
|
if (mContactsManager.hasReadContactsAccess()) {
|
||||||
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
|
}
|
||||||
|
ContactsManager.getInstance().initializeContactManager();
|
||||||
|
|
||||||
Compatibility.createChatShortcuts(this);
|
Compatibility.createChatShortcuts(this);
|
||||||
mOrientationHelper.enable();
|
mOrientationHelper.enable();
|
||||||
|
|
|
@ -280,11 +280,6 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
||||||
|
|
||||||
requestRequiredPermissions();
|
requestRequiredPermissions();
|
||||||
|
|
||||||
if (checkPermission(Manifest.permission.READ_CONTACTS)) {
|
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
|
||||||
}
|
|
||||||
ContactsManager.getInstance().initializeContactManager();
|
|
||||||
|
|
||||||
if (DeviceUtils.isAppUserRestricted(this)) {
|
if (DeviceUtils.isAppUserRestricted(this)) {
|
||||||
Log.w(
|
Log.w(
|
||||||
"[Main Activity] Device has been restricted by user (Android 9+), push notifications won't work !");
|
"[Main Activity] Device has been restricted by user (Android 9+), push notifications won't work !");
|
||||||
|
|
|
@ -99,6 +99,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange, Uri uri) {
|
public void onChange(boolean selfChange, Uri uri) {
|
||||||
|
Log.i("[Contacts Manager] Content observer detected a changing in at least one contact");
|
||||||
fetchContactsAsync();
|
fetchContactsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
mContext.getContentResolver().unregisterContentObserver(ContactsManager.getInstance());
|
mContext.getContentResolver().unregisterContentObserver(this);
|
||||||
|
|
||||||
if (mLoadContactTask != null) {
|
if (mLoadContactTask != null) {
|
||||||
mLoadContactTask.cancel(true);
|
mLoadContactTask.cancel(true);
|
||||||
|
@ -256,7 +257,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
&& hasWriteContactsAccess()
|
&& hasWriteContactsAccess()
|
||||||
&& hasWriteSyncPermission()) {
|
&& hasWriteSyncPermission()) {
|
||||||
if (LinphoneService.isReady()) {
|
if (LinphoneService.isReady()) {
|
||||||
ContactsManager.getInstance().initializeSyncAccount();
|
initializeSyncAccount();
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,7 +463,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
public void onPresenceReceived(FriendList list, Friend[] friends) {
|
public void onPresenceReceived(FriendList list, Friend[] friends) {
|
||||||
boolean updated = false;
|
boolean updated = false;
|
||||||
for (Friend lf : friends) {
|
for (Friend lf : friends) {
|
||||||
boolean newContact = ContactsManager.getInstance().refreshSipContact(lf);
|
boolean newContact = refreshSipContact(lf);
|
||||||
if (newContact) {
|
if (newContact) {
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,15 @@ public class BootReceiver extends BroadcastReceiver {
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SHUTDOWN)) {
|
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SHUTDOWN)) {
|
||||||
android.util.Log.d(
|
android.util.Log.d(
|
||||||
"LinphoneBootReceiver",
|
"Linphone",
|
||||||
"Device is shutting down, destroying Core to unregister");
|
"[Boot Receiver] Device is shutting down, destroying Core to unregister");
|
||||||
context.stopService(
|
context.stopService(
|
||||||
new Intent(Intent.ACTION_MAIN).setClass(context, LinphoneService.class));
|
new Intent(Intent.ACTION_MAIN).setClass(context, LinphoneService.class));
|
||||||
} else {
|
} else {
|
||||||
|
LinphonePreferences.instance().setContext(context);
|
||||||
boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
|
boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
|
||||||
android.util.Log.i(
|
android.util.Log.i(
|
||||||
"LinphoneBootReceiver", "Device is starting, auto_start is " + autostart);
|
"Linphone", "[Boot Receiver] Device is starting, auto_start is " + autostart);
|
||||||
if (autostart && !LinphoneService.isReady()) {
|
if (autostart && !LinphoneService.isReady()) {
|
||||||
Intent serviceIntent = new Intent(Intent.ACTION_MAIN);
|
Intent serviceIntent = new Intent(Intent.ACTION_MAIN);
|
||||||
serviceIntent.setClass(context, LinphoneService.class);
|
serviceIntent.setClass(context, LinphoneService.class);
|
||||||
|
|
Loading…
Reference in a new issue