Initial Android SDK API skeleton

Summary:
This proposes an API skeleton for the Android SDK with similar capabilities
to the iOS SDK.

Caveats:
- This does not include test session support.
- The controls do not expose sub-controls yet.
- ISSUE markers scattered throughout.

Test Plan: Build at command-line and in Eclipse.

Reviewers: clang, jacl, joeb

CC: gregschechte, platform-diffs@lists

Differential Revision: https://phabricator.fb.com/D480561

Revert Plan: Safe to revert.

Task ID: 1073053
adding an empty string to bundle if no parameter value is given

Summary:
query strings like this "a=b&c" did not get parsed correctly.  the c would get dropped as
a parameter.  we will now add it to the bundle with an empty string as it's value

Test Plan:
build
Upload an image in hackbook?

any pointers?

Reviewers: mmarucheck

Reviewed By: mmarucheck

CC: zli

Differential Revision: https://phabricator.fb.com/D488937

Task ID: 686555
Adds a trivial unit test to Android SDK

Summary:
Initial step to get unit tests going before we implement
stuff so we can verify as we go.

Test Plan:
- cd facebook/tests
- ant all clean debug install run-tests

Revert Plan:
safe to revert

Reviewers: clang, jacl, joeb

Reviewed By: jacl

Differential Revision: https://phabricator.fb.com/D495804
Disable password saving in FbDialog

Summary:
By default, Android WebViews store passwords in a per-application
sqlite database.  This changes the default for the Facebook SDK.

Test Plan:
- Build from command-line.
- Uninstall Facebook app, run Hackbook, log in, adb shell, inspect
  webview database to verify no password was saved.

Revert Plan: OK

Reviewers: clang, jacl, vijaye

Reviewed By: vijaye

Differential Revision: https://phabricator.fb.com/D497389

Task ID: 1108189
[android-sdk] Fix directory structure so JUnit tests run in Eclipse IDE.

Summary:
Running the unit tests in Eclipse IDE works if you add the facebook/tests project as a separate Android project in your
workspace. However, it requires that the directory structure the unit tests live in matches their Java namespace
of com.facebook.sdk.tests.

Test Plan:
- Ran unit tests via Ant
- Ran unit tests in IDE

Revert Plan:

Reviewers: mmarucheck, jacl

Reviewed By: mmarucheck

Differential Revision: https://phabricator.fb.com/D499107
[android-sdk] Rudimentary functionality on Request.

Summary:
This commit adds some functionality around creating Requests, setting properties, and beginning to handle
serialization of requests (or batches of requests) into HTTP requests. It stops short of creating actual HTTP stack
objects, as mmarucheck and I uncovered information that may lead us to change our choice of HTTP stack.
Want to get this committed, even though it is still very rudimentary, in order to isolate it from changes
that are likely coming next related to the HTTP stack change.

Test Plan:
- Ran unit tests

Revert Plan:

Reviewers: mmarucheck, jacl, gregschechte, ayden

Reviewed By: mmarucheck

Differential Revision: https://phabricator.fb.com/D500176
[android-sdk] Fix up test app package name in order to add INTERNET permission to tests.

Summary:
We need to add the INTERNET permission so unit tests can access the Internet. The package name for the test app
needs to match what the unit tests are configured to look for.

Test Plan:
- Can run unit tests that hit the Internet

Revert Plan:

Reviewers: mmarucheck

Reviewed By: mmarucheck

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D501302
[android-sdk] Adds basic single-request logic to Request/Response classes.

Summary:
This commit changes our HTTP stack from the Apache HttpClient stack to the HttpURLConnection stack, which
the Android development team has suggested is the stack to use going forward. Basic functionality for single (i.e.,
non-batched) requests is functional, with many caveats. There is no (de-)serialization of GraphObjects as of yet, so most
requests to Graph API will not result in a Response that is useful for anything (though the debugger can be used to
verify that JSONObjects in the right shape are being created). There is no support for requests that return JSONArrays
rather than JSONObjects. There are a million "TODO port:" comments indicating where functional parity with iOS is still
lacking.

