Search in sources :

Example 51 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by DirtyUnicorns.

the class MediaBrowser method getItem.

/**
     * Retrieves a specific {@link MediaItem} from the connected service. Not
     * all services may support this, so falling back to subscribing to the
     * parent's id should be used when unavailable.
     *
     * @param mediaId The id of the item to retrieve.
     * @param cb The callback to receive the result on.
     */
public void getItem(@NonNull final String mediaId, @NonNull final ItemCallback cb) {
    if (TextUtils.isEmpty(mediaId)) {
        throw new IllegalArgumentException("mediaId is empty.");
    }
    if (cb == null) {
        throw new IllegalArgumentException("cb is null.");
    }
    if (mState != CONNECT_STATE_CONNECTED) {
        Log.i(TAG, "Not connected, unable to retrieve the MediaItem.");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                cb.onError(mediaId);
            }
        });
        return;
    }
    ResultReceiver receiver = new ResultReceiver(mHandler) {

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode != 0 || resultData == null || !resultData.containsKey(MediaBrowserService.KEY_MEDIA_ITEM)) {
                cb.onError(mediaId);
                return;
            }
            Parcelable item = resultData.getParcelable(MediaBrowserService.KEY_MEDIA_ITEM);
            if (!(item instanceof MediaItem)) {
                cb.onError(mediaId);
                return;
            }
            cb.onItemLoaded((MediaItem) item);
        }
    };
    try {
        mServiceBinder.getMediaItem(mediaId, receiver, mServiceCallbacks);
    } catch (RemoteException e) {
        Log.i(TAG, "Remote error getting media item.");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                cb.onError(mediaId);
            }
        });
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) RemoteException(android.os.RemoteException) ResultReceiver(android.os.ResultReceiver)

Example 52 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by DirtyUnicorns.

the class Pm method runShellCommand.

private int runShellCommand(String serviceName, String[] args) {
    final HandlerThread handlerThread = new HandlerThread("results");
    handlerThread.start();
    try {
        ServiceManager.getService(serviceName).shellCommand(FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, args, new ResultReceiver(new Handler(handlerThread.getLooper())));
        return 0;
    } catch (RemoteException e) {
        e.printStackTrace();
    } finally {
        handlerThread.quitSafely();
    }
    return -1;
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) RemoteException(android.os.RemoteException) ResultReceiver(android.os.ResultReceiver)

Example 53 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by DirtyUnicorns.

