/**
 * This file is part of the Android DependencyManager project hosted at
 * http://code.google.com/p/android-dependencymanager/
 *
 * Copyright (C) 2009 Jens Finkhaeuser <jens@finkhaeuser.de>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

package de.finkhaeuser.dm.client;

import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.ComponentName;

import android.os.IBinder;
import android.os.RemoteException;

import android.os.Looper;

import de.finkhaeuser.dm.IDependencyManager;

import android.util.Log;

/**
 * Client object to the IDependencyManager interface; simplifies binding to
 * the service.
 **/
public class DependencyManager
{
  /***************************************************************************
   * Private constants
   **/
  private static final String LTAG = "DependencyManager";



  /***************************************************************************
   * Implement BindListener to receive a DependencyManager instance that's
   * bound to IDependencyManager.
   **/
  public interface BindListener
  {
    public void onBound(DependencyManager dm);
  }



  /***************************************************************************
   * Private data
   **/
  private Context                     mContext;
  private BindListener                mBindListener;

  // Service stub
  private volatile IDependencyManager mStub = null;

  // Service connection
  private ServiceConnection           mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service)
    {
      mStub = IDependencyManager.Stub.asInterface(service);
      mBindListener.onBound(DependencyManager.this);
    }


    public void onServiceDisconnected(ComponentName className)
    {
      mStub = null;
    }
  };



  /***************************************************************************
   * Extra functions
   **/

  /**
   * Returns true if binding was successful, false otherwise. Shortly after a
   * successful bind, BindListener's onBound() method will be called with
   * a DependencyManager instance through which you can communicate with the
   * service.
   **/
  public static boolean bindService(Context context, BindListener listener)
  {
    DependencyManager dm = new DependencyManager(context, listener);
    return dm.bindService();
  }



  /**
   * Always unbind each DependencyManager object.
   **/
  public void unbindService()
  {
    if (null == mStub) {
      return;
    }

    mContext.unbindService(mConnection);
  }



  private DependencyManager(Context context, BindListener listener)
  {
    mContext = context;
    mBindListener = listener;
  }



  private boolean bindService()
  {
    return mContext.bindService(
        new Intent(IDependencyManager.class.getName()),
        mConnection, Context.BIND_AUTO_CREATE);
  }



  /***************************************************************************
   * Implementation of IDependencyManager API
   **/

  /**
   * Returns false on errors, true otherwise. Will try to resolve the
   * dependencies for the given package by prompting the user with appropriate
   * choices.
   **/
  public boolean resolveDependencies(String packageName)
  {
    if (null == mStub) {
      return false;
    }

    try {
      mStub.resolveDependencies(packageName);
    } catch (RemoteException ex) {
      Log.e(LTAG, "Exception " + ex.getMessage());
      return false;
    }

    return true;
  }
}

@@ -1018,24 +1018,48 @@
 os.Looper;%0A%0A
+import java.util.List;%0A%0A
 import de.fi
@@ -3585,267 +3585,440 @@
 %0A%0A  
-/**%0A   * Returns false on errors, true otherwise. Will try to resolve the%0A   * dependencies for the given package by prompting the user with appropriate%0A   * choices.%0A   **/%0A  public boolean resolveDependencies(String packageName)%0A  %7B%0A    if (null == mStub) %7B
+public void resolveDependencies(String packageName)%0A  %7B%0A    try %7B%0A      mStub.resolveDependencies(packageName);%0A    %7D catch (RemoteException ex) %7B%0A      Log.e(LTAG, %22Exception %22 + ex.getMessage());%0A    %7D%0A  %7D%0A%0A%0A%0A  List%3CIntent%3E scanPackageForDependencies(String packageName)%0A  %7B%0A    try %7B%0A      return mStub.scanPackageForDependencies(packageName);%0A    %7D catch (RemoteException ex) %7B%0A      Log.e(LTAG, %22Exception %22 + ex.getMessage());
 %0A   
@@ -4023,37 +4023,36 @@
      return 
-false
+null
 ;%0A    %7D%0A
 %0A    try %7B%0A 
@@ -4035,24 +4035,95 @@
 null;%0A    %7D%0A
+  %7D%0A%0A%0A%0A  List%3CIntent%3E removeResolvableIntents(List%3CIntent%3E intents)%0A  %7B
 %0A    try %7B%0A 
@@ -4123,32 +4123,39 @@
 try %7B%0A      
+return 
 mStub.re
 solveDepende
@@ -4146,37 +4146,37 @@
 b.re
-solveDependencies(packageName
+moveResolvableIntents(intents
 );%0A 
@@ -4277,41 +4277,237 @@
 urn 
-false;%0A    %7D%0A%0A    return true;%0A  %7D
+null;%0A    %7D%0A  %7D%0A%0A%0A%0A  void displayChoicesForIntents(List%3CIntent%3E intents)%0A  %7B%0A    try %7B%0A      mStub.displayChoicesForIntents(intents);%0A    %7D catch (RemoteException ex) %7B%0A      Log.e(LTAG, %22Exception %22 + ex.getMessage());%0A    %7D%0A  %7D%0A
 %0A%7D%0A

Create wrappers for all IDependencyManager functions