List of usage examples for android.net TrafficStats setThreadStatsTag
public static void setThreadStatsTag(int tag)
From source file:org.gdg.frisbee.android.api.OkStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { if (Const.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { TrafficStats.setThreadStatsTag(0xF00D); try {// w w w .j a v a2s .c om HttpResponse res = super.performRequest(request, additionalHeaders); return res; } finally { TrafficStats.clearThreadStatsTag(); } } else { return super.performRequest(request, additionalHeaders); } }
From source file:com.android.volley.NetworkDispatcher.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void addTrafficStatsTag(Request<?> request) { // Tag the request (if API >= 14) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { TrafficStats.setThreadStatsTag(request.getTrafficStatsTag()); }//from ww w.j a v a 2s.com }
From source file:com.android.exchange.EasAccountService.java
@Override public void run() { mExitStatus = EXIT_DONE;/*from w w w. ja v a2 s . c o m*/ try { // Make sure account and mailbox are still valid if (!setupService()) return; // If we've been stopped, we're done if (mStop) return; try { mDeviceId = ExchangeService.getDeviceId(mContext); int trafficFlags = TrafficFlags.getSyncFlags(mContext, mAccount); TrafficStats.setThreadStatsTag(trafficFlags | TrafficFlags.DATA_EMAIL); if ((mMailbox == null) || (mAccount == null)) { return; } else { sync(); } } catch (EasAuthenticationException e) { userLog("Caught authentication error"); mExitStatus = EXIT_LOGIN_FAILURE; } catch (IOException e) { String message = e.getMessage(); userLog("Caught IOException: ", (message == null) ? "No message" : message); mExitStatus = EXIT_IO_ERROR; } catch (Exception e) { userLog("Uncaught exception in AccountMailboxService", e); } finally { ExchangeService.done(this); if (!mStop) { userLog("Sync finished"); switch (mExitStatus) { case EXIT_SECURITY_FAILURE: // Ask for a new folder list. This should wake up the account mailbox; a // security error in account mailbox should start provisioning ExchangeService.reloadFolderList(mContext, mAccount.mId, true); break; case EXIT_EXCEPTION: errorLog("Sync ended due to an exception."); break; } } else { userLog("Stopped sync finished."); } // Make sure ExchangeService knows about this ExchangeService.kick("sync finished"); } } catch (ProviderUnavailableException e) { LogUtils.e(TAG, "EmailProvider unavailable; sync ended prematurely"); } }
From source file:com.android.exchange.service.EasSyncHandler.java
/** * Perform the sync, updating {@link #mSyncResult} as appropriate (which was passed in from * the system SyncManager and will be read by it on the way out). * This function can send multiple Sync messages to the Exchange server, due to the server * replying to a Sync request with MoreAvailable. * In the case of errors, this function should not attempt any retries, but rather should * set {@link #mSyncResult} to reflect the problem and let the system SyncManager handle * any it.//from ww w. ja v a2s .c o m * @param syncResult */ public final boolean performSync(SyncResult syncResult) { // Set up traffic stats bookkeeping. final int trafficFlags = TrafficFlags.getSyncFlags(mContext, mAccount); TrafficStats.setThreadStatsTag(trafficFlags | getTrafficFlag()); // TODO: Properly handle UI status updates. //syncMailboxStatus(EmailServiceStatus.IN_PROGRESS, 0); int result = SYNC_RESULT_MORE_AVAILABLE; int numWindows = 1; String key = getSyncKey(); while (result == SYNC_RESULT_MORE_AVAILABLE) { result = performOneSync(syncResult, numWindows); // TODO: Clear pending request queue. final String newKey = getSyncKey(); if (result == SYNC_RESULT_MORE_AVAILABLE && key.equals(newKey)) { LogUtils.e(TAG, "Server has more data but we have the same key: %s numWindows: %d", key, numWindows); numWindows++; } else { numWindows = 1; } key = newKey; } return result == SYNC_RESULT_DONE; }