the class ActivityManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (checkCallingPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump ActivityManager from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " without permission " + android.Manifest.permission.DUMP);
        return;
    }
    boolean dumpAll = false;
    boolean dumpClient = false;
    boolean dumpCheckin = false;
    boolean dumpCheckinFormat = false;
    String dumpPackage = null;
    int opti = 0;
    while (opti < args.length) {
        String opt = args[opti];
        if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
            break;
        }
        opti++;
        if ("-a".equals(opt)) {
            dumpAll = true;
        } else if ("-c".equals(opt)) {
            dumpClient = true;
        } else if ("-p".equals(opt)) {
            if (opti < args.length) {
                dumpPackage = args[opti];
                opti++;
            } else {
                pw.println("Error: -p option requires package argument");
                return;
            }
            dumpClient = true;
        } else if ("--checkin".equals(opt)) {
            dumpCheckin = dumpCheckinFormat = true;
        } else if ("-C".equals(opt)) {
            dumpCheckinFormat = true;
        } else if ("-h".equals(opt)) {
            ActivityManagerShellCommand.dumpHelp(pw, true);
            return;
        } else {
            pw.println("Unknown argument: " + opt + "; use -h for help");
        }
    }
    long origId = Binder.clearCallingIdentity();
    boolean more = false;
    // Is the caller requesting to dump a particular piece of data?
    if (opti < args.length) {
        String cmd = args[opti];
        opti++;
        if ("activities".equals(cmd) || "a".equals(cmd)) {
            synchronized (this) {
                dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, dumpPackage);
            }
        } else if ("recents".equals(cmd) || "r".equals(cmd)) {
            synchronized (this) {
                dumpRecentsLocked(fd, pw, args, opti, true, dumpPackage);
            }
        } else if ("broadcasts".equals(cmd) || "b".equals(cmd)) {
            String[] newArgs;
            String name;
            if (opti >= args.length) {
                name = null;
                newArgs = EMPTY_STRING_ARRAY;
            } else {
                dumpPackage = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
            }
            synchronized (this) {
                dumpBroadcastsLocked(fd, pw, args, opti, true, dumpPackage);
            }
        } else if ("broadcast-stats".equals(cmd)) {
            String[] newArgs;
            String name;
            if (opti >= args.length) {
                name = null;
                newArgs = EMPTY_STRING_ARRAY;
            } else {
                dumpPackage = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
            }
            synchronized (this) {
                if (dumpCheckinFormat) {
                    dumpBroadcastStatsCheckinLocked(fd, pw, args, opti, dumpCheckin, dumpPackage);
                } else {
                    dumpBroadcastStatsLocked(fd, pw, args, opti, true, dumpPackage);
                }
            }
        } else if ("intents".equals(cmd) || "i".equals(cmd)) {
            String[] newArgs;
            String name;
            if (opti >= args.length) {
                name = null;
                newArgs = EMPTY_STRING_ARRAY;
            } else {
                dumpPackage = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
            }
            synchronized (this) {
                dumpPendingIntentsLocked(fd, pw, args, opti, true, dumpPackage);
            }
        } else if ("processes".equals(cmd) || "p".equals(cmd)) {
            String[] newArgs;
            String name;
            if (opti >= args.length) {
                name = null;
                newArgs = EMPTY_STRING_ARRAY;
            } else {
                dumpPackage = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
            }
            synchronized (this) {
                dumpProcessesLocked(fd, pw, args, opti, true, dumpPackage);
            }
        } else if ("oom".equals(cmd) || "o".equals(cmd)) {
            synchronized (this) {
                dumpOomLocked(fd, pw, args, opti, true);
            }
        } else if ("permissions".equals(cmd) || "perm".equals(cmd)) {
            synchronized (this) {
                dumpPermissionsLocked(fd, pw, args, opti, true, null);
            }
        } else if ("provider".equals(cmd)) {
            String[] newArgs;
            String name;
            if (opti >= args.length) {
                name = null;
                newArgs = EMPTY_STRING_ARRAY;
            } else {
                name = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
            }
            if (!dumpProvider(fd, pw, name, newArgs, 0, dumpAll)) {
                pw.println("No providers match: " + name);
                pw.println("Use -h for help.");
            }
        } else if ("providers".equals(cmd) || "prov".equals(cmd)) {
            synchronized (this) {
                dumpProvidersLocked(fd, pw, args, opti, true, null);
            }
        } else if ("service".equals(cmd)) {
            String[] newArgs;
            String name;
            if (opti >= args.length) {
                name = null;
                newArgs = EMPTY_STRING_ARRAY;
            } else {
                name = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
            }
            if (!mServices.dumpService(fd, pw, name, newArgs, 0, dumpAll)) {
                pw.println("No services match: " + name);
                pw.println("Use -h for help.");
            }
        } else if ("package".equals(cmd)) {
            String[] newArgs;
            if (opti >= args.length) {
                pw.println("package: no package name specified");
                pw.println("Use -h for help.");
            } else {
                dumpPackage = args[opti];
                opti++;
                newArgs = new String[args.length - opti];
                if (args.length > 2)
                    System.arraycopy(args, opti, newArgs, 0, args.length - opti);
                args = newArgs;
                opti = 0;
                more = true;
            }
        } else if ("associations".equals(cmd) || "as".equals(cmd)) {
            synchronized (this) {
                dumpAssociationsLocked(fd, pw, args, opti, true, dumpClient, dumpPackage);
            }
        } else if ("services".equals(cmd) || "s".equals(cmd)) {
            if (dumpClient) {
                ActiveServices.ServiceDumper dumper;
                synchronized (this) {
                    dumper = mServices.newServiceDumperLocked(fd, pw, args, opti, true, dumpPackage);
                }
                dumper.dumpWithClient();
            } else {
                synchronized (this) {
                    mServices.newServiceDumperLocked(fd, pw, args, opti, true, dumpPackage).dumpLocked();
                }
            }
        } else if ("locks".equals(cmd)) {
            LockGuard.dump(fd, pw, args);
        } else {
            // Dumping a single activity?
            if (!dumpActivity(fd, pw, cmd, args, opti, dumpAll)) {
                ActivityManagerShellCommand shell = new ActivityManagerShellCommand(this, true);
                int res = shell.exec(this, null, fd, null, args, new ResultReceiver(null));
                if (res < 0) {
                    pw.println("Bad activity command, or no activities match: " + cmd);
                    pw.println("Use -h for help.");
                }
            }
        }
        if (!more) {
            Binder.restoreCallingIdentity(origId);
            return;
        }
    }
    // No piece of data specified, dump everything.
    if (dumpCheckinFormat) {
        dumpBroadcastStatsCheckinLocked(fd, pw, args, opti, dumpCheckin, dumpPackage);
    } else if (dumpClient) {
        ActiveServices.ServiceDumper sdumper;
        synchronized (this) {
            dumpPendingIntentsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpBroadcastsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            if (dumpAll || dumpPackage != null) {
                dumpBroadcastStatsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
                pw.println();
                if (dumpAll) {
                    pw.println("-------------------------------------------------------------------------------");
                }
            }
            dumpProvidersLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpPermissionsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            sdumper = mServices.newServiceDumperLocked(fd, pw, args, opti, dumpAll, dumpPackage);
        }
        sdumper.dumpWithClient();
        pw.println();
        synchronized (this) {
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpRecentsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
            if (mAssociations.size() > 0) {
                pw.println();
                if (dumpAll) {
                    pw.println("-------------------------------------------------------------------------------");
                }
                dumpAssociationsLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
            }
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpProcessesLocked(fd, pw, args, opti, dumpAll, dumpPackage);
        }
    } else {
        synchronized (this) {
            dumpPendingIntentsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpBroadcastsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            if (dumpAll || dumpPackage != null) {
                dumpBroadcastStatsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
                pw.println();
                if (dumpAll) {
                    pw.println("-------------------------------------------------------------------------------");
                }
            }
            dumpProvidersLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpPermissionsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            mServices.newServiceDumperLocked(fd, pw, args, opti, dumpAll, dumpPackage).dumpLocked();
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpRecentsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
            if (mAssociations.size() > 0) {
                pw.println();
                if (dumpAll) {
                    pw.println("-------------------------------------------------------------------------------");
                }
                dumpAssociationsLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
            }
            pw.println();
            if (dumpAll) {
                pw.println("-------------------------------------------------------------------------------");
            }
            dumpProcessesLocked(fd, pw, args, opti, dumpAll, dumpPackage);
        }
    }
    Binder.restoreCallingIdentity(origId);
}
Also used : Point(android.graphics.Point) IResultReceiver(com.android.internal.os.IResultReceiver) ResultReceiver(android.os.ResultReceiver)

