title: My custom system app doesn't toggle FlightMode as it should
body: <p>My girlfriend has a problem with her Samsung Galaxy S with Cyanogenmod 10.2. Every time she restarts her phone, the APN list is empty and she can't add new (which means she can't use mobile internet nor send/receive MMS). To temporarily fix it until next reboot, she needs to turn airplane mode on, wait few seconds, and then turn airplane mode off again.</p>
  
  <p>To ease things up, I've written a simple application which is supposed to do it instead of her. But it doesn't work - I see in logs that the app was started, but it doesn't toggle Airplane mode.</p>
  
  <p>Permissions should be set correctly, I even installed the app into /system/app to make Android think it's a system app. The permissions are displayed correctly when I look at the application in Applications list.</p>
  
  <p>Here's my code:</p>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="cz.berzeger.autoflightmode"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="18"
          android:targetSdkVersion="18" /&gt;
  
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_SETTINGS" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
          &lt;service android:name=".AutoFlightModeService" android:label="AutoFlightMode Service" /&gt;
  
          &lt;receiver
              android:name=".ServiceReceiver"
              android:enabled="true"
              android:exported="true"
              android:label="ServiceReceiver"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>ServiceReceiver.java</p>
  
  <pre><code>package cz.berzeger.autoflightmode;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  
  public class ServiceReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
              Intent serviceIntent = new Intent(context, AutoFlightModeService.class);
              context.startService(serviceIntent);
          }
      }
  }
  </code></pre>
  
  <p>AutoFlightModeService.java:</p>
  
  <pre><code>package cz.berzeger.autoflightmode;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.provider.Settings;
  
  
  public class AutoFlightModeService extends Service {  
  
  
      @Override
      public IBinder onBind(Intent arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          // Turn AirPlane mode on
          Settings.Global.putString(getContentResolver(), "airplane_mode_on", "1");
  
  
          // All services run in one thread. We need to explicitly create a new thread,
          // if we want to implement non-blocking wait.
          new Thread( new Runnable() {
              public void run()  {
                  try  { Thread.sleep( 5000 ); }
                  catch (InterruptedException ie)  {}
                  // After 5 seconds, turn Airplane mode off
                  Settings.Global.putString(getContentResolver(), "airplane_mode_on", "0");
              }
          }).start();
  
          return START_NOT_STICKY;
      }
  }
  </code></pre>
  
  <p>Any ideas what I'm doing wrong? Thanks.</p>