summaryrefslogtreecommitdiff
path: root/partnerconfig
diff options
context:
space:
mode:
Diffstat (limited to 'partnerconfig')
-rw-r--r--partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java52
-rw-r--r--partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java151
-rw-r--r--partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java52
-rw-r--r--partnerconfig/java/com/google/android/setupcompat/partnerconfig/ResourceEntry.java73
4 files changed, 270 insertions, 58 deletions
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java
index 73d66e6..56256c9 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfig.java
@@ -93,6 +93,14 @@ public enum PartnerConfig {
CONFIG_FOOTER_BUTTON_TEXT_SIZE(
PartnerConfigKey.KEY_FOOTER_BUTTON_TEXT_SIZE, ResourceType.DIMENSION),
+ // Disabled background alpha of the footer buttons
+ CONFIG_FOOTER_BUTTON_DISABLED_ALPHA(
+ PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_ALPHA, ResourceType.FRACTION),
+
+ // Disabled background color of the footer buttons
+ CONFIG_FOOTER_BUTTON_DISABLED_BG_COLOR(
+ PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_BG_COLOR, ResourceType.COLOR),
+
// Background color of the primary footer button
CONFIG_FOOTER_PRIMARY_BUTTON_BG_COLOR(
PartnerConfigKey.KEY_FOOTER_PRIMARY_BUTTON_BG_COLOR, ResourceType.COLOR),
@@ -139,15 +147,55 @@ public enum PartnerConfig {
PartnerConfigKey.KEY_DESCRIPTION_LINK_TEXT_COLOR, ResourceType.COLOR),
// Font family of the description
- CONFIG_DESCRIPTION_FONT_FAMILY(PartnerConfigKey.KEY_DESCRIPTION_FONT_FAMILY, ResourceType.STRING);
+ CONFIG_DESCRIPTION_FONT_FAMILY(PartnerConfigKey.KEY_DESCRIPTION_FONT_FAMILY, ResourceType.STRING),
+
+ // Text size of the body content text
+ CONFIG_CONTENT_TEXT_SIZE(PartnerConfigKey.KEY_CONTENT_TEXT_SIZE, ResourceType.DIMENSION),
+
+ // Text color of the body content text
+ CONFIG_CONTENT_TEXT_COLOR(PartnerConfigKey.KEY_CONTENT_TEXT_COLOR, ResourceType.COLOR),
+
+ // Link text color of the body content text
+ CONFIG_CONTENT_LINK_TEXT_COLOR(PartnerConfigKey.KEY_CONTENT_LINK_TEXT_COLOR, ResourceType.COLOR),
+
+ // Font family of the body content text
+ CONFIG_CONTENT_FONT_FAMILY(PartnerConfigKey.KEY_CONTENT_FONT_FAMILY, ResourceType.STRING),
+
+ // Gravity of the body content text
+ CONFIG_CONTENT_LAYOUT_GRAVITY(PartnerConfigKey.KEY_CONTENT_LAYOUT_GRAVITY, ResourceType.STRING),
+
+ // The animation of loading screen used in those activities which is non of below type.
+ CONFIG_PROGRESS_ILLUSTRATION_DEFAULT(
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_DEFAULT, ResourceType.ILLUSTRATION),
+
+ // The animation of loading screen used in those activity which is processing account info or
+ // related functions.
+ // For example:com.google.android.setupwizard.LOAD_ADD_ACCOUNT_INTENT
+ CONFIG_PROGRESS_ILLUSTRATION_ACCOUNT(
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_ACCOUNT, ResourceType.ILLUSTRATION),
+
+ // The animation of loading screen used in those activity which is processing data connection.
+ // For example:com.android.setupwizard.CAPTIVE_PORTAL
+ CONFIG_PROGRESS_ILLUSTRATION_CONNECTION(
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_CONNECTION, ResourceType.ILLUSTRATION),
+
+ // The animation of loading screen used in those activities which is updating device.
+ // For example:com.google.android.setupwizard.COMPAT_EARLY_UPDATE
+ CONFIG_PROGRESS_ILLUSTRATION_UPDATE(
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_UPDATE, ResourceType.ILLUSTRATION),
+
+ CONFIG_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS(
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS, ResourceType.INTEGER);
public enum ResourceType {
+ INTEGER,
BOOL,
COLOR,
DRAWABLE,
STRING,
DIMENSION,
- FRACTION;
+ FRACTION,
+ ILLUSTRATION;
}
private final String resourceName;
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
index eac403f..7b9f65b 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
@@ -18,7 +18,6 @@ package com.google.android.setupcompat.partnerconfig;
import android.content.ContentResolver;
import android.content.Context;
-import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
@@ -45,6 +44,9 @@ public class PartnerConfigHelper {
public static final String SUW_AUTHORITY = "com.google.android.setupwizard.partner";
@VisibleForTesting public static final String SUW_GET_PARTNER_CONFIG_METHOD = "getOverlayConfig";
+
+ @VisibleForTesting public static final String KEY_FALLBACK_CONFIG = "fallbackConfig";
+
private static PartnerConfigHelper instance = null;
@VisibleForTesting Bundle resultBundle = null;
@@ -92,16 +94,18 @@ public class PartnerConfigHelper {
int result = 0;
try {
- String resourceName = resourceConfig.getResourceName();
- ResourceEntry resourceEntry = getResourceEntryFromKey(resourceName);
- Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
+
if (Build.VERSION.SDK_INT >= VERSION_CODES.M) {
- result = resource.getColor(resourceEntry.getResourceId(), null);
+ result = resource.getColor(resId, null);
} else {
- result = resource.getColor(resourceEntry.getResourceId());
+ result = resource.getColor(resId);
}
partnerResourceCache.put(resourceConfig, result);
- } catch (PackageManager.NameNotFoundException | NullPointerException exception) {
+ } catch (NullPointerException exception) {
// fall through
}
return result;
@@ -127,25 +131,25 @@ public class PartnerConfigHelper {
Drawable result = null;
try {
- ResourceEntry resourceEntry = getResourceEntryFromKey(resourceConfig.getResourceName());
- Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
// for @null
TypedValue outValue = new TypedValue();
- resource.getValue(resourceEntry.getResourceId(), outValue, true);
+ resource.getValue(resId, outValue, true);
if (outValue.type == TypedValue.TYPE_REFERENCE && outValue.data == 0) {
return result;
}
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- result = resource.getDrawable(resourceEntry.getResourceId(), null);
+ result = resource.getDrawable(resId, null);
} else {
- result = resource.getDrawable(resourceEntry.getResourceId());
+ result = resource.getDrawable(resId);
}
partnerResourceCache.put(resourceConfig, result);
- } catch (PackageManager.NameNotFoundException
- | NullPointerException
- | NotFoundException exception) {
+ } catch (NullPointerException | NotFoundException exception) {
// fall through
}
return result;
@@ -171,11 +175,14 @@ public class PartnerConfigHelper {
String result = null;
try {
- ResourceEntry resourceEntry = getResourceEntryFromKey(resourceConfig.getResourceName());
- Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
- result = resource.getString(resourceEntry.getResourceId());
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
+
+ result = resource.getString(resId);
partnerResourceCache.put(resourceConfig, result);
- } catch (PackageManager.NameNotFoundException | NullPointerException exception) {
+ } catch (NullPointerException exception) {
// fall through
}
return result;
@@ -202,11 +209,14 @@ public class PartnerConfigHelper {
boolean result = defaultValue;
try {
- ResourceEntry resourceEntry = getResourceEntryFromKey(resourceConfig.getResourceName());
- Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
- result = resource.getBoolean(resourceEntry.getResourceId());
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
+
+ result = resource.getBoolean(resId);
partnerResourceCache.put(resourceConfig, result);
- } catch (PackageManager.NameNotFoundException | NullPointerException exception) {
+ } catch (NullPointerException exception) {
// fall through
}
return result;
@@ -244,17 +254,18 @@ public class PartnerConfigHelper {
float result = defaultValue;
try {
- ResourceEntry resourceEntry = getResourceEntryFromKey(resourceConfig.getResourceName());
- Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
- result = resource.getDimension(resourceEntry.getResourceId());
- TypedValue value =
- getTypedValueFromResource(
- resource, resourceEntry.getResourceId(), TypedValue.TYPE_DIMENSION);
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
+
+ result = resource.getDimension(resId);
+ TypedValue value = getTypedValueFromResource(resource, resId, TypedValue.TYPE_DIMENSION);
partnerResourceCache.put(resourceConfig, value);
result =
getDimensionFromTypedValue(
context, (TypedValue) partnerResourceCache.get(resourceConfig));
- } catch (PackageManager.NameNotFoundException | NullPointerException exception) {
+ } catch (NullPointerException exception) {
// fall through
}
return result;
@@ -291,16 +302,63 @@ public class PartnerConfigHelper {
float result = defaultValue;
try {
- ResourceEntry resourceEntry = getResourceEntryFromKey(resourceConfig.getResourceName());
- Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
- result = resource.getFraction(resourceEntry.getResourceId(), 1, 1);
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
+
+ result = resource.getFraction(resId, 1, 1);
partnerResourceCache.put(resourceConfig, result);
- } catch (PackageManager.NameNotFoundException | NullPointerException exception) {
+ } catch (NullPointerException exception) {
// fall through
}
return result;
}
+ /**
+ * Returns the {@link ResourceEntry} of given {@code resourceConfig}, or {@code null} if the given
+ * {@code resourceConfig} is not found. If the {@link ResourceType} of the given {@code
+ * resourceConfig} is not illustration, IllegalArgumentException will be thrown.
+ *
+ * @param context The context of client activity
+ * @param resourceConfig The {@link PartnerConfig} of target resource
+ */
+ @Nullable
+ public ResourceEntry getIllustrationResourceEntry(
+ @NonNull Context context, PartnerConfig resourceConfig) {
+ if (resourceConfig.getResourceType() != ResourceType.ILLUSTRATION) {
+ throw new IllegalArgumentException("Not a illustration resource");
+ }
+
+ if (partnerResourceCache.containsKey(resourceConfig)) {
+ return (ResourceEntry) partnerResourceCache.get(resourceConfig);
+ }
+
+ try {
+ ResourceEntry resourceEntry =
+ getResourceEntryFromKey(context, resourceConfig.getResourceName());
+
+ Resources resource = resourceEntry.getResources();
+ int resId = resourceEntry.getResourceId();
+
+ // TODO: The illustration resource entry validation should validate is it a video
+ // resource or not?
+ // for @null
+ TypedValue outValue = new TypedValue();
+ resource.getValue(resId, outValue, true);
+ if (outValue.type == TypedValue.TYPE_REFERENCE && outValue.data == 0) {
+ return null;
+ }
+
+ partnerResourceCache.put(resourceConfig, resourceEntry);
+ return resourceEntry;
+ } catch (NullPointerException exception) {
+ // fall through
+ }
+
+ return null;
+ }
+
private void getPartnerConfigBundle(Context context) {
if (resultBundle == null || resultBundle.isEmpty()) {
try {
@@ -316,29 +374,20 @@ public class PartnerConfigHelper {
.call(
contentUri, SUW_GET_PARTNER_CONFIG_METHOD, /* arg= */ null, /* extras= */ null);
partnerResourceCache.clear();
- } catch (IllegalArgumentException exception) {
+ } catch (IllegalArgumentException | SecurityException exception) {
Log.w(TAG, "Fail to get config from suw provider");
}
}
}
- private Resources getResourcesByPackageName(Context context, String packageName)
- throws PackageManager.NameNotFoundException {
- PackageManager manager = context.getPackageManager();
- if (Build.VERSION.SDK_INT >= VERSION_CODES.N) {
- return manager.getResourcesForApplication(
- manager.getApplicationInfo(packageName, PackageManager.MATCH_DISABLED_COMPONENTS));
- } else {
- return manager.getResourcesForApplication(
- manager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_COMPONENTS));
- }
- }
-
- private ResourceEntry getResourceEntryFromKey(String resourceName) {
- if (resultBundle == null) {
- return null;
+ @Nullable
+ private ResourceEntry getResourceEntryFromKey(Context context, String resourceName) {
+ Bundle resourceEntryBundle = resultBundle.getBundle(resourceName);
+ Bundle fallbackBundle = resultBundle.getBundle(KEY_FALLBACK_CONFIG);
+ if (fallbackBundle != null) {
+ resourceEntryBundle.putBundle(KEY_FALLBACK_CONFIG, fallbackBundle.getBundle(resourceName));
}
- return ResourceEntry.fromBundle(resultBundle.getBundle(resourceName));
+ return ResourceEntry.fromBundle(context, resourceEntryBundle);
}
@VisibleForTesting
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java
index 87f51ba..e5c5442 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigKey.java
@@ -43,6 +43,8 @@ import java.lang.annotation.RetentionPolicy;
PartnerConfigKey.KEY_FOOTER_BUTTON_RADIUS,
PartnerConfigKey.KEY_FOOTER_BUTTON_RIPPLE_ALPHA,
PartnerConfigKey.KEY_FOOTER_BUTTON_TEXT_SIZE,
+ PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_ALPHA,
+ PartnerConfigKey.KEY_FOOTER_BUTTON_DISABLED_BG_COLOR,
PartnerConfigKey.KEY_FOOTER_PRIMARY_BUTTON_BG_COLOR,
PartnerConfigKey.KEY_FOOTER_PRIMARY_BUTTON_TEXT_COLOR,
PartnerConfigKey.KEY_FOOTER_SECONDARY_BUTTON_BG_COLOR,
@@ -57,6 +59,16 @@ import java.lang.annotation.RetentionPolicy;
PartnerConfigKey.KEY_DESCRIPTION_TEXT_COLOR,
PartnerConfigKey.KEY_DESCRIPTION_LINK_TEXT_COLOR,
PartnerConfigKey.KEY_DESCRIPTION_FONT_FAMILY,
+ PartnerConfigKey.KEY_CONTENT_TEXT_SIZE,
+ PartnerConfigKey.KEY_CONTENT_TEXT_COLOR,
+ PartnerConfigKey.KEY_CONTENT_LINK_TEXT_COLOR,
+ PartnerConfigKey.KEY_CONTENT_FONT_FAMILY,
+ PartnerConfigKey.KEY_CONTENT_LAYOUT_GRAVITY,
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_DEFAULT,
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_ACCOUNT,
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_CONNECTION,
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_UPDATE,
+ PartnerConfigKey.KEY_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS,
})
// TODO: can be removed and always reference PartnerConfig.getResourceName()?
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
@@ -121,6 +133,12 @@ public @interface PartnerConfigKey {
// Text size of the footer button
String KEY_FOOTER_BUTTON_TEXT_SIZE = "setup_compat_footer_button_text_size";
+ // Disabled background alpha of the footer buttons
+ String KEY_FOOTER_BUTTON_DISABLED_ALPHA = "setup_compat_footer_button_disabled_alpha";
+
+ // Disabled background color of the footer buttons
+ String KEY_FOOTER_BUTTON_DISABLED_BG_COLOR = "setup_compat_footer_button_disabled_bg_color";
+
// Background color of the primary footer button
String KEY_FOOTER_PRIMARY_BUTTON_BG_COLOR = "setup_compat_footer_primary_button_bg_color";
@@ -162,4 +180,38 @@ public @interface PartnerConfigKey {
// Font family of the description
String KEY_DESCRIPTION_FONT_FAMILY = "setup_design_description_font_family";
+
+ // Text size of the body content text
+ String KEY_CONTENT_TEXT_SIZE = "setup_design_content_text_size";
+
+ // Text color of the body content text
+ String KEY_CONTENT_TEXT_COLOR = "setup_design_content_text_color";
+
+ // Link text color of the body content text
+ String KEY_CONTENT_LINK_TEXT_COLOR = "setup_design_content_link_text_color";
+
+ // Font family of the body content text
+ String KEY_CONTENT_FONT_FAMILY = "setup_design_content_font_family";
+
+ // Gravity of the body content text
+ String KEY_CONTENT_LAYOUT_GRAVITY = "setup_design_content_layout_gravity";
+
+ // The animation of loading screen used in those activities which is non of below type.
+ String KEY_PROGRESS_ILLUSTRATION_DEFAULT = "progress_illustration_custom_default";
+
+ // The animation of loading screen used in those activity which is processing account info or
+ // related functions.
+ // For example:com.google.android.setupwizard.LOAD_ADD_ACCOUNT_INTENT
+ String KEY_PROGRESS_ILLUSTRATION_ACCOUNT = "progress_illustration_custom_account";
+
+ // The animation of loading screen used in those activity which is processing data connection.
+ // For example:com.android.setupwizard.CAPTIVE_PORTAL
+ String KEY_PROGRESS_ILLUSTRATION_CONNECTION = "progress_illustration_custom_connection";
+
+ // The animation of loading screen used in those activities which is updating device.
+ // For example:com.google.android.setupwizard.COMPAT_EARLY_UPDATE
+ String KEY_PROGRESS_ILLUSTRATION_UPDATE = "progress_illustration_custom_update";
+
+ // The minimum illustration display time, set to 0 may cause the illustration stuck
+ String KEY_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS = "progress_illustration_display_minimum_ms";
}
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/ResourceEntry.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/ResourceEntry.java
index 2794f22..8f7c9d8 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/ResourceEntry.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/ResourceEntry.java
@@ -16,15 +16,29 @@
package com.google.android.setupcompat.partnerconfig;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
+import android.os.Build;
+import android.os.Build.VERSION_CODES;
import android.os.Bundle;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
+import android.util.Log;
/**
* A potentially cross-package resource entry, which can then be retrieved using {@link
- * PackageManager#getApplicationForResources}. This class can also be sent across to other packages
+ * PackageManager#getResourcesForApplication}. This class can also be sent across to other packages
* on IPC via the Bundle representation.
*/
public final class ResourceEntry {
+
+ private static final String TAG = ResourceEntry.class.getSimpleName();
+
+ @VisibleForTesting static final String KEY_FALLBACK_CONFIG = "fallbackConfig";
+
@VisibleForTesting static final String KEY_PACKAGE_NAME = "packageName";
@VisibleForTesting static final String KEY_RESOURCE_NAME = "resourceName";
@VisibleForTesting static final String KEY_RESOURCE_ID = "resourceId";
@@ -34,11 +48,22 @@ public final class ResourceEntry {
private final int resourceId;
/**
- * Creates a {@code ResourceEntry} object from a provided bundle.
+ * The {@link Resources} for accessing a specific package's resources. This is {@code null} only
+ * if the deprecated constructor {@link #ResourceEntry(String, String, int)} is used.
+ */
+ @Nullable private final Resources resources;
+
+ /**
+ * Creates a {@code ResourceEntry} object from a provided bundle or the fallback resource if
+ * partner resource not found and the {@code fallbackConfig} key exists in provided bundle.
+ * Returns {@code null} if fallback package is not found or the {@code bundle} doesn't contain
+ * packageName, resourceName, or resourceId.
*
+ * @param context the context need to retrieve the {@link Resources}
* @param bundle the source bundle needs to have all the information for a {@code ResourceEntry}
*/
- public static ResourceEntry fromBundle(Bundle bundle) {
+ @Nullable
+ public static ResourceEntry fromBundle(@NonNull Context context, Bundle bundle) {
String packageName;
String resourceName;
int resourceId;
@@ -50,13 +75,31 @@ public final class ResourceEntry {
packageName = bundle.getString(KEY_PACKAGE_NAME);
resourceName = bundle.getString(KEY_RESOURCE_NAME);
resourceId = bundle.getInt(KEY_RESOURCE_ID);
- return new ResourceEntry(packageName, resourceName, resourceId);
+ try {
+ return new ResourceEntry(
+ packageName, resourceName, resourceId, getResourcesByPackageName(context, packageName));
+ } catch (NameNotFoundException e) {
+ Bundle fallbackBundle = bundle.getBundle(KEY_FALLBACK_CONFIG);
+ if (fallbackBundle != null) {
+ Log.w(TAG, packageName + " not found, " + resourceName + " fallback to default value");
+ return fromBundle(context, fallbackBundle);
+ }
+ }
+ return null;
}
+ /** @deprecated Use {@link #ResourceEntry(String, String, int, Resources)} instead. */
+ @Deprecated
public ResourceEntry(String packageName, String resourceName, int resourceId) {
+ this(packageName, resourceName, resourceId, /* resources= */ null);
+ }
+
+ public ResourceEntry(
+ String packageName, String resourceName, int resourceId, @Nullable Resources resources) {
this.packageName = packageName;
this.resourceName = resourceName;
this.resourceId = resourceId;
+ this.resources = resources;
}
public String getPackageName() {
@@ -72,9 +115,17 @@ public final class ResourceEntry {
}
/**
+ * Returns a {@link Resources} for accessing specific package's resources. It will be {@code null}
+ * when the {@link #ResourceEntry(String, String, int)} is used).
+ */
+ public Resources getResources() {
+ return resources;
+ }
+
+ /**
* Returns a bundle representation of this resource entry, which can then be sent over IPC.
*
- * @see #fromBundle(Bundle)
+ * @see #fromBundle(Context, Bundle)
*/
public Bundle toBundle() {
Bundle result = new Bundle();
@@ -83,4 +134,16 @@ public final class ResourceEntry {
result.putInt(KEY_RESOURCE_ID, resourceId);
return result;
}
+
+ private static Resources getResourcesByPackageName(Context context, String packageName)
+ throws NameNotFoundException {
+ PackageManager manager = context.getPackageManager();
+ if (Build.VERSION.SDK_INT >= VERSION_CODES.N) {
+ return manager.getResourcesForApplication(
+ manager.getApplicationInfo(packageName, PackageManager.MATCH_DISABLED_COMPONENTS));
+ } else {
+ return manager.getResourcesForApplication(
+ manager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_COMPONENTS));
+ }
+ }
}