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 8706418..0f68645 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
@@ -130,6 +130,8 @@
 
   private static PartnerConfigHelper instance = null;
 
+  private final Context mContext;
+
   @VisibleForTesting Bundle resultBundle = null;
 
   @VisibleForTesting
@@ -211,6 +213,7 @@
     getPartnerConfigBundle(context);
 
     registerContentObserver(context);
+    mContext = context;
   }
 
   /**
@@ -219,7 +222,7 @@
    * are customized by the overlay APK.
    */
   public boolean isAvailable() {
-    return resultBundle != null && !resultBundle.isEmpty();
+    return (resultBundle != null && !resultBundle.isEmpty()) || mContext != null;
   }
 
   /**
@@ -229,7 +232,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);
+    }
   }
 
   /**
@@ -347,9 +360,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;
   }
 
@@ -378,10 +402,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;
   }
 
@@ -413,9 +448,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;
   }
 
@@ -462,9 +508,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;
   }
 
@@ -506,9 +566,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;
   }
 
@@ -539,9 +609,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;
   }