Bug 1201384 - Add support for determining Switchboard buckets locally r=chenxia

This commit is contained in:
Mark Finkle 2015-09-08 23:28:01 -04:00
Родитель c4cca794a2
Коммит a73066ceb2
1 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -24,6 +24,7 @@ import java.net.ProtocolException;
import java.net.URL;
import java.util.Locale;
import java.util.UUID;
import java.util.zip.CRC32;
import org.json.JSONException;
import org.json.JSONObject;
@ -218,7 +219,15 @@ public class SwitchBoard {
e.printStackTrace();
}
}
public static boolean isInBucket(Context c, int low, int high) {
int userBucket = getUserBucket(c);
if (userBucket >= low && userBucket < high)
return true;
else
return false;
}
/**
* Looks up in config if user is in certain experiment. Returns false as a default value when experiment
* does not exist.
@ -370,4 +379,18 @@ public class SwitchBoard {
return null;
}
/**
* Return the bucket number of the user. There are 100 possible buckets.
*/
private static int getUserBucket(Context c) {
//get uuid
DeviceUuidFactory df = new DeviceUuidFactory(c);
String uuid = df.getDeviceUuid().toString();
CRC32 crc = new CRC32();
crc.update(uuid.getBytes());
long checksum = crc.getValue();
return (int)(checksum % 100L);
}
}