Set focus to current active window

This commit is contained in:
Simon Fels 2016-11-26 13:04:50 +01:00
commit 84b3fa430b
15 changed files with 189 additions and 41 deletions

View file

@ -7,6 +7,7 @@ set(ANBOXD_SOURCES
${CMAKE_SOURCE_DIR}/src/anbox/rpc/message_processor.cpp
${CMAKE_SOURCE_DIR}/src/anbox/rpc/pending_call_cache.cpp
${CMAKE_SOURCE_DIR}/src/anbox/common/fd.cpp
service/activity_manager_interface.cpp
service/platform_service.cpp
service/platform_service_interface.cpp
service/platform_api_stub.cpp

View file

@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define LOG_TAG "Anboxd"
#include "android/service/activity_manager_interface.h"
namespace android {
BpActivityManager::BpActivityManager(const sp<IBinder> &binder) :
BpInterface<IActivityManager>(binder) {
}
status_t BpActivityManager::setFocusedTask(int32_t id) {
Parcel data, reply;
data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor());
data.writeInt32(id);
return remote()->transact(IActivityManager::SET_FOCUSED_TASK, data, &reply);
}
IMPLEMENT_META_INTERFACE(ActivityManager, "android.app.IActivityManager");
} // namespace android

View file

@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ANBOX_ANDROID_ACTIVITY_MANAGER_INTERFACE_H_
#define ANBOX_ANDROID_ACTIVITY_MANAGER_INTERFACE_H_
#include <binder/IBinder.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
#include <cstdint>
namespace android {
class IActivityManager : public IInterface {
public:
DECLARE_META_INTERFACE(ActivityManager);
enum {
// This needs to stay synchronized with frameworks/base/core/java/android/app/IActivityManager.java
SET_FOCUSED_TASK = IBinder::FIRST_CALL_TRANSACTION + 130,
};
virtual status_t setFocusedTask(int32_t id) = 0;
};
class BpActivityManager : public BpInterface<IActivityManager> {
public:
BpActivityManager(const sp<IBinder> &binder);
status_t setFocusedTask(int32_t id) override;
};
} // namespace android
#endif

View file

@ -15,6 +15,8 @@
*
*/
#define LOG_TAG "Anboxd"
#include "android/service/android_api_skeleton.h"
#include "anbox_rpc.pb.h"
@ -23,6 +25,8 @@
#include <core/posix/exec.h>
#include <core/posix/child_process.h>
#include <binder/IServiceManager.h>
namespace {
std::map<std::string,std::string> common_env = {
{"ANDROID_DATA", "/data"},
@ -48,6 +52,14 @@ void AndroidApiSkeleton::wait_for_process(core::posix::ChildProcess &process,
}
}
void AndroidApiSkeleton::connect_services() {
if (!activity_manager_.get()) {
auto am = android::defaultServiceManager()->getService(android::String16("activity"));
if (am.get())
activity_manager_ = new android::BpActivityManager(am);
}
}
void AndroidApiSkeleton::install_application(anbox::protobuf::bridge::InstallApplication const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) {
@ -106,4 +118,19 @@ void AndroidApiSkeleton::set_dns_servers(anbox::protobuf::bridge::SetDnsServers
done->Run();
}
void AndroidApiSkeleton::set_focused_task(anbox::protobuf::bridge::SetFocusedTask const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done) {
(void) response;
connect_services();
if (activity_manager_.get())
activity_manager_->setFocusedTask(request->id());
else
response->set_error("ActivityManager is not available");
done->Run();
}
} // namespace anbox

View file

@ -18,6 +18,8 @@
#ifndef ANBOX_PLATFORM_API_SKELETON_H_
#define ANBOX_PLATFORM_API_SKELETON_H_
#include "android/service/activity_manager_interface.h"
namespace google {
namespace protobuf {
class Closure;
@ -36,6 +38,7 @@ namespace bridge {
class InstallApplication;
class LaunchApplication;
class SetDnsServers;
class SetFocusedTask;
} // namespace bridge
namespace rpc {
class Void;
@ -58,9 +61,17 @@ public:
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done);
void set_focused_task(anbox::protobuf::bridge::SetFocusedTask const *request,
anbox::protobuf::rpc::Void *response,
google::protobuf::Closure *done);
private:
void wait_for_process(core::posix::ChildProcess &process,
anbox::protobuf::rpc::Void *response);
void connect_services();
android::sp<android::BpActivityManager> activity_manager_;
};
} // namespace anbox

View file

@ -41,6 +41,8 @@ void MessageProcessor::dispatch(rpc::Invocation const& invocation) {
invoke(this, platform_api_.get(), &AndroidApiSkeleton::launch_application, invocation);
else if (invocation.method_name() == "set_dns_servers")
invoke(this, platform_api_.get(), &AndroidApiSkeleton::set_dns_servers, invocation);
else if (invocation.method_name() == "set_focused_task")
invoke(this, platform_api_.get(), &AndroidApiSkeleton::set_focused_task, invocation);
}
void MessageProcessor::process_event_sequence(const std::string&) {