Skip to content

Commit

Permalink
SystemUI: Support display for radio tech
Browse files Browse the repository at this point in the history
Support monitor locale change and display for radio tech.

CRs-Fixed: 653747
Change-Id: I66d0bb29d0121a19ada0c1ad03ceeec9a03243df
  • Loading branch information
Shufeng Hou committed Nov 26, 2015
1 parent 75e20b5 commit 3259cb7
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 0 deletions.
92 changes: 92 additions & 0 deletions core/java/android/util/NativeTextHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2015, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package android.util;

import android.content.Context;

/**
*@hide
*/
public class NativeTextHelper {

/**
* parse the string to current language.
*
* @param context base context of the application
* @param originalString original string
* @param defPackage the target package where the local language strings
* defined
* @param originNamesId the id of the original string array.
* @param localNamesId the id of the local string keys.
* @return local language string
*/
private static final String getLocalString(Context context, String originalString,
String defPackage, int originNamesId, int localNamesId) {
String[] origNames = context.getResources().getStringArray(originNamesId);
String[] localNames = context.getResources().getStringArray(localNamesId);
for (int i = 0; i < origNames.length; i++) {
if (origNames[i].equalsIgnoreCase(originalString)) {
return context.getString(context.getResources().getIdentifier(localNames[i],
"string", defPackage));
}
}
return originalString;
}

/**
* parse the string to current language string in public resources.
*
* @param context base context of the application
* @param originalString original string
* @param originNamesId the id of the original string array.
* @param localNamesId the id of the local string keys.
* @return local language string
*/
public static final String getLocalString(Context context, String originalString,
int originNamesId, int localNamesId) {
return getLocalString(context, originalString, "android", originNamesId, localNamesId);
}

/**
* parse the string to current language string in current resources.
*
* @param context base context of the application
* @param originalString original string
* @param originNamesId the id of the original string array.
* @param localNamesId the id of the local string keys.
* @return local language string
*/
public static final String getInternalLocalString(Context context, String originalString,
int originNamesId,
int localNamesId) {
return getLocalString(context, originalString, context.getPackageName(), originNamesId,
localNamesId);
}

}
4 changes: 4 additions & 0 deletions core/res/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1523,4 +1523,8 @@
<item quantity="other">已选择 <xliff:g id="COUNT_1">%1$d</xliff:g> 项</item>
<item quantity="one">已选择 <xliff:g id="COUNT_0">%1$d</xliff:g> 项</item>
</plurals>
<!-- Carrier Name -->
<string name="China_Mobile">中国移动</string>
<string name="China_Unicom">中国联通</string>
<string name="China_Telecom">中国电信</string>
</resources>
4 changes: 4 additions & 0 deletions core/res/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1516,4 +1516,8 @@
<item quantity="other">已選取 <xliff:g id="COUNT_1">%1$d</xliff:g> 個項目</item>
<item quantity="one">已選取 <xliff:g id="COUNT_0">%1$d</xliff:g> 個項目</item>
</plurals>
<!-- Carrier Name -->
<string name="China_Mobile">中國移動</string>
<string name="China_Unicom">中國聯通</string>
<string name="China_Telecom">中國電信</string>
</resources>
43 changes: 43 additions & 0 deletions core/res/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2327,4 +2327,47 @@
<!-- Configuration that determines if PROTOCOL_ERRORS is to be treated as a
permanent error -->
<bool translatable="false" name="config_protocol_errors_perm_failure">true</bool>

<string-array name="origin_carrier_names">
<item>CHINA\u0020\u0020MOBILE</item>
<item>CMCC</item>
<item>CHN-UNICOM</item>
<item>China Mobile</item>
<item>China Unicom</item>
<item>China Telecom</item>
<item>中国移动</item>
<item>中国联通</item>
<item>中国电信</item>
<item>中國移動</item>
<item>中國聯通</item>
<item>中國電信</item>
<item>Searching for Service</item>
</string-array>

<string-array name="locale_carrier_names">
<item>China_Mobile</item>
<item>China_Mobile</item>
<item>China_Unicom</item>
<item>China_Mobile</item>
<item>China_Unicom</item>
<item>China_Telecom</item>
<item>China_Mobile</item>
<item>China_Unicom</item>
<item>China_Telecom</item>
<item>China_Mobile</item>
<item>China_Unicom</item>
<item>China_Telecom</item>
<item>roamingTextSearching</item>
</string-array>

<!-- monitor locale change -->
<bool name="config_monitor_locale_change">false</bool>

<!-- display for radio tech -->
<bool name="config_display_rat">false</bool>

<!-- config 2G/3G/4G RAT strings for carriers -->
<string name="config_rat_2g" translatable="false">2G</string>
<string name="config_rat_3g" translatable="false">3G</string>
<string name="config_rat_4g" translatable="false">4G</string>
</resources>
5 changes: 5 additions & 0 deletions core/res/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4122,4 +4122,9 @@
<item quantity="one"><xliff:g id="count" example="1">%1$d</xliff:g> selected</item>
<item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> selected</item>
</plurals>

<!-- Carrier Name -->
<string name="China_Mobile">China Mobile</string>
<string name="China_Unicom">China Unicom</string>
<string name="China_Telecom">China Telecom</string>
</resources>
14 changes: 14 additions & 0 deletions core/res/res/values/symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2392,4 +2392,18 @@
<java-symbol type="string" name="def_wifi_wifihotspot_pass" />
<java-symbol type="string" name="def_wifi_direct_name" />
<java-symbol type="string" name="def_custom_bt_defname" />
<!-- config 2G/3G/4G RAT strings for carriers -->
<java-symbol type="string" name="config_rat_2g" />
<java-symbol type="string" name="config_rat_3g" />
<java-symbol type="string" name="config_rat_4g" />

