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

import android.os.Binder;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

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

public class XLocationClient extends XHook {
	private Methods mMethod;
	private static final Map<Object, Object> mMapProxy = new WeakHashMap<Object, Object>();

	private XLocationClient(Methods method, String restrictionName) {
		super(restrictionName, method.name(), String.format("GMS.%s", method.name()));
		mMethod = method;
	}

	public String getClassName() {
		return "com.google.android.gms.location.LocationClient";
	}

	// @formatter:off

	// void addGeofences(List<Geofence> geofences, PendingIntent pendingIntent, LocationClient.OnAddGeofencesResultListener listener)
	// Location getLastLocation()
	// void removeGeofences(List<String> geofenceRequestIds, LocationClient.OnRemoveGeofencesResultListener listener)
	// void removeGeofences(PendingIntent pendingIntent, LocationClient.OnRemoveGeofencesResultListener listener)
	// void removeLocationUpdates(LocationListener listener)
	// void removeLocationUpdates(PendingIntent callbackIntent)
	// void requestLocationUpdates(LocationRequest request, PendingIntent callbackIntent)
	// void requestLocationUpdates(LocationRequest request, LocationListener listener)
	// void requestLocationUpdates(LocationRequest request, LocationListener listener, Looper looper)
	// https://developer.android.com/reference/com/google/android/gms/location/LocationClient.html

	// @formatter:on

	private enum Methods {
		addGeofences, getLastLocation, removeGeofences, removeLocationUpdates, requestLocationUpdates
	};

	public static List<XHook> getInstances() {
		Util.log(null, Log.WARN, "Hooking LocationClient uid=" + Binder.getCallingUid());

		List<XHook> listHook = new ArrayList<XHook>();
		listHook.add(new XLocationClient(Methods.addGeofences, PrivacyManager.cLocation));
		listHook.add(new XLocationClient(Methods.getLastLocation, PrivacyManager.cLocation));
		listHook.add(new XLocationClient(Methods.removeGeofences, null));
		listHook.add(new XLocationClient(Methods.removeLocationUpdates, null));
		listHook.add(new XLocationClient(Methods.requestLocationUpdates, PrivacyManager.cLocation));
		return listHook;
	}

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


		case getLastLocation:
			// Do nothing
			break;

		case removeGeofences:

		case removeLocationUpdates:


		case requestLocationUpdates:

		}
	}

	@Override
	protected void after(XParam param) throws Throwable {
		switch (mMethod) {
		case addGeofences:
		case removeGeofences:
			// Do nothing
			break;

		case getLastLocation:

		case removeLocationUpdates:
			// Do nothing
			break;

		case requestLocationUpdates:
			// Do nothing
			break;

		}
	}


}
