Commit 9b4367a9 authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

Add autotest private API to set ARC touch mode

This change adds an extension API to set touch mode in ARC, which will
be used in tast test.

Bug: b:147116837
Test: tast run DUT arc.Accessibility* (crrev/c/1999865)
Change-Id: I4bfdc11c5fec41e45207ceeffa0be0c985b172c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1997436
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732244}
parent f7e9505f
......@@ -3921,6 +3921,28 @@ void AutotestPrivateStopTracingFunction::OnTracingComplete(
base::Value value(*trace.get());
Respond(OneArgument(base::Value::ToUniquePtrValue(std::move(value))));
}
///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateSetArcTouchModeFunction
///////////////////////////////////////////////////////////////////////////////
AutotestPrivateSetArcTouchModeFunction::
AutotestPrivateSetArcTouchModeFunction() = default;
AutotestPrivateSetArcTouchModeFunction::
~AutotestPrivateSetArcTouchModeFunction() = default;
ExtensionFunction::ResponseAction
AutotestPrivateSetArcTouchModeFunction::Run() {
std::unique_ptr<api::autotest_private::SetArcTouchMode::Params> params(
api::autotest_private::SetArcTouchMode::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
DVLOG(1) << "AutotestPrivateSetArcTouchModeFunction " << params->enabled;
if (!arc::SetTouchMode(params->enabled))
return RespondNow(Error("Could not send intent to ARC."));
return RespondNow(NoArguments());
}
///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateAPI
///////////////////////////////////////////////////////////////////////////////
......
......@@ -1137,6 +1137,17 @@ class AutotestPrivateStopTracingFunction : public ExtensionFunction {
void OnTracingComplete(std::unique_ptr<std::string> trace);
};
class AutotestPrivateSetArcTouchModeFunction : public ExtensionFunction {
public:
AutotestPrivateSetArcTouchModeFunction();
DECLARE_EXTENSION_FUNCTION("autotestPrivate.setArcTouchMode",
AUTOTESTPRIVATE_SETARCTOUCHMODE)
private:
~AutotestPrivateSetArcTouchModeFunction() override;
ResponseAction Run() override;
};
template <>
KeyedService*
BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor(
......
......@@ -152,18 +152,8 @@ bool Launch(content::BrowserContext* context,
return false;
}
arc::mojom::IntentHelperInstance* intent_helper_instance =
GET_INTENT_HELPER_INSTANCE(SendBroadcast);
if (intent_helper_instance && IsMouseOrTouchEventFromFlags(event_flags)) {
base::DictionaryValue extras;
extras.SetBoolean("inTouchMode", IsMouseOrTouchEventFromFlags(event_flags));
std::string extras_string;
base::JSONWriter::Write(extras, &extras_string);
intent_helper_instance->SendBroadcast(
kSetInTouchModeIntent,
ArcIntentHelperBridge::kArcIntentHelperPackageName,
kIntentHelperClassName, extras_string);
}
if (IsMouseOrTouchEventFromFlags(event_flags))
SetTouchMode(IsMouseOrTouchEventFromFlags(event_flags));
// Unthrottle the ARC instance before launching an ARC app. This is done
// to minimize lag on an app launch.
......@@ -438,6 +428,23 @@ void CloseTask(int task_id) {
app_instance->CloseTask(task_id);
}
bool SetTouchMode(bool enable) {
arc::mojom::IntentHelperInstance* intent_helper_instance =
GET_INTENT_HELPER_INSTANCE(SendBroadcast);
if (!intent_helper_instance)
return false;
base::DictionaryValue extras;
extras.SetBoolean("inTouchMode", enable);
std::string extras_string;
base::JSONWriter::Write(extras, &extras_string);
intent_helper_instance->SendBroadcast(
kSetInTouchModeIntent, ArcIntentHelperBridge::kArcIntentHelperPackageName,
kIntentHelperClassName, extras_string);
return true;
}
std::vector<std::string> GetSelectedPackagesFromPrefs(
content::BrowserContext* context) {
std::vector<std::string> packages;
......
......@@ -148,6 +148,9 @@ void SetTaskActive(int task_id);
// Closes the task.
void CloseTask(int task_id);
// Sets TouchMode in Android. Returns true if the intent was sent.
bool SetTouchMode(bool enable);
// Gets user selected package names.
std::vector<std::string> GetSelectedPackagesFromPrefs(
content::BrowserContext* context);
......
......@@ -897,6 +897,10 @@ namespace autotestPrivate {
// parameter.
static void stopTracing(TraceCompleteCallback completeCallback);
// Sends ARC touch mode enabled or disabled.
// |enable|: whether enabled touch mode.
// |callback|: called when action performed.
static void setArcTouchMode(boolean enabled, VoidCallback callback);
};
interface Events {
......
......@@ -1494,6 +1494,7 @@ enum HistogramValue {
AUTOTESTPRIVATE_STOPTRACING = 1431,
LOGIN_LOCKMANAGEDGUESTSESSION = 1432,
LOGIN_UNLOCKMANAGEDGUESTSESSION = 1433,
AUTOTESTPRIVATE_SETARCTOUCHMODE = 1434,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -21755,6 +21755,7 @@ to ensure that the crash string is shown properly on the user-facing crash UI.
<int value="1431" label="AUTOTESTPRIVATE_STOPTRACING"/>
<int value="1432" label="LOGIN_LOCKMANAGEDGUESTSESSION"/>
<int value="1433" label="LOGIN_UNLOCKMANAGEDGUESTSESSION"/>
<int value="1434" label="AUTOTESTPRIVATE_SETARCTOUCHMODE"/>
</enum>
<enum name="ExtensionIconState">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment