Java Code Examples for android.os.ResultReceiver#send()

The following examples show how to use android.os.ResultReceiver#send() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectivityServiceWrapper.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private static void sendNfcState(ResultReceiver receiver) {
    if (mContext == null || receiver == null) return;
    int nfcState = NFC_STATE_UNKNOWN;
    try {
        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
        if (adapter != null) {
            nfcState = (Integer) XposedHelpers.callMethod(adapter, "getAdapterState");
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    } finally {
        Bundle b = new Bundle();
        b.putInt("nfcState", nfcState);
        receiver.send(0, b);
    }
}
 
Example 2
Source File: BluetoothAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Request the record of {@link BluetoothActivityEnergyInfo} object that
 * has the activity and energy info. This can be used to ascertain what
 * the controller has been up to, since the last sample.
 *
 * A null value for the activity info object may be sent if the bluetooth service is
 * unreachable or the device does not support reporting such information.
 *
 * @param result The callback to which to send the activity info.
 * @hide
 */
public void requestControllerActivityEnergyInfo(ResultReceiver result) {
    try {
        mServiceLock.readLock().lock();
        if (mService != null) {
            mService.requestActivityInfo(result);
            result = null;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
    } finally {
        mServiceLock.readLock().unlock();
        if (result != null) {
            // Only send an immediate result if we failed.
            result.send(0, null);
        }
    }
}
 
Example 3
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@MainThread
@Override
public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
    if (DEBUG) Log.v(TAG, "hideSoftInput()");
    boolean wasVis = isInputViewShown();
    mShowInputFlags = 0;
    mShowInputRequested = false;
    doHideWindow();
    clearInsetOfPreviousIme();
    if (resultReceiver != null) {
        resultReceiver.send(wasVis != isInputViewShown()
                ? InputMethodManager.RESULT_HIDDEN
                : (wasVis ? InputMethodManager.RESULT_UNCHANGED_SHOWN
                        : InputMethodManager.RESULT_UNCHANGED_HIDDEN), null);
    }
}
 
Example 4
Source File: TorchService.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private void maybeProcessStartIntent() {
    if (mStartIntent == null || mTorchStatus == TORCH_STATUS_UNKNOWN) return;

    if (ACTION_TOGGLE_TORCH.equals(mStartIntent.getAction())) {
        if (DEBUG) Log.d(TAG, "maybeProcessStartIntent: ACTION_TOGGLE_TORCH");
        toggleTorch();
    } else if (ACTION_TORCH_GET_STATUS.equals(mStartIntent.getAction())) {
        if (DEBUG) Log.d(TAG, "maybeProcessStartIntent: " +
                "ACTION_TORCH_GET_STATUS: mTorchStatus=" + mTorchStatus);
        ResultReceiver receiver = mStartIntent.getParcelableExtra("receiver");
        Bundle data = new Bundle();
        data.putInt(EXTRA_TORCH_STATUS, mTorchStatus);
        receiver.send(0, data);
    }
    mStartIntent = null;
}
 
Example 5
Source File: RecordingService.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null && intent.getAction() != null) {
        if (intent.getAction().equals(ACTION_RECORDING_START)) {
            if (intent.hasExtra(EXTRA_SAMPLING_RATE)) {
                mSamplingRate = intent.getIntExtra(EXTRA_SAMPLING_RATE, DEFAULT_SAMPLING_RATE);
            }
            startRecording();
            return START_STICKY;
        } else if (intent.getAction().equals(ACTION_RECORDING_STOP)) {
            stopRecording();
            return START_STICKY;
        } else if (intent.getAction().equals(ACTION_RECORDING_GET_STATUS)) {
            ResultReceiver receiver = intent.getParcelableExtra("receiver");
            Bundle data = new Bundle();
            data.putInt(EXTRA_RECORDING_STATUS, mRecordingStatus);
            receiver.send(0, data);
            return START_STICKY;
        }
    }

    stopSelf();
    return START_NOT_STICKY;
}
 
