forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice_manager_proxy.cc
66 lines (59 loc) · 2.37 KB
/
service_manager_proxy.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/binder/service_manager_proxy.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/binder/command_broker.h"
#include "chromeos/binder/object.h"
#include "chromeos/binder/transaction_data.h"
#include "chromeos/binder/transaction_data_reader.h"
#include "chromeos/binder/writable_transaction_data.h"
namespace binder {
// static
const char ServiceManagerProxy::kInterfaceName[] = "android.os.IServiceManager";
// static
scoped_refptr<Object> ServiceManagerProxy::CheckService(
CommandBroker* command_broker,
const base::string16& service_name) {
// TODO(hashimoto): Propagate the current thread's strict mode policy
// (crbug.com/575574).
const int kStrictModePolicy = 0;
WritableTransactionData data;
data.SetCode(CHECK_SERVICE_TRANSACTION);
data.WriteInterfaceToken(base::ASCIIToUTF16(kInterfaceName),
kStrictModePolicy);
data.WriteString16(service_name);
std::unique_ptr<TransactionData> reply;
if (!command_broker->Transact(kContextManagerHandle, data, &reply) ||
!reply || reply->HasStatus()) {
LOG(ERROR) << "Failed to get the service.";
return scoped_refptr<Object>();
}
TransactionDataReader reader(*reply);
return reader.ReadObject(command_broker);
}
// static
bool ServiceManagerProxy::AddService(CommandBroker* command_broker,
const base::string16& service_name,
scoped_refptr<Object> object,
int options) {
// TODO(hashimoto): Propagate the current thread's strict mode policy
// (crbug.com/575574).
const int kStrictModePolicy = 0;
WritableTransactionData data;
data.SetCode(ADD_SERVICE_TRANSACTION);
data.WriteInterfaceToken(base::ASCIIToUTF16(kInterfaceName),
kStrictModePolicy);
data.WriteString16(service_name);
data.WriteObject(object);
data.WriteInt32((options & ALLOW_ISOLATED) ? 1 : 0);
std::unique_ptr<TransactionData> reply;
if (!command_broker->Transact(kContextManagerHandle, data, &reply) ||
!reply || reply->HasStatus()) {
LOG(ERROR) << "Failed to add the service.";
return false;
}
return true;
}
} // namespace binder