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

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

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

public class XNetworkInterface extends XHook {
	private Methods mMethod;

	private XNetworkInterface(Methods method, String restrictionName) {
		super(restrictionName, method.name(), "NetworkInterface." + method.name());
		mMethod = method;
	}

	public String getClassName() {
		return "java.net.NetworkInterface";
	}

	// Internet:
	// - public static NetworkInterface getByIndex(int index)
	// - public static NetworkInterface getByInetAddress(InetAddress address)
	// - public static NetworkInterface getByName(String interfaceName)
	// - public static Enumeration<NetworkInterface> getNetworkInterfaces()

	// Network:
	// - public byte[] getHardwareAddress()
	// - public Enumeration<InetAddress> getInetAddresses()
	// - public List<InterfaceAddress> getInterfaceAddresses()

	// libcore/luni/src/main/java/java/net/NetworkInterface.java
	// http://developer.android.com/reference/java/net/NetworkInterface.html

	// @formatter:off
	private enum Methods {
		getByIndex, getByInetAddress, getByName, getNetworkInterfaces,
		getHardwareAddress, getInetAddresses, getInterfaceAddresses
	};
	// @formatter:on

	public static List<XHook> getInstances() {
		List<XHook> listHook = new ArrayList<XHook>();
		listHook.add(new XNetworkInterface(Methods.getByIndex, PrivacyManager.cInternet));
		listHook.add(new XNetworkInterface(Methods.getByInetAddress, PrivacyManager.cInternet));
		listHook.add(new XNetworkInterface(Methods.getByName, PrivacyManager.cInternet));
		listHook.add(new XNetworkInterface(Methods.getNetworkInterfaces, PrivacyManager.cInternet));

		listHook.add(new XNetworkInterface(Methods.getHardwareAddress, PrivacyManager.cNetwork));
		listHook.add(new XNetworkInterface(Methods.getInetAddresses, PrivacyManager.cNetwork));
		listHook.add(new XNetworkInterface(Methods.getInterfaceAddresses, PrivacyManager.cNetwork));
		return listHook;
	}

	@Override
	protected void before(XParam param) throws Throwable {
		// Do nothing
	}

	@Override
	protected void after(XParam param) throws Throwable {

	}
}
