private void processResponse(ImageResponse response) { // First check if the response is for the right request. We may have: // 1. Sent a new request, thus super-ceding this one. // 2. Detached this view, in which case the response should be discarded. if (response.getRequest() == lastRequest) { lastRequest = null; Bitmap responseImage = response.getBitmap(); Exception error = response.getError(); if (error != null) { OnErrorListener listener = onErrorListener; if (listener != null) { listener.onError(new FacebookException( "Error in downloading profile picture for profileId: " + getProfileId(), error)); } else { Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, error.toString()); } } else if (responseImage != null) { setImageBitmap(responseImage); if (response.isCachedRedirect()) { sendImageRequest(false); } } } }
void onSuspend(AppEventsLogger logger, long eventTime) { if (!isAppActive) { Logger.log(LoggingBehavior.APP_EVENTS, TAG, "Suspend for inactive app"); return; } long now = eventTime; long delta = (now - lastResumeTime); if (delta < 0) { Logger.log(LoggingBehavior.APP_EVENTS, TAG, "Clock skew detected"); delta = 0; } millisecondsSpentInSession += delta; lastSuspendTime = now; isAppActive = false; }
public static JSONObject getJSONObjectForGraphAPICall( GraphAPIActivityType activityType, AttributionIdentifiers attributionIdentifiers, String anonymousAppDeviceGUID, boolean limitEventUsage, Context context) throws JSONException { JSONObject publishParams = new JSONObject(); publishParams.put("event", API_ACTIVITY_TYPE_TO_STRING.get(activityType)); Utility.setAppEventAttributionParameters(publishParams, attributionIdentifiers, anonymousAppDeviceGUID, limitEventUsage); // The code to get all the Extended info is safe but just in case we can wrap the // whole call in its own try/catch block since some of the things it does might // cause unexpected exceptions on rooted/funky devices: try { Utility.setAppEventExtendedDeviceInfoParameters( publishParams, context); } catch (Exception e) { // Swallow but log Logger.log(LoggingBehavior.APP_EVENTS, "AppEvents", "Fetching extended device info parameters failed: '%s'", e.toString()); } publishParams.put("application_package_name", context.getPackageName()); return publishParams; }
public static void log( LoggingBehavior behavior, int priority, String tag, String format, Object... args) { if (FacebookSdk.isLoggingBehaviorEnabled(behavior)) { String string = String.format(format, args); log(behavior, priority, tag, string); } }
public static void log(LoggingBehavior behavior, int priority, String tag, String string) { if (FacebookSdk.isLoggingBehaviorEnabled(behavior)) { string = replaceStrings(string); if (tag.startsWith(LOG_TAG_BASE) == false) { tag = LOG_TAG_BASE + tag; } Log.println(priority, tag, string); // Developer errors warrant special treatment by printing out a stack trace, to make // both more noticeable, and let the source of the problem be more easily pinpointed. if (behavior == LoggingBehavior.DEVELOPER_ERRORS) { (new Exception()).printStackTrace(); } } }
public Logger(LoggingBehavior behavior, String tag) { Validate.notNullOrEmpty(tag, "tag"); this.behavior = behavior; this.tag = LOG_TAG_BASE + tag; this.contents = new StringBuilder(); }
static InputStream getCachedImageStream(Uri uri, Context context) { InputStream imageStream = null; if (uri != null) { if (isCDNURL(uri)) { try { FileLruCache cache = getCache(context); imageStream = cache.get(uri.toString()); } catch (IOException e) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString()); } } } return imageStream; }
static void clearCache(Context context) { try { getCache(context).clearCache(); } catch (IOException e) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, "clearCache failed " + e.getMessage()); } }
static void clearCache() { try { getCache().clearCache(); } catch (IOException e) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, "clearCache failed " + e.getMessage()); } }
public static void log(LoggingBehavior behavior, int priority, String tag, String string) { if (Settings.isLoggingBehaviorEnabled(behavior)) { string = replaceStrings(string); if (tag.startsWith(LOG_TAG_BASE) == false) { tag = LOG_TAG_BASE + tag; } Log.println(priority, tag, string); // Developer errors warrant special treatment by printing out a stack trace, to make both more noticeable, // and let the source of the problem be more easily pinpointed. if (behavior == LoggingBehavior.DEVELOPER_ERRORS) { (new Exception()).printStackTrace(); } } }
static InputStream getCachedImageStream(URI url, Context context) { InputStream imageStream = null; if (url != null) { if (isCDNURL(url)) { try { FileLruCache cache = getCache(context); imageStream = cache.get(url.toString()); } catch (IOException e) { Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString()); } } } return imageStream; }
private void sendImageRequest(boolean allowCachedResponse) { try { ImageRequest.Builder requestBuilder = new ImageRequest.Builder( getContext(), ImageRequest.getProfilePictureUrl(profileId, queryWidth, queryHeight)); ImageRequest request = requestBuilder.setAllowCachedRedirects(allowCachedResponse) .setCallerTag(this) .setCallback( new ImageRequest.Callback() { @Override public void onCompleted(ImageResponse response) { processResponse(response); } }) .build(); // Make sure to cancel the old request before sending the new one to prevent // accidental cancellation of the new request. This could happen if the URL and // caller tag stayed the same. if (lastRequest != null) { ImageDownloader.cancelRequest(lastRequest); } lastRequest = request; ImageDownloader.downloadAsync(request); } catch (URISyntaxException e) { Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, e.toString()); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); FacebookSdk.addLoggingBehavior(LoggingBehavior.REQUESTS); }
static void saveAppSessionInformation(Context context) { ObjectOutputStream oos = null; synchronized (staticLock) { if (hasChanges) { try { oos = new ObjectOutputStream( new BufferedOutputStream( context.openFileOutput( PERSISTED_SESSION_INFO_FILENAME, Context.MODE_PRIVATE) ) ); oos.writeObject(appSessionInfoMap); hasChanges = false; Logger.log( LoggingBehavior.APP_EVENTS, "AppEvents", "App session info saved"); } catch (Exception e) { Log.d(TAG, "Got unexpected exception: " + e.toString()); } finally { Utility.closeQuietly(oos); } } } }
@SuppressWarnings("unchecked") private static void restoreAppSessionInformation(Context context) { ObjectInputStream ois = null; synchronized (staticLock) { if (!isLoaded) { try { ois = new ObjectInputStream( context.openFileInput(PERSISTED_SESSION_INFO_FILENAME)); appSessionInfoMap = (HashMap<AccessTokenAppIdPair, FacebookTimeSpentData>) ois.readObject(); Logger.log( LoggingBehavior.APP_EVENTS, "AppEvents", "App session info loaded"); } catch (FileNotFoundException fex) { } catch (Exception e) { Log.d(TAG, "Got unexpected exception: " + e.toString()); } finally { Utility.closeQuietly(ois); context.deleteFile(PERSISTED_SESSION_INFO_FILENAME); if (appSessionInfoMap == null) { appSessionInfoMap = new HashMap<AccessTokenAppIdPair, FacebookTimeSpentData>(); } // Regardless of the outcome of the load, the session information cache // is always deleted. Therefore, always treat the session information cache // as loaded isLoaded = true; hasChanges = false; } } } }