Skip to content

Commit

Permalink
Facebook Android SDK 4.17
Browse files Browse the repository at this point in the history
  • Loading branch information
David Emmel committed Oct 26, 2016
1 parent 0dc11b5 commit 8ca2341
Show file tree
Hide file tree
Showing 124 changed files with 1,630 additions and 636 deletions.
8 changes: 4 additions & 4 deletions facebook/build.gradle
Expand Up @@ -8,10 +8,10 @@ project.group = 'com.facebook.android'

dependencies {
// Facebook Dependencies
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:customtabs:23.4.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
compile 'com.android.support:customtabs:25.0.0'
compile 'com.parse.bolts:bolts-android:1.4.0'

// Unit Tests
Expand Down
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.facebook.appevents;

import android.os.Bundle;

import com.facebook.FacebookTestCase;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.TestBlocker;

public class UpdateUserPropertiesTests extends FacebookTestCase {
public void testUserUpdateProperties() throws Exception {
final TestBlocker blocker = getTestBlocker();
Bundle parameters = new Bundle();
parameters.putString("custom_value", "1");
AppEventsLogger.setUserID("1");
AppEventsLogger.updateUserProperties(
parameters,
getApplicationId(),
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (response.getError() != null) {
blocker.setException(response.getError().getException());
}

blocker.signal();
}
});

blocker.waitForSignals(1);
if (blocker.getException() != null) {
throw blocker.getException();
}
}
}
Expand Up @@ -29,8 +29,8 @@ public class UtilityTest extends FacebookTestCase {

@LargeTest
public void testFetchedAppSettingsErrorClassification() throws Exception {
Utility.FetchedAppSettings fetchedAppSettings =
Utility.queryAppSettings(getApplicationId(), false);
FetchedAppSettings fetchedAppSettings =
FetchedAppSettingsManager.queryAppSettings(getApplicationId(), false);
FacebookRequestErrorClassification errorClassification = fetchedAppSettings
.getErrorClassification();
assertNotNull(errorClassification);
Expand Down
10 changes: 7 additions & 3 deletions facebook/src/main/java/com/facebook/AccessToken.java
Expand Up @@ -23,8 +23,6 @@
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
Expand All @@ -37,7 +35,13 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* This class represents an immutable access token for using Facebook APIs. It also includes
Expand Down
6 changes: 4 additions & 2 deletions facebook/src/main/java/com/facebook/FacebookRequestError.java
Expand Up @@ -24,6 +24,8 @@
import android.os.Parcelable;

import com.facebook.internal.FacebookRequestErrorClassification;
import com.facebook.internal.FetchedAppSettings;
import com.facebook.internal.FetchedAppSettingsManager;
import com.facebook.internal.Utility;

import org.json.JSONException;
Expand Down Expand Up @@ -426,8 +428,8 @@ static FacebookRequestError checkResponseAndCreateError(

static synchronized FacebookRequestErrorClassification getErrorClassification() {
FacebookRequestErrorClassification errorClassification;
Utility.FetchedAppSettings appSettings =
Utility.getAppSettingsWithoutQuery(FacebookSdk.getApplicationId());
FetchedAppSettings appSettings =
FetchedAppSettingsManager.getAppSettingsWithoutQuery(FacebookSdk.getApplicationId());
if (appSettings == null) {
return FacebookRequestErrorClassification.getDefaultErrorClassification();
}
Expand Down
5 changes: 2 additions & 3 deletions facebook/src/main/java/com/facebook/FacebookSdk.java
Expand Up @@ -27,20 +27,19 @@
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;

import com.facebook.appevents.AppEventsLogger;
import com.facebook.internal.AppEventsLoggerUtility;
import com.facebook.internal.FetchedAppSettingsManager;
import com.facebook.internal.LockOnGetVariable;
import com.facebook.internal.BoltsMeasurementEventListener;
import com.facebook.internal.AttributionIdentifiers;
import com.facebook.internal.NativeProtocol;
import com.facebook.internal.ServerProtocol;
import com.facebook.internal.Utility;
import com.facebook.internal.Validate;
import com.facebook.internal.WebDialog;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -212,7 +211,7 @@ public static synchronized void sdkInitialize(
sdkInitialized = true;

// Load app settings from network so that dialog configs are available
Utility.loadAppSettingsAsync(FacebookSdk.applicationContext, applicationId);
FetchedAppSettingsManager.loadAppSettingsAsync(FacebookSdk.applicationContext, applicationId);
// Fetch available protocol versions from the apps on the device
NativeProtocol.updateAllAvailableProtocolVersionsAsync();

Expand Down
Expand Up @@ -21,5 +21,5 @@
package com.facebook;

final class FacebookSdkVersion {
public static final String BUILD = "4.16.1";
public static final String BUILD = "4.17.0";
}
3 changes: 1 addition & 2 deletions facebook/src/main/java/com/facebook/GraphResponse.java
Expand Up @@ -359,8 +359,7 @@ private static List<GraphResponse> createResponsesFromObject(
}

if (!(object instanceof JSONArray) || ((JSONArray) object).length() != numRequests) {
FacebookException exception = new FacebookException("Unexpected number of results");
throw exception;
throw new FacebookException("Unexpected number of results");
}

JSONArray jsonArray = (JSONArray) object;
Expand Down
1 change: 0 additions & 1 deletion facebook/src/main/java/com/facebook/Profile.java
Expand Up @@ -21,7 +21,6 @@
package com.facebook;

import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
Expand Down
@@ -0,0 +1,113 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Facebook.
*
* As with any software that integrates with the Facebook platform, your use of
* this software is subject to the Facebook Developer Principles and Policies
* [http://developers.facebook.com/policy/]. This copyright notice shall be
* included in all copies or substantial portions of the software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.facebook.appevents;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import com.facebook.FacebookSdk;
import com.facebook.appevents.internal.AppEventUtility;

import java.util.concurrent.locks.ReentrantReadWriteLock;

class AnalyticsUserIDStore {
private static final String TAG = AnalyticsUserIDStore.class.getSimpleName();
private static final String ANALYTICS_USER_ID_KEY =
"com.facebook.appevents.AnalyticsUserIDStore.userID";

private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private static String userID;
private static volatile boolean initialized = false;

public static void initStore() {
if (initialized) {
return;
}

AppEventsLogger.getAnalyticsExecutor().execute(new Runnable() {
@Override
public void run() {
initAndWait();
}
});
}

public static void setUserID(final String id) {
AppEventUtility.assertIsNotMainThread();
if (!initialized) {
Log.w(TAG, "initStore should have been called before calling setUserID");
initAndWait();
}

AppEventsLogger.getAnalyticsExecutor().execute(new Runnable() {
@Override
public void run() {
lock.writeLock().lock();
try {
userID = id;
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(
FacebookSdk.getApplicationContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(ANALYTICS_USER_ID_KEY, userID);
editor.apply();
} finally {
lock.writeLock().unlock();
}
}
});
}

public static String getUserID() {
if (!initialized) {
Log.w(TAG, "initStore should have been called before calling setUserID");
initAndWait();
}

lock.readLock().lock();
try {
return userID;
} finally {
lock.readLock().unlock();
}
}

private static void initAndWait() {
if (initialized) {
return;
}

lock.writeLock().lock();
try {
if (initialized) {
return;
}

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
FacebookSdk.getApplicationContext());
userID = sharedPreferences.getString(ANALYTICS_USER_ID_KEY, null);
initialized = true;
} finally {
lock.writeLock().unlock();
}
}
}
9 changes: 7 additions & 2 deletions facebook/src/main/java/com/facebook/appevents/AppEvent.java
Expand Up @@ -124,7 +124,7 @@ private static void validateIdentifier(String identifier) throws FacebookExcepti
);
}

boolean alreadyValidated = false;
boolean alreadyValidated;
synchronized (validatedIdentifiers) {
alreadyValidated = validatedIdentifiers.contains(identifier);
}
Expand Down Expand Up @@ -174,6 +174,11 @@ private static JSONObject getJSONObjectForAppEvent(
eventObject.put("_implicitlyLogged", "1");
}

String externalAnalyticsUserId = AppEventsLogger.getUserID();
if (externalAnalyticsUserId != null) {
eventObject.put("_app_user_id", externalAnalyticsUserId);
}

if (parameters != null) {
for (String key : parameters.keySet()) {

Expand Down Expand Up @@ -254,7 +259,7 @@ private String calculateChecksum() {

private static String md5Checksum(String toHash )
{
String hash = null;
String hash;
try
{
MessageDigest digest = MessageDigest.getInstance("MD5");
Expand Down
Expand Up @@ -31,14 +31,15 @@
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.LoggingBehavior;
import com.facebook.internal.FetchedAppSettings;
import com.facebook.internal.FetchedAppSettingsManager;
import com.facebook.internal.Logger;
import com.facebook.internal.Utility;

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

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -194,8 +195,8 @@ private static GraphRequest buildRequestForSession(
final FlushStatistics flushState) {
String applicationId = accessTokenAppId.getApplicationId();

Utility.FetchedAppSettings fetchedAppSettings =
Utility.queryAppSettings(applicationId, false);
FetchedAppSettings fetchedAppSettings =
FetchedAppSettingsManager.queryAppSettings(applicationId, false);

final GraphRequest postRequest = GraphRequest.newPostRequest(
null,
Expand Down
Expand Up @@ -21,15 +21,12 @@
package com.facebook.appevents;

import android.content.Context;
import android.os.Looper;
import android.util.Log;

import com.facebook.FacebookSdk;
import com.facebook.appevents.internal.AppEventUtility;
import com.facebook.internal.Utility;

import junit.framework.Assert;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
Expand All @@ -38,8 +35,6 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.util.HashMap;
import java.util.List;

class AppEventStore {
private static final String TAG = AppEventStore.class.getName();
Expand Down

0 comments on commit 8ca2341

Please sign in to comment.