Browse Source

Add binder to context analyser service

master
Chris Smith 14 years ago
parent
commit
a94471d7b8

+ 12
- 4
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/ContextAnalyserService.java View File

@@ -24,14 +24,14 @@ package uk.co.md87.android.contextanalyser;
24 24
 
25 25
 import android.app.Service;
26 26
 import android.content.Intent;
27
-import android.content.pm.PackageManager.NameNotFoundException;
28 27
 import android.location.Address;
29 28
 import android.location.Geocoder;
30 29
 import android.location.Location;
31 30
 import android.os.Handler;
32 31
 import android.os.IBinder;
33
-import android.telephony.TelephonyManager;
32
+import android.os.RemoteException;
34 33
 import android.util.Log;
34
+
35 35
 import com.flurry.android.FlurryAgent;
36 36
 
37 37
 import java.io.IOException;
@@ -41,8 +41,8 @@ import java.util.Iterator;
41 41
 import java.util.LinkedList;
42 42
 import java.util.List;
43 43
 import java.util.Map;
44
-import uk.co.md87.android.common.ExceptionHandler;
45 44
 
45
+import uk.co.md87.android.common.ExceptionHandler;
46 46
 import uk.co.md87.android.common.ModelReader;
47 47
 import uk.co.md87.android.common.accel.AccelReaderFactory;
48 48
 import uk.co.md87.android.common.aggregator.AutoAggregator;
@@ -52,6 +52,7 @@ import uk.co.md87.android.common.geo.LocationMonitorFactory;
52 52
 import uk.co.md87.android.common.model.Journey;
53 53
 import uk.co.md87.android.common.model.JourneyStep;
54 54
 import uk.co.md87.android.common.model.Place;
55
+import uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder;
55 56
 
56 57
 /**
57 58
  * Background service which monitors and aggregates various sources of
@@ -89,6 +90,13 @@ public class ContextAnalyserService extends Service {
89 90
         }
90 91
     };
91 92
 
93
+    private final ContextAnalyserBinder.Stub binder = new ContextAnalyserBinder.Stub() {
94
+
95
+        public String getActivity() throws RemoteException {
96
+            return lastActivity;
97
+        }
98
+    };
99
+
92 100
     private final Map<String, Long> names = new HashMap<String, Long>();
93 101
     private final List<String> activityLog = new LinkedList<String>();
94 102
 
@@ -322,7 +330,7 @@ public class ContextAnalyserService extends Service {
322 330
 
323 331
     @Override
324 332
     public IBinder onBind(Intent arg0) {
325
-        return null;
333
+        return binder;
326 334
     }
327 335
 
328 336
 }

+ 34
- 0
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/rpc/ContextAnalyserBinder.aidl View File

@@ -0,0 +1,34 @@
1
+/*
2
+ * Copyright (c) 2009-2010 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.android.contextanalyser.rpc;
24
+
25
+/**
26
+ * Interface to facilitate RPC with the context analyser service.
27
+ *
28
+ * @author chris
29
+ */
30
+interface ContextAnalyserBinder {
31
+
32
+    String getActivity();
33
+
34
+}

+ 103
- 0
code/ContextAnalyser/src/uk/co/md87/android/contextanalyser/rpc/ContextAnalyserBinder.java View File

@@ -0,0 +1,103 @@
1
+/*
2
+ * This file is auto-generated.  DO NOT MODIFY.
3
+ * Original file: uk/co/md87/android/contextanalyser/rpc/ContextAnalyserBinder.aidl
4
+ */
5
+package uk.co.md87.android.contextanalyser.rpc;
6
+import java.lang.String;
7
+import android.os.RemoteException;
8
+import android.os.IBinder;
9
+import android.os.IInterface;
10
+import android.os.Binder;
11
+import android.os.Parcel;
12
+/**
13
+ * Interface to facilitate RPC with the context analyser service.
14
+ *
15
+ * @author chris
16
+ */
17
+public interface ContextAnalyserBinder extends android.os.IInterface
18
+{
19
+/** Local-side IPC implementation stub class. */
20
+public static abstract class Stub extends android.os.Binder implements uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder
21
+{
22
+private static final java.lang.String DESCRIPTOR = "uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder";
23
+/** Construct the stub at attach it to the interface. */
24
+public Stub()
25
+{
26
+this.attachInterface(this, DESCRIPTOR);
27
+}
28
+/**
29
+ * Cast an IBinder object into an ContextAnalyserBinder interface,
30
+ * generating a proxy if needed.
31
+ */
32
+public static uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder asInterface(android.os.IBinder obj)
33
+{
34
+if ((obj==null)) {
35
+return null;
36
+}
37
+android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
38
+if (((iin!=null)&&(iin instanceof uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder))) {
39
+return ((uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder)iin);
40
+}
41
+return new uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder.Stub.Proxy(obj);
42
+}
43
+public android.os.IBinder asBinder()
44
+{
45
+return this;
46
+}
47
+@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
48
+{
49
+switch (code)
50
+{
51
+case INTERFACE_TRANSACTION:
52
+{
53
+reply.writeString(DESCRIPTOR);
54
+return true;
55
+}
56
+case TRANSACTION_getActivity:
57
+{
58
+data.enforceInterface(DESCRIPTOR);
59
+java.lang.String _result = this.getActivity();
60
+reply.writeNoException();
61
+reply.writeString(_result);
62
+return true;
63
+}
64
+}
65
+return super.onTransact(code, data, reply, flags);
66
+}
67
+private static class Proxy implements uk.co.md87.android.contextanalyser.rpc.ContextAnalyserBinder
68
+{
69
+private android.os.IBinder mRemote;
70
+Proxy(android.os.IBinder remote)
71
+{
72
+mRemote = remote;
73
+}
74
+public android.os.IBinder asBinder()
75
+{
76
+return mRemote;
77
+}
78
+public java.lang.String getInterfaceDescriptor()
79
+{
80
+return DESCRIPTOR;
81
+}
82
+public java.lang.String getActivity() throws android.os.RemoteException
83
+{
84
+android.os.Parcel _data = android.os.Parcel.obtain();
85
+android.os.Parcel _reply = android.os.Parcel.obtain();
86
+java.lang.String _result;
87
+try {
88
+_data.writeInterfaceToken(DESCRIPTOR);
89
+mRemote.transact(Stub.TRANSACTION_getActivity, _data, _reply, 0);
90
+_reply.readException();
91
+_result = _reply.readString();
92
+}
93
+finally {
94
+_reply.recycle();
95
+_data.recycle();
96
+}
97
+return _result;
98
+}
99
+}
100
+static final int TRANSACTION_getActivity = (IBinder.FIRST_CALL_TRANSACTION + 0);
101
+}
102
+public java.lang.String getActivity() throws android.os.RemoteException;
103
+}

Loading…
Cancel
Save