Example usage for android.os RemoteException RemoteException

List of usage examples for android.os RemoteException RemoteException

Introduction

In this page you can find the example usage for android.os RemoteException RemoteException.

Prototype

public RemoteException() 

Source Link

Usage

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

@Override
public void dumpAsync(FileDescriptor arg0, String[] arg1) throws RemoteException {
    RemoteException re = new RemoteException();
    re.initCause(new MethodNotSupportedException("dumpAsync"));
    throw re;//from   w w  w  .  j a v  a2  s  .c  o m
}

From source file:org.ohmage.sync.StreamSyncAdapterTest.java

public void testOnPerformSyncForStreams_remoteExceptionAccessingDb_setsDbErrorInSyncResult() throws Exception {
    Streams fakeStreams = new Streams();
    fakeStreams.add(fakeStream);/*  w w w . j  a  va  2  s .  c  o m*/
    when(fakeWriter.moveToNextBatch()).thenReturn(true, false);
    whenAccountStillExists();
    doThrow(new RemoteException()).when(fakeWriter).query(anyString(), any(Stream.class));

    mSyncAdapter.performSyncForStreams(fakeAccount, fakeStreams, fakeWriter, fakeSyncResult);

    assertTrue(fakeSyncResult.databaseError);
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

@Override
public boolean isBinderAlive(int connid, int oid, long timeout) throws RemoteException {
    if (D)/*from ww w.j av  a2 s.c  om*/
        Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "isBinderAlive...");
    if (!isBinderAlive()) {
        if (E)
            Log.e(TAG_CLIENT_BIND, PREFIX_LOG + "Binder is not alive");
        throw new RemoteException();
    }
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInt(oid);
        transactRemoteAndroid(getConnectionId(), IS_BINDER_ALIVE, data, reply, 0, timeout);
        return reply.readByte() == 1;
    } finally {
        if (data != null)
            data.recycle();
        if (reply != null)
            reply.recycle();
    }
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

public void pushMe(final Context context, final PublishListener listener, final int bufsize, final int flags,
        final long timeout) throws RemoteException, IOException {
    new AsyncTask<PublishListener, Integer, Object>() {

        private PublishListener listener;

        @Override//from w w  w  . j a v a2 s.  com
        protected Object doInBackground(PublishListener... params) {
            listener = params[0];
            FileInputStream in = null;
            int fd = -1;
            int connid = -1;
            int s;
            byte[] buf = new byte[bufsize];
            byte[] signature = null;
            try {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo info = Droid2DroidManagerImpl.sAppInfo;
                String label = context.getString(info.labelRes);
                PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
                File filename = new File(info.publicSourceDir);

                int versionCode = pi.versionCode;
                signature = pi.signatures[0].toByteArray();

                long length = filename.length();
                connid = getConnectionId();
                if (V)
                    Log.v(TAG_INSTALL, PREFIX_LOG + "CLI propose apk " + info.packageName);
                fd = proposeApk(connid, label, info.packageName, versionCode, signature, length, flags,
                        timeout);
                if (fd > 0) {
                    // TODO: ask sender before send datas
                    if (V)
                        Log.v(TAG_INSTALL, PREFIX_LOG + "CLI it's accepted");
                    in = new FileInputStream(filename);
                    StringBuilder prog = new StringBuilder();
                    // TODO: multi thread for optimize read latency ?
                    long timeoutSendFile = 30000; // FIXME: Time out pour send file en dur.
                    long pos = 0;
                    if (V)
                        Log.v(TAG_INSTALL, PREFIX_LOG + "CLI send file");
                    while ((s = in.read(buf, 0, buf.length)) > 0) {
                        if (V) {
                            prog.append('*');
                            if (V)
                                Log.v(TAG_INSTALL, PREFIX_LOG + "" + prog.toString()); // TODO: A garder ?
                        }
                        if (!sendFileData(connid, fd, buf, s, pos, length, timeoutSendFile)) {
                            if (E)
                                Log.e(TAG_INSTALL, PREFIX_LOG + "Impossible to send file data");
                            throw new RemoteException();
                        }
                        pos += s;
                        publishProgress((int) ((double) pos / length * 10000L));
                    }
                    if (V)
                        Log.v(TAG_INSTALL, PREFIX_LOG + "CLI send file done");
                    if (installApk(connid, label, fd, flags, timeout)) {
                        if (V)
                            Log.v(TAG_INSTALL, PREFIX_LOG + "CLI apk is installed");
                        return 1;
                    } else {
                        if (V)
                            Log.v(TAG_INSTALL, PREFIX_LOG + "CLI install apk is canceled");
                        return new CancellationException("Install apk " + pi.packageName + " is canceled");
                    }
                } else {
                    if (V)
                        Log.v(TAG_INSTALL, PREFIX_LOG + "CLI install apk is accepted (" + fd + ")");
                    return fd;
                }
            } catch (NameNotFoundException e) {
                cancelCurrentUpload(timeout, fd, connid);
                return e;
            } catch (IOException e) {
                cancelCurrentUpload(timeout, fd, connid);
                return e;
            } catch (RemoteException e) {
                if (D)
                    Log.d(TAG_INSTALL, "Impossible to push apk (" + e.getMessage() + ")", e);
                cancelCurrentUpload(timeout, fd, connid);
                return e;
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        // Ignore
                    }
                }
            }
        }

        private void cancelCurrentUpload(final long timeout, int fd, int connid) {
            if (connid != -1 && fd != -1) {
                try {
                    cancelFileData(connid, fd, timeout);
                } catch (RemoteException e1) {
                    // Ignore
                }
            }
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            postPublishProgress(listener, values[0]);
        }

        @Override
        protected void onPostExecute(Object result) {
            if (result instanceof Throwable) {
                postPublishError(listener, (Throwable) result);
            } else
                postPublishFinish(listener, ((Integer) result).intValue());
        }
    }.execute(listener);
}

