1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "VrManager"
18 #include <utils/Log.h>
19
20 #include <vr/vr_manager/vr_manager.h>
21 #include <stdint.h>
22 #include <sys/types.h>
23 #include <binder/Parcel.h>
24
25 namespace android {
26
27 // Must be kept in sync with interface defined in IVrStateCallbacks.aidl.
28
29 class BpVrStateCallbacks : public BpInterface<IVrStateCallbacks> {
30 public:
BpVrStateCallbacks(const sp<IBinder> & impl)31 explicit BpVrStateCallbacks(const sp<IBinder>& impl)
32 : BpInterface<IVrStateCallbacks>(impl) {}
33
onVrStateChanged(bool enabled)34 void onVrStateChanged(bool enabled) {
35 Parcel data, reply;
36 data.writeInterfaceToken(IVrStateCallbacks::getInterfaceDescriptor());
37 data.writeBool(enabled);
38 remote()->transact(ON_VR_STATE_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
39 }
40 };
41
42 IMPLEMENT_META_INTERFACE(VrStateCallbacks, "android.service.vr.IVrStateCallbacks");
43
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)44 status_t BnVrStateCallbacks::onTransact(uint32_t code, const Parcel& data,
45 Parcel* reply, uint32_t flags) {
46 switch(code) {
47 case ON_VR_STATE_CHANGED: {
48 CHECK_INTERFACE(IVrStateCallbacks, data, reply);
49 onVrStateChanged(data.readBool());
50 return OK;
51 }
52 }
53 return BBinder::onTransact(code, data, reply, flags);
54 }
55
56 // Must be kept in sync with interface defined in
57 // IPersistentVrStateCallbacks.aidl.
58
59 class BpPersistentVrStateCallbacks
60 : public BpInterface<IPersistentVrStateCallbacks> {
61 public:
BpPersistentVrStateCallbacks(const sp<IBinder> & impl)62 explicit BpPersistentVrStateCallbacks(const sp<IBinder>& impl)
63 : BpInterface<IPersistentVrStateCallbacks>(impl) {}
64
onPersistentVrStateChanged(bool enabled)65 void onPersistentVrStateChanged(bool enabled) {
66 Parcel data, reply;
67 data.writeInterfaceToken(
68 IPersistentVrStateCallbacks::getInterfaceDescriptor());
69 data.writeBool(enabled);
70 remote()->transact(ON_PERSISTENT_VR_STATE_CHANGED,
71 data, &reply, IBinder::FLAG_ONEWAY);
72 }
73 };
74
75 IMPLEMENT_META_INTERFACE(PersistentVrStateCallbacks,
76 "android.service.vr.IPersistentVrStateCallbacks");
77
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)78 status_t BnPersistentVrStateCallbacks::onTransact(
79 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
80 switch(code) {
81 case ON_PERSISTENT_VR_STATE_CHANGED: {
82 CHECK_INTERFACE(IPersistentVrStateCallbacks, data, reply);
83 onPersistentVrStateChanged(data.readBool());
84 return OK;
85 }
86 }
87 return BBinder::onTransact(code, data, reply, flags);
88 }
89
90 // Must be kept in sync with interface defined in IVrManager.aidl.
91
92 class BpVrManager : public BpInterface<IVrManager> {
93 public:
BpVrManager(const sp<IBinder> & impl)94 explicit BpVrManager(const sp<IBinder>& impl)
95 : BpInterface<IVrManager>(impl) {}
96
registerListener(const sp<IVrStateCallbacks> & cb)97 void registerListener(const sp<IVrStateCallbacks>& cb) override {
98 Parcel data;
99 data.writeInterfaceToken(IVrManager::getInterfaceDescriptor());
100 data.writeStrongBinder(IInterface::asBinder(cb));
101 remote()->transact(REGISTER_LISTENER, data, NULL);
102 }
103
unregisterListener(const sp<IVrStateCallbacks> & cb)104 void unregisterListener(const sp<IVrStateCallbacks>& cb) override {
105 Parcel data;
106 data.writeInterfaceToken(IVrManager::getInterfaceDescriptor());
107 data.writeStrongBinder(IInterface::asBinder(cb));
108 remote()->transact(UNREGISTER_LISTENER, data, NULL);
109 }
110
registerPersistentVrStateListener(const sp<IPersistentVrStateCallbacks> & cb)111 void registerPersistentVrStateListener(
112 const sp<IPersistentVrStateCallbacks>& cb) override {
113 Parcel data;
114 data.writeInterfaceToken(IVrManager::getInterfaceDescriptor());
115 data.writeStrongBinder(IInterface::asBinder(cb));
116 remote()->transact(REGISTER_PERSISTENT_VR_STATE_LISTENER, data, NULL);
117 }
118
unregisterPersistentVrStateListener(const sp<IPersistentVrStateCallbacks> & cb)119 void unregisterPersistentVrStateListener(
120 const sp<IPersistentVrStateCallbacks>& cb) override {
121 Parcel data;
122 data.writeInterfaceToken(IVrManager::getInterfaceDescriptor());
123 data.writeStrongBinder(IInterface::asBinder(cb));
124 remote()->transact(UNREGISTER_PERSISTENT_VR_STATE_LISTENER, data, NULL);
125 }
126
getVrModeState()127 bool getVrModeState() override {
128 Parcel data, reply;
129 data.writeInterfaceToken(IVrManager::getInterfaceDescriptor());
130 remote()->transact(GET_VR_MODE_STATE, data, &reply);
131 int32_t ret = reply.readExceptionCode();
132 if (ret != 0) {
133 return false;
134 }
135 return reply.readBool();
136 }
137 };
138
139 IMPLEMENT_META_INTERFACE(VrManager, "android.service.vr.IVrManager");
140
141 } // namespace android
142