美文网首页
[Android][工具类]PropertisUtils

[Android][工具类]PropertisUtils

作者: 子木同 | 来源:发表于2018-06-26 15:07 被阅读31次

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;
}

}

相关文章

网友评论

      本文标题:[Android][工具类]PropertisUtils

      本文链接:https://www.haomeiwen.com/subject/yqcmyftx.html