Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

#259 #260

Merged
merged 3 commits into from
Jul 23, 2014
Merged

#259 #260

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions library/src/org/onepf/oms/OpenIabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
Expand Down Expand Up @@ -375,7 +376,13 @@ public void run() {
// try it only if samsung SKUs are specified
stores2check.add(new SamsungApps(activity, options));
}
//Nokia TODO change logic
stores2check.add(new NokiaStore(context));
if (!hasRequestedPermission(context, "com.nokia.payment.BILLING")) {
if (isDebugLog()) {
Log.w(TAG, "Required permission \"com.nokia.payment.BILLING\" NOT REQUESTED");
}
}
}

//todo redo
Expand Down Expand Up @@ -492,6 +499,7 @@ private static void checkSettings(Options options, Context context){
if (BuildConfig.FORTUMO_ENABLE) {
checkFortumo(options, context);
}
checkNokia(options, context);
}

private static void checkFortumo(Options options, Context context) {
Expand Down Expand Up @@ -593,6 +601,43 @@ private static void checkFortumo(Options options, Context context) {

}

private static void checkNokia(Options options, Context context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does method static? OpenIab helper contains Options in field. You can make method non-static and remove Option from parametres.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for Context parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these methods should be moved later to an Utils class.

List<Appstore> availableStores = options.availableStores;
boolean hasNokia = false;
if (availableStores != null && availableStores.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use !availableStore.isEmpty instead of availableStores.size() > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a matter of taste. As for me I don't like ! before smt.isEmpty.

for (Appstore appstore : availableStores) {
if (appstore.getAppstoreName().equals(NAME_NOKIA)) {
hasNokia = true;
break;
}
}
}
if (hasNokia) {
if (!hasRequestedPermission(context, "com.nokia.payment.BILLING")) {
throw new IllegalStateException("Nokia permission \"com.nokia.payment.BILLING\" NOT REQUESTED");
}
}
}

//todo move to Utils
private static boolean hasRequestedPermission(Context context, String permission) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't move method immediate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to understand the architecture before to add new classes. And this fix is urgent.

try {
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
if (info.requestedPermissions != null) {
for (String p : info.requestedPermissions) {
if (p.equals(permission)) {
return true;
}
}
}
} catch (NameNotFoundException e) {
if (isDebugLog()) {
Log.e(TAG, "error during checking permissions", e);
}
}
return false;
}

//todo move to Utils
private static void checkPermission(Context context, String paramString, StringBuilder builder) {
if (context.checkCallingOrSelfPermission(paramString) != PackageManager.PERMISSION_GRANTED) {
Expand Down
86 changes: 55 additions & 31 deletions library/src/org/onepf/oms/appstore/nokiaUtils/NokiaStoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.List;

public class NokiaStoreHelper implements AppstoreInAppBillingService {

//todo why own constants?
public static final int RESULT_OK = 0;
public static final int RESULT_USER_CANCELED = 1;
public static final int RESULT_BILLING_UNAVAILABLE = 3;
Expand All @@ -45,6 +45,8 @@ public class NokiaStoreHelper implements AppstoreInAppBillingService {
public static final int RESULT_ITEM_NOT_OWNED = 8;
public static final int RESULT_NO_SIM = 9;

public static final int RESULT_BAD_RESPONSE = -1002;

private static final String TAG = NokiaStoreHelper.class.getSimpleName();
public static final boolean IS_DEBUG_MODE = false;

Expand Down Expand Up @@ -128,12 +130,18 @@ public void onServiceDisconnected(final ComponentName name) {
"Billing service unavailable on device."));
}

} else {

mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

}
}
} else {
try {
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
} catch (SecurityException e) {
logError("Can't bind to the service", e);
if (listener != null) {
listener.onIabSetupFinished(new NokiaResult(RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device due to lack of the permission \"com.nokia.payment.BILLING\"."));
}
}
}
}

private Intent getServiceIntent() {
final Intent intent = new Intent(NokiaStore.VENDING_ACTION);
Expand Down Expand Up @@ -180,29 +188,36 @@ public void launchPurchaseFlow(final Activity act, final String sku, final Strin
}

try {
final Bundle buyIntentBundle = mService.getBuyIntent(
3, getPackageName(), sku, IabHelper.ITEM_TYPE_INAPP, extraData
);

logDebug("buyIntentBundle = " + buyIntentBundle);

final int responseCode = buyIntentBundle.getInt("RESPONSE_CODE", 0);
final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

if (responseCode == RESULT_OK) {
mRequestCode = requestCode;
mPurchaseListener = listener;

final IntentSender intentSender = pendingIntent.getIntentSender();
act.startIntentSenderForResult(
intentSender, requestCode, new Intent(), 0, 0, 0
);
} else if(listener != null) {
final IabResult result = new NokiaResult(responseCode, "Failed to get buy intent.");
listener.onIabPurchaseFinished(result, null);
}

} catch (RemoteException e) {
if (mService == null) {
if (listener != null) {
logError("Unable to buy item, Error response: service is not connected.");
NokiaResult result = new NokiaResult(RESULT_ERROR, "Unable to buy item");
listener.onIabPurchaseFinished(result, null);
}
} else {
final Bundle buyIntentBundle = mService.getBuyIntent(
3, getPackageName(), sku, IabHelper.ITEM_TYPE_INAPP, extraData
);

logDebug("buyIntentBundle = " + buyIntentBundle);

final int responseCode = buyIntentBundle.getInt("RESPONSE_CODE", 0);
final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

if (responseCode == RESULT_OK) {
mRequestCode = requestCode;
mPurchaseListener = listener;

final IntentSender intentSender = pendingIntent.getIntentSender();
act.startIntentSenderForResult(
intentSender, requestCode, new Intent(), 0, 0, 0
);
} else if (listener != null) {
final IabResult result = new NokiaResult(responseCode, "Failed to get buy intent.");
listener.onIabPurchaseFinished(result, null);
}
}
} catch (RemoteException e) {
logError("RemoteException: " + e, e);

final IabResult result = new NokiaResult(IabHelper.IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
Expand Down Expand Up @@ -460,6 +475,11 @@ private void refreshPurchasedItems(final List<String> moreItemSkus, final Invent
storeSkusBundle.putStringArrayList("ITEM_ID_LIST", storeSkus);

try {
if (mService == null) {
logError("Unable to refresh purchased items.");
throw new IabException(RESULT_BAD_RESPONSE, "Error refreshing inventory (querying owned items).");
}

final Bundle purchasedBundle = mService.getPurchases(
3, getPackageName(), OpenIabHelper.ITEM_TYPE_INAPP, storeSkusBundle, null
);
Expand Down Expand Up @@ -535,8 +555,12 @@ private void refreshItemDetails(final List<String> moreItemSkus, final Inventory
storeSkusBundle.putStringArrayList("ITEM_ID_LIST", combinedStoreSkus);

try {
if (mService == null) {
logError("Unable to refresh item details.");
throw new IabException(RESULT_BAD_RESPONSE, "Error refreshing item details.");
}

final Bundle productDetailBundle = mService.getProductDetails(
final Bundle productDetailBundle = mService.getProductDetails(
3, getPackageName(), OpenIabHelper.ITEM_TYPE_INAPP, storeSkusBundle
);

Expand Down