Fixed start at boot time crash on Android O

This commit is contained in:
Sylvain Berfini 2017-11-17 12:01:13 +01:00
parent 352701270b
commit 808d03494f
4 changed files with 25 additions and 9 deletions

View file

@ -19,18 +19,19 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LpConfig;
import org.linphone.mediastream.Log;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LpConfig;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
LinphonePreferences.instance().setContext(context);
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SHUTDOWN)) {
android.util.Log.d("LinphoneBootReceiver", "Device is shutting down, destroying LinphoneCore to unregister");
LinphoneManager.destroy();
@ -42,11 +43,7 @@ public class BootReceiver extends BroadcastReceiver {
if (autostart) {
Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
try {
context.startService(lLinphoneServiceIntent);
} catch (RuntimeException e) {
Log.e(e);
}
Compatibility.startService(context, lLinphoneServiceIntent);
}
}
}

View file

@ -6,6 +6,7 @@ import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
@ -137,4 +138,8 @@ public class ApiSixteenPlus {
return notif;
}
public static void startService(Context context, Intent intent) {
context.startService(intent);
}
}

View file

@ -7,6 +7,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.AudioAttributes;
import android.view.ViewTreeObserver;
@ -176,4 +177,8 @@ public class ApiTwentySixPlus {
return notif;
}
public static void startService(Context context, Intent intent) {
context.startForegroundService(intent);
}
}

View file

@ -23,6 +23,7 @@ import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.PowerManager;
@ -154,4 +155,12 @@ public class Compatibility {
ApiElevenPlus.scheduleAlarm(alarmManager, type, triggerAtMillis, operation);
}
}
public static void startService(Context context, Intent intent) {
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
ApiTwentySixPlus.startService(context, intent);
} else {
ApiSixteenPlus.startService(context, intent);
}
}
}