Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteException handling not supported #52

Open
larsa71 opened this issue Nov 9, 2011 · 12 comments
Open

RemoteException handling not supported #52

larsa71 opened this issue Nov 9, 2011 · 12 comments
Assignees
Labels

Comments

@larsa71
Copy link

larsa71 commented Nov 9, 2011

Hi,

I have a test-case where I simulate that the market is stopped in an purchase:

  1. Lunch a test app with a buy button. At this point I am connected with help of the android billing library
  2. I do a force stop on the "Market" application from the "Manage applications" settings
  3. This will generate a remote exception

The current implementation in BillingService.java looks like this:

private void runRequest(BillingRequest request) {
    try {
        final long requestId = request.run(mService);
        BillingController.onRequestSent(requestId, request);
    } catch (RemoteException e) {
        Log.w(this.getClass().getSimpleName(), "Remote billing service crashed");
        // TODO: Retry?
    }
}

So the question here is how to handle: "//TODO: Retry?"

Here is my suggestion in code, don't know if anyone else have a better fix or suggestion how to handle this?

Suggested improvements:

BillingService.java:

public void onServiceDisconnected(ComponentName name) {

    // Genxbit customization to handle the case when we are disconnected.

    // Ensure we're not leaking Android Market billing service
    if (mService != null) {
        try {
            unbindService(this);
        } catch (IllegalArgumentException e) {
            // This might happen if the service was disconnected
        }
    }

    mService = null;
}


private void runRequest(BillingRequest request) {
    try {
        final long requestId = request.run(mService);
        BillingController.onRequestSent(requestId, request);
    } catch (RemoteException e) {
        Log.w(this.getClass().getSimpleName(), "Remote billing service crashed");

        // Genxbit customization

        onServiceDisconnected(null);
        request.onResponseCode(ResponseCode.RESULT_ERROR);
    }
}


// Genxbit customization

public static boolean hasService() {
    return mService != null;
}

BillingController.java

public static BillingStatus checkBillingSupported(Context context) {

    // Genxbit customization

    if (status == BillingStatus.UNKNOWN || !BillingService.hasService()) {
        BillingService.checkBillingSupported(context);
    }
    return status;
}

So then for the retry this can be up to the actual individual implementation to handle in my case I use the the "onRequestPurchaseResponse" callback and in case for ResponseCode.RESULT_ERROR I just perform a BillingController.checkBillingSupported(applicationContext).

@klemensz
Copy link

klemensz commented Aug 8, 2012

+1 for this

@mikeos
Copy link

mikeos commented Sep 12, 2012

+1; without this patch the billing library is unable to recover from crash, which I observed on Galaxy Nexus JB 4.1.1 factory ROM

@thisisnottheaccountyourelookingfor

This should really be labeled as a bug and not a feature. The play store will randomly exit and then your app is stranded with a bad reference that won't get removed until the your app is killed. I opted to catch the RemoteException in runPendingRequests and then rebind the service. This seems to seamlessly rebind and launch the play store without showing an error.

    private void runPendingRequests() {
        BillingRequest request;
        int maxStartId = -1;
        while ((request = mPendingRequests.peek()) != null) {
            if (mService != null) {
                try {
                    runRequest(request);
                    mPendingRequests.remove();
                    if (maxStartId < request.getStartId()) {
                        maxStartId = request.getStartId();
                    }
                } catch (RemoteException re) {
                    rebindMarketBillingService();
                    return;
                }
            } else {
                bindMarketBillingService();
                return;
            }
        }
        if (maxStartId >= 0) {
            stopSelf(maxStartId);
        }
    }
    private void rebindMarketBillingService() {
        try {
            unbindService(this);
        } catch (Exception ignore) { }

        mService = null;
        bindMarketBillingService();
    }

@hpique
Copy link
Member

hpique commented Sep 15, 2012

@jgilbert42 Re-labeled.

Will be fixed in the next update.

@ghost ghost assigned hpique Oct 4, 2012
hpique added a commit to hpique/AndroidBillingLibrary that referenced this issue Oct 17, 2012
@ludocrazy
Copy link

i would like to add the question: why does it crash, first hand?

because i can report that remote exception been thrown / that crash happening on a motorola droid with android 2.1 where the market version is 2002306 - which i do not know what /normal/ market version number fits. 3.06 ? 2.306 ??

and the situation is that isBillingSupported properly returns with support, and the crash appears as soon as i try to requestPurchase. there is a mobile connection present, and the device & market have been previously used. so why does it crash? any ideas?

because, if i use any of the above mentioned fixes, i guess the crash will just appear over and over?

@ludocrazy
Copy link

okay, i have the remotexception (BillingService.runRequest() line 260) been thrown on every device. i googled and hoped it would be a stupid standard mistake, but couldnt find it. as far as i know i follow the typical test steps. the funny thing is, if i do not have connection (wifi + 3g off) then i still get the exception (instead of a "not connected" when i try to purchase my own stuff), if i requestPurchase() on a static response then it works properly (either telling me "not connected" or when connected does what it should, for example the static cancel response returning cancel)

does anybody have an idea what i missed?

@hpique
Copy link
Member

hpique commented Oct 30, 2012

@ludocrazy Can you reproduce the problem with my fork too (or by applying hpique@a625937)?

@ludocrazy
Copy link

i will try, but if i repress the button in my GUI to retry, then it crashes EVERY TIME. so what should your code help, besides endlessly trying? did i miss something reading the code change you linked?

i'm new to github, i do not understand how i can get the files from your pull request. what keywords do i google to learn / understand that? or can you explain it without taking tomuch of your time? thx!

@fraggle222
Copy link

I'm running into this issue on Galaxy Nexus Android 4.1.1, running app directly from eclipse (debug signed) with developer account on phone.

I see that hpique and jgilbert42 both have solutions, but nothing has been released.

Should I implement one of these solutions or is this something that only occurs using debug signed app or what?

@nagoya0
Copy link

nagoya0 commented Feb 4, 2013

+1. My users encountered similar behavior.

@tasomaniac
Copy link

Why this issue is closed? The library has the same error and the same wrong code still.

@konrad-g
Copy link

+1 for suggested improvements - without them this library is useless because it often prevents user from buying products.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants