├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── devyk
│ │ │ └── ykprobus
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── devyk
│ │ │ └── ykprobus
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── devyk
│ │ └── ykprobus
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── module_a
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── colors.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── devyk
│ │ │ └── module_a
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── devyk
│ │ │ └── module_a
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── devyk
│ │ └── module_a
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── component_eventbus
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── devyk
│ │ │ └── component_eventbus
│ │ │ └── proevent
│ │ │ ├── dispatcher
│ │ │ ├── IMessageHandler.java
│ │ │ └── MessageDispatcher.java
│ │ │ ├── Constants.java
│ │ │ ├── service
│ │ │ ├── MessengerService.java
│ │ │ └── MessengerManager.java
│ │ │ ├── utils
│ │ │ └── ProcessUtils.java
│ │ │ ├── entity
│ │ │ └── BaseMessageEntity.java
│ │ │ ├── EventManager.java
│ │ │ └── local
│ │ │ └── MessageController.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── devyk
│ │ │ └── component_eventbus
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── devyk
│ │ └── component_eventbus
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── encodings.xml
├── vcs.xml
├── runConfigurations.xml
├── gradle.xml
├── codeStyles
│ └── Project.xml
├── misc.xml
└── dbnavigator.xml
├── .gitignore
├── config.gradle
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module_a/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/component_eventbus/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':module_a',':component_eventbus'
2 |
--------------------------------------------------------------------------------
/module_a/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | YKProBus
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/module_a/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module_A
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/component_eventbus/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | component_eventbus
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yangkun19921001/YKProBus/HEAD/module_a/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/module_a/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 11 15:28:49 CST 2019
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-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | android = [
3 | compileSdkVersion: 28,
4 | buildToolsVersion: "28.0.3",
5 | minSdkVersion : 14,
6 | targetSdkVersion : 28,
7 | versionCode : 1,
8 | versionName : "1.0.1"
9 | ]
10 | }
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/module_a/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/test/java/com/devyk/ykprobus/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.devyk.ykprobus;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/module_a/src/test/java/com/devyk/module_a/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.devyk.module_a;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/component_eventbus/src/test/java/com/devyk/component_eventbus/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/module_a/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/dispatcher/IMessageHandler.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.dispatcher;
2 |
3 |
4 | import android.os.Handler;
5 |
6 | /**
7 | *
8 | * author : devyk on 2019-08-09 14:35
9 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
10 | * github : https://github.com/yangkun19921001
11 | * mailbox : yang1001yk@gmail.com
12 | * desc : This is IMessageHandler 负责接收消息的
13 | *
14 | */
15 | public interface IMessageHandler {
16 |
17 | Handler getHandler();
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/devyk/ykprobus/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.devyk.ykprobus;
2 | import android.app.Activity;
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.devyk.component_eventbus.proevent.EventManager;
7 |
8 | public class MainActivity extends Activity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | EventManager.getInstance().bindApplication(getApplicationContext(),"com.devyk.module_a");
15 | }
16 |
17 | public void sendProMessage(View view) {
18 | Bundle bundle = new Bundle();
19 | bundle.putString("message", "进程间开始传递信息");
20 | EventManager.getInstance().sendMessage(0x001, bundle);
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/module_a/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 |
--------------------------------------------------------------------------------
/component_eventbus/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/devyk/ykprobus/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.devyk.ykprobus;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.devyk.ykprobus", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/module_a/src/androidTest/java/com/devyk/module_a/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.devyk.module_a;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.devyk.module_a", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/component_eventbus/src/androidTest/java/com/devyk/component_eventbus/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.devyk.component_eventbus.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/Constants.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent;
2 |
3 | /**
4 | *
5 | * author : devyk on 2019-08-09 10:06
6 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
7 | * github : https://github.com/yangkun19921001
8 | * mailbox : yang1001yk@gmail.com
9 | * desc : This is Constants 对一些常亮提供统一管理
10 | *
11 | */
12 | public class Constants {
13 |
14 |
15 | /**
16 | * 发送接收消息号统一管理
17 | */
18 | public interface IMessageNumber{
19 |
20 | //----------------------- 服务端消息号 -------------------------//
21 | /**
22 | * 注册消息
23 | */
24 | int VIEW_REGISTER_CLIENT_MSG = 0x1991001;// 注册消息
25 | /**
26 | * 销毁消息
27 | */
28 | int VIEW_UNREGISTER_CLIENT_MSG = 0x19921002;// 销毁消息
29 | //消息 TAG
30 | String DISPATCHER_MESSAGE_TAG = "DISPATCHER_MESSAGE_TAG";
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/component_eventbus/build.gradle:
--------------------------------------------------------------------------------
1 |
2 |
3 | apply plugin: 'com.android.library'
4 |
5 | android {
6 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
7 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
8 | useLibrary 'org.apache.http.legacy'
9 |
10 | compileOptions {
11 | targetCompatibility JavaVersion.VERSION_1_8
12 | sourceCompatibility JavaVersion.VERSION_1_8
13 | }
14 |
15 | defaultConfig {
16 | minSdkVersion rootProject.ext.android["minSdkVersion"]
17 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
18 | versionCode rootProject.ext.android["versionCode"]
19 | versionName rootProject.ext.android["versionName"]
20 | javaCompileOptions {
21 | annotationProcessorOptions {
22 | arguments = [moduleName: project.getName()]
23 | }
24 | }
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 |
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/module_a/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/service/MessengerService.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.service;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 | import android.util.Log;
7 |
8 | /**
9 | *
10 | * author : devyk on 2019-08-09 09:46
11 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
12 | * github : https://github.com/yangkun19921001
13 | * mailbox : yang1001yk@gmail.com
14 | * desc : This is Messenger 服务端 处理消息接收并转发
15 | *
16 | */
17 | public class MessengerService extends Service {
18 | private MessengerManager mServiceMessenger;
19 |
20 | private String TAG = "MessengerService";
21 |
22 | @Override
23 | public IBinder onBind(Intent intent) {
24 | return mServiceMessenger.getServiceMessenger().getBinder();
25 | }
26 |
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 | Log.d(TAG,"onCreate");
31 | init();
32 | }
33 |
34 |
35 | /**
36 | * 对服务端做一些初始化操作
37 | */
38 | private void init() {
39 | mServiceMessenger = MessengerManager.getServiceMessenger(getApplicationContext());
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
5 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
6 | useLibrary 'org.apache.http.legacy'
7 |
8 | compileOptions {
9 | targetCompatibility JavaVersion.VERSION_1_8
10 | sourceCompatibility JavaVersion.VERSION_1_8
11 | }
12 |
13 | defaultConfig {
14 | minSdkVersion rootProject.ext.android["minSdkVersion"]
15 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
16 | versionCode rootProject.ext.android["versionCode"]
17 | versionName rootProject.ext.android["versionName"]
18 | javaCompileOptions {
19 | annotationProcessorOptions {
20 | arguments = [moduleName: project.getName()]
21 | }
22 | }
23 | }
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 | implementation project(path: ':component_eventbus')
35 | implementation 'com.github.yangkun19921001:YKProBus:1.0.1'
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/module_a/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
5 | buildToolsVersion rootProject.ext.android["buildToolsVersion"]
6 | useLibrary 'org.apache.http.legacy'
7 |
8 | compileOptions {
9 | targetCompatibility JavaVersion.VERSION_1_8
10 | sourceCompatibility JavaVersion.VERSION_1_8
11 | }
12 |
13 | defaultConfig {
14 | minSdkVersion rootProject.ext.android["minSdkVersion"]
15 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
16 | versionCode rootProject.ext.android["versionCode"]
17 | versionName rootProject.ext.android["versionName"]
18 |
19 | javaCompileOptions {
20 | annotationProcessorOptions {
21 | arguments = [moduleName: project.getName()]
22 | }
23 | }
24 | }
25 |
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 |
33 | }
34 |
35 | dependencies {
36 | implementation fileTree(dir: 'libs', include: ['*.jar'])
37 | // implementation project(path: ':component_eventbus')
38 | implementation 'com.github.yangkun19921001:YKProBus:1.0.1'
39 | }
40 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/utils/ProcessUtils.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.utils;
2 |
3 | import android.app.ActivityManager;
4 | import android.content.Context;
5 |
6 | /**
7 | *
8 | * author : devyk on 2019-08-11 13:17
9 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
10 | * github : https://github.com/yangkun19921001
11 | * mailbox : yang1001yk@gmail.com
12 | * desc : This is ProcessUtils
13 | *
14 | */
15 | public class ProcessUtils {
16 |
17 | /**
18 | * 当前进程名称
19 | */
20 | private static String procName;
21 |
22 |
23 | /**
24 | * 获取当前进程 pid
25 | */
26 | public static int getProPid(){
27 | return android.os.Process.myPid();
28 | }
29 |
30 |
31 | /**
32 | * 获取当前进程名称
33 | */
34 | public static String getProName(Context context){
35 | ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
36 | for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager
37 | .getRunningAppProcesses()) {
38 | if (appProcess.pid == getProPid()) {
39 | procName = appProcess.processName;
40 | }
41 | }
42 | return procName;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/module_a/src/main/java/com/devyk/module_a/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.devyk.module_a;
2 |
3 |
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.os.Message;
8 | import android.widget.Toast;
9 |
10 | import com.devyk.component_eventbus.proevent.EventManager;
11 | import com.devyk.component_eventbus.proevent.dispatcher.IMessageHandler;
12 |
13 | public class MainActivity extends Activity implements IMessageHandler {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 | EventManager.getInstance().registerMessager(0x001, this);
20 | }
21 |
22 |
23 | /**
24 | * 接收其它进程发送过来的消息
25 | *
26 | * @return
27 | */
28 | @Override
29 | public Handler getHandler() {
30 | return new Handler() {
31 | @Override
32 | public void handleMessage(Message msg) {
33 | super.handleMessage(msg);
34 | switch (msg.what) {
35 | case 0x001:
36 | if (msg.getData() != null && msg.getData().getString("message") != null) {
37 | String message = msg.getData().getString("message");
38 | Toast.makeText(getApplicationContext(), "收到其它进程发送过来的消息:" + message, Toast.LENGTH_SHORT).show();
39 | }
40 | break;
41 | }
42 | }
43 | };
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/module_a/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/entity/BaseMessageEntity.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.entity;
2 |
3 | import android.os.Bundle;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 |
7 | /**
8 | *
9 | * author : devyk on 2019-08-09 14:02
10 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
11 | * github : https://github.com/yangkun19921001
12 | * mailbox : yang1001yk@gmail.com
13 | * desc : This is BaseMessageEntity 负责在 服务端跟客服端传递消息的实体类
14 | *
15 | */
16 | public class BaseMessageEntity implements Parcelable {
17 |
18 | /**
19 | * 消息类型,也就是注册的那个类中
20 | */
21 | private int messageType;
22 |
23 | /**
24 | * 消息实体
25 | */
26 | private Bundle message;
27 |
28 | public BaseMessageEntity(int messageType, Bundle message) {
29 | this.messageType = messageType;
30 | this.message = message;
31 | }
32 |
33 | public BaseMessageEntity() {
34 | }
35 |
36 | public int getMessageType() {
37 | return messageType;
38 | }
39 |
40 | public void setMessageType(int messageType) {
41 | this.messageType = messageType;
42 | }
43 |
44 | public Bundle getMessage() {
45 | return message;
46 | }
47 |
48 | public void setMessage(Bundle message) {
49 | this.message = message;
50 | }
51 |
52 | @Override
53 | public int describeContents() {
54 | return 0;
55 | }
56 |
57 | @Override
58 | public void writeToParcel(Parcel dest, int flags) {
59 | dest.writeInt(this.messageType);
60 | dest.writeBundle(this.message);
61 | }
62 |
63 | protected BaseMessageEntity(Parcel in) {
64 | this.messageType = in.readInt();
65 | this.message = in.readBundle();
66 | }
67 |
68 | public static final Creator CREATOR = new Creator() {
69 | @Override
70 | public BaseMessageEntity createFromParcel(Parcel source) {
71 | return new BaseMessageEntity(source);
72 | }
73 |
74 | @Override
75 | public BaseMessageEntity[] newArray(int size) {
76 | return new BaseMessageEntity[size];
77 | }
78 | };
79 | }
80 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/dispatcher/MessageDispatcher.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.dispatcher;
2 |
3 | import android.os.Message;
4 | import android.os.Messenger;
5 | import android.util.Log;
6 |
7 | import com.devyk.component_eventbus.proevent.local.MessageController;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | *
13 | * author : devyk on 2019-08-09 14:19
14 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
15 | * github : https://github.com/yangkun19921001
16 | * mailbox : yang1001yk@gmail.com
17 | * desc : This is MessageDispatcher 负责服务端的消息转发到注册模块中去
18 | *
19 | */
20 | public class MessageDispatcher {
21 |
22 | private static MessageDispatcher sMessageDispatcher;
23 | private String TAG = "MessageDispatcher";
24 |
25 |
26 | /**
27 | * 单例
28 | */
29 | public static synchronized MessageDispatcher getInstance() {
30 | if (sMessageDispatcher == null) {
31 | sMessageDispatcher = new MessageDispatcher();
32 | }
33 | return sMessageDispatcher;
34 | }
35 |
36 |
37 | /**
38 | * 将消息反馈到本地端
39 | *
40 | * @param mClients 需要发送到本地端
41 | * @param msg
42 | */
43 | public void dispatchMessage(List mClients, Message msg) {
44 | //拿到需要转发到注册接收消息处
45 | Log.d(TAG,"收到客服端的信使对象" + mClients.size());
46 | if (msg != null) {
47 | Message obtain = Message.obtain();
48 | obtain.what = msg.what;
49 | obtain.setData(msg.getData());
50 | try {
51 | if (mClients.size() == 1) {
52 | if (mClients.get(0) != null) {
53 | mClients.get(0).send(obtain);
54 | }
55 | } else {
56 | while (mClients.iterator().hasNext()) {
57 | mClients.iterator().next().send(obtain);
58 | }
59 | }
60 |
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | }
64 | }
65 | }
66 |
67 |
68 | /**
69 | * 将消息下发到消息控制器转发
70 | * @param message
71 | */
72 | public void dispatchMessageToRegister(Message message){
73 | MessageController.getInstance().dispatchMessageToRegister(message);
74 | }
75 |
76 | /**
77 | * 将消息发送到本地端
78 | */
79 | public void sendMessageLocal() {
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/EventManager.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.Message;
6 | import android.os.RemoteException;
7 | import android.util.Log;
8 |
9 | import com.devyk.component_eventbus.proevent.local.MessageController;
10 |
11 |
12 | /**
13 | *
14 | * author : devyk on 2019-08-08 22:33
15 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
16 | * github : https://github.com/yangkun19921001
17 | * mailbox : yang1001yk@gmail.com
18 | * desc : This is EventManager 组件间/进程间 通信管理类
19 | *
20 | */
21 | public class EventManager {
22 |
23 | private final String TAG = getClass().getSimpleName();
24 | private static EventManager instance;
25 |
26 |
27 | /**
28 | * 定义一个单例
29 | */
30 | public static synchronized EventManager getInstance() {
31 | if (instance == null)
32 | instance = new EventManager();
33 | return instance;
34 | }
35 |
36 | /**
37 | * 框架初始化
38 | */
39 | public void bindApplication(Context context,String proName) {
40 | if (context == null)
41 | throw new NullPointerException("init error,context is not null?");
42 | MessageController.getInstance().bindApplication(context,proName);
43 | }
44 |
45 | /**
46 | * 框架销毁 不在使用
47 | */
48 | public void unBindApplication() {
49 | MessageController.getInstance().unBindApplication();
50 | }
51 |
52 | /**
53 | * 注册消息
54 | * 在需要的地方注册消息
55 | */
56 | public void registerMessager(int messageType,Object object) {
57 | MessageController.getInstance().registerMessager(messageType,object);
58 | }
59 |
60 | /**
61 | * 反注册消息
62 | */
63 | public void unRegisterMessager(int messageType) {
64 | MessageController.getInstance().unRegisterMessager(messageType);
65 | }
66 |
67 |
68 | /**
69 | * 发送消息
70 | */
71 | public void sendMessage(int what, Bundle entity) {
72 | Message message = new Message();
73 | message.what = what;
74 | message.setData(entity);
75 |
76 | if (MessageController.getInstance().getServiceMessenger() != null) {
77 | try {
78 | MessageController.getInstance().getServiceMessenger().send(message);
79 | } catch (RemoteException e) {
80 | e.printStackTrace();
81 | Log.e(TAG, e.getMessage());
82 | }
83 | }
84 | }
85 |
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/service/MessengerManager.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.service;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.os.Messenger;
7 | import android.util.Log;
8 |
9 |
10 | import com.devyk.component_eventbus.proevent.Constants;
11 | import com.devyk.component_eventbus.proevent.dispatcher.MessageDispatcher;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | *
18 | * author : devyk on 2019-08-09 09:50
19 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
20 | * github : https://github.com/yangkun19921001
21 | * mailbox : yang1001yk@gmail.com
22 | * desc : This is MessengerManager
23 | *
24 | * 信使管理类
25 | * 1. 单例模式管理信使
26 | * 2. 初始化各个模块(是在Service启动时调用)
27 | * 3. 将从View接收到的消息传递到 MessageDispatcher
28 | * 4. 将消息发送到注册接收的地方
29 | *
30 | */
31 | public class MessengerManager {
32 |
33 | /**
34 | * LOG TAG
35 | */
36 | private String TAG = getClass().getSimpleName();
37 |
38 | /**
39 | * 服务端 Messenger
40 | */
41 | private Messenger mServiceMessenger;
42 |
43 | /**
44 | * 信使管理
45 | */
46 | private static MessengerManager mMessengerManager;
47 |
48 | /**
49 | * 本地端信使列表
50 | */
51 | private List mClients = new ArrayList() {
52 | };
53 |
54 | /**
55 | * 对外暴露信使管理
56 | *
57 | * @param context
58 | * @return
59 | */
60 | public static synchronized MessengerManager getServiceMessenger(Context context) {
61 | if (mMessengerManager == null)
62 | mMessengerManager = new MessengerManager();
63 | return mMessengerManager;
64 | }
65 |
66 | /**
67 | * 初始化服务端 Messenger
68 | */
69 | public MessengerManager() {
70 | if (null == mServiceMessenger)
71 | mServiceMessenger = new Messenger(mMessengerServiceHandler);
72 | }
73 |
74 | /**
75 | * 得到服务端信使对象
76 | */
77 | public Messenger getServiceMessenger() {
78 | return mServiceMessenger;
79 | }
80 |
81 |
82 | /**
83 | * 接收客服端发来的消息
84 | */
85 | public Handler mMessengerServiceHandler = new Handler() {
86 | @Override
87 | public void handleMessage(Message msg) {
88 | super.handleMessage(msg);
89 | switch (msg.what) {
90 | //需要接收消息转发的注册
91 | case Constants
92 | .IMessageNumber.VIEW_REGISTER_CLIENT_MSG:
93 | registerMessenger(msg.replyTo);
94 | break;
95 |
96 | //需要销毁消息
97 | case Constants
98 | .IMessageNumber.VIEW_UNREGISTER_CLIENT_MSG:
99 | unRegisterMessenger(msg.replyTo);
100 | break;
101 | default:
102 | dispatcherMessage(msg);
103 | break;
104 | }
105 | }
106 | };
107 |
108 | /**
109 | * 收到其它消息就直接下发到注册的接收的地方
110 | *
111 | * @param msg
112 | */
113 | private void dispatcherMessage(Message msg) {
114 | Log.d(TAG, "当前信使所有对象个数 " + mClients.size());
115 | Message message = new Message();
116 | message.setData(msg.getData());
117 | message.what = msg.what;
118 | MessageDispatcher.getInstance().dispatchMessageToRegister(message);
119 | }
120 |
121 |
122 | /**
123 | * 注册信使
124 | *
125 | * @param messenger 本地端的信使
126 | */
127 | private void registerMessenger(Messenger messenger) {
128 | if (null != messenger) {
129 | mClients.add(messenger);
130 | Log.d(TAG, "收到客服端的信使对象");
131 | }
132 | }
133 |
134 | /**
135 | * 将消息发送出去
136 | */
137 |
138 | /**
139 | * 销毁信使
140 | *
141 | * @param messenger
142 | */
143 | private void unRegisterMessenger(Messenger messenger) {
144 | if (null != messenger)
145 | mClients.remove(messenger);
146 |
147 | }
148 |
149 | /**
150 | * 销毁所有
151 | */
152 | private void clearAllMessenger() {
153 | //先判断是信使列表是否存在
154 | if (mClients.size() > 0) {
155 | mClients.clear();
156 | }
157 |
158 | }
159 |
160 |
161 | /**
162 | * 销毁事务
163 | */
164 | public void onMessagerManagerOnDestory() {
165 | if (null != mMessengerServiceHandler) {
166 | mMessengerServiceHandler.removeCallbacksAndMessages(null);
167 | mMessengerServiceHandler = null;
168 | }
169 |
170 | clearAllMessenger();
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/module_a/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 概述
2 |
3 | 现在多进程传递数据使用越来越广泛了,在 Android 中进程间通信提供了 `文件` 、`AIDL` 、`Binder` 、`Messenger` 、`ContentProvider` 、`Socket` 、`MemoryFile` 等,实际开发中使用最多的应该是 AIDL ,但是 AIDL 需要编写 aidl 文件,如果使用 AIDL 仅仅是为了传递数据, 那么 [YKProBus](https://github.com/yangkun19921001/YKProBus) 是你不错的选择。
4 |
5 | ## YKProBus
6 |
7 | ### 怎么使用?
8 |
9 | 
10 |
11 | #### 1. root/build.gradle 中添加框架 maven
12 |
13 | ```java
14 | allprojects {
15 | repositories {
16 | ...
17 | maven { url 'https://jitpack.io' }
18 | }
19 | }
20 | ```
21 |
22 | #### 2. app/build.gradle 中添加框架 依赖
23 |
24 | ```java
25 | dependencies {
26 | implementation 'com.github.yangkun19921001:YKProBus:1.0.1'
27 | }
28 | ```
29 |
30 | #### 3. 发送进程绑定接收进程服务
31 |
32 | ```java
33 | EventManager.getInstance().bindApplication(Context context,String proName);
34 | ```
35 |
36 | #### 4. 发送消息
37 |
38 | ```java
39 | EventManager.getInstance().sendMessage(int messageTag,Bundle bundle);
40 | ```
41 |
42 | #### 5. 接收进程中需要在清单文件注册服务
43 |
44 | ```java
45 |
49 |
50 |
51 |
52 |
53 |
54 | ```
55 |
56 | #### 6. 接收消息
57 |
58 | 6.1 在需要接收消息的类中实现 IMessageHandler 并实例化一个 Handler 用于接收发送进程发来的消息
59 |
60 | ```java
61 | public class MainActivity extends Activity implements IMessageHandler{
62 | ...
63 |
64 |
65 | /**
66 | * 接收其它进程发送过来的消息
67 | *
68 | * @return
69 | */
70 | @Override
71 | public Handler getHandler() {
72 | return new Handler() {
73 | @Override
74 | public void handleMessage(Message msg) {
75 | super.handleMessage(msg);
76 | switch (msg.what) {
77 | case 0x001:
78 | ...
79 | break;
80 | }
81 | }
82 | };
83 | }
84 | ...
85 | }
86 | ```
87 |
88 | 6.2 注册当前类需要接收消息
89 |
90 | ```java
91 | EventManager.getInstance().registerMessager(int messageTag, Object obj);
92 | ```
93 |
94 |
95 |
96 | ### 框架设计大概流程
97 |
98 | [](https://free.imgsha.com/i/z9RYd)
99 |
100 | ## Messenger 源码分析
101 |
102 | Messenger 内部其实也是依赖 aidl 实现的进程间通信。
103 |
104 | ### 服务端
105 |
106 | ```java
107 | @Override
108 | public IBinder onBind(Intent intent) {
109 | return mServiceMessenger.getServiceMessenger().getBinder();
110 | }
111 | ```
112 |
113 | getBinder() 跟进去
114 |
115 | ```java
116 | public IBinder getBinder() {
117 | return mTarget.asBinder();
118 | }
119 | ```
120 |
121 | mTarget 从何而来,从源码找找
122 |
123 | ```java
124 | public Messenger(Handler target) {
125 | mTarget = target.getIMessenger();
126 | }
127 | ```
128 |
129 | 这里是我们实例化 服务端 Messenger 传入的 Handler target
130 |
131 | ```java
132 | /**
133 | * 初始化服务端 Messenger
134 | */
135 | public MessengerManager() {
136 | if (null == mServiceMessenger)
137 | mServiceMessenger = new Messenger(mMessengerServiceHandler);
138 | }
139 | ```
140 |
141 | 那么我们在点击 getIMessenger() 在看看内部实现
142 |
143 | ```java
144 | final IMessenger getIMessenger() {
145 | synchronized (mQueue) {
146 | if (mMessenger != null) {
147 | return mMessenger;
148 | }
149 | mMessenger = new MessengerImpl();
150 | return mMessenger;
151 | }
152 | }
153 |
154 | ```
155 |
156 | 继续点击 MessengerImple
157 |
158 | ```java
159 | private final class MessengerImpl extends IMessenger.Stub {
160 | public void send(Message msg) {
161 | msg.sendingUid = Binder.getCallingUid();
162 | Handler.this.sendMessage(msg);
163 | }
164 | }
165 | ```
166 |
167 | 这个是一个内部实现的类,可以看到继承的是 IMessenger.Stub 然后实现 send (Message msg) 函数,然后通过 mTarget.sendMessage(msg) 发送消息,最后在我们传入进去的 mMessengerServiceHandler 的 handleMessage (Message) 接收发来的消息。
168 |
169 | 既然这里内部帮我们写了 aidl 文件 ,并且也继承了 IMessenger.Stub 我们今天就要看到 aidl 才死心 , 好吧我们来找找 IMessenger aidl 文件。
170 |
171 | [](https://free.imgsha.com/i/z9LB1)
172 |
173 | 可以看到是在 framework/base/core/java/android/os 路径中,我们点击在来看下文件中怎么写的
174 |
175 | 
176 |
177 | 内部就一个 send 函数,看到这,大家应该都明白了,Messenger 其实也没什么大不了,就是系统内部帮我们写了 aidl 并且也实现了 aidl ,最后又帮我们做了一个 Handler 线程间通信,所以服务端收到了客服端发来的消息。
178 |
179 | ### 客服端
180 |
181 | 客服端需要在 bindServicer onServiceConnected 回调中拿到 servicer, 平时我们自己写 应该是这么拿到 Ibinder 对象吧
182 |
183 | ```java
184 | IMessenger mServiceMessenger = IMessenger.Stub.asInterface(service);
185 | ```
186 |
187 | 但是我们实际客服端是这样拿到服务端的 Messenger
188 |
189 | ```java
190 | /**
191 | * 服务端消息是否连接成功
192 | */
193 | private class EventServiceConnection implements ServiceConnection {
194 | @Override
195 | public void onServiceConnected(ComponentName name, IBinder service) {
196 | isBindApplication = true;
197 | // 得到服务信使对象
198 | mServiceMessenger = new Messenger(service);
199 |
200 | //将本地信使告诉服务端
201 | registerMessenger();
202 |
203 | String proName = ProcessUtils.getProName(mApplicationContext);
204 | Log.d(TAG, " EventServiceConnection " + proName);
205 |
206 | }
207 |
208 | @Override
209 | public void onServiceDisconnected(ComponentName name) {
210 | isBindApplication = false;
211 | }
212 | }
213 | ```
214 |
215 | ```java
216 | // 得到服务信使对象
217 | mServiceMessenger = new Messenger(service);
218 | ```
219 |
220 | 跟进去
221 |
222 | ```java
223 | public Messenger(IBinder target) {
224 | mTarget = IMessenger.Stub.asInterface(target);
225 | }
226 | ```
227 |
228 | 这不就是我们刚刚说的自己实现的那种写法吧,到这里我们都懂了吧,我们平时写的 aidl android 中已经帮我们写了,想当于在 aidl 中封装下就变成了现在的 Messenger , 而我们又在 Messenger 上封装了下,想当于 三次封装了,为了使用更简单。封装才是王道!
229 |
230 | ## 总结
231 |
232 | 我们自己的 [YKProBus](https://github.com/yangkun19921001/YKProBus) 为了进程间通信使用更简单方便,其实相当于在 AIDL 中的三次封装。想要了解的可以去看下我具体的封装或者 Messenger 源码。
233 |
234 | 感谢大家抽空阅览文章,谢谢!
--------------------------------------------------------------------------------
/component_eventbus/src/main/java/com/devyk/component_eventbus/proevent/local/MessageController.java:
--------------------------------------------------------------------------------
1 | package com.devyk.component_eventbus.proevent.local;
2 |
3 | import android.content.ComponentName;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.ServiceConnection;
7 | import android.os.Handler;
8 | import android.os.IBinder;
9 | import android.os.Message;
10 | import android.os.Messenger;
11 | import android.os.RemoteException;
12 | import android.text.TextUtils;
13 | import android.util.Log;
14 |
15 | import com.devyk.component_eventbus.proevent.Constants;
16 | import com.devyk.component_eventbus.proevent.dispatcher.IMessageHandler;
17 | import com.devyk.component_eventbus.proevent.utils.ProcessUtils;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | /**
23 | *
24 | * author : devyk on 2019-08-09 15:37
25 | * blog : https://juejin.im/user/578259398ac2470061f3a3fb/posts
26 | * github : https://github.com/yangkun19921001
27 | * mailbox : yang1001yk@gmail.com
28 | * desc : This is MessageController 接收来自服务端的消息负责转发
29 | *
30 | */
31 | public class MessageController {
32 |
33 | private static MessageController instance;
34 | private Context mApplicationContext;
35 | private Messenger mServiceMessenger;
36 |
37 | private String TAG = getClass().getSimpleName();
38 |
39 | /**
40 | * 缓存当前注册的 class
41 | */
42 | private Map mCacheMessageHandler = new HashMap();
43 |
44 |
45 | /**
46 | * 是否绑定成功
47 | */
48 | private boolean isBindApplication = false;
49 | private EventServiceConnection mEventServiceConnection;
50 | private Messenger mLocalMessenger;
51 | private LocalMessengerHandler mLocalMessengerHandler;
52 | private Intent service;
53 |
54 | public static synchronized MessageController getInstance() {
55 | if (instance == null)
56 | instance = new MessageController();
57 |
58 | return instance;
59 | }
60 |
61 |
62 | /**
63 | * 框架绑定 需要跟 sendMessage 在同一个进程
64 | */
65 | public void bindApplication(Context context, String proName) {
66 | if (context == null || TextUtils.isEmpty(proName))
67 | throw new NullPointerException("init error,context or proName is null?");
68 | //已经绑定成功就不需要在绑定了
69 | if (isBindApplication) return;
70 | try {
71 | initLocalMessenger();
72 | mEventServiceConnection = new EventServiceConnection();
73 | mApplicationContext = context.getApplicationContext();
74 | service = new Intent();
75 | service.setAction("com.devyk.component_eventbus.service");
76 | service.setPackage(proName);
77 | mApplicationContext.startService(service);
78 | mApplicationContext.bindService(service, mEventServiceConnection, 0);
79 | } catch (Exception e) {
80 | Log.e(TAG, e.getMessage());
81 | }
82 |
83 | }
84 |
85 | private void initLocalMessenger() {
86 | mLocalMessengerHandler = new LocalMessengerHandler();
87 | mLocalMessenger = new Messenger(mLocalMessengerHandler);
88 | }
89 |
90 | private Messenger getLocalMessenger() {
91 | return mLocalMessenger;
92 | }
93 |
94 | private Handler getLocalMessengerHandler() {
95 | return mLocalMessengerHandler;
96 | }
97 |
98 | /**
99 | * 框架销毁 不在使用
100 | */
101 | public void unBindApplication() {
102 | if (mEventServiceConnection != null) {
103 | mApplicationContext.unbindService(mEventServiceConnection);
104 | mLocalMessengerHandler.removeCallbacksAndMessages(null);
105 | mLocalMessengerHandler = null;
106 | mApplicationContext.stopService(service);
107 | }
108 | }
109 |
110 |
111 | /**
112 | * 向服务器注册一个信使,用来传递从Service到View的消息
113 | */
114 | private void registerMessenger() {
115 | // 注册消息号:Content.MSG_REGISTER_CTRL
116 | Message message = Message.obtain(null, Constants.IMessageNumber.VIEW_REGISTER_CLIENT_MSG);
117 | //拿到当前进程的 pid
118 | message.arg1 = android.os.Process.myPid();
119 | // 传递自己的信使到服务端
120 | message.replyTo = getLocalMessenger();
121 | try {
122 | getServiceMessenger().send(message);
123 | } catch (RemoteException e) {
124 | e.printStackTrace();
125 | }
126 | }
127 |
128 |
129 | /**
130 | * 注册消息
131 | * 在需要的地方注册消息
132 | */
133 | public void registerMessager(Integer tag, Object object) {
134 | if (object == null) {
135 | throw new NullPointerException("registerMessager is null");
136 | }
137 |
138 | IMessageHandler iMessageHandler = null;
139 |
140 | if (object instanceof IMessageHandler)
141 | iMessageHandler = (IMessageHandler) object;
142 |
143 | if (iMessageHandler == null)
144 | throw new NullPointerException(" IMessageHandler is null?");
145 |
146 | if (!mCacheMessageHandler.containsKey(tag)) {
147 | mCacheMessageHandler.put(tag, iMessageHandler);
148 | }
149 | }
150 |
151 |
152 | /**
153 | * 将消息转发到注册的地方上去
154 | *
155 | * @param message
156 | */
157 | public void dispatchMessageToRegister(Message message) {
158 | if (message != null) {
159 | if (mCacheMessageHandler.containsKey(message.what)) {
160 | Handler handler = mCacheMessageHandler.get(message.what).getHandler();
161 | Message dispatchMessage = handler.obtainMessage();
162 | dispatchMessage.what = message.what;
163 | dispatchMessage.setData(message.getData());
164 | dispatchMessage.sendToTarget();
165 | }
166 | }
167 | }
168 |
169 |
170 | /**
171 | * 反注册消息
172 | */
173 | public void unRegisterMessager(int tag) {
174 | if (mCacheMessageHandler.containsKey(tag)) {
175 | mCacheMessageHandler.remove(tag);
176 |
177 | }
178 |
179 | }
180 |
181 |
182 | /**
183 | * 得到服务端的消息信使
184 | *
185 | * @return
186 | */
187 | public Messenger getServiceMessenger() {
188 | return mServiceMessenger;
189 | }
190 |
191 |
192 | /**
193 | * 接收到服务端传递过来的消息
194 | */
195 | private class LocalMessengerHandler extends Handler {
196 | @Override
197 | public void handleMessage(Message msg) {
198 | super.handleMessage(msg);
199 | String proName = ProcessUtils.getProName(mApplicationContext);
200 | Log.d(TAG, " LocalMessengerHandler " + proName);
201 | Log.d(TAG, "收到服务端发来的消息" + msg.what);
202 |
203 | }
204 | }
205 |
206 | /**
207 | * 服务端消息是否连接成功
208 | */
209 | private class EventServiceConnection implements ServiceConnection {
210 | @Override
211 | public void onServiceConnected(ComponentName name, IBinder service) {
212 | isBindApplication = true;
213 | // 得到服务信使对象
214 | mServiceMessenger = new Messenger(service);
215 |
216 | //将本地信使告诉服务端
217 | registerMessenger();
218 |
219 | String proName = ProcessUtils.getProName(mApplicationContext);
220 | Log.d(TAG, " EventServiceConnection " + proName);
221 |
222 | }
223 |
224 | @Override
225 | public void onServiceDisconnected(ComponentName name) {
226 | isBindApplication = false;
227 | }
228 | }
229 |
230 | }
231 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Abstraction issuesJava
10 |
11 |
12 | Android
13 |
14 |
15 | Assignment issuesJava
16 |
17 |
18 | Bitwise operation issuesJava
19 |
20 |
21 | Class metricsJava
22 |
23 |
24 | Class structureJava
25 |
26 |
27 | Cloning issuesJava
28 |
29 |
30 | Code maturityJava
31 |
32 |
33 | Code style issuesJava
34 |
35 |
36 | Compiler issuesJava
37 |
38 |
39 | Concurrency annotation issuesJava
40 |
41 |
42 | Control flow issuesJava
43 |
44 |
45 | CorrectnessLintAndroid
46 |
47 |
48 | Data flowJava
49 |
50 |
51 | Declaration redundancyJava
52 |
53 |
54 | Dependency issuesJava
55 |
56 |
57 | EncapsulationJava
58 |
59 |
60 | Error handlingJava
61 |
62 |
63 | FinalizationJava
64 |
65 |
66 | GPathGroovy
67 |
68 |
69 | General
70 |
71 |
72 | GeneralJava
73 |
74 |
75 | Google Cloud Endpoints
76 |
77 |
78 | Gradle
79 |
80 |
81 | GradleMigrationKotlin
82 |
83 |
84 | Groovy
85 |
86 |
87 | ImportsJava
88 |
89 |
90 | Inheritance issuesJava
91 |
92 |
93 | InitializationJava
94 |
95 |
96 | InternationalizationJava
97 |
98 |
99 | InternationalizationLintAndroid
100 |
101 |
102 | InteroperabilityLintAndroid
103 |
104 |
105 | J2ME issuesJava
106 |
107 |
108 | JNIAndroid
109 |
110 |
111 | JUnitJava
112 |
113 |
114 | Java
115 |
116 |
117 | Java 10Java language level migration aidsJava
118 |
119 |
120 | Java 11Java language level migration aidsJava
121 |
122 |
123 | Java 5Java language level migration aidsJava
124 |
125 |
126 | Java 7Java language level migration aidsJava
127 |
128 |
129 | Java 8Java language level migration aidsJava
130 |
131 |
132 | Java 9Java language level migration aidsJava
133 |
134 |
135 | Java interop issuesKotlin
136 |
137 |
138 | Java language level issuesJava
139 |
140 |
141 | Java language level migration aidsJava
142 |
143 |
144 | JavaBeans issuesJava
145 |
146 |
147 | JavadocJava
148 |
149 |
150 | Kotlin
151 |
152 |
153 | Kotlin InteroperabilityInteroperabilityLintAndroid
154 |
155 |
156 | Language Injection
157 |
158 |
159 | LintAndroid
160 |
161 |
162 | LoggingJava
163 |
164 |
165 | Manifest
166 |
167 |
168 | MemoryJava
169 |
170 |
171 | MessagesCorrectnessLintAndroid
172 |
173 |
174 | Method metricsJava
175 |
176 |
177 | MigrationKotlin
178 |
179 |
180 | Modularization issuesJava
181 |
182 |
183 | Naming conventionsGroovy
184 |
185 |
186 | Naming conventionsJava
187 |
188 |
189 | Numeric issuesJava
190 |
191 |
192 | Packaging issuesJava
193 |
194 |
195 | PerformanceJava
196 |
197 |
198 | PerformanceLintAndroid
199 |
200 |
201 | PortabilityJava
202 |
203 |
204 | Potentially confusing code constructsGroovy
205 |
206 |
207 | Probable bugsGradle
208 |
209 |
210 | Probable bugsGroovy
211 |
212 |
213 | Probable bugsJava
214 |
215 |
216 | Probable bugsKotlin
217 |
218 |
219 | Properties Files
220 |
221 |
222 | Properties FilesJava
223 |
224 |
225 | Reflective accessJava
226 |
227 |
228 | Resource managementJava
229 |
230 |
231 | SecurityJava
232 |
233 |
234 | SecurityLintAndroid
235 |
236 |
237 | Serialization issuesJava
238 |
239 |
240 | Style issuesKotlin
241 |
242 |
243 | StyleGroovy
244 |
245 |
246 | TestNGJava
247 |
248 |
249 | Threading issuesGroovy
250 |
251 |
252 | Threading issuesJava
253 |
254 |
255 | UsabilityLintAndroid
256 |
257 |
258 | Verbose or redundant code constructsJava
259 |
260 |
261 | VisibilityJava
262 |
263 |
264 | toString() issuesJava
265 |
266 |
267 |
268 |
269 | Android
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
--------------------------------------------------------------------------------
/.idea/dbnavigator.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 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
--------------------------------------------------------------------------------