Android通过SystemProperties类查看系统参数

首先我们通过adb命令  adb shell ---》回车---》 getprop

得到以下系统参数

[audio.hdmi.available]: [1]
[audio.hdmi.expected]: [0]
[audio.input.active]: [AUDIO_CODEC]
[audio.output.active]: [AUDIO_CODEC,AUDIO_HDMI]
[dalvik.vm.heapgrowthlimit]: [96m]
[dalvik.vm.heapmaxfree]: [8m]
[dalvik.vm.heapminfree]: [2m]
[dalvik.vm.heapsize]: [256m]
[dalvik.vm.heapstartsize]: [8m]
[dalvik.vm.heaptargetutilization]: [0.75]
[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
[debug.egl.hw]: [1]
[dev.bootcomplete]: [1]
[gsm.current.phone-type]: [1]
[gsm.operator.alpha]: []
[gsm.operator.iso-country]: []
[gsm.operator.isroaming]: [false]
[gsm.operator.numeric]: []
[gsm.sim.state]: [NOT_READY]
[gsm.version.ril-impl]: [Quectel_Android_RIL_SR01A41V02]
[hwui.render_dirty_regions]: [false]
[init.svc.adbd]: [running]
[init.svc.bootanim]: [stopped]
[init.svc.console]: [running]
[init.svc.debuggerd]: [running]
[init.svc.drm]: [running]
[init.svc.gpio]: [running]
[init.svc.installd]: [running]
[init.svc.isomountmanager]: [running]
[init.svc.keystore]: [running]
[init.svc.media]: [running]
[init.svc.netd]: [running]
[init.svc.p2p_supplicant]: [running]
[init.svc.preinstall]: [stopped]
[init.svc.property]: [running]
[init.svc.ril-daemon]: [running]
[init.svc.securefile]: [running]
[init.svc.sensors]: [stopped]
[init.svc.servicemanager]: [running]
[init.svc.surfaceflinger]: [running]
[init.svc.tvdecoderserver]: [running]
[init.svc.u3gmonitor]: [running]
[init.svc.ueventd]: [running]
[init.svc.vold]: [running]
[init.svc.zygote]: [running]
[keyguard.no_require_sim]: [true]
[mediasw.sft.rawdata]: [PCM]
[net.bt.name]: [Android]
[net.change]: [net.qtaguid_enabled]
[net.hostname]: [android-66ccfd4a013cea3a]
[net.qtaguid_enabled]: [1]
[net.tcp.buffersize.default]: [4096,87380,110208,4096,16384,110208]
[net.tcp.buffersize.edge]: [4093,26280,35040,4096,16384,35040]
[net.tcp.buffersize.gprs]: [4092,8760,11680,4096,8760,11680]
[net.tcp.buffersize.hspa]: [4094,87380,262144,4096,16384,262144]
[net.tcp.buffersize.lte]: [524288,1048576,2097152,262144,524288,1048576]
[net.tcp.buffersize.umts]: [4094,87380,110208,4096,16384,110208]
[net.tcp.buffersize.wifi]: [524288,1048576,2097152,262144,524288,1048576]
[persist.sys.country]: [CN]
[persist.sys.device_name]: [MiniMax]
[persist.sys.language]: [zh]
[persist.sys.profiler_ms]: [0]
[persist.sys.strictmode.disable]: [1]
[persist.sys.strictmode.visual]: [0]
[persist.sys.sw.firstLaunch]: [false]
[persist.sys.timezone]: [Asia/Shanghai]
[persist.sys.usb.config]: [mass_storage,adb]
[rild.libargs]: [-d/dev/ttyUSB2]
[rild.libpath]: [/system/lib/libreference-EC20-ril.so]
[ro.allow.mock.location]: [1]
[ro.audio.multi.output]: [true]
[ro.baseband]: [unknown]
[ro.board.platform]: [exDroid]
[ro.bootloader]: [unknown]
[ro.bootmode]: [unknown]
[ro.build.characteristics]: [tablet]
[ro.build.date.utc]: [1468285100]
[ro.build.date]: [Tue Jul 12 08:58:20 CST 2016]
[ro.build.description]: [sugar_adtv-eng 4.2.2 JDQ39 20160712 test-keys]
[ro.build.display.id]: [sugar_adtv-eng 4.2.2 JDQ39 20180428 test-keys]
[ro.build.fingerprint]: [softwinners/sugar_adtv/sugar-adtv:4.2.2/JDQ39/20160712:eng/test-keys]
[ro.build.host]: [zhm]
[ro.build.id]: [JDQ39]
[ro.build.product]: [sugar-adtv]
[ro.build.tags]: [test-keys]
[ro.build.type]: [eng]
[ro.build.user]: [zhm]
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [20160712]
[ro.build.version.release]: [4.2.2]
[ro.build.version.sdk]: [17]
[ro.com.android.dateformat]: [MM-dd-yyyy]
[ro.config.alarm_alert]: [Alarm_Classic.ogg]
[ro.config.notification_sound]: [pixiedust.ogg]
[ro.config.ringtone]: [Ring_Synth_04.ogg]
[ro.debuggable]: [1]
[ro.display.switch]: [1]
[ro.factorytest]: [0]
[ro.hardware]: [sun7i]
[ro.kernel.android.checkjni]: [0]
[ro.opengles.version]: [131072]
[ro.product.board]: [wing]
[ro.product.brand]: [softwinners]
[ro.product.cpu.abi2]: [armeabi]
[ro.product.cpu.abi]: [armeabi-v7a]
[ro.product.device]: [56iqDS]
[ro.product.firmware]: [v2.0]
[ro.product.locale.language]: [en]
[ro.product.locale.region]: [US]
[ro.product.manufacturer]: [unknown]
[ro.product.model]: [SoftwinerEvb]
[ro.product.name]: [sugar_adtv]
[ro.property.tabletUI]: [true]
[ro.revision]: [0]
[ro.runtime.firstboot]: [1420070452201]
[ro.secure]: [0]
[ro.serialno]: []
[ro.softmouse.bottom.code]: [108]
[ro.softmouse.left.code]: [105]
[ro.softmouse.leftbtn.code]: [28]
[ro.softmouse.midbtn.code]: [52]
[ro.softmouse.right.code]: [106]
[ro.softmouse.rightbtn.code]: [-1]
[ro.softmouse.top.code]: [103]
[ro.sw.defaultlauncherclass]: [com.softwinner.launcher.Launcher]
[ro.sw.defaultlauncherpackage]: [com.softwinner.launcher]
[ro.sw.directlypoweroff]: [true]
[ro.sw.shortpressleadshut]: [false]
[ro.sw.videotrimming]: [1]
[ro.udisk.lable]: [sugar]
[ro.wifi.channels]: []
[service.bootanim.exit]: [1]
[sys.boot_completed]: [1]
[sys.sensors]: [1]
[sys.settings_global_version]: [5]
[sys.settings_secure_version]: [10]
[sys.settings_system_version]: [9]
[sys.usb.config]: [mass_storage,adb]
[sys.usb.state]: [mass_storage,adb]
[system_init.startsurfaceflinger]: [0]
[telephony.lteOnCdmaDevice]: [0]
[wifi.interface]: [wlan0]
[wifi.supplicant_scan_interval]: [15]
[wlan.driver.status]: [ok]
[wlan.wfddnsmasq.peer]: []
[wlan.wfdp2p.addr]: []
[wlan.wfdp2p.role]: []

格式为“[参数名]:[参数值]”

各个开发板拿到的系统参数会有差异。

在应用内我们可以通过android.os.Build拿到部分系统参数,但是拿到的系统参数有限。百度后发现可以通过SystemProperties这个类取获取更多的系统参数。SystemProperties类在应用中是无法访问的,我们需要在app下的build.gradle文件下新增以下内容

android {
  ...............

    //以下是为了找到android.os.SystemProperties这个隐藏的类
    String SDK_DIR = System.getenv("ANDROID_SDK_HOME")
    //("TAG", "SDK_DIR = " + SDK_DIR );
    if(SDK_DIR == null) {
        Properties props = new Properties()
        props.load(new FileInputStream(project.rootProject.file("local.properties")))
        SDK_DIR = props.get('sdk.dir');
    }
    dependencies {
        compileOnly files("${SDK_DIR}/platforms/android-21/data/layoutlib.jar")
    }
    //以上是为了找到android.os.SystemProperties这个隐藏的类
}

之后我们可以通过

android.os.SystemProperties.get("gsm.version.ril-impl")

这种方式取得所需的系统参数。get方法中所填的参数可填入刚刚通过adb命令拿到的参数名。

 

参考:https://blog.csdn.net/yf1252555020/article/details/82148176

 

 

 

你可能感兴趣的:(android)