Permalink
Browse files

Makes network mode toggle work. Port from CM7.

Added LTE_ONLY needed code to PhoneToggler.
Added LTE to the double check MODE_GLOBAL condition on Settings and
PhoneToggler.

Integrated patch by Danny Baumann to make PhoneToggler accept the same
values as are configurable in settings, from change:
http://review.cyanogenmod.com/#change,14120

Tested-by: Rick C
Tested-by: Emerson Pinter
Signed-off-by: Emerson Pinter <dev@pinter.com.br>

*** Settings.java and PhoneToggler.java original authors:

commit 3e6b2ca
Author: Emilio López <turl@tuxfamily.org>
Date:   Wed Sep 14 23:50:06 2011 +0000

    Phone: Double check mode before changing, part 2

    A modem might report world phone mode when it really is only GSM or
    CDMA capable, making the system switch to an invalid mode which
    will later break the telephony code.
    This simple check enforces the world phone overlay which is already
    in place and will only consider it a correct value in that case.

    This complements a commit with the same title by applying the same
    logic to another code path that uses similar checks.

    Change-Id: Ib7332511a693d40f53a79ba98844c9117871228a

commit 19215c8
Author: Emilio López <turl@tuxfamily.org>
Date:   Wed Sep 14 23:50:06 2011 +0000

    Phone: Double check mode before changing

    A modem might report world phone mode when it really is only GSM or
    CDMA capable, making the system switch to an invalid mode which
    will later break the telephony code.
    This simple check enforces the world phone overlay which is already
    in place and will only consider it a correct value in that case.

    Change-Id: Iedbc529497b2779f3a12ff56ca1b028cc9434227

commit 0d396f7
Author: piaf <piaf@mediacenter-desktop.(none)>
Date:   Tue Aug 3 00:56:09 2010 +0100

    Added permission control for the 2G/3G switch

commit 5c85d54
Author: Mediacenter <mediacenter@mediacenter-desktop.(none)>
Date:   Sat Jul 31 01:45:03 2010 +0100

    Added support for Changing Phone network mode
    Todo: Add permission control

*** Translations original authors:

commit e26b7ba
Author: Hep Happy <hephappy@gmail.com>
Date:   Tue Feb 7 19:27:02 2012 +0200

    Phone: tr: CM Turkish Translations

    Change-Id: I8555f71cdaf3fbbfbc4b0ac84c9e5a93829c33bd

commit 60b4bee
Author: Ondrej Zima <keltuv.email@gmail.com>
Date:   Tue Jan 10 13:09:48 2012 +0100

    Czech: fixed translation, added missing strings

    And removed untranslatable strings. Thanks Ricardo.

    Please, translate this extensive text is not easy and it is
    very important the translation be well organized. Therefore, was
    made ​​more changes.

    Change-Id: I8face661bc096d4b2d7213cceed1f048fd1bc784

commit 61da03f
Author: jjsan <juraj.janecek@gmail.com>
Date:   Mon Sep 19 21:47:51 2011 +0200

    Updated Slovak Language

    Change-Id: I6fdbe8301f53bd59be72542137fca8b22487820a

commit b088359
Author: Hawkeyexp <hawkeyexp@googlemail.com>
Date:   Sat Aug 6 23:08:05 2011 +0200

    extend translation (de)

    Change-Id: I16bfbb10d278f25e99e71798c669e8f99aea34c3

commit d7b89d1
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Sat Jul 30 15:20:22 2011 +0200

    french: translation of phone settings

    Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>

    Change-Id: Icd7d83c467ccc7925b5a5aa9986b5effd5df299f

commit 95d0647
Author: ottuh <michel91@gmail.com>
Date:   Sat Jun 25 12:59:59 2011 +0200

    Phone: Dutch translation updated!

commit 0311b57
Author: skyscribe <skyscribe.yf@gmail.com>
Date:   Sun Jun 19 21:37:34 2011 +0800

    Simplified Chinese: update translations.

    Change-Id: Ife8ebb610ccaf3f17aec3d269df8075f5a509440

