@@ -238,8 +238,7 @@ private void runPendingRequests() {
238
238
BillingRequest request ;
239
239
int maxStartId = -1 ;
240
240
while ((request = mPendingRequests .peek ()) != null ) {
241
- if (mService != null ) {
242
- runRequest (request );
241
+ if (runIfConnected (request )) {
243
242
mPendingRequests .remove ();
244
243
if (maxStartId < request .getStartId ()) {
245
244
maxStartId = request .getStartId ();
@@ -253,17 +252,35 @@ private void runPendingRequests() {
253
252
stopSelf (maxStartId );
254
253
}
255
254
}
256
-
257
- private void runRequest (BillingRequest request ) {
258
- try {
259
- final long requestId = request .run (mService );
260
- BillingController .onRequestSent (requestId , request );
261
- } catch (RemoteException e ) {
262
- Log .w (this .getClass ().getSimpleName (), "Remote billing service crashed" );
263
- // TODO: Retry?
264
- }
265
- }
266
-
255
+
256
+ /**
257
+ * Called when a remote exception occurs while trying to execute the
258
+ * {@link BillingRequest#run(IMarketBillingService)} method.
259
+ * @param e the exception
260
+ */
261
+ protected void onRemoteException (RemoteException e ) {
262
+ Log .w (this .getClass ().getSimpleName (), "Remote billing service crashed" );
263
+ mService = null ;
264
+ }
265
+
266
+ /**
267
+ * Runs the given billing request if the service is already connected.
268
+ * @param request the billing request
269
+ * @return true if the request ran successfully; false if the service
270
+ * is not connected or there was an error when trying to use it
271
+ */
272
+ private boolean runIfConnected (BillingRequest request ) {
273
+ if (mService == null ) return false ;
274
+ try {
275
+ final long requestId = request .run (mService );
276
+ BillingController .onRequestSent (requestId , request );
277
+ return true ;
278
+ } catch (RemoteException e ) {
279
+ onRemoteException (e );
280
+ }
281
+ return false ;
282
+ }
283
+
267
284
private void runRequestOrQueue (BillingRequest request ) {
268
285
mPendingRequests .add (request );
269
286
if (mService == null ) {
0 commit comments