diff --git a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java index f25c4ca8c..a0090f564 100644 --- a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java +++ b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java @@ -10,6 +10,9 @@ import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.os.Build; +import android.provider.Settings.Secure; +import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -21,6 +24,7 @@ import com.todoroo.andlib.service.NotificationManager; import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.QueryTemplate; +import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.TagViewActivity; @@ -72,6 +76,35 @@ public class C2DMReceiver extends BroadcastReceiver { } }; + private static String getDeviceID() { + String id = ((TelephonyManager) ContextManager.getContext().getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); + + if(id == null) { // check for devices that do not have a Telephony Manager device id + + if(AndroidUtilities.getSdkVersion() > 8) { //Gingerbread and above + + //the following uses relection to get android.os.Build.SERIAL to avoid having to build with Gingerbread + try { + id = Build.SERIAL; + if(Build.UNKNOWN.equals(id)) + id = ""; + } catch(Exception e) { + e.printStackTrace(); + id = ""; + } + + } else { + id = Secure.getString(ContextManager.getContext().getContentResolver(), Secure.ANDROID_ID); + } + + if ("".equals(id) || "9774d56d682e549c".equals(id)) { // check for failure or devices affected by the "9774d56d682e549c" bug + return null; + } + + } + return id; + } + @Override public void onReceive(Context context, final Intent intent) { ContextManager.setContext(context); @@ -116,7 +149,7 @@ public class C2DMReceiver extends BroadcastReceiver { tagData.readFromCursor(cursor); } - new ActFmSyncV2Provider().synchronizeList(tagData, false, refreshOnlyCallback); + actFmSyncService.fetchTag(tagData); } finally { cursor.close(); } @@ -291,7 +324,13 @@ public class C2DMReceiver extends BroadcastReceiver { new Thread(new Runnable() { @Override public void run() { - new ActFmSyncV2Provider().synchronizeList(tagData, false, refreshOnlyCallback); + try { + actFmSyncService.fetchTag(tagData); + } catch (IOException e) { + Log.e("c2dm-tag-rx", "io-exception", e); + } catch (JSONException e) { + Log.e("c2dm-tag-rx", "json-exception", e); + } } }).start(); } else { @@ -366,7 +405,11 @@ public class C2DMReceiver extends BroadcastReceiver { @Override public void run() { try { - actFmSyncService.invoke("user_set_c2dm", "c2dm", registration); + String deviceId = getDeviceID(); + if (deviceId != null) + actFmSyncService.invoke("user_set_c2dm", "c2dm", registration, "device_id", deviceId); + else + actFmSyncService.invoke("user_set_c2dm", "c2dm", registration); Preferences.setString(PREF_REGISTRATION, registration); } catch (IOException e) { Log.e("astrid-actfm", "error-c2dm-transfer", e);