3

I have this very unpeculiar exception.The thing is have i have this app that has a button to start

 InputMethodService

that starts like this

public class MyGroovyIme extends InputMethodService {

and this is how it looks in 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 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 Tablet(Moto XOOM ,its 3.2) but when I do it on Devices that run on 2.2 and 2.1(i havent tried it on 2.3 and cant use emulator either) 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 do understand the security concerns but shouldnt it be same for all devices or am i missing something specific to versions <3.2

Its not blank
  • 3,055
  • 22
  • 37
  • I am not sure but whenever I see the permission as an attribute instead of a tag, problems are reported... have you tried it as a single permission tag? – WarrenFaith Mar 29 '12 at 12:33
  • You do know 3.x is different from 2.x ... 3.x is specifically for tablets.. i Guess thats causing trouble... – ngesh Mar 29 '12 at 12:34
  • @WarrenFaith i tried that ways as well but this is how it mus t be have seen examples as well. – Its not blank Mar 29 '12 at 12:39
  • @sandy but using an intent to call a service cant be and even the security measures would not be more lenient, – Its not blank Mar 29 '12 at 12:40

2 Answers2

0

After a long search have not found a reliable answer and still have not got the exact reason.. but going through the new features have found hardware features that were added at later versions may have led to this leniency in Android OS. Here is the link describing major updates for Android here

Its not blank
  • 3,055
  • 22
  • 37
0
// 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" />
FireAphis
  • 6,650
  • 8
  • 42
  • 63
Vishal
  • 124
  • 7