Skip to content

Commit

Permalink
Facebook Android SDK 4.32
Browse files Browse the repository at this point in the history
  • Loading branch information
fbtaoge committed Apr 11, 2018
2 parents fc05b51 + 8543e64 commit cf963f5
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 33 deletions.
14 changes: 7 additions & 7 deletions README.mdown
Expand Up @@ -68,25 +68,25 @@ include the appropriate dependency (or dependencies) listed below in your `app/b

dependencies {
// Facebook Core only (Analytics)
implementation 'com.facebook.android:facebook-core:4.31.0'
implementation 'com.facebook.android:facebook-core:4.32.0'

// Facebook Login only
implementation 'com.facebook.android:facebook-login:4.31.0'
implementation 'com.facebook.android:facebook-login:4.32.0'

// Facebook Share only
implementation 'com.facebook.android:facebook-share:4.31.0'
implementation 'com.facebook.android:facebook-share:4.32.0'

// Facebook Places only
implementation 'com.facebook.android:facebook-places:4.31.0'
implementation 'com.facebook.android:facebook-places:4.32.0'

// Facbeook Messenger only
implementation 'com.facebook.android:facebook-messenger:4.31.0'
implementation 'com.facebook.android:facebook-messenger:4.32.0'

// Facebook App Links only
implementation 'com.facebook.android:facebook-applinks:4.31.0'
implementation 'com.facebook.android:facebook-applinks:4.32.0'

// Facebook Android SDK (everything)
implementation 'com.facebook.android:facebook-android-sdk:4.31.0'
implementation 'com.facebook.android:facebook-android-sdk:4.32.0'
}

You may also need to add the following to your project/build.gradle file.
Expand Down
Expand Up @@ -21,5 +21,5 @@
package com.facebook;

final class FacebookSdkVersion {
public static final String BUILD = "4.31.0";
public static final String BUILD = "4.32.0";
}
10 changes: 7 additions & 3 deletions facebook-core/src/main/java/com/facebook/GraphRequest.java
Expand Up @@ -1442,7 +1442,11 @@ private void addCommonParameters() {
}
}

private String appendParametersToBaseUrl(String baseUrl) {
private String appendParametersToBaseUrl(String baseUrl, Boolean isBatch) {
if (!isBatch && httpMethod == HttpMethod.POST) {
return baseUrl;
}

Uri.Builder uriBuilder = Uri.parse(baseUrl).buildUpon();

Set<String> keys = this.parameters.keySet();
Expand Down Expand Up @@ -1480,7 +1484,7 @@ final String getRelativeUrlForBatchedRequest() {
String baseUrl =
String.format("%s/%s", ServerProtocol.getGraphUrlBase(), getGraphPathWithVersion());
addCommonParameters();
String fullUrl = appendParametersToBaseUrl(baseUrl);
String fullUrl = appendParametersToBaseUrl(baseUrl, true);
Uri uri = Uri.parse(fullUrl);
String relativeUrl = String.format("%s?%s", uri.getPath(), uri.getQuery());
return relativeUrl;
Expand All @@ -1502,7 +1506,7 @@ final String getUrlForSingleRequest() {
String baseUrl = String.format("%s/%s", graphBaseUrlBase, getGraphPathWithVersion());

addCommonParameters();
return appendParametersToBaseUrl(baseUrl);
return appendParametersToBaseUrl(baseUrl, false);
}

private String getGraphPathWithVersion() {
Expand Down
Expand Up @@ -107,8 +107,28 @@ public class AppEventsConstants {
*/
public static final String EVENT_NAME_SPENT_CREDITS = "fb_mobile_spent_credits";

/**
* Log the live streaming events from sdk
*/
public static final String EVENT_NAME_LIVE_STREAMING_START = "fb_sdk_live_streaming_start";
public static final String EVENT_NAME_LIVE_STREAMING_STOP = "fb_sdk_live_streaming_stop";
public static final String EVENT_NAME_LIVE_STREAMING_PAUSE = "fb_sdk_live_streaming_pause";
public static final String EVENT_NAME_LIVE_STREAMING_RESUME = "fb_sdk_live_streaming_resume";
public static final String EVENT_NAME_LIVE_STREAMING_ERROR = "fb_sdk_live_streaming_error";
public static final String EVENT_NAME_LIVE_STREAMING_UPDATE_STATUS =
"fb_sdk_live_streaming_update_status";

// Event parameters

/**
* Paramete keys for live streaming events
*
*/
public static final String EVENT_PARAM_LIVE_STREAMING_PREV_STATUS =
"live_streaming_prev_status";
public static final String EVENT_PARAM_LIVE_STREAMING_STATUS = "live_streaming_status";
public static final String EVENT_PARAM_LIVE_STREAMING_ERROR = "live_streaming_error";

/**
* Parameter key used to specify currency used with logged event. E.g. "USD", "EUR", "GBP". See
* <a href="http://en.wikipedia.org/wiki/ISO_4217">ISO-4217</a>
Expand Down
Expand Up @@ -78,24 +78,26 @@ public static void logActivateAppEvent() {
}

public static void logActivityTimeSpentEvent(String activityName, long timeSpentInSeconds) {
final Context context = FacebookSdk.getApplicationContext();
final String appId = FacebookSdk.getApplicationId();
Validate.notNull(context, "context");
final FetchedAppSettings settings = FetchedAppSettingsManager.queryAppSettings(
appId, false);
if (settings != null && settings.getAutomaticLoggingEnabled() && timeSpentInSeconds > 0) {
AppEventsLogger appEventsLogger = AppEventsLogger.newLogger(context);
Bundle params = new Bundle(1);
params.putCharSequence(Constants.AA_TIME_SPENT_SCREEN_PARAMETER_NAME, activityName);
appEventsLogger.logEvent(
Constants.AA_TIME_SPENT_EVENT_NAME, timeSpentInSeconds, params);
final Context context = FacebookSdk.getApplicationContext();
final String appId = FacebookSdk.getApplicationId();
Validate.notNull(context, "context");
final FetchedAppSettings settings = FetchedAppSettingsManager.queryAppSettings(
appId, false);
if (settings != null
&& settings.getAutomaticLoggingEnabled()
&& timeSpentInSeconds > 0) {
AppEventsLogger appEventsLogger = AppEventsLogger.newLogger(context);
Bundle params = new Bundle(1);
params.putCharSequence(Constants.AA_TIME_SPENT_SCREEN_PARAMETER_NAME, activityName);
appEventsLogger.logEvent(
Constants.AA_TIME_SPENT_EVENT_NAME, timeSpentInSeconds, params);
}
}
}

public static boolean logInAppPurchaseEvent(
final Context context,
int resultCode,
Intent data) {
final Context context,
int resultCode,
Intent data) {

if (data == null || !isImplicitPurchaseLoggingEnabled()) {
return false;
Expand Down
Expand Up @@ -46,6 +46,7 @@ public final class FetchedAppSettings {
private String smartLoginBookmarkIconURL;
private String smartLoginMenuIconURL;
private boolean IAPAutomaticLoggingEnabled;
private String sdkUpdateMessage;

public FetchedAppSettings(boolean supportsImplicitLogging,
String nuxContent,
Expand All @@ -58,7 +59,8 @@ public FetchedAppSettings(boolean supportsImplicitLogging,
FacebookRequestErrorClassification errorClassification,
String smartLoginBookmarkIconURL,
String smartLoginMenuIconURL,
boolean IAPAutomaticLoggingEnabled
boolean IAPAutomaticLoggingEnabled,
String sdkUpdateMessage
) {
this.supportsImplicitLogging = supportsImplicitLogging;
this.nuxContent = nuxContent;
Expand All @@ -72,6 +74,7 @@ public FetchedAppSettings(boolean supportsImplicitLogging,
this.smartLoginBookmarkIconURL = smartLoginBookmarkIconURL;
this.smartLoginMenuIconURL = smartLoginMenuIconURL;
this.IAPAutomaticLoggingEnabled = IAPAutomaticLoggingEnabled;
this.sdkUpdateMessage = sdkUpdateMessage;
}

public boolean supportsImplicitLogging() {
Expand Down Expand Up @@ -117,6 +120,8 @@ public boolean getIAPAutomaticLoggingEnabled() {
return IAPAutomaticLoggingEnabled;
}

public String getSdkUpdateMessage() { return sdkUpdateMessage; }

public static class DialogFeatureConfig {
private static final String DIALOG_CONFIG_DIALOG_NAME_FEATURE_NAME_SEPARATOR = "\\|";
private static final String DIALOG_CONFIG_NAME_KEY = "name";
Expand Down
Expand Up @@ -25,16 +25,20 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.appevents.internal.AutomaticAnalyticsLogger;
import com.facebook.appevents.internal.Constants;
import com.facebook.core.BuildConfig;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -72,6 +76,7 @@ public final class FetchedAppSettingsManager {
"seamless_login";
private static final String SMART_LOGIN_BOOKMARK_ICON_URL = "smart_login_bookmark_icon_url";
private static final String SMART_LOGIN_MENU_ICON_URL = "smart_login_menu_icon_url";
private static final String SDK_UPDATE_MESSAGE = "sdk_update_message";

private static final String[] APP_SETTING_FIELDS = new String[]{
APP_SETTING_SUPPORTS_IMPLICIT_SDK_LOGGING,
Expand All @@ -84,14 +89,16 @@ public final class FetchedAppSettingsManager {
APP_SETTING_APP_EVENTS_FEATURE_BITMASK,
APP_SETTING_SMART_LOGIN_OPTIONS,
SMART_LOGIN_BOOKMARK_ICON_URL,
SMART_LOGIN_MENU_ICON_URL,
SMART_LOGIN_MENU_ICON_URL
};
private static final String APPLICATION_FIELDS = "fields";

private static Map<String, FetchedAppSettings> fetchedAppSettings =
new ConcurrentHashMap<String, FetchedAppSettings>();
private static AtomicBoolean loadingSettings = new AtomicBoolean(false);

private static boolean printedSDKUpdatedMessage = false;

public static void loadAppSettingsAsync() {
final Context context = FacebookSdk.getApplicationContext();
final String applicationId = FacebookSdk.getApplicationId();
Expand All @@ -112,6 +119,7 @@ public void run() {
APP_SETTINGS_PREFS_STORE,
Context.MODE_PRIVATE);
String settingsJSONString = sharedPrefs.getString(settingsKey, null);
FetchedAppSettings appSettings = null;
if (!Utility.isNullOrEmpty(settingsJSONString)) {
JSONObject settingsJSON = null;
try {
Expand All @@ -120,7 +128,7 @@ public void run() {
Utility.logd(Utility.LOG_TAG, je);
}
if (settingsJSON != null) {
parseAppSettingsFromJSON(applicationId, settingsJSON);
appSettings = parseAppSettingsFromJSON(applicationId, settingsJSON);
}
}

Expand All @@ -133,6 +141,17 @@ public void run() {
.apply();
}

// Print log to notify developers to upgrade SDK when version is too old
if (appSettings != null) {
String updateMessage = appSettings.getSdkUpdateMessage();
if (!printedSDKUpdatedMessage
&& updateMessage != null
&& updateMessage.length() > 0) {
printedSDKUpdatedMessage = true;
Log.w(TAG, updateMessage);
}
}

// Start log activate & deactivate app events, in case autoLogAppEvents flag is set
AutomaticAnalyticsLogger.logActivateAppEvent();

Expand Down Expand Up @@ -197,7 +216,8 @@ private static FetchedAppSettings parseAppSettingsFromJSON(
errorClassification,
settingsJSON.optString(SMART_LOGIN_BOOKMARK_ICON_URL),
settingsJSON.optString(SMART_LOGIN_MENU_ICON_URL),
inAppPurchaseAutomaticLoggingEnabled
inAppPurchaseAutomaticLoggingEnabled,
settingsJSON.optString(SDK_UPDATE_MESSAGE)
);

fetchedAppSettings.put(applicationId, result);
Expand All @@ -209,7 +229,13 @@ private static FetchedAppSettings parseAppSettingsFromJSON(
// main thread.
private static JSONObject getAppSettingsQueryResponse(String applicationId) {
Bundle appSettingsParams = new Bundle();
appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));
ArrayList<String> appSettingFields = new ArrayList<>(Arrays.asList(APP_SETTING_FIELDS));

if (BuildConfig.DEBUG) {
appSettingFields.add(SDK_UPDATE_MESSAGE);
}

appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", appSettingFields));

GraphRequest request = GraphRequest.newGraphPathRequest(null, applicationId, null);
request.setSkipClientToken(true);
Expand Down
3 changes: 2 additions & 1 deletion samples/LoginSample/build.gradle
Expand Up @@ -14,11 +14,12 @@ android {

buildTypes {
debug {
minifyEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions samples/RPSSample/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
#Wed Feb 21 15:51:04 PST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2 changes: 1 addition & 1 deletion settings.gradle
@@ -1,7 +1,7 @@
// Facebook SDK
include ':facebook-core'
include ':facebook-common', ':facebook-login', ':facebook-share', ':facebook-places', ':facebook-applinks', ':facebook-messenger'

include ':facebook-loginkit'

include ':facebook'

Expand Down

0 comments on commit cf963f5

Please sign in to comment.