Example usage for android.telecom TelecomManager PRESENTATION_ALLOWED

List of usage examples for android.telecom TelecomManager PRESENTATION_ALLOWED

Introduction

In this page you can find the example usage for android.telecom TelecomManager PRESENTATION_ALLOWED.

Prototype

int PRESENTATION_ALLOWED

To view the source code for android.telecom TelecomManager PRESENTATION_ALLOWED.

Click Source Link

Document

Indicates that the address or number of a call is allowed to be displayed for caller ID.

Usage

From source file:com.android.incallui.ContactInfoCache.java

private void findInfoQueryComplete(Call call, CallerInfo callerInfo, boolean isIncoming,
        boolean didLocalLookup) {
    final String callId = call.getId();
    int presentationMode = call.getNumberPresentation();
    if (callerInfo.contactExists || callerInfo.isEmergencyNumber() || callerInfo.isVoiceMailNumber()) {
        presentationMode = TelecomManager.PRESENTATION_ALLOWED;
    }/*from  w w  w. ja  va 2 s . c  o m*/

    ContactCacheEntry cacheEntry = mInfoMap.get(callId);
    // Ensure we always have a cacheEntry. Replace the existing entry if
    // it has no name or if we found a local contact.
    if (cacheEntry == null || TextUtils.isEmpty(cacheEntry.name) || callerInfo.contactExists) {
        cacheEntry = buildEntry(mContext, callId, callerInfo, presentationMode, isIncoming);
        mInfoMap.put(callId, cacheEntry);
    }

    sendInfoNotifications(callId, cacheEntry);

    if (didLocalLookup) {
        // Before issuing a request for more data from other services, we only check that the
        // contact wasn't found in the local DB.  We don't check the if the cache entry already
        // has a name because we allow overriding cnap data with data from other services.
        if (!callerInfo.contactExists && mPhoneNumberService != null) {
            Log.d(TAG, "Contact lookup. Local contacts miss, checking remote");
            final PhoneNumberServiceListener listener = new PhoneNumberServiceListener(callId);
            mPhoneNumberService.getPhoneNumberInfo(cacheEntry.number, listener, listener, isIncoming);
        } else if (cacheEntry.displayPhotoUri != null) {
            Log.d(TAG, "Contact lookup. Local contact found, starting image load");
            // Load the image with a callback to update the image state.
            // When the load is finished, onImageLoadComplete() will be called.
            ContactsAsyncHelper.startObtainPhotoAsync(TOKEN_UPDATE_PHOTO_FOR_CALL_STATE, mContext,
                    cacheEntry.displayPhotoUri, ContactInfoCache.this, callId);
        } else {
            if (callerInfo.contactExists) {
                Log.d(TAG, "Contact lookup done. Local contact found, no image.");
            } else {
                Log.d(TAG, "Contact lookup done. Local contact not found and"
                        + " no remote lookup service available.");
            }
            clearCallbacks(callId);
        }
    }
}

From source file:com.android.incallui.ContactInfoCache.java

/**
 * Populate a cache entry from a call (which got converted into a caller info).
 *//* www  .j  av  a 2s .c o  m*/
