From fea5fb275d55951cb22410f4193e327ed41b9e02 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 12 Jul 2012 18:04:19 -0700 Subject: [PATCH] Pass the purchase token through the various layers of the billing system --- .../astrid/billing/BillingActivity.java | 2 +- .../astrid/billing/BillingService.java | 2 +- .../astrid/billing/PurchaseObserver.java | 6 +++--- .../astrid/billing/ResponseHandler.java | 20 +++++++++---------- .../com/todoroo/astrid/billing/Security.java | 7 +++++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/billing/BillingActivity.java b/astrid/src/com/todoroo/astrid/billing/BillingActivity.java index 806c81f82..276163e68 100644 --- a/astrid/src/com/todoroo/astrid/billing/BillingActivity.java +++ b/astrid/src/com/todoroo/astrid/billing/BillingActivity.java @@ -195,7 +195,7 @@ public class BillingActivity extends Activity { @Override public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, - int quantity, long purchaseTime, String developerPayload) { + int quantity, long purchaseTime, String developerPayload, String purchaseToken) { if (Constants.DEBUG) { Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState); } diff --git a/astrid/src/com/todoroo/astrid/billing/BillingService.java b/astrid/src/com/todoroo/astrid/billing/BillingService.java index 207f79ae4..a2a5b3c6b 100644 --- a/astrid/src/com/todoroo/astrid/billing/BillingService.java +++ b/astrid/src/com/todoroo/astrid/billing/BillingService.java @@ -551,7 +551,7 @@ public class BillingService extends Service implements ServiceConnection { notifyList.add(vp.notificationId); } ResponseHandler.purchaseResponse(this, vp.purchaseState, vp.productId, - vp.orderId, vp.purchaseTime, vp.developerPayload); + vp.orderId, vp.purchaseTime, vp.developerPayload, vp.purchaseToken); } if (!notifyList.isEmpty()) { String[] notifyIds = notifyList.toArray(new String[notifyList.size()]); diff --git a/astrid/src/com/todoroo/astrid/billing/PurchaseObserver.java b/astrid/src/com/todoroo/astrid/billing/PurchaseObserver.java index 316aba62c..ac79e100e 100644 --- a/astrid/src/com/todoroo/astrid/billing/PurchaseObserver.java +++ b/astrid/src/com/todoroo/astrid/billing/PurchaseObserver.java @@ -66,7 +66,7 @@ public abstract class PurchaseObserver { * milliseconds since the epoch (Jan 1, 1970) */ public abstract void onPurchaseStateChange(PurchaseState purchaseState, - String itemId, int quantity, long purchaseTime, String developerPayload); + String itemId, int quantity, long purchaseTime, String developerPayload, String purchaseToken); /** * This is called when we receive a response code from Market for a @@ -150,12 +150,12 @@ public abstract class PurchaseObserver { * @param quantity the quantity of items in this purchase */ void postPurchaseStateChange(final PurchaseState purchaseState, final String itemId, - final int quantity, final long purchaseTime, final String developerPayload) { + final int quantity, final long purchaseTime, final String developerPayload, final String purchaseToken) { mHandler.post(new Runnable() { @Override public void run() { onPurchaseStateChange( - purchaseState, itemId, quantity, purchaseTime, developerPayload); + purchaseState, itemId, quantity, purchaseTime, developerPayload, purchaseToken); } }); } diff --git a/astrid/src/com/todoroo/astrid/billing/ResponseHandler.java b/astrid/src/com/todoroo/astrid/billing/ResponseHandler.java index 48f22e060..5d346d57e 100644 --- a/astrid/src/com/todoroo/astrid/billing/ResponseHandler.java +++ b/astrid/src/com/todoroo/astrid/billing/ResponseHandler.java @@ -104,7 +104,7 @@ public class ResponseHandler { */ public static void purchaseResponse( final Context context, final PurchaseState purchaseState, final String productId, - final String orderId, final long purchaseTime, final String developerPayload) { + final String orderId, final long purchaseTime, final String developerPayload, final String purchaseToken) { // Update the database with the purchase state. We shouldn't do that // from the main thread so we do the work in a background thread. @@ -118,15 +118,15 @@ public class ResponseHandler { // int quantity = db.updatePurchase( // orderId, productId, purchaseState, purchaseTime, developerPayload); // db.close(); -// -// // This needs to be synchronized because the UI thread can change the -// // value of sPurchaseObserver. -// synchronized(ResponseHandler.class) { -// if (sPurchaseObserver != null) { -// sPurchaseObserver.postPurchaseStateChange( -// purchaseState, productId, quantity, purchaseTime, developerPayload); -// } -// } + + // This needs to be synchronized because the UI thread can change the + // value of sPurchaseObserver. + synchronized(ResponseHandler.class) { + if (sPurchaseObserver != null) { + sPurchaseObserver.postPurchaseStateChange( + purchaseState, productId, 1, purchaseTime, developerPayload, purchaseToken); + } + } } }).start(); } diff --git a/astrid/src/com/todoroo/astrid/billing/Security.java b/astrid/src/com/todoroo/astrid/billing/Security.java index 6c1491f0c..79577440f 100644 --- a/astrid/src/com/todoroo/astrid/billing/Security.java +++ b/astrid/src/com/todoroo/astrid/billing/Security.java @@ -62,15 +62,17 @@ public class Security { public String orderId; public long purchaseTime; public String developerPayload; + public String purchaseToken; public VerifiedPurchase(PurchaseState purchaseState, String notificationId, - String productId, String orderId, long purchaseTime, String developerPayload) { + String productId, String orderId, long purchaseTime, String developerPayload, String purchaseToken) { this.purchaseState = purchaseState; this.notificationId = notificationId; this.productId = productId; this.orderId = orderId; this.purchaseTime = purchaseTime; this.developerPayload = developerPayload; + this.purchaseToken = purchaseToken; } } @@ -169,6 +171,7 @@ public class Security { if (jElement.has("notificationId")) { notifyId = jElement.getString("notificationId"); } + String purchaseToken = jElement.optString("purchaseToken"); String developerPayload = jElement.optString("developerPayload", null); // If the purchase state is PURCHASED, then we require a @@ -177,7 +180,7 @@ public class Security { continue; } purchases.add(new VerifiedPurchase(purchaseState, notifyId, productId, - orderId, purchaseTime, developerPayload)); + orderId, purchaseTime, developerPayload, purchaseToken)); } } catch (JSONException e) { Log.e(TAG, "JSON exception: ", e);