Fixed null pointer issue.

Summary:
We need to call unbindService on a Context.  In some cases, mAuthActivity
is null.  Since applicationsContext is passed in to the constructor
and never modified, it should not be null.  So we call unbindService
on applicationsContext instead.

Test Plan: Try SSO with pre-1.8 FB app.

Reviewers: vijaye, jacl, caabernathy

Reviewed By: vijaye

CC: selekman, constantin, lshepard

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

Revert Plan: Safe to revert

Task ID: 982981
Merge small pull requests

Summary:
To give credit for changes, I am listing author/pull request here
for changes incorporated in this checkin.

I am submitting these changes directly to master to preserve a
linear history, to allow for minor edits, and to credit multiple
people when more than one change was merged to fix a single issue.

=== Summary by submitter of pull requests in this commit ===
andypalmer:
- 160: ClassCastExceptions in Util.java
grant land:
- 216: Fix ArrayOutOfBoundsException when clicking "Don't Allow" in FbDialog one
iamnoah:
- 117: Fixed a NPE
lvillani:
- 261: Add support for Android build system.
nikreiman:
- 218: Fix exception when trying to decode invalid string
plowman:
- 246: Fix for Issue #160: ClassCastExceptions filling up the logs.

To investigate pull request 260, I enabled orientation changes in Hackbook.
This did not demonstrate the issue, but doesn't hurt anything and makes it
easier to test on the x86 emulator.

I also fixed some build issues in Hackbook around SDK version required and
the path to the SDK.

Test Plan:
Full clean builds of facebook and Hackbook.
Verify creating Eclipse project per public docs still works.
Upload photo in Android Hackbook.

Reviewers: caabernathy, jacl, vijaye, yariv

Reviewed By: jacl

CC: ekoneil, gregschechte

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

Revert Plan: Safe to revert

Task ID: 1028564
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