Add option to look at main app for Partner resources

Change-Id: I452318d8c6d25a3cb8827f1ad81586535a75a697
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
index e87d998..bd8ba66 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
@@ -112,6 +112,8 @@
 
   private static PartnerConfigHelper instance = null;
 
+  private final Context mContext;
+
   @VisibleForTesting Bundle resultBundle = null;
 
   @VisibleForTesting
@@ -182,6 +184,7 @@
     getPartnerConfigBundle(context);
 
     registerContentObserver(context);
+    mContext = context;
   }
 
   /**
@@ -190,7 +193,7 @@
    * are customized by the overlay APK.
    */
   public boolean isAvailable() {
-    return resultBundle != null && !resultBundle.isEmpty();
+    return (resultBundle != null && !resultBundle.isEmpty()) || mContext != null;
   }
 
   /**
@@ -200,7 +203,17 @@
    * overlay APK.
    */
   public boolean isPartnerConfigAvailable(PartnerConfig resourceConfig) {
-    return isAvailable() && resultBundle.containsKey(resourceConfig.getResourceName());
+    if (resultBundle != null && !resultBundle.isEmpty())
+      return resultBundle.containsKey(resourceConfig.getResourceName());
+    else {
+      String resType = resourceConfig.getResourceType().name().toLowerCase();
+      if (resType.equals("dimension"))
+        resType = "dimen";
+
+      int resId = mContext.getResources().getIdentifier(resourceConfig.getResourceName(), resType,
+          mContext.getPackageName());
+      return (resId != 0);
+    }
   }
 
   /**
@@ -318,9 +331,20 @@
 
       result = resource.getString(resId);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "string",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getString(resIdApp);
+      partnerResourceCache.put(resourceConfig, result);
+    }
+
     return result;
   }
 
@@ -349,10 +373,21 @@
 
       result = resource.getStringArray(resId);
       Collections.addAll(listResult, result);
+      return listResult;
     } catch (NullPointerException exception) {
       // fall through
     }
 
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "array",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getStringArray(resIdApp);
+      Collections.addAll(listResult, result);
+      return listResult;
+    }
+
     return listResult;
   }
 
@@ -384,9 +419,20 @@
 
       result = resource.getBoolean(resId);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "bool",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getBoolean(resIdApp);
+      partnerResourceCache.put(resourceConfig, result);
+    }
+
     return result;
   }
 
@@ -433,9 +479,23 @@
       result =
           getDimensionFromTypedValue(
               context, (TypedValue) partnerResourceCache.get(resourceConfig));
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "dimen",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      TypedValue value = getTypedValueFromResource(appResource, resIdApp,
+          TypedValue.TYPE_DIMENSION);
+      partnerResourceCache.put(resourceConfig, value);
+      result =
+          getDimensionFromTypedValue(
+              context, (TypedValue) partnerResourceCache.get(resourceConfig));
+    }
     return result;
   }
 
@@ -477,9 +537,19 @@
 
       result = resource.getFraction(resId, 1, 1);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "fraction",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getFraction(resIdApp, 1, 1);
+      partnerResourceCache.put(resourceConfig, result);
+    }
     return result;
   }
 
@@ -510,9 +580,19 @@
 
       result = resource.getInteger(resId);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "integer",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getInteger(resIdApp);
+      partnerResourceCache.put(resourceConfig, result);
+    }
     return result;
   }