FileDocCategorySizeDatePackage
ApkInstallManager.javaAPI DocAndroid 1.5 API7598Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.adt.project

ApkInstallManager

public class ApkInstallManager extends Object implements com.android.ide.eclipse.editors.resources.manager.ResourceMonitor.IProjectListener, com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener, com.android.ddmlib.AndroidDebugBridge.IDebugBridgeChangeListener
Registers which apk was installed on which device.

The goal of this class is to remember the installation of APKs on devices, and provide information about whether a new APK should be installed on a device prior to running the application from a launch configuration.

The manager uses {@link IProject} and {@link IDevice} to identify the target device and the (project generating the) APK. This ensures that disconnected and reconnected devices will always receive new APKs (since the APK could be uninstalled manually).

Manually uninstalling an APK from a connected device will still be a problem, but this should be a limited use case.

This is a singleton. To get the instance, use {@link #getInstance()}

Fields Summary
private static final ApkInstallManager
sThis
private final ArrayList
mInstallList
Constructors Summary
private ApkInstallManager()

        AndroidDebugBridge.addDeviceChangeListener(this);
        AndroidDebugBridge.addDebugBridgeChangeListener(this);
        ResourceMonitor.getMonitor().addProjectListener(this);
    
Methods Summary
public voidbridgeChanged(com.android.ddmlib.AndroidDebugBridge bridge)

        // the bridge changed, there is no way to know which IDevice will be which.
        // We reset everything
        synchronized (mInstallList) {
            mInstallList.clear();
        }
    
public voiddeviceChanged(com.android.ddmlib.Device device, int changeMask)

        // nothing to do.
    
public voiddeviceConnected(com.android.ddmlib.Device device)

        // nothing to do.
    
public voiddeviceDisconnected(com.android.ddmlib.Device device)

        synchronized (mInstallList) {
            for (int i = 0 ; i < mInstallList.size() ;) {
                ApkInstall install = mInstallList.get(i);
                if (install.device == device) {
                    mInstallList.remove(i);
                } else {
                    i++;
                }
            }
        }
    
public static com.android.ide.eclipse.adt.project.ApkInstallManagergetInstance()

    
        
        return sThis;
    
public booleanisApplicationInstalled(org.eclipse.core.resources.IProject project, com.android.ddmlib.IDevice device)
Returns whether a project was installed on the device.

param
project the project that may have been installed.
param
device the device that may have received the installation.
return

        synchronized (mInstallList) {
            for (ApkInstall install : mInstallList) {
                if (project == install.project && device == install.device) {
                    return true;
                }
            }
        }
        return false;
    
public voidprojectClosed(org.eclipse.core.resources.IProject project)

        resetInstallationFor(project);
    
public voidprojectDeleted(org.eclipse.core.resources.IProject project)

        resetInstallationFor(project);
    
public voidprojectOpened(org.eclipse.core.resources.IProject project)

        // nothing to do.
    
public voidprojectOpenedWithWorkspace(org.eclipse.core.resources.IProject project)

        // nothing to do.
    
public voidregisterInstallation(org.eclipse.core.resources.IProject project, com.android.ddmlib.IDevice device)
Registers an installation of project onto device

param
project The project that was installed.
param
device The device that received the installation.

        synchronized (mInstallList) {
            mInstallList.add(new ApkInstall(project, device));
        }
    
public voidresetInstallationFor(org.eclipse.core.resources.IProject project)
Resets registered installations for a specific {@link IProject}.

This ensures that {@link #isApplicationInstalled(IProject, IDevice)} will always return null for this specified project, for any device.

param
project the project for which to reset all installations.

        synchronized (mInstallList) {
            for (int i = 0 ; i < mInstallList.size() ;) {
                ApkInstall install = mInstallList.get(i);
                if (install.project == project) {
                    mInstallList.remove(i);
                } else {
                    i++;
                }
            }
        }