├── DroidService ├── .gitignore ├── Libraries │ └── droidservices │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── morgoo │ │ │ └── droidservices │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── aidl │ │ │ └── com │ │ │ │ └── morgoo │ │ │ │ └── droidservices │ │ │ │ └── IServiceManager.aidl │ │ ├── java │ │ │ └── com │ │ │ │ └── morgoo │ │ │ │ └── droidservices │ │ │ │ ├── CompatUtils.java │ │ │ │ ├── ContentProviderBinderTransact.java │ │ │ │ ├── IServiceManagerImpl.java │ │ │ │ ├── ServiceItem.java │ │ │ │ └── ServiceManager.java │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── morgoo │ │ └── droidservices │ │ └── ExampleUnitTest.java ├── app │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── morgoo │ │ │ └── droidservicetest │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── morgoo │ │ │ │ └── droidservicetest │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainActivityFragment.java │ │ └── res │ │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ ├── content_main.xml │ │ │ └── fragment_main.xml │ │ │ ├── menu │ │ │ └── menu_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-v21 │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── morgoo │ │ └── droidservicetest │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── LICENSE └── readme.md /DroidService/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /bin 8 | /captures 9 | /gradle 10 | /Libraries/droidservices/bin 11 | /app/bin 12 | 13 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 10 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | } 24 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Program_Files\android-sdk-windows/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/androidTest/java/com/morgoo/droidservices/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/aidl/com/morgoo/droidservices/IServiceManager.aidl: -------------------------------------------------------------------------------- 1 | // IServiceManager.aidl 2 | package com.morgoo.droidservices; 3 | 4 | import android.os.IBinder; 5 | import android.content.Intent; 6 | 7 | interface IServiceManager { 8 | 9 | void addService(in String callingPackageName, in String name, in IBinder binder); 10 | 11 | void addIntentService(in String callingPackageName, in String name, in Intent intent); 12 | 13 | IBinder getService(in String callingPackageName, in String name); 14 | 15 | void removeService(in String callingPackageName, in String name); 16 | } 17 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/java/com/morgoo/droidservices/CompatUtils.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.ContentResolver; 5 | import android.net.Uri; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.os.IBinder; 9 | import android.util.Log; 10 | 11 | import java.lang.reflect.Method; 12 | 13 | /** 14 | * Created by zhangyong232@gmail.com on 2016/3/9. 15 | */ 16 | class CompatUtils { 17 | 18 | static class ContentResolverCompat { 19 | 20 | public static Bundle call(ContentResolver resolver, Uri uri, String method, 21 | String arg, Bundle extras) { 22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 23 | return callAPI11(resolver, uri, method, arg, extras); 24 | } else { 25 | return callAPI10(resolver, uri, method, arg, extras); 26 | } 27 | } 28 | 29 | private static Bundle callAPI10(ContentResolver resolver, Uri uri, String method, String arg, Bundle extras) { 30 | try { 31 | Method call = null; 32 | try { 33 | call = ContentResolver.class.getDeclaredMethod("call", Uri.class, String.class, String.class, Bundle.class); 34 | } catch (NoSuchMethodException e) { 35 | } 36 | if (call == null) { 37 | call = ContentResolver.class.getDeclaredMethod("call", Uri.class, String.class, String.class, Bundle.class); 38 | } 39 | return (Bundle) call.invoke(resolver, uri, method, arg, extras); 40 | } catch (Exception e) { 41 | RuntimeException exception = new RuntimeException(e); 42 | exception.initCause(e); 43 | throw exception; 44 | } 45 | } 46 | 47 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 48 | private static Bundle callAPI11(ContentResolver resolver, Uri uri, String method, String arg, Bundle extras) { 49 | return resolver.call(uri, method, arg, extras); 50 | } 51 | } 52 | 53 | static class BundleCompat { 54 | 55 | private static final String TAG = "Bundle"; 56 | 57 | public static IBinder getBinder(Bundle data, String key) { 58 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 59 | return getBinerAPI18(data, key); 60 | } else { 61 | return getBinerAPI10(data, key); 62 | } 63 | } 64 | 65 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) 66 | private static IBinder getBinerAPI18(Bundle data, String key) { 67 | return data.getBinder(key); 68 | } 69 | 70 | private static IBinder getBinerAPI10(Bundle data, String key) { 71 | Object o = data.get(key); 72 | if (o == null) { 73 | return null; 74 | } 75 | try { 76 | return (IBinder) o; 77 | } catch (ClassCastException e) { 78 | typeWarning(key, o, "IBinder", e); 79 | return null; 80 | } 81 | } 82 | 83 | public static void putBinder(Bundle data, String key, IBinder value) { 84 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 85 | putBinerAPI18(data, key, value); 86 | } else { 87 | putBinerAPI10(data, key, value); 88 | } 89 | } 90 | 91 | private static void putBinerAPI10(Bundle data, String key, IBinder value) { 92 | //public void putIBinder(String key, IBinder value) 93 | try { 94 | Method putIBinder = null; 95 | try { 96 | putIBinder = Bundle.class.getDeclaredMethod("putIBinder", String.class, IBinder.class); 97 | } catch (NoSuchMethodException e) { 98 | } 99 | if (putIBinder == null) { 100 | putIBinder = Bundle.class.getMethod("putIBinder", String.class, IBinder.class); 101 | } 102 | putIBinder.invoke(data, key, value); 103 | } catch (Exception e) { 104 | RuntimeException exception = new RuntimeException(e); 105 | exception.initCause(e); 106 | throw exception; 107 | } 108 | } 109 | 110 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) 111 | private static void putBinerAPI18(Bundle data, String key, IBinder value) { 112 | data.putBinder(key, value); 113 | } 114 | 115 | 116 | private static void typeWarning(String key, Object value, String className, 117 | ClassCastException e) { 118 | typeWarning(key, value, className, "", e); 119 | } 120 | 121 | private static void typeWarning(String key, Object value, String className, 122 | Object defaultValue, ClassCastException e) { 123 | StringBuilder sb = new StringBuilder(); 124 | sb.append("Key "); 125 | sb.append(key); 126 | sb.append(" expected "); 127 | sb.append(className); 128 | sb.append(" but value was a "); 129 | sb.append(value.getClass().getName()); 130 | sb.append(". The default value "); 131 | sb.append(defaultValue); 132 | sb.append(" was returned."); 133 | Log.w(TAG, sb.toString()); 134 | Log.w(TAG, "Attempt to cast generated internal exception:", e); 135 | } 136 | } 137 | 138 | 139 | } 140 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/java/com/morgoo/droidservices/ContentProviderBinderTransact.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.os.IBinder; 7 | 8 | /** 9 | * Created by zhangyong232@gmail.com on 2016/3/9. 10 | */ 11 | class ContentProviderBinderTransact { 12 | 13 | static final String METHOD_GET_SERVICE_MANAGER = "GetServiceManager"; 14 | static final String EXTRA_BINDER = "com.morgoo.droidservice.EXTRA_BINDER"; 15 | 16 | static IBinder getBinder(Context context, Uri mUri) { 17 | Bundle extra = new Bundle(); 18 | extra.setClassLoader(context.getClassLoader()); 19 | Bundle data = CompatUtils.ContentResolverCompat.call(context.getContentResolver(), mUri, METHOD_GET_SERVICE_MANAGER, null, extra); 20 | return CompatUtils.BundleCompat.getBinder(data, EXTRA_BINDER); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/java/com/morgoo/droidservices/IServiceManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 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.Binder; 8 | import android.os.IBinder; 9 | import android.os.Looper; 10 | import android.os.RemoteException; 11 | import android.util.Log; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | import java.util.concurrent.BlockingQueue; 16 | import java.util.concurrent.LinkedBlockingQueue; 17 | 18 | /** 19 | * Created by zhangyong232@gmail.com on 2016/3/9. 20 | */ 21 | class IServiceManagerImpl extends IServiceManager.Stub { 22 | 23 | private Map sAliveServices = new HashMap<>(); 24 | private Map sDiedServices = new HashMap<>(); 25 | 26 | private Context mContext; 27 | 28 | IServiceManagerImpl(Context context) { 29 | mContext = context; 30 | } 31 | 32 | @Override 33 | public synchronized void addService(final String callingPackageName, final String name, final IBinder binder) throws RemoteException { 34 | if (sAliveServices.containsKey(name)) { 35 | ServiceItem item = sAliveServices.get(name); 36 | throw new RuntimeException(String.format("Service %s has registed by pid:%s,uid:%s", name, item.callingPid, item.callingUid)); 37 | } 38 | 39 | IBinder.DeathRecipient recipient = new DeathRecipient() { 40 | @Override 41 | public void binderDied() { 42 | ServiceItem item = sAliveServices.remove(name); 43 | if (item != null) { 44 | sDiedServices.put(name, item); 45 | } 46 | } 47 | }; 48 | 49 | final ServiceItem item = new ServiceItem(name, binder, null, recipient, callingPackageName, Binder.getCallingPid(), Binder.getCallingUid()); 50 | sAliveServices.put(name, item); 51 | sDiedServices.remove(name); 52 | item.linkToDeath(); 53 | } 54 | 55 | @Override 56 | public void addIntentService(String callingPackageName, String name, Intent intent) throws RemoteException { 57 | //TODO 58 | RemoteException remoteException = new RemoteException(); 59 | remoteException.initCause(new UnsupportedOperationException()); 60 | throw remoteException; 61 | } 62 | 63 | private static void ensureNotOnMainThread() { 64 | Looper looper = Looper.myLooper(); 65 | if (looper != null && looper == Looper.getMainLooper()) { 66 | throw new IllegalStateException( 67 | "calling this from your main thread can lead to deadlock"); 68 | } 69 | } 70 | 71 | private IBinder connectToService(Context context, Intent service) throws InterruptedException { 72 | if (context == null) { 73 | throw new NullPointerException("context == null"); 74 | } 75 | ensureNotOnMainThread(); 76 | final BlockingQueue q = new LinkedBlockingQueue(1); 77 | ServiceConnection serviceConnection = new ServiceConnection() { 78 | volatile boolean mConnectedAtLeastOnce = false; 79 | 80 | @Override 81 | public void onServiceConnected(ComponentName name, IBinder service) { 82 | if (!mConnectedAtLeastOnce) { 83 | mConnectedAtLeastOnce = true; 84 | try { 85 | q.put(service); 86 | } catch (InterruptedException e) { 87 | // will never happen, since the queue starts with one available slot 88 | } 89 | } 90 | } 91 | 92 | @Override 93 | public void onServiceDisconnected(ComponentName name) { 94 | } 95 | }; 96 | boolean isBound = context.bindService(service, 97 | serviceConnection, 98 | Context.BIND_AUTO_CREATE); 99 | if (!isBound) { 100 | throw new RuntimeException("Could not bind to Service:" + service); 101 | } 102 | return q.take(); 103 | } 104 | 105 | @Override 106 | public IBinder getService(final String callingPackageName, final String name) throws RemoteException { 107 | ServiceItem item = sAliveServices.get(name); 108 | if (item == null) { 109 | item = sDiedServices.get(name); 110 | } 111 | if (item != null) { 112 | return item.binder; 113 | } 114 | Log.e("IServiceManagerImpl", "getService in :" + Thread.currentThread() + ",l=" + Looper.myLooper()); 115 | return null; 116 | } 117 | 118 | 119 | @Override 120 | public void removeService(final String callingPackageName, final String name) throws RemoteException { 121 | ServiceItem item = sAliveServices.remove(name); 122 | if (item != null) { 123 | item.unlinkToDeath(); 124 | } 125 | sDiedServices.remove(name); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/java/com/morgoo/droidservices/ServiceItem.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 2 | 3 | import android.content.Intent; 4 | import android.os.IBinder; 5 | import android.os.RemoteException; 6 | 7 | /** 8 | * Created by zhangyong232@gmail.com on 2016/3/9. 9 | */ 10 | class ServiceItem { 11 | 12 | final String name; 13 | final int callingPid; 14 | final int callingUid; 15 | final IBinder binder; 16 | final Intent intent; 17 | 18 | IBinder.DeathRecipient recipient; 19 | 20 | ServiceItem(String name, IBinder binder, Intent intent, IBinder.DeathRecipient recipient, String callingPackage, int callingPid, int callingUid) { 21 | this.name = name; 22 | this.callingPid = callingPid; 23 | this.callingUid = callingUid; 24 | this.binder = binder; 25 | this.intent = intent; 26 | this.recipient = recipient; 27 | } 28 | 29 | void linkToDeath() throws RemoteException { 30 | if (binder != null && recipient != null) { 31 | binder.linkToDeath(recipient, 0); 32 | } 33 | } 34 | 35 | void unlinkToDeath() { 36 | if (binder != null && recipient != null) { 37 | binder.unlinkToDeath(recipient, 0); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/java/com/morgoo/droidservices/ServiceManager.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.IBinder; 7 | import android.os.RemoteException; 8 | 9 | /** 10 | * 服务器管理器。 11 | * 对于任意的服务提供者,都可以向该服务系统中注册服务。 12 | * 服务注册有两种方式: 13 | * 1、直接注册:ServiceManager.getInstance().registerService(Context context, String name, IBinder binder); 14 | * 2、间接注册:ServiceManager.getInstance().registerService(Context context, String name, Intent intent); 15 | *

