/** * 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; } }
@Override public void onBeforeCalling(URL url, Map<String, String> headers) { if (AppCenterLog.getLogLevel() <= VERBOSE) { /* Log url. */ AppCenterLog.verbose(LOG_TAG, "Calling " + url + "..."); /* Log headers. */ Map<String, String> logHeaders = new HashMap<>(headers); String appSecret = logHeaders.get(APP_SECRET); if (appSecret != null) { logHeaders.put(APP_SECRET, HttpUtils.hideSecret(appSecret)); } AppCenterLog.verbose(LOG_TAG, "Headers: " + logHeaders); } } }
@Override public void onBeforeCalling(URL url, Map<String, String> headers) { if (AppCenterLog.getLogLevel() <= VERBOSE) { /* Log url. */ String urlString = url.toString().replaceAll(mAppSecret, HttpUtils.hideSecret(mAppSecret)); AppCenterLog.verbose(LOG_TAG, "Calling " + urlString + "..."); /* Log headers. */ Map<String, String> logHeaders = new HashMap<>(headers); String apiToken = logHeaders.get(HEADER_API_TOKEN); if (apiToken != null) { logHeaders.put(HEADER_API_TOKEN, HttpUtils.hideSecret(apiToken)); } AppCenterLog.verbose(LOG_TAG, "Headers: " + logHeaders); } } }, new ServiceCallback() {
@Override public void onBeforeCalling(URL url, Map<String, String> headers) { if (AppCenterLog.getLogLevel() <= VERBOSE) { /* Log url. */ AppCenterLog.verbose(LOG_TAG, "Calling " + url + "..."); /* Log headers. */ Map<String, String> logHeaders = new HashMap<>(headers); String apiKeys = logHeaders.get(API_KEY); if (apiKeys != null) { logHeaders.put(API_KEY, HttpUtils.hideApiKeys(apiKeys)); } String tickets = logHeaders.get(TICKETS); if (tickets != null) { logHeaders.put(TICKETS, HttpUtils.hideTickets(tickets)); } AppCenterLog.verbose(LOG_TAG, "Headers: " + logHeaders); } } }
final long startTime = System.currentTimeMillis(); final TestUrl testUrl = iterator.next(); AppCenterLog.verbose(LOG_TAG, "Calling " + testUrl.url); mHttpClient.callAsync(testUrl.url, METHOD_GET, HEADERS, null, new ServiceCallback() { AppCenterLog.verbose(LOG_TAG, "Report payload=" + results.toString(2));
/** * Get configuration. */ private synchronized void getConfiguration(final int configurationUrlIndex, final String rumKey, final HttpClient httpClient) { /* Check if a disable happened while we were waiting the remote configuration. */ if (httpClient != mHttpClient) { return; } if (configurationUrlIndex >= CONFIGURATION_ENDPOINTS.length) { AppCenterLog.error(LOG_TAG, "Could not get configuration file from any of the endpoints."); return; } final String url = CONFIGURATION_ENDPOINTS[configurationUrlIndex]; AppCenterLog.verbose(LOG_TAG, "Calling " + url); httpClient.callAsync(url, METHOD_GET, HEADERS, null, new ServiceCallback() { @Override public void onCallSucceeded(String payload) { /* Read JSON configuration and start testing. */ handleRemoteConfiguration(httpClient, rumKey, payload); } @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); } }); }
reportUrl = String.format(REPORT_URL_FORMAT, reportUrl, reportId, rumKey, parameters); final String finalReportUrl = reportUrl; AppCenterLog.verbose(LOG_TAG, "Calling " + finalReportUrl); mHttpClient.callAsync(finalReportUrl, METHOD_GET, HEADERS, null, new ServiceCallback() {
@Test @SuppressWarnings("unchecked") public void onBeforeCallingWithAnotherLogLevel() throws Exception { /* Mock instances. */ String appSecret = UUID.randomUUID().toString(); String apiToken = UUID.randomUUID().toString(); HttpClient.CallTemplate callTemplate = getCallTemplate(appSecret, apiToken); /* Change log level. */ when(AppCenterLog.getLogLevel()).thenReturn(Log.WARN); /* Call onBeforeCalling with parameters. */ callTemplate.onBeforeCalling(mock(URL.class), mock(Map.class)); /* Verify. */ verifyStatic(never()); AppCenterLog.verbose(anyString(), anyString()); }
@Test public void onBeforeCallingWithoutToken() throws Exception { /* Mock instances. */ String urlFormat = "http://mock/path/%s/path/file"; String appSecret = UUID.randomUUID().toString(); String obfuscatedSecret = HttpUtils.hideSecret(appSecret); URL url = new URL(String.format(urlFormat, appSecret)); String obfuscatedUrlString = String.format(urlFormat, obfuscatedSecret); Map<String, String> headers = new HashMap<>(); HttpClient.CallTemplate callTemplate = getCallTemplate(appSecret, null); when(AppCenterLog.getLogLevel()).thenReturn(Log.VERBOSE); mockStatic(AppCenterLog.class); /* Call onBeforeCalling with parameters. */ callTemplate.onBeforeCalling(url, headers); /* Verify url log. */ verifyStatic(); AppCenterLog.verbose(anyString(), contains(obfuscatedUrlString)); /* Verify header log. */ for (Map.Entry<String, String> header : headers.entrySet()) { verifyStatic(); AppCenterLog.verbose(anyString(), contains(header.getValue())); } }
private static void callLogs() { AppCenterLog.logAssert("my-tag", "error with my-tag"); AppCenterLog.logAssert("my-tag", "error with my-tag with exception", new Exception()); AppCenterLog.error("my-tag", "error with my-tag"); AppCenterLog.error("my-tag", "error with my-tag with exception", new Exception()); AppCenterLog.warn("my-tag", "warn with my-tag"); AppCenterLog.warn("my-tag", "warn with my-tag with exception", new Exception()); AppCenterLog.info("my-tag", "info with my-tag"); AppCenterLog.info("my-tag", "info with my-tag with exception", new Exception()); AppCenterLog.debug("my-tag", "debug with my-tag"); AppCenterLog.debug("my-tag", "debug with my-tag with exception", new Exception()); AppCenterLog.verbose("my-tag", "verbose with my-tag"); AppCenterLog.verbose("my-tag", "verbose with my-tag with exception", new Exception()); }
@Test @SuppressWarnings("unchecked") public void onBeforeCallingWithAnotherLogLevel() throws Exception { /* Mock instances. */ String appSecret = UUIDUtils.randomUUID().toString(); HttpClient.CallTemplate callTemplate = getCallTemplate(appSecret); /* Change log level. */ AppCenterLog.setLogLevel(android.util.Log.WARN); /* Call onBeforeCalling with parameters. */ callTemplate.onBeforeCalling(mock(URL.class), mock(Map.class)); /* Verify. */ verifyStatic(never()); AppCenterLog.verbose(anyString(), anyString()); }
@Test @SuppressWarnings("unchecked") public void onBeforeCallingWithAnotherLogLevel() throws Exception { /* Mock instances. */ String apiKey = UUIDUtils.randomUUID().toString(); HttpClient.CallTemplate callTemplate = getCallTemplate(); /* Change log level. */ AppCenterLog.setLogLevel(android.util.Log.WARN); /* Call onBeforeCalling with parameters. */ callTemplate.onBeforeCalling(mock(URL.class), mock(Map.class)); /* Verify. */ verifyStatic(never()); AppCenterLog.verbose(anyString(), anyString()); }
@Test public void onBeforeCalling() throws Exception { /* Mock instances. */ URL url = new URL("http://mock/path/file"); String appSecret = UUIDUtils.randomUUID().toString(); String obfuscatedSecret = HttpUtils.hideSecret(appSecret); Map<String, String> headers = new HashMap<>(); headers.put("Another-Header", "Another-Value"); HttpClient.CallTemplate callTemplate = getCallTemplate(appSecret); AppCenterLog.setLogLevel(android.util.Log.VERBOSE); mockStatic(AppCenterLog.class); /* Call onBeforeCalling with parameters. */ callTemplate.onBeforeCalling(url, headers); /* Verify url log. */ verifyStatic(); AppCenterLog.verbose(anyString(), contains(url.toString())); /* Verify header log. */ for (Map.Entry<String, String> header : headers.entrySet()) { verifyStatic(); AppCenterLog.verbose(anyString(), contains(header.getValue())); } /* Put app secret to header. */ headers.put(AppCenterIngestion.APP_SECRET, appSecret); callTemplate.onBeforeCalling(url, headers); /* Verify app secret is in log. */ verifyStatic(); AppCenterLog.verbose(anyString(), contains(obfuscatedSecret)); }
AppCenterLog.verbose(anyString(), contains(url.toString())); AppCenterLog.verbose(anyString(), contains(header.getValue())); AppCenterLog.verbose(anyString(), contains(obfuscatedApiKeys)); callTemplate.onBeforeCalling(url, headers); verifyStatic(); AppCenterLog.verbose(anyString(), contains(obfuscatedTickets));
AppCenterLog.verbose(anyString(), argThat(new ArgumentMatcher<String>() {
AppCenterLog.verbose(anyString(), argThat(new ArgumentMatcher<String>() {
AppCenterLog.verbose(anyString(), argThat(new ArgumentMatcher<String>() { @Override public boolean matches(Object argument) {
AppCenterLog.verbose(anyString(), argThat(new ArgumentMatcher<String>() { @Override public boolean matches(Object argument) {
code = errorDetails.getCode(); } catch (JSONException je) { AppCenterLog.verbose(LOG_TAG, "Cannot read the error as JSON", je);