出處: http://blog.csdn.net/ouyang_peng/article/details/49121645
版权声明:本文为【欧阳鹏】原创文章,欢迎转载,转载请注明出处! 【http://blog.csdn.net/ouyang_peng】
在修改显示的信号强度之前,先了解一下什么是dB,什么是dBm?
1.dB
dB是一个表征相对值的值,纯粹的比值,只表示两个量的相对大小关系,没有单位,当考虑甲的功率相比于乙功率大或小多少个dB时,
按下面的计算公式:10log(甲功率/乙功率),如果采用两者的电压比计算,要用20log(甲电压/乙电压)。)
[例] 甲功率比乙功率大一倍,那么10lg(甲功率/乙功率)=10lg2=3dB。也就是说,甲的功率比乙的功率大3 dB。
反之,如果甲的功率是乙的功率的一半,则甲的功率比乙的功率小3 dB。
2.dBm
dBm是一个表示功率绝对值的值(也可以认为是以1mW功率为基准的一个比值),计算公式为:10log(功率值/1mw)。
[例] 如果功率P为1mw,折算为dBm后为0dBm。
[例] 对于40W的功率,按dBm单位进行折算后的值应为:
10log(40W/1mw)=10log(40000)=10log4+10log10000=46dBm。
总之,dB是两个量之间的比值,表示两个量间的相对大小,而dBm则是表示功率绝对大小的值。在dB,dBm计算中,要注意基本概念,
用一个dBm减另外一个dBm时,得到的结果是dB,如:30dBm – 0dBm = 30dB。
3.手机信号强度表示
好了,那么手机上显示的数字的单位是那个呢,是dBm。当你仔细看的时候会发现这个值是负的,也就是说手机会显示比如 -67(dBm),那就说明信号很强了.
这里还说一个小知识:
中国移动的规范规定,手机接收电平>=(城市取-90dBm ;乡村取 -94dBm )时,则满足覆盖要求,也就是说此处无线信号强度满足覆盖要求。
-67dBm 要比-90dBm 信号要强20多个dB ,那么它在打电话接通成功率和通话过程中的话音质量都会好的多(当然也包括EDGE/GPRS上网的速度那些 )
所以,那个值越大信号就越好,因为那是个负值,而且在你手里的时候它永远是负值 ,如果你感
兴趣且附近有无线基站的天线的话,你也可以把你的手机尽量接近天线面板,那么值就越来越大,如果手机跟天线面板挨到一起,
那么它可能十分接近于0了(0是达不到的,这里的0的意思也不是说手机没信号了。)
在信号强度计选择工程模式,显示了很多参数,你只要看BCCHLev(控制信道电平值)它就是手机的信号强度值,单位dBm,多大的信号你的手机可以正常接听呢,BCCHLev-C1,C1也有显示数值,如:BCCHLev(-63) ,C1(34),表示你的手机在信号大于-97dBm的状况下是不会掉话的。
再来看手机发射功率要多大才合适呢,按GSM协议规定,手机发射功率是可以被基站控制的。基站通过下行SACCH信道,发出命令控制手机的发射功率级别,
每个功率级别差2dB;
GSM900 手机最大发射功率级别是5(2W=2000mw,33dBm),最小发射功率级别是19(3mw,5dBm),
DCS1800手机最大发射功率级别是0(1W,30dBm),最小发射功率级别是15(1mW,0dBm)。
当手机远离基站,或者处于无线阴影区时,基站可以命令手机发出较大功率,直至33dBm(GSM900),
以克服远距离传输或建筑物遮挡所造成的信号损耗。
强度计里的TXPower就是手机发射功率,你在拨打电话的状态下可以看出你的手机发射功率,也就是数值越大越省电,辐射越小,数值在5,
你的电话耗电大电池用不了一天,通话时别人经常听不到你的声音,你的手机经常会突然没信号,会掉话,这样你可以打投诉电话让运营商来做信号覆盖,
让你的手机信号好起来,减少辐射。
以上那么多字,只有一个核心意思。不要被你手机信号还有多少格欺骗!!!那都是手机厂商自己定义的。咱要玩专业点的,直接看信号强度dBm。
android系统查信号强度在设置—关于手机—网络里。
室内和室外的信号强度是有差距的。一般室外信号比室内好。
现在来看这个所谓的dBm,数值范围在-XX~0之间。这个数越大,信号强度越高。
-50dBm~0dBm范围内,恭喜你,你的信号已经好得很了。话说你就站在基站旁边是吧,哈
-90dBm~-60dBm,同样恭喜你,你基本不会面临打不了电话的问题。如果打不了的,找运营商吧,那是他们的问题。
G室内,DS放桌上信号强度-67dBm,23asu。作打电话状握手里,-75dBm,19asu。调整各种姿势,看到的最低是-83dBm,15asu。
这属于什么等级呢?简单说就是,信号很不错。室外没看,但肯定比这个高,
至于其他手机,可以自己上网去看,和DS的dBm值大多在一个档次。个别帖子炫耀自己大于-50dBm的,都是因为他就在基站边上。正常的范围是-90dBm~-60dBm。
====================================================================================
下面我们来看看手机没有修改时候的显示效果,关于手机–>状态信息–>SIM卡状态–>信号强度,就能看到手机的信号强度了。如下图所示:
1、当信号大于等于-85dBm时候,信号显示满格
2、当信号大于等于-95dBm时候,而小于-85dBm时,信号显示3格
3、当信号大于等于-105dBm时候,而小于-95dBm时,信号显示2格,不好捕捉到。
4、当信号大于等于-115dBm时候,而小于-105dBm时,信号显示1格,不好捕捉到。
5、当信号大于等于-140dBm时候,而小于-115dBm时,信号显示0格,不好捕捉到。
上面几个等级的相应划分的源代码在:rameworks/base/telephony/java/android/telephony/SignalStrength.java
中的getLteLevel()方法中,代码1如下:
- /**
- * Get LTE as level 0..4
- *
- * @hide
- */
- public int getLteLevel() {
- /*
- * TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
- * signal + noise RSRP = reference signal dBm RSRQ = quality of signal
- * dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
- * = -10log P1/P2 dB
- */
- int rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- int rsrpIconLevel = –1;
- int snrIconLevel = –1;
- int rsrpThreshType = Resources.getSystem().getInteger(com.android.internal.R.integer.
- config_LTE_RSRP_threshold_type);
- int[] threshRsrp;
- if (rsrpThreshType == RSRP_THRESH_TYPE_STRICT) {
- threshRsrp = RSRP_THRESH_STRICT;
- } else {
- threshRsrp = RSRP_THRESH_LENIENT;
- }
- //[ALPS01440836][ALPS01594704]-START: change level mapping rule of signal for CMCC
- if (!IS_BSP_PACKAGE) {
- IServiceStateExt ssExt = getPlugInInstance();
- if (ssExt != null) {
- rsrpIconLevel = ssExt.mapLteSignalLevel(mLteRsrp, mLteRssnr, mLteSignalStrength);
- //added by ouyang
- android.util.Log.e(“oyp”, “ssExt != null, rsrpIconLevel:”+ rsrpIconLevel);
- return rsrpIconLevel;
- } else {
- log(“[getLteLevel] null plug-in instance”);
- }
- }
- //modifed by ouyang [2015-10-12] start
- // if (mLteRsrp > -44) {
- // rsrpIconLevel = -1;
- // } else if (mLteRsrp >= -85) {
- // rsrpIconLevel = SIGNAL_STRENGTH_GREAT;
- // } else if (mLteRsrp >= -95) {
- // rsrpIconLevel = SIGNAL_STRENGTH_GOOD;
- // } else if (mLteRsrp >= -105) {
- // rsrpIconLevel = SIGNAL_STRENGTH_MODERATE;
- // } else if (mLteRsrp >= -115) {
- // rsrpIconLevel = SIGNAL_STRENGTH_POOR;
- // } else if (mLteRsrp >= -140) {
- // rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- // }
- if (mLteRsrp > –44) {
- rsrpIconLevel = –1;
- } else if (mLteRsrp >= –97) {
- rsrpIconLevel = SIGNAL_STRENGTH_GREAT;
- } else if (mLteRsrp >= –105) {
- rsrpIconLevel = SIGNAL_STRENGTH_GOOD;
- } else if (mLteRsrp >= –110) {
- rsrpIconLevel = SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRsrp >= –120) {
- rsrpIconLevel = SIGNAL_STRENGTH_POOR;
- } else if (mLteRsrp >= –140) {
- rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //modifed by ouyang [2015-10-12] end
- //added by ouyang
- android.util.Log.e(“oyp”, “getLTELevel – rsrp:” + mLteRsrp + ” rsrpIconLevel:”
- + rsrpIconLevel);
- /*
- * Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
- * dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
- * -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
- * Icon Only
- */
- if (mLteRssnr > 300) {
- snrIconLevel = –1;
- } else if (mLteRssnr >= 130) {
- snrIconLevel = SIGNAL_STRENGTH_GREAT;
- } else if (mLteRssnr >= 45) {
- snrIconLevel = SIGNAL_STRENGTH_GOOD;
- } else if (mLteRssnr >= 10) {
- snrIconLevel = SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRssnr >= –30) {
- snrIconLevel = SIGNAL_STRENGTH_POOR;
- } else if (mLteRssnr >= –200) {
- snrIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //added by ouyang
- android.util.Log.e(“oyp”, “getLTELevel – snr:” + mLteRssnr + ” snrIconLevel:” + snrIconLevel);
- if (DBG) log(“getLTELevel – rsrp:” + mLteRsrp + ” snr:” + mLteRssnr + ” rsrpIconLevel:”
- + rsrpIconLevel + ” snrIconLevel:” + snrIconLevel);
- /* Choose a measurement type to use for notification */
- if (snrIconLevel != –1 && rsrpIconLevel != –1) {
- /*
- * The number of bars displayed shall be the smaller of the bars
- * associated with LTE RSRP and the bars associated with the LTE
- * RS_SNR
- */
- //added by ouyang
- android.util.Log.e(“oyp”, “snrIconLevel != -1 && rsrpIconLevel != -1,”
- +“return rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel”
- +(rsrpIconLevel < snrIconLevel));
- return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel);
- }
- if (snrIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“oyp”, “snrIconLevel != -1”);
- return snrIconLevel;
- }
- if (rsrpIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“oyp”, “rsrpIconLevel != -1”);
- return rsrpIconLevel;
- }
- /* Valid values are (0-63, 99) as defined in TS 36.331 */
- if (mLteSignalStrength > 63) {
- rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (mLteSignalStrength >= 12) {
- rssiIconLevel = SIGNAL_STRENGTH_GREAT;
- } else if (mLteSignalStrength >= 8) {
- rssiIconLevel = SIGNAL_STRENGTH_GOOD;
- } else if (mLteSignalStrength >= 5) {
- rssiIconLevel = SIGNAL_STRENGTH_MODERATE;
- } else if (mLteSignalStrength >= 0) {
- rssiIconLevel = SIGNAL_STRENGTH_POOR;
- }
- //added by ouyang
- android.util.Log.e(“oyp”, “getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- if (DBG) {
- log(“getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- }
- return rssiIconLevel;
- //[ALPS01440836][ALPS01594704]-END: change level mapping rule of signal for CMCC
- }
可以看到未修改前,划分的几个等级是:
1.大于-85时候,等级为SIGNAL_STRENGTH_GREAT,即为4
2.大于-95时候,等级为SIGNAL_STRENGTH_GOOD,即为3
3.大于-105时候,等级为SIGNAL_STRENGTH_MODERATE,即为2
4.大于-115时候,等级为SIGNAL_STRENGTH_POOR,即为1
5.大于-140时候,等级为SIGNAL_STRENGTH_NONE_OR_UNKNOWN,即为0
6.大于-44时候,等级为-1
修改后,将上面的几个等级划分改为:
1.大于-97时候,等级为SIGNAL_STRENGTH_GREAT,即为4
2.大于-105时候,等级为SIGNAL_STRENGTH_GOOD,即为3
3.大于-110时候,等级为SIGNAL_STRENGTH_MODERATE,即为2
4.大于-120时候,等级为SIGNAL_STRENGTH_POOR,即为1
5.大于-140时候,等级为SIGNAL_STRENGTH_NONE_OR_UNKNOWN,即为0
6.大于-44时候,等级为-1
由于上面的,加入了MTK的修复patch,代码2如下:
- //[ALPS01440836][ALPS01594704]-START: change level mapping rule of signal for CMCC
- if (!IS_BSP_PACKAGE) {
- IServiceStateExt ssExt = getPlugInInstance();
- if (ssExt != null) {
- rsrpIconLevel = ssExt.mapLteSignalLevel(mLteRsrp, mLteRssnr, mLteSignalStrength);
- //added by ouyang
- android.util.Log.e(“oyp”, “ssExt != null, rsrpIconLevel:”+ rsrpIconLevel);
- return rsrpIconLevel;
- } else {
- log(“[getLteLevel] null plug-in instance”);
- }
- }
上面代码的意思是,先把这等级划分的值从加入的插件中去获取,如果获取不到再执行我上面修改的,所以要去修改
IServiceStateExt的mapLteSignalLevel(mLteRsrp, mLteRssnr, mLteSignalStrength)方法。当然如果没有这个插件的话,可以直接把我上面的这段代码2从代码1中注释即可。
由于IServiceStateExt是个接口,所以去修改它的具体实现类。通过查找源代码,找到了实现类DefaultServiceStateExt。
该类目录位于:vendor/mediatek/proprietary/frameworks/base/packages/FwkPlugin/src/com/mediatek/op/telephony/DefaultServiceStateExt.java
修改后代码如下:
- //[ALPS01440836][ALPS01594704]-START: change level mapping rule of signal for CMCC
- public int mapLteSignalLevel(int mLteRsrp, int mLteRssnr, int mLteSignalStrength) {
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “mapLteSignalLevel starting …….”);
- /*
- * TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
- * signal + noise RSRP = reference signal dBm RSRQ = quality of signal
- * dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
- * = -10log P1/P2 dB
- */
- int rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- int rsrpIconLevel = –1;
- int snrIconLevel = –1;
- //modifed by ouyang [2015-10-14] start
- // if (mLteRsrp > -44) {
- // rsrpIconLevel = -1;
- // } else if (mLteRsrp >= -85) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- // } else if (mLteRsrp >= -95) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- // } else if (mLteRsrp >= -105) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- // } else if (mLteRsrp >= -115) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- // } else if (mLteRsrp >= -140) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- // }
- if (mLteRsrp > –44) {
- rsrpIconLevel = –1;
- } else if (mLteRsrp >= –97) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (mLteRsrp >= –105) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (mLteRsrp >= –110) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRsrp >= –120) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- } else if (mLteRsrp >= –140) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “getLTELevel – rsrp:” + mLteRsrp + ” rsrpIconLevel:”+ rsrpIconLevel);
- //modifed by ouyang [2015-10-14] end
- /*
- * Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
- * dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
- * -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
- * Icon Only
- */
- if (mLteRssnr > 300) {
- snrIconLevel = –1;
- } else if (mLteRssnr >= 130) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (mLteRssnr >= 45) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (mLteRssnr >= 10) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRssnr >= –30) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- } else if (mLteRssnr >= –200) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “getLTELevel – snr:” + mLteRssnr + ” snrIconLevel:” + snrIconLevel);
- Log.i(TAG, “getLTELevel – rsrp:” + mLteRsrp + ” snr:” + mLteRssnr + ” rsrpIconLevel:”
- + rsrpIconLevel + ” snrIconLevel:” + snrIconLevel);
- /* Choose a measurement type to use for notification */
- if (snrIconLevel != –1 && rsrpIconLevel != –1) {
- /*
- * The number of bars displayed shall be the smaller of the bars
- * associated with LTE RSRP and the bars associated with the LTE
- * RS_SNR
- */
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “snrIconLevel != -1 && rsrpIconLevel != -1,”
- +“return rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel”
- +(rsrpIconLevel < snrIconLevel));
- return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel);
- }
- if (snrIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “snrIconLevel != -1”);
- return snrIconLevel;
- }
- if (rsrpIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “rsrpIconLevel != -1”);
- return rsrpIconLevel;
- }
- /* Valid values are (0-63, 99) as defined in TS 36.331 */
- if (mLteSignalStrength > 63) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (mLteSignalStrength >= 12) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (mLteSignalStrength >= 8) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (mLteSignalStrength >= 5) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else if (mLteSignalStrength >= 0) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- }
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- Log.i(TAG, “getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- return rssiIconLevel;
- }
- //[ALPS01440836][ALPS01594704]-END: change level mapping rule of signal for CMCC
修改完代码后,make systemimage后烧录到MTK平台手机即可。
====================================================================================
修改后的效果图如下所示:
1、当信号大于等于-97dBm时候,信号显示满格,而修改之前需要大于-85dBm。
2、当信号大于等于-105dBm时候,而小于-97dBm时,信号显示少一个,而修改之前需要大于-95dBm。
3、当信号大于等于-110dBm时候,而小于-105dBm时,信号显示2格,不好捕捉到。
4、当信号大于等于-120dBm时候,而小于-110dBm时,信号显示1格,不好捕捉到。
5、当信号大于等于-140dBm时候,而小于-120dBm时,信号显示0格,不好捕捉到。
====================================================================================
当然,要修改电信、移动、联通的3G、2G信号也可以在这个类中去修改。
最后附上源代码 \frameworks\base\telephony\java\android\telephony\SignalStrength.java
- /*
- * Copyright (C) 2014 MediaTek Inc.
- * Modification based on code covered by the mentioned copyright
- * and/or permission notice(s).
- */
- /*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the “License”);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an “AS IS” BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package android.telephony;
- import android.os.Bundle;
- import android.os.Parcel;
- import android.os.Parcelable;
- import android.telephony.Rlog;
- import android.content.res.Resources;
- import android.os.SystemProperties;
- import com.mediatek.common.MPlugin;
- import com.mediatek.common.telephony.IServiceStateExt;
- /**
- * Contains phone signal strength related information.
- */
- public class SignalStrength implements Parcelable {
- private static final String LOG_TAG = “SignalStrength”;
- private static final boolean DBG = false;
- /** @hide */
- public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
- /** @hide */
- public static final int SIGNAL_STRENGTH_POOR = 1;
- /** @hide */
- public static final int SIGNAL_STRENGTH_MODERATE = 2;
- /** @hide */
- public static final int SIGNAL_STRENGTH_GOOD = 3;
- /** @hide */
- public static final int SIGNAL_STRENGTH_GREAT = 4;
- /** @hide */
- public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
- /** @hide */
- public static final String[] SIGNAL_STRENGTH_NAMES = {
- “none”, “poor”, “moderate”, “good”, “great”
- };
- /** @hide */
- //Use int max, as -1 is a valid value in signal strength
- public static final int INVALID = 0x7FFFFFFF;
- private static final int RSRP_THRESH_TYPE_STRICT = 0;
- //modified by ouyang
- //private static final int[] RSRP_THRESH_STRICT = new int[] {-140, -115, -105, -95, -85, -44};
- private static final int[] RSRP_THRESH_STRICT = new int[] {-140, –120, –110, –105, –97, –44};
- private static final int[] RSRP_THRESH_LENIENT = new int[] {-140, –128, –118, –108, –98, –44};
- private int mGsmSignalStrength; // Valid values are (0-31, 99) as defined in TS 27.007 8.5
- private int mGsmBitErrorRate; // bit error rate (0-7, 99) as defined in TS 27.007 8.5
- private int mCdmaDbm; // This value is the RSSI value
- private int mCdmaEcio; // This value is the Ec/Io
- private int mEvdoDbm; // This value is the EVDO RSSI value
- private int mEvdoEcio; // This value is the EVDO Ec/Io
- private int mEvdoSnr; // Valid values are 0-8. 8 is the highest signal to noise ratio
- private int mLteSignalStrength;
- private int mLteRsrp;
- private int mLteRsrq;
- private int mLteRssnr;
- private int mLteCqi;
- //MTK-START
- private int mGsmRssiQdbm; // This valus is GSM 3G rssi value
- private int mGsmRscpQdbm; // This valus is GSM 3G rscp value
- private int mGsmEcn0Qdbm; // This valus is GSM 3G ecn0 value
- private static IServiceStateExt mServiceStateExt = null;
- private static final boolean IS_BSP_PACKAGE = (SystemProperties.getInt(“ro.mtk_bsp_package”, 0) == 1);
- //MTK-END
- private boolean isGsm; // This value is set by the ServiceStateTracker onSignalStrengthResult
- /**
- * Create a new SignalStrength from a intent notifier Bundle
- *
- * This method is used by PhoneStateIntentReceiver and maybe by
- * external applications.
- *
- * @param m Bundle from intent notifier
- * @return newly created SignalStrength
- *
- * @hide
- */
- public static SignalStrength newFromBundle(Bundle m) {
- SignalStrength ret;
- ret = new SignalStrength();
- ret.setFromNotifierBundle(m);
- return ret;
- }
- /**
- * Empty constructor
- *
- * @hide
- */
- public SignalStrength() {
- mGsmSignalStrength = 99;
- mGsmBitErrorRate = –1;
- mCdmaDbm = –1;
- mCdmaEcio = –1;
- mEvdoDbm = –1;
- mEvdoEcio = –1;
- mEvdoSnr = –1;
- mLteSignalStrength = 99;
- mLteRsrp = INVALID;
- mLteRsrq = INVALID;
- mLteRssnr = INVALID;
- mLteCqi = INVALID;
- isGsm = true;
- }
- /**
- * This constructor is used to create SignalStrength with default
- * values and set the isGsmFlag with the value passed in the input
- *
- * @param gsmFlag true if Gsm Phone,false if Cdma phone
- * @return newly created SignalStrength
- * @hide
- */
- public SignalStrength(boolean gsmFlag) {
- mGsmSignalStrength = 99;
- mGsmBitErrorRate = –1;
- mCdmaDbm = –1;
- mCdmaEcio = –1;
- mEvdoDbm = –1;
- mEvdoEcio = –1;
- mEvdoSnr = –1;
- mLteSignalStrength = 99;
- mLteRsrp = INVALID;
- mLteRsrq = INVALID;
- mLteRssnr = INVALID;
- mLteCqi = INVALID;
- isGsm = gsmFlag;
- }
- /**
- * Constructor
- *
- * @hide
- */
- public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
- int cdmaDbm, int cdmaEcio,
- int evdoDbm, int evdoEcio, int evdoSnr,
- int lteSignalStrength, int lteRsrp, int lteRsrq, int lteRssnr, int lteCqi,
- boolean gsmFlag) {
- initialize(gsmSignalStrength, gsmBitErrorRate, cdmaDbm, cdmaEcio,
- evdoDbm, evdoEcio, evdoSnr, lteSignalStrength, lteRsrp,
- lteRsrq, lteRssnr, lteCqi, gsmFlag);
- }
- //MTK-START
- /**
- * Constructor
- *
- * @hide
- */
- public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
- int cdmaDbm, int cdmaEcio,
- int evdoDbm, int evdoEcio, int evdoSnr,
- int lteSignalStrength, int lteRsrp, int lteRsrq, int lteRssnr, int lteCqi,
- boolean gsmFlag, int gsmRssiQdbm, int gsmRscpQdbm, int gsmEcn0Qdbm) {
- initialize(gsmSignalStrength, gsmBitErrorRate, cdmaDbm, cdmaEcio,
- evdoDbm, evdoEcio, evdoSnr, lteSignalStrength, lteRsrp,
- lteRsrq, lteRssnr, lteCqi, gsmFlag);
- mGsmRssiQdbm = gsmRssiQdbm;
- mGsmRscpQdbm = gsmRscpQdbm;
- mGsmEcn0Qdbm = gsmEcn0Qdbm;
- }
- //MTK-END
- /**
- * Constructor
- *
- * @hide
- */
- public SignalStrength(int gsmSignalStrength, int gsmBitErrorRate,
- int cdmaDbm, int cdmaEcio,
- int evdoDbm, int evdoEcio, int evdoSnr,
- boolean gsmFlag) {
- initialize(gsmSignalStrength, gsmBitErrorRate, cdmaDbm, cdmaEcio,
- evdoDbm, evdoEcio, evdoSnr, 99, INVALID,
- INVALID, INVALID, INVALID, gsmFlag);
- }
- /**
- * Copy constructors
- *
- * @param s Source SignalStrength
- *
- * @hide
- */
- public SignalStrength(SignalStrength s) {
- copyFrom(s);
- }
- /**
- * Initialize gsm/cdma values, sets lte values to defaults.
- *
- * @param gsmSignalStrength
- * @param gsmBitErrorRate
- * @param cdmaDbm
- * @param cdmaEcio
- * @param evdoDbm
- * @param evdoEcio
- * @param evdoSnr
- * @param gsm
- *
- * @hide
- */
- public void initialize(int gsmSignalStrength, int gsmBitErrorRate,
- int cdmaDbm, int cdmaEcio,
- int evdoDbm, int evdoEcio, int evdoSnr,
- boolean gsm) {
- initialize(gsmSignalStrength, gsmBitErrorRate, cdmaDbm, cdmaEcio,
- evdoDbm, evdoEcio, evdoSnr, 99, INVALID,
- INVALID, INVALID, INVALID, gsm);
- }
- /**
- * Initialize all the values
- *
- * @param gsmSignalStrength
- * @param gsmBitErrorRate
- * @param cdmaDbm
- * @param cdmaEcio
- * @param evdoDbm
- * @param evdoEcio
- * @param evdoSnr
- * @param lteSignalStrength
- * @param lteRsrp
- * @param lteRsrq
- * @param lteRssnr
- * @param lteCqi
- * @param gsm
- *
- * @hide
- */
- public void initialize(int gsmSignalStrength, int gsmBitErrorRate,
- int cdmaDbm, int cdmaEcio,
- int evdoDbm, int evdoEcio, int evdoSnr,
- int lteSignalStrength, int lteRsrp, int lteRsrq, int lteRssnr, int lteCqi,
- boolean gsm) {
- mGsmSignalStrength = gsmSignalStrength;
- mGsmBitErrorRate = gsmBitErrorRate;
- mCdmaDbm = cdmaDbm;
- mCdmaEcio = cdmaEcio;
- mEvdoDbm = evdoDbm;
- mEvdoEcio = evdoEcio;
- mEvdoSnr = evdoSnr;
- mLteSignalStrength = lteSignalStrength;
- mLteRsrp = lteRsrp;
- mLteRsrq = lteRsrq;
- mLteRssnr = lteRssnr;
- mLteCqi = lteCqi;
- isGsm = gsm;
- if (DBG) {
- log(“initialize: “ + toString());
- }
- }
- private static IServiceStateExt getPlugInInstance() {
- log(“SignalStrength get plugin”);
- if (!IS_BSP_PACKAGE) {
- if (mServiceStateExt == null) {
- try {
- mServiceStateExt = MPlugin.createInstance(IServiceStateExt.class.getName());
- } catch (RuntimeException e) {
- log(“Get plugin fail”);
- mServiceStateExt = null;
- e.printStackTrace();
- }
- }
- } else {
- log(“BSP package should not use plug in”);
- }
- return mServiceStateExt;
- }
- /**
- * @hide
- */
- protected void copyFrom(SignalStrength s) {
- mGsmSignalStrength = s.mGsmSignalStrength;
- mGsmBitErrorRate = s.mGsmBitErrorRate;
- mCdmaDbm = s.mCdmaDbm;
- mCdmaEcio = s.mCdmaEcio;
- mEvdoDbm = s.mEvdoDbm;
- mEvdoEcio = s.mEvdoEcio;
- mEvdoSnr = s.mEvdoSnr;
- mLteSignalStrength = s.mLteSignalStrength;
- mLteRsrp = s.mLteRsrp;
- mLteRsrq = s.mLteRsrq;
- mLteRssnr = s.mLteRssnr;
- mLteCqi = s.mLteCqi;
- isGsm = s.isGsm;
- mGsmRssiQdbm = s.mGsmRssiQdbm;
- mGsmRscpQdbm = s.mGsmRscpQdbm;
- mGsmEcn0Qdbm = s.mGsmEcn0Qdbm;
- }
- /**
- * Construct a SignalStrength object from the given parcel.
- *
- * @hide
- */
- public SignalStrength(Parcel in) {
- if (DBG) {
- log(“Size of signalstrength parcel:” + in.dataSize());
- }
- mGsmSignalStrength = in.readInt();
- mGsmBitErrorRate = in.readInt();
- mCdmaDbm = in.readInt();
- mCdmaEcio = in.readInt();
- mEvdoDbm = in.readInt();
- mEvdoEcio = in.readInt();
- mEvdoSnr = in.readInt();
- mLteSignalStrength = in.readInt();
- mLteRsrp = in.readInt();
- mLteRsrq = in.readInt();
- mLteRssnr = in.readInt();
- mLteCqi = in.readInt();
- isGsm = (in.readInt() != 0);
- //MTK-START [ALPS00516994]
- mGsmRssiQdbm = in.readInt();
- mGsmRscpQdbm = in.readInt();
- mGsmEcn0Qdbm = in.readInt();
- //MTK-END [ALPS00516994]
- }
- /**
- * Make a SignalStrength object from the given parcel as passed up by
- * the ril which does not have isGsm. isGsm will be changed by ServiceStateTracker
- * so the default is a don’t care.
- *
- * @hide
- */
- public static SignalStrength makeSignalStrengthFromRilParcel(Parcel in) {
- if (DBG) {
- log(“Size of signalstrength parcel:” + in.dataSize());
- }
- SignalStrength ss = new SignalStrength();
- ss.mGsmSignalStrength = in.readInt();
- ss.mGsmBitErrorRate = in.readInt();
- ss.mCdmaDbm = in.readInt();
- ss.mCdmaEcio = in.readInt();
- ss.mEvdoDbm = in.readInt();
- ss.mEvdoEcio = in.readInt();
- ss.mEvdoSnr = in.readInt();
- ss.mLteSignalStrength = in.readInt();
- ss.mLteRsrp = in.readInt();
- ss.mLteRsrq = in.readInt();
- ss.mLteRssnr = in.readInt();
- ss.mLteCqi = in.readInt();
- ss.isGsm = (in.readInt() != 0);
- //MTK-START [ALPS00516994]
- ss.mGsmRssiQdbm = in.readInt();
- ss.mGsmRscpQdbm = in.readInt();
- ss.mGsmEcn0Qdbm = in.readInt();
- //MTK-END [ALPS00516994]
- return ss;
- }
- /**
- * {@link Parcelable#writeToParcel}
- */
- public void writeToParcel(Parcel out, int flags) {
- out.writeInt(mGsmSignalStrength);
- out.writeInt(mGsmBitErrorRate);
- out.writeInt(mCdmaDbm);
- out.writeInt(mCdmaEcio);
- out.writeInt(mEvdoDbm);
- out.writeInt(mEvdoEcio);
- out.writeInt(mEvdoSnr);
- out.writeInt(mLteSignalStrength);
- out.writeInt(mLteRsrp);
- out.writeInt(mLteRsrq);
- out.writeInt(mLteRssnr);
- out.writeInt(mLteCqi);
- out.writeInt(isGsm ? 1 : 0);
- //MTK-START [ALPS00516994]
- out.writeInt(mGsmRssiQdbm);
- out.writeInt(mGsmRscpQdbm);
- out.writeInt(mGsmEcn0Qdbm);
- //MTK-END [ALPS00516994]
- }
- /**
- * {@link Parcelable#describeContents}
- */
- public int describeContents() {
- return 0;
- }
- /**
- * {@link Parcelable.Creator}
- *
- * @hide
- */
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
- public SignalStrength createFromParcel(Parcel in) {
- return new SignalStrength(in);
- }
- public SignalStrength[] newArray(int size) {
- return new SignalStrength[size];
- }
- };
- /**
- * Validate the individual signal strength fields as per the range
- * specified in ril.h
- * Set to invalid any field that is not in the valid range
- * Cdma, evdo, lte rsrp & rsrq values are sign converted
- * when received from ril interface
- *
- * @return
- * Valid values for all signalstrength fields
- * @hide
- */
- public void validateInput() {
- if (DBG) {
- log(“Signal before validate=” + this);
- }
- // TS 27.007 8.5
- mGsmSignalStrength = mGsmSignalStrength >= 0 ? mGsmSignalStrength : 99;
- // BER no change;
- mCdmaDbm = mCdmaDbm > 0 ? -mCdmaDbm : –120;
- mCdmaEcio = (mCdmaEcio > 0) ? -mCdmaEcio : –160;
- mEvdoDbm = (mEvdoDbm > 0) ? -mEvdoDbm : –120;
- mEvdoEcio = (mEvdoEcio >= 0) ? -mEvdoEcio : –1;
- mEvdoSnr = ((mEvdoSnr > 0) && (mEvdoSnr <= 8)) ? mEvdoSnr : –1;
- // TS 36.214 Physical Layer Section 5.1.3, TS 36.331 RRC
- mLteSignalStrength = (mLteSignalStrength >= 0) ? mLteSignalStrength : 99;
- mLteRsrp = ((mLteRsrp >= 44) && (mLteRsrp <= 140)) ? -mLteRsrp : SignalStrength.INVALID;
- mLteRsrq = ((mLteRsrq >= 3) && (mLteRsrq <= 20)) ? -mLteRsrq : SignalStrength.INVALID;
- mLteRssnr = ((mLteRssnr >= –200) && (mLteRssnr <= 300)) ? mLteRssnr
- : SignalStrength.INVALID;
- // Cqi no change
- if (DBG) {
- log(“Signal after validate=” + this);
- }
- }
- /**
- * @param true – Gsm, Lte phones
- * false – Cdma phones
- *
- * Used by voice phone to set the isGsm
- * flag
- * @hide
- */
- public void setGsm(boolean gsmFlag) {
- isGsm = gsmFlag;
- }
- /**
- * Get the GSM Signal Strength, valid values are (0-31, 99) as defined in TS
- * 27.007 8.5
- */
- public int getGsmSignalStrength() {
- return this.mGsmSignalStrength;
- }
- /**
- * Get the GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5
- */
- public int getGsmBitErrorRate() {
- return this.mGsmBitErrorRate;
- }
- /**
- * Get the CDMA RSSI value in dBm
- */
- public int getCdmaDbm() {
- return this.mCdmaDbm;
- }
- /**
- * Get the CDMA Ec/Io value in dB*10
- */
- public int getCdmaEcio() {
- return this.mCdmaEcio;
- }
- /**
- * Get the EVDO RSSI value in dBm
- */
- public int getEvdoDbm() {
- return this.mEvdoDbm;
- }
- /**
- * Get the EVDO Ec/Io value in dB*10
- */
- public int getEvdoEcio() {
- return this.mEvdoEcio;
- }
- /**
- * Get the signal to noise ratio. Valid values are 0-8. 8 is the highest.
- */
- public int getEvdoSnr() {
- return this.mEvdoSnr;
- }
- /** @hide */
- public int getLteSignalStrength() {
- return mLteSignalStrength;
- }
- /** @hide */
- public int getLteRsrp() {
- return mLteRsrp;
- }
- /** @hide */
- public int getLteRsrq() {
- return mLteRsrq;
- }
- /** @hide */
- public int getLteRssnr() {
- return mLteRssnr;
- }
- /** @hide */
- public int getLteCqi() {
- return mLteCqi;
- }
- /**
- * Get signal level as an int from 0..4
- *
- * @hide
- */
- public int getLevel() {
- int level;
- if (isGsm) {
- level = getLteLevel();
- //MTE-START [ALPS01200757]
- //if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
- if (!isCampOnLte()) {
- //MTE-END [ALPS01200757]
- level = getGsmLevel();
- }
- } else {
- int cdmaLevel = getCdmaLevel();
- int evdoLevel = getEvdoLevel();
- if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
- /* We don’t know evdo, use cdma */
- level = cdmaLevel;
- } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
- /* We don’t know cdma, use evdo */
- level = evdoLevel;
- } else {
- /* We know both, use the lowest level */
- level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
- }
- }
- if (DBG) {
- log(“getLevel=” + level);
- }
- return level;
- }
- /**
- * Get the signal level as an asu value between 0..31, 99 is unknown
- *
- * @hide
- */
- public int getAsuLevel() {
- int asuLevel;
- if (isGsm) {
- //MTE-START [ALPS01200757]
- //if (getLteLevel() == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
- if (!isCampOnLte()) {
- //MTE-END [ALPS01200757]
- asuLevel = getGsmAsuLevel();
- } else {
- asuLevel = getLteAsuLevel();
- }
- } else {
- int cdmaAsuLevel = getCdmaAsuLevel();
- int evdoAsuLevel = getEvdoAsuLevel();
- if (evdoAsuLevel == 0) {
- /* We don’t know evdo use, cdma */
- asuLevel = cdmaAsuLevel;
- } else if (cdmaAsuLevel == 0) {
- /* We don’t know cdma use, evdo */
- asuLevel = evdoAsuLevel;
- } else {
- /* We know both, use the lowest level */
- asuLevel = cdmaAsuLevel < evdoAsuLevel ? cdmaAsuLevel : evdoAsuLevel;
- }
- }
- if (DBG) {
- log(“getAsuLevel=” + asuLevel);
- }
- return asuLevel;
- }
- /**
- * Get the signal strength as dBm
- *
- * @hide
- */
- public int getDbm() {
- int dBm;
- if(isGsm()) {
- dBm = getLteDbm();
- //MTE-START [ALPS01200757]
- //if (dBm == INVALID) {
- if (!isCampOnLte()) {
- //MTE-END [ALPS01200757]
- dBm = getGsmDbm();
- }
- } else {
- int cdmaDbm = getCdmaDbm();
- int evdoDbm = getEvdoDbm();
- return (evdoDbm == –120 || evdoDbm == –113) ? cdmaDbm
- : ((cdmaDbm == –120 || cdmaDbm == –113) ? evdoDbm
- : (cdmaDbm < evdoDbm ? cdmaDbm : evdoDbm));
- }
- if (DBG) {
- log(“getDbm=” + dBm);
- }
- return dBm;
- }
- /**
- * Get Gsm signal strength as dBm
- *
- * @hide
- */
- public int getGsmDbm() {
- int dBm;
- int gsmSignalStrength = getGsmSignalStrength();
- int asu = (gsmSignalStrength == 99 ? –1 : gsmSignalStrength);
- if (asu != –1) {
- if (!IS_BSP_PACKAGE) {
- IServiceStateExt ssExt = getPlugInInstance();
- if (ssExt != null) {
- dBm = ssExt.mapGsmSignalDbm(mGsmRscpQdbm, asu);
- } else {
- log(“[getGsmDbm] null plug-in instance”);
- }
- }
- log(“mapGsmSignalDbm() mGsmRscpQdbm=” + mGsmRscpQdbm + ” asu=” + asu);
- if (mGsmRscpQdbm < 0) {
- dBm = mGsmRscpQdbm / 4; //Return raw value for 3G Network
- } else {
- dBm = –113 + (2 * asu);
- }
- } else {
- dBm = –1;
- }
- if (DBG) {
- log(“getGsmDbm=” + dBm);
- }
- return dBm;
- }
- /**
- * Get gsm as level 0..4
- *
- * @hide
- */
- public int getGsmLevel() {
- int level;
- // ASU ranges from 0 to 31 – TS 27.007 Sec 8.5
- // asu = 0 (-113dB or less) is very weak
- // signal, its better to show 0 bars to the user in such cases.
- // asu = 99 is a special case, where the signal strength is unknown.
- int asu = getGsmSignalStrength();
- if (!IS_BSP_PACKAGE) {
- IServiceStateExt ssExt = getPlugInInstance();
- if (ssExt != null) {
- level = ssExt.mapGsmSignalLevel(asu, mGsmRscpQdbm);
- return level;
- } else {
- log(“[getGsmLevel] null plug-in instance”);
- }
- }
- // [ALPS01055164] — START , for 3G network
- if (mGsmRscpQdbm < 0) {
- // 3G network
- if (asu <= 5 || asu == 99) {
- level = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (asu >= 15) {
- level = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (asu >= 12) {
- level = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (asu >= 9) {
- level = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else {
- level = SignalStrength.SIGNAL_STRENGTH_POOR;
- }
- // [ALPS01055164] — END
- } else {
- // 2G network
- if (asu <= 2 || asu == 99) {
- level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (asu >= 12) {
- level = SIGNAL_STRENGTH_GREAT;
- } else if (asu >= 8) {
- level = SIGNAL_STRENGTH_GOOD;
- } else if (asu >= 5) {
- level = SIGNAL_STRENGTH_MODERATE;
- } else {
- level = SIGNAL_STRENGTH_POOR;
- }
- }
- if (DBG) {
- log(“getGsmLevel=” + level);
- }
- return level;
- }
- /**
- * Get the gsm signal level as an asu value between 0..31, 99 is unknown
- *
- * @hide
- */
- public int getGsmAsuLevel() {
- // ASU ranges from 0 to 31 – TS 27.007 Sec 8.5
- // asu = 0 (-113dB or less) is very weak
- // signal, its better to show 0 bars to the user in such cases.
- // asu = 99 is a special case, where the signal strength is unknown.
- int level = getGsmSignalStrength();
- if (DBG) {
- log(“getGsmAsuLevel=” + level);
- }
- return level;
- }
- /**
- * Get cdma as level 0..4
- *
- * @hide
- */
- public int getCdmaLevel() {
- final int cdmaDbm = getCdmaDbm();
- final int cdmaEcio = getCdmaEcio();
- int levelDbm;
- int levelEcio;
- if (cdmaDbm >= –75) levelDbm = SIGNAL_STRENGTH_GREAT;
- else if (cdmaDbm >= –85) levelDbm = SIGNAL_STRENGTH_GOOD;
- else if (cdmaDbm >= –95) levelDbm = SIGNAL_STRENGTH_MODERATE;
- else if (cdmaDbm >= –100) levelDbm = SIGNAL_STRENGTH_POOR;
- else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- // Ec/Io are in dB*10
- if (cdmaEcio >= –90) levelEcio = SIGNAL_STRENGTH_GREAT;
- else if (cdmaEcio >= –110) levelEcio = SIGNAL_STRENGTH_GOOD;
- else if (cdmaEcio >= –130) levelEcio = SIGNAL_STRENGTH_MODERATE;
- else if (cdmaEcio >= –150) levelEcio = SIGNAL_STRENGTH_POOR;
- else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- int level = (levelDbm < levelEcio) ? levelDbm : levelEcio;
- /// M: [C2K] Only use dbm as to calculate level. @{
- if (isC2KSupport()) {
- level = levelDbm;
- }
- /// M: [C2K] Only use dbm as to calculate level. @}
- if (DBG) {
- log(“getCdmaLevel=” + level);
- }
- return level;
- }
- /**
- * Get the cdma signal level as an asu value between 0..31, 99 is unknown
- *
- * @hide
- */
- public int getCdmaAsuLevel() {
- final int cdmaDbm = getCdmaDbm();
- final int cdmaEcio = getCdmaEcio();
- int cdmaAsuLevel;
- int ecioAsuLevel;
- if (cdmaDbm >= –75) cdmaAsuLevel = 16;
- else if (cdmaDbm >= –82) cdmaAsuLevel = 8;
- else if (cdmaDbm >= –90) cdmaAsuLevel = 4;
- else if (cdmaDbm >= –95) cdmaAsuLevel = 2;
- else if (cdmaDbm >= –100) cdmaAsuLevel = 1;
- else cdmaAsuLevel = 99;
- // Ec/Io are in dB*10
- if (cdmaEcio >= –90) ecioAsuLevel = 16;
- else if (cdmaEcio >= –100) ecioAsuLevel = 8;
- else if (cdmaEcio >= –115) ecioAsuLevel = 4;
- else if (cdmaEcio >= –130) ecioAsuLevel = 2;
- else if (cdmaEcio >= –150) ecioAsuLevel = 1;
- else ecioAsuLevel = 99;
- int level = (cdmaAsuLevel < ecioAsuLevel) ? cdmaAsuLevel : ecioAsuLevel;
- if (DBG) {
- log(“getCdmaAsuLevel=” + level);
- }
- return level;
- }
- /**
- * Get Evdo as level 0..4
- *
- * @hide
- */
- public int getEvdoLevel() {
- int evdoDbm = getEvdoDbm();
- int evdoSnr = getEvdoSnr();
- int levelEvdoDbm;
- int levelEvdoSnr;
- if (evdoDbm >= –65) levelEvdoDbm = SIGNAL_STRENGTH_GREAT;
- else if (evdoDbm >= –75) levelEvdoDbm = SIGNAL_STRENGTH_GOOD;
- else if (evdoDbm >= –90) levelEvdoDbm = SIGNAL_STRENGTH_MODERATE;
- else if (evdoDbm >= –105) levelEvdoDbm = SIGNAL_STRENGTH_POOR;
- else levelEvdoDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- if (evdoSnr >= 7) levelEvdoSnr = SIGNAL_STRENGTH_GREAT;
- else if (evdoSnr >= 5) levelEvdoSnr = SIGNAL_STRENGTH_GOOD;
- else if (evdoSnr >= 3) levelEvdoSnr = SIGNAL_STRENGTH_MODERATE;
- else if (evdoSnr >= 1) levelEvdoSnr = SIGNAL_STRENGTH_POOR;
- else levelEvdoSnr = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- int level = (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
- if (DBG) {
- log(“getEvdoLevel=” + level);
- }
- return level;
- }
- /**
- * Get the evdo signal level as an asu value between 0..31, 99 is unknown
- *
- * @hide
- */
- public int getEvdoAsuLevel() {
- int evdoDbm = getEvdoDbm();
- int evdoSnr = getEvdoSnr();
- int levelEvdoDbm;
- int levelEvdoSnr;
- if (evdoDbm >= –65) levelEvdoDbm = 16;
- else if (evdoDbm >= –75) levelEvdoDbm = 8;
- else if (evdoDbm >= –85) levelEvdoDbm = 4;
- else if (evdoDbm >= –95) levelEvdoDbm = 2;
- else if (evdoDbm >= –105) levelEvdoDbm = 1;
- else levelEvdoDbm = 99;
- if (evdoSnr >= 7) levelEvdoSnr = 16;
- else if (evdoSnr >= 6) levelEvdoSnr = 8;
- else if (evdoSnr >= 5) levelEvdoSnr = 4;
- else if (evdoSnr >= 3) levelEvdoSnr = 2;
- else if (evdoSnr >= 1) levelEvdoSnr = 1;
- else levelEvdoSnr = 99;
- int level = (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
- if (DBG) {
- log(“getEvdoAsuLevel=” + level);
- }
- return level;
- }
- /**
- * Get LTE as dBm
- *
- * @hide
- */
- public int getLteDbm() {
- return mLteRsrp;
- }
- /**
- * Get LTE as level 0..4
- *
- * @hide
- */
- public int getLteLevel() {
- /*
- * TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
- * signal + noise RSRP = reference signal dBm RSRQ = quality of signal
- * dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
- * = -10log P1/P2 dB
- */
- int rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- int rsrpIconLevel = –1;
- int snrIconLevel = –1;
- int rsrpThreshType = Resources.getSystem().getInteger(com.android.internal.R.integer.
- config_LTE_RSRP_threshold_type);
- int[] threshRsrp;
- if (rsrpThreshType == RSRP_THRESH_TYPE_STRICT) {
- threshRsrp = RSRP_THRESH_STRICT;
- } else {
- threshRsrp = RSRP_THRESH_LENIENT;
- }
- //[ALPS01440836][ALPS01594704]-START: change level mapping rule of signal for CMCC
- if (!IS_BSP_PACKAGE) {
- IServiceStateExt ssExt = getPlugInInstance();
- if (ssExt != null) {
- rsrpIconLevel = ssExt.mapLteSignalLevel(mLteRsrp, mLteRssnr, mLteSignalStrength);
- //added by ouyang
- android.util.Log.e(“oyp”, “ssExt != null, rsrpIconLevel:”+ rsrpIconLevel);
- return rsrpIconLevel;
- } else {
- log(“[getLteLevel] null plug-in instance”);
- }
- }
- //modifed by ouyang [2015-10-12] start
- // if (mLteRsrp > -44) {
- // rsrpIconLevel = -1;
- // } else if (mLteRsrp >= -85) {
- // rsrpIconLevel = SIGNAL_STRENGTH_GREAT;
- // } else if (mLteRsrp >= -95) {
- // rsrpIconLevel = SIGNAL_STRENGTH_GOOD;
- // } else if (mLteRsrp >= -105) {
- // rsrpIconLevel = SIGNAL_STRENGTH_MODERATE;
- // } else if (mLteRsrp >= -115) {
- // rsrpIconLevel = SIGNAL_STRENGTH_POOR;
- // } else if (mLteRsrp >= -140) {
- // rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- // }
- if (mLteRsrp > –44) {
- rsrpIconLevel = –1;
- } else if (mLteRsrp >= –97) {
- rsrpIconLevel = SIGNAL_STRENGTH_GREAT;
- } else if (mLteRsrp >= –105) {
- rsrpIconLevel = SIGNAL_STRENGTH_GOOD;
- } else if (mLteRsrp >= –110) {
- rsrpIconLevel = SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRsrp >= –120) {
- rsrpIconLevel = SIGNAL_STRENGTH_POOR;
- } else if (mLteRsrp >= –140) {
- rsrpIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //modifed by ouyang [2015-10-12] end
- //added by ouyang
- android.util.Log.e(“oyp”, “getLTELevel – rsrp:” + mLteRsrp + ” rsrpIconLevel:”
- + rsrpIconLevel);
- /*
- * Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
- * dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
- * -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
- * Icon Only
- */
- if (mLteRssnr > 300) {
- snrIconLevel = –1;
- } else if (mLteRssnr >= 130) {
- snrIconLevel = SIGNAL_STRENGTH_GREAT;
- } else if (mLteRssnr >= 45) {
- snrIconLevel = SIGNAL_STRENGTH_GOOD;
- } else if (mLteRssnr >= 10) {
- snrIconLevel = SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRssnr >= –30) {
- snrIconLevel = SIGNAL_STRENGTH_POOR;
- } else if (mLteRssnr >= –200) {
- snrIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //added by ouyang
- android.util.Log.e(“oyp”, “getLTELevel – snr:” + mLteRssnr + ” snrIconLevel:” + snrIconLevel);
- if (DBG) log(“getLTELevel – rsrp:” + mLteRsrp + ” snr:” + mLteRssnr + ” rsrpIconLevel:”
- + rsrpIconLevel + ” snrIconLevel:” + snrIconLevel);
- /* Choose a measurement type to use for notification */
- if (snrIconLevel != –1 && rsrpIconLevel != –1) {
- /*
- * The number of bars displayed shall be the smaller of the bars
- * associated with LTE RSRP and the bars associated with the LTE
- * RS_SNR
- */
- //added by ouyang
- android.util.Log.e(“oyp”, “snrIconLevel != -1 && rsrpIconLevel != -1,”
- +“return rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel”
- +(rsrpIconLevel < snrIconLevel));
- return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel);
- }
- if (snrIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“oyp”, “snrIconLevel != -1”);
- return snrIconLevel;
- }
- if (rsrpIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“oyp”, “rsrpIconLevel != -1”);
- return rsrpIconLevel;
- }
- /* Valid values are (0-63, 99) as defined in TS 36.331 */
- if (mLteSignalStrength > 63) {
- rssiIconLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (mLteSignalStrength >= 12) {
- rssiIconLevel = SIGNAL_STRENGTH_GREAT;
- } else if (mLteSignalStrength >= 8) {
- rssiIconLevel = SIGNAL_STRENGTH_GOOD;
- } else if (mLteSignalStrength >= 5) {
- rssiIconLevel = SIGNAL_STRENGTH_MODERATE;
- } else if (mLteSignalStrength >= 0) {
- rssiIconLevel = SIGNAL_STRENGTH_POOR;
- }
- //added by ouyang
- android.util.Log.e(“oyp”, “getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- if (DBG) {
- log(“getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- }
- return rssiIconLevel;
- //[ALPS01440836][ALPS01594704]-END: change level mapping rule of signal for CMCC
- }
- /**
- * Get the LTE signal level as an asu value between 0..97, 99 is unknown
- * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
- *
- * @hide
- */
- public int getLteAsuLevel() {
- int lteAsuLevel = 99;
- int lteDbm = getLteDbm();
- /*
- * 3GPP 27.007 (Ver 10.3.0) Sec 8.69
- * 0 -140 dBm or less
- * 1 -139 dBm
- * 2…96 -138… -44 dBm
- * 97 -43 dBm or greater
- * 255 not known or not detectable
- */
- /*
- * validateInput will always give a valid range between -140 t0 -44 as
- * per ril.h. so RSRP >= -43 & <-140 will fall under asu level 255
- * and not 97 or 0
- */
- if (lteDbm == SignalStrength.INVALID) {
- lteAsuLevel = 255;
- } else {
- lteAsuLevel = lteDbm + 140;
- }
- if (DBG) {
- log(“Lte Asu level: “ + lteAsuLevel);
- }
- return lteAsuLevel;
- }
- /**
- * @return true if this is for GSM
- */
- public boolean isGsm() {
- return this.isGsm;
- }
- /**
- * @return hash code
- */
- @Override
- public int hashCode() {
- int primeNum = 31;
- return ((mGsmSignalStrength * primeNum)
- + (mGsmBitErrorRate * primeNum)
- + (mCdmaDbm * primeNum) + (mCdmaEcio * primeNum)
- + (mEvdoDbm * primeNum) + (mEvdoEcio * primeNum) + (mEvdoSnr * primeNum)
- + (mLteSignalStrength * primeNum) + (mLteRsrp * primeNum)
- + (mLteRsrq * primeNum) + (mLteRssnr * primeNum) + (mLteCqi * primeNum)
- + (isGsm ? 1 : 0));
- }
- /**
- * @return true if the signal strengths are the same
- */
- @Override
- public boolean equals (Object o) {
- SignalStrength s;
- try {
- s = (SignalStrength) o;
- } catch (ClassCastException ex) {
- return false;
- }
- if (o == null) {
- return false;
- }
- return (mGsmSignalStrength == s.mGsmSignalStrength
- && mGsmBitErrorRate == s.mGsmBitErrorRate
- && mCdmaDbm == s.mCdmaDbm
- && mCdmaEcio == s.mCdmaEcio
- && mEvdoDbm == s.mEvdoDbm
- && mEvdoEcio == s.mEvdoEcio
- && mEvdoSnr == s.mEvdoSnr
- && mLteSignalStrength == s.mLteSignalStrength
- && mLteRsrp == s.mLteRsrp
- && mLteRsrq == s.mLteRsrq
- && mLteRssnr == s.mLteRssnr
- && mLteCqi == s.mLteCqi
- && isGsm == s.isGsm
- && mGsmRscpQdbm == s.mGsmRscpQdbm); /* ALPS00334516 */
- }
- /**
- * @return string representation.
- */
- @Override
- public String toString() {
- return (“SignalStrength:”
- + ” “ + mGsmSignalStrength
- + ” “ + mGsmBitErrorRate
- + ” “ + mCdmaDbm
- + ” “ + mCdmaEcio
- + ” “ + mEvdoDbm
- + ” “ + mEvdoEcio
- + ” “ + mEvdoSnr
- + ” “ + mLteSignalStrength
- + ” “ + mLteRsrp
- + ” “ + mLteRsrq
- + ” “ + mLteRssnr
- + ” “ + mLteCqi
- + ” “ + (isGsm ? “gsm|lte” : “cdma”)
- + ” “ + mGsmRssiQdbm
- + ” “ + mGsmRscpQdbm
- + ” “ + mGsmEcn0Qdbm);
- }
- /**
- * Set SignalStrength based on intent notifier map
- *
- * @param m intent notifier map
- * @hide
- */
- private void setFromNotifierBundle(Bundle m) {
- mGsmSignalStrength = m.getInt(“GsmSignalStrength”);
- mGsmBitErrorRate = m.getInt(“GsmBitErrorRate”);
- mCdmaDbm = m.getInt(“CdmaDbm”);
- mCdmaEcio = m.getInt(“CdmaEcio”);
- mEvdoDbm = m.getInt(“EvdoDbm”);
- mEvdoEcio = m.getInt(“EvdoEcio”);
- mEvdoSnr = m.getInt(“EvdoSnr”);
- mLteSignalStrength = m.getInt(“LteSignalStrength”);
- mLteRsrp = m.getInt(“LteRsrp”);
- mLteRsrq = m.getInt(“LteRsrq”);
- mLteRssnr = m.getInt(“LteRssnr”);
- mLteCqi = m.getInt(“LteCqi”);
- isGsm = m.getBoolean(“isGsm”);
- mGsmRssiQdbm = m.getInt(“RssiQdbm”);
- mGsmRscpQdbm = m.getInt(“RscpQdbm”);
- mGsmEcn0Qdbm = m.getInt(“Ecn0Qdbm”);
- }
- /**
- * Set intent notifier Bundle based on SignalStrength
- *
- * @param m intent notifier Bundle
- * @hide
- */
- public void fillInNotifierBundle(Bundle m) {
- m.putInt(“GsmSignalStrength”, mGsmSignalStrength);
- m.putInt(“GsmBitErrorRate”, mGsmBitErrorRate);
- m.putInt(“CdmaDbm”, mCdmaDbm);
- m.putInt(“CdmaEcio”, mCdmaEcio);
- m.putInt(“EvdoDbm”, mEvdoDbm);
- m.putInt(“EvdoEcio”, mEvdoEcio);
- m.putInt(“EvdoSnr”, mEvdoSnr);
- m.putInt(“LteSignalStrength”, mLteSignalStrength);
- m.putInt(“LteRsrp”, mLteRsrp);
- m.putInt(“LteRsrq”, mLteRsrq);
- m.putInt(“LteRssnr”, mLteRssnr);
- m.putInt(“LteCqi”, mLteCqi);
- m.putBoolean(“isGsm”, Boolean.valueOf(isGsm));
- m.putInt(“RssiQdbm”, mGsmRssiQdbm);
- m.putInt(“RscpQdbm”, mGsmRscpQdbm);
- m.putInt(“Ecn0Qdbm”, mGsmEcn0Qdbm);
- }
- /**
- * log
- */
- private static void log(String s) {
- Rlog.w(LOG_TAG, s);
- }
- /**
- * Get the GSM 3G rssi value
- *
- * @hide
- */
- public int getGsmRssiQdbm() {
- return this.mGsmRssiQdbm;
- }
- /**
- * Get the GSM 3G rscp value
- *
- * @hide
- */
- public int getGsmRscpQdbm() {
- return this.mGsmRscpQdbm;
- }
- /**
- * Get the GSM 3G ecn0 value
- *
- * @hide
- */
- public int getGsmEcn0Qdbm() {
- return this.mGsmEcn0Qdbm;
- }
- /**
- * Get the GSM Signal Strength Dbm value
- *
- * @hide
- * @internal
- */
- public int getGsmSignalStrengthDbm() {
- int dBm = –1;
- int gsmSignalStrength = this.mGsmSignalStrength;
- int asu = (gsmSignalStrength == 99 ? –1 : gsmSignalStrength);
- if (asu != –1) {
- if (!IS_BSP_PACKAGE) {
- IServiceStateExt ssExt = getPlugInInstance();
- if (ssExt != null) {
- dBm = ssExt.mapGsmSignalDbm(mGsmRscpQdbm, asu);
- return dBm;
- } else {
- log(“[getGsmSignalStrengthDbm] null plug-in instance”);
- }
- }
- dBm = –113 + (2 * asu);
- }
- return dBm;
- }
- /**
- * Test whether two objects hold the same data values or both are null
- *
- * @param a first obj
- * @param b second obj
- * @return true if two objects equal or both are null
- * @hide
- */
- private static boolean equalsHandlesNulls(Object a, Object b) {
- return (a == null) ? (b == null) : a.equals(b);
- }
- //MTE-START [ALPS01200757]
- /**
- * check if current network is LTE
- *
- * if we camp on LTE network then the least fiele of +ECSQ will be .
- * It will be set to mEvdoDbm in getSingnalStrength() of ril_nw.c
- * And change value to “-7” by SingnalStrength.validateInput() when GsmSST receive signal update.
- * @return true when camp on LTE network
- *
- * @hide
- * @internal
- */
- private boolean isCampOnLte() {
- return (isGsm() && (mEvdoDbm == –7)) ;
- }
- //MTE-END [ALPS01200757]
- ///M:For svlte signal strength. @{
- /**
- * Set the GSM Signal Strength.
- *
- * @param gsmSignalStrength The GSM GSM Signal Strength
- * @hide
- */
- public void setGsmSignalStrength(int gsmSignalStrength) {
- mGsmSignalStrength = gsmSignalStrength;
- }
- /**
- * Set the GSM Bit Error Rate.
- *
- * @param gsmBitErrorRate the GSM Bit Error Rate
- * @hide
- */
- public void setGsmBitErrorRate(int gsmBitErrorRate) {
- mGsmBitErrorRate = gsmBitErrorRate;
- }
- /**
- * Set the CDMA Dbm.
- *
- * @param cdmaDbm the CDMA Dbm
- * @hide
- */
- public void setCdmaDbm(int cdmaDbm) {
- mCdmaDbm = cdmaDbm;
- }
- /**
- * Set the CDMA Ecio.
- *
- * @param cdmaEcio the CDMA Ecio
- * @hide
- */
- public void setCdmaEcio(int cdmaEcio) {
- mCdmaEcio = cdmaEcio;
- }
- /**
- * Set the EVDO Dbm.
- *
- * @param evdoDbm the EVDO Dbm
- * @hide
- */
- public void setEvdoDbm(int evdoDbm) {
- mEvdoDbm = evdoDbm;
- }
- /**
- * Set the EVDO Ecio.
- *
- * @param evdoEcio the EVDO Ecio
- * @hide
- */
- public void setEvdoEcio(int evdoEcio) {
- mEvdoEcio = evdoEcio;
- }
- /**
- * Set the EVDO Snr.
- *
- * @param evdoSnr the EVDO Snr
- * @hide
- */
- public void setEvdoSnr(int evdoSnr) {
- mEvdoSnr = evdoSnr;
- }
- /**
- * Set the LTE Signal Strength.
- *
- * @param lteSignalStrength the LTE Signal Strength
- * @hide
- */
- public void setLteSignalStrength(int lteSignalStrength) {
- mLteSignalStrength = lteSignalStrength;
- }
- /**
- * Set the LTE Rsrp.
- *
- * @param lteRsrp the LTE Rsrp
- * @hide
- */
- public void setLteRsrp(int lteRsrp) {
- mLteRsrp = lteRsrp;
- }
- /**
- * Set the LTE Rsrq.
- *
- * @param lteRsrq the LTE Rsrq
- * @hide
- */
- public void setLteRsrq(int lteRsrq) {
- mLteRsrq = lteRsrq;
- }
- /**
- * Set the LTE Rssnr.
- *
- * @param lteRssnr the LTE Rssnr
- * @hide
- */
- public void setLteRssnr(int lteRssnr) {
- mLteRssnr = lteRssnr;
- }
- /**
- * Set the LTE Cqi.
- *
- * @param lteCqi the LTE Cqi
- * @hide
- */
- public void setLteCqi(int lteCqi) {
- mLteCqi = lteCqi;
- }
- /**
- * Set the GSM rssi Qdbm.
- *
- * @param gsmRssiQdbm the GSM rssi Qdbm
- * @hide
- */
- public void setGsmRssiQdbm(int gsmRssiQdbm) {
- mGsmRssiQdbm = gsmRssiQdbm;
- }
- /**
- * Get the GSM Rscp Qdbm.
- *
- * @param gsmRscpQdbm the GSM Rscp Qdbm
- * @hide
- */
- public void setGsmRscpQdbm(int gsmRscpQdbm) {
- mGsmRscpQdbm = gsmRscpQdbm;
- }
- /**
- * Set the Gsm Ecn0 Qdbm.
- *
- * @param gsmEcn0Qdbm the Gsm Ecn0 Qdbm
- * @hide
- */
- public void setGsmEcn0Qdbm(int gsmEcn0Qdbm) {
- mGsmEcn0Qdbm = gsmEcn0Qdbm;
- }
- /**
- * Check if C2K feature is supported.
- * @return True if C2K feature is supported.
- */
- private static boolean isC2KSupport() {
- return SystemProperties.get(“ro.mtk_c2k_support”).equals(“1”);
- }
- /// M: [C2K][SVLTE] Added API for SignalStrength. @}
- }
====================================================================================
vendor/mediatek/proprietary/frameworks/base/packages/FwkPlugin/src/com/mediatek/op/telephony/DefaultServiceStateExt.java代码如下:
- /* Copyright Statement:
- *
- * This software/firmware and related documentation (“MediaTek Software”) are
- * protected under relevant copyright laws. The information contained herein is
- * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
- * the prior written permission of MediaTek inc. and/or its licensors, any
- * reproduction, modification, use or disclosure of MediaTek Software, and
- * information contained herein, in whole or in part, shall be strictly
- * prohibited.
- *
- * MediaTek Inc. (C) 2010. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS (“MEDIATEK SOFTWARE”)
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
- * ON AN “AS-IS” BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
- * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
- * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
- * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
- * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
- * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER’S SOLE RESPONSIBILITY TO
- * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
- * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
- * RELEASES MADE TO RECEIVER’S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER’S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK’S
- * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
- * RELEASED HEREUNDER WILL BE, AT MEDIATEK’S OPTION, TO REVISE OR REPLACE THE
- * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
- * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * The following software/firmware and/or related documentation (“MediaTek
- * Software”) have been modified by MediaTek Inc. All revisions are subject to
- * any receiver’s applicable license agreements with MediaTek Inc.
- */
- package com.mediatek.op.telephony;
- import android.content.Context;
- import android.content.res.Resources;
- import android.os.SystemProperties;
- import android.telephony.ServiceState;
- import android.telephony.SignalStrength;
- import android.util.Log;
- import com.mediatek.common.PluginImpl;
- import com.mediatek.common.telephony.IServiceStateExt;
- import android.provider.Settings;
- import android.telephony.SubscriptionManager;
- import com.android.internal.telephony.Phone;
- import com.android.internal.telephony.PhoneConstants;
- import com.android.internal.telephony.PhoneBase;
- import com.android.internal.telephony.PhoneFactory;
- import com.android.internal.telephony.PhoneProxy;
- import java.util.Map;
- @PluginImpl(interfaceName=“com.mediatek.common.telephony.IServiceStateExt”)
- public class DefaultServiceStateExt implements IServiceStateExt {
- static final String TAG = “GSM”;
- private Context mContext;
- public DefaultServiceStateExt() {
- }
- public DefaultServiceStateExt(Context context) {
- mContext = context;
- }
- public String onUpdateSpnDisplay(String plmn, ServiceState ss, int phoneId) {
- /* ALPS00362903 */
- if (SystemProperties.get(“ro.mtk_network_type_always_on”).equals(“1”)) {
- // for LTE
- if (ss.getRilVoiceRadioTechnology() == ServiceState.RIL_RADIO_TECHNOLOGY_LTE
- && plmn != Resources.getSystem().getText(com.android.internal.R.string.
- lockscreen_carrier_default).toString()) {
- plmn = plmn + ” 4G”;
- } else if (ss.getRilVoiceRadioTechnology() > ServiceState.RIL_RADIO_TECHNOLOGY_EDGE
- /* ALPS00492303 */
- //if (radioTechnology > 2 && plmn != null){
- && plmn != Resources.getSystem().getText(com.android.internal.R.string.
- lockscreen_carrier_default).toString()) {
- plmn = plmn + ” 3G”;
- }
- }
- return plmn;
- }
- public boolean isImeiLocked() {
- return false;
- }
- public boolean isBroadcastEmmrrsPsResume(int value) {
- return false;
- }
- public boolean needEMMRRS() {
- return false;
- }
- public boolean needSpnRuleShowPlmnOnly() {
- //[ALPS01679495]-start: don’t show SPN for CTA case
- if (SystemProperties.get(“ro.mtk_cta_support”).equals(“1”)) {
- return true;
- }
- //[ALPS01679495]-end
- return false;
- }
- public boolean needBrodcastAcmt(int errorType, int errorCause) {
- return false;
- }
- public boolean needRejectCauseNotification(int cause) {
- return false;
- }
- public boolean needIgnoredState(int state, int newState, int cause) {
- if ((state == ServiceState.STATE_IN_SERVICE) && (newState == 2)) {
- /* Don’t update for searching state, there shall be final registered state
- update later */
- Log.i(TAG, “set dontUpdateNetworkStateFlag for searching state”);
- return true;
- }
- /* -1 means modem didn’t provide information. */
- if (cause != –1) {
- // [ALPS01384143] need to check if previous state is IN_SERVICE for invalid sim
- if ((state == ServiceState.STATE_IN_SERVICE) && (newState == 3) && (cause != 0)) {
- //if((newState == 3) && (cause != 0)){
- /* This is likely temporarily network failure, don’t update for better UX */
- Log.i(TAG, “set dontUpdateNetworkStateFlag for REG_DENIED with cause”);
- return true;
- //[ALPS01976914] – start
- } else if ((state == ServiceState.STATE_IN_SERVICE) && (newState == 0) && (cause != 0)) {
- Log.i(TAG, “set dontUpdateNetworkStateFlag for NOT_REG_AND_NOT_SEARCH with cause”);
- return true;
- }
- //[ALPS01976914] – end
- }
- Log.i(TAG, “clear dontUpdateNetworkStateFlag”);
- return false;
- }
- public boolean ignoreDomesticRoaming() {
- return false;
- }
- public int mapGsmSignalLevel(int asu, int gsmRscpQdbm) {
- int level;
- // [ALPS01055164] — START , for 3G network
- if (gsmRscpQdbm < 0) {
- // 3G network
- if (asu <= 5 || asu == 99) {
- level = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (asu >= 15) {
- level = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (asu >= 12) {
- level = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (asu >= 9) {
- level = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else {
- level = SignalStrength.SIGNAL_STRENGTH_POOR;
- }
- // [ALPS01055164] — END
- } else {
- // 2G network
- if (asu <= 2 || asu == 99) {
- level = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (asu >= 12) {
- level = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (asu >= 8) {
- level = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (asu >= 5) {
- level = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else {
- level = SignalStrength.SIGNAL_STRENGTH_POOR;
- }
- }
- return level;
- }
- //[ALPS01440836][ALPS01594704]-START: change level mapping rule of signal for CMCC
- public int mapLteSignalLevel(int mLteRsrp, int mLteRssnr, int mLteSignalStrength) {
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “mapLteSignalLevel starting …….”);
- /*
- * TS 36.214 Physical Layer Section 5.1.3 TS 36.331 RRC RSSI = received
- * signal + noise RSRP = reference signal dBm RSRQ = quality of signal
- * dB= Number of Resource blocksxRSRP/RSSI SNR = gain=signal/noise ratio
- * = -10log P1/P2 dB
- */
- int rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- int rsrpIconLevel = –1;
- int snrIconLevel = –1;
- //modifed by ouyang [2015-10-14] start
- // if (mLteRsrp > -44) {
- // rsrpIconLevel = -1;
- // } else if (mLteRsrp >= -85) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- // } else if (mLteRsrp >= -95) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- // } else if (mLteRsrp >= -105) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- // } else if (mLteRsrp >= -115) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- // } else if (mLteRsrp >= -140) {
- // rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- // }
- if (mLteRsrp > –44) {
- rsrpIconLevel = –1;
- } else if (mLteRsrp >= –97) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (mLteRsrp >= –105) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (mLteRsrp >= –110) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRsrp >= –120) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- } else if (mLteRsrp >= –140) {
- rsrpIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “getLTELevel – rsrp:” + mLteRsrp + ” rsrpIconLevel:”+ rsrpIconLevel);
- //modifed by ouyang [2015-10-14] end
- /*
- * Values are -200 dB to +300 (SNR*10dB) RS_SNR >= 13.0 dB =>4 bars 4.5
- * dB <= RS_SNR < 13.0 dB => 3 bars 1.0 dB <= RS_SNR < 4.5 dB => 2 bars
- * -3.0 dB <= RS_SNR < 1.0 dB 1 bar RS_SNR < -3.0 dB/No Service Antenna
- * Icon Only
- */
- if (mLteRssnr > 300) {
- snrIconLevel = –1;
- } else if (mLteRssnr >= 130) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (mLteRssnr >= 45) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (mLteRssnr >= 10) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else if (mLteRssnr >= –30) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- } else if (mLteRssnr >= –200) {
- snrIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- }
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “getLTELevel – snr:” + mLteRssnr + ” snrIconLevel:” + snrIconLevel);
- Log.i(TAG, “getLTELevel – rsrp:” + mLteRsrp + ” snr:” + mLteRssnr + ” rsrpIconLevel:”
- + rsrpIconLevel + ” snrIconLevel:” + snrIconLevel);
- /* Choose a measurement type to use for notification */
- if (snrIconLevel != –1 && rsrpIconLevel != –1) {
- /*
- * The number of bars displayed shall be the smaller of the bars
- * associated with LTE RSRP and the bars associated with the LTE
- * RS_SNR
- */
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “snrIconLevel != -1 && rsrpIconLevel != -1,”
- +“return rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel”
- +(rsrpIconLevel < snrIconLevel));
- return (rsrpIconLevel < snrIconLevel ? rsrpIconLevel : snrIconLevel);
- }
- if (snrIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “snrIconLevel != -1”);
- return snrIconLevel;
- }
- if (rsrpIconLevel != –1) {
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “rsrpIconLevel != -1”);
- return rsrpIconLevel;
- }
- /* Valid values are (0-63, 99) as defined in TS 36.331 */
- if (mLteSignalStrength > 63) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
- } else if (mLteSignalStrength >= 12) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_GREAT;
- } else if (mLteSignalStrength >= 8) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_GOOD;
- } else if (mLteSignalStrength >= 5) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_MODERATE;
- } else if (mLteSignalStrength >= 0) {
- rssiIconLevel = SignalStrength.SIGNAL_STRENGTH_POOR;
- }
- //added by ouyang
- android.util.Log.e(“mapLteSignalLevel”, “getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- Log.i(TAG, “getLTELevel – rssi:” + mLteSignalStrength + ” rssiIconLevel:”
- + rssiIconLevel);
- return rssiIconLevel;
- }
- //[ALPS01440836][ALPS01594704]-END: change level mapping rule of signal for CMCC
- public int mapGsmSignalDbm(int gsmRscpQdbm, int asu) {
- int dBm;
- Log.d(TAG, “mapGsmSignalDbm() gsmRscpQdbm=” + gsmRscpQdbm + ” asu=” + asu);
- if (gsmRscpQdbm < 0) {
- dBm = gsmRscpQdbm / 4; //Return raw value for 3G Network
- } else {
- dBm = –113 + (2 * asu);
- }
- return dBm;
- }
- public void log(String text) {
- Log.d(TAG, text);
- }
- public Map loadSpnOverrides() {
- return null;
- }
- public boolean allowSpnDisplayed() {
- return true;
- }
- public boolean supportEccForEachSIM() {
- return false;
- }
- public void updateOplmn(Context context, Object ci) {
- }
- //[ALPS01558804] MTK-START: send notification for using some spcial icc card
- public boolean needIccCardTypeNotification(String iccCardType) {
- return false;
- }
- //[ALPS01862093]-Start: not supprot auto switch rat for SIM card type
- //du to UI spec. define chagend
- public int needAutoSwitchRatMode(int phoneId, String nwPlmn) {
- return –1;
- }
- //re-mark
- /*
- //[ALPS01577029] To support auto switch rat mode
- public int needAutoSwitchRatMode(int phoneId,String nwPlmn) {
- int simType = -1; // 0: SIM , 1: USIM
- int currentNetworkMode = -1;
- int userNetworkMode = -1;
- Phone[] phones = null; //all phone proxy instance
- Phone phoneProxy = null; //current phone proxy instance
- // For World phone OM version START
- if ((SystemProperties.getInt(“ro.mtk_lte_support”, 0) == 1) &&
- (SystemProperties.getInt(“ro.mtk_world_phone”, 0) == 1)) {
- //get sim switch status
- int switchStatus = Integer.valueOf(
- SystemProperties.get(PhoneConstants.CAPABILITY_SWITCH_PROP, “1”));
- log(“needAutoSwitchRatMode,phoneId=” + phoneId+”, switchStatus=”+switchStatus+
- “,SubscriptionManager.isValidPhoneId(phoneId)=”+SubscriptionManager.isValidPhoneId(phoneId));
- if ((phoneId == (switchStatus – 1)) &&
- SubscriptionManager.isValidPhoneId(phoneId)) {
- phones = PhoneFactory.getPhones();
- if (phones.length > phoneId) {
- phoneProxy = phones[phoneId];
- }
- if (phoneProxy == null) {
- log(“needSwitchRatMode()= -1 cause phone proxy is null”);
- return currentNetworkMode;
- }
- String simtype = null;
- simtype = ((PhoneProxy)phoneProxy).getIccCard().getIccCardType();
- if (simtype != null && simtype.equals(“SIM”)) {
- simType = 0;
- } else if (simtype != null && simtype.equals(“USIM”)) {
- simType = 1;
- }
- if (simType == 0) {//SIM
- //get rat mode if user has change it
- userNetworkMode = Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.USER_PREFERRED_NETWORK_MODE, -1);
- if (userNetworkMode >= Phone.NT_MODE_WCDMA_PREF) {
- currentNetworkMode = userNetworkMode;
- if(userNetworkMode >= Phone.NT_MODE_LTE_GSM_WCDMA) {
- currentNetworkMode = Phone.NT_MODE_WCDMA_PREF;
- }
- log(“DefaultServiceStateExt needSwitchRatMode for SIM: userNetworkMode=” + userNetworkMode);
- } else {
- //log(“needSwitchRatMode: set Rat to 2/3G auto”);
- currentNetworkMode = Phone.NT_MODE_WCDMA_PREF;
- }
- } else if (simType == 1) {//USIM
- //get rat mode if user has change it
- userNetworkMode = Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.USER_PREFERRED_NETWORK_MODE, -1);
- if (userNetworkMode >= Phone.NT_MODE_WCDMA_PREF) {
- log(“DefaultServiceStateExt needSwitchRatMode for USIM: userNetworkMode=” + userNetworkMode);
- currentNetworkMode = userNetworkMode;
- } else {
- //log(“needSwitchRatMode: set Rat to 4/3/2G”);
- currentNetworkMode = Phone.NT_MODE_LTE_GSM_WCDMA;
- }
- } else {
- log(“DefaultServiceStateExt unknown sim type, do nothing”);
- }
- }
- }
- // For World phone OM version END
- log(“DefaultServiceStateExt currentNetworkMode = “+currentNetworkMode+” ,simType= “+simType);
- return currentNetworkMode;
- }
- */
- //[ALPS01862093]-End
- public boolean isSupportRatBalancing() {
- return false;
- }
- /**
- * Return if roaming for special SIM.
- *
- * @param strServingPlmn The operator numberic get from service state.
- * @param strHomePlmn The mcc+mnc get from SIM IMSI.
- * @return if roaming for the special SIM
- */
- public boolean isRoamingForSpecialSIM(String strServingPlmn, String strHomePlmn) {
- return false;
- }
- }
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================