Search in sources :

Example 26 with CanceledException

use of android.app.PendingIntent.CanceledException in project android_packages_apps_Dialer by LineageOS.

the class Bubble method primaryButtonClick.

void primaryButtonClick() {
    if (expanded || textShowing || currentInfo.getActions().isEmpty()) {
        try {
            currentInfo.getPrimaryIntent().send();
        } catch (CanceledException e) {
            throw new RuntimeException(e);
        }
        return;
    }
    doResize(() -> {
        onLeftRightSwitch(isDrawingFromRight());
        viewHolder.setDrawerVisibility(View.VISIBLE);
    });
    View expandedView = viewHolder.getExpandedView();
    expandedView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            expandedView.getViewTreeObserver().removeOnPreDrawListener(this);
            expandedView.setTranslationX(isDrawingFromRight() ? expandedView.getWidth() : -expandedView.getWidth());
            expandedView.animate().setInterpolator(new LinearOutSlowInInterpolator()).translationX(0);
            return false;
        }
    });
    setFocused(true);
    expanded = true;
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) LinearOutSlowInInterpolator(android.support.v4.view.animation.LinearOutSlowInInterpolator) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OnPreDrawListener(android.view.ViewTreeObserver.OnPreDrawListener)

Example 27 with CanceledException

use of android.app.PendingIntent.CanceledException in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSMSDispatcher method sendText.

/**
 * {@inheritDoc}
 */
@Override
public void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, Uri messageUri, String callingPkg, boolean persistMessage) {
    SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu(scAddr, destAddr, text, (deliveryIntent != null), null);
    if (pdu != null) {
        HashMap map = getSmsTrackerMap(destAddr, scAddr, text, pdu);
        SmsTracker tracker = getSmsTracker(map, sentIntent, deliveryIntent, getFormat(), messageUri, false, /*isExpectMore*/
        text, true, /*isText*/
        persistMessage);
        String carrierPackage = getCarrierAppPackageName();
        if (carrierPackage != null) {
            Rlog.d(TAG, "Found carrier package.");
            TextSmsSender smsSender = new TextSmsSender(tracker);
            smsSender.sendSmsByCarrierApp(carrierPackage, new SmsSenderCallback(smsSender));
        } else {
            Rlog.v(TAG, "No carrier package.");
            sendSubmitPdu(tracker);
        }
    } else {
        Rlog.e(TAG, "CdmaSMSDispatcher.sendText(): getSubmitPdu() returned null");
        if (sentIntent != null) {
            try {
                sentIntent.send(SmsManager.RESULT_ERROR_GENERIC_FAILURE);
            } catch (CanceledException ex) {
                Rlog.e(TAG, "Intent has been canceled!");
            }
        }
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) HashMap(java.util.HashMap)

Example 28 with CanceledException

use of android.app.PendingIntent.CanceledException in project android_frameworks_opt_telephony by LineageOS.

the class GsmSMSDispatcher method handleStatusReport.

/**
 * Called when a status report is received.  This should correspond to
 * a previously successful SEND.
 *
 * @param ar AsyncResult passed into the message handler.  ar.result should
 *           be a String representing the status report PDU, as ASCII hex.
 */
private void handleStatusReport(AsyncResult ar) {
    byte[] pdu = (byte[]) ar.result;
    SmsMessage sms = SmsMessage.newFromCDS(pdu);
    if (sms != null) {
        int tpStatus = sms.getStatus();
        int messageRef = sms.mMessageRef;
        for (int i = 0, count = deliveryPendingList.size(); i < count; i++) {
            SmsTracker tracker = deliveryPendingList.get(i);
            if (tracker.mMessageRef == messageRef) {
                // Found it.  Remove from list and broadcast.
                if (tpStatus >= Sms.STATUS_FAILED || tpStatus < Sms.STATUS_PENDING) {
                    deliveryPendingList.remove(i);
                    // Update the message status (COMPLETE or FAILED)
                    tracker.updateSentMessageStatus(mContext, tpStatus);
                }
                PendingIntent intent = tracker.mDeliveryIntent;
                Intent fillIn = new Intent();
                fillIn.putExtra("pdu", pdu);
                fillIn.putExtra("format", getFormat());
                try {
                    intent.send(mContext, Activity.RESULT_OK, fillIn);
                } catch (CanceledException ex) {
                }
                // Only expect to see one tracker matching this messageref
                break;
            }
        }
    }
    mCi.acknowledgeLastIncomingGsmSms(true, Intents.RESULT_SMS_HANDLED, null);
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 29 with CanceledException

use of android.app.PendingIntent.CanceledException in project android_frameworks_opt_telephony by LineageOS.

the class ImsSMSDispatcher method injectSmsPdu.

@VisibleForTesting
@Override
public void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) {
    Rlog.d(TAG, "ImsSMSDispatcher:injectSmsPdu");
    try {
        // TODO We need to decide whether we should allow injecting GSM(3gpp)
        // SMS pdus when the phone is camping on CDMA(3gpp2) network and vice versa.
        android.telephony.SmsMessage msg = android.telephony.SmsMessage.createFromPdu(pdu, format);
        // Only class 1 SMS are allowed to be injected.
        if (msg == null || msg.getMessageClass() != android.telephony.SmsMessage.MessageClass.CLASS_1) {
            if (msg == null) {
                Rlog.e(TAG, "injectSmsPdu: createFromPdu returned null");
            }
            if (receivedIntent != null) {
                receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR);
            }
            return;
        }
        AsyncResult ar = new AsyncResult(receivedIntent, msg, null);
        if (format.equals(SmsConstants.FORMAT_3GPP)) {
            Rlog.i(TAG, "ImsSMSDispatcher:injectSmsText Sending msg=" + msg + ", format=" + format + "to mGsmInboundSmsHandler");
            mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_INJECT_SMS, ar);
        } else if (format.equals(SmsConstants.FORMAT_3GPP2)) {
            Rlog.i(TAG, "ImsSMSDispatcher:injectSmsText Sending msg=" + msg + ", format=" + format + "to mCdmaInboundSmsHandler");
            mCdmaInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_INJECT_SMS, ar);
        } else {
            // Invalid pdu format.
            Rlog.e(TAG, "Invalid pdu format: " + format);
            if (receivedIntent != null)
                receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR);
        }
    } catch (Exception e) {
        Rlog.e(TAG, "injectSmsPdu failed: ", e);
        try {
            if (receivedIntent != null)
                receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR);
        } catch (CanceledException ex) {
        }
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) AsyncResult(android.os.AsyncResult) CanceledException(android.app.PendingIntent.CanceledException) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 30 with CanceledException

