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
This commit is contained in:
Jeremy Meyer
2022-06-02 21:31:15 +00:00
parent d43e0f25eb
commit 05466592a3
7 changed files with 51 additions and 10 deletions

View File

@@ -234,7 +234,11 @@ Status Idmap2Service::createFabricatedOverlay(
}
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

View File

@@ -23,4 +23,5 @@ parcelable FabricatedOverlayInternalEntry {
@utf8InCpp String resourceName;
int dataType;
int data;
@nullable @utf8InCpp String stringData;
}

View File

@@ -41,6 +41,9 @@ struct FabricatedOverlay {
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 @@ struct FabricatedOverlay {
std::string resource_name;
DataType data_type;
DataValue data_value;
std::string data_string_value;
};
std::string package_name_;

View File

@@ -40,6 +40,7 @@ using DataValue = uint32_t; // Res_value::data
struct TargetValue {
DataType data_type;
DataValue data_value;
std::string data_string_value;
};
namespace utils {

View File

@@ -65,7 +65,13 @@ FabricatedOverlay::Builder& FabricatedOverlay::Builder::SetOverlayable(const std
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 @@ Result<FabricatedOverlay> FabricatedOverlay::Builder::Build() {
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;

View File

@@ -88,7 +88,7 @@ public class FabricatedOverlay {
}
/**
* 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 @@ public class FabricatedOverlay {
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();

View File

@@ -62,7 +62,8 @@ final class OverlayManagerShellCommand extends ShellCommand {
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 @@ final class OverlayManagerShellCommand extends ShellCommand {
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 {