@@ -104,14 +104,14 @@ private void bindMarketBillingService() {
104
104
105
105
private void checkBillingSupported (int startId ) {
106
106
final String packageName = getPackageName ();
107
- final CheckBillingSupported request = new CheckBillingSupported (packageName ,startId );
107
+ final CheckBillingSupported request = new CheckBillingSupported (packageName , startId );
108
108
runRequestOrQueue (request );
109
109
}
110
110
111
- private void confirmNotifications (Intent intent ,int startId ) {
111
+ private void confirmNotifications (Intent intent , int startId ) {
112
112
final String packageName = getPackageName ();
113
113
final String [] notifyIds = intent .getStringArrayExtra (EXTRA_NOTIFY_IDS );
114
- final ConfirmNotifications request = new ConfirmNotifications (packageName ,startId , notifyIds );
114
+ final ConfirmNotifications request = new ConfirmNotifications (packageName , startId , notifyIds );
115
115
runRequestOrQueue (request );
116
116
}
117
117
@@ -127,11 +127,11 @@ private Action getActionFromIntent(Intent intent) {
127
127
return Action .valueOf (split [split .length - 1 ]);
128
128
}
129
129
130
- private void getPurchaseInformation (Intent intent ,int startId ) {
130
+ private void getPurchaseInformation (Intent intent , int startId ) {
131
131
final String packageName = getPackageName ();
132
132
final long nonce = intent .getLongExtra (EXTRA_NONCE , 0 );
133
133
final String [] notifyIds = intent .getStringArrayExtra (EXTRA_NOTIFY_IDS );
134
- final GetPurchaseInformation request = new GetPurchaseInformation (packageName ,startId , notifyIds );
134
+ final GetPurchaseInformation request = new GetPurchaseInformation (packageName , startId , notifyIds );
135
135
request .setNonce (nonce );
136
136
runRequestOrQueue (request );
137
137
}
@@ -157,16 +157,16 @@ public void onServiceDisconnected(ComponentName name) {
157
157
// method will not be called.
158
158
@ Override
159
159
public void onStart (Intent intent , int startId ) {
160
- handleCommand (intent ,startId );
160
+ handleCommand (intent , startId );
161
161
}
162
162
163
163
// @Override // Avoid compile errors on pre-2.0
164
164
public int onStartCommand (Intent intent , int flags , int startId ) {
165
- handleCommand (intent ,startId );
165
+ handleCommand (intent , startId );
166
166
return Compatibility .START_NOT_STICKY ;
167
167
}
168
168
169
- private void handleCommand (Intent intent ,int startId ) {
169
+ private void handleCommand (Intent intent , int startId ) {
170
170
final Action action = getActionFromIntent (intent );
171
171
if (action == null ) {
172
172
return ;
@@ -176,49 +176,53 @@ private void handleCommand(Intent intent,int startId) {
176
176
checkBillingSupported (startId );
177
177
break ;
178
178
case REQUEST_PURCHASE :
179
- requestPurchase (intent ,startId );
179
+ requestPurchase (intent , startId );
180
180
break ;
181
181
case GET_PURCHASE_INFORMATION :
182
- getPurchaseInformation (intent ,startId );
182
+ getPurchaseInformation (intent , startId );
183
183
break ;
184
184
case CONFIRM_NOTIFICATIONS :
185
- confirmNotifications (intent ,startId );
185
+ confirmNotifications (intent , startId );
186
186
break ;
187
187
case RESTORE_TRANSACTIONS :
188
- restoreTransactions (intent ,startId );
188
+ restoreTransactions (intent , startId );
189
189
}
190
190
}
191
191
192
- private void requestPurchase (Intent intent ,int startId ) {
192
+ private void requestPurchase (Intent intent , int startId ) {
193
193
final String packageName = getPackageName ();
194
194
final String itemId = intent .getStringExtra (EXTRA_ITEM_ID );
195
195
final String developerPayload = intent .getStringExtra (EXTRA_DEVELOPER_PAYLOAD );
196
- final RequestPurchase request = new RequestPurchase (packageName ,startId , itemId , developerPayload );
196
+ final RequestPurchase request = new RequestPurchase (packageName , startId , itemId , developerPayload );
197
197
runRequestOrQueue (request );
198
198
}
199
199
200
- private void restoreTransactions (Intent intent ,int startId ) {
200
+ private void restoreTransactions (Intent intent , int startId ) {
201
201
final String packageName = getPackageName ();
202
202
final long nonce = intent .getLongExtra (EXTRA_NONCE , 0 );
203
- final RestoreTransactions request = new RestoreTransactions (packageName ,startId );
203
+ final RestoreTransactions request = new RestoreTransactions (packageName , startId );
204
204
request .setNonce (nonce );
205
205
runRequestOrQueue (request );
206
206
}
207
207
208
208
private void runPendingRequests () {
209
209
BillingRequest request ;
210
- int maxId = -1 ;
210
+ int maxStartId = -1 ;
211
211
while ((request = mPendingRequests .peek ()) != null ) {
212
212
if (mService != null ) {
213
213
runRequest (request );
214
214
mPendingRequests .remove ();
215
-
216
- if (maxId <request .getStartId ())
217
- maxId =request .getStartId ();
215
+ if (maxStartId < request .getStartId ()) {
216
+ maxStartId = request .getStartId ();
217
+ }
218
+ } else {
219
+ bindMarketBillingService ();
220
+ return ;
218
221
}
219
222
}
220
- if (maxId >=0 )
221
- stopSelf (maxId );
223
+ if (maxStartId >= 0 ) {
224
+ stopSelf (maxStartId );
225
+ }
222
226
}
223
227
224
228
private void runRequest (BillingRequest request ) {
@@ -243,7 +247,7 @@ private void runRequestOrQueue(BillingRequest request) {
243
247
@ Override
244
248
public void onDestroy () {
245
249
super .onDestroy ();
246
- //Ensure not leaking android market billing service
250
+ // Ensure we're not leaking Android Market billing service
247
251
if (mService != null ) {
248
252
try {
249
253
unbindService (this );
0 commit comments