Example 6
Source File: DfuBaseService.java    From microbit with Apache License 2.0 6 votes vote down vote up
@Override
protected void onHandleIntent(final Intent intent) {


    int phase = intent.getIntExtra(INTENT_REQUESTED_PHASE, 0) & 0x03;
    resultReceiver = (ResultReceiver) intent.getParcelableExtra(INTENT_RESULT_RECEIVER);
    delayForInitDeviceFirmware = intent.getLongExtra(EXTRA_WAIT_FOR_INIT_DEVICE_FIRMWARE, 0);

    int rc = 0;

    logi("DFUBaseService onHandleIntent phase = " + phase);
    mServicePhase = 0;

    if ((phase & FLASHING_WITH_PAIR_CODE) != 0) {
        mServicePhase = FLASHING_WITH_PAIR_CODE;

        rc = flashingWithPairCode(intent);
    }

    if (resultReceiver != null) {
        rc <<= 8;
        resultReceiver.send(rc | phase, null);
    }
}
 
Example 7
Source File: PermissionUtils.java    From flutter-incall-manager with ISC License 5 votes vote down vote up
private static void send(
        ResultReceiver resultReceiver,
        int requestCode,
        String[] permissions,
        int[] grantResults) {
    Bundle resultData = new Bundle();
    resultData.putStringArray(PERMISSIONS, permissions);
    resultData.putIntArray(GRANT_RESULTS, grantResults);

    resultReceiver.send(requestCode, resultData);
}
 
Example 8
Source File: DownloadService.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private void publishProgress(ResultReceiver receiver, long current, long total, String file) {
    // publishing the progress....
    Bundle resultData = new Bundle();
    resultData.putInt("progress", (int) (current * 100 / total));
    resultData.putLong("current", current);
    resultData.putLong("total", total);
    resultData.putString("file", file);
    receiver.send(UPDATE_PROGRESS, resultData);
}
 
Example 9
Source File: ModHwKeys.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private static void updateWifiConfig(ArrayList<WifiConfiguration> configList, ResultReceiver receiver) {
    try {
        WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        for (WifiConfiguration c : configList) {
            wm.updateNetwork(c);
        }
        wm.saveConfiguration();
        if (receiver != null) {
            receiver.send(0, null);
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 10
Source File: GravityBoxService.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if (intent.getAction().equals(ACTION_TOGGLE_SYNC)) {
        final boolean newState;
        if (intent.hasExtra(AShortcut.EXTRA_ENABLE)) {
            newState = intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false);
        } else {
            newState = !ContentResolver.getMasterSyncAutomatically();
        }
        ContentResolver.setMasterSyncAutomatically(newState);
        if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
            showToast(newState ? 
                    R.string.quick_settings_sync_on :
                        R.string.quick_settings_sync_off);
        }
    } else if (intent.getAction().equals(ACTION_GET_SYNC_STATUS)) {
        boolean syncStatus = ContentResolver.getMasterSyncAutomatically();
        ResultReceiver receiver = intent.getParcelableExtra("receiver");
        Bundle data = new Bundle();
        data.putBoolean(KEY_SYNC_STATUS, syncStatus);
        receiver.send(RESULT_SYNC_STATUS, data);
    } else if (intent.getAction().equals(QuietHoursActivity.ACTION_SET_QUIET_HOURS_MODE)) {
        QuietHours.Mode qhMode = QuietHoursActivity.setQuietHoursMode(this, intent.getStringExtra(
                QuietHoursActivity.EXTRA_QH_MODE));
        if (qhMode != null && intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
            showToast(QuietHoursActivity.getToastResIdFromMode(qhMode));
        }
    }
}
 
