Fix bug 6479405 On tablet, sometimes, QC -> full contact...

card yields in an empty details screen.

In the old code, we even copied the requested URI, which caused the issue
if the URIs for the first request and the second request are different
but still point at the same contact.  If we do this, the second result
will have a different requested URI than the actual requeseted URI,
which makes ContactLoaderFragment ignore the result.

This really happens because the lookup URI has variations.

Also make sure not to cache error results.

Bug 6479405

Change-Id: I71254578f0513b391804ee27a21a810bdb6881ac
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 5d188fb..ab2ac41 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -226,10 +226,11 @@
             mIsUserProfile = isUserProfile;
         }
 
-        private Result(Result from) {
+        private Result(Uri requestedUri, Result from) {
+            mRequestedUri = requestedUri;
+
             mStatus = from.mStatus;
             mException = from.mException;
-            mRequestedUri = from.mRequestedUri;
             mLookupUri = from.mLookupUri;
             mUri = from.mUri;
             mDirectoryId = from.mDirectoryId;
@@ -520,6 +521,12 @@
         public boolean isUserProfile() {
             return mIsUserProfile;
         }
+
+        @Override
+        public String toString() {
+            return "{requested=" + mRequestedUri + ",lookupkey=" + mLookupKey +
+                    ",uri=" + mUri + ",status=" + mStatus + "}";
+        }
     }
 
     /**
@@ -730,13 +737,13 @@
                     UriUtils.areEqual(cachedResult.getLookupUri(), mLookupUri)) {
                 // We are using a cached result from earlier. Below, we should make sure
                 // we are not doing any more network or disc accesses
-                result = cachedResult;
+                result = new Result(mRequestedUri, cachedResult);
                 resultIsCached = true;
             } else {
                 result = loadContactEntity(resolver, uriCurrentFormat);
                 resultIsCached = false;
             }
-            if (!result.isNotFound()) {
+            if (result.isLoaded()) {
                 if (result.isDirectoryEntry()) {
                     if (!resultIsCached) {
                         loadDirectoryMetaData(result);
@@ -1345,10 +1352,10 @@
      * contact. If the next load is for a different contact, the cached result will be dropped
      */
     public void cacheResult() {
-        if (mContact == null) {
+        if (mContact == null || !mContact.isLoaded()) {
             sCachedResult = null;
         } else {
-            sCachedResult = new Result(mContact);
+            sCachedResult = mContact;
         }
     }
 }