@Override public void onCallFailed(Exception e) { /* Log error and try the next configuration endpoint. */ AppCenterLog.error(LOG_TAG, "Could not get configuration file at " + url, e); getConfiguration(configurationUrlIndex + 1, rumKey, httpClient); } });
@Override public void run() { mUserId = UserIdContext.getPrefixedUserId(userId); } });
/** * Notify listeners that the network state changed. * * @param connected whether the network is connected or not. */ private void notifyNetworkStateUpdated(boolean connected) { for (Listener listener : mListeners) { listener.onNetworkStateUpdated(connected); } }
@Override public synchronized ServiceCall callAsync(String url, String method, Map<String, String> headers, CallTemplate callTemplate, ServiceCallback serviceCallback) { Call call = new Call(mDecoratedApi, url, method, headers, callTemplate, serviceCallback); if (mNetworkStateHelper.isNetworkConnected()) { call.run(); } else { mCalls.add(call); AppCenterLog.debug(LOG_TAG, "Call triggered with no network connectivity, waiting network to become available..."); } return call; }
@Override public void run() { /* And make sure we run the original command on U.I. thread. */ HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { runIfEnabled(runnable); } }); } }, new Runnable() {
/** * Handle network available update on API level >= 21. */ private synchronized void onNetworkLost(Network network) { /* * We will have WIFI network available event before we lose mobile network. * This notification scheme is similar to the old connectivity receiver implementation. */ AppCenterLog.debug(LOG_TAG, "Network lost netId: " + network); mAvailableNetworks.remove(network); AppCenterLog.debug(LOG_TAG, "Available networks netIds: " + mAvailableNetworks); notifyNetworkStateUpdated(false); if (!mAvailableNetworks.isEmpty()) { notifyNetworkStateUpdated(true); } }
@Override public void onCallSucceeded(String payload) { AppCenterLog.info(LOG_TAG, "Measurements reported successfully."); }
@NonNull static String computeReleaseHash(@NonNull PackageInfo packageInfo) { return HashUtils.sha256(packageInfo.packageName + ":" + packageInfo.versionName + ":" + DeviceInfoHelper.getVersionCode(packageInfo)); }
/** * Used to avoid querying download manager on every activity change. * * @param releaseDetails release details to check state. */ synchronized void markDownloadStillInProgress(ReleaseDetails releaseDetails) { if (releaseDetails == mReleaseDetails) { AppCenterLog.verbose(LOG_TAG, "Download is still in progress..."); mCheckedDownload = true; } }
/** * Create a new authentication provider. * * @param type The type for the provider. * @param ticketKey The ticket key for the provider. This can be any value and does not need to match user identifier. * This value will be used in the token provider callback for giving context. The only requirement * is that ticket key is different if registering a new provider (for example to switch user). * Typical implementations will pass user identifier as a value but it's not a requirement. * @param tokenProvider The token provider that will be used to get a current authentication token. */ public AuthenticationProvider(Type type, String ticketKey, TokenProvider tokenProvider) { mType = type; mTicketKey = ticketKey; mTicketKeyHash = ticketKey == null ? null : HashUtils.sha256(ticketKey); mTokenProvider = tokenProvider; }
/** * Init. * * @param decoratedApi decorated API. * @param networkStateHelper network state helper. */ public HttpClientNetworkStateHandler(HttpClient decoratedApi, NetworkStateHelper networkStateHelper) { super(decoratedApi); mNetworkStateHelper = networkStateHelper; mNetworkStateHelper.addListener(this); }
/** * Get shared instance. * * @param context any context. * @return shared instance. */ public static synchronized NetworkStateHelper getSharedInstance(Context context) { if (sSharedInstance == null) { sSharedInstance = new NetworkStateHelper(context); } return sSharedInstance; }
/** * {@link #setLogLevel(int)} implementation at instance level. * * @param logLevel log level. */ private synchronized void setInstanceLogLevel(int logLevel) { mLogLevelConfigured = true; AppCenterLog.setLogLevel(logLevel); }
/** * Get unique instance. * * @return unique instance. */ public static synchronized UserIdContext getInstance() { if (sInstance == null) { sInstance = new UserIdContext(); } return sInstance; }
/** * Common validation for both AppCenter and One Collector, specific validation happens later. */ private boolean isValidValue(Object value) { if (value == null) { AppCenterLog.error(LOG_TAG, VALUE_NULL_ERROR_MESSAGE); return false; } return true; } }
@Override protected void onPostExecute(final DownloadProgress result) { if (result != null) { /* onPostExecute is not always called on UI thread due to an old Android bug. */ HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { Distribute.getInstance().updateProgressDialog(mReleaseDetails, result); } }); } }
/** * Handle network available update on API level >= 21. */ private synchronized void onNetworkAvailable(Network network) { AppCenterLog.debug(LOG_TAG, "Network available netId: " + network); mAvailableNetworks.add(network); AppCenterLog.debug(LOG_TAG, "Available networks netIds: " + mAvailableNetworks); /* * Trigger event only once if we gain a new network while one was already * available. Special logic is handled in network lost events. */ if (mAvailableNetworks.size() == 1) { notifyNetworkStateUpdated(true); } }
@Override public void onCallFailed(Exception e) { AppCenterLog.error(LOG_TAG, testUrl.url + " call failed", e); testUrl(httpClient, rumKey, iterator); } });
@Override public void onCallSucceeded(final String payload) { /* onPostExecute is not always called on UI thread due to an old Android bug. */ HandlerUtils.runOnUiThread(new Runnable() { @Override public void run() { try { handleApiCallSuccess(releaseCallId, payload, ReleaseDetails.parse(payload)); } catch (JSONException e) { onCallFailed(e); } } }); }
@Override public void run() { /* This flag is always read/written in the background thread. */ if (mStartedFromApp) { queuePage(name, propertiesCopy); } else { AppCenterLog.error(LOG_TAG, "Cannot track page if not started from app."); } } });