summaryrefslogtreecommitdiff
path: root/src/org/fox/ttrss/BillingReceiver.java
blob: 42cd5df678b499a1b83a6e84ee54d610dc089a0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.fox.ttrss;

import static org.fox.ttrss.BillingConstants.*;

import java.util.ArrayList;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Message;
import android.util.Log;

import org.fox.ttrss.BillingConstants;
import org.fox.ttrss.BillingSecurity.VerifiedPurchase;

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));
	}
}