title: java.lang.SecurityException: Neither user 10032 nor current process has android.permission.MODIFY_PHONE_STATE
body: <p>I'm working on a service to auto PIN/PUK when starting device.
  Service is launched at Boot time.
  I'm using ITelephony with reflexive methods.
  My phone is lollipop 5.1.1, it's a rooted nexus 5.
  My manifest has 
      
  Android Studio says "Permission is only granted to system apps"</p>
  
  <p>I'm using this code snippet :</p>
  
  <pre><code>    TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
          int state = tm.getSimState();
  
          if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
          {
              Log.d(TAG,"PIN PUK STATE = " + state );
  
  
              if (state  == TelephonyManager.SIM_STATE_PIN_REQUIRED ){
                  try {
                      message += ", PIN Code required" ;
                      Class clazz = Class.forName(tm.getClass().getName());
                      if (clazz != null) {
                          Method m = clazz.getDeclaredMethod("getITelephony");
                          m.setAccessible(true);
                          Object iTelephony = m.invoke(tm);
  
                          Class params[] = new Class[1];
                          params[0] = String.class;
  
                          Method m2 = iTelephony.getClass().getDeclaredMethod("supplyPin", params);
                          m2.setAccessible(true);
  
                          Object i = m2.invoke(iTelephony, "1111");
  
                          Log.d(TAG, m2.toString() + " *** " + i.toString());
                      }
                  }catch (Exception e) {
                      Log.d(TAG,"Impossible to unlock " + e.toString());
                      e.printStackTrace();
  
                  }
              }
  </code></pre>
  
  <p>And I get this log :</p>
  
  <pre><code>07-20 10:31:33.109    1267-1267/eu.cabrera.pinunlocker W/System.err﹕ Caused by: java.lang.SecurityException: Neither user 10032 nor current process has android.permission.MODIFY_PHONE_STATE.
  07-20 10:31:33.112    1267-1267/eu.cabrera.pinunlocker W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1546)
  07-20 10:31:33.112    1267-1267/eu.cabrera.pinunlocker W/System.err﹕ at android.os.Parcel.readException(Parcel.java:1499)
  07-20 10:31:33.112    1267-1267/eu.cabrera.pinunlocker W/System.err﹕ at com.android.internal.telephony.ITelephony$Stub$Proxy.supplyPin(ITelephony.java:1540)
  </code></pre>
  
  <p>I've tested with a regular app and now with a system app, same problem.</p>
  
  <p>Am I doing something bad? Is my app really system? I have copied eu.cabrera.pinunlocker.apk to <code>/system/app</code></p>
  
  <p>What do I need to grant my app the android.permission.MODIFY_PHONE_STATE?</p>
  
  <p>Thanks for your help.
  Antoine</p>