commit b2201ba
Author: evgenln <evgenln4@gmail.com>
Date:   Sun Mar 20 19:00:08 2011 +0200

    Update Ukrainian translation
    - Add missing translations
    - Replace unneeded reductions
    - Fix terminology

    Signed-off-by: evgenln <evgenln4@gmail.com>

commit 0793138
Author: KalimochoAz <calimochoazucarado@gmail.com>
Date:   Sun Mar 20 14:26:50 2011 +0100

    Added missing Spanish translations to the phone ( by Chuckycrx )

    Change-Id: I6b8ce8ba90ce00316d38be088fedec6d7e5eef9a

commit 37c5261
Author: ladios <ladios.jonquil@gmail.com>
Date:   Mon Mar 7 23:20:24 2011 +0800

    Traditional Chinese: Translation tweaked.

    Change-Id: I50254545e9b7b1645d9c3db61f06acd77fe21fa4

commit 2476b38
Author: dh-harald <github@criminal.hu>
Date:   Fri Mar 4 10:31:07 2011 +0100

    Added missing HU translations from Hungarian Spica Community

    Change-Id: Id22f6f042750dd0ace42e3b87f1025347144fb17

commit bfd9dae
Author: ladios <ladios.jonquil@gmail.com>
Date:   Thu Mar 3 04:15:03 2011 +0800

    Traditional Chinese: Translation updated.

     - all extra strings

    Change-Id: I9b98852f4fea47b204ad91fd7735aef461ad31e8

commit 3d61fca
Author: iAndroid members and David Kohen <kohen.d@gmail.com>
Date:   Sun Feb 27 15:44:53 2011 +0200

    Added Hebrew translations

    Change-Id: Ie93df0ef90d193fb6ca5f1f0f4689613a4d313a7

commit b11713b
Author: evgenln <evgenln4@gmail.com>
Date:   Sat Feb 19 22:22:50 2011 +0200

    Add Ukrainian translation

    Signed-off-by: evgenln <evgenln4@gmail.com>

commit 4f4325b
Author: Patrik Kullman <patrik.kullman@gmail.com>
Date:   Tue Feb 8 18:25:26 2011 +0100

    Updated Swedish translations

    Change-Id: I01017b84536dd4e8430e6b52f0f9b1d4d1c6ae98

commit 2900dd0
Author: flr <rozbicki.maciek@gmail.com>
Date:   Sun Jan 23 07:54:51 2011 +0100

    Updated polish translation

    Change-Id: I95acdfa9095fe22eb138753a307775898184d196

commit 0bd1739
Author: Inseok Lee <dlunch@gmail.com>
Date:   Tue Jan 11 16:02:20 2011 +0900

    Update korean translation

    Change-Id: Id089d141c29fc7b2713d63abca636733cd03802d

commit 61fa7f1
Author: cytown <cytown@gmail.com>
Date:   Tue Dec 28 16:40:01 2010 +0800

    fix error in Russian and remove hu support to pass the compile

commit dfd49da
Author: pellix <pellix@gmail.com>
Date:   Thu Dec 2 10:49:01 2010 +0100

    Catalan translation added

commit af4e28e
Author: Schnee <akos.schneemaier@gmail.com>
Date:   Thu Nov 25 12:47:13 2010 +0100

    Hu translation for Phone.apk

    Change-Id: I3c5c83c92a5b09537fdac7c986481018aa3b3be1

commit 479264b
Author: Eduardo Martins <eduardo@martins>
Date:   Tue Aug 24 11:44:40 2010 -0700

    Update Portuguese translation: Advanced Setting in Call Settings

commit 34884db
Author: Eug89 <eugenioziliotto@gmail.com>
Date:   Thu Aug 19 00:18:23 2010 +0200

    Updated Italian Translations: permission control for 2G/3G switch

commit c90c303
Author: thiasB <m.buechner@gmail.com>
Date:   Wed Aug 18 23:33:08 2010 +0200

    German:
    - remove some deprecated strings
    - Re-enabled "Affiliated Networks"
    - permission control for the 2G/3G switch
    - option for setting device phone number
    - Fix CM issue 1916

commit 765daae
Author: Takuo Kitame <kitame@gmail.com>
Date:   Tue Aug 17 10:31:26 2010 +0900

    Update Japanese translation: My phone number and permission.

