Search in sources :

Example 91 with WorkerThread

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);
    }
}
Also used : AnalyticsValidator(com.microsoft.appcenter.analytics.channel.AnalyticsValidator) Activity(android.app.Activity) SessionTracker(com.microsoft.appcenter.analytics.channel.SessionTracker) WorkerThread(androidx.annotation.WorkerThread)

Example 92 with WorkerThread

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);
    }
}
Also used : ArrayList(java.util.ArrayList) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) WorkerThread(androidx.annotation.WorkerThread)

Example 93 with WorkerThread

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();
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) ConnectException(java.net.ConnectException) WorkerThread(androidx.annotation.WorkerThread)

Example 94 with WorkerThread

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();
            }
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) OutputStreamWriter(java.io.OutputStreamWriter) URL(java.net.URL) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException) WorkerThread(androidx.annotation.WorkerThread)

Example 95 with WorkerThread

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);
                }
            }
        }
    }
}
Also used : Region(org.altbeacon.beacon.Region) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)365 NonNull (androidx.annotation.NonNull)151 IOException (java.io.IOException)83 Recipient (org.thoughtcrime.securesms.recipients.Recipient)82 Nullable (androidx.annotation.Nullable)51 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)46 Cursor (android.database.Cursor)41 ArrayList (java.util.ArrayList)41 Context (android.content.Context)39 Uri (android.net.Uri)32 LinkedList (java.util.LinkedList)30 List (java.util.List)30 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)28 Stream (com.annimon.stream.Stream)26 HashMap (java.util.HashMap)26 Log (org.signal.core.util.logging.Log)26 HashSet (java.util.HashSet)24 Map (java.util.Map)21 Collections (java.util.Collections)20 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)20