Allow string type when fabricating FRROs
This includes all of the work of passing the string all the way down to
the native code but then does nothing with it. Storing and retrieving of
it will be in follow up changes.
Test: Manual
Bug: 232940948
Change-Id: Ie00cc23680a0132588744991bf829afad6ba336f
diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp
index 1b2d905..073d987 100644
--- a/cmds/idmap2/idmap2d/Idmap2Service.cpp
+++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp
@@ -234,7 +234,11 @@
}
for (const auto& res : overlay.entries) {
- builder.SetResourceValue(res.resourceName, res.dataType, res.data);
+ if (res.dataType == Res_value::TYPE_STRING) {
+ builder.SetResourceValue(res.resourceName, res.dataType, res.stringData.value());
+ } else {
+ builder.SetResourceValue(res.resourceName, res.dataType, res.data);
+ }
}
// Generate the file path of the fabricated overlay and ensure it does not collide with an
diff --git a/cmds/idmap2/idmap2d/aidl/core/android/os/FabricatedOverlayInternalEntry.aidl b/cmds/idmap2/idmap2d/aidl/core/android/os/FabricatedOverlayInternalEntry.aidl
index 6c2af27..a6824da 100644
--- a/cmds/idmap2/idmap2d/aidl/core/android/os/FabricatedOverlayInternalEntry.aidl
+++ b/cmds/idmap2/idmap2d/aidl/core/android/os/FabricatedOverlayInternalEntry.aidl
@@ -23,4 +23,5 @@
@utf8InCpp String resourceName;
int dataType;
int data;
+ @nullable @utf8InCpp String stringData;
}
\ No newline at end of file
diff --git a/cmds/idmap2/include/idmap2/FabricatedOverlay.h b/cmds/idmap2/include/idmap2/FabricatedOverlay.h
index 3756718..65916d7 100644
--- a/cmds/idmap2/include/idmap2/FabricatedOverlay.h
+++ b/cmds/idmap2/include/idmap2/FabricatedOverlay.h
@@ -41,6 +41,9 @@
Builder& SetResourceValue(const std::string& resource_name, uint8_t data_type,
uint32_t data_value);
+ Builder& SetResourceValue(const std::string& resource_name, uint8_t data_type,
+ const std::string& data_string_value);
+
WARN_UNUSED Result<FabricatedOverlay> Build();
private:
@@ -48,6 +51,7 @@
std::string resource_name;
DataType data_type;
DataValue data_value;
+ std::string data_string_value;
};
std::string package_name_;
diff --git a/cmds/idmap2/include/idmap2/ResourceUtils.h b/cmds/idmap2/include/idmap2/ResourceUtils.h
index a0202df..414aa06 100644
--- a/cmds/idmap2/include/idmap2/ResourceUtils.h
+++ b/cmds/idmap2/include/idmap2/ResourceUtils.h
@@ -40,6 +40,7 @@
struct TargetValue {
DataType data_type;
DataValue data_value;
+ std::string data_string_value;
};
namespace utils {
diff --git a/cmds/idmap2/libidmap2/FabricatedOverlay.cpp b/cmds/idmap2/libidmap2/FabricatedOverlay.cpp
index 8352dbb..4d49674 100644
--- a/cmds/idmap2/libidmap2/FabricatedOverlay.cpp
+++ b/cmds/idmap2/libidmap2/FabricatedOverlay.cpp
@@ -65,7 +65,13 @@
FabricatedOverlay::Builder& FabricatedOverlay::Builder::SetResourceValue(
const std::string& resource_name, uint8_t data_type, uint32_t data_value) {
- entries_.emplace_back(Entry{resource_name, data_type, data_value});
+ entries_.emplace_back(Entry{resource_name, data_type, data_value, ""});
+ return *this;
+}
+
+FabricatedOverlay::Builder& FabricatedOverlay::Builder::SetResourceValue(
+ const std::string& resource_name, uint8_t data_type, const std::string& data_string_value) {
+ entries_.emplace_back(Entry{resource_name, data_type, 0, data_string_value});
return *this;
}
@@ -111,7 +117,8 @@
entry = type->second.insert(std::make_pair(entry_name.to_string(), TargetValue())).first;
}
- entry->second = TargetValue{res_entry.data_type, res_entry.data_value};
+ entry->second = TargetValue{
+ res_entry.data_type, res_entry.data_value, res_entry.data_string_value};
}
pb::FabricatedOverlay overlay_pb;
diff --git a/core/java/android/content/om/FabricatedOverlay.java b/core/java/android/content/om/FabricatedOverlay.java
index d62b47b..5efc1f9 100644
--- a/core/java/android/content/om/FabricatedOverlay.java
+++ b/core/java/android/content/om/FabricatedOverlay.java
@@ -88,7 +88,7 @@
}
/**
- * Sets the value of
+ * Sets the value of the fabricated overlay
*
* @param resourceName name of the target resource to overlay (in the form
* [package]:type/entry)
@@ -106,6 +106,25 @@
return this;
}
+ /**
+ * Sets the value of the fabricated overlay
+ *
+ * @param resourceName name of the target resource to overlay (in the form
+ * [package]:type/entry)
+ * @param dataType the data type of the new value
+ * @param value the string representing the new value
+ *
+ * @see android.util.TypedValue#type
+ */
+ public Builder setResourceValue(@NonNull String resourceName, int dataType, String value) {
+ final FabricatedOverlayInternalEntry entry = new FabricatedOverlayInternalEntry();
+ entry.resourceName = resourceName;
+ entry.dataType = dataType;
+ entry.stringData = value;
+ mEntries.add(entry);
+ return this;
+ }
+
/** Builds an immutable fabricated overlay. */
public FabricatedOverlay build() {
final FabricatedOverlayInternal overlay = new FabricatedOverlayInternal();
diff --git a/services/core/java/com/android/server/om/OverlayManagerShellCommand.java b/services/core/java/com/android/server/om/OverlayManagerShellCommand.java
index bdde4f6..b05e44f 100644
--- a/services/core/java/com/android/server/om/OverlayManagerShellCommand.java
+++ b/services/core/java/com/android/server/om/OverlayManagerShellCommand.java
@@ -62,7 +62,8 @@
private final Context mContext;
private final IOverlayManager mInterface;
private static final Map<String, Integer> TYPE_MAP = Map.of(
- "color", TypedValue.TYPE_FIRST_COLOR_INT);
+ "color", TypedValue.TYPE_FIRST_COLOR_INT,
+ "string", TypedValue.TYPE_STRING);
OverlayManagerShellCommand(@NonNull final Context ctx, @NonNull final IOverlayManager iom) {
mContext = ctx;
@@ -390,13 +391,17 @@
type = Integer.parseUnsignedInt(typeString);
}
}
- final int intData;
- if (valueString.startsWith("0x")) {
- intData = Integer.parseUnsignedInt(valueString.substring(2), 16);
+ if (type == TypedValue.TYPE_STRING) {
+ overlayBuilder.setResourceValue(resourceName, type, valueString);
} else {
- intData = Integer.parseUnsignedInt(valueString);
+ final int intData;
+ if (valueString.startsWith("0x")) {
+ intData = Integer.parseUnsignedInt(valueString.substring(2), 16);
+ } else {
+ intData = Integer.parseUnsignedInt(valueString);
+ }
+ overlayBuilder.setResourceValue(resourceName, type, intData);
}
- overlayBuilder.setResourceValue(resourceName, type, intData);
}
private int runEnableExclusive() throws RemoteException {