commit edd6a17
Author: sebyx31 <seb.vaucher+github@gmail.com>
Date:   Tue Aug 10 22:11:02 2010 +0200

    Added new French translations

commit 0d396f7
Author: piaf <piaf@mediacenter-desktop.(none)>
Date:   Tue Aug 3 00:56:09 2010 +0100

    Added permission control for the 2G/3G switch

Change-Id: I84db8082b4e35262f1c6cdb8d1156f3cbf997a99
  • Loading branch information...
1 parent df07cb2 commit bd3e968644a94a6858db10e7b24454de3c298fa7 @epinter epinter committed Feb 19, 2012
View
13 AndroidManifest.xml
@@ -491,6 +491,13 @@
android:configChanges="orientation|screenSize|keyboardHidden">
</activity>
+ <receiver android:name="com.android.phone.PhoneToggler" android:permission="com.android.phone.CHANGE_NETWORK_MODE">
+ <intent-filter>
+ <action android:name="com.android.internal.telephony.REQUEST_NETWORK_MODE" />
+ <action android:name="com.android.internal.telephony.MODIFY_NETWORK_MODE" />
+ </intent-filter>
+ </receiver>
+
<activity android:name="RespondViaSmsManager$Settings"
android:label="@string/respond_via_sms_setting_title"
android:configChanges="orientation|screenSize|keyboardHidden"
@@ -499,6 +506,10 @@
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
-
</application>
+ <permission android:name="com.android.phone.CHANGE_NETWORK_MODE"
+ android:label="@string/perm_change_mobile_network"
+ android:description="@string/perm_change_mobile_network_desc"
+ android:permissionGroup="android.permission-group.COST_MONEY"
+ android:protectionLevel="dangerous" />
</manifest>
View
2 res/values-cs/strings.xml
@@ -729,4 +729,6 @@
<string name="vibrate_hangup_sum">Vibrace po ukončení hovoru</string>
<string name="vibrate_call_waiting">Vibrace při dalším hovoru</string>
<string name="vibrate_call_waiting_sum">Vibrace při čekajícím hovoru na lince</string>
+ <string name="perm_change_mobile_network">Změnit typ sítě (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Aplikace s tímto oprávněním může kdykoliv změnit mezi 2G data a 3G data. 3G je rychlejší, ale náročnější na využití baterie a také může stát více peněz.</string>
</resources>
View
2 res/values-de/strings.xml
@@ -749,4 +749,6 @@
<string name="vibrate_hangup_sum">Vibriere, wenn Anruf beendet wurde</string>
<string name="vibrate_call_waiting">Vibriere bei Anklopfen</string>
<string name="vibrate_call_waiting_sum">Vibriere bei Anklopfen</string>
+ <string name="perm_change_mobile_network">Mobilfunkstandard wechseln (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Anwendungen mit dieser Berechtigung können jederzeit zwischen 2G- und 3G-Netz wechseln. 3G ist schneller, verbraucht mehr Batterieladung und kann teurer sein</string>
</resources>
View
2 res/values-es/strings.xml
@@ -746,4 +746,6 @@
<string name="vibrate_hangup_sum">Vibra cuando ha finalizado una llamada</string>
<string name="vibrate_call_waiting">Vibrar en Llamada en Espera</string>
<string name="vibrate_call_waiting_sum">Vibra al tener una Llamada en Espera</string>
+ <string name="perm_change_mobile_network">Cambiar red (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Las aplicaciones con este permiso, pueden en cualquier momento, cambiar entre datos 2G y 3G. 3G es rápido, consume mas batería, y puede costarte mas dinero.</string>
</resources>
View
2 res/values-fr/strings.xml
@@ -736,4 +736,6 @@
<string name="vibrate_hangup_sum">Vibration lorsque l\' appel est terminé</string>
<string name="vibrate_call_waiting">Vibrer sur double appel</string>
<string name="vibrate_call_waiting_sum">Vibrer lorsqu\'un appel est en attente</string>
+ <string name="perm_change_mobile_network">Changer la technologie réseau (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Les applications possédant cette permission peuvent à chaque instant changer entre les technologies 2G et 3G. La 3G est plus rapide, consomme plus de batterie, et peut également vous coûter plus</string>
</resources>
View
2 res/values-hu/strings.xml
@@ -752,4 +752,6 @@
<string name="vibrate_hangup_sum">Rezgéssel jelzi a hívás befejeztét</string>
<string name="vibrate_call_waiting">Hívásvárakoztatáskor rezeg</string>
<string name="vibrate_call_waiting_sum">Hívásvárakoztatáskor rezeg a telefon</string>
+ <string name="perm_change_mobile_network">Hálózat módosítása (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Az ilyen engedéllyel rendelkező alkalmazás, bármikor válthat 2G és 3G közt. A 3G gyorsabb, jobban meríti az akkumulátort, és több pénzbe is kerülhet a nagyobb adatforgalom miatt.</string>
</resources>
View
2 res/values-it/strings.xml
@@ -733,4 +733,6 @@
<string name="vibrate_hangup_sum">Vibra quando termini una chiamata</string>
<string name="vibrate_call_waiting">Vibra quando in attesa</string>
<string name="vibrate_call_waiting_sum">Vibra quando c\'è una chiamata in attesa</string>
+ <string name="perm_change_mobile_network">Cambia rete (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Un\'applicazione con questo permesso può passare da 2G a 3G e viceversa in qualsiasi momento. Il 3G è più veloce, consuma più batteria e può anche farti spendere di più.</string>
</resources>
View
2 res/values-ja/strings.xml
@@ -745,5 +745,7 @@
<string name="vibrate_hangup_sum">通話を終了した時にバイブレーションする</string>
<string name="vibrate_call_waiting">呼出中に振動</string>
<string name="vibrate_call_waiting_sum">呼び出し中にバイブレーションする</string>
+ <string name="perm_change_mobile_network">ネットワークを変更(2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">この権限を許可されたアプリケーションは、いつでも2G/3Gデータの切り替えが可能です。3Gは高速ですが、バッテリ消費が増加します。また、キャリアの課金も増加することがあります。</string>
</resources>
View
2 res/values-ko/strings.xml
@@ -729,4 +729,6 @@
<string name="vibrate_hangup_sum">통화가 끝났을 때 진동합니다.</string>
<string name="vibrate_call_waiting">통화 중 대기시 진동</string>
<string name="vibrate_call_waiting_sum">통화 중 대기가 있을 경우 진동합니다.</string>
+ <string name="perm_change_mobile_network">네트워크 바꾸기 (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">이 권한을 가진 어플리케이션은 아무 때나 2G 데이터와 3G 데이터를 선택할 수 있습니다. 3G는 더 빠르지만 배터리를 더 많이 소모하며 요금이 더 많이 나올 수 있습니다.</string>
</resources>
View
2 res/values-nl/strings.xml
@@ -741,4 +741,6 @@
<string name="vibrate_hangup_sum">Trillen bij het beëindigen van een oproep.</string>
<string name="vibrate_call_waiting">Trillen wachten gesprek</string>
<string name="vibrate_call_waiting_sum">Trillen bij wachten op een gesprek.</string>
+ <string name="perm_change_mobile_network">Verander netwerk (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Applicatie met deze toegang kan op elk moment wisselen tussen 2G en 3G. 3G is sneller, verbruikt meer stroom en kan duurder zijn.</string>
</resources>
View
6 res/values-pl/strings.xml
@@ -713,12 +713,14 @@
<string name="description_target_answer" msgid="7205604197797472471">"Odpowiedz"</string>
<string name="description_target_send_sms" msgid="2098326025587950144">"Wyślij SMS"</string>
<string name="description_target_decline" msgid="4789834364389731957">"Odrzuć"</string>
-
+ <string name="perm_change_mobile_network">Zmień sieć (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Aplikacja ma możliwość przełącania się między siecią 2G i 3G. 3G jest szybsze, ale zużywa szybciej baterię.</string>
+
<!-- **** CYANOGENMOD EDITS START **** -->
<!-- Dialer UI Settings -->
<string name="dialer_ui_settings_title">Wybieranie numeru</string>
<string name="dialer_ui_settings_summary">Ustawienia wybierania numeru</string>
-
+
<string name="phone_number_label">Mój numer</string>
<string name="phone_number_summary">Ustaw numer telefoniczny tego urządzenia</string>
<!-- **** CYANOGENMOD EDITS END **** -->
View
2 res/values-pt/strings.xml
@@ -740,4 +740,6 @@
<string name="vibrate_hangup_sum">Vibra quando a chamada é desligada</string>
<string name="vibrate_call_waiting">Vibrar c/ chamada em espera</string>
<string name="vibrate_call_waiting_sum">Vibra quando existem chamadas em espera</string>
+ <string name="perm_change_mobile_network">Alternar rede de dados (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Aplicação com está permissão pode a qualquer momento, alterar entre dados 2G and 3G. 3G é mais rápido, consome mais bateria, e também pode gastar mais seu dinheiro.</string>
</resources>
View
2 res/values-sk/strings.xml
@@ -729,4 +729,6 @@
<string name="vibrate_hangup_sum">Vibrovať pri ukončení hovoru</string>
<string name="vibrate_call_waiting">Vibrovať pri čakajúcom hovore</string>
<string name="vibrate_call_waiting_sum">Vibrovať pri čakajúcom hovore</string>
+ <string name="perm_change_mobile_network">Zmeniť sieť (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Aplikácia s týmito povoleniami môže kedykoľvek zmeniť sieť medzi 2G a 3G. 3G je rýchlejšie, viac využíva batériu, a taktiež Vás môže stáť viac peňazí.</string>
</resources>
View
2 res/values-sv/strings.xml
@@ -735,4 +735,6 @@
<string name="vibrate_hangup_sum">Vibrera när ett samtal har avslutats</string>
<string name="vibrate_call_waiting">Vibrera vid samtal väntar</string>
<string name="vibrate_call_waiting_sum">Vibrera när samtal väntar</string>
+ <string name="perm_change_mobile_network">Byt nätverk (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">En applikation med denna tillåtelse kan, när som helst, byta mellan 2G data och 3G data. 3G är snabbare, förbrukar mer batteri och kan också kosta dig mer pengar.</string>
</resources>
View
2 res/values-tr/strings.xml
@@ -729,4 +729,6 @@
<string name="vibrate_hangup_sum">Çağrı sonlandığında titret</string>
<string name="vibrate_call_waiting">Çağrı bekletilirse titret</string>
<string name="vibrate_call_waiting_sum">Çağrı bekletildiğinde titret</string>
+ <string name="perm_change_mobile_network">Şebeke değiştir (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Bu ayar istediğiniz zaman 2G ve 3G arasında geçiş yapmanızı sağlar. 3G daha hızlıdır ama daha fazla pil tüketir ve ek olarak daha fazla ücret ödemenize sebep olabilir.</string>
</resources>
View
2 res/values-uk/strings.xml
@@ -729,4 +729,6 @@
<string name="vibrate_hangup_sum">Сигналізування про завершення виклику вібруванням</string>
<string name="vibrate_call_waiting">Вібросигнал очікування виклику</string>
<string name="vibrate_call_waiting_sum">Сигналізування про очікування виклику вібруванням</string>
+ <string name="perm_change_mobile_network">Змінення режиму мережі (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Програма з цими правами може в будь-який момент змінити режим мережі. 3G швидше, але споживає більше енергії, а також може тарифікуватися дорожче.</string>
</resources>
View
2 res/values-zh-rCN/strings.xml
@@ -735,4 +735,6 @@
<string name="vibrate_hangup_sum">通话结束时震动.</string>
<string name="vibrate_call_waiting">呼叫等待震动</string>
<string name="vibrate_call_waiting_sum">当呼叫等待时震动通知.</string>
+ <string name="perm_change_mobile_network">2G/3G移动网络切换</string>
+ <string name="perm_change_mobile_network_desc">获得该权限的应用程序可以在任何时候在2G/3G移动网络之间切换。使用3G网络存取资料的速度会比较快,但是也会相应消耗比较多的电量并消耗您更多金钱。</string>
</resources>
View
2 res/values-zh-rTW/strings.xml
@@ -733,4 +733,6 @@
<string name="vibrate_hangup_sum">通話結束時震動</string>
<string name="vibrate_call_waiting">來電待接震動</string>
<string name="vibrate_call_waiting_sum">當有來電待接時震動通知</string>
+ <string name="perm_change_mobile_network">切換行動網路(2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">被授予此權限的應用程式能夠於任何時候在 2G 及 3G 行動網路之間進行切換。使用 3G 行動網路取存資料的速度會比較快,但相對的會消耗較多的電池電量,亦會令您花費較多的金錢。</string>
</resources>
View
2 res/values/strings.xml
@@ -1621,6 +1621,8 @@
<!-- Description of the decline on target in the Slide unlock screen. [CHAR LIMIT=NONE] -->
<string name="description_target_decline">Decline</string>
+ <string name="perm_change_mobile_network">Change network (2G/3G)</string>
+ <string name="perm_change_mobile_network_desc">Application with this permission can, at any time, change between 2G data and 3G data. 3G is faster, consumes more battery, and can also cost you more money.</string>
<string name="phone_number_label">My phone number</string>
<string name="phone_number_summary">Set the phone number for this device</string>
View
181 src/com/android/phone/PhoneToggler.java
@@ -0,0 +1,181 @@
+package com.android.phone;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.AsyncResult;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneFactory;
+
+public class PhoneToggler extends BroadcastReceiver {
+
+ /** Used for brodcasting network data change and receive new mode **/
+ public static final String NETWORK_MODE_CHANGED="com.android.internal.telephony.NETWORK_MODE_CHANGED";
+ public static final String REQUEST_NETWORK_MODE="com.android.internal.telephony.REQUEST_NETWORK_MODE";
+ public static final String MODIFY_NETWORK_MODE="com.android.internal.telephony.MODIFY_NETWORK_MODE";
+ public static final String MOBILE_DATA_CHANGED="com.android.internal.telephony.MOBILE_DATA_CHANGED";
+ public static final String NETWORK_MODE = "networkMode";
+
+ public static final String CHANGE_NETWORK_MODE_PERM= "com.android.phone.CHANGE_NETWORK_MODE";
+ private static final String LOG_TAG = "PhoneToggler";
+ private static final boolean DBG = true;
+
+ private Phone mPhone;
+ private MyHandler mHandler;
+
+
+ private Phone getPhone() {
+ if (mPhone==null) mPhone = PhoneFactory.getDefaultPhone();
+ return mPhone;
+ }
+
+ private MyHandler getHandler() {
+ if (mHandler==null) mHandler = new MyHandler();
+ return mHandler;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(MODIFY_NETWORK_MODE)) {
+ if (DBG) Log.d(LOG_TAG,"Got modify intent");
+ if (intent.getExtras()!=null) {
+ int networkMode = intent.getExtras().getInt(NETWORK_MODE);
+ boolean networkModeOk = false;
+ int phoneType = getPhone().getPhoneType();
+ boolean isLteOnCdma = getPhone().getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE;
+
+ if (phoneType == Phone.PHONE_TYPE_GSM) {
+ if (networkMode == Phone.NT_MODE_GSM_ONLY
+ || networkMode == Phone.NT_MODE_GSM_UMTS
+ || networkMode == Phone.NT_MODE_WCDMA_PREF
+ || networkMode == Phone.NT_MODE_WCDMA_ONLY) {
+ networkModeOk = true;
+ }
+ } else if (phoneType == Phone.PHONE_TYPE_CDMA) {
+ if (networkMode == Phone.NT_MODE_CDMA
+ || networkMode == Phone.NT_MODE_CDMA_NO_EVDO
+ || networkMode == Phone.NT_MODE_EVDO_NO_CDMA) {
+ networkModeOk = true;
+ }
+ }
+ if (context.getResources().getBoolean(R.bool.world_phone) || isLteOnCdma) {
+ if (networkMode == Phone.NT_MODE_GLOBAL) {
+ networkModeOk = true;
+ }
+ }
+
+ if (networkModeOk) {
+ if (DBG) Log.d(LOG_TAG,"Will modify it to: "+networkMode);
+ changeNetworkMode(networkMode);
+ if (DBG) Log.d(LOG_TAG,"Accepted modification of network mode to : "+networkMode);
+ } else {
+ Log.e(LOG_TAG,"Not accepted network mode: "+networkMode);
+ }
+ }
+ } else if (intent.getAction().equals(REQUEST_NETWORK_MODE)) {
+ if (DBG) Log.d(LOG_TAG,"Sending Intent with current phone network mode");
+ triggerIntent();
+ } else {
+ Log.e(LOG_TAG,"Not accepted intent: "+intent.getAction());
+ }
+ }
+
+ private void changeNetworkMode(int modemNetworkMode) {
+ getPhone().setPreferredNetworkType(modemNetworkMode, getHandler()
+ .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
+
+ }
+
+ private void triggerIntent() {
+ getPhone().getPreferredNetworkType(getHandler()
+ .obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE));
+ }
+
+ private class MyHandler extends Handler {
+
+ private static final int MESSAGE_GET_PREFERRED_NETWORK_TYPE = 0;
+ private static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 1;
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MESSAGE_GET_PREFERRED_NETWORK_TYPE:
+ handleGetPreferredNetworkTypeResponse(msg);
+ break;
+
+ case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
+ handleSetPreferredNetworkTypeResponse(msg);
+ break;
+ }
+ }
+
+ private void handleGetPreferredNetworkTypeResponse(Message msg) {
+ AsyncResult ar = (AsyncResult) msg.obj;
+
+ if (ar.exception == null) {
+ int modemNetworkMode = ((int[])ar.result)[0];
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeResponse: modemNetworkMode = "+modemNetworkMode);
+ int settingsNetworkMode = android.provider.Settings.Secure.getInt(
+ getPhone().getContext().getContentResolver(),
+ android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
+ Settings.preferredNetworkMode);
+
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeReponse: settingsNetworkMode = "+settingsNetworkMode);
+
+ //check that modemNetworkMode is from an accepted value
+ if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF ||
+ modemNetworkMode == Phone.NT_MODE_GSM_ONLY ||
+ modemNetworkMode == Phone.NT_MODE_WCDMA_ONLY ||
+ modemNetworkMode == Phone.NT_MODE_GSM_UMTS ||
+ modemNetworkMode == Phone.NT_MODE_CDMA ||
+ modemNetworkMode == Phone.NT_MODE_CDMA_NO_EVDO ||
+ modemNetworkMode == Phone.NT_MODE_EVDO_NO_CDMA ||
+ //A modem might report world phone sometimes
+ //but it's not true. Double check here
+ (getPhone().getContext().getResources().getBoolean(R.bool.world_phone) == true &&
+ modemNetworkMode == Phone.NT_MODE_GLOBAL) ) {
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = "+modemNetworkMode);
+
+ //check changes in modemNetworkMode and updates settingsNetworkMode
+ if (modemNetworkMode != settingsNetworkMode) {
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeResponse: if 2: modemNetworkMode != settingsNetworkMode");
+ settingsNetworkMode = modemNetworkMode;
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeResponse: if 2: settingsNetworkMode = "+settingsNetworkMode);
+
+ //changes the Settings.System accordingly to modemNetworkMode
+ android.provider.Settings.Secure.putInt(
+ getPhone().getContext().getContentResolver(),
+ android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
+ settingsNetworkMode );
+ }
+ Intent intent = new Intent(NETWORK_MODE_CHANGED);
+ intent.putExtra(NETWORK_MODE, settingsNetworkMode);
+ getPhone().getContext().sendBroadcast(intent,CHANGE_NETWORK_MODE_PERM);
+ } else if (modemNetworkMode == Phone.NT_MODE_LTE_ONLY) {
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeResponse: lte only: no action");
+ } else {
+ if (DBG) Log.d(LOG_TAG,"handleGetPreferredNetworkTypeResponse: else: reset to default");
+ resetNetworkModeToDefault();
+ }
+ }
+ }
+
+ private void handleSetPreferredNetworkTypeResponse(Message msg) {
+ //PSAFS - TODO: For now no status is stored, so we will always get the real status from Phone.
+ getPhone().getPreferredNetworkType(obtainMessage(MESSAGE_GET_PREFERRED_NETWORK_TYPE));
+ }
+
+ private void resetNetworkModeToDefault() {
+ android.provider.Settings.Secure.putInt(getPhone().getContext().getContentResolver(),
+ android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
+ Settings.preferredNetworkMode );
+ //Set the Modem
+ getPhone().setPreferredNetworkType(Settings.preferredNetworkMode,
+ this.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
+ }
+ }
+}
View
22 src/com/android/phone/Settings.java
@@ -182,6 +182,10 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
cm.setMobileDataEnabled(mButtonDataEnabled.isChecked());
+
+ Intent intent = new Intent(PhoneToggler.MOBILE_DATA_CHANGED);
+ intent.putExtra(PhoneToggler.NETWORK_MODE, mButtonDataEnabled.isChecked());
+ mPhone.getContext().sendBroadcast(intent);
return true;
} else if (preference == mLteDataServicePref) {
String tmpl = android.provider.Settings.Secure.getString(getContentResolver(),
@@ -406,6 +410,10 @@ public boolean onPreferenceChange(Preference preference, Object objValue) {
//Set the modem network mode
mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
+
+ Intent intent = new Intent(PhoneToggler.NETWORK_MODE_CHANGED);
+ intent.putExtra(PhoneToggler.NETWORK_MODE, buttonNetworkMode);
+ mPhone.getContext().sendBroadcast(intent, PhoneToggler.CHANGE_NETWORK_MODE_PERM);
}
}
@@ -452,6 +460,7 @@ private void handleGetPreferredNetworkTypeResponse(Message msg) {
settingsNetworkMode);
}
+ boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE;
//check that modemNetworkMode is from an accepted value
if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF ||
modemNetworkMode == Phone.NT_MODE_GSM_ONLY ||
@@ -461,7 +470,10 @@ private void handleGetPreferredNetworkTypeResponse(Message msg) {
modemNetworkMode == Phone.NT_MODE_CDMA_NO_EVDO ||
modemNetworkMode == Phone.NT_MODE_EVDO_NO_CDMA ||
modemNetworkMode == Phone.NT_MODE_LTE_GSM_WCDMA ||
- modemNetworkMode == Phone.NT_MODE_GLOBAL ) {
+ //A modem might report world phone sometimes
+ //but it's not true. Double check here
+ ((getResources().getBoolean(R.bool.world_phone) == true || isLteOnCdma) &&
+ modemNetworkMode == Phone.NT_MODE_GLOBAL) ) {
if (DBG) {
log("handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = " +
modemNetworkMode);
@@ -490,6 +502,10 @@ private void handleGetPreferredNetworkTypeResponse(Message msg) {
UpdatePreferredNetworkModeSummary(modemNetworkMode);
// changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode
mButtonPreferredNetworkMode.setValue(Integer.toString(modemNetworkMode));
+
+ Intent intent = new Intent(PhoneToggler.NETWORK_MODE_CHANGED);
+ intent.putExtra(PhoneToggler.NETWORK_MODE, modemNetworkMode);
+ mPhone.getContext().sendBroadcast(intent, PhoneToggler.CHANGE_NETWORK_MODE_PERM);
} else if (modemNetworkMode == Phone.NT_MODE_LTE_ONLY) {
// LTE Only mode not yet supported on UI, but could be used for testing
if (DBG) log("handleGetPreferredNetworkTypeResponse: lte only: no action");
@@ -509,6 +525,10 @@ private void handleSetPreferredNetworkTypeResponse(Message msg) {
android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
networkMode );
+
+ Intent intent = new Intent(PhoneToggler.NETWORK_MODE_CHANGED);
+ intent.putExtra(PhoneToggler.NETWORK_MODE, networkMode);
+ mPhone.getContext().sendBroadcast(intent, PhoneToggler.CHANGE_NETWORK_MODE_PERM);
} else {
mPhone.getPreferredNetworkType(obtainMessage(MESSAGE_GET_PREFERRED_NETWORK_TYPE));
}

0 comments on commit bd3e968

Please sign in to comment.