use of androidx.annotation.WorkerThread in project mobile-center-sdk-android by Microsoft.
the class Analytics method startAppLevelFeatures.
/**
* Start features at app level, this is not done if only libraries started the service.
*/
@WorkerThread
private void startAppLevelFeatures() {
/* Share the started from app check between all calls. */
if (mStartedFromApp) {
/* Enable filtering logs. */
mAnalyticsValidator = new AnalyticsValidator();
mChannel.addListener(mAnalyticsValidator);
/* Start session tracker. */
mSessionTracker = new SessionTracker(mChannel, ANALYTICS_GROUP);
if (isManualSessionTrackerEnabled) {
mSessionTracker.enableManualSessionTracker();
}
mChannel.addListener(mSessionTracker);
/* If we are in foreground, make sure we send start session log now (and track page). */
if (mCurrentActivity != null) {
Activity activity = mCurrentActivity.get();
if (activity != null) {
processOnResume(activity);
}
}
/* Add new channel listener for transmission target. */
mAnalyticsTransmissionTargetListener = AnalyticsTransmissionTarget.getChannelListener();
mChannel.addListener(mAnalyticsTransmissionTargetListener);
}
}
use of androidx.annotation.WorkerThread in project mobile-center-sdk-android by Microsoft.
the class AppCenter method sendStartServiceLog.
/**
* Queue start service log.
*/
@WorkerThread
private void sendStartServiceLog() {
if (!mStartedServicesNamesToLog.isEmpty() && isInstanceEnabled()) {
List<String> allServiceNamesToStart = new ArrayList<>(mStartedServicesNamesToLog);
mStartedServicesNamesToLog.clear();
StartServiceLog startServiceLog = new StartServiceLog();
startServiceLog.setServices(allServiceNamesToStart);
startServiceLog.oneCollectorEnabled(mTransmissionTargetToken != null);
mChannel.enqueue(startServiceLog, CORE_GROUP, Flags.DEFAULTS);
}
}
use of androidx.annotation.WorkerThread in project LshUtils by SenhLinsh.
the class HttpConnectionUtilsEx method get.
@WorkerThread
public static String get(String path, HashMap<String, Object> params, HashMap<String, Object> headers) throws IOException {
HttpURLConnection conn = null;
try {
URL url = new URL(addParams(path, params));
conn = (HttpURLConnection) url.openConnection();
// 请求配置
// POST 请求
conn.setRequestMethod("POST");
// 连接超时
conn.setConnectTimeout(5000);
// 读取超时
conn.setReadTimeout(5000);
// 设置编码
conn.setRequestProperty("Accept-Charset", "utf-8");
// 不使用缓存
conn.setUseCaches(false);
// 添加 Header
if (headers != null) {
for (String key : headers.keySet()) {
conn.setRequestProperty(key, headers.get(key).toString());
}
}
conn.connect();
// 获取响应码
if (conn.getResponseCode() == 200) {
// 读取流
return StreamUtils.readAsString(conn.getInputStream());
} else {
throw new ConnectException(conn.getResponseMessage() + ". Response code is " + conn.getResponseCode());
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
use of androidx.annotation.WorkerThread in project LshUtils by SenhLinsh.
the class HttpConnectionUtilsEx method post.
@WorkerThread
public static String post(String path, HashMap<String, Object> params, HashMap<String, Object> headers, String body) throws IOException {
HttpURLConnection conn = null;
OutputStreamWriter outputStreamWriter = null;
// 是否有http正文提交
boolean hasBody = body != null && body.length() > 0;
try {
URL url = new URL(addParams(path, params));
conn = (HttpURLConnection) url.openConnection();
// 请求配置
// POST 请求
conn.setRequestMethod("POST");
// 连接超时
conn.setConnectTimeout(5000);
// 读取超时
conn.setReadTimeout(5000);
// 设置编码
conn.setRequestProperty("Accept-Charset", "utf-8");
// 不使用缓存
conn.setUseCaches(false);
// 添加 Body 长度
if (hasBody) {
conn.setDoOutput(true);
conn.setRequestProperty("Content-Length", String.valueOf(body.length()));
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
}
// 添加 Header
if (headers != null) {
for (String key : headers.keySet()) {
conn.setRequestProperty(key, headers.get(key).toString());
}
}
conn.connect();
// 发送 Body
if (hasBody) {
outputStreamWriter = new OutputStreamWriter(conn.getOutputStream());
outputStreamWriter.write(body);
outputStreamWriter.flush();
}
// 获取响应码
if (conn.getResponseCode() == 200) {
// 读取流
return StreamUtils.readAsString(conn.getInputStream());
} else {
throw new ConnectException(conn.getResponseMessage() + ". Response code is " + conn.getResponseCode());
}
} finally {
if (conn != null) {
conn.disconnect();
}
if (outputStreamWriter != null) {
try {
outputStreamWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of androidx.annotation.WorkerThread in project android-beacon-library by AltBeacon.
the class ScanHelper method processBeaconFromScan.
/**
* Helper for processing BLE beacons. This has been extracted from {@link ScanHelper.ScanProcessor} to
* support simulated scan data for test and debug environments.
* <p>
* Processing beacons is a frequent and expensive operation. It should not be run on the main
* thread to avoid UI contention.
*/
@WorkerThread
private void processBeaconFromScan(@NonNull Beacon beacon) {
if (Stats.getInstance().isEnabled()) {
Stats.getInstance().log(beacon);
}
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "beacon detected : %s", beacon.toString());
}
beacon = mExtraDataBeaconTracker.track(beacon);
// the above
if (beacon == null) {
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "not processing detections for GATT extra data beacon");
}
} else {
mMonitoringStatus.updateNewlyInsideInRegionsContaining(beacon);
List<Region> matchedRegions;
Iterator<Region> matchedRegionIterator;
LogManager.d(TAG, "looking for ranging region matches for this beacon");
synchronized (mRangedRegionState) {
matchedRegions = matchingRegions(beacon, mRangedRegionState.keySet());
matchedRegionIterator = matchedRegions.iterator();
while (matchedRegionIterator.hasNext()) {
Region region = matchedRegionIterator.next();
LogManager.d(TAG, "matches ranging region: %s", region);
RangeState rangeState = mRangedRegionState.get(region);
if (rangeState != null) {
rangeState.addBeacon(beacon);
}
}
}
}
}
Aggregations