public static void populateCacheEntry(Context context, CallerInfo info, ContactCacheEntry cce, int presentation,
        boolean isIncoming) {
    Preconditions.checkNotNull(info);
    String displayName = null;
    String displayNumber = null;
    String displayLocation = null;
    String label = null;
    boolean isSipCall = false;

    // It appears that there is a small change in behaviour with the
    // PhoneUtils' startGetCallerInfo whereby if we query with an
    // empty number, we will get a valid CallerInfo object, but with
    // fields that are all null, and the isTemporary boolean input
    // parameter as true.

    // In the past, we would see a NULL callerinfo object, but this
    // ends up causing null pointer exceptions elsewhere down the
    // line in other cases, so we need to make this fix instead. It
    // appears that this was the ONLY call to PhoneUtils
    // .getCallerInfo() that relied on a NULL CallerInfo to indicate
    // an unknown contact.

    // Currently, infi.phoneNumber may actually be a SIP address, and
    // if so, it might sometimes include the "sip:" prefix. That
    // prefix isn't really useful to the user, though, so strip it off
    // if present. (For any other URI scheme, though, leave the
    // prefix alone.)
    // TODO: It would be cleaner for CallerInfo to explicitly support
    // SIP addresses instead of overloading the "phoneNumber" field.
    // Then we could remove this hack, and instead ask the CallerInfo
    // for a "user visible" form of the SIP address.
    String number = info.phoneNumber;

    if (!TextUtils.isEmpty(number)) {
        isSipCall = PhoneNumberHelper.isUriNumber(number);
        if (number.startsWith("sip:")) {
            number = number.substring(4);
        }
    }

    if (TextUtils.isEmpty(info.name)) {
        // No valid "name" in the CallerInfo, so fall back to
        // something else.
        // (Typically, we promote the phone number up to the "name" slot
        // onscreen, and possibly display a descriptive string in the
        // "number" slot.)
        if (TextUtils.isEmpty(number)) {
            // No name *or* number! Display a generic "unknown" string
            // (or potentially some other default based on the presentation.)
            displayName = getPresentationString(context, presentation);
            Log.d(TAG, "  ==> no name *or* number! displayName = " + displayName);
        } else if (presentation != TelecomManager.PRESENTATION_ALLOWED) {
            // This case should never happen since the network should never send a phone #
            // AND a restricted presentation. However we leave it here in case of weird
            // network behavior
            displayName = getPresentationString(context, presentation);
            Log.d(TAG, "  ==> presentation not allowed! displayName = " + displayName);
        } else if (!TextUtils.isEmpty(info.cnapName)) {
            // No name, but we do have a valid CNAP name, so use that.
            displayName = info.cnapName;
            info.name = info.cnapName;
            displayNumber = number;
            Log.d(TAG, "  ==> cnapName available: displayName '" + displayName + "', displayNumber '"
                    + displayNumber + "'");
        } else {
            // No name; all we have is a number. This is the typical
            // case when an incoming call doesn't match any contact,
            // or if you manually dial an outgoing number using the
            // dialpad.
            displayNumber = number;

            // Display a geographical description string if available
            // (but only for incoming calls.)
            if (isIncoming) {
                // TODO (CallerInfoAsyncQuery cleanup): Fix the CallerInfo
                // query to only do the geoDescription lookup in the first
                // place for incoming calls.
                displayLocation = info.geoDescription; // may be null
                Log.d(TAG, "Geodescrption: " + info.geoDescription);
            }

            Log.d(TAG, "  ==>  no name; falling back to number:" + " displayNumber '" + Log.pii(displayNumber)
                    + "', displayLocation '" + displayLocation + "'");
        }
    } else {
        // We do have a valid "name" in the CallerInfo. Display that
        // in the "name" slot, and the phone number in the "number" slot.
        if (presentation != TelecomManager.PRESENTATION_ALLOWED) {
            // This case should never happen since the network should never send a name
            // AND a restricted presentation. However we leave it here in case of weird
            // network behavior
            displayName = getPresentationString(context, presentation);
            Log.d(TAG, "  ==> valid name, but presentation not allowed!" + " displayName = " + displayName);
        } else {
            displayName = info.name;
            displayNumber = number;
            label = info.phoneLabel;
            Log.d(TAG, "  ==>  name is present in CallerInfo: displayName '" + displayName
                    + "', displayNumber '" + displayNumber + "'");
        }
    }

    cce.name = displayName;
    cce.number = displayNumber;
    cce.location = displayLocation;
    cce.label = label;
    cce.isSipCall = isSipCall;
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
        final ConnectionRequest request) {
    PhoneAccountHandle accountHandle = request.getAccountHandle();
    ComponentName componentName = new ComponentName(this, TestConnectionService.class);
    if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) {
        final TestConnection connection = new TestConnection(false);
        final Bundle extras = request.getExtras();
        final Uri providedHandle = extras.getParcelable(EXTRA_HANDLE);

        Uri handle = providedHandle == null
                ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(false), null)
                : providedHandle;/*  w  w w .  jav a2 s  .c om*/

        connection.setAddress(handle, TelecomManager.PRESENTATION_ALLOWED);
        connection.setDialing();

        addCall(connection);
        return connection;
    } else {
        return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR,
                "Invalid inputs: " + accountHandle + " " + componentName));
    }
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

private void setAddress(Connection connection, Uri address) {
    connection.setAddress(address, TelecomManager.PRESENTATION_ALLOWED);
    if ("5551234".equals(address.getSchemeSpecificPart())) {
        connection.setCallerDisplayName("Hello World", TelecomManager.PRESENTATION_ALLOWED);
    }/*from www.  j a  v  a2 s  .c  o  m*/
}