Skip to content

Commit

Permalink
Frameworks: Customize network name and indicator on status bar
Browse files Browse the repository at this point in the history
Support following carrier specific customizations:
1. Add operator name (i.e network name) into left top of status bar.
This function is controlled by config_showOperatorNameInStatusBar and
also configurable to users via Settings-->Display-->Operator name

2. Show both roaming and network icons
Some regional carriers requires the status bar display the Roaming
icon "R" and Network Icon "3G/4G" and so on, when the phone Roaming
and data connection is on.

3. Show network capacity instead of current RAT in network indicator
For some carrier, the network indicator should display the network
capacity (i.e highest RAT) of a given cell.

CRs-Fixed: 945412

Change-Id: I5603965b0303f3e1a0ec8fb1897ef6a93c45d116
  • Loading branch information
Fang Yunong committed Dec 30, 2015
1 parent 3001f27 commit 93d9213
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 6 deletions.
5 changes: 5 additions & 0 deletions core/res/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,11 @@
<item>-44</item>
</integer-array>

<!-- Enables the feature that can show/hide the operator name in statusbar.
When true, the user can select to show/hide operator name through a
checkbox in Settings. When false, there is no option to show operator
name (no checkbox in Settings). -->
<bool name="config_showOperatorNameInStatusBar">false</bool>
<bool name="config_regional_hotspot_show_maximum_connection_enable">false</bool>
<bool name="config_regional_hotspot_show_broadcast_ssid_checkbox">false</bool>
<bool name="config_regional_hotspot_show_notification_when_turn_on">false</bool>
Expand Down
2 changes: 2 additions & 0 deletions core/res/res/values/symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2439,4 +2439,6 @@

<java-symbol type="bool" name="config_regional_hotspot_show_broadcast_ssid_checkbox" />
<java-symbol type="bool" name="config_regional_hotspot_show_notification_when_turn_on" />

<java-symbol type="bool" name="config_showOperatorNameInStatusBar" />
</resources>
10 changes: 10 additions & 0 deletions packages/SystemUI/res/layout/mobile_signal_group.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<ImageView
android:id="@+id/mobile_roaming"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<ImageView
android:id="@+id/mobile_type"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<ImageView
android:id="@+id/mobile_inout"
android:layout_height="17dp"
Expand Down
10 changes: 10 additions & 0 deletions packages/SystemUI/res/layout/status_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
android:orientation="horizontal"
>

<TextView android:id="@+id/network_label"
android:textSize="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:maxLength="@integer/config_operatorNameMaxLength"
android:gravity="center_vertical"
android:singleLine="true"
android:visibility="gone"
/>

<com.android.systemui.statusbar.AlphaOptimizedFrameLayout
android:id="@+id/notification_icon_area"
android:layout_width="0dip"
Expand Down
10 changes: 10 additions & 0 deletions packages/SystemUI/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,15 @@

<!-- Show 4G for HSPAP -->
<bool name="config_show4gForHspap">false</bool>

<!-- Maximum length of operator name to be shown in status bar -->
<integer name="config_operatorNameMaxLength">20</integer>

<!-- show different network indicators -->
<bool name="show_network_indicators">false</bool>

<!-- Show roaming and network icons -->
<bool name="show_roaming_and_network_icons">false</bool>

</resources>

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.systemui.R;
import com.android.systemui.qs.QSTile.SignalState;
Expand All @@ -36,6 +38,7 @@ public final class SignalTileView extends QSTileView {
private ImageView mOverlay;
private ImageView mIn;
private ImageView mOut;
private ImageView mRoaming;

private int mWideOverlayIconStartPadding;

Expand Down Expand Up @@ -63,7 +66,17 @@ protected View createIcon() {
mSignal = new ImageView(mContext);
mIconFrame.addView(mSignal);
mOverlay = new ImageView(mContext);
mIconFrame.addView(mOverlay, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if (getContext().getResources().getBoolean(R.bool.show_roaming_and_network_icons)) {
mRoaming = new ImageView(mContext);
mRoaming.setImageResource(R.drawable.ic_qs_signal_r);
mRoaming.setVisibility(View.GONE);
LinearLayout iconLayout = new LinearLayout(mContext);
iconLayout.addView(mOverlay, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
iconLayout.addView(mRoaming, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mIconFrame.addView(iconLayout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
} else {
mIconFrame.addView(mOverlay, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
return mIconFrame;
}

Expand Down Expand Up @@ -123,6 +136,11 @@ protected void handleStateChanged(QSTile.State state) {
final boolean shown = isShown();
setVisibility(mIn, shown, s.activityIn);
setVisibility(mOut, shown, s.activityOut);
if (getContext().getResources().getBoolean(R.bool.show_roaming_and_network_icons)) {
TelephonyManager tm =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
mRoaming.setVisibility(tm.isNetworkRoaming()? View.VISIBLE : View.GONE);
}
}

private void setVisibility(View view, boolean shown, boolean visible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -554,7 +555,7 @@ private class PhoneState {
private String mMobileDescription, mMobileTypeDescription;

private ViewGroup mMobileGroup;
private ImageView mMobile, mMobileDark, mMobileType;
private ImageView mMobile, mMobileDark, mMobileType, mRoaming;

private int mDataActivityId = 0, mMobileActivityId = 0;
private int mStackedDataId = 0, mStackedVoiceId = 0;
Expand All @@ -581,6 +582,7 @@ public void setViews(ViewGroup root) {

mMobileSingleGroup = (ViewGroup) root.findViewById(R.id.mobile_signal_single);
mMobileStackedGroup = (ViewGroup) root.findViewById(R.id.mobile_signal_stacked);
mRoaming = (ImageView) root.findViewById(R.id.mobile_roaming);
}

public boolean apply(boolean isSecondaryIcon) {
Expand Down Expand Up @@ -635,6 +637,14 @@ public boolean apply(boolean isSecondaryIcon) {
mMobileStackedGroup.setVisibility(View.GONE);
}

TelephonyManager tm =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if (tm != null && tm.isNetworkRoaming(mSubId)) {
mRoaming.setImageDrawable(getContext().getResources().getDrawable(
R.drawable.stat_sys_data_fully_connected_roam));
} else {
mRoaming.setImageDrawable(null);
}
mMobileGroup.setContentDescription(mMobileTypeDescription
+ " " + mMobileDescription);
mMobileGroup.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.telephony.TelephonyManager;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.EventLog;
Expand Down Expand Up @@ -239,6 +240,13 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
/** Allow some time inbetween the long press for back and recents. */
private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;

/**
* A key that is used to retrieve the value of the checkbox
* in Settings application that allows a user to add or remove
* the operator name in statusbar.
*/
protected static final String SHOW_OPERATOR_NAME = "show_network_name_mode";

/** If true, the system is in the half-boot-to-decryption-screen state.
* Prudently disable QS and notifications. */
private static final boolean ONLY_CORE_APPS;
Expand Down Expand Up @@ -411,6 +419,23 @@ public void onChange(boolean selfChange) {
}
};

private final ContentObserver mShowOperatorNameObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
boolean showOperatorName = (0 != Settings.System.getInt(
mContext.getContentResolver(), SHOW_OPERATOR_NAME, 1));
TextView networkLabel = (TextView)mStatusBarWindow.findViewById(R.id.network_label);
if (networkLabel != null) {
if (!showOperatorName || mState != StatusBarState.SHADE) {
mNetworkController.removeNetworkLabelView();
networkLabel.setVisibility(View.GONE);
} else {
mNetworkController.addNetworkLabelView(networkLabel);
}
}
}
};

private int mInteractingWindows;
private boolean mAutohideSuspended;
private int mStatusBarMode;
Expand Down Expand Up @@ -624,6 +649,22 @@ public void start() {
// TODO: use MediaSessionManager.SessionListener to hook us up to future updates
// in session state

// If the phone is configured to show the operator name
// then register the observer.
// Phones without simcard should not show
// operatorname in statusbar.
final TelephonyManager tm = (TelephonyManager)mContext.getSystemService(Context.
TELEPHONY_SERVICE);
final boolean enableOperatorName = (mContext.getResources().
getBoolean(com.android.internal.R.bool.config_showOperatorNameInStatusBar));
if (enableOperatorName) {
mContext.getContentResolver().unregisterContentObserver(mShowOperatorNameObserver);
mShowOperatorNameObserver.onChange(false); // setup
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(SHOW_OPERATOR_NAME), true,
mShowOperatorNameObserver);
}

addNavigationBar();

// Lastly, call to the icon policy to install/update all the icons.
Expand Down Expand Up @@ -3825,6 +3866,23 @@ public void setBarState(int state) {
mGroupManager.setStatusBarState(state);
mStatusBarWindowManager.setStatusBarState(state);
updateDozing();

final TelephonyManager tm = (TelephonyManager)mContext.getSystemService(Context.
TELEPHONY_SERVICE);
boolean showOperatorName = (0 != Settings.System.getInt(
mContext.getContentResolver(), SHOW_OPERATOR_NAME, 1));
final boolean enableOperatorName = (mContext.getResources().
getBoolean(com.android.internal.R.bool.config_showOperatorNameInStatusBar));

TextView networkLabel = (TextView)mStatusBarWindow.findViewById(R.id.network_label);
if (networkLabel != null) {
if (!enableOperatorName || !showOperatorName || mState != StatusBarState.SHADE) {
mNetworkController.removeNetworkLabelView();
networkLabel.setVisibility(View.GONE);
} else {
mNetworkController.addNetworkLabelView(networkLabel);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import android.content.res.Resources;
import android.net.NetworkCapabilities;
import android.os.Looper;
import android.telephony.CellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;

import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
Expand Down Expand Up @@ -72,6 +75,8 @@ public class MobileSignalController extends SignalController<
private SignalStrength mSignalStrength;
private MobileIconGroup mDefaultIcons;
private Config mConfig;
private int mCellIdentity = Integer.MAX_VALUE;
private int mNewCellIdentity = Integer.MAX_VALUE;

private final int STATUS_BAR_STYLE_ANDROID_DEFAULT = 0;
private final int STATUS_BAR_STYLE_CDMA_1X_COMBINED = 1;
Expand Down Expand Up @@ -202,6 +207,9 @@ private void mapIconSets() {
TelephonyIcons.THREE_G);
mDefaultIcons = TelephonyIcons.THREE_G;
}
if (mContext.getResources().getBoolean(R.bool.show_network_indicators)) {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EDGE, TelephonyIcons.E);
}

MobileIconGroup hGroup = TelephonyIcons.THREE_G;
if (mConfig.hspaDataDistinguishable) {
Expand All @@ -215,6 +223,12 @@ private void mapIconSets() {
} else {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSPAP, hGroup);
}
if (mContext.getResources().getBoolean(R.bool.show_network_indicators)) {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSDPA, TelephonyIcons.ONE_X);
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSUPA, TelephonyIcons.ONE_X);
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSPA, TelephonyIcons.ONE_X);
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_HSPAP, TelephonyIcons.H);
}

if (mConfig.show4gForLte) {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE, TelephonyIcons.FOUR_G);
Expand All @@ -224,6 +238,13 @@ private void mapIconSets() {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE, TelephonyIcons.LTE);
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, TelephonyIcons.LTE);
}
if (mContext.getResources().getBoolean(R.bool.show_network_indicators)) {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE, TelephonyIcons.LTE);
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, TelephonyIcons.WFC);
} else {
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE, TelephonyIcons.FOUR_G);
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_LTE_CA, TelephonyIcons.FOUR_G_PLUS);
}
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_IWLAN, TelephonyIcons.WFC);
}

Expand Down Expand Up @@ -270,6 +291,13 @@ public void notifyListeners() {
icons.mStackedDataIcon, icons.mStackedVoiceIcon,
dataContentDescription, description, icons.mIsWide,
mSubscriptionInfo.getSubscriptionId());

mCallbackHandler.post(new Runnable() {
@Override
public void run() {
mNetworkController.updateNetworkLabelView();
}
});
}

@Override
Expand Down Expand Up @@ -502,7 +530,9 @@ private final void updateTelephony() {
if (isCarrierNetworkChangeActive()) {
mCurrentState.iconGroup = TelephonyIcons.CARRIER_NETWORK_CHANGE;
} else if (isRoaming()) {
mCurrentState.iconGroup = TelephonyIcons.ROAMING;
if (!mContext.getResources().getBoolean(R.bool.show_roaming_and_network_icons)) {
mCurrentState.iconGroup = TelephonyIcons.ROAMING;
}
}
if (isEmergencyOnly() != mCurrentState.isEmergency) {
mCurrentState.isEmergency = isEmergencyOnly();
Expand Down Expand Up @@ -777,9 +807,32 @@ public void onDataConnectionStateChanged(int state, int networkType) {
Log.d(mTag, "onDataConnectionStateChanged: state=" + state
+ " type=" + networkType);
}
mDataState = state;
mDataNetType = networkType;
updateTelephony();
if (mContext.getResources().getBoolean(R.bool.show_network_indicators)) {
CellLocation cl = mPhone.getCellLocation();
if (cl instanceof GsmCellLocation) {
GsmCellLocation cellLocation = (GsmCellLocation)cl;
mNewCellIdentity = cellLocation.getCid();
Log.d(mTag, "onDataConnectionStateChanged, mNewCellIdentity = "
+ mNewCellIdentity);
}
Log.d(mTag, "onDataConnectionStateChanged, mCellIdentity = " + mCellIdentity
+ ", mNewCellIdentity = " + mNewCellIdentity
+ ", mDataNetType = " + mDataNetType
+ ", networkType = " + networkType);
if (mCellIdentity != mNewCellIdentity) {
mDataNetType = networkType;
} else {
if (networkType > mDataNetType) {
mDataNetType = networkType;
}
}
mDataState = state;
updateTelephony();
} else {
mDataState = state;
mDataNetType = networkType;
updateTelephony();
}
}

@Override
Expand Down
Loading

0 comments on commit 93d9213

Please sign in to comment.