use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.

the class ShadowPendingIntent method send.

@Implementation(minSdk = M)
protected void send(Context context, int code, Intent intent, PendingIntent.OnFinished onFinished, Handler handler, String requiredPermission, Bundle options) throws CanceledException {
    this.lastOnFinished = handler == null ? onFinished : (pendingIntent, intent1, resultCode, resultData, resultExtras) -> handler.post(() -> onFinished.onSendFinished(pendingIntent, intent1, resultCode, resultData, resultExtras));
    if (canceled) {
        throw new CanceledException();
    }
    // Fill in the last Intent, if it is mutable, with information now available at send-time.
    Intent[] intentsToSend;
    if (intent != null && isMutable(flags)) {
        // Copy the last intent before filling it in to avoid modifying this PendingIntent.
        intentsToSend = Arrays.copyOf(savedIntents, savedIntents.length);
        Intent lastIntentCopy = new Intent(intentsToSend[intentsToSend.length - 1]);
        lastIntentCopy.fillIn(intent, 0);
        intentsToSend[intentsToSend.length - 1] = lastIntentCopy;
    } else {
        intentsToSend = savedIntents;
    }
    ActivityThread activityThread = (ActivityThread) RuntimeEnvironment.getActivityThread();
    ShadowInstrumentation shadowInstrumentation = Shadow.extract(activityThread.getInstrumentation());
    if (isActivityIntent()) {
        for (Intent intentToSend : intentsToSend) {
            shadowInstrumentation.execStartActivity(context, (IBinder) null, (IBinder) null, (Activity) null, intentToSend, 0, (Bundle) null);
        }
    } else if (isBroadcastIntent()) {
        for (Intent intentToSend : intentsToSend) {
            shadowInstrumentation.sendBroadcastWithPermission(intentToSend, requiredPermission, context, options, code);
        }
    } else if (isServiceIntent()) {
        for (Intent intentToSend : intentsToSend) {
            context.startService(intentToSend);
        }
    } else if (isForegroundServiceIntent()) {
        for (Intent intentToSend : intentsToSend) {
            context.startForegroundService(intentToSend);
        }
    }
    if (isOneShot(flags)) {
        cancel();
    }
}
Also used : Context(android.content.Context) RealObject(org.robolectric.annotation.RealObject) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IIntentSender(android.content.IIntentSender) IBinder(android.os.IBinder) Parcel(android.os.Parcel) ArrayList(java.util.ArrayList) Implements(org.robolectric.annotation.Implements) SuppressLint(android.annotation.SuppressLint) IntentSender(android.content.IntentSender) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) OnMarshaledListener(android.app.PendingIntent.OnMarshaledListener) Accessor(org.robolectric.util.reflector.Accessor) ForType(org.robolectric.util.reflector.ForType) FLAG_ONE_SHOT(android.app.PendingIntent.FLAG_ONE_SHOT) Handler(android.os.Handler) FLAG_NO_CREATE(android.app.PendingIntent.FLAG_NO_CREATE) Nullable(javax.annotation.Nullable) M(android.os.Build.VERSION_CODES.M) O(android.os.Build.VERSION_CODES.O) Iterator(java.util.Iterator) N(android.os.Build.VERSION_CODES.N) Shadow(org.robolectric.shadow.api.Shadow) ActivityThread(android.app.ActivityThread) FLAG_UPDATE_CURRENT(android.app.PendingIntent.FLAG_UPDATE_CURRENT) FLAG_IMMUTABLE(android.app.PendingIntent.FLAG_IMMUTABLE) Creator(android.os.Parcelable.Creator) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) NonNull(android.annotation.NonNull) GuardedBy(javax.annotation.concurrent.GuardedBy) FLAG_CANCEL_CURRENT(android.app.PendingIntent.FLAG_CANCEL_CURRENT) CanceledException(android.app.PendingIntent.CanceledException) Implementation(org.robolectric.annotation.Implementation) Resetter(org.robolectric.annotation.Resetter) Objects(java.util.Objects) RoboIntentSender(org.robolectric.fakes.RoboIntentSender) List(java.util.List) JELLY_BEAN_MR1(android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) Reflector.reflector(org.robolectric.util.reflector.Reflector.reflector) Activity(android.app.Activity) CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ActivityThread(android.app.ActivityThread) Implementation(org.robolectric.annotation.Implementation)

Aggregations

CanceledException (android.app.PendingIntent.CanceledException)33 PendingIntent (android.app.PendingIntent)26 Intent (android.content.Intent)26 AlertDialog (android.app.AlertDialog)3 Bundle (android.os.Bundle)3 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)3 KeyEvent (android.view.KeyEvent)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 AsyncResult (android.os.AsyncResult)2 RecognizerIntent (android.speech.RecognizerIntent)2 SmsMessage (android.telephony.SmsMessage)2 ArrayList (java.util.ArrayList)2 NonNull (android.annotation.NonNull)1 ActivityThread (android.app.ActivityThread)1 FLAG_CANCEL_CURRENT (android.app.PendingIntent.FLAG_CANCEL_CURRENT)1 FLAG_IMMUTABLE (android.app.PendingIntent.FLAG_IMMUTABLE)1 FLAG_NO_CREATE (android.app.PendingIntent.FLAG_NO_CREATE)1 FLAG_ONE_SHOT (android.app.PendingIntent.FLAG_ONE_SHOT)1 FLAG_UPDATE_CURRENT (android.app.PendingIntent.FLAG_UPDATE_CURRENT)1