FileDocCategorySizeDatePackage
Installer.javaAPI DocAndroid 1.5 API7828Wed May 06 22:42:00 BST 2009com.android.server

Installer

public class Installer extends Object

Fields Summary
private static final String
TAG
InputStream
mIn
OutputStream
mOut
android.net.LocalSocket
mSocket
byte[]
buf
int
buflen
Constructors Summary
Methods Summary
public intclearUserData(java.lang.String name)

        StringBuilder builder = new StringBuilder("rmuserdata");
        builder.append(' ");
        builder.append(name);
        return execute(builder.toString());
    
private booleanconnect()


       
        if (mSocket != null) {
            return true;
        }
        Log.i(TAG, "connecting...");
        try {
            mSocket = new LocalSocket();

            LocalSocketAddress address = new LocalSocketAddress(
                "installd", LocalSocketAddress.Namespace.RESERVED);

            mSocket.connect(address);

            mIn = mSocket.getInputStream();
            mOut = mSocket.getOutputStream();
        } catch (IOException ex) {
            disconnect();
            return false;
        }
        return true;
    
public intdeleteCacheFiles(java.lang.String name)

        StringBuilder builder = new StringBuilder("rmcache");
        builder.append(' ");
        builder.append(name);
        return execute(builder.toString());
    
public intdexopt(java.lang.String apkPath, int uid, boolean isPublic)

        StringBuilder builder = new StringBuilder("dexopt");
        builder.append(' ");
        builder.append(apkPath);
        builder.append(' ");
        builder.append(uid);
        builder.append(isPublic ? " 1" : " 0");
        return execute(builder.toString());
    
private voiddisconnect()

        Log.i(TAG,"disconnecting...");
		try {
			if (mSocket != null) mSocket.close();
		} catch (IOException ex) { }
		try {
			if (mIn != null) mIn.close();
		} catch (IOException ex) { }
		try {
			if (mOut != null) mOut.close();
		} catch (IOException ex) { }
		mSocket = null;
		mIn = null;
		mOut = null;
	
private intexecute(java.lang.String cmd)

		String res = transaction(cmd);
		try {
			return Integer.parseInt(res);
		} catch (NumberFormatException ex) {
			return -1;
		}
	
public intfreeCache(long freeStorageSize)

        StringBuilder builder = new StringBuilder("freecache");
        builder.append(' ");
        builder.append(String.valueOf(freeStorageSize));
        return execute(builder.toString());
    
public intgetSizeInfo(java.lang.String pkgName, java.lang.String apkPath, java.lang.String fwdLockApkPath, android.content.pm.PackageStats pStats)

        StringBuilder builder = new StringBuilder("getsize");
        builder.append(' ");
        builder.append(pkgName);
        builder.append(' ");
        builder.append(apkPath);
        builder.append(' ");
        builder.append(fwdLockApkPath != null ? fwdLockApkPath : "!");

        String s = transaction(builder.toString());
        String res[] = s.split(" ");

        if((res == null) || (res.length != 4)) {
            return -1;
        }
        try {
            pStats.codeSize = Long.parseLong(res[1]);
            pStats.dataSize = Long.parseLong(res[2]);
            pStats.cacheSize = Long.parseLong(res[3]);
            return Integer.parseInt(res[0]);
        } catch (NumberFormatException e) {
            return -1;
        }
    
public intinstall(java.lang.String name, int uid, int gid)

        StringBuilder builder = new StringBuilder("install");
        builder.append(' ");
        builder.append(name);
        builder.append(' ");
        builder.append(uid);
        builder.append(' ");
        builder.append(gid);
        return execute(builder.toString());
    
public intmovedex(java.lang.String srcPath, java.lang.String dstPath)

        StringBuilder builder = new StringBuilder("movedex");
        builder.append(' ");
        builder.append(srcPath);
        builder.append(' ");
        builder.append(dstPath);
        return execute(builder.toString());
    
public booleanping()

        if (execute("ping") < 0) {
            return false;
        } else {
            return true;
        }
    
private booleanreadBytes(byte[] buffer, int len)

		int off = 0, count;
        if (len < 0) return false;
		while (off != len) {
			try {
				count = mIn.read(buffer, off, len - off);
				if (count <= 0) {
                    Log.e(TAG, "read error " + count);
                    break;
                }
				off += count;
			} catch (IOException ex) {
                Log.e(TAG,"read exception");
				break;
			}
		}
//        Log.i(TAG, "read "+len+" bytes");
		if (off == len) return true;
		disconnect();
		return false;
	
private booleanreadReply()

		int len;
		buflen = 0;
		if (!readBytes(buf, 2)) return false;
		len = (((int) buf[0]) & 0xff) | ((((int) buf[1]) & 0xff) << 8);
		if ((len < 1) || (len > 1024)) {
            Log.e(TAG,"invalid reply length ("+len+")");
			disconnect();
			return false;
		}
		if (!readBytes(buf, len)) return false;
		buflen = len;
		return true;
	
public intremove(java.lang.String name)

        StringBuilder builder = new StringBuilder("remove");
        builder.append(' ");
        builder.append(name);
        return execute(builder.toString());
    
public intrmdex(java.lang.String codePath)

        StringBuilder builder = new StringBuilder("rmdex");
        builder.append(' ");
        builder.append(codePath);
        return execute(builder.toString());
    
public intsetForwardLockPerm(java.lang.String packageName, int gid)

        StringBuilder builder = new StringBuilder("protect");
        builder.append(' ");
        builder.append(packageName);
        builder.append(' ");
        builder.append(gid);
        return execute(builder.toString());
    
private synchronized java.lang.Stringtransaction(java.lang.String cmd)

		if (!connect()) {
            Log.e(TAG, "connection failed");
            return "-1";
        }

        if (!writeCommand(cmd)) {
                /* If installd died and restarted in the background
                 * (unlikely but possible) we'll fail on the next
                 * write (this one).  Try to reconnect and write
                 * the command one more time before giving up.
                 */
            Log.e(TAG, "write command failed? reconnect!");
            if (!connect() || !writeCommand(cmd)) {
                return "-1";
            }
        }
//        Log.i(TAG,"send: '"+cmd+"'");
		if (readReply()) {
            String s = new String(buf, 0, buflen);
//            Log.i(TAG,"recv: '"+s+"'");
			return s;
		} else {
//            Log.i(TAG,"fail");
			return "-1";
		}
	
private booleanwriteCommand(java.lang.String _cmd)

		byte[] cmd = _cmd.getBytes();
		int len = cmd.length;
		if ((len < 1) || (len > 1024)) return false;
		buf[0] = (byte) (len & 0xff);
		buf[1] = (byte) ((len >> 8) & 0xff);
		try {
			mOut.write(buf, 0, 2);
			mOut.write(cmd, 0, len);
		} catch (IOException ex) {
            Log.e(TAG,"write error");
			disconnect();
			return false;
		}
		return true;