Example usage for android.content ContentValues getAsByte

List of usage examples for android.content ContentValues getAsByte

Introduction

In this page you can find the example usage for android.content ContentValues getAsByte.

Prototype

public Byte getAsByte(String key) 

Source Link

Document

Gets a value and converts it to a Byte.

Usage

From source file:com.koushikdutta.superuser.MultitaskSuRequestActivity.java

void manageSocket() {
    new Thread() {
        @Override// w w  w .j a  v  a 2  s .  c o  m
        public void run() {
            try {
                mSocket = new LocalSocket();
                mSocket.connect(new LocalSocketAddress(mSocketPath, Namespace.FILESYSTEM));

                DataInputStream is = new DataInputStream(mSocket.getInputStream());

                ContentValues payload = new ContentValues();

                for (int i = 0; i < SU_PROTOCOL_PARAM_MAX; i++) {
                    int nameLen = is.readInt();
                    if (nameLen > SU_PROTOCOL_NAME_MAX)
                        throw new IllegalArgumentException("name length too long: " + nameLen);
                    byte[] nameBytes = new byte[nameLen];
                    is.readFully(nameBytes);
                    String name = new String(nameBytes);
                    int dataLen = is.readInt();
                    if (dataLen > getValueMax(name))
                        throw new IllegalArgumentException(name + " data length too long: " + dataLen);
                    byte[] dataBytes = new byte[dataLen];
                    is.readFully(dataBytes);
                    String data = new String(dataBytes);
                    payload.put(name, data);
                    //                        Log.i(LOGTAG, name);
                    //                        Log.i(LOGTAG, data);
                    if ("eof".equals(name))
                        break;
                }

                int protocolVersion = payload.getAsInteger("version");
                mCallerUid = payload.getAsInteger("from.uid");
                mDesiredUid = payload.getAsByte("to.uid");
                mDesiredCmd = payload.getAsString("command");
                String calledBin = payload.getAsString("from.bin");
                mPid = payload.getAsInteger("pid");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mRequestReady = true;
                        requestReady();
                    }
                });

                if ("com.koushikdutta.superuser".equals(getPackageName())) {
                    if (!SuHelper.CURRENT_VERSION.equals(payload.getAsString("binary.version")))
                        SuCheckerReceiver.doNotification(MultitaskSuRequestActivity.this);
                }
            } catch (Exception ex) {
                Log.i(LOGTAG, ex.getMessage(), ex);
                try {
                    mSocket.close();
                } catch (Exception e) {
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        finish();
                    }
                });
            }
        }
    }.start();
}