Fix generic and amazon compile

Can't unlock pro with these builds yet
pull/699/head
Alex Baker 8 years ago
parent 9c0ba990ae
commit 5731489e9c

@ -166,8 +166,8 @@ dependencies {
implementation "me.leolin:ShortcutBadger:1.1.18@aar" implementation "me.leolin:ShortcutBadger:1.1.18@aar"
implementation 'com.google.apis:google-api-services-tasks:v1-rev47-1.22.0' implementation 'com.google.apis:google-api-services-tasks:v1-rev47-1.22.0'
implementation 'com.google.api-client:google-api-client-android:1.22.0' implementation 'com.google.api-client:google-api-client-android:1.22.0'
implementation 'com.android.billingclient:billing:1.0'
googleplayImplementation 'com.android.billingclient:billing:1.0'
googleplayImplementation "com.google.android.gms:play-services-location:${GPS_VERSION}" googleplayImplementation "com.google.android.gms:play-services-location:${GPS_VERSION}"
googleplayImplementation "com.google.android.gms:play-services-analytics:${GPS_VERSION}" googleplayImplementation "com.google.android.gms:play-services-analytics:${GPS_VERSION}"
googleplayImplementation "com.google.android.gms:play-services-auth:${GPS_VERSION}" googleplayImplementation "com.google.android.gms:play-services-auth:${GPS_VERSION}"

@ -1,6 +1,9 @@
package org.tasks.analytics; package org.tasks.analytics;
import static org.tasks.billing.BillingClient.BillingResponseToString;
import android.content.Context; import android.content.Context;
import com.android.billingclient.api.BillingClient.BillingResponse;
import com.google.android.gms.analytics.ExceptionParser; import com.google.android.gms.analytics.ExceptionParser;
import com.google.android.gms.analytics.ExceptionReporter; import com.google.android.gms.analytics.ExceptionReporter;
import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.GoogleAnalytics;
@ -90,4 +93,13 @@ public class Tracker {
} }
tracker.send(eventBuilder.build()); tracker.send(eventBuilder.build());
} }
public void reportIabResult(@BillingResponse int response, String sku) {
tracker.send(
new HitBuilders.EventBuilder()
.setCategory(context.getString(R.string.tracking_category_iab))
.setAction(sku)
.setLabel(BillingResponseToString(response))
.build());
}
} }

@ -1,28 +0,0 @@
package org.tasks.billing;
import android.app.Activity;
import android.content.Intent;
import javax.inject.Inject;
public class PurchaseHelper {
@Inject
public PurchaseHelper() {}
public boolean purchase(
final Activity activity,
final String sku,
final String pref,
final int requestCode,
final PurchaseHelperCallback callback) {
callback.purchaseCompleted(false, sku);
return false;
}
public void handleActivityResult(
PurchaseHelperCallback callback, int requestCode, int resultCode, Intent data) {}
public void disposeIabHelper() {}
public void consumePurchases() {}
}

@ -0,0 +1,13 @@
package org.tasks.billing;
import com.android.billingclient.api.Purchase;
import javax.inject.Inject;
public class SignatureVerifier {
@Inject
public SignatureVerifier() {}
public boolean verifySignature(Purchase purchase) {
return true;
}
}

@ -25,4 +25,6 @@ public class Tracker {
public void reportEvent(Tracking.Events setPreference, int resId, String s) {} public void reportEvent(Tracking.Events setPreference, int resId, String s) {}
public void reportEvent(Tracking.Events category, String action, String label) {} public void reportEvent(Tracking.Events category, String action, String label) {}
public void reportIabResult(int resultCode, String skus) {}
} }

@ -1,34 +0,0 @@
package org.tasks.billing;
import android.app.Activity;
import android.content.Intent;
import javax.inject.Inject;
import org.tasks.preferences.Preferences;
public class PurchaseHelper {
private Preferences preferences;
@Inject
public PurchaseHelper(Preferences preferences) {
this.preferences = preferences;
}
public boolean purchase(
final Activity activity,
final String sku,
final String pref,
final int requestCode,
final PurchaseHelperCallback callback) {
preferences.setBoolean(pref, true);
callback.purchaseCompleted(true, sku);
return true;
}
public void handleActivityResult(
PurchaseHelperCallback callback, int requestCode, int resultCode, Intent data) {}
public void disposeIabHelper() {}
public void consumePurchases() {}
}

@ -0,0 +1,14 @@
package org.tasks.billing;
import com.android.billingclient.api.Purchase;
import javax.inject.Inject;
public class SignatureVerifier {
@Inject
public SignatureVerifier() {}
public boolean verifySignature(Purchase purchase) {
return true;
}
}

@ -102,6 +102,4 @@ public class Tracker {
.setLabel(BillingResponseToString(response)) .setLabel(BillingResponseToString(response))
.build()); .build());
} }
} }

@ -0,0 +1,29 @@
package org.tasks.billing;
import android.content.Context;
import com.android.billingclient.api.Purchase;
import java.io.IOException;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.injection.ForApplication;
import timber.log.Timber;
public class SignatureVerifier {
private final String billingKey;
@Inject
public SignatureVerifier(@ForApplication Context context) {
billingKey = context.getString(R.string.gp_key);
}
public boolean verifySignature(Purchase purchase) {
try {
return Security.verifyPurchase(
billingKey, purchase.getOriginalJson(), purchase.getSignature());
} catch (IOException e) {
Timber.e(e);
return false;
}
}
}

@ -1,16 +1,12 @@
package org.tasks.billing; package org.tasks.billing;
import android.content.Context;
import com.android.billingclient.api.Purchase; import com.android.billingclient.api.Purchase;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.R;
import org.tasks.injection.ApplicationScope; import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
import timber.log.Timber; import timber.log.Timber;
@ -26,14 +22,14 @@ public class Inventory {
public static final List<String> SKU_SUBS = ImmutableList.of(SKU_PRO); public static final List<String> SKU_SUBS = ImmutableList.of(SKU_PRO);
private final Preferences preferences; private final Preferences preferences;
private final String billingKey; private final SignatureVerifier signatureVerifier;
private Map<String, Purchase> purchases = new HashMap<>(); private Map<String, Purchase> purchases = new HashMap<>();
@Inject @Inject
public Inventory(@ForApplication Context context, Preferences preferences) { public Inventory(Preferences preferences, SignatureVerifier signatureVerifier) {
this.preferences = preferences; this.preferences = preferences;
billingKey = context.getString(R.string.gp_key); this.signatureVerifier = signatureVerifier;
for (Purchase purchase : preferences.getPurchases()) { for (Purchase purchase : preferences.getPurchases()) {
add(purchase); add(purchase);
} }
@ -52,7 +48,7 @@ public class Inventory {
} }
private void add(Purchase purchase) { private void add(Purchase purchase) {
if (verifySignature(purchase)) { if (signatureVerifier.verifySignature(purchase)) {
Timber.d("add(%s)", purchase); Timber.d("add(%s)", purchase);
purchases.put(purchase.getSku(), purchase); purchases.put(purchase.getSku(), purchase);
} }
@ -82,16 +78,6 @@ public class Inventory {
return purchases.containsKey(sku); return purchases.containsKey(sku);
} }
private boolean verifySignature(Purchase purchase) {
try {
return Security.verifyPurchase(
billingKey, purchase.getOriginalJson(), purchase.getSignature());
} catch (IOException e) {
Timber.e(e);
return false;
}
}
public Purchase getPurchase(String sku) { public Purchase getPurchase(String sku) {
return purchases.get(sku); return purchases.get(sku);
} }

Loading…
Cancel
Save