package edu.umich.PowerTutor.service;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;

/**
 * @author luxiaoyu01@baidu.com
 * @date 2012-9-23
 * @version
 * @todo
 */
public class PowerTutorConnector {
    private Context                  mContext;
    private ICounterService          counterService;
    private CounterServiceConnection conn;
    private Intent                   serviceIntent;

    public PowerTutorConnector(Context context) {
        mContext = context;
    }

    private class CounterServiceConnection implements ServiceConnection {
        public void onServiceConnected(ComponentName className, IBinder boundService) {
            counterService = ICounterService.Stub.asInterface((IBinder) boundService);
        }

        public void onServiceDisconnected(ComponentName className) {
            counterService = null;
            mContext.unbindService(conn);
//            mContext.bindService(serviceIntent, conn, 0);
        }
    }

    public void connectToPowerTutor() {
        serviceIntent.setClassName(mContext, ICounterService.class.getName());
        mContext.startService(serviceIntent);
        conn = new CounterServiceConnection();
        mContext.bindService(serviceIntent, conn, 0);
        try {
            counterService.hello();
        } catch (RemoteException e) {
            e.printStackTrace();
        } finally {
        }
    }
}

@@ -32,16 +32,93 @@
 rvice;%0A%0A
+import com.baidu.cafe.remote.IRemoteArms;%0Aimport com.baidu.cafe.remote.Log;%0A%0A
 import a
@@ -700,24 +700,71 @@
  = context;%0A
+        conn = new CounterServiceConnection();%0A
     %7D%0A%0A    p
@@ -1164,16 +1164,28 @@
 (conn);%0A
+            
 //      
@@ -1289,24 +1289,553 @@
 erTutor() %7B%0A
+        mContext.bindService(new Intent(ICounterService.class.getName()), conn, Context.BIND_AUTO_CREATE);%0A        int count = 0;%0A        try %7B%0A            while (null == conn) %7B%0A                Thread.sleep(200);%0A                count++;%0A                if (count == 20) %7B //timeout = 4 seconds%0A                    Log.print(%22timeout 4 seconds!!!%22);%0A                    mContext.unbindService(conn);%0A                %7D%0A            %7D%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        //
         serv
@@ -1901,16 +1901,26 @@
 ame());%0A
+        //
         
@@ -1969,47 +1969,10 @@
     
-conn = new CounterServiceConnection();%0A
+//
     

modify Android.mk