Test Plan:
- Ran unit tests

Revert Plan:

Reviewers: mmarucheck, jacl, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D501547
Implement Session

Summary:
Initial implementation of Session in Facebook SDK for Android.
This includes:
- SSO login
- Dialog login
- JustLoginSample
- Unit tests for AccessToken

Test Plan:
- Run unit tests
- Run JustLoginSample without FB4A
- Run JustLoginSample with FB4A

Revert Plan:
OK

Reviewers: clang, jacl

Reviewed By: clang

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D501918

Task ID: 1138263
[android-sdk] Add batch support to Request/Response classes, and GraphObjectWrapper.

Summary:
Two pieces of functionality in this commit:

- Request/Response now have support for batched queries. Many TODOs still remain in order to provide parity
with iOS.

- GraphObjectWrapper is implemented, which uses Java dynamic proxies to provide implementations for
getters/setters on GraphObject-derived classes. Responses will now deserialize JSON into GraphObjects. No
serialization is done yet for posting GraphObjects.

Test Plan:
- Ran unit tests

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@, platform-diffs@lists, security-diffs@lists

Differential Revision: https://phabricator.fb.com/D507975

Task ID: 1137468
[android-sdk] Added support for collections in GraphObject wrapper.

Summary:
Added basic support for properties that get/set collections on a GraphObject.
Collections of primitive types and GraphObjects are supported. A GraphObjectCollection
class provides additional functionality beyond a Collection, including casting the
entire collection to a GraphObjectCollection of another GraphObject type. (Casting
collections of non-GraphObjects is not supported, as we don't proxy non-GraphObjects.)

TODOs remain around fully supporting putting collections, as we need to ensure that
we are storing the underlying JSONArray, if applicable.

Test Plan:
- Ran unit tests

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@, platform-diffs@lists

Differential Revision: https://phabricator.fb.com/D510578
Implemented file-based cache for Android SDK

Summary:
This implements a thread-safe cache for the Android SDK.  It
supports the following features:
- Read/write/clear
- Writes are supported both directly (create an OutputStream
  and write to it) and indirectly (clone an InputStream from
  some other source).
- Quotas based on file count and total byte count.
- Quota enforced in LRU order where both reads and writes
  update the timestamp.
- Multiple instances with separate quotas.
- The implementation is thread-safe--all public methods can be
  safely called from multiple threads without synchronization.
- Only File-based operations are needed--there is no sqlite
  dependency.

Test Plan:
new unit tests

Revert Plan: OK

Reviewers: clang, jacl

Reviewed By: clang

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D512569

Task ID: 1168131
[android-sdk] Added TestSession, FacebookTestCase, TestBlocker.

Summary:
This commit adds a TestSession class, which serves much the same purpose as the FBTestSession class in
the iOS SDK. It allows test accounts to be created in either a shared or private mode. In shared mode,
the permissions of the test account are encoded as part of its name, so future test cases can re-use
the same test account rather than create a new one. In private mode, a test account is created with the
necessary permissions and then deleted at the end of the session, to avoid proliferation of test accounts.
(The encoding of permissions is done using the String.hash method, which will be different than the encoding
used on iOS, so test accounts will not be shared between the two platforms at the moment, and there is a very
small possibility of hash code collisions that could result in permissions-related errors. The possibility is
pretty remote.)

Added a FacebookTestCase that simplifies use of TestSession by reading in applicationId and applicationSecret
from a config.json file that is created by the new configure_unit_tests.sh script, similar to what we did
for iOS.

TestBlocker provides message-pumping-and-waiting functionality similar to FBTestBlocker. Given the synchronous
nature of calls on Android, TestBlocker will not be needed as frequently as on iOS, but it is needed to test
session authorization, which happens asynchronously, as well as obviously any asynchronous-specific test cases.

Made necessary changes to some classes (AccessToken, Session) to make certain members have default visibility
rather than private, in order to let TestSession override functionality it needed to. Session can now take a
handler passed in from outside rather than using its own, which is necessary to correctly pump messages through
the TestBlocker's handler in test cases.

Fixed up some code in Response that was incorrectly handling Facebook returning naked 'true' or 'false' responses.

Test Plan:
- Ran all unit tests

Revert Plan:

Reviewers: mmarucheck, jacl, ayden, gregschechte

Reviewed By: mmarucheck

CC: msdkexp@, security-diffs@lists

Differential Revision: https://phabricator.fb.com/D514919
[ios-sdk] Added Logger class, fixed bugs in Request, unit test cleanup

Summary:
Added a Logger class, analogous to FBLogger in the iOS SDK. The logger uses the underlying Log infrastructure
for logging, but checks the logging behavior flags in Settings to determine what to log. It also supports
replacement of access tokens in generated logs.

Added request/response logging.

Request was not setting access tokens correctly for non-batched requests.

Annotated all unit tests with @Small/Medium/LargeTest to help developers create debug configurations for different
purposes (e.g., run Small/Medium as part of a TDD flow and Large only as integration/checkin tests).

Refined TestBlocker to remove the need to call reset() between uses.

Added machineUniqueUserTag to TestSession for parity with iOS SDK.

Test Plan:
- Ran unit tests

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: jacl

CC: msdkexp@, platform-diffs@lists

Differential Revision: https://phabricator.fb.com/D518850
[android-sdk] When putting wrapped GraphObjects, store their underlying JSON representation.

Summary:
To improve serialization support, when a GraphObject or GraphObjectList is being stored in another
GraphObject or GraphObjectList, we really want to store the underlying JSONObject or JSONArray.

Test Plan:
- Ran unit tests

Revert Plan:

Reviewers: mmarucheck, jacl, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@, platform-diffs@lists, security-diffs@lists

Differential Revision: https://phabricator.fb.com/D528051
[android-sdk] Serialize graph objects in requests.

Summary:
Implements another TODO, serializing graph objects in the correct format for POST requests. Both
single and batch representations are implemented.

Test Plan:
- Ran new unit tests

Revert Plan:

Reviewers: mmarucheck, jacl, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D529770
[android-sdk] Added more batch request tests, fixed some errors.

Summary:
Added more batch request unit tests, to bring us to parity with iOS.

Fixed an error in TestSession related to signed int handling.

Fixed an error in Response in dealing with results that are JSONObject.NULL.

Fixed an error in Request where we were serializing access_token parameters twice. Reordered serialization
of common parameters to be the same as in iOS (to simplify comparing URLs generated by the two different SDKs).

Added some helpers to FacebookTestCase and refactored some of the unit test code to increase sharing.

Test Plan:
- Ran all the tests

Revert Plan:

Reviewers: mmarucheck, jacl, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D531647
[android-sdk] Added support for REST requests and multiple results in Response.

Summary:
REST API support was another TODO for iOS parity. Added it.

Since REST APIs can return multiple results as a JSON array, rather than a JSON object with an
array-valued property, we need to support that. Added a getGraphObjectList accessor to Response.
A response can have either a GraphObject or a GraphObjectList, but not both.

Test Plan:
- Ran the tests

Revert Plan:

Reviewers: mmarucheck, jacl, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@, security-diffs@lists

Differential Revision: https://phabricator.fb.com/D531849
Integrate Session with the Facebook class

Summary:
This changes the Facebook class to use the new Session.  The result
is that Hackbook works correctly with SSO or non-SSO using the
Session object to log in.

Test Plan:
- Run unit tests.
- Run Hackbook with/without Facebook native app installed

Revert Plan:safe

Tags:

Reviewers: clang, jacl

Reviewed By: clang

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D531794

Task ID: 1168392
Add Attribution Id Query

Summary: Added api support for quering FB4A's Attribution Id content provider. By calling getAttributionId(), 3rd party app will be able to get a fresh attribution Id from FB4A's content provider.

Test Plan: Test with a 3rd party app that does not have the same signature as FB4A.

Reviewers: mmarucheck, jacl, clang

Reviewed By: mmarucheck

CC: teck, vijaye

Differential Revision: https://phabricator.fb.com/D528070

Task ID: 1142563