use of android.os.ResultReceiver in project android_frameworks_base by ResurrectionRemix.
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;
}
use of android.os.ResultReceiver in project android_frameworks_base by ResurrectionRemix.
the class Tethering method runSilentTetherProvisioningAndEnable.
private void runSilentTetherProvisioningAndEnable(int type, ResultReceiver receiver) {
ResultReceiver proxyReceiver = getProxyReceiver(type, receiver);
sendSilentTetherProvisionIntent(type, proxyReceiver);
}
use of android.os.ResultReceiver in project android_frameworks_base by ResurrectionRemix.
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);
}
});
}
}
use of android.os.ResultReceiver in project android_frameworks_base by ResurrectionRemix.
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));
}
}
}
use of android.os.ResultReceiver in project android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest7 method callShellCommand.
private List<String> callShellCommand(String... args) throws IOException, RemoteException {
// For reset to work, the current time needs to be incrementing.
mInjectedCurrentTimeMillis++;
final AtomicInteger resultCode = new AtomicInteger(Integer.MIN_VALUE);
final ResultReceiver rr = new ResultReceiver(mHandler) {
@Override
public void send(int resultCode_, Bundle resultData) {
resultCode.set(resultCode_);
}
};
final File out = File.createTempFile("shellout-", ".tmp", getTestContext().getCacheDir());
try {
try (final ParcelFileDescriptor fd = ParcelFileDescriptor.open(out, ParcelFileDescriptor.MODE_READ_WRITE)) {
mService.onShellCommand(/* fdin*/
null, /* fdout*/
fd.getFileDescriptor(), /* fderr*/
fd.getFileDescriptor(), args, rr);
}
return readAll(out);
} finally {
out.delete();
}
}
Aggregations