Java.lang.SecurityException: without permission android.permission.BIND_INPUT_METHOD only for <= 2.2
I have this very unusual exception. The thing is, I have this application that has a button to launch
InputMethodService
which starts like this
public class MyGroovyIme extends InputMethodService {
and this is how it looks in the manifest.
<service android:name=".MyGroovyIme" android:enabled="true" android:exported="true" android:permission="android.permission.BIND_INPUT_METHOD" > <intent-filter> <action android:name="android.view.InputMethod" /> <!-- <category android:name="android.intent.category.DEFAULT" /> --> </intent-filter> <meta-data android:name="android.view.im" android:resource="@xml/method" /> </service>
and this is how i start the service
void startServer() { Log.v(TAG, "Starting service..."); Intent serviceIntent = new Intent(this, MyGroovyIme.class); startService(serviceIntent); Log.v(TAG, "Starting service...success!!!"); // this.finish(); Log.v(TAG, "finish called..."); }
the whole setup works like a charm when I do it on a tablet (Moto XOOM, its 3.2), but when I do it on devices that run 2.2 and 2.1 (I haven't tried this on 2.3 and couldn't use an emulator) this is what i get
java.lang.SecurityException: Not allowed to start service Intent { cmp=com.spp.ime.demo/.MyGroovyIme } without permission android.permission.BIND_INPUT_METHOD at android.app.ContextImpl.startService(ContextImpl.java:840) at android.content.ContextWrapper.startService(ContextWrapper.java:336) at com.spp.ime.demo.GROOVY_IME_DEMOActivity.startServer(GROOVY_IME_DEMOActivity.java:137) at com.spp.ime.demo.GROOVY_IME_DEMOActivity.onStartClick(GROOVY_IME_DEMOActivity.java:104) at com.spp.ime.demo.GROOVY_IME_DEMOActivity.onClick(GROOVY_IME_DEMOActivity.java:67) at android.view.View.performClick(View.java:2408) at android.view.View$PerformClick.run(View.java:8816) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4633) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at dalvik.system.NativeStart.main(Native Method)
I understand security concerns, but shouldn't be the same for all devices, or I am missing something specific for versions <3.2
source share
After a long search, they have not found a reliable answer and still have not received the exact reason. but through new features found hardware features that were added in later versions may have led to this indulgence in Android OS. Here is a link describing major Android updates here
source share
// only work for pre-lolipop <uses-permission android:name="android.permission.BIND_INPUT_METHOD" tools:ignore="ProtectedPermissions" android:protectionLevel="signature" /> <service android:name="SimpleIME" android:permission="android.permission.BIND_INPUT_METHOD" android:protectionLevel="signature"> <intent-filter> <action android:name="android.view.InputMethod" /> </intent-filter> <meta-data android:name="android.view.im" android:resource="@xml/method" /> </service> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" />
source share