mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Bug fixes.
This commit is contained in:
@@ -25,6 +25,7 @@ import org.apache.http.message.BasicNameValuePair;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
@@ -108,9 +109,15 @@ public class DeviceRegistrar {
|
||||
String urlPath) throws Exception {
|
||||
SharedPreferences settings = Prefs.get(context);
|
||||
String accountName = settings.getString("accountName", null);
|
||||
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new BasicNameValuePair("devregid", deviceRegistrationID));
|
||||
|
||||
String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
||||
if (deviceId != null) {
|
||||
params.add(new BasicNameValuePair("deviceId", deviceId));
|
||||
}
|
||||
|
||||
AppEngineClient client = new AppEngineClient(context, accountName);
|
||||
return client.makeRequest(urlPath, params);
|
||||
}
|
||||
|
||||
@@ -54,17 +54,11 @@ public class DeviceInfo {
|
||||
@Persistent
|
||||
private Key key;
|
||||
|
||||
@Persistent
|
||||
private String deviceRegistrationID;
|
||||
|
||||
/**
|
||||
* Each device should provide a stable ID. It can be the
|
||||
* hash of the first registration, the phone ID, etc.
|
||||
* Using the name seems error-prone, users may use the default
|
||||
* which may be the same in identical phones, they may change name, etc.
|
||||
* The ID used for sending messages to.
|
||||
*/
|
||||
@Persistent
|
||||
private String id;
|
||||
private String deviceRegistrationID;
|
||||
|
||||
/**
|
||||
* Current supported types:
|
||||
@@ -136,15 +130,6 @@ public class DeviceInfo {
|
||||
this.deviceRegistrationID = deviceRegistrationID;
|
||||
}
|
||||
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -106,16 +106,15 @@ public class RegisterServlet extends HttpServlet {
|
||||
deviceName = "Phone";
|
||||
}
|
||||
|
||||
String deviceId = req.getParameter("deviceId");
|
||||
if (deviceId == null) {
|
||||
deviceId = Long.toHexString(Math.abs(deviceRegistrationId.hashCode()));
|
||||
}
|
||||
|
||||
String deviceType = req.getParameter("deviceType");
|
||||
if (deviceType == null) {
|
||||
deviceType = "ac2dm";
|
||||
}
|
||||
|
||||
// Because the deviceRegistrationId isn't static, we use a static
|
||||
// identifier for the device. (Can be null in older clients)
|
||||
String deviceId = req.getParameter("deviceId");
|
||||
|
||||
User user = checkUser(req, resp, true);
|
||||
if (user != null) {
|
||||
// Context-shared PMF.
|
||||
@@ -143,26 +142,25 @@ public class RegisterServlet extends HttpServlet {
|
||||
pm.deletePersistent(oldest);
|
||||
}
|
||||
|
||||
// TODO: dup ? update
|
||||
String id = Long.toHexString(Math.abs(deviceRegistrationId.hashCode()));
|
||||
|
||||
Key key = KeyFactory.createKey(DeviceInfo.class.getSimpleName(),
|
||||
user.getEmail() + "#" + id);
|
||||
|
||||
// Get device if it already exists, else create
|
||||
String suffix =
|
||||
(deviceId != null ? "#" + Long.toHexString(Math.abs(deviceId.hashCode())) : "");
|
||||
Key key = KeyFactory.createKey(DeviceInfo.class.getSimpleName(),
|
||||
user.getEmail() + suffix);
|
||||
|
||||
DeviceInfo device = null;
|
||||
try {
|
||||
device = pm.getObjectById(DeviceInfo.class, key);
|
||||
} catch (JDOObjectNotFoundException e) { }
|
||||
if (device == null) {
|
||||
device = new DeviceInfo(key, deviceRegistrationId);
|
||||
device.setId(deviceId);
|
||||
device.setName(deviceName);
|
||||
device.setType(deviceType);
|
||||
pm.makePersistent(device);
|
||||
}
|
||||
|
||||
if (device.getType().equals(DeviceInfo.TYPE_CHROME)) {
|
||||
device.setName(deviceName); // update display name
|
||||
|
||||
if (device.getType() != null && device.getType().equals(DeviceInfo.TYPE_CHROME)) {
|
||||
if (device.getPhoneToChromeExperimentEnabled()) {
|
||||
String channelId =
|
||||
ChannelServiceFactory.getChannelService().createChannel(deviceRegistrationId);
|
||||
|
||||
@@ -66,7 +66,6 @@ public class SendServlet extends HttpServlet {
|
||||
return;
|
||||
}
|
||||
|
||||
String deviceId = req.getParameter("deviceId");
|
||||
String deviceName = req.getParameter("deviceName");
|
||||
String deviceType = req.getParameter("deviceType");
|
||||
if (deviceType == null) deviceType = DeviceInfo.TYPE_AC2DM;
|
||||
@@ -74,14 +73,14 @@ public class SendServlet extends HttpServlet {
|
||||
User user = RegisterServlet.checkUser(req, resp, false);
|
||||
if (user != null) {
|
||||
doSendToDevice(url, title, sel, user.getEmail(),
|
||||
deviceId, deviceName, deviceType, resp);
|
||||
deviceName, deviceType, resp);
|
||||
} else {
|
||||
resp.getWriter().println(LOGIN_REQUIRED_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doSendToDevice(String url, String title, String sel, String userAccount,
|
||||
String deviceId, String deviceName, String deviceType, HttpServletResponse resp) throws IOException {
|
||||
String deviceName, String deviceType, HttpServletResponse resp) throws IOException {
|
||||
|
||||
// ok = we sent to at least one phone.
|
||||
boolean ok = false;
|
||||
@@ -103,15 +102,12 @@ public class SendServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
if (registrations.size() == 0) {
|
||||
log.warning("Device not registered");
|
||||
log.warning("Device not registered " + userAccount);
|
||||
resp.getWriter().println(DEVICE_NOT_REGISTERED_STATUS);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (DeviceInfo deviceInfo : registrations) {
|
||||
if (deviceId != null && !deviceId.equals(deviceInfo.getId())) {
|
||||
continue; // user-specified device id
|
||||
}
|
||||
if (deviceName != null && !deviceName.equals(deviceInfo.getName())) {
|
||||
continue; // user-specified device name
|
||||
}
|
||||
@@ -138,7 +134,6 @@ public class SendServlet extends HttpServlet {
|
||||
"InvalidRegistration".equals(ex.getMessage())) {
|
||||
// remove registrations, it no longer works
|
||||
pm.deletePersistent(deviceInfo);
|
||||
throw ex;
|
||||
} else {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
BIN
appengine/war/favicon.ico
Executable file
BIN
appengine/war/favicon.ico
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 529 B |
@@ -112,7 +112,8 @@ function initializeBrowserChannel() {
|
||||
}
|
||||
}
|
||||
};
|
||||
var data = 'devregid=' + deviceRegistrationId + '&deviceType=chrome' + '&deviceName=Chrome';
|
||||
var data = 'devregid=' + deviceRegistrationId + '&deviceId=' + deviceRegistrationId +
|
||||
'&deviceType=chrome' + '&deviceName=Chrome';
|
||||
req.send(data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user