Skip to content

Commit 7555c66

Browse files
committed
增加service接口定义,服务接口代理
1 parent f09e32e commit 7555c66

File tree

12 files changed

+171
-0
lines changed

12 files changed

+171
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.devyok.droidipc.services"
3+
android:versionCode="1"
4+
android:versionName="1.0" >
5+
6+
<uses-sdk
7+
android:minSdkVersion="19"
8+
android:targetSdkVersion="21" />
9+
10+
<application
11+
android:allowBackup="true"
12+
android:icon="@drawable/ic_launcher"
13+
android:label="@string/app_name"
14+
android:theme="@style/AppTheme" >
15+
</application>
16+
17+
</manifest>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-23
15+
android.library.reference.1=../droidipc_libcore
16+
android.library=true
Loading
Loading
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
3+
<string name="app_name">droidipc_services</string>
4+
5+
</resources>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.devy.service_interfaces;
2+
3+
import android.os.IInterface;
4+
5+
public interface IActivityServcie extends IInterface{
6+
7+
public static final String ACTION_START_ACTIVITY = "com.devyok.action.START_ACTIVITY";
8+
9+
public int startActivity(String className);
10+
11+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.devy.service_interfaces;
2+
3+
import android.os.Bundle;
4+
import android.os.IBinder;
5+
import android.os.IInterface;
6+
7+
import com.devy.droidipc.BundleColumns;
8+
import com.devy.droidipc.IBundleSender;
9+
10+
class IActivityServiceProxy implements IActivityServcie{
11+
12+
private static IActivityServiceProxy sInstance = new IActivityServiceProxy();
13+
14+
private IBundleSender bundleSender ;
15+
16+
public static IActivityServcie asService(IInterface iInterface) {
17+
sInstance.bundleSender = (IBundleSender) iInterface;
18+
return sInstance;
19+
}
20+
21+
@Override
22+
public IBinder asBinder() {
23+
return bundleSender.asBinder();
24+
}
25+
26+
@Override
27+
public int startActivity(String className) {
28+
29+
Bundle bundle = new Bundle();
30+
bundle.putString(BundleColumns.ACTION, ACTION_START_ACTIVITY);
31+
32+
Bundle result = bundleSender.send(bundle);
33+
return result.getInt(BundleColumns.RESULT);
34+
}
35+
36+
37+
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.devy.service_interfaces;
2+
3+
import android.os.IInterface;
4+
5+
import com.devy.droidipc.ServiceManager;
6+
import com.devy.droidipc.exception.IPCServiceNotFoundException;
7+
8+
public final class IPC {
9+
10+
public static synchronized void onAppReady(Context context){
11+
}
12+
13+
public static final class Context {
14+
public final static String ACTIVITY_SERVICE = "activity_service";
15+
private Context(){}
16+
}
17+
18+
public static IInterface proxyService(String name) throws IPCServiceNotFoundException {
19+
return ServiceManagerProxy.instance.getService(name);
20+
}
21+
22+
static final class ServiceManagerProxy{
23+
24+
private static ServiceManagerProxy instance = new ServiceManagerProxy();
25+
26+
private ServiceManagerProxy(){}
27+
28+
public IInterface getService(String name) throws IPCServiceNotFoundException {
29+
30+
IInterface service = ServiceManager.getService(IPC.Context.ACTIVITY_SERVICE);
31+
32+
if(Context.ACTIVITY_SERVICE.equals(name)) {
33+
IActivityServcie activityServcie = IActivityServiceProxy.asService((service));
34+
return activityServcie;
35+
}
36+
return service;
37+
}
38+
39+
}
40+
41+
}

0 commit comments

Comments
 (0)