Example usage for android.os IBinder isBinderAlive

List of usage examples for android.os IBinder isBinderAlive

Introduction

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

Prototype

public boolean isBinderAlive();

Source Link

Document

Check to see if the process that the binder is in is still alive.

Usage

From source file:edu.umich.flowfence.service.Sandbox.java

private void unbind() {
    if (localLOGD) {
        Log.d(TAG, "unbind: " + this);
    }/*from  w  w w  .  ja  va2  s .  c om*/
    onBeforeDisconnect.fire(this, null);
    ISandboxService sandbox;
    synchronized (mSync) {
        sandbox = mSandboxService;
        mApplication.unbindService(mConnection);
    }

    if (sandbox != null) {
        handleDisconnected();
    } else {
        return;
    }

    synchronized (mSync) {
        // Ask it to terminate itself.
        try {
            IBinder binder = sandbox.asBinder();
            sandbox.kill();

            if (!binder.isBinderAlive()) {
                return;
            }

            int timeout = DEATH_PING_MAX;
            while (--timeout >= 0) {
                if (!binder.pingBinder() || !binder.isBinderAlive()) {
                    return;
                }
                SystemClock.sleep(DEATH_PING_INTERVAL);
            }
            throw new SecurityException("Sandbox process has not died");
        } catch (RemoteException e) {
            // Object's already dead, or we're getting a spurious TransactionTooLarge.
        }
    }
}

From source file:org.opensilk.music.library.provider.LibraryProvider.java

@Override
public final Bundle call(String method, String arg, Bundle extras) {

    final Bundle ok = new Bundle();
    ok.putBoolean(Extras.OK, true);/*from w  w w . j  a  va  2  s.c om*/

    if (method == null)
        method = "";
    switch (method) {
    case LibraryMethods.QUERY: {
        extras.setClassLoader(getClass().getClassLoader());

        final IBinder binder = getBinderCallbackFromBundle(extras);
        if (binder == null || !binder.isBinderAlive()) {
            //this is mostly for the null, if the binder is dead then
            //sending them a reason is moot. but we check the binder here
            //so we dont have to do it 50 times below and we can be pretty
            //sure the linkToDeath will succeed
            ok.putBoolean(Extras.OK, false);
            writeCause(ok, new LibraryException(BAD_BINDER, null));
            return ok;
        }

        final Uri uri = extras.getParcelable(Extras.URI);
        final List<String> pathSegments = uri.getPathSegments();
        if (pathSegments.size() < 3 || pathSegments.size() > 5) {
            Log.e(TAG, "Wrong number of path segments: uri=" + uri);
            ok.putBoolean(Extras.OK, false);
            writeCause(ok, new LibraryException(ILLEGAL_URI, new IllegalArgumentException(uri.toString())));
            return ok;
        }

        final String library = pathSegments.get(0);
        final String identity;
        if (pathSegments.size() > 3) {
            identity = pathSegments.get(3);
        } else {
            identity = null;
        }

        final Bundle args = new Bundle();
        args.putParcelable(Extras.URI, uri);
        String sortOrder = extras.getString(Extras.SORTORDER);
        args.putString(Extras.SORTORDER, sortOrder != null ? sortOrder : BundleableSortOrder.A_Z);

        switch (mMatcher.match(uri)) {
        case M_ALBUMS: {
            final BundleableSubscriber<Album> subscriber = new BundleableSubscriber<>(binder);
            queryAlbumsInternal(library, subscriber, args);
            break;
        }
        case M_ALBUM: {
            final BundleableSubscriber<Album> subscriber = new BundleableSubscriber<>(binder);
            getAlbumInternal(library, identity, subscriber, args);
            break;
        }
        case M_ALBUM_TRACKS: {
            final BundleableSubscriber<Track> subscriber = new BundleableSubscriber<>(binder);
            getAlbumTracksInternal(library, identity, subscriber, args);
            break;
        }
        case M_ARTISTS: {
            final BundleableSubscriber<Artist> subscriber = new BundleableSubscriber<>(binder);
            queryArtistsInternal(library, subscriber, args);
            break;
        }
        case M_ARTIST: {
            final BundleableSubscriber<Artist> subscriber = new BundleableSubscriber<>(binder);
            getArtistInternal(library, identity, subscriber, args);
            break;
        }
        case M_ARTIST_ALBUMS: {
            final BundleableSubscriber<Album> subscriber = new BundleableSubscriber<>(binder);
            getArtistAlbumsInternal(library, identity, subscriber, args);
            break;
        }
        case M_ARTIST_TRACKS: {
            final BundleableSubscriber<Track> subscriber = new BundleableSubscriber<>(binder);
            getArtistTracksInternal(library, identity, subscriber, args);
            break;
        }
        case M_FOLDERS:
        case M_FOLDER: {
            final BundleableSubscriber<Bundleable> subscriber = new BundleableSubscriber<>(binder);
            browseFoldersInternal(library, identity, subscriber, args);
            break;
        }
        case M_GENRES: {
            final BundleableSubscriber<Genre> subscriber = new BundleableSubscriber<>(binder);
            queryGenresInternal(library, subscriber, args);
            break;
        }
        case M_GENRE: {
            final BundleableSubscriber<Genre> subscriber = new BundleableSubscriber<>(binder);
            getGenreInternal(library, identity, subscriber, args);
            break;
        }
        case M_GENRE_ALBUMS: {
            final BundleableSubscriber<Album> subscriber = new BundleableSubscriber<>(binder);
            getGenreAlbumsInternal(library, identity, subscriber, args);
            break;
        }
        case M_GENRE_TRACKS: {
            final BundleableSubscriber<Track> subscriber = new BundleableSubscriber<>(binder);
            getGenreTracksInternal(library, identity, subscriber, args);
            break;
        }
        case M_PLAYLISTS: {
            final BundleableSubscriber<Playlist> subscriber = new BundleableSubscriber<>(binder);
            queryPlaylistsInternal(library, subscriber, args);
            break;
        }
        case M_PLAYLIST: {
            final BundleableSubscriber<Playlist> subscriber = new BundleableSubscriber<>(binder);
            getPlaylistInternal(library, identity, subscriber, args);
            break;
        }
        case M_PLAYLIST_TRACKS: {
            final BundleableSubscriber<Track> subscriber = new BundleableSubscriber<>(binder);
            getPlaylistTracksInternal(library, identity, subscriber, args);
            break;
        }
        case M_TRACKS: {
            final BundleableSubscriber<Track> subscriber = new BundleableSubscriber<>(binder);
            queryTracksInternal(library, subscriber, args);
            break;
        }
        case M_TRACK: {
            final BundleableSubscriber<Track> subscriber = new BundleableSubscriber<>(binder);
            getTrackInternal(library, identity, subscriber, args);
            break;
        }
        default: {
            ok.putBoolean(Extras.OK, false);
            writeCause(ok, new LibraryException(ILLEGAL_URI, new IllegalArgumentException(uri.toString())));
        }
        }
        return ok;
    }
    case LibraryMethods.LIBRARYCONF:
        return getLibraryConfig().dematerialize();
    default:
        Log.e(TAG, "Unknown method " + method);
        ok.putBoolean(Extras.OK, false);
        writeCause(ok, new LibraryException(METHOD_NOT_IMPLEMENTED, new UnsupportedOperationException(method)));
        return ok;
    }
}