package guard.api.sensitive.ui.sapiguard.hookedapis;

import java.util.ArrayList;
import java.util.List;

import guard.api.sensitive.ui.sapiguard.utils.PrivacyManager;
import guard.api.sensitive.ui.sapiguard.XHook;
import guard.api.sensitive.ui.sapiguard.utils.XParam;

public class XSensorManager extends XHook {
    private Methods mMethod;
    private String mClassName;
    private static final String cClassName = "android.hardware.SensorManager";

    private static final int cMaxRateUs = (int) (0.01 * 1000 * 1000); // 100 Hz

    private XSensorManager(Methods method, String restrictionName, String className) {
        super(restrictionName, method.name(), null);
        mMethod = method;
        mClassName = className;
    }

    public String getClassName() {
        return mClassName;
    }

    // @formatter:off

    // public Sensor getDefaultSensor(int type)
    // public List<Sensor> getSensorList(int type)
    // boolean registerListener(SensorEventListener listener, Sensor sensor, int rateUs, int maxBatchReportLatencyUs)
    // boolean registerListener(SensorEventListener listener, Sensor sensor, int rateUs, Handler handler)
    // boolean registerListener(SensorEventListener listener, Sensor sensor, int rateUs, int maxBatchReportLatencyUs, Handler handler)
    // boolean registerListener(SensorEventListener listener, Sensor sensor, int rateUs)
    // frameworks/base/core/java/android/hardware/SensorManager.java
    // http://developer.android.com/reference/android/hardware/SensorManager.html
    // http://developer.android.com/reference/android/hardware/Sensor.html

    // @formatter:on

    private enum Methods {
        getDefaultSensor, getSensorList, registerListener
    }

    ;

    public static List<XHook> getInstances(String className, boolean server) {
        List<XHook> listHook = new ArrayList<XHook>();
        if (!cClassName.equals(className)) {
            if (className == null)
                className = cClassName;

            listHook.add(new XSensorManager(Methods.getDefaultSensor, PrivacyManager.cSensors, className));
            listHook.add(new XSensorManager(Methods.getSensorList, PrivacyManager.cSensors, className));
            listHook.add(new XSensorManager(Methods.registerListener, PrivacyManager.cSensors, className));
        }
        return listHook;
    }

    @Override
    protected void before(XParam param) throws Throwable {
        switch (mMethod) {
            case getDefaultSensor:


            case getSensorList:


            case registerListener:

        }
    }

    @Override
    @SuppressWarnings("unchecked")
    protected void after(XParam param) throws Throwable {
        switch (mMethod) {
            case getDefaultSensor:
            case registerListener:
                // Do nothing
                break;

            case getSensorList:

                break;
        }
    }


}
