Merge change 23372 into eclair

* changes:
  Show the Use location prompt only once if user agrees. Bug #1910370
diff --git a/src/com/android/settings/AirplaneModeEnabler.java b/src/com/android/settings/AirplaneModeEnabler.java
index 45411b2..ff4b27d 100644
--- a/src/com/android/settings/AirplaneModeEnabler.java
+++ b/src/com/android/settings/AirplaneModeEnabler.java
@@ -22,11 +22,14 @@
 import android.content.Intent;
 import android.os.Handler;
 import android.os.Message;
+import android.os.SystemProperties;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.provider.Settings;
 import android.telephony.ServiceState;
 
+import com.android.internal.telephony.TelephonyProperties;
+
 public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListener {
 
     private final Context mContext;
@@ -111,8 +114,23 @@
      * Called when someone clicks on the checkbox preference.
      */
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        setAirplaneModeOn((Boolean) newValue);
+        if (Boolean.parseBoolean(
+                    SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
+            // In ECM mode, do not update database at this point
+        } else {
+            setAirplaneModeOn((Boolean) newValue);
+        }
         return true;
     }
 
+    public void setAirplaneModeInECM(boolean isECMExit, boolean isAirplaneModeOn) {
+        if (isECMExit) {
+            // update database based on the current checkbox state
+            setAirplaneModeOn(isAirplaneModeOn);
+        } else {
+            // update checkbox state based on database value
+            onAirplaneModeChanged();
+        }
+    }
+
 }
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index f160bac..b5c9ec1 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -19,13 +19,19 @@
 import com.android.settings.bluetooth.BluetoothEnabler;
 import com.android.settings.wifi.WifiEnabler;
 
+import android.content.Intent;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
+import android.os.SystemProperties;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
+import android.preference.PreferenceScreen;
 import android.preference.PreferenceActivity;
 import android.provider.Settings;
 
+import com.android.internal.telephony.TelephonyIntents;
+import com.android.internal.telephony.TelephonyProperties;
+
 public class WirelessSettings extends PreferenceActivity {
 
     private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
@@ -33,10 +39,36 @@
     private static final String KEY_TOGGLE_WIFI = "toggle_wifi";
     private static final String KEY_WIFI_SETTINGS = "wifi_settings";
     private static final String KEY_VPN_SETTINGS = "vpn_settings";
+    public static final String EXIT_ECM_RESULT = "exit_ecm_result";
+    public static final int REQUEST_CODE_EXIT_ECM = 1;
 
     private WifiEnabler mWifiEnabler;
     private AirplaneModeEnabler mAirplaneModeEnabler;
     private BluetoothEnabler mBtEnabler;
+    private CheckBoxPreference mAirplaneModePreference;
+
+    /**
+     * Invoked on each preference click in this hierarchy, overrides
+     * PreferenceActivity's implementation.  Used to make sure we track the
+     * preference click events.
+     */
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        if ( (preference == mAirplaneModePreference) &&
+                (Boolean.parseBoolean(
+                    SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) ) {
+            // In ECM mode launch ECM app dialog
+            startActivityForResult(
+                new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
+                REQUEST_CODE_EXIT_ECM);
+
+            return true;
+        }
+        else {
+            // Let the intents be launched by the Preference manager
+            return false;
+        }
+    }
     
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -45,6 +77,7 @@
         addPreferencesFromResource(R.xml.wireless_settings);
 
         initToggles();
+        mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
     }
     
     @Override
@@ -90,4 +123,20 @@
         }
     }
 
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        switch(requestCode) {
+        case REQUEST_CODE_EXIT_ECM:
+            Boolean isChoiceYes =
+                data.getBooleanExtra(EXIT_ECM_RESULT, false);
+            // Set Airplane mode based on the return value and checkbox state
+            mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
+                    mAirplaneModePreference.isChecked());
+            break;
+
+        default:
+            break;
+        }
+    }
+
 }