Search in sources :

Example 11 with ResultReceiver

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

the class DirectStatementService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    if (intent == null) {
        Log.e(TAG, "onStartCommand called with null intent");
        return START_STICKY;
    }
    if (intent.getAction().equals(CHECK_ALL_ACTION)) {
        Bundle extras = intent.getExtras();
        List<String> sources = extras.getStringArrayList(EXTRA_SOURCE_ASSET_DESCRIPTORS);
        String target = extras.getString(EXTRA_TARGET_ASSET_DESCRIPTOR);
        String relation = extras.getString(EXTRA_RELATION);
        ResultReceiver resultReceiver = extras.getParcelable(EXTRA_RESULT_RECEIVER);
        if (resultReceiver == null) {
            Log.e(TAG, " Intent does not have extra " + EXTRA_RESULT_RECEIVER);
            return START_STICKY;
        }
        if (sources == null) {
            Log.e(TAG, " Intent does not have extra " + EXTRA_SOURCE_ASSET_DESCRIPTORS);
            resultReceiver.send(RESULT_FAIL, Bundle.EMPTY);
            return START_STICKY;
        }
        if (target == null) {
            Log.e(TAG, " Intent does not have extra " + EXTRA_TARGET_ASSET_DESCRIPTOR);
            resultReceiver.send(RESULT_FAIL, Bundle.EMPTY);
            return START_STICKY;
        }
        if (relation == null) {
            Log.e(TAG, " Intent does not have extra " + EXTRA_RELATION);
            resultReceiver.send(RESULT_FAIL, Bundle.EMPTY);
            return START_STICKY;
        }
        mHandler.post(new ExceptionLoggingFutureTask<Void>(new IsAssociatedCallable(sources, target, relation, resultReceiver), TAG));
    } else {
        Log.e(TAG, "onStartCommand called with unsupported action: " + intent.getAction());
    }
    return START_STICKY;
}
Also used : Bundle(android.os.Bundle) ResultReceiver(android.os.ResultReceiver)

Example 12 with ResultReceiver

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

the class BatteryService method dumpInternal.

private void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) {
    synchronized (mLock) {
        if (args == null || args.length == 0 || "-a".equals(args[0])) {
            pw.println("Current Battery Service state:");
            if (mUpdatesStopped) {
                pw.println("  (UPDATES STOPPED -- use 'reset' to restart)");
            }
            pw.println("  AC powered: " + mBatteryProps.chargerAcOnline);
            pw.println("  USB powered: " + mBatteryProps.chargerUsbOnline);
            pw.println("  Wireless powered: " + mBatteryProps.chargerWirelessOnline);
            pw.println("  Max charging current: " + mBatteryProps.maxChargingCurrent);
            pw.println("  Max charging voltage: " + mBatteryProps.maxChargingVoltage);
            pw.println("  Charge counter: " + mBatteryProps.batteryChargeCounter);
            pw.println("  status: " + mBatteryProps.batteryStatus);
            pw.println("  health: " + mBatteryProps.batteryHealth);
            pw.println("  present: " + mBatteryProps.batteryPresent);
            pw.println("  level: " + mBatteryProps.batteryLevel);
            pw.println("  scale: " + BATTERY_SCALE);
            pw.println("  voltage: " + mBatteryProps.batteryVoltage);
            pw.println("  temperature: " + mBatteryProps.batteryTemperature);
            pw.println("  technology: " + mBatteryProps.batteryTechnology);
        } else {
            Shell shell = new Shell();
            shell.exec(mBinderService, null, fd, null, args, new ResultReceiver(null));
        }
    }
}
Also used : ResultReceiver(android.os.ResultReceiver)

Example 13 with ResultReceiver

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

the class ExitTransitionCoordinator method notifyComplete.

protected void notifyComplete() {
    if (isReadyToNotify()) {
        if (!mSharedElementNotified) {
            mSharedElementNotified = true;
            delayCancel();
            if (mListener == null) {
                mResultReceiver.send(MSG_TAKE_SHARED_ELEMENTS, mSharedElementBundle);
                notifyExitComplete();
            } else {
                final ResultReceiver resultReceiver = mResultReceiver;
                final Bundle sharedElementBundle = mSharedElementBundle;
                mListener.onSharedElementsArrived(mSharedElementNames, mSharedElements, new OnSharedElementsReadyListener() {

                    @Override
                    public void onSharedElementsReady() {
                        resultReceiver.send(MSG_TAKE_SHARED_ELEMENTS, sharedElementBundle);
                        notifyExitComplete();
                    }
                });
            }
        } else {
            notifyExitComplete();
        }
    }
}
Also used : Bundle(android.os.Bundle) OnSharedElementsReadyListener(android.app.SharedElementCallback.OnSharedElementsReadyListener) ResultReceiver(android.os.ResultReceiver)

Example 14 with ResultReceiver

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

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 15 with ResultReceiver

use of android.os.ResultReceiver in project easy by MehdiBenmesa.

the class NoteService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        switch(intent.getAction()) {
            case PUT_STUDENT_NOTE:
                final ResultReceiver receiverNote = intent.getParcelableExtra(DATA_RECEIVER);
                Bundle noteStudent = new Bundle();
                receiverNote.send(STATUS_RUNNING, Bundle.EMPTY);
                try {
                    JSONObject dataToSend = new JSONObject(intent.getStringExtra("dataToSend"));
                    putNoteStudent(dataToSend);
                    receiverNote.send(STATUS_FINISHED, noteStudent);
                } catch (Exception e) {
                    /* Sending error message back to activity */
                    noteStudent.putString(Intent.EXTRA_TEXT, e.toString());
                    receiverNote.send(STATUS_ERROR, noteStudent);
                }
                break;
            case GET_NOTE_STUDENT:
                final ResultReceiver receiver = intent.getParcelableExtra(DATA_RECEIVER);
                final Bundle note = new Bundle();
                receiver.send(STATUS_RUNNING, Bundle.EMPTY);
                try {
                    getNotesByStudent(new INote() {

                        @Override
                        public void onDataReceived(JSONArray data) {
                            note.putString("action", GET_NOTE_STUDENT);
                            note.putSerializable("result", data.toString());
                            receiver.send(STATUS_FINISHED, note);
                        }
                    });
                } catch (Exception e) {
                    /* Sending error message back to activity */
                    note.putString(Intent.EXTRA_TEXT, e.toString());
                    receiver.send(STATUS_ERROR, note);
                }
                break;
            case GET_NOTE_STUDENT_MODULE:
                final ResultReceiver receiverStudentModule = intent.getParcelableExtra(DATA_RECEIVER);
                final String moduleId = intent.getParcelableExtra("moduleId");
                final Bundle noteStudentModule = new Bundle();
                receiverStudentModule.send(STATUS_RUNNING, Bundle.EMPTY);
                try {
                    getNoteByStudentByModule(moduleId, new INote() {

                        @Override
                        public void onDataReceived(JSONArray data) {
                            noteStudentModule.putString("action", GET_NOTE_STUDENT);
                            noteStudentModule.putSerializable("result", data.toString());
                            receiverStudentModule.send(STATUS_FINISHED, noteStudentModule);
                        }
                    });
                } catch (Exception e) {
                    /* Sending error message back to activity */
                    noteStudentModule.putString(Intent.EXTRA_TEXT, e.toString());
                    receiverStudentModule.send(STATUS_ERROR, noteStudentModule);
                }
                break;
        }
        this.stopSelf();
    }
}
Also used : JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) 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