首页 > 代码库 > android4.3从app到kernel代码追踪gsensor所遇到的问题
android4.3从app到kernel代码追踪gsensor所遇到的问题
我目前所遇到的问题是在android4.3代码上追踪gsensor的时候出现代码的断层,并且找不到对应的解决方法
希望各位又看到的指导一下:
packages/apps/Settings/src/com/android/settings/gsensor/GestureScreenEnabler.java
public GestureScreenEnabler(Context context, Switch switch_) {
52 mContext = context;
53 mSwitch = switch_;
54 sm = (GSensorManager)context.getSystemService(Context.GSENSOR_SERVICE);
55 if (sm == null) {
56 mSwitch.setEnabled(false);
57 }
58 mIntentFilter = new IntentFilter(GSensorManager.ACTION_STATE_CHANGED);
59 }
然后找到对应的GSensorManager服务
frameworks/base/core/java/android/hardware/GSensorManager.java
7 public class GSensorManager {
8
9 private static final boolean DEBUG = false;
10 private static final String TAG = "GSensorManager";
11
12 public static final String ACTION_STATE_CHANGED = "android.hardware.gsensormanager.STATE_CHANGED";
13 public static final String EXTRA_STATE = "android.hardware.gsensormanager.extra.STATE";
14
15 IGSensorManager mService;
16
17 public GSensorManager(IGSensorManager service) {
18 mService = service;
19 }
20
21 public void setEnabled(boolean isEnabled) {
22 try {
23 if (mService != null)
24 mService.setEnabled(isEnabled);
25 } catch (RemoteException e) {
26
27 }
28 }
29
30 public boolean isEnabled() {
31 try {
32 if (mService != null)
33 return mService.isEnabled();
34 } catch (RemoteException e) {
35 }
36 return false;
37 }
38
39 public int setReferenceStatus() {
40 try {
41 if (mService != null)
42 return mService.setReferenceStatus();
43 } catch (RemoteException e) {
44 }
45 return 0;
46 }
47
48
49 public void setThreshold(int level){
50 try {
51 if (mService != null)
52 mService.setThreshold(level);
53 } catch (RemoteException e) {
54 }
55 }
下面是定义的getSystemService服务的接口
frameworks/base/core/java/android/content/Context.java
public static final String GSENSOR_SERVICE = "gsensor";
public abstract Object getSystemService(String name);
在frameworks/base/core/java/android/app/ContextImpl.java中实现的接口函数
public Object getSystemService(String name) {
ServiceFetcher fetcher = SYSTEM_SERVICE_MAP.get(name);
return fetcher == null ? null : fetcher.getService(this);
}
注册gsensor服务
registerService(GSENSOR_SERVICE, new ServiceFetcher() {
544 public Object createService(ContextImpl ctx) {
545 IBinder b = ServiceManager.getService(GSENSOR_SERVICE);
546 IGSensorManager service = IGSensorManager.Stub.asInterface(b);
547 return new GSensorManager(service);
548 }
549 });
frameworks/base/services/java/com/android/server/SystemServer.java
构建各功能和对应的服务的一一对应关系
if (SystemProperties.get("ro.gesturescreenon.support").equals("true")) {
792 try {
793 Slog.i(TAG,"gsensor service");
794 gSensor = new GSensorService(context);
795 ServiceManager.addService("gsensor", gSensor);
796 } catch (Throwable e) {
797 Slog.e(TAG,"Failure starting gsensor Service", e);
798 }
799 }
紧接着,下面的代码就没有办法构建成功了。并且也不知道该如何操作下面的代码了。
以下是我从hardware开始向APP曾追踪代码的说明:
hardware/libhardware/include/hardware/sensors.h
这里是定义的一些sensor的结构,也就不一一列出它们了。
struct sensors_module_t {
826 struct hw_module_t common;
827
828 /**
829 * Enumerate all available sensors. The list is returned in "list".
830 * @return number of sensors in the list
831 */
832 int (*get_sensors_list)(struct sensors_module_t* module,
833 struct sensor_t const** list);
834 };
frameworks/base/services/jni/com_android_server_GSensorService.cpp
#define GSENSOR_DIR_NAME "/sys/bus/iio/devices/iio:device0"
#define GSENSOR_DEFAULT_THRESHOLD (8 * 32)
#define GSENSOR_REFERENCE_X "motion_lpa_threshold"
#define GSENSOR_REFERENCE_Y "motion_lpa_threshold"
#define GSENSOR_REFERENCE_Z "motion_lpa_threshold"
static int setEnabled(JNIEnv *env, jobject clazz, jboolean on) {
int enable = on;
int ret = write_sysfs_int("buffer/enable", 0);
if (ret < 0)
return -1;
ret = write_sysfs_int("power_state", 1);
if (ret < 0)
return -1;
ret = write_sysfs_int("motion_lpa_on", enable);
if (ret < 0)
return -1;
if (enable) {
ret = write_sysfs_int("motion_lpa_threshold", 31 * 32);
if (ret < 0)
return -1;
ret = write_sysfs_int("motion_lpa_duration", 200);
if (ret < 0)
return -1;
ret = write_sysfs_int("motion_lpa_freq", 2);
if (ret < 0)
return -1;
}
ret = write_sysfs_int("buffer/length", 6);
if (ret < 0)
return -1;
ret = write_sysfs_int("accl_enable", 1);
if (ret < 0)
return -1;
ret = write_sysfs_int("buffer/enable", 1);
if (ret < 0)
return -1;
ret = write_sysfs_int("irq_wake_enable", enable);
if (ret < 0)
return -1;
staticEnabled = on;
return 0;
}
static JNINativeMethod gMethods[] = {
{"_setEnabled", "(Z)I", (void*)setEnabled},
{"_isEnabled", "()Z", (void*)isEnabled},
{"_setReferenceStatus", "()I", (void*)setReferenceStatus},
{"_setThreshold", "(I)V", (void*)setThreshold},
{"_getThreshold", "()I",(void*)getThreshold},
{"_setReference","(III)V", (void*)setReference},
{"_getReference", "()[I", (void*)getReference},
};
int register_android_server_GSensorService(JNIEnv *env) {
return jniRegisterNativeMethods(env, "com/android/server/GSensorService",
gMethods, NELEM(gMethods));
}
frameworks/base/services/java/com/android/server/GSensorService.java
public void setEnabled(boolean isEnabled) throws RemoteException {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SETTINGS, null);
Settings.System.putInt(mContext.getContentResolver(),Settings.System.GSENSOR_ENABLE,
isEnabled ? 1:0 );
int res = _setEnabled(isEnabled);
Intent intent = new Intent(GSensorManager.ACTION_STATE_CHANGED);
if (res == 0) {
//Send broadcast message to everyone else
intent.putExtra(GSensorManager.EXTRA_STATE, true);
} else {
intent.putExtra(GSensorManager.EXTRA_STATE, false);
}
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Log.d(TAG,"gsensor gesture State Change Intent true");
mContext.sendBroadcast(intent);
}
private native int _setEnabled(boolean isEnabled);
private native boolean _isEnabled();
private native int _setReferenceStatus();
private native void _setThreshold(int level);
private native int _getThreshold();
private native void _setReference(int x, int y, int z);
private native int[] _getReference();
这样的关系我实在是不明白,希望各位看到的给与指点。
android4.3从app到kernel代码追踪gsensor所遇到的问题