Improved logging

pull/160/head
M66B 5 years ago
parent 361e9f68b3
commit 321daabd0e

@ -175,8 +175,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
} }
BillingResult result = billingClient.launchBillingFlow(this, flowParams.build()); BillingResult result = billingClient.launchBillingFlow(this, flowParams.build());
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB launch billing flow");
Log.i("IAB launch billing flow response=" + text);
if (result.getResponseCode() != BillingClient.BillingResponseCode.OK) if (result.getResponseCode() != BillingClient.BillingResponseCode.OK)
notifyError(text); notifyError(text);
} else } else
@ -187,9 +186,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() { billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
@Override @Override
public void onPurchaseHistoryResponse(BillingResult result, List<PurchaseHistoryRecord> records) { public void onPurchaseHistoryResponse(BillingResult result, List<PurchaseHistoryRecord> records) {
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB history");
Log.i("IAB history response=" + text);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) { if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (PurchaseHistoryRecord record : records) for (PurchaseHistoryRecord record : records)
Log.i("IAB history=" + record.toString()); Log.i("IAB history=" + record.toString());
@ -234,9 +231,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
@Override @Override
public void onBillingSetupFinished(BillingResult result) { public void onBillingSetupFinished(BillingResult result) {
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB connected");
Log.i("IAB connected response=" + text);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) { if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (IBillingListener listener : listeners) for (IBillingListener listener : listeners)
listener.onConnected(); listener.onConnected();
@ -267,9 +262,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
@Override @Override
public void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases) { public void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases) {
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB purchases updated");
Log.i("IAB purchases updated response=" + text);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
checkPurchases(purchases); checkPurchases(purchases);
else else
@ -278,9 +271,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
private void queryPurchases() { private void queryPurchases() {
Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP); Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
String text = getBillingResponseText(result.getBillingResult()); String text = getBillingResponseText(result.getBillingResult(), "IAB query purchases");
Log.i("IAB query purchases response=" + text);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
checkPurchases(result.getPurchasesList()); checkPurchases(result.getPurchasesList());
else else
@ -407,8 +398,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
new SkuDetailsResponseListener() { new SkuDetailsResponseListener() {
@Override @Override
public void onSkuDetailsResponse(BillingResult result, List<SkuDetails> skuDetailsList) { public void onSkuDetailsResponse(BillingResult result, List<SkuDetails> skuDetailsList) {
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB query SKUs");
Log.i("IAB query SKUs response=" + text);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) { if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (SkuDetails skuDetail : skuDetailsList) { for (SkuDetails skuDetail : skuDetailsList) {
Log.i("IAB SKU detail=" + skuDetail); Log.i("IAB SKU detail=" + skuDetail);
@ -416,7 +406,8 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
for (IBillingListener listener : listeners) for (IBillingListener listener : listeners)
listener.onSkuDetails(skuDetail.getSku(), skuDetail.getPrice()); listener.onSkuDetails(skuDetail.getSku(), skuDetail.getPrice());
} }
} } else
notifyError(text);
} }
}); });
} }
@ -429,8 +420,9 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
billingClient.consumeAsync(params, new ConsumeResponseListener() { billingClient.consumeAsync(params, new ConsumeResponseListener() {
@Override @Override
public void onConsumeResponse(BillingResult result, String purchaseToken) { public void onConsumeResponse(BillingResult result, String purchaseToken) {
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB consumed SKU=" + purchase.getSku());
Log.i("IAB SKU=" + purchase.getSku() + " consumed response=" + text); if (result.getResponseCode() != BillingClient.BillingResponseCode.OK)
notifyError(text);
} }
}); });
} }
@ -444,8 +436,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
billingClient.acknowledgePurchase(params, new AcknowledgePurchaseResponseListener() { billingClient.acknowledgePurchase(params, new AcknowledgePurchaseResponseListener() {
@Override @Override
public void onAcknowledgePurchaseResponse(BillingResult result) { public void onAcknowledgePurchaseResponse(BillingResult result) {
String text = getBillingResponseText(result); String text = getBillingResponseText(result, "IAB acknowledged SKU=" + purchase.getSku());
Log.i("IAB acknowledged SKU=" + purchase.getSku() + " response=" + text);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) { if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityBilling.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityBilling.this);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
@ -455,7 +446,8 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
for (IBillingListener listener : listeners) for (IBillingListener listener : listeners)
listener.onPurchased(purchase.getSku()); listener.onPurchased(purchase.getSku());
} } else
notifyError(text);
} }
}); });
} }
@ -465,9 +457,14 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
listener.onError(message); listener.onError(message);
} }
private static String getBillingResponseText(BillingResult result) { private static String getBillingResponseText(BillingResult result, String message) {
String debug = result.getDebugMessage(); String debug = result.getDebugMessage();
return _getBillingResponseText(result) + (debug == null ? "" : " " + debug); String text = _getBillingResponseText(result) + (debug == null ? "" : " " + debug);
if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
Log.i(message + " response=" + text);
else
Log.e(message + " response=" + text);
return text;
} }
private static String _getBillingResponseText(BillingResult result) { private static String _getBillingResponseText(BillingResult result) {

Loading…
Cancel
Save