Example 54 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by DirtyUnicorns.

the class Tethering method runSilentTetherProvisioningAndEnable.

private void runSilentTetherProvisioningAndEnable(int type, ResultReceiver receiver) {
    ResultReceiver proxyReceiver = getProxyReceiver(type, receiver);
    sendSilentTetherProvisionIntent(type, proxyReceiver);
}
Also used : ResultReceiver(android.os.ResultReceiver)

Example 55 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by DirtyUnicorns.

the class Tethering method getProxyReceiver.

/**
     * Creates a proxy {@link ResultReceiver} which enables tethering if the provsioning result is
     * successful before firing back up to the wrapped receiver.
     *
     * @param type The type of tethering being enabled.
     * @param receiver A ResultReceiver which will be called back with an int resultCode.
     * @return The proxy receiver.
     */
private ResultReceiver getProxyReceiver(final int type, final ResultReceiver receiver) {
    ResultReceiver rr = new ResultReceiver(null) {

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            // If provisioning is successful, enable tethering, otherwise just send the error.
            if (resultCode == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
                enableTetheringInternal(type, true, receiver);
            } else {
                sendTetherResult(receiver, resultCode);
            }
        }
    };
    // The following is necessary to avoid unmarshalling issues when sending the receiver
    // across processes.
    Parcel parcel = Parcel.obtain();
    rr.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    ResultReceiver receiverForSending = ResultReceiver.CREATOR.createFromParcel(parcel);
    parcel.recycle();
    return receiverForSending;
}
Also used : Bundle(android.os.Bundle) Parcel(android.os.Parcel) ResultReceiver(android.os.ResultReceiver)

Aggregations

ResultReceiver (android.os.ResultReceiver)70 Bundle (android.os.Bundle)38 RemoteException (android.os.RemoteException)11 Handler (android.os.Handler)9 HandlerThread (android.os.HandlerThread)6 OnSharedElementsReadyListener (android.app.SharedElementCallback.OnSharedElementsReadyListener)5 Intent (android.content.Intent)5 Parcel (android.os.Parcel)5 Parcelable (android.os.Parcelable)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 JSONArray (org.json.JSONArray)5 JSONException (org.json.JSONException)5 ParcelFileDescriptor (android.os.ParcelFileDescriptor)4 File (java.io.File)4 SharedPreferences (android.content.SharedPreferences)3 IOException (java.io.IOException)3 Point (android.graphics.Point)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 IResultReceiver (com.android.internal.os.IResultReceiver)2 JSONObject (org.json.JSONObject)2