Example 11
Source File: FetchAddressIntentService.java    From GitJourney with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(@Nullable Intent intent) {
    Log.v(TAG, "onHandleIntent");
    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    String errorMessage = "";
    // Get the location passed to this service through an extra.
    ArrayList<GitHubUserLocationDataEntry> locationsList = intent.getParcelableArrayListExtra(
            LocationConstants.LOCATION_DATA_EXTRA);
    ResultReceiver mReceiver = intent.getParcelableExtra(
            LocationConstants.RECEIVER);
    try {
        for (int i = 0; i < locationsList.size(); i++) {
            GitHubUserLocationDataEntry entry = locationsList.get(i);
            List<Address> addressList = geocoder.getFromLocationName(entry.getLocation(), 1);
            if (!addressList.isEmpty()) {
                Address address = addressList.get(0);
                entry.setLatitude(address.getLatitude());
                entry.setLongitude(address.getLongitude());
            }
        }
    } catch (IOException ioException) {
        // Catch network or other I/O problems.
        errorMessage = getString(R.string.service_not_available);
        Log.e(TAG, errorMessage, ioException);
    } catch (IllegalArgumentException illegalArgumentException) {
        // Catch invalid latitude or longitude values.
        errorMessage = getString(R.string.invalid_lat_long_used);
        Log.e(TAG, errorMessage, illegalArgumentException);
    }
    Bundle bundle = new Bundle();
    bundle.putParcelableArrayList(LocationConstants.LOCATION_DATA_EXTRA, locationsList);
    mReceiver.send(0, bundle);
}
 
Example 12
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleIsInCallQuery(Intent intent) {
  ResultReceiver resultReceiver = intent.getParcelableExtra(EXTRA_RESULT_RECEIVER);

  if (resultReceiver != null) {
    resultReceiver.send(activePeer != null ? 1 : 0, null);
  }
}
 
Example 13
Source File: ConnectivityManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void startTethering(int type, boolean showProvisioningUi,
        final OnStartTetheringCallback callback, Handler handler) {
    Preconditions.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 {
        String pkgName = mContext.getOpPackageName();
        Log.i(TAG, "startTethering caller:" + pkgName);
        mService.startTethering(type, wrappedCallback, showProvisioningUi, pkgName);
    } catch (RemoteException e) {
        Log.e(TAG, "Exception trying to start tethering.", e);
        wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
    }
}
 
Example 14
Source File: CarrierService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void getCarrierConfig(CarrierIdentifier id, ResultReceiver result) {
    try {
        Bundle data = new Bundle();
        data.putParcelable(KEY_CONFIG_BUNDLE, CarrierService.this.onLoadConfig(id));
        result.send(RESULT_OK, data);
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error in onLoadConfig: " + e.getMessage(), e);
        result.send(RESULT_ERROR, null);
    }
}
 
Example 15
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@MainThread
@Override
public void showSoftInput(int flags, ResultReceiver resultReceiver) {
    if (DEBUG) Log.v(TAG, "showSoftInput()");
    boolean wasVis = isInputViewShown();
    if (dispatchOnShowInputRequested(flags, false)) {
        try {
            showWindow(true);
        } catch (BadTokenException e) {
            // We have ignored BadTokenException here since Jelly Bean MR-2 (API Level 18).
            // We could ignore BadTokenException in InputMethodService#showWindow() instead,
            // but it may break assumptions for those who override #showWindow() that we can
            // detect errors in #showWindow() by checking BadTokenException.
            // TODO: Investigate its feasibility.  Update JavaDoc of #showWindow() of
            // whether it's OK to override #showWindow() or not.
        }
    }
    clearInsetOfPreviousIme();
    // If user uses hard keyboard, IME button should always be shown.
    mImm.setImeWindowStatus(mToken, mStartInputToken,
            mapToImeWindowStatus(isInputViewShown()), mBackDisposition);
    if (resultReceiver != null) {
        resultReceiver.send(wasVis != isInputViewShown()
                ? InputMethodManager.RESULT_SHOWN
                : (wasVis ? InputMethodManager.RESULT_UNCHANGED_SHOWN
                        : InputMethodManager.RESULT_UNCHANGED_HIDDEN), null);
    }
}
 
