forked from facebook/facebook-android-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Emmel
committed
Oct 26, 2016
1 parent
0dc11b5
commit 8ca2341
Showing
124 changed files
with
1,630 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
facebook/src/androidTest/java/com/facebook/appevents/UpdateUserPropertiesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
facebook/src/main/java/com/facebook/appevents/AnalyticsUserIDStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.