Skip to content

Commit 73689f9

Browse files
author
Robot Media
committed
More verbose debug mode. Closes robotmedia#25
1 parent f10502c commit 73689f9

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

AndroidBillingLibrary/src/net/robotmedia/billing/BillingController.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ public static int countPurchasesNet(Context context, String itemId) {
195195
return count;
196196
}
197197

198+
protected static void debug(String message) {
199+
if (debug) {
200+
Log.d(LOG_TAG, message);
201+
}
202+
}
203+
198204
/**
199205
* Requests purchase information for the specified notification. Immediately
200206
* followed by a call to
@@ -349,6 +355,8 @@ public static void onBillingChecked(boolean supported) {
349355
* notification id.
350356
*/
351357
protected static void onNotify(Context context, String notifyId) {
358+
debug("Notification " + notifyId + " available");
359+
352360
getPurchaseInformation(context, notifyId);
353361
}
354362

@@ -381,6 +389,8 @@ public static void onPurchaseIntent(String itemId, PendingIntent purchaseIntent)
381389
* data signature.
382390
*/
383391
protected static void onPurchaseStateChanged(Context context, String signedData, String signature) {
392+
debug("Purchase state changed");
393+
384394
if (TextUtils.isEmpty(signedData)) {
385395
Log.w(LOG_TAG, "Signed data is empty");
386396
return;
@@ -391,7 +401,8 @@ protected static void onPurchaseStateChanged(Context context, String signedData,
391401
Log.w(LOG_TAG, "Empty signature requires debug mode");
392402
return;
393403
}
394-
final ISignatureValidator validator = BillingController.validator != null ? BillingController.validator : new DefaultSignatureValidator(BillingController.configuration);
404+
final ISignatureValidator validator = BillingController.validator != null ? BillingController.validator
405+
: new DefaultSignatureValidator(BillingController.configuration);
395406
if (!validator.validate(signedData, signature)) {
396407
Log.w(LOG_TAG, "Signature does not match data.");
397408
return;
@@ -402,12 +413,12 @@ protected static void onPurchaseStateChanged(Context context, String signedData,
402413
try {
403414
JSONObject jObject = new JSONObject(signedData);
404415
if (!verifyNonce(jObject)) {
405-
Log.w(BillingController.class.getSimpleName(), "Invalid nonce");
416+
Log.w(LOG_TAG, "Invalid nonce");
406417
return;
407418
}
408419
purchases = parsePurchases(jObject);
409420
} catch (JSONException e) {
410-
Log.e(BillingController.class.getSimpleName(), "JSON exception: ", e);
421+
Log.e(LOG_TAG, "JSON exception: ", e);
411422
return;
412423
}
413424

@@ -439,10 +450,8 @@ protected static void onPurchaseStateChanged(Context context, String signedData,
439450
* the billing request.
440451
*/
441452
protected static void onRequestSent(long requestId, BillingRequest request) {
442-
if (debug) {
443-
Log.d(BillingController.class.getSimpleName(), "Request " + requestId + " of type "
444-
+ request.getRequestType() + " sent");
445-
}
453+
debug("Request " + requestId + " of type " + request.getRequestType() + " sent");
454+
446455
if (request.isSuccess()) {
447456
pendingRequests.put(requestId, request);
448457
} else if (request.hasNonce()) {
@@ -462,10 +471,8 @@ protected static void onRequestSent(long requestId, BillingRequest request) {
462471
* @see net.robotmedia.billing.request.ResponseCode
463472
*/
464473
protected static void onResponseCode(Context context, long requestId, int responseCode) {
465-
if (debug) {
466-
Log.d(BillingController.class.getSimpleName(), "Request " + requestId + " received response "
467-
+ ResponseCode.valueOf(responseCode));
468-
}
474+
debug("Request " + requestId + " received response " + ResponseCode.valueOf(responseCode));
475+
469476
final BillingRequest request = pendingRequests.get(requestId);
470477
if (request != null) {
471478
pendingRequests.remove(requestId);
@@ -585,7 +592,9 @@ public static final void setDebug(boolean value) {
585592

586593
/**
587594
* Sets a custom signature validator. If no custom signature validator is
588-
* provided, {@link net.robotmedia.billing.signature.DefaultSignatureValidator} will be used.
595+
* provided,
596+
* {@link net.robotmedia.billing.signature.DefaultSignatureValidator} will
597+
* be used.
589598
*
590599
* @param validator
591600
* signature validator instance.

AndroidBillingLibrary/src/net/robotmedia/billing/BillingReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public class BillingReceiver extends BroadcastReceiver {
3636

3737
@Override
3838
public void onReceive(Context context, Intent intent) {
39-
String action = intent.getAction();
39+
final String action = intent.getAction();
40+
BillingController.debug("Received " + action);
41+
4042
if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
4143
purchaseStateChanged(context, intent);
4244
} else if (ACTION_NOTIFY.equals(action)) {

0 commit comments

Comments
 (0)