use of android.os.ResultReceiver in project platform_frameworks_base by android.
the class ConnectivityManager method startTethering.
/**
* Runs tether provisioning for the given type if needed and then starts tethering if
* the check succeeds. If no carrier provisioning is required for tethering, tethering is
* enabled immediately. If provisioning fails, tethering will not be enabled. It also
* schedules tether provisioning re-checks if appropriate.
*
* @param type The type of tethering to start. Must be one of
* {@link ConnectivityManager.TETHERING_WIFI},
* {@link ConnectivityManager.TETHERING_USB}, or
* {@link ConnectivityManager.TETHERING_BLUETOOTH}.
* @param showProvisioningUi a boolean indicating to show the provisioning app UI if there
* is one. This should be true the first time this function is called and also any time
* the user can see this UI. It gives users information from their carrier about the
* check failing and how they can sign up for tethering if possible.
* @param callback an {@link OnStartTetheringCallback} which will be called to notify the caller
* of the result of trying to tether.
* @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
* @hide
*/
@SystemApi
public void startTethering(int type, boolean showProvisioningUi, final OnStartTetheringCallback callback, Handler handler) {
checkNotNull(callback, "OnStartTetheringCallback cannot be null.");
ResultReceiver wrappedCallback = new ResultReceiver(handler) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == TETHER_ERROR_NO_ERROR) {
callback.onTetheringStarted();
} else {
callback.onTetheringFailed();
}
}
};
try {
mService.startTethering(type, wrappedCallback, showProvisioningUi);
} catch (RemoteException e) {
Log.e(TAG, "Exception trying to start tethering.", e);
wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
}
}
use of android.os.ResultReceiver in project storymaker by StoryMaker.
the class CacheWordActivity method requestPassphrase.
private void requestPassphrase() {
mViewCreatePin.setVisibility(View.GONE);
mViewEnterPin.setVisibility(View.VISIBLE);
mButton = (Button) findViewById(R.id.btnOpen);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mTextEnterPin.getText().toString().length() == 0)
return;
// Check passphrase
try {
if (mNotif == null) {
Timber.d("no handler notification");
// only display notification if the user has set a pin
SharedPreferences sp = getSharedPreferences("appPrefs", MODE_PRIVATE);
String cachewordStatus = sp.getString("cacheword_status", "default");
if (cachewordStatus.equals(BaseActivity.CACHEWORD_SET)) {
Timber.d("pin set, so display notification (cacheword)");
mNotif = buildNotification(CacheWordActivity.this);
mCacheWordHandler.setNotification(mNotif);
} else {
Timber.d("no pin set, so no notification (cacheword)");
}
Timber.d("set handler notification?");
} else {
Timber.d("handler has a notification");
}
mCacheWordHandler.setPassphrase(mTextEnterPin.getText().toString().toCharArray());
Timber.d("verified pin (request)");
} catch (GeneralSecurityException gse) {
mTextEnterPin.setText("");
Log.e("CacheWordActivity", "failed to verify pin (request): " + gse.getMessage());
return;
}
}
});
mTextEnterPin.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_GO) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
Handler threadHandler = new Handler();
imm.hideSoftInputFromWindow(v.getWindowToken(), 0, new ResultReceiver(threadHandler) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
mButton.performClick();
}
});
return true;
}
return false;
}
});
}
use of android.os.ResultReceiver in project platform_frameworks_base by android.
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();
}
}
use of android.os.ResultReceiver in project platform_frameworks_base by android.
the class Tethering method runUiTetherProvisioningAndEnable.
private void runUiTetherProvisioningAndEnable(int type, ResultReceiver receiver) {
ResultReceiver proxyReceiver = getProxyReceiver(type, receiver);
sendUiTetherProvisionIntent(type, proxyReceiver);
}
use of android.os.ResultReceiver in project platform_frameworks_base by android.
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));
}
}
}
Aggregations