1) 增加AIDL接口文件
文件:frameworks/base/core/java/android/os/ICpuFreqService.aidl
package android.os;
import android.os.WorkSource;
/** @hide */
interface ICpuFreqService
{
int getCurGovernor();
int getCurFrequency();
}
2) 在Android.mk中增加ICpuFreqService.aidl接口文件的编译选项
文件:frameworks/base/Android.mk
LOCAL_SRC_FILES += \
……….
core/java/android/os/ICpuFreqService.aidl\
……..
3) 实现CpuFreqService.java
文件:frameworks/base/services/java/com/android/server$ ls CpuFreqService.java
package com.android.server;
import android.os.ICpuFreqService;
class CpuFreqService extendsICpuFreqService.Stub{
static int EnterTimes=0;
public int getCurGovernor()
{
return0x11233;
}
public int getCurFrequency()
{
EnterTimes++;
return (EnterTimes*50);
}
}
4) 在SystemService中注册service
文件:frameworks/base/services/java/com/android/server/SystemServer.java
CpuFreqService cpufreq=null;
………………
Slog.i(TAG, "CpuFreq Manager");
cpufreq = new CpuFreqService();
ServiceManager.addService("cpufreq",cpufreq);
5) 在APP中调用AIDL接口
…………….
import android.os.ServiceManager;
import android.os.ICpuFreqService;
……………...
try {
ICpuFreqService cpuFreq=
ICpuFreqService.Stub.asInterface( ServiceManager.getService("cpufreq"));
setSummaryText("baseband_version",Integer.toString(cpuFreq.getCurGovernor()));
Log.e("Status","Governor=" + Integer.toString(cpuFreq.getCurGovernor()));
Log.e("Status","Freq ="+ Integer.toString(cpuFreq.getCurFrequency()));
} catch (Exception e)
{
}