dumpsys命令的使用及telephony.registry解读

Posted 小树的朋友

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dumpsys命令的使用及telephony.registry解读相关的知识,希望对你有一定的参考价值。

adb shell dumpsys,默认打印出当前系统所有的service信息,通常情况下我们并不想看那么多信息,可以在后面加上具体的服务名,比如想获取关于设备电池的信息,就可以使用以下命令:

>adb shell dumpsys battery

Current Battery Service state:
AC powered: false
USB powered: true
Wireless powered: false
Max charging current: 0
status: 5
health: 2
present: true
level: 100
scale: 100
voltage: 4321
temperature: 302
technology: Li-ion

获取完整的系统服务的列表可以使用以下命令:

>adb shell dumpsys -l

Currently running services:
AutoLaunch
DockObserver
SurfaceFlinger
accessibility
account
activity
alarm
alipayservice
android.App6939Service
android.hardware.fingerprint.IFingerprintDaemon
android.security.keystore
appops
appwidget
audio
backup
battery

...

几个常用的命令:

adb shell dumpsys display #获取显示相关信息,可以从中提取分辨率信息

adb shell dumpsys cpuinfo #获取CPU信息

adb shell dumpsys meminfo #获取内存信息
adb shell dumpsys meminfo PACKAGE_NAME #获取具体应用的内存信息

adb shell dumpsys activity #获取activity信息
adb shell dumpsys activity top #获取当前界面的UI信息
adb shell dumpsys activity top | findstr ACTIVITY #获取当前界面的activity

adb shell dumpsys wifi #获取wifi信息

adb shell dumpsys power #获取电源管理信息,可以获取到是否处于锁屏状态:mWakefulness=Asleep或者Awake

接下来主要介绍下telephony.registry服务,这个服务是关于无线通讯的,可以从中获取无线通讯相关的参数。执行命令得到如下输出:

>adb shell dumpsys telephony.registry

last known state:
Phone Id=0 #双卡终端中的第一个卡
mCallState=0 #0表示待机状态、1表示来电未接听状态、2表示电话占线状态
mCallIncomingNumber=
mServiceState=0 0 voice home data home CMCC CMCC 46000 CMCC CMCC 46000 LTE LTE CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=false IsDataRoamingFromRegistration=false
mSignalStrength=SignalStrength: 99 0 -120 -160 -120 -1 -1 17 -113 -15 -40 2147483647 2147483647 gsm|lte
mMessageWaiting=false
mCallForwarding=false #是否启用呼叫转移
mDataActivity=0
mDataConnectionState=2 #0:无数据连接 1:正在创建数据连接 2:已连接
mDataConnectionPossible=true #是否有数据连接
mDataConnectionReason=dataAttached
mDataConnectionApn=
mDataConnectionLinkProperties=null
mDataConnectionNetworkCapabilities=null
mCellLocation=Bundle[mParcelledData.dataSize=64]
mCellInfo=null
Phone Id=1
mCallState=0
mCallIncomingNumber=

...

除了以上注释外,接下来主要解读两个字段:mServiceState和mSignalStrength。从源码可以看出是直接打印出了类ServiceStateSignalStrength的内容:

private SignalStrength mSignalStrength = new SignalStrength();

...

        pw.println("last known state:");
        ...
        pw.println("  mServiceState=" + mServiceState);
        pw.println("  mSignalStrength=" + mSignalStrength);
        ...

ServiceState类的内容输出格式可以查看源代码https://github.com/android/platform_frameworks_base/blob/master/telephony/java/android/telephony/ServiceState.java

(搜索”toString”函数):

    @Override
    public String toString() {
        String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology);
        String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology);

        return (mVoiceRegState + " " + mDataRegState
                + " "
                + "voice " + getRoamingLogString(mVoiceRoamingType)
                + " "
                + "data " + getRoamingLogString(mDataRoamingType)
                + " " + mVoiceOperatorAlphaLong
                + " " + mVoiceOperatorAlphaShort
                + " " + mVoiceOperatorNumeric
                + " " + mDataOperatorAlphaLong
                + " " + mDataOperatorAlphaShort
                + " " + mDataOperatorNumeric
                + " " + (mIsManualNetworkSelection ? "(manual)" : "")
                + " " + radioTechnology
                + " " + dataRadioTechnology
                + " " + (mCssIndicator ? "CSS supported" : "CSS not supported")
                + " " + mNetworkId
                + " " + mSystemId
                + " RoamInd=" + mCdmaRoamingIndicator
                + " DefRoamInd=" + mCdmaDefaultRoamingIndicator
                + " EmergOnly=" + mIsEmergencyOnly
                + " IsDataRoamingFromRegistration=" + mIsDataRoamingFromRegistration);
    }

如此一来,mServiceState=0 0 voice home data home CMCC CMCC 46000 CMCC CMCC 46000 LTE LTE CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=false IsDataRoamingFromRegistration=false 中各个字段的意义便一目了然了。

同样,SignalStrength类也可以找到“toString”源码:

    /**
     * @return string representation.
     */
    @Override
    public String toString() {
        return ("SignalStrength:"
                + " " + mGsmSignalStrength
                + " " + mGsmBitErrorRate
                + " " + mCdmaDbm
                + " " + mCdmaEcio
                + " " + mEvdoDbm
                + " " + mEvdoEcio
                + " " + mEvdoSnr
                + " " + mLteSignalStrength
                + " " + mLteRsrp
                + " " + mLteRsrq
                + " " + mLteRssnr
                + " " + mLteCqi
                + " " + mTdScdmaRscp
                + " " + (isGsm ? "gsm|lte" : "cdma"));
    }

从mSignalStrength=SignalStrength: 99 0 -120 -160 -120 -1 -1 17 -113 -15 -40 2147483647 2147483647 gsm|lte,可看出RSRP=-113,RSRQ=-15等等。

 

以上是关于dumpsys命令的使用及telephony.registry解读的主要内容,如果未能解决你的问题,请参考以下文章

Android dumpsys命令详细使用

Android 进阶——Framework 核心之dumpsys命令浅析

Android 进阶——Framework 核心之dumpsys命令浅析

android调试——教你用dumpsys命令调试

dumpsys命令用法

dumpsys命令用法