Skip to content

Commit 60c09ca

Browse files
cuiziweizwopenvela-robot
authored andcommitted
binder: Add aidl_demo
Change-Id: I64fb4a4423e9a9b01605a79ce180765b891027ce
1 parent 2ede90e commit 60c09ca

File tree

13 files changed

+359
-0
lines changed

13 files changed

+359
-0
lines changed

Make.defs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
include $(wildcard $(APPDIR)/frameworks/binder/*/Make.defs)

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
MENUDESC = "Binder"
18+
19+
include $(APPDIR)/Directory.mk

README.md

Whitespace-only changes.

examples/Make.defs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
include $(wildcard $(APPDIR)/frameworks/binder/examples/*/Make.defs)

examples/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
MENUDESC = "Binder"
18+
19+
include $(APPDIR)/Directory.mk

examples/aidl_demo/ITestStuff.aidl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
/*
3+
* Copyright (C) 2020 The Android Open Source Project
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
interface ITestStuff {
18+
void write(int sample);
19+
void read(int idx);
20+
}

examples/aidl_demo/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
config BINDER_EXAMPLES
18+
tristate "Binder examples"
19+
depends on ANDROID_BINDER
20+
21+
config BINDER_EXAMPLES_STACKSIZE
22+
int "Binder examples stack size"
23+
depends on BINDER_EXAMPLES
24+
default DEFAULT_TASK_STACKSIZE

examples/aidl_demo/Make.defs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
ifneq ($(CONFIG_BINDER_EXAMPLES),)
18+
CONFIGURED_APPS += $(APPDIR)/frameworks/binder/examples/aidl_demo
19+
endif

examples/aidl_demo/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Copyright (C) 2023 Xiaomi Corporation
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+
include $(APPDIR)/Make.defs
18+
19+
CXXEXT = .cpp
20+
21+
MODULE = $(CONFIG_BINDER_EXAMPLES)
22+
PRIORITY = SCHED_PRIORITY_DEFAULT
23+
STACKSIZE = $(CONFIG_BINDER_EXAMPLES_STACKSIZE)
24+
25+
AIDLFLAGS = --lang=cpp -h. -o.
26+
AIDLSRCS += ITestStuff.aidl
27+
28+
CXXFLAGS += -I.
29+
30+
CXXSRCS += ITestStuff.cpp
31+
MAINSRC += TestClient.cpp
32+
PROGNAME += TestClient
33+
MAINSRC += TestServer.cpp
34+
PROGNAME += TestServer
35+
36+
MAINSRC += TestClientCpc.cpp
37+
PROGNAME += TestClientCpc
38+
MAINSRC += TestServerCpc.cpp
39+
PROGNAME += TestServerCpc
40+
41+
include $(APPDIR)/Application.mk

examples/aidl_demo/TestClient.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#define LOG_TAG "TestClient"
2+
3+
#include <binder/IPCThreadState.h>
4+
#include <binder/ProcessState.h>
5+
#include <binder/IServiceManager.h>
6+
7+
#include "ITestStuff.h"
8+
#include "BnTestStuff.h"
9+
#include "BpTestStuff.h"
10+
11+
#include <utils/Log.h>
12+
#include <utils/String8.h>
13+
14+
using namespace android;
15+
using android::binder::Status;
16+
17+
extern "C" int main(int count, char **argv)
18+
{
19+
ALOGI("demo client start count: %d, argv[0]: %s", count, argv[0]);
20+
21+
// obtain service manager
22+
sp<IServiceManager> sm(defaultServiceManager());
23+
ALOGI("defaultServiceManager(): %p", sm.get());
24+
25+
// obtain demo.service
26+
sp<IBinder> binder = sm->getService(String16("aidldemo.service"));
27+
if (binder == NULL) {
28+
ALOGE("aidldemo service binder is null, abort...");
29+
return -1;
30+
}
31+
ALOGI("aidldemo service binder is %p", binder.get());
32+
33+
// by interface_cast restore ITest
34+
sp<ITestStuff> service = interface_cast<ITestStuff>(binder);
35+
ALOGI("aidldemo service is %p", service.get());
36+
37+
// use service provided by demo.service
38+
service->write(123);
39+
service->read(456);
40+
return 0;
41+
}

0 commit comments

Comments
 (0)