[Android][工具类]PropertisUtils

package com.cw.testapp.utils;

import android.util.VendorUtils;

import com.cw.testapp.misc.Constants;
import com.gzgd.log.LogUtils;

import java.lang.reflect.Method;

/**

  • Created by lenovo3 on 2016/8/25.
    */
    public class PropertisUtils {
    private final static String TAG = "PropertisUtils";

    public static String getHardware() {
    String result = VendorUtils.Xget(Constants.GET_HWVERSION);
    LogUtils.i(TAG, "HWVERSION:" + result);
    return result;
    }

    public static String getSoftware() {
    String result = VendorUtils.Xget(Constants.GET_SWVERSION);
    LogUtils.i(TAG, "SWVERSION:" + result);
    return result;
    }

    public static String getProductModel() {
    String result = VendorUtils.Xget(Constants.GET_MACHINE_MODEL);
    LogUtils.i(TAG, "MACHINE_MODEL:" + result);
    return result;
    }

    public static String getBuildDate() {
    return getProperities("ro.build.date", "");
    }

    public static String getTestapptwice() {
    return getProperities("testapptwice", "");
    }

    public static void setTestapptwice(String b) {
    setProperties("testapptwice", b);
    }

    public static void setLogOff() {
    setProperties("persist.sys.log.enable", "false");
    }

    public static void setLogOn() {
    setProperties("persist.sys.log.enable", "true");
    }

    public static void setBootAuth() {
    setProperties("service.bootauth.exsit", "0");
    }

    public static String getTemperature() {
    return getProperities("mstar.product.temperature", "");
    }

    public static String getEmmcLife() {
    return getProperities("ro.emmclife", "");
    }

    public static String getEmmcID() {
    return getProperities("ro.emmcid", "");
    }

    public static String getProperities(String key, String defaultValue) {
    String value = "";
    Class<?> systemPropertiesClass;
    Method method = null;
    try {
    systemPropertiesClass = Class.forName("android.os.SystemProperties");
    Class<?> getType[] = new Class[2];
    getType[0] = String.class;
    getType[1] = String.class;
    method = systemPropertiesClass.getMethod("get", getType);
    Object arglist[] = new Object[2];
    arglist[0] = key;
    arglist[1] = defaultValue;
    Object receiver = new Object();
    Object returnValue = method.invoke(receiver, arglist);
    if (receiver != null) {
    value = (String) returnValue;
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return value.trim();
    }

public static String setProperties(String key, String value) {
    String Value = null;
    Class<?> SystemPropertiesClass = null;
    Method method = null;

    try {

        SystemPropertiesClass = Class
                .forName("android.os.SystemProperties");
        Class<?> getType[] = new Class[2];
        getType[0] = String.class;
        getType[1] = String.class;
        method = SystemPropertiesClass.getMethod("set", getType);

        Object arglist[] = new Object[2];
        arglist[0] = key;
        arglist[1] = value;

        Object receiver = new Object();

        Object returnvalue = method.invoke(receiver, arglist);
        if (receiver != null) {
            Value = (String) returnvalue;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return Value;
}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,312评论 19 139
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 7,591评论 0 3
  • 先创建服务端的APP 1.官网下载Winrun4j。http://winrun4j.sourceforge.net...
    Alex_1799阅读 5,842评论 1 2
  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 5,803评论 0 9
  • 通过大致十天左右时间学习方法关的的学习,知道了很多的学习口才的理论知识。明白了,持续行动是很重要的。 1....
    大牙苏_e0dc阅读 1,137评论 1 3