<!-- monitor locale change -->
<java-symbol type="bool" name="config_monitor_locale_change" />

<!-- display for radio tech -->
<java-symbol type="bool" name="config_display_rat" />

<java-symbol type="array" name="origin_carrier_names" />
<java-symbol type="array" name="locale_carrier_names" />

</resources>
57 changes: 57 additions & 0 deletions packages/Keyguard/src/com/android/keyguard/CarrierText.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.net.wifi.WifiManager;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.method.SingleLineTransformationMethod;
import android.util.AttributeSet;
Expand Down Expand Up @@ -105,15 +106,59 @@ public CarrierText(Context context, AttributeSet attrs) {
protected void updateCarrierText() {
boolean allSimsMissing = true;
boolean anySimReadyAndInService = false;
boolean showLocale = getContext().getResources().getBoolean(
com.android.internal.R.bool.config_monitor_locale_change);
boolean showRat = getContext().getResources().getBoolean(
com.android.internal.R.bool.config_display_rat);
CharSequence displayText = null;

List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
final int N = subs.size();
if (DEBUG) Log.d(TAG, "updateCarrierText(): " + N);
for (int i = 0; i < N; i++) {
CharSequence networkClass = "";
int subId = subs.get(i).getSubscriptionId();
State simState = mKeyguardUpdateMonitor.getSimState(subId);
if (showRat) {
ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
if (ss != null && (ss.getDataRegState() == ServiceState.STATE_IN_SERVICE
|| ss.getVoiceRegState() == ServiceState.STATE_IN_SERVICE)) {
int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
if (ss.getRilDataRadioTechnology() !=
ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
networkType = ss.getDataNetworkType();
} else if (ss.getRilVoiceRadioTechnology() !=
ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
networkType = ss.getVoiceNetworkType();
}
networkClass = networkClassToString(TelephonyManager
.getNetworkClass(networkType));
}
}
CharSequence carrierName = subs.get(i).getCarrierName();
if (showLocale || showRat) {
String[] names = carrierName.toString().split(mSeparator.toString(), 2);
StringBuilder newCarrierName = new StringBuilder();
for (int j = 0; j < names.length; j++) {
if (showLocale) {
names[j] = android.util.NativeTextHelper.getLocalString(getContext(),
names[j], com.android.internal.R.array.origin_carrier_names,
com.android.internal.R.array.locale_carrier_names);
}
if (!TextUtils.isEmpty(names[j])) {
if (!TextUtils.isEmpty(networkClass) && showRat) {
names[j] = new StringBuilder().append(names[j]).append(" ")
.append(networkClass).toString();
}
if (j > 0 && names[j].equals(names[j-1])) {
continue;
}
if (j > 0) newCarrierName.append(mSeparator);
newCarrierName.append(names[j]);
}
}
carrierName = newCarrierName.toString();
}
CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
if (DEBUG) {
Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
Expand Down Expand Up @@ -395,4 +440,16 @@ public CharSequence getTransformation(CharSequence source, View view) {
return source;
}
}

private String networkClassToString (int networkClass) {
final int[] classIds = { 0, // TelephonyManager.NETWORK_CLASS_UNKNOWN
com.android.internal.R.string.config_rat_2g,
com.android.internal.R.string.config_rat_3g,
com.android.internal.R.string.config_rat_4g };
String classString = null;
if (networkClass < classIds.length) {
classString = getContext().getResources().getString(classIds[networkClass]);
}
return (classString == null) ? "" : classString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
private static final int MSG_SIM_SUBSCRIPTION_INFO_CHANGED = 328;
private static final int MSG_AIRPLANE_MODE_CHANGED = 329;
private static final int MSG_SERVICE_STATE_CHANGE = 330;
private static final int MSG_LOCALE_CHANGED = 500;

private static KeyguardUpdateMonitor sInstance;

Expand Down Expand Up @@ -247,6 +248,9 @@ public void handleMessage(Message msg) {
case MSG_SERVICE_STATE_CHANGE:
handleServiceStateChange(msg.arg1, (ServiceState) msg.obj);
break;
case MSG_LOCALE_CHANGED:
handleLocaleChanged();
break;
}
}
};
Expand Down Expand Up @@ -593,6 +597,8 @@ public void onReceive(Context context, Intent intent) {
}
mHandler.sendMessage(
mHandler.obtainMessage(MSG_SERVICE_STATE_CHANGE, subId, 0, serviceState));
} else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
mHandler.sendEmptyMessage(MSG_LOCALE_CHANGED);
}
}
};
Expand Down Expand Up @@ -836,6 +842,7 @@ private KeyguardUpdateMonitor(Context context) {
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Expand Down Expand Up @@ -1158,6 +1165,18 @@ private void handleSimStateChange(int subId, int slotId, State state) {
}
}

/**
* Handle {@link #MSG_LOCALE_CHANGED}
*/
private void handleLocaleChanged() {
for (int j = 0; j < mCallbacks.size(); j++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get();
if (cb != null) {
cb.onRefreshCarrierInfo();
}
}
}

/**
* Handle {@link #MSG_SERVICE_STATE_CHANGE}
*/
Expand Down
Loading

0 comments on commit 3259cb7

Please sign in to comment.