summaryrefslogtreecommitdiff
path: root/src/org/fox/ttrss/billing/BillingReceiver.java
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2012-06-19 18:00:38 +0400
committerAndrew Dolgov <fox@fakecake.org>2012-06-19 18:00:38 +0400
commit82035f40035bf5fb72b24fe8cc38491ff5d7dfc6 (patch)
tree825ffbf2d98a311ee4ba4c5b1581afd28e9aeeb0 /src/org/fox/ttrss/billing/BillingReceiver.java
parent299682bb6d4e2e9f2b0f0553f6f475f7f7585a99 (diff)
parentf01f0ab35831fefbee30a4ae587ae1edf5c1fe20 (diff)
Merge branch 'master' of github.com:gothfox/Tiny-Tiny-RSS-for-Honeycomb
Diffstat (limited to 'src/org/fox/ttrss/billing/BillingReceiver.java')
-rw-r--r--src/org/fox/ttrss/billing/BillingReceiver.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/org/fox/ttrss/billing/BillingReceiver.java b/src/org/fox/ttrss/billing/BillingReceiver.java
new file mode 100644
index 00000000..9b772054
--- /dev/null
+++ b/src/org/fox/ttrss/billing/BillingReceiver.java
@@ -0,0 +1,57 @@
+package org.fox.ttrss.billing;
+
+import static org.fox.ttrss.billing.BillingConstants.ACTION_NOTIFY;
+import static org.fox.ttrss.billing.BillingConstants.ACTION_PURCHASE_STATE_CHANGED;
+import static org.fox.ttrss.billing.BillingConstants.ACTION_RESPONSE_CODE;
+import static org.fox.ttrss.billing.BillingConstants.INAPP_REQUEST_ID;
+import static org.fox.ttrss.billing.BillingConstants.INAPP_RESPONSE_CODE;
+import static org.fox.ttrss.billing.BillingConstants.INAPP_SIGNATURE;
+import static org.fox.ttrss.billing.BillingConstants.INAPP_SIGNED_DATA;
+import static org.fox.ttrss.billing.BillingConstants.NOTIFICATION_ID;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+public class BillingReceiver extends BroadcastReceiver {
+
+ private static final String TAG = "BillingService";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.i(TAG, "Received action: " + action);
+ if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
+ String signedData = intent.getStringExtra(INAPP_SIGNED_DATA);
+ String signature = intent.getStringExtra(INAPP_SIGNATURE);
+ purchaseStateChanged(context, signedData, signature);
+ } else if (ACTION_NOTIFY.equals(action)) {
+ String notifyId = intent.getStringExtra(NOTIFICATION_ID);
+ notify(context, notifyId);
+ } else if (ACTION_RESPONSE_CODE.equals(action)) {
+ long requestId = intent.getLongExtra(INAPP_REQUEST_ID, -1);
+ int responseCodeIndex = intent.getIntExtra(INAPP_RESPONSE_CODE, BillingConstants.ResponseCode.RESULT_ERROR.ordinal());
+ checkResponseCode(context, requestId, responseCodeIndex);
+ } else {
+ Log.e(TAG, "unexpected action: " + action);
+ }
+ }
+
+
+ private void purchaseStateChanged(Context context, String signedData, String signature) {
+ Log.i(TAG, "purchaseStateChanged got signedData: " + signedData);
+ Log.i(TAG, "purchaseStateChanged got signature: " + signature);
+ BillingHelper.verifyPurchase(signedData, signature);
+ }
+
+ private void notify(Context context, String notifyId) {
+ Log.i(TAG, "notify got id: " + notifyId);
+ String[] notifyIds = {notifyId};
+ BillingHelper.getPurchaseInformation(notifyIds);
+ }
+
+ private void checkResponseCode(Context context, long requestId, int responseCodeIndex) {
+ Log.i(TAG, "checkResponseCode got requestId: " + requestId);
+ Log.i(TAG, "checkResponseCode got responseCode: " + BillingConstants.ResponseCode.valueOf(responseCodeIndex));
+ }
+} \ No newline at end of file