Example 16
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
        String[] args, ShellCallback callback, ResultReceiver resultReceiver) {

    enforceShell();

    final long token = injectClearCallingIdentity();
    try {
        final int status = (new MyShellCommand()).exec(this, in, out, err, args, callback,
                resultReceiver);
        resultReceiver.send(status, null);
    } finally {
        injectRestoreCallingIdentity(token);
    }
}
 
Example 17
Source File: WebRtcCallService.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleIsInCallQuery(Intent intent) {
    ResultReceiver resultReceiver = intent.getParcelableExtra(EXTRA_RESULT_RECEIVER);

    if (resultReceiver != null) {
        resultReceiver.send(callState.get() != CallState.STATE_IDLE ? 1 : 0, null);
    }
}
 
Example 18
Source File: FetchChannelService.java    From alltv with MIT License 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    if (intent != null) {
        ResultReceiver channelResultReceiver = intent
                .getParcelableExtra(getStringById(R.string.FETCHCHANNELRESULTRECEIVER_STR));

        Gson gson = new Gson();
        SettingsData settingsData = gson.fromJson(intent
                .getStringExtra(getStringById(R.string.SETTINGSDATA_STR)), SettingsData.class);

        Utils.SiteType siteType = (Utils.SiteType) intent.getSerializableExtra(getStringById(R.string.SITETYPE_STR));

        if (siteType == Utils.SiteType.Pooq) {
            mSiteProcessor = new PooqSiteProcessor(getApplicationContext());
        } else if (siteType == Utils.SiteType.Tving) {
            mSiteProcessor = new TvingSiteProcessor(getApplicationContext());
        } else if (siteType == Utils.SiteType.Oksusu) {
            mSiteProcessor = new OksusuSiteProcessor(getApplicationContext());
        }

        String authkey = (String) intent.getSerializableExtra(getStringById(R.string.AUTHKEY_STR));

        if (authkey == null || authkey.length() == 0) {
            mSiteProcessor.setAuthKey("");
        } else {
            mSiteProcessor.setAuthKey(authkey);
        }

        String mode = (String) intent.getSerializableExtra(getStringById(R.string.FETCHMODE_STR));

        ArrayList<ChannelData> channels = new ArrayList<>();
        ArrayList<CategoryData> category = new ArrayList<>();
        boolean error = false;

        if(mode.equals("create")) {
            if (mSiteProcessor.doProcess(settingsData)) {
                channels = mSiteProcessor.getChannelList();
                category = mSiteProcessor.getCategorylList();
            } else {
                error = true;
            }
        } else if(mode.equals("refresh")) {
            channels = intent.getParcelableArrayListExtra(getStringById(R.string.CHANNELS_STR));
            category = intent.getParcelableArrayListExtra(getStringById(R.string.CATEGORY_STR));

            mSiteProcessor.setChannelList(channels);
            mSiteProcessor.setCategorylList(category);

            if(!mSiteProcessor.updateProcess()) {
                error = true;
            }
        }

        Bundle retBundle = new Bundle();
        retBundle.putParcelableArrayList(getStringById(R.string.CHANNELS_STR), channels);
        retBundle.putParcelableArrayList(getStringById(R.string.CATEGORY_STR), category);
        retBundle.putString(getStringById(R.string.AUTHKEY_STR), mSiteProcessor.getAuthKey());
        retBundle.putSerializable(getStringById(R.string.SITETYPE_STR), siteType);
        retBundle.putString(getStringById(R.string.FETCHMODE_STR), mode);

        int retCode;

        if(error) retCode = Utils.Code.ServiceIntent_Fail.ordinal();
        else      retCode = Utils.Code.ServiceIntent_OK.ordinal();

        channelResultReceiver.send(retCode, retBundle);
    }
}
 
