The problem I'm currently experiencing is that the code fault occurred while tracing the gsensor on the android4.3 code, and the corresponding workaround was not found.
I hope you can see the guidance again:
Packages/apps/settings/src/com/android/settings/gsensor/gesturescreenenabler.java
public gesturescreenenabler (context context, Switch Switch_) { & nbsp , &NB Sp
52 &NBSP ; Mcontext = context;
53 Mswitch = Switch_;
54  SM = (Gsensormanager) Context.getsystemservice (context.gsensor_service);
55 if (SM = = null) {
56 MSWITCH.S Etenabled (FALSE);
57 }
58 Mintentfilter = new Intentfilter (gsensormanager.action_state_changed);
59 }
and find the corresponding Gsensormanager service.
Frameworks/base/core/java/android/hardware/gsensormanager.java
7 public class Gsensormanager {
8
9 private static Final Boolean DEBUG = false;
Ten private static final String TAG = "Gsensormanager";
11
public static final String action_state_changed = "Android.hardware.gsensormanager.STATE_CHANGED";
public static final String extra_state = "Android.hardware.gsensormanager.extra.STATE";
14
Igsensormanager Mservice;
16
Gsensormanager Public (Igsensormanager service) {
Mservice = Service;
19}
20
public void SetEnabled (Boolean isenabled) {
try {
if (mservice! = null)
Mservice.setenabled (isenabled);
The catch (RemoteException e) {
26
27}
28}
29
public Boolean isenabled () {
try {
if (mservice! = null)
return mservice.isenabled ();
RemoteException} catch (e) {
35}
return false;
37}
38
Setreferencestatus public int () {
try {
if (mservice! = null)
Mservice.setreferencestatus return ();
RemoteException} catch (e) {
44}
return 0;
46}
47
48
$ public void Setthreshold (Int. level) {
try {
Wuyi if (mservice! = null)
Mservice.setthreshold (level);
(RemoteException e) {
54}
55}
The following is the interface for the defined Getsystemservice service
Frameworks/base/core/java/android/content/context.java
public static final String Gsensor_service = "Gsensor";
Public abstract Object Getsystemservice (String name);
interface functions implemented in 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);
}
Register Gsensor Service
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
Build one by one correspondence between each function and the corresponding service
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}
Next, the code below will not be able to build successfully. And I don't know what to do with the code below.
Here's a description of the code I've traced to the app since hardware:
Hardware/libhardware/include/hardware/sensors.h
Here is the structure of some of the sensor's definitions, and they are not listed.
struct sensors_module_t { and nbsp , &NB Sp , &NB Sp
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 &N Bsp 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 ();
This kind of relationship I really do not understand, I hope you see the give and guidance.
android4.3 issues from app to kernel code tracking gsensor