MTK平台NvRam读取
最近做项目需要读取NvRam信息,完成之后做下笔记以便以后用,由于是MTK平台,MTK有自己得一套NvRam读取得方式,目前是在android L版本做的,还是用得NvRAMAgent来操作
首先将NvRAMAgent文件放到工程目录中,内容如下,记得改下包名
/* 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.*//** This file is auto-generated. DO NOT MODIFY.* Original file: NvRAMAgent.aidl*/
package com.android.server.pm;
import java.lang.String;
import android.os.RemoteException;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Binder;
import android.os.Parcel;
public interface NvRAMAgent extends android.os.IInterface
{/** Local-side IPC implementation stub class. */public static abstract class Stub extends android.os.Binder implements NvRAMAgent{private static final java.lang.String DESCRIPTOR = "NvRAMAgent";/** Construct the stub at attach it to the interface. */public Stub(){this.attachInterface(this, DESCRIPTOR);}/*** Cast an IBinder object into an NvRAMAgent interface,* generating a proxy if needed.*/public static NvRAMAgent asInterface(android.os.IBinder obj){if ((obj==null)) {return null;}android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);if (((iin!=null)&&(iin instanceof NvRAMAgent))) {return ((NvRAMAgent)iin);}return new NvRAMAgent.Stub.Proxy(obj);}public android.os.IBinder asBinder(){return this;}public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException{switch (code){case INTERFACE_TRANSACTION:{reply.writeString(DESCRIPTOR);return true;}case TRANSACTION_readFile:{data.enforceInterface(DESCRIPTOR);int _arg0;_arg0 = data.readInt();byte[] _result = this.readFile(_arg0);reply.writeNoException();reply.writeByteArray(_result);return true;}case TRANSACTION_writeFile:{data.enforceInterface(DESCRIPTOR);int _arg0;_arg0 = data.readInt();byte[] _arg1;_arg1 = data.createByteArray();int _result = this.writeFile(_arg0, _arg1);reply.writeNoException();reply.writeInt(_result);return true;}case TRANSACTION_readFileByName:{data.enforceInterface(DESCRIPTOR);System.out.println("NVRAM TRANSACTION_readFile="+data.readString());String _arg0;_arg0 = data.readString();byte[] _result = this.readFileByName(_arg0);reply.writeNoException();reply.writeByteArray(_result);return true;}case TRANSACTION_writeFileByName:{data.enforceInterface(DESCRIPTOR);String _arg0;_arg0 = data.readString();System.out.println("NVRAM TRANSACTION_writeFile="+data.readString());byte[] _arg1;_arg1 = data.createByteArray();int _result = this.writeFileByName(_arg0, _arg1);reply.writeNoException();reply.writeInt(_result);return true;}}return super.onTransact(code, data, reply, flags);}private static class Proxy implements NvRAMAgent{private android.os.IBinder mRemote;Proxy(android.os.IBinder remote){mRemote = remote;}public android.os.IBinder asBinder(){return mRemote;}public java.lang.String getInterfaceDescriptor(){return DESCRIPTOR;}public byte[] readFile(int file_lid) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();byte[] _result;try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeInt(file_lid);mRemote.transact(Stub.TRANSACTION_readFile, _data, _reply, 0);_reply.readException();_result = _reply.createByteArray();}finally {_reply.recycle();_data.recycle();}return _result;}public int writeFile(int file_lid, byte[] buff) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();int _result;try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeInt(file_lid);_data.writeByteArray(buff);mRemote.transact(Stub.TRANSACTION_writeFile, _data, _reply, 0);_reply.readException();_result = _reply.readInt();}finally {_reply.recycle();_data.recycle();}return _result;}public byte[] readFileByName(String filename) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();byte[] _result;try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeString(filename);mRemote.transact(Stub.TRANSACTION_readFileByName, _data, _reply, 0);_reply.readException();_result = _reply.createByteArray();}finally {_reply.recycle();_data.recycle();}return _result;}public int writeFileByName(String filename, byte[] buff) throws android.os.RemoteException{android.os.Parcel _data = android.os.Parcel.obtain();android.os.Parcel _reply = android.os.Parcel.obtain();int _result;System.out.println("writeFile"+filename); try {_data.writeInterfaceToken(DESCRIPTOR);_data.writeString(filename);_data.writeByteArray(buff);mRemote.transact(Stub.TRANSACTION_writeFileByName, _data, _reply, 0);_reply.readException();_result = _reply.readInt();}finally {_reply.recycle();_data.recycle();}return _result;}}
static final int TRANSACTION_readFile = (IBinder.FIRST_CALL_TRANSACTION + 0);
static final int TRANSACTION_writeFile = (IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_readFileByName = (IBinder.FIRST_CALL_TRANSACTION + 2);
static final int TRANSACTION_writeFileByName = (IBinder.FIRST_CALL_TRANSACTION + 3);}
public byte[] readFile(int file_lid) throws android.os.RemoteException;
public int writeFile(int file_lid, byte[] buff) throws android.os.RemoteException;
public byte[] readFileByName(String filename) throws android.os.RemoteException;
public int writeFileByName(String filename, byte[] buff) throws android.os.RemoteException;
}
然后在使用得地方先导入NvRAMAgent,代码如下
IBinder binder = android.os.ServiceManager.getService("NvRAMAgent");
NvRAMAgent agent = NvRAMAgent.Stub.asInterface(binder);
if(agent == null){android.util.Log.i("wei","agent is null");
}
byte[] buff = null;
StringBuilder builder = new StringBuilder();
try {buff = agent.readFileByName("/data/nvram/APCFG/APRDEB/PRODUCT_INFO");// AP_CFG_REEB_PRODUCT_INFO_LID//buff = agent.readFileByName("/data/nvram/APCFG/APRDEB/WIFI");for(int i=0;i<buff.length;i++){builder.append(buff[i]);}
} catch (Exception ee) { android.util.Log.i("wei","into error");}
首先获取NvRAMAgent服务,读取自己想要得NV节点即可,关于这个文件定义是在CFG_file_info_custom.h文件中,根据结构体得描述读取自己需要得对应位数即可
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