16 | * Created by zhangyong232@gmail.com on 2016/3/9. 17 | */ 18 | public class ServiceManager { 19 | 20 | 21 | private ServiceManager() { 22 | 23 | } 24 | 25 | 26 | private static class SingleHodler { 27 | private static final ServiceManager sInstance = new ServiceManager(); 28 | } 29 | 30 | 31 | public static ServiceManager getInstance() { 32 | return SingleHodler.sInstance; 33 | } 34 | 35 | 36 | private IServiceManager sIServiceManager; 37 | 38 | 39 | private synchronized void doGetIServiceManager(final Context context) throws RemoteException { 40 | if (sIServiceManager == null) { 41 | IBinder binder = ContentProviderBinderTransact.getBinder(context, mUri); 42 | binder.linkToDeath(new IBinder.DeathRecipient() { 43 | @Override 44 | public void binderDied() { 45 | try { 46 | doGetIServiceManager(context); 47 | } catch (RemoteException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | }, 0); 52 | sIServiceManager = IServiceManager.Stub.asInterface(binder); 53 | } 54 | } 55 | 56 | private IServiceManager getIServiceManager(Context context) throws RemoteException { 57 | doGetIServiceManager(context); 58 | return sIServiceManager; 59 | } 60 | 61 | private Uri mUri = Uri.parse("content://com.morgoo.droidservice/"); 62 | 63 | public void setAuthorities(String authorities) { 64 | mUri = Uri.parse("content://" + authorities + "/"); 65 | } 66 | 67 | public void registerService(final Context context, final String name, IBinder binder) throws RemoteException { 68 | getIServiceManager(context).addService(context.getPackageName(), name, binder); 69 | } 70 | 71 | public void registerService(final Context context, final String name, Intent intent) throws RemoteException { 72 | getIServiceManager(context).addIntentService(context.getPackageName(), name, intent); 73 | } 74 | 75 | public void unregisterService(final Context context, final String name) throws RemoteException { 76 | getIServiceManager(context).removeService(context.getPackageName(), name); 77 | } 78 | 79 | public void getService(final Context context, final String name) throws RemoteException { 80 | getIServiceManager(context).getService(context.getPackageName(), name); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DroidServices 3 | 4 | -------------------------------------------------------------------------------- /DroidService/Libraries/droidservices/src/test/java/com/morgoo/droidservices/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservices; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /DroidService/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.morgoo.droidservicetest" 9 | minSdkVersion 10 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | compile project(':Libraries:droidservices') 28 | } 29 | -------------------------------------------------------------------------------- /DroidService/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Program_Files\android-sdk-windows/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /DroidService/app/src/androidTest/java/com/morgoo/droidservicetest/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservicetest; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /DroidService/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /DroidService/app/src/main/java/com/morgoo/droidservicetest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservicetest; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.View; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 19 | setSupportActionBar(toolbar); 20 | 21 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 22 | fab.setOnClickListener(new View.OnClickListener() { 23 | @Override 24 | public void onClick(View view) { 25 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 26 | .setAction("Action", null).show(); 27 | } 28 | }); 29 | } 30 | 31 | @Override 32 | public boolean onCreateOptionsMenu(Menu menu) { 33 | // Inflate the menu; this adds items to the action bar if it is present. 34 | getMenuInflater().inflate(R.menu.menu_main, menu); 35 | return true; 36 | } 37 | 38 | @Override 39 | public boolean onOptionsItemSelected(MenuItem item) { 40 | // Handle action bar item clicks here. The action bar will 41 | // automatically handle clicks on the Home/Up button, so long 42 | // as you specify a parent activity in AndroidManifest.xml. 43 | int id = item.getItemId(); 44 | 45 | //noinspection SimplifiableIfStatement 46 | if (id == R.id.action_settings) { 47 | return true; 48 | } 49 | 50 | return super.onOptionsItemSelected(item); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DroidService/app/src/main/java/com/morgoo/droidservicetest/MainActivityFragment.java: -------------------------------------------------------------------------------- 1 | package com.morgoo.droidservicetest; 2 | 3 | import android.os.Bundle; 4 | import android.os.RemoteException; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.morgoo.droidservices.ServiceManager; 11 | 12 | /** 13 | * A placeholder fragment containing a simple view. 14 | */ 15 | public class MainActivityFragment extends Fragment { 16 | 17 | public MainActivityFragment() { 18 | } 19 | 20 | @Override 21 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 22 | Bundle savedInstanceState) { 23 | View view = inflater.inflate(R.layout.fragment_main, container, false); 24 | try { 25 | ServiceManager.getInstance().setAuthorities("com.morgoo.droidservicetest.CoreContentProvider"); 26 | ServiceManager.getInstance().getService(getActivity(), "haa"); 27 | } catch (RemoteException e) { 28 | e.printStackTrace(); 29 | } 30 | return view; 31 | } 32 | 33 | @Override 34 | public void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 |

5 | 10 | 11 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/DroidService/a098d65cbd11de3057628a0cdf3f15312bd8c98a/DroidService/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /DroidService/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/DroidService/a098d65cbd11de3057628a0cdf3f15312bd8c98a/DroidService/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /DroidService/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/DroidService/a098d65cbd11de3057628a0cdf3f15312bd8c98a/DroidService/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /DroidService/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/DroidService/a098d65cbd11de3057628a0cdf3f15312bd8c98a/DroidService/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /DroidService/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/DroidService/a098d65cbd11de3057628a0cdf3f15312bd8c98a/DroidService/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /DroidService/app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DroidServiceTest 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /DroidService/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |