private void fetchProvisioning(
     String acceptedTosVersion, final Runnable successRunnable, final Runnable errorRunnable) {
   CarrierBillingParameters params = this.mDcbStorage.getParams();
   if (params != null) {
     final String carrierId = params.getId();
     fetchProvisioning(
         acceptedTosVersion,
         new Listener<CarrierBillingProvisioning>() {
           public void onResponse(CarrierBillingProvisioning provisioning) {
             long now = System.currentTimeMillis();
             if (provisioning == null) {
               FinskyLog.w("Fetching provisioning returned null.", new Object[0]);
               BillingPreferences.EARLIEST_PROVISIONING_CHECK_TIME_MILLIS.put(
                   Long.valueOf(
                       now + ((Long) G.vendingCarrierProvisioningRetryMs.get()).longValue()));
               BillingEventRecorder.recordError(carrierId, 0, "SERVER");
             } else {
               BillingPreferences.EARLIEST_PROVISIONING_CHECK_TIME_MILLIS.put(
                   Long.valueOf(
                       now
                           + ((Long) G.vendingCarrierProvisioningRefreshFrequencyMs.get())
                               .longValue()));
               CarrierProvisioningAction.this.mDcbStorage.setProvisioning(provisioning);
               BillingEventRecorder.recordSuccess(carrierId, 0, provisioning.isProvisioned());
             }
             if (successRunnable != null) {
               successRunnable.run();
             }
           }
         },
         new ErrorListener() {
           public void onErrorResponse(VolleyError error) {
             FinskyLog.d("CarrierProvisioningAction encountered an error: %s", error);
             String legacyMessage = DfeUtils.getLegacyErrorCode(error);
             String exceptionMessage = error.getMessage();
             String exceptionType = error.getClass().getCanonicalName();
             String message =
                 String.format(
                     "%s/%s/%s", new Object[] {legacyMessage, exceptionMessage, exceptionType});
             BillingPreferences.EARLIEST_PROVISIONING_CHECK_TIME_MILLIS.put(
                 Long.valueOf(
                     System.currentTimeMillis()
                         + ((Long) G.vendingCarrierProvisioningRetryMs.get()).longValue()));
             BillingEventRecorder.recordError(carrierId, 0, message);
             if (errorRunnable != null) {
               errorRunnable.run();
             }
           }
         });
     updateBillingPreferences(System.currentTimeMillis());
   } else if (errorRunnable != null) {
     errorRunnable.run();
   }
 }
 static boolean shouldFetchProvisioning(
     CarrierBillingStorage carrierBillingStorage,
     long now,
     long awakeTime,
     long lastCheck,
     long earliestCheck) {
   CarrierBillingParameters params = carrierBillingStorage.getParams();
   if (params == null || params.getGetProvisioningUrl() == null) {
     FinskyLog.d(
         "Required CarrierBillingParams missing. Shouldn't fetch provisioning.", new Object[0]);
     return false;
   }
   boolean hasBootedSinceLastCheck = now - lastCheck > awakeTime;
   if (now > earliestCheck) {
     return true;
   }
   if (CarrierBillingUtils.isProvisioned(carrierBillingStorage) || !hasBootedSinceLastCheck) {
     return false;
   }
   return true;
 }