Bug 17687 - Implicit intents with startService are not safe in Android 4.4.2
Summary: Implicit intents with startService are not safe in Android 4.4.2
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.10.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-02-10 10:38 UTC by Allie Miller
Modified: 2014-02-10 14:39 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Allie Miller 2014-02-10 10:38:26 UTC
When deploying the attached project to Genymotion emulator (2.11 using the Nexus 10, Android version 4.3 virtual device), the project deploys as expected.

However, when attempting to deploy using a real Nexus 7 (Android version 4.4.2) the app fails with the following message:

[ContextImpl] Implicit intents with startService are not safe: Intent {
act=com.mayastudios.sqlite.SharedLibraryProviderService (has extras) }
android.content.ContextWrapper.startService:494
mono.java.lang.RunnableImplementor.n_run:-2
mono.java.lang.RunnableImplementor.run:29

Attached to this bug report is the Test project, the steps to reproduce the error and the logcat from the failed deployment.

Versioning Information:
Xamarin Studio
Version 4.2.2 (build 2)
Runtime:
Microsoft .NET 4.0.30319.18408
GTK+ 2.24.20 theme: MS-Windows
GTK# (2.12.0.0)
Xamarin.Android
Version: 4.10.2 (Business Edition)
Operating System
Windows 6.1.7601.65536 (64-bit)
Comment 4 Jonathan Pryor 2014-02-10 14:39:26 UTC
The crash and the message about Implicit intents are unrelated.

The crash is due to missing libsqlitex.so:

> [mono] Unhandled Exception:
> [mono] System.TypeInitializationException: An exception was thrown by the type initializer for spatialite.SLDatabaseConnection ---> System.TypeInitializationException: An exception was thrown by the type initializer for sqlite.SQLiteLibrary ---> System.InvalidOperationException: Shared library service for 'libsqlitex.so' is not installed.
> [mono]   at AndroidSharedLibraryProvider.SharedLibraryLoader.GetData () [0x00000] in <filename unknown>:0
> [mono]   at AndroidSharedLibraryProvider.SharedLibraryLoader.LoadLibrary () [0x00000] in <filename unknown>:0
> [mono]   at sqlite.SQLiteLibrary..cctor () [0x00000] in <filename unknown>:0
> [mono]   --- End of inner exception stack trace ---
> [mono]   at spatialite.SpatialiteLibLoader.Load () [0x00000] in <filename unknown>:0
> [mono]   at spatialite.SLDatabaseConnection..cctor () [0x00000] in <filename unknown>:0
> [mono]   --- End of inner exception stack trace ---
> [mono]   at SpatialiteExample.Example.RunExample () [0x00000] in <filename unknown>:0
> [mono]   at SpatialiteExample.SpatialiteDemoActivity+<>c__DisplayCla

libsqlitex.so is in turn missing because it has the wrong Build action within SpatialiteSharedLibrary.MonoDroid/SpatialiteSharedLibrary.csproj; it's marked as an @(AndroidAsset) instead of as an @(AndroidNativeLibrary).

Please use the appropriate Build action for .so files.

The message about Implicit intents is due to SQLite/SharedLibrary.MonoDroid/SharedLibraryLoader.cs: RunOnServiceThread():

	var serviceIntent = new Intent(SharedLibraryProviderConfig.GET_LIB_PATH_ACTION);
	serviceIntent.PutExtra(SharedConstants.REPLY_MESSENGER_KEY, replyMessenger);
	
	if (Application.Context.StartService(serviceIntent) == null) {
		...

The reason Android is complaining is because "any" app could provide a Service with the same //intent-filter/action value within AndroidManifest.xml, and thus the service launcher can't know for sure what Service will _actually_ be launched in response to the StartService() call.

The fix is to explicitly specify the Service that you wish to launch:

	var serviceIntent = new Intent(Android.App.Application.Context, typeof(SharedLibraryService));
	serviceIntent.SetAction(SharedLibraryProviderConfig.GET_LIB_PATH_ACTION);
	serviceIntent.PutExtra(SharedConstants.REPLY_MESSENGER_KEY, replyMessenger);
	
	if (Application.Context.StartService(serviceIntent) == null) {
		...