[Q] How to hook the step counter sensor? topic

SOCIALIZE IT ⇨

I have searched relative keyword such as `sensor` in the repo, but could not find the answer.

I want to hook the step counter's sensor to do some auto-testing jobs on a health-kit app. Basically, we could get the steps by listening the SensorManager, the demo code would be

Code:


public class StepsActivity extends Activity implements SensorEventListener {
    private SensorManager sensorManager;
    private TextView count;
    boolean activityRunning;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_steps);
        count = (TextView) findViewById(R.id.count);
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        activityRunning = true;
        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
        if (countSensor != null) {
            sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
        } else {
            Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        activityRunning = false;
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (activityRunning) {
            count.setText(String.valueOf(event.values[0]));
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }
}


I've read the tutorial, I know we could hook a specific function in a specific class, such as

Code:


        findAndHookMethod("com.android.systemui.statusbar.policy.Clock", lpparam.classLoader, "updateClock", new XC_MethodHook() {

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                TextView tv = (TextView) param.thisObject;
                String text = tv.getText().toString();
                tv.setText("time is:"+text);
                tv.setTextColor(Color.RED);
            }
        });


But I'm wondering how to hook the data on system sensor?

xda-developers


0 commentaires:

Enregistrer un commentaire