From source file:com.android.exchange.EasSyncService.java

/**
 * Use the Exchange 2007 AutoDiscover feature to try to retrieve server information using
 * only an email address and the password
 *
 * @param userName the user's email address
 * @param password the user's password//www .jav  a  2s.c o m
 * @return a HostAuth ready to be saved in an Account or null (failure)
 */
public Bundle tryAutodiscover(String userName, String password) throws RemoteException {
    XmlSerializer s = Xml.newSerializer();
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    HostAuth hostAuth = new HostAuth();
    Bundle bundle = new Bundle();
    bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.NO_ERROR);
    try {
        // Build the XML document that's sent to the autodiscover server(s)
        s.setOutput(os, "UTF-8");
        s.startDocument("UTF-8", false);
        s.startTag(null, "Autodiscover");
        s.attribute(null, "xmlns", AUTO_DISCOVER_SCHEMA_PREFIX + "requestschema/2006");
        s.startTag(null, "Request");
        s.startTag(null, "EMailAddress").text(userName).endTag(null, "EMailAddress");
        s.startTag(null, "AcceptableResponseSchema");
        s.text(AUTO_DISCOVER_SCHEMA_PREFIX + "responseschema/2006");
        s.endTag(null, "AcceptableResponseSchema");
        s.endTag(null, "Request");
        s.endTag(null, "Autodiscover");
        s.endDocument();
        String req = os.toString();

        // Initialize the user name and password
        mUserName = userName;
        mPassword = password;
        // Make sure the authentication string is recreated and cached
        cacheAuthAndCmdString();

        // Split out the domain name
        int amp = userName.indexOf('@');
        // The UI ensures that userName is a valid email address
        if (amp < 0) {
            throw new RemoteException();
        }
        String domain = userName.substring(amp + 1);

        // There are up to four attempts here; the two URLs that we're supposed to try per the
        // specification, and up to one redirect for each (handled in postAutodiscover)
        // Note: The expectation is that, of these four attempts, only a single server will
        // actually be identified as the autodiscover server.  For the identified server,
        // we may also try a 2nd connection with a different format (bare name).

        // Try the domain first and see if we can get a response
        HttpPost post = new HttpPost("https://" + domain + AUTO_DISCOVER_PAGE);
        setHeaders(post, false);
        post.setHeader("Content-Type", "text/xml");
        post.setEntity(new StringEntity(req));
        HttpClient client = getHttpClient(COMMAND_TIMEOUT);
        HttpResponse resp;
        try {
            resp = postAutodiscover(client, post, true /*canRetry*/);
        } catch (IOException e1) {
            userLog("IOException in autodiscover; trying alternate address");
            // We catch the IOException here because we have an alternate address to try
            post.setURI(URI.create("https://autodiscover." + domain + AUTO_DISCOVER_PAGE));
            // If we fail here, we're out of options, so we let the outer try catch the
            // IOException and return null
            resp = postAutodiscover(client, post, true /*canRetry*/);
        }

        // Get the "final" code; if it's not 200, just return null
        int code = resp.getStatusLine().getStatusCode();
        userLog("Code: " + code);
        if (code != HttpStatus.SC_OK)
            return null;

        // At this point, we have a 200 response (SC_OK)
        HttpEntity e = resp.getEntity();
        InputStream is = e.getContent();
        try {
            // The response to Autodiscover is regular XML (not WBXML)
            // If we ever get an error in this process, we'll just punt and return null
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            XmlPullParser parser = factory.newPullParser();
            parser.setInput(is, "UTF-8");
            int type = parser.getEventType();
            if (type == XmlPullParser.START_DOCUMENT) {
                type = parser.next();
                if (type == XmlPullParser.START_TAG) {
                    String name = parser.getName();
                    if (name.equals("Autodiscover")) {
                        hostAuth = new HostAuth();
                        parseAutodiscover(parser, hostAuth);
                        // On success, we'll have a server address and login
                        if (hostAuth.mAddress != null) {
                            // Fill in the rest of the HostAuth
                            // We use the user name and password that were successful during
                            // the autodiscover process
                            hostAuth.mLogin = mUserName;
                            hostAuth.mPassword = mPassword;
                            hostAuth.mPort = 443;
                            hostAuth.mProtocol = "eas";
                            hostAuth.mFlags = HostAuth.FLAG_SSL | HostAuth.FLAG_AUTHENTICATE;
                            bundle.putParcelable(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_HOST_AUTH, hostAuth);
                        } else {
                            bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE,
                                    MessagingException.UNSPECIFIED_EXCEPTION);
                        }
                    }
                }
            }
        } catch (XmlPullParserException e1) {
            // This would indicate an I/O error of some sort
            // We will simply return null and user can configure manually
        }
        // There's no reason at all for exceptions to be thrown, and it's ok if so.
        // We just won't do auto-discover; user can configure manually
    } catch (IllegalArgumentException e) {
        bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE,
                MessagingException.UNSPECIFIED_EXCEPTION);
    } catch (IllegalStateException e) {
        bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE,
                MessagingException.UNSPECIFIED_EXCEPTION);
    } catch (IOException e) {
        userLog("IOException in Autodiscover", e);
        bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE, MessagingException.IOERROR);
    } catch (MessagingException e) {
        bundle.putInt(EmailServiceProxy.AUTO_DISCOVER_BUNDLE_ERROR_CODE,
                MessagingException.AUTHENTICATION_FAILED);
    }
    return bundle;
}