title: Airplane mode in Jelly Bean
body: <p>I am trying to set the airplane mode in a Nexus 4 with Android 4.2.2.
  I know it is not possible since AIRPLANE_MODE_ON was moved to <a href="http://developer.android.com/reference/android/provider/Settings.Global.html" rel="noreferrer">Global system settings</a> and it is just a read option.</p>
  
  <p>Is there any other way to do something similar, I mean disable the radio? I can disable Bluetooth, wifi and Internet connection, but the phone call network is still active.</p>
  
  <p>Could be possible to create a library with the <a href="http://developer.android.com/tools/sdk/ndk/index.html" rel="noreferrer">NDK</a> to disable completely the network?</p>
  
  <p><strong>EDIT</strong>: I have tried with <code>java.lang.reflect</code> making this method:</p>
  
  <pre><code>@SuppressLint("NewApi")
  @SuppressWarnings("rawtypes")
  private boolean putStringAirplaneMode() throws ClassNotFoundException,
          NoSuchMethodException, IllegalArgumentException,
          IllegalAccessException, InvocationTargetException {
  
      ContentResolver resolver = context.getContentResolver();
      String name = Settings.Global.AIRPLANE_MODE_ON;
      String value = (isEnabled() ? "1" : "0");
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN_MR1) {
          Log.v("AirplaneBatterySaver",
                  "Using reflection to change airplane mode");
          // For JELLY_BEAN_MR1 use reflection. TODO test if works reflection
          Class SystemProperties = android.provider.Settings.Global.class;
  
          Class[] parameterTypes = new Class[3];
          parameterTypes[0] = ContentResolver.class;
          parameterTypes[1] = String.class;
          parameterTypes[2] = String.class;
  
          @SuppressWarnings("unchecked")
          Method method = SystemProperties.getMethod("putString",
                  parameterTypes);
  
          method.setAccessible(true);
          return (Boolean) method.invoke(new Object(), resolver, name, value);
          // return Settings.Global.putString(resolver, name, value);
  
      } else {
          Log.v("AirplaneBatterySaver",
                  "Using Settings.System to change airplane mode");
          return Settings.System.putString(resolver, name, value);
      }
  }
  </code></pre>
  
  <p>As you can see I replace the method <code>Settings.System.putString(resolver, name, value);</code> over <code>JELLY_BEAN_MR1</code> but, of course, I am getting a <code>SecurityException</code> because my app is not a system app. This is the trace:</p>
  
  <pre><code>Caused by: java.lang.SecurityException: Permission denial: writing to secure 
      settings requires android.permission.WRITE_SECURE_SETTINGS
  at android.os.Parcel.readException(Parcel.java:1425)
  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
  at android.content.ContentProviderProxy.call(ContentProviderNative.java:574)
  at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:777)
  at android.provider.Settings$Global.putStringForUser(Settings.java:5421)
  at android.provider.Settings$Global.putString(Settings.java:5411)
  </code></pre>
  
  <p>If I use <code>&lt;uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/&gt;</code> I get the error <code>Permission is only granted to system apps</code>. I was checking the SDK sources (in the files from the trace) to try to find a way to set the airplane mode without this permission but I did not get any success.</p>