├── AHardwareBuffer
├── AHardwareBuffer-IPC-Client
│ ├── .gitignore
│ ├── .idea
│ │ ├── caches
│ │ │ └── build_file_checksums.ser
│ │ ├── codeStyles
│ │ │ └── Project.xml
│ │ ├── gradle.xml
│ │ ├── misc.xml
│ │ └── runConfigurations.xml
│ ├── app
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── cpp
│ │ │ ├── native-lib.cpp
│ │ │ └── native-lib.h
│ │ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── AHardwareBuffer-IPC-Server
│ ├── .gitignore
│ ├── .idea
│ │ ├── caches
│ │ │ └── build_file_checksums.ser
│ │ ├── codeStyles
│ │ │ └── Project.xml
│ │ ├── gradle.xml
│ │ ├── misc.xml
│ │ └── runConfigurations.xml
│ ├── app
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── cpp
│ │ │ ├── native-lib.cpp
│ │ │ └── native-lib.h
│ │ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
└── README.md
├── README.md
├── Shared_Memory
├── README.md
├── SharedMem-IPC-Client
│ ├── .gitignore
│ ├── app
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── cpp
│ │ │ ├── display.cpp
│ │ │ ├── display.h
│ │ │ └── native-lib.cpp
│ │ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
└── SharedMem-IPC-Server
│ ├── .gitignore
│ ├── app
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── cpp
│ │ ├── display.cpp
│ │ ├── display.h
│ │ └── native-lib.cpp
│ │ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ └── strings.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── Unix_Sockets
├── README.md
├── Socket-IPC-Client
│ ├── .gitignore
│ ├── app
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── cpp
│ │ │ ├── display.cpp
│ │ │ ├── display.h
│ │ │ └── native-lib.cpp
│ │ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
└── Socket-IPC-Server
│ ├── .gitignore
│ ├── app
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── cpp
│ │ ├── display.cpp
│ │ ├── display.h
│ │ └── native-lib.cpp
│ │ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ └── strings.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── demo1.gif
└── demo2.gif
/AHardwareBuffer/AHardwareBuffer-IPC-Client/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
4 | include_directories(${APP_GLUE_DIR})
5 | add_library( app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
6 |
7 | add_library( ClientIPC
8 | SHARED
9 | src/main/cpp/native-lib.cpp )
10 |
11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
12 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
13 |
14 | target_link_libraries( ClientIPC
15 | app-glue
16 | log
17 | android)
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.spencerfricke.ahardwarebuffer_ipc_client"
7 | minSdkVersion 26
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | externalNativeBuild {
13 | cmake {
14 | cppFlags ""
15 | }
16 | }
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | externalNativeBuild {
25 | cmake {
26 | path "CMakeLists.txt"
27 | }
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: 'libs', include: ['*.jar'])
33 | implementation 'com.android.support:appcompat-v7:26.1.0'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
37 | }
38 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
13 |
14 |
16 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/cpp/native-lib.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #ifndef SHAREDMEM_IPC_CLIENT_DISPLAY_H
6 | #define SHAREDMEM_IPC_CLIENT_DISPLAY_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | // Android log function wrappers
18 | static const char* kTAG = "ClientIPC";
19 | #define LOGI(...) \
20 | ((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
21 | #define LOGW(...) \
22 | ((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
23 | #define LOGE(...) \
24 | ((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
25 |
26 | // 0xAABBGGRR for pixel
27 | #define RED_SHIFT 0
28 | #define GREEN_SHIFT 8
29 | #define BLUE_SHIFT 16
30 |
31 | const uint32_t color_wheel[4] = {
32 | 0x000000FF, // red
33 | 0x0000FF00, // green
34 | 0x00FF0000, // blue
35 | 0x00000FFFF // yellow
36 | };
37 |
38 | bool IsNDKReady(void);
39 |
40 | void setColorSections(ANativeWindow* native_window);
41 |
42 | void setSharedMem(uint8_t color);
43 |
44 | // Process the next main command.
45 | void handle_cmd(android_app* app, int32_t cmd);
46 |
47 | #endif //SHAREDMEM_IPC_CLIENT_DISPLAY_H
48 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AHardwareBuffer-IPC-Client
3 |
4 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Client/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jun 10 11:05:29 CDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Client/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
4 | include_directories(${APP_GLUE_DIR})
5 | add_library( app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
6 |
7 | add_library( ServerIPC
8 | SHARED
9 | src/main/cpp/native-lib.cpp )
10 |
11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
12 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
13 |
14 | target_link_libraries( ServerIPC
15 | app-glue
16 | log
17 | android)
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.spencerfricke.ahardwarebuffer_ipc_server"
7 | minSdkVersion 26
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | externalNativeBuild {
12 | cmake {
13 | cppFlags ""
14 | }
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | externalNativeBuild {
24 | cmake {
25 | path "CMakeLists.txt"
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | }
33 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
13 |
14 |
16 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include "native-lib.h"
2 |
3 | static AHardwareBuffer* h_buffer = nullptr;
4 | static AHardwareBuffer_Desc h_buffer_desc;
5 |
6 | static ANativeWindow* native_window;
7 |
8 | // Server to get socket data with information of SharedMem's file descriptor
9 | void* setupServer(void* na) {
10 | int ret;
11 | struct sockaddr_un server_addr;
12 | int socket_fd;
13 | int data_socket;
14 | char socket_name[108]; // 108 sun_path length max
15 |
16 | LOGI("Start server setup");
17 |
18 | // AF_UNIX for domain unix IPC and SOCK_STREAM since it works for the example
19 | socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
20 | if (socket_fd < 0) {
21 | LOGE("socket: %s", strerror(errno));
22 | exit(EXIT_FAILURE);
23 | }
24 | LOGI("Socket made");
25 |
26 | // NDK needs abstract namespace by leading with '\0'
27 | // Ya I was like WTF! too... http://www.toptip.ca/2013/01/unix-domain-socket-with-abstract-socket.html?m=1
28 | // Note you don't need to unlink() the socket then
29 | memcpy(&socket_name[0], "\0", 1);
30 | strcpy(&socket_name[1], SOCKET_NAME);
31 |
32 | // clear for safty
33 | memset(&server_addr, 0, sizeof(struct sockaddr_un));
34 | server_addr.sun_family = AF_UNIX; // Unix Domain instead of AF_INET IP domain
35 | strncpy(server_addr.sun_path, socket_name, sizeof(server_addr.sun_path) - 1); // 108 char max
36 |
37 | ret = bind(socket_fd, (const struct sockaddr *) &server_addr, sizeof(struct sockaddr_un));
38 | if (ret < 0) {
39 | LOGE("bind: %s", strerror(errno));
40 | exit(EXIT_FAILURE);
41 | }
42 | LOGI("Bind made");
43 |
44 | // Open 8 back buffers for this demo
45 | ret = listen(socket_fd, 8);
46 | if (ret < 0) {
47 | LOGE("listen: %s", strerror(errno));
48 | exit(EXIT_FAILURE);
49 | }
50 | LOGI("Socket listening for packages");
51 |
52 | // Wait for incoming connection.
53 | data_socket = accept(socket_fd, NULL, NULL);
54 | if (data_socket < 0) {
55 | LOGE("accept: %s", strerror(errno));
56 | exit(EXIT_FAILURE);
57 | }
58 | LOGI("Accepted data");
59 | // This is the main loop for handling connections
60 | // Assuming in example connection is established only once
61 | // Would be better to refactor this for robustness
62 | for (;;) {
63 |
64 | // Blocks until sent data
65 | ret = AHardwareBuffer_recvHandleFromUnixSocket(data_socket, &h_buffer);
66 | if (ret != 0) {
67 | LOGE("Failed to AHardwareBuffer_recvHandleFromUnixSocket");
68 | }
69 |
70 | }
71 | close(data_socket);
72 | close(socket_fd);
73 |
74 | return NULL;
75 | }
76 |
77 | // Takes the native_window and sets a color
78 | // This is so we can know the IPC worked
79 | void setWindowWithBuffer() {
80 | int ret;
81 | void* shared_buffer;
82 |
83 | ANativeWindow_acquire(native_window);
84 | ANativeWindow_Buffer buffer;
85 | if (ANativeWindow_lock(native_window, &buffer, nullptr) < 0) {
86 | LOGE("Failed to lock native window");
87 | return;
88 | }
89 |
90 | // need to pull out description of size info
91 | // currently assuming in demo, should use this to error check and stuff
92 | AHardwareBuffer_describe(h_buffer, &h_buffer_desc);
93 |
94 | LOGI("ANativeWindow_Buffer Size: %d", buffer.height * buffer.stride * 4);
95 | LOGI("AHardwareBuffer Size: %d", h_buffer_desc.height * h_buffer_desc.stride * 4);
96 |
97 | ret = AHardwareBuffer_lock(h_buffer,
98 | AHARDWAREBUFFER_USAGE_CPU_READ_MASK,
99 | -1, // no fence in demo
100 | NULL,
101 | &shared_buffer);
102 | if (ret != 0) {
103 | LOGE("Failed to AHardwareBuffer_lock");
104 | }
105 |
106 | // assuming format was set to 4 bytes per pixel and not 565 mode
107 | memcpy(buffer.bits, shared_buffer, (buffer.height * buffer.stride * 4));
108 |
109 | ret = AHardwareBuffer_unlock(h_buffer, NULL);
110 | if (ret != 0) {
111 | LOGE("Failed to AHardwareBuffer_unlock");
112 | }
113 |
114 | ANativeWindow_unlockAndPost(native_window);
115 | ANativeWindow_release(native_window);
116 | }
117 |
118 | // Process the next main command.
119 | void handle_cmd(android_app* app, int32_t cmd) {
120 | switch (cmd) {
121 | case APP_CMD_INIT_WINDOW:
122 | native_window = app->window;
123 |
124 | // Here we set the buffer to use RGBX_8888 as default might be; RGB_565
125 | ANativeWindow_setBuffersGeometry(app->window,
126 | ANativeWindow_getHeight(app->window),
127 | ANativeWindow_getWidth(app->window),
128 | WINDOW_FORMAT_RGBX_8888);
129 |
130 | // Only can set window with screen is active
131 | if (h_buffer != nullptr) {
132 | setWindowWithBuffer();
133 | }
134 |
135 | break;
136 | case APP_CMD_TERM_WINDOW:
137 | // The window is being hidden or closed, clean it up.
138 | break;
139 | default:
140 | LOGI("event not handled: %d", cmd);
141 | }
142 | }
143 |
144 | bool IsNDKReady(void) {
145 | // add prep logic
146 | return true;
147 | }
148 |
149 | // Main function
150 | void android_main(struct android_app* app) {
151 |
152 | // Set the callback to process system events
153 | app->onAppCmd = handle_cmd;
154 |
155 | // Used to poll the events in the main loop
156 | int events;
157 | android_poll_source* source;
158 |
159 | // Start server daemon on new thread
160 | pthread_t server_thread;
161 | pthread_create( &server_thread, NULL, setupServer, (void*) NULL);
162 |
163 | // Main loop
164 | do {
165 | if (ALooper_pollAll(IsNDKReady() ? 1 : 0, nullptr,
166 | &events, (void**)&source) >= 0) {
167 | if (source != NULL) source->process(app, source);
168 | }
169 | } while (app->destroyRequested == 0);
170 |
171 | LOGI("GAME OVER");
172 | }
173 |
174 |
175 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/cpp/native-lib.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #ifndef AHARDWAREBUFFER_IPC_SERVER_H
6 | #define AHARDWAREBUFFER_IPC_SERVER_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | // Android log function wrappers
28 | static const char* kTAG = "ServerIPC";
29 | #define LOGI(...) \
30 | ((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
31 | #define LOGW(...) \
32 | ((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
33 | #define LOGE(...) \
34 | ((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
35 |
36 | // Can be anything if using abstract namespace
37 | #define SOCKET_NAME "sharedServerSocket"
38 |
39 | bool IsNDKReady(void);
40 |
41 | void setWindowWithBuffer(void);
42 |
43 | void* setupServer(void* na);
44 |
45 | // Process the next main command.
46 | void handle_cmd(android_app* app, int32_t cmd);
47 |
48 | #endif //AHARDWAREBUFFER_IPC_SERVER_H
49 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AHardwareBuffer-IPC-Server
3 |
4 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/AHardwareBuffer/AHardwareBuffer-IPC-Server/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jun 10 11:06:14 CDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/AHardwareBuffer/AHardwareBuffer-IPC-Server/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/AHardwareBuffer/README.md:
--------------------------------------------------------------------------------
1 | # AHardwareBuffer IPC
2 |
3 | This is a working demo using `AHardwareBuffer` API to send shared data between two processes.
4 |
5 | This works by having the Client app `AHardwareBuffer_allocate()` and then writing to the shared memory upon picking a color (it generates the gradient pattern you see). From here the Server app upons an active window will see the data has been sent via `AHardwareBuffer_recvHandleFromUnixSocket()` and then write that memory to the `ANativeWindow_Buffer` which is then displayed on the screen.
6 |
7 | 
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NDK-Socket-IPC
2 |
3 | This this a experiment to see different forms of IPC (inter-process communication) for native apps not exposed to the Android Binder SDK class. The current 3 forms are Unix Domain Sockets, NDK Shared Memory, and NDK AHardwareBuffer. This app has a server app that is one of 4 colors and a client app that changes the color. [My blog post with more details](https://medium.com/@spencerfricke/android-ahardwarebuffer-shared-memory-over-unix-domain-sockets-7b27b1271b36)
4 |
5 |
6 | Pure Unix Domain demo (generates full screen color on server end)
7 |  |
8 |
9 |
10 |
11 | AHardwareBuffer demo (server reads data generated from client saved in shared memory buffer)
12 |  |
13 |
14 |
15 | > Disclaimer: The code was a quick prototype, for a friend as a proof of concept. Also have not profiled and not sure if there is better way of doing IPC in native Android app, if so please share since a Google search shows very little on topic
16 |
17 | ## The 3 Methods
18 |
19 | 1. [Unix Domain Sockets](Unix_Sockets)
20 | - Good o'l C style Unix Domain Sockets
21 | - Same idea if ever sent TCP/UDP Sockets before
22 | - Works for any version of Android
23 | 2. [Shared Memory](Shared_Memory)
24 | - Using the shared memory API [](https://developer.android.com/ndk/reference/group/memory)
25 | - Android 8.0 (API 26) needed to run
26 | 3. [AHardwareBuffer](AHardwareBuffer)
27 | - Using the native hardware buffer API [](https://developer.android.com/ndk/reference/group/native-activity)
28 | - Android 8.0 (API 26) needed to run
29 |
30 | ## How to run
31 |
32 | - Each folder has a Client and Server folder each containing an Android Studio project.
33 | - Open both and install on device.
34 | - Open server app first (currently working on more robust example)
35 | - Open client app and pick color
36 | - Either switch back to server app to see change of color or open LogCat and view the print out
37 |
--------------------------------------------------------------------------------
/Shared_Memory/README.md:
--------------------------------------------------------------------------------
1 | # Shared Memory IPC
2 |
3 | So after playing around I found that it **Should** be possible to use the Shared Memory API, but this is not the route you want. the `` API was designed to share memory between processes like `` where you will call [ANeuralNetworksMemory_createFromFd()](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ga3510b07da0ab9626fb84688fb91112be) and the under lying Android NDK will take the file descriptor from there.
4 |
5 | To finish this example, which I honestly will probably not do, is to share the file descriptor from the mapped memory of your `ASharedMemory_create()` call (which is really just a `shm_open()` call) and send use the Unix Domain Sockets to send the file descriptor to the other process using `sendmsg(2)` and `recvmsg(2)`. Mainly because the `AHardwareBuffer` API [already does this better](https://android.googlesource.com/platform/frameworks/native/+/android-8.1.0_r33/libs/nativewindow/AHardwareBuffer.cpp#143)
6 |
7 | Here are some links if you still want to go this route
8 |
9 | - https://keithp.com/blogs/fd-passing/
10 | - http://poincare.matf.bg.ac.rs/~ivana/courses/ps/sistemi_knjige/pomocno/apue/APUE/0201433079/ch17lev1sec4.html
11 | - https://gist.github.com/nazgee/2396992
12 | - https://stackoverflow.com/questions/2358684/can-i-share-a-file-descriptor-to-another-process-on-linux-or-are-they-local-to-t?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
13 |
14 | ## The better option
15 |
16 | For the example of sending data across two seperate process, I recommend using the `` API which came out with Android 8.0 as well with I assume these two purpose in mind... who knows with the NDK :D
17 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 | .idea/
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
4 | include_directories(${APP_GLUE_DIR})
5 | add_library( app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
6 |
7 | add_library( ClientIPC
8 | SHARED
9 | src/main/cpp/display.cpp
10 | src/main/cpp/native-lib.cpp )
11 |
12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
13 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
14 |
15 | target_link_libraries( ClientIPC
16 | app-glue
17 | log
18 | android)
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.spencerfricke.sharedmem_ipc_client"
7 | minSdkVersion 26
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | externalNativeBuild {
12 | cmake {
13 | cppFlags ""
14 | }
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | externalNativeBuild {
24 | cmake {
25 | path "CMakeLists.txt"
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | }
33 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
13 |
14 |
16 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/cpp/display.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #include "display.h"
6 |
7 | bool IsNDKReady(void) {
8 | // add prep logic
9 | return true;
10 | }
11 |
12 | // Takes the native_window and sets a color
13 | // This is so we can know what square to click
14 | void setColorSections(ANativeWindow* native_window) {
15 |
16 | ANativeWindow_acquire(native_window);
17 | ANativeWindow_Buffer buffer;
18 | if (ANativeWindow_lock(native_window, &buffer, nullptr) < 0) {
19 | LOGE("Failed to lock native window");
20 | return;
21 | }
22 |
23 | LOGI("/// H-W-S-F: %d, %d, %d, %d", buffer.height, buffer.width, buffer.stride, buffer.format);
24 |
25 | // 3 columns of color
26 | for (int i = 0; i < buffer.height; i++) {
27 | for (int j = 0; j < buffer.stride; j++) {
28 | if (j < buffer.width / 3) {
29 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[0], sizeof(uint32_t));
30 | } else if (j < buffer.width * 2 / 3) {
31 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[1], sizeof(uint32_t));
32 | } else {
33 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[2], sizeof(uint32_t));
34 | }
35 | }
36 | }
37 |
38 | // get height and stride while having window buffer
39 | screen_height = buffer.height;
40 | screen_stride = buffer.stride;
41 |
42 | ANativeWindow_unlockAndPost(native_window);
43 | ANativeWindow_release(native_window);
44 | }
45 |
46 | // Process the next main command.
47 | void handle_cmd(android_app* app, int32_t cmd) {
48 | switch (cmd) {
49 | case APP_CMD_INIT_WINDOW:
50 | // The window is being shown, get it ready.
51 | LOGI( "Width: %d", ANativeWindow_getWidth(app->window));
52 | LOGI( "Height: %d", ANativeWindow_getHeight(app->window));
53 |
54 | // Here we set the buffer to use RGBX_8888 as default might be; RGB_565
55 | ANativeWindow_setBuffersGeometry(app->window,
56 | ANativeWindow_getHeight(app->window),
57 | ANativeWindow_getWidth(app->window),
58 | WINDOW_FORMAT_RGBX_8888);
59 |
60 | setColorSections(app->window);
61 |
62 | break;
63 | case APP_CMD_TERM_WINDOW:
64 | // The window is being hidden or closed, clean it up.
65 | break;
66 | default:
67 | LOGI("event not handled: %d", cmd);
68 | }
69 | }
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/cpp/display.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #ifndef SHAREDMEM_IPC_CLIENT_DISPLAY_H
6 | #define SHAREDMEM_IPC_CLIENT_DISPLAY_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | // Android log function wrappers
18 | static const char* kTAG = "ClientIPC";
19 | #define LOGI(...) \
20 | ((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
21 | #define LOGW(...) \
22 | ((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
23 | #define LOGE(...) \
24 | ((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
25 |
26 | // 0xAABBGGRR for pixel
27 | #define RED_SHIFT 0
28 | #define GREEN_SHIFT 8
29 | #define BLUE_SHIFT 16
30 |
31 | const uint32_t color_wheel[4] = {
32 | 0x000000FF, // red
33 | 0x0000FF00, // green
34 | 0x00FF0000, // blue
35 | 0x00000FFFF // yellow
36 | };
37 |
38 | static int screen_height = 0;
39 | static int screen_stride = 0;
40 |
41 | bool IsNDKReady(void);
42 |
43 | void setColorSections(ANativeWindow* native_window);
44 |
45 | void setSharedMem(uint8_t color);
46 |
47 | int getScreenHeight() { return screen_height; }
48 | int getScreenStride() { return screen_stride; }
49 |
50 | // Process the next main command.
51 | void handle_cmd(android_app* app, int32_t cmd);
52 |
53 | #endif //SHAREDMEM_IPC_CLIENT_DISPLAY_H
54 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include "display.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 |
14 | // Can be anything if using abstract namespace
15 | #define SOCKET_NAME "sharedServerSocket"
16 | #define BUFFER_SIZE 32
17 |
18 | // Shared Memory has file descriptor we need to get to other app
19 | // Also need size of data inside shared memory
20 | static struct shared_mem {
21 | int fd = -1;
22 | int size = 0;
23 | } shared_mem;
24 | char *shared_buffer;
25 |
26 | static int data_socket;
27 | static struct sockaddr_un server_addr;
28 |
29 | void setupClient(void) {
30 | char socket_name[108]; // 108 sun_path length max
31 |
32 | data_socket = socket(AF_UNIX, SOCK_STREAM, 0);
33 | if (data_socket < 0) {
34 | LOGE("socket: %s", strerror(errno));
35 | exit(EXIT_FAILURE);
36 | }
37 |
38 | // NDK needs abstract namespace by leading with '\0'
39 | // Ya I was like WTF! too... http://www.toptip.ca/2013/01/unix-domain-socket-with-abstract-socket.html?m=1
40 | // Note you don't need to unlink() the socket then
41 | memcpy(&socket_name[0], "\0", 1);
42 | strcpy(&socket_name[1], SOCKET_NAME);
43 |
44 | // clear for safty
45 | memset(&server_addr, 0, sizeof(struct sockaddr_un));
46 | server_addr.sun_family = AF_UNIX; // Unix Domain instead of AF_INET IP domain
47 | strncpy(server_addr.sun_path, socket_name, sizeof(server_addr.sun_path) - 1); // 108 char max
48 |
49 | // Assuming only one init connection for demo
50 | int ret = connect(data_socket, (const struct sockaddr *) &server_addr, sizeof(struct sockaddr_un));
51 | if (ret < 0) {
52 | LOGE("connect: %s", strerror(errno));
53 | exit(EXIT_FAILURE);
54 | }
55 |
56 | LOGI("Client Setup Complete");
57 | }
58 |
59 | void setSharedMem(uint8_t shift) {
60 |
61 | // Set up shared memory for first time
62 | if (shared_mem.fd < 0) {
63 | // Set up shared memory for 4 bytes per pixed
64 | shared_mem.size = getScreenHeight() * getScreenStride() * 4;
65 |
66 | shared_mem.fd = ASharedMemory_create("colorBuffer", shared_mem.size);
67 |
68 | shared_buffer = (char *)mmap(NULL, shared_mem.size, PROT_READ | PROT_WRITE, MAP_SHARED, shared_mem.fd, 0);
69 | }
70 |
71 | //Produces a gradient pattern, uses shift to set as red, blue, or green
72 | for (int i = 0; i < getScreenHeight(); i++) {
73 | uint32_t color = imaxabs(255 - (i % 510)) << shift;
74 | for (int j = 0; j < getScreenStride(); j++) {
75 | memcpy(shared_buffer + (((i * getScreenStride()) + j) * 4), &color, sizeof(uint32_t));
76 | }
77 | }
78 |
79 | }
80 |
81 | void sendSharedMem() {
82 | int ret;
83 | uint8_t buffer[BUFFER_SIZE];
84 | uint8_t ret_buffer[BUFFER_SIZE];
85 |
86 | memcpy(buffer, &shared_mem, sizeof(shared_mem));
87 |
88 | ret = write(data_socket, &shared_mem, BUFFER_SIZE);
89 | if (ret < 0) {
90 | LOGE("write: %s", strerror(errno));
91 | exit(EXIT_FAILURE);
92 | }
93 |
94 | ret = read(data_socket, ret_buffer, BUFFER_SIZE);
95 | if (ret < 0) {
96 | LOGE("read: %s", strerror(errno));
97 | exit(EXIT_FAILURE);
98 | }
99 |
100 | LOGI("Return: %s", (char*)ret_buffer);
101 | }
102 |
103 |
104 | // Handles input touches to the screen
105 | int32_t handle_input(struct android_app* app, AInputEvent* event) {
106 | if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
107 | if (AInputEvent_getSource(event) == AINPUT_SOURCE_TOUCHSCREEN) {
108 | if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN) {
109 | float x = AMotionEvent_getX(event,0);
110 | float y = AMotionEvent_getY(event,0);
111 | int32_t h_width = ANativeWindow_getWidth(app->window)/2;
112 | int32_t h_height = ANativeWindow_getHeight(app->window)/2;
113 |
114 | // try to compenstate for the touch screen's home and back button on phone
115 | if (y > ANativeWindow_getHeight(app->window) * 0.95) {
116 | return 1;
117 | }
118 |
119 | LOGI("X: %f -- Y: %f", x, y);
120 |
121 | // Sends color depending on region
122 | if (x < h_width / 3) {
123 | setSharedMem(RED_SHIFT);
124 | } else if (x < h_width * 2 / 3) {
125 | setSharedMem(GREEN_SHIFT);
126 | } else {
127 | setSharedMem(BLUE_SHIFT);
128 | }
129 |
130 | sendSharedMem();
131 | }
132 | }
133 | }
134 | return 1;
135 | }
136 |
137 | // Main Function
138 | void android_main(struct android_app* app) {
139 |
140 | // Set the callback to process system events
141 | app->onAppCmd = handle_cmd;
142 | app->onInputEvent = handle_input;
143 |
144 | // Used to poll the events in the main loop
145 | int events;
146 | android_poll_source* source;
147 |
148 | setupClient();
149 |
150 | // Main loop
151 | do {
152 | if (ALooper_pollAll(IsNDKReady() ? 1 : 0, nullptr,
153 | &events, (void**)&source) >= 0) {
154 | if (source != NULL) source->process(app, source);
155 | }
156 | } while (app->destroyRequested == 0);
157 |
158 | LOGI("GAME OVER");
159 | }
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SharedMem-IPC-Client
3 |
4 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Client/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 08 17:27:00 CDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Client/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 | .idea/
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
4 | include_directories(${APP_GLUE_DIR})
5 | add_library( app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
6 |
7 | add_library( ServerIPC
8 | SHARED
9 | src/main/cpp/display.cpp
10 | src/main/cpp/native-lib.cpp )
11 |
12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
13 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
14 |
15 | target_link_libraries( ServerIPC
16 | app-glue
17 | log
18 | android)
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.spencerfricke.sharedmem_ipc_server"
7 | minSdkVersion 24
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | externalNativeBuild {
12 | cmake {
13 | cppFlags ""
14 | }
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | externalNativeBuild {
24 | cmake {
25 | path "CMakeLists.txt"
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | }
33 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
13 |
14 |
16 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/cpp/display.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #include "display.h"
6 |
7 | bool IsNDKReady(void) {
8 | // add prep logic
9 |
10 | // 4 bytes per pixel of max screen size
11 | color_buffer = (uint8_t*)malloc(MAX_SCREEN_SIZE * 4);
12 | if (color_buffer == NULL) {
13 | LOGE("Cant allocated color_buffer");
14 | exit(-1);
15 | }
16 |
17 | // Fills the buffer to green
18 | uint32_t green = 0x0000FF00;
19 |
20 | // 4K screen is 4096 x 2160
21 | int height = 4096;
22 | int width = 2160;
23 |
24 | for (int i = 0; i < height; i++) {;
25 | for (int j = 0; j < width; j++) {
26 | memcpy(color_buffer + (((i * width) + j) * 4), &green, sizeof(uint32_t));
27 | }
28 | }
29 |
30 | return true;
31 | }
32 |
33 |
34 | // Takes the native_window and sets a color
35 | // This is so we can know the IPC worked
36 | void setWindowWithBuffer() {
37 |
38 | ANativeWindow_acquire(native_window);
39 | ANativeWindow_Buffer buffer;
40 | if (ANativeWindow_lock(native_window, &buffer, nullptr) < 0) {
41 | LOGE("Failed to lock native window");
42 | return;
43 | }
44 |
45 | LOGI("/// H-W-S-F: %d, %d, %d, %d", buffer.height, buffer.width, buffer.stride, buffer.format);
46 |
47 | // assuming format was set to 4 bytes per pixel and not 565 mode
48 | memcpy(buffer.bits, color_buffer, (buffer.height * buffer.stride * 4));
49 |
50 | ANativeWindow_unlockAndPost(native_window);
51 | ANativeWindow_release(native_window);
52 | }
53 |
54 | void copyToColorBuffer(uint8_t* new_buffer, uint32_t size) {
55 | memcpy(color_buffer, new_buffer, size);
56 | }
57 |
58 | void cleanup() {
59 | free(color_buffer);
60 | }
61 |
62 | // Process the next main command.
63 | void handle_cmd(android_app* app, int32_t cmd) {
64 | switch (cmd) {
65 | case APP_CMD_INIT_WINDOW:
66 | native_window = app->window;
67 |
68 | // Here we set the buffer to use RGBX_8888 as default might be; RGB_565
69 | ANativeWindow_setBuffersGeometry(app->window,
70 | ANativeWindow_getHeight(app->window),
71 | ANativeWindow_getWidth(app->window),
72 | WINDOW_FORMAT_RGBX_8888);
73 |
74 | setWindowWithBuffer();
75 |
76 | break;
77 | case APP_CMD_TERM_WINDOW:
78 | // The window is being hidden or closed, clean it up.
79 | break;
80 | default:
81 | LOGI("event not handled: %d", cmd);
82 | }
83 | }
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/cpp/display.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #ifndef SHAREDMEM_IPC_SERVER_DISPLAY_H
6 | #define SHAREDMEM_IPC_SERVER_DISPLAY_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | // Android log function wrappers
20 | static const char* kTAG = "ServerIPC";
21 | #define LOGI(...) \
22 | ((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
23 | #define LOGW(...) \
24 | ((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
25 | #define LOGE(...) \
26 | ((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
27 |
28 |
29 | // 4K screen is 4096 x 2160 so have buffer for up to 4K (assuming same NativeWindow stride)
30 | #define MAX_SCREEN_SIZE 8847360
31 |
32 | static ANativeWindow* native_window;
33 |
34 | // The buffer that fills the screen
35 | static uint8_t* color_buffer;
36 |
37 | bool IsNDKReady(void);
38 |
39 | void setWindowWithBuffer(void);
40 |
41 | void copyToColorBuffer(uint8_t* new_buffer, uint32_t size);
42 |
43 | void cleanup(void);
44 |
45 | // Process the next main command.
46 | void handle_cmd(android_app* app, int32_t cmd);
47 |
48 | #endif //SHAREDMEM_IPC_SERVER_DISPLAY_H
49 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include "display.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | // Can be anything if using abstract namespace
12 | #define SOCKET_NAME "sharedServerSocket"
13 | #define BUFFER_SIZE 32
14 |
15 | // Server to get socket data with information of SharedMem's file descriptor
16 | void* setupServer(void* na) {
17 | int ret;
18 | struct sockaddr_un server_addr;
19 | int socket_fd;
20 | int data_socket;
21 | uint8_t buffer[BUFFER_SIZE];
22 | uint8_t ret_buffer[BUFFER_SIZE];
23 | char socket_name[108]; // 108 sun_path length max
24 |
25 | LOGI("Start server setup");
26 |
27 | // AF_UNIX for domain unix IPC and SOCK_STREAM since it works for the example
28 | socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
29 | if (socket_fd < 0) {
30 | LOGE("socket: %s", strerror(errno));
31 | exit(EXIT_FAILURE);
32 | }
33 | LOGI("Socket made");
34 |
35 | // NDK needs abstract namespace by leading with '\0'
36 | // Ya I was like WTF! too... http://www.toptip.ca/2013/01/unix-domain-socket-with-abstract-socket.html?m=1
37 | // Note you don't need to unlink() the socket then
38 | memcpy(&socket_name[0], "\0", 1);
39 | strcpy(&socket_name[1], SOCKET_NAME);
40 |
41 | // clear for safty
42 | memset(&server_addr, 0, sizeof(struct sockaddr_un));
43 | server_addr.sun_family = AF_UNIX; // Unix Domain instead of AF_INET IP domain
44 | strncpy(server_addr.sun_path, socket_name, sizeof(server_addr.sun_path) - 1); // 108 char max
45 |
46 | ret = bind(socket_fd, (const struct sockaddr *) &server_addr, sizeof(struct sockaddr_un));
47 | if (ret < 0) {
48 | LOGE("bind: %s", strerror(errno));
49 | exit(EXIT_FAILURE);
50 | }
51 | LOGI("Bind made");
52 |
53 | // Open 8 back buffers for this demo
54 | ret = listen(socket_fd, 8);
55 | if (ret < 0) {
56 | LOGE("listen: %s", strerror(errno));
57 | exit(EXIT_FAILURE);
58 | }
59 | LOGI("Socket listening for packages");
60 |
61 | // Wait for incoming connection.
62 | data_socket = accept(socket_fd, NULL, NULL);
63 | if (data_socket < 0) {
64 | LOGE("accept: %s", strerror(errno));
65 | exit(EXIT_FAILURE);
66 | }
67 | LOGI("Accepted data");
68 | // This is the main loop for handling connections
69 | // Assuming in example connection is established only once
70 | // Would be better to refactor this for robustness
71 | for (;;) {
72 |
73 | // Wait for next data packet
74 | ret = read(data_socket, buffer, BUFFER_SIZE);
75 | if (ret < 0) {
76 | LOGE("read: %s", strerror(errno));
77 | exit(EXIT_FAILURE);
78 | }
79 |
80 | // Data is packed as [file_descriptor][size] or [int][int]
81 |
82 | LOGI("File Descriptor: %d", ((int*)buffer)[0]);
83 | LOGI("Size: %d", ((int*)buffer)[1]);
84 | //copyToColorBuffer();
85 |
86 | // Send back result
87 | sprintf((char*)ret_buffer, "%d", "Got message");
88 | ret = write(data_socket, ret_buffer, BUFFER_SIZE);
89 | if (ret < 0) {
90 | LOGE("write: %s", strerror(errno));
91 | exit(EXIT_FAILURE);
92 | }
93 |
94 | }
95 | close(data_socket);
96 | close(socket_fd);
97 |
98 | return NULL;
99 | }
100 |
101 | // Main function
102 | void android_main(struct android_app* app) {
103 |
104 | // Set the callback to process system events
105 | app->onAppCmd = handle_cmd;
106 |
107 | // Used to poll the events in the main loop
108 | int events;
109 | android_poll_source* source;
110 |
111 | // Start server daemon on new thread
112 | pthread_t server_thread;
113 | pthread_create( &server_thread, NULL, setupServer, (void*) NULL);
114 |
115 | // Main loop
116 | do {
117 | if (ALooper_pollAll(IsNDKReady() ? 1 : 0, nullptr,
118 | &events, (void**)&source) >= 0) {
119 | if (source != NULL) source->process(app, source);
120 | }
121 | } while (app->destroyRequested == 0);
122 |
123 | cleanup();
124 | LOGI( "GAME OVER");
125 | }
126 |
127 |
128 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SharedMem-IPC-Server
3 |
4 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Shared_Memory/SharedMem-IPC-Server/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 08 17:26:13 CDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Shared_Memory/SharedMem-IPC-Server/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Unix_Sockets/README.md:
--------------------------------------------------------------------------------
1 | # Unix Socket IPC
2 |
3 | This example uses `` sockets lib to handle communication between two app processes. I use the `AF_UNIX` Unix Domain which sends the data via the kernel over a file descriptor compared to using the `AF_INET` IP Protocol.
4 |
5 | ## Things to Note
6 |
7 | - The app example atm assumes you open the sever app, then the client app. I didn't build example to handle reconnects or polling for a valid server app in this example.
8 | - You are can only from my testing write a Unix Domain file descriptor to internal storage which is useless since the other app can't see it. You can't write a Unix Domain socket file descriptor to the Public External Storage due to security risk and therefore use an abstracted namespace for the file descriptor. Here is a [GREAT PAPER](http://web.eecs.umich.edu/~yurushao/pubs/sinspector_ccs2016.pdf) on the security of Unix Domain IPC in Android!
9 | - [Slides for paper](http://web.eecs.umich.edu/~yurushao/pubs/sinspector_ccs2016_slides.pdf)
10 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 | .idea/
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
4 | include_directories(${APP_GLUE_DIR})
5 | add_library( app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
6 |
7 | add_library( ClientIPC
8 | SHARED
9 | src/main/cpp/display.cpp
10 | src/main/cpp/native-lib.cpp )
11 |
12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
13 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
14 |
15 | target_link_libraries( ClientIPC
16 | app-glue
17 | log
18 | android)
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.spencerfricke.socket_ipc_client"
7 | minSdkVersion 24
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | externalNativeBuild {
13 | cmake {
14 | cppFlags ""
15 | }
16 | }
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | externalNativeBuild {
25 | cmake {
26 | path "CMakeLists.txt"
27 | }
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: 'libs', include: ['*.jar'])
33 | implementation 'com.android.support:appcompat-v7:26.1.0'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
37 | }
38 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
15 |
16 |
18 |
22 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/cpp/display.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #include "display.h"
6 |
7 | bool IsNDKReady(void) {
8 | // add prep logic
9 | return true;
10 | }
11 |
12 | // Takes the native_window and sets a color
13 | // This is so we can know what square to click
14 | void setColorSections(ANativeWindow* native_window) {
15 |
16 | ANativeWindow_acquire(native_window);
17 | ANativeWindow_Buffer buffer;
18 | if (ANativeWindow_lock(native_window, &buffer, nullptr) < 0) {
19 | LOGE("Failed to lock native window");
20 | return;
21 | }
22 |
23 | LOGI("/// H-W-S-F: %d, %d, %d, %d", buffer.height, buffer.width, buffer.stride, buffer.format);
24 |
25 | // set top left red, top right green, bottom left blue, bottom right yellow
26 | for (int i = 0; i < buffer.height; i++) {
27 |
28 | if (i < buffer.height / 2) {
29 | for (int j = 0; j < buffer.stride; j++) {
30 | if (j < buffer.width / 2) {
31 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[0], sizeof(uint32_t));
32 | } else {
33 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[1], sizeof(uint32_t));
34 | }
35 | }
36 | } else {
37 | for (int j = 0; j < buffer.stride; j++) {
38 | if (j < buffer.width / 2) {
39 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[2], sizeof(uint32_t));
40 | } else {
41 | memcpy((char *) buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[3], sizeof(uint32_t));
42 | }
43 | }
44 | }
45 | }
46 |
47 | ANativeWindow_unlockAndPost(native_window);
48 | ANativeWindow_release(native_window);
49 | }
50 |
51 | // Process the next main command.
52 | void handle_cmd(android_app* app, int32_t cmd) {
53 | switch (cmd) {
54 | case APP_CMD_INIT_WINDOW:
55 | // The window is being shown, get it ready.
56 | LOGI( "Width: %d", ANativeWindow_getWidth(app->window));
57 | LOGI( "Height: %d", ANativeWindow_getHeight(app->window));
58 |
59 | // Here we set the buffer to use RGBX_8888 as default might be; RGB_565
60 | ANativeWindow_setBuffersGeometry(app->window,
61 | ANativeWindow_getHeight(app->window),
62 | ANativeWindow_getWidth(app->window),
63 | WINDOW_FORMAT_RGBX_8888);
64 |
65 | setColorSections(app->window);
66 |
67 | break;
68 | case APP_CMD_TERM_WINDOW:
69 | // The window is being hidden or closed, clean it up.
70 | break;
71 | default:
72 | LOGI("event not handled: %d", cmd);
73 | }
74 | }
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/cpp/display.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #ifndef SOCKET_IPC_CLIENT_DISPLAY_H
6 | #define SOCKET_IPC_CLIENT_DISPLAY_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | // Android log function wrappers
18 | static const char* kTAG = "ClientIPC";
19 | #define LOGI(...) \
20 | ((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
21 | #define LOGW(...) \
22 | ((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
23 | #define LOGE(...) \
24 | ((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
25 |
26 | const uint32_t color_wheel[4] = {
27 | 0x000000FF, // red
28 | 0x0000FF00, // green
29 | 0x00FF0000, // blue
30 | 0x00000FFFF // yellow
31 | };
32 |
33 | bool IsNDKReady(void);
34 |
35 | void setColorSections(ANativeWindow* native_window);
36 |
37 | // Process the next main command.
38 | void handle_cmd(android_app* app, int32_t cmd);
39 |
40 | #endif //SOCKET_IPC_CLIENT_DISPLAY_H
41 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include "display.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | // Can be anything if using abstract namespace
12 | #define SOCKET_NAME "serverSocket"
13 | #define BUFFER_SIZE 16
14 |
15 | static int data_socket;
16 | static struct sockaddr_un server_addr;
17 |
18 | void setupClient(void) {
19 | char socket_name[108]; // 108 sun_path length max
20 |
21 | data_socket = socket(AF_UNIX, SOCK_STREAM, 0);
22 | if (data_socket < 0) {
23 | LOGE("socket: %s", strerror(errno));
24 | exit(EXIT_FAILURE);
25 | }
26 |
27 | // NDK needs abstract namespace by leading with '\0'
28 | // Ya I was like WTF! too... http://www.toptip.ca/2013/01/unix-domain-socket-with-abstract-socket.html?m=1
29 | // Note you don't need to unlink() the socket then
30 | memcpy(&socket_name[0], "\0", 1);
31 | strcpy(&socket_name[1], SOCKET_NAME);
32 |
33 | // clear for safty
34 | memset(&server_addr, 0, sizeof(struct sockaddr_un));
35 | server_addr.sun_family = AF_UNIX; // Unix Domain instead of AF_INET IP domain
36 | strncpy(server_addr.sun_path, socket_name, sizeof(server_addr.sun_path) - 1); // 108 char max
37 |
38 | // Assuming only one init connection for demo
39 | int ret = connect(data_socket, (const struct sockaddr *) &server_addr, sizeof(struct sockaddr_un));
40 | if (ret < 0) {
41 | LOGE("connect: %s", strerror(errno));
42 | exit(EXIT_FAILURE);
43 | }
44 |
45 | LOGI("Client Setup Complete");
46 | }
47 |
48 | void sendColor(uint8_t color) {
49 | int ret;
50 | uint8_t buffer[BUFFER_SIZE];
51 |
52 | LOGI("Color: %d", color);
53 | memcpy(buffer, &color, sizeof(uint8_t));
54 | LOGI("Buffer: %d", buffer[0]);
55 |
56 | ret = write(data_socket, buffer, BUFFER_SIZE);
57 | if (ret < 0) {
58 | LOGE("write: %s", strerror(errno));
59 | exit(EXIT_FAILURE);
60 | }
61 |
62 | ret = read(data_socket, buffer, BUFFER_SIZE);
63 | if (ret < 0) {
64 | LOGE("read: %s", strerror(errno));
65 | exit(EXIT_FAILURE);
66 | }
67 |
68 | LOGI("Return: %s", (char*)buffer);
69 | }
70 |
71 | // Handles input touches to the screen
72 | int32_t handle_input(struct android_app* app, AInputEvent* event) {
73 | if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
74 | if (AInputEvent_getSource(event) == AINPUT_SOURCE_TOUCHSCREEN) {
75 | if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN) {
76 | float x = AMotionEvent_getX(event,0);
77 | float y = AMotionEvent_getY(event,0);
78 | int32_t h_width = ANativeWindow_getWidth(app->window)/2;
79 | int32_t h_height = ANativeWindow_getHeight(app->window)/2;
80 |
81 | // try to compenstate for the touch screen's home and back button on phone
82 | if (y > ANativeWindow_getHeight(app->window) * 0.95) {
83 | return 1;
84 | }
85 |
86 | LOGI("X: %f -- Y: %f", x, y);
87 |
88 | // Sends color depending on region
89 | if (x < h_width && y < h_height) { sendColor(0); }
90 | else if (x > h_width && y < h_height) { sendColor(1); }
91 | else if (x < h_width && y > h_height) { sendColor(2); }
92 | else { sendColor(3); }
93 | }
94 | }
95 | }
96 | return 1;
97 | }
98 |
99 | // Main Function
100 | void android_main(struct android_app* app) {
101 |
102 | // Set the callback to process system events
103 | app->onAppCmd = handle_cmd;
104 | app->onInputEvent = handle_input;
105 |
106 | // Used to poll the events in the main loop
107 | int events;
108 | android_poll_source* source;
109 |
110 | setupClient();
111 |
112 | // Main loop
113 | do {
114 | if (ALooper_pollAll(IsNDKReady() ? 1 : 0, nullptr,
115 | &events, (void**)&source) >= 0) {
116 | if (source != NULL) source->process(app, source);
117 | }
118 | } while (app->destroyRequested == 0);
119 |
120 | close(data_socket);
121 | LOGI( "GAME OVER");
122 | }
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Socket-IPC-Client
3 |
4 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Client/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 07 21:27:15 CDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Client/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 | .idea/
43 |
44 | # Keystore files
45 | *.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
4 | include_directories(${APP_GLUE_DIR})
5 | add_library( app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
6 |
7 | add_library( ServerIPC
8 | SHARED
9 | src/main/cpp/display.cpp
10 | src/main/cpp/native-lib.cpp )
11 |
12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
13 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
14 |
15 | target_link_libraries( ServerIPC
16 | app-glue
17 | log
18 | android)
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.spencerfricke.socket_ipc_server"
7 | minSdkVersion 24
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | externalNativeBuild {
12 | cmake {
13 | cppFlags ""
14 | }
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | externalNativeBuild {
24 | cmake {
25 | path "CMakeLists.txt"
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | }
33 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
13 |
14 |
16 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/cpp/display.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #include "display.h"
6 |
7 | static uint8_t color_selected;
8 |
9 | void setColorSelected(uint8_t color) {
10 | color_selected = color;
11 | }
12 |
13 | bool IsNDKReady(void) {
14 | // add prep logic
15 | return true;
16 | }
17 |
18 | // Takes the native_window and sets a color
19 | // This is so we can know the IPC worked
20 | void setWindowColor(uint8_t color_index) {
21 |
22 | ANativeWindow_acquire(native_window);
23 | ANativeWindow_Buffer buffer;
24 | if (ANativeWindow_lock(native_window, &buffer, nullptr) < 0) {
25 | LOGE("Failed to lock native window");
26 | return;
27 | }
28 |
29 | LOGI("/// H-W-S-F: %d, %d, %d, %d", buffer.height, buffer.width, buffer.stride, buffer.format);
30 |
31 | // set each pixel
32 | for (int i = 0; i < buffer.height; i++) {
33 | for (int j = 0; j < buffer.stride; j++) {
34 | memcpy((char*)buffer.bits + (((i * buffer.stride) + j) * 4), &color_wheel[color_index], sizeof(uint32_t));
35 | }
36 | }
37 |
38 | ANativeWindow_unlockAndPost(native_window);
39 | ANativeWindow_release(native_window);
40 | }
41 |
42 |
43 | // Process the next main command.
44 | void handle_cmd(android_app* app, int32_t cmd) {
45 | switch (cmd) {
46 | case APP_CMD_INIT_WINDOW:
47 | native_window = app->window;
48 | // The window is being shown, get it ready.
49 | LOGI( "Width: %d", ANativeWindow_getWidth(app->window));
50 | LOGI( "Height: %d", ANativeWindow_getHeight(app->window));
51 |
52 | // Here we set the buffer to use RGBX_8888 as default might be; RGB_565
53 | ANativeWindow_setBuffersGeometry(app->window,
54 | ANativeWindow_getHeight(app->window),
55 | ANativeWindow_getWidth(app->window),
56 | WINDOW_FORMAT_RGBX_8888);
57 |
58 | LOGI("Color index to set: %d", color_selected);
59 | setWindowColor(color_selected); // Set screen to color from color_wheel[]
60 |
61 | break;
62 | case APP_CMD_TERM_WINDOW:
63 | // The window is being hidden or closed, clean it up.
64 | break;
65 | default:
66 | LOGI("event not handled: %d", cmd);
67 | }
68 | }
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/cpp/display.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This display file is design to do all the graphical UI display related stuff
3 | * This is to keep the actual IPC code separate for better understanding
4 | */
5 | #ifndef SOCKET_IPC_SERVER_DISPLAY_H
6 | #define SOCKET_IPC_SERVER_DISPLAY_H
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | // Android log function wrappers
18 | static const char* kTAG = "ServerIPC";
19 | #define LOGI(...) \
20 | ((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
21 | #define LOGW(...) \
22 | ((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
23 | #define LOGE(...) \
24 | ((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
25 |
26 | const uint32_t color_wheel[4] = {
27 | 0x000000FF, // red
28 | 0x0000FF00, // green
29 | 0x00FF0000, // blue
30 | 0x00000FFFF // yellow
31 | };
32 |
33 | // color to set when screen goes back to foreground process
34 | void setColorSelected(uint8_t color);
35 |
36 | static ANativeWindow* native_window;
37 |
38 | bool IsNDKReady(void);
39 |
40 | void setWindowColor(uint8_t color_index);
41 |
42 | // Process the next main command.
43 | void handle_cmd(android_app* app, int32_t cmd);
44 |
45 | #endif //SOCKET_IPC_SERVER_DISPLAY_H
46 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include "display.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | // Can be anything if using abstract namespace
12 | #define SOCKET_NAME "serverSocket"
13 | #define BUFFER_SIZE 16
14 |
15 | void* setupServer(void* na) {
16 | int ret;
17 | struct sockaddr_un server_addr;
18 | int socket_fd;
19 | int data_socket;
20 | uint8_t buffer[BUFFER_SIZE];
21 | char socket_name[108]; // 108 sun_path length max
22 |
23 | LOGI("Start server setup");
24 |
25 | // AF_UNIX for domain unix IPC and SOCK_STREAM since it works for the example
26 | socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
27 | if (socket_fd < 0) {
28 | LOGE("socket: %s", strerror(errno));
29 | exit(EXIT_FAILURE);
30 | }
31 | LOGI("Socket made");
32 |
33 | // NDK needs abstract namespace by leading with '\0'
34 | // Ya I was like WTF! too... http://www.toptip.ca/2013/01/unix-domain-socket-with-abstract-socket.html?m=1
35 | // Note you don't need to unlink() the socket then
36 | memcpy(&socket_name[0], "\0", 1);
37 | strcpy(&socket_name[1], SOCKET_NAME);
38 |
39 | // clear for safty
40 | memset(&server_addr, 0, sizeof(struct sockaddr_un));
41 | server_addr.sun_family = AF_UNIX; // Unix Domain instead of AF_INET IP domain
42 | strncpy(server_addr.sun_path, socket_name, sizeof(server_addr.sun_path) - 1); // 108 char max
43 |
44 | ret = bind(socket_fd, (const struct sockaddr *) &server_addr, sizeof(struct sockaddr_un));
45 | if (ret < 0) {
46 | LOGE("bind: %s", strerror(errno));
47 | exit(EXIT_FAILURE);
48 | }
49 | LOGI("Bind made");
50 |
51 | // Open 8 back buffers for this demo
52 | ret = listen(socket_fd, 8);
53 | if (ret < 0) {
54 | LOGE("listen: %s", strerror(errno));
55 | exit(EXIT_FAILURE);
56 | }
57 | LOGI("Socket listening for packages");
58 |
59 | // Wait for incoming connection.
60 | data_socket = accept(socket_fd, NULL, NULL);
61 | if (data_socket < 0) {
62 | LOGE("accept: %s", strerror(errno));
63 | exit(EXIT_FAILURE);
64 | }
65 | LOGI("Accepted data");
66 | // This is the main loop for handling connections
67 | // Assuming in example connection is established only once
68 | // Would be better to refactor this for robustness
69 | for (;;) {
70 |
71 | // Wait for next data packet
72 | ret = read(data_socket, buffer, BUFFER_SIZE);
73 | if (ret < 0) {
74 | LOGE("read: %s", strerror(errno));
75 | exit(EXIT_FAILURE);
76 | }
77 |
78 | LOGI("Buffer: %d", buffer[0]);
79 | setColorSelected(buffer[0]);
80 |
81 | // Send back result
82 | sprintf((char*)buffer, "%d", "Got message");
83 | ret = write(data_socket, buffer, BUFFER_SIZE);
84 | if (ret < 0) {
85 | LOGE("write: %s", strerror(errno));
86 | exit(EXIT_FAILURE);
87 | }
88 |
89 | // Close socket between accepts
90 | }
91 | close(data_socket);
92 | close(socket_fd);
93 |
94 | return NULL;
95 | }
96 |
97 | // Main function
98 | void android_main(struct android_app* app) {
99 |
100 | // Set the callback to process system events
101 | app->onAppCmd = handle_cmd;
102 |
103 | // Used to poll the events in the main loop
104 | int events;
105 | android_poll_source* source;
106 |
107 | setColorSelected(0); // Start with red
108 |
109 | // Start server daemon on new thread
110 | pthread_t server_thread;
111 | pthread_create( &server_thread, NULL, setupServer, (void*) NULL);
112 |
113 | // Main loop
114 | do {
115 | if (ALooper_pollAll(IsNDKReady() ? 1 : 0, nullptr,
116 | &events, (void**)&source) >= 0) {
117 | if (source != NULL) source->process(app, source);
118 | }
119 | } while (app->destroyRequested == 0);
120 |
121 | LOGI( "GAME OVER");
122 | }
123 |
124 |
125 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Socket-IPC-Server
3 |
4 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.2'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/Unix_Sockets/Socket-IPC-Server/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 07 21:29:04 CDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Unix_Sockets/Socket-IPC-Server/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/demo1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/demo1.gif
--------------------------------------------------------------------------------
/demo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjfricke/NDK-Socket-IPC/85ff728cdbca6f1426d6a762277269ccbb07bf12/demo2.gif
--------------------------------------------------------------------------------