Search in sources :

Example 36 with ResultReceiver

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();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Bundle(android.os.Bundle) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) ResultReceiver(android.os.ResultReceiver)

Example 37 with ResultReceiver

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;
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) GeneralSecurityException(java.security.GeneralSecurityException) Handler(android.os.Handler) CacheWordHandler(info.guardianproject.cacheword.CacheWordHandler) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) ResultReceiver(android.os.ResultReceiver)

Example 38 with ResultReceiver

use of android.os.ResultReceiver in project muzei by romannurik.

the class ActivateMuzeiIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String action = intent.getAction();
    if (TextUtils.equals(action, ACTION_MARK_NOTIFICATION_READ)) {
        preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
        return;
    } else if (TextUtils.equals(action, ACTION_REMOTE_INSTALL_MUZEI)) {
        Intent remoteIntent = new Intent(Intent.ACTION_VIEW).addCategory(Intent.CATEGORY_BROWSABLE).setData(Uri.parse("market://details?id=" + getPackageName()));
        RemoteIntent.startRemoteActivity(this, remoteIntent, new ResultReceiver(new Handler()) {

            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == RemoteIntent.RESULT_OK) {
                    FirebaseAnalytics.getInstance(ActivateMuzeiIntentService.this).logEvent("activate_notif_install_sent", null);
                    preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
                } else {
                    Toast.makeText(ActivateMuzeiIntentService.this, R.string.activate_install_failed, Toast.LENGTH_SHORT).show();
                }
            }
        });
        return;
    }
    // else -> Open on Phone action
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
    ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "Failed to connect to GoogleApiClient.");
        Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
        return;
    }
    Set<Node> nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_REACHABLE).await().getCapability().getNodes();
    if (nodes.isEmpty()) {
        Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
    } else {
        FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null);
        // Show the open on phone animation
        Intent openOnPhoneIntent = new Intent(this, ConfirmationActivity.class);
        openOnPhoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        openOnPhoneIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
        startActivity(openOnPhoneIntent);
        // Clear the notification
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(INSTALL_NOTIFICATION_ID);
        preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
        // Send the message to the phone to open Muzei
        for (Node node : nodes) {
            Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "notification/open", null).await();
        }
    }
    googleApiClient.disconnect();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ConnectionResult(com.google.android.gms.common.ConnectionResult) Node(com.google.android.gms.wearable.Node) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RemoteIntent(com.google.android.wearable.intent.RemoteIntent) ResultReceiver(android.os.ResultReceiver)

Example 39 with ResultReceiver

use of android.os.ResultReceiver in project platform_frameworks_base by android.

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

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);
    }
}
Also used : Bundle(android.os.Bundle) RemoteException(android.os.RemoteException) ResultReceiver(android.os.ResultReceiver) SystemApi(android.annotation.SystemApi)

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