Remove Osmand code from class

This commit is contained in:
cepprice 2021-03-05 20:27:49 +05:00
parent 9da63447c1
commit 83bd81eea7
2 changed files with 27 additions and 10 deletions

View file

@ -200,6 +200,7 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
BillingManager billingManager = getBillingManager(); BillingManager billingManager = getBillingManager();
if (billingManager != null) { if (billingManager != null) {
storeUserInfo(billingManager);
billingManager.initiatePurchaseFlow(activity, skuDetails); billingManager.initiatePurchaseFlow(activity, skuDetails);
} else { } else {
throw new IllegalStateException("BillingManager disposed"); throw new IllegalStateException("BillingManager disposed");
@ -227,6 +228,7 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
} }
BillingManager billingManager = getBillingManager(); BillingManager billingManager = getBillingManager();
if (billingManager != null) { if (billingManager != null) {
storeUserInfo(billingManager);
billingManager.initiatePurchaseFlow(activity, skuDetails); billingManager.initiatePurchaseFlow(activity, skuDetails);
} else { } else {
throw new IllegalStateException("BillingManager disposed"); throw new IllegalStateException("BillingManager disposed");
@ -566,6 +568,7 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
if (AndroidUtils.isActivityNotDestroyed(a) && skuDetails != null) { if (AndroidUtils.isActivityNotDestroyed(a) && skuDetails != null) {
BillingManager billingManager = getBillingManager(); BillingManager billingManager = getBillingManager();
if (billingManager != null) { if (billingManager != null) {
storeUserInfo(billingManager);
billingManager.initiatePurchaseFlow(a, skuDetails); billingManager.initiatePurchaseFlow(a, skuDetails);
} else { } else {
throw new IllegalStateException("BillingManager disposed"); throw new IllegalStateException("BillingManager disposed");
@ -617,6 +620,12 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
onPurchaseDone(getPurchaseInfo(purchase)); onPurchaseDone(getPurchaseInfo(purchase));
} }
private void storeUserInfo(BillingManager billingManager) {
OsmandSettings settings = ctx.getSettings();
billingManager.setUserId(settings.BILLING_USER_ID.get());
billingManager.setUserToken(settings.BILLING_USER_TOKEN.get());
}
@Override @Override
protected boolean isBillingManagerExists() { protected boolean isBillingManagerExists() {
return getBillingManager() != null; return getBillingManager() != null;

View file

@ -2,6 +2,7 @@ package net.osmand.plus.inapp.util;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import com.android.billingclient.api.AcknowledgePurchaseParams; import com.android.billingclient.api.AcknowledgePurchaseParams;
import com.android.billingclient.api.AcknowledgePurchaseResponseListener; import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
@ -22,8 +23,6 @@ import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.SkuDetailsResponseListener; import com.android.billingclient.api.SkuDetailsResponseListener;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -59,6 +58,8 @@ public class BillingManager implements PurchasesUpdatedListener {
// Public key for verifying signature, in base64 encoding // Public key for verifying signature, in base64 encoding
private String mSignatureBase64; private String mSignatureBase64;
private String mUserId;
private String mUserToken;
private final BillingUpdatesListener mBillingUpdatesListener; private final BillingUpdatesListener mBillingUpdatesListener;
private final List<Purchase> mPurchases = new ArrayList<>(); private final List<Purchase> mPurchases = new ArrayList<>();
@ -146,11 +147,14 @@ public class BillingManager implements PurchasesUpdatedListener {
@Override @Override
public void run() { public void run() {
LOG.debug("Launching in-app purchase flow. Replace old SKU? " + (oldSku != null && purchaseToken != null)); LOG.debug("Launching in-app purchase flow. Replace old SKU? " + (oldSku != null && purchaseToken != null));
OsmandSettings settings = getSettings(activity);
BillingFlowParams.Builder paramsBuilder = BillingFlowParams.newBuilder() BillingFlowParams.Builder paramsBuilder = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails) .setSkuDetails(skuDetails);
.setObfuscatedAccountId(settings.BILLING_USER_ID.get()) if (!TextUtils.isEmpty(mUserId)) {
.setObfuscatedProfileId(settings.BILLING_USER_TOKEN.get()); paramsBuilder.setObfuscatedAccountId(mUserId);
}
if (!TextUtils.isEmpty(mUserToken)) {
paramsBuilder.setObfuscatedProfileId(mUserToken);
}
if (oldSku != null && purchaseToken != null) { if (oldSku != null && purchaseToken != null) {
paramsBuilder.setOldSku(oldSku, purchaseToken); paramsBuilder.setOldSku(oldSku, purchaseToken);
} }
@ -401,6 +405,14 @@ public class BillingManager implements PurchasesUpdatedListener {
}); });
} }
public void setUserId(String userId) {
mUserId = userId;
}
public void setUserToken(String userToken) {
mUserToken = userToken;
}
private void executeServiceRequest(Runnable runnable) { private void executeServiceRequest(Runnable runnable) {
if (mIsServiceConnected) { if (mIsServiceConnected) {
runnable.run(); runnable.run();
@ -413,10 +425,6 @@ public class BillingManager implements PurchasesUpdatedListener {
private boolean verifyValidSignature(String signedData, String signature) { private boolean verifyValidSignature(String signedData, String signature) {
return Security.verifyPurchase(mSignatureBase64, signedData, signature); return Security.verifyPurchase(mSignatureBase64, signedData, signature);
} }
private OsmandSettings getSettings(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings();
}
} }