Example 19
Source File: ModDisplay.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG) log("Broadcast received: " + intent.toString());
    if (intent.getAction().equals(ACTION_GET_AUTOBRIGHTNESS_CONFIG) &&
            intent.hasExtra("receiver")) {
        ResultReceiver receiver = intent.getParcelableExtra("receiver");
        Bundle data = new Bundle();
        Resources res = context.getResources();
        data.putIntArray("config_autoBrightnessLevels",
                res.getIntArray(res.getIdentifier(
                        "config_autoBrightnessLevels", "array", "android")));
        data.putIntArray("config_autoBrightnessLcdBacklightValues",
                res.getIntArray(res.getIdentifier(
                        "config_autoBrightnessLcdBacklightValues", "array", "android")));
        receiver.send(RESULT_AUTOBRIGHTNESS_CONFIG, data);
    } else if (intent.getAction().equals(ACTION_SET_AUTOBRIGHTNESS_CONFIG)) {
        int[] luxArray = intent.getIntArrayExtra("config_autoBrightnessLevels");
        int[] brightnessArray = intent.getIntArrayExtra("config_autoBrightnessLcdBacklightValues");
        updateAutobrightnessConfig(luxArray, brightnessArray);
    } else if (intent.getAction().equals(GravityBoxSettings.ACTION_PREF_BUTTON_BACKLIGHT_CHANGED)) {
        if (intent.hasExtra(GravityBoxSettings.EXTRA_BB_MODE)) {
            mButtonBacklightMode = intent.getStringExtra(GravityBoxSettings.EXTRA_BB_MODE);
            updateButtonBacklight();
        }
        if (intent.hasExtra(GravityBoxSettings.EXTRA_BB_NOTIF)) {
            mButtonBacklightNotif = intent.getBooleanExtra(GravityBoxSettings.EXTRA_BB_NOTIF, false);
            if (!mButtonBacklightNotif) {
                updateButtonBacklight();
            }
        }
    } else if ((intent.getAction().equals(Intent.ACTION_SCREEN_ON)
            || intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) &&
            !mButtonBacklightMode.equals(GravityBoxSettings.BB_MODE_DEFAULT)) {
        updateButtonBacklight(intent.getAction().equals(Intent.ACTION_SCREEN_ON));
    } else if (intent.getAction().equals(GravityBoxSettings.ACTION_PREF_LOCKSCREEN_BG_CHANGED) &&
            intent.hasExtra(GravityBoxSettings.EXTRA_LOCKSCREEN_BG)) {
        mLsBgLastScreenEnabled = intent.getStringExtra(GravityBoxSettings.EXTRA_LOCKSCREEN_BG)
                .equals(GravityBoxSettings.LOCKSCREEN_BG_LAST_SCREEN);
        if (DEBUG_KIS) log("mLsBgLastScreenEnabled = " + mLsBgLastScreenEnabled);
    } else if (intent.getAction().equals(GravityBoxSettings.ACTION_BATTERY_LED_CHANGED) &&
            intent.hasExtra(GravityBoxSettings.EXTRA_BLED_CHARGING)) {
        ChargingLed cg = ChargingLed.valueOf(intent.getStringExtra(GravityBoxSettings.EXTRA_BLED_CHARGING));
        if (cg == ChargingLed.EMULATED || cg == ChargingLed.CONSTANT) {
            resetLight(LIGHT_ID_BATTERY);
        }
        mChargingLed = cg;
        if (!mPendingNotif) {
            resetLight(LIGHT_ID_NOTIFICATIONS);
        }
    } else if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
        boolean charging = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
        int level = (int) (100f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
                / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
        if (mCharging != charging || mBatteryLevel != level) {
            mCharging = charging;
            mBatteryLevel = level;
            if ((mChargingLed == ChargingLed.EMULATED || mChargingLed == ChargingLed.CONSTANT) &&
                    !mPendingNotif) {
                resetLight(LIGHT_ID_NOTIFICATIONS);
            }
        }
    }
}
 
Example 20
Source File: Tethering.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void sendTetherResult(ResultReceiver receiver, int result) {
    if (receiver != null) {
        receiver.send(result, null);
    }
}