Search in sources :

Example 16 with DialerPhoneNumber

use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.

the class BlockingCommand method run.

@Override
public ListenableFuture<String> run(Arguments args) throws IllegalCommandLineArgumentException {
    if (args.getPositionals().isEmpty()) {
        return Futures.immediateFuture(getUsage());
    }
    String command = args.getPositionals().get(0);
    if ("block".equals(command)) {
        String number = args.getPositionals().get(1);
        return Futures.transform(Blocking.block(appContext, ImmutableList.of(number), null), (unused) -> "blocked " + number, MoreExecutors.directExecutor());
    }
    if ("unblock".equals(command)) {
        String number = args.getPositionals().get(1);
        return Futures.transform(Blocking.unblock(appContext, ImmutableList.of(number), null), (unused) -> "unblocked " + number, MoreExecutors.directExecutor());
    }
    if ("isblocked".equals(command)) {
        String number = args.getPositionals().get(1);
        ListenableFuture<DialerPhoneNumber> dialerPhoneNumberFuture = executorService.submit(() -> new DialerPhoneNumberUtil().parse(number, null));
        ListenableFuture<PhoneLookupInfo> lookupFuture = Futures.transformAsync(dialerPhoneNumberFuture, (dialerPhoneNumber) -> PhoneLookupComponent.get(appContext).compositePhoneLookup().lookup(dialerPhoneNumber), executorService);
        return Futures.transform(lookupFuture, (info) -> new PhoneLookupInfoConsolidator(info).isBlocked() ? "true" : "false", MoreExecutors.directExecutor());
    }
    return Futures.immediateFuture(getUsage());
}
Also used : PhoneLookupInfoConsolidator(com.android.dialer.phonelookup.consolidator.PhoneLookupInfoConsolidator) PhoneLookupInfo(com.android.dialer.phonelookup.PhoneLookupInfo) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) DialerPhoneNumberUtil(com.android.dialer.phonenumberproto.DialerPhoneNumberUtil)

Example 17 with DialerPhoneNumber

use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.

the class SystemCallLogDataSource method handleInsertsAndUpdates.

private void handleInsertsAndUpdates(Context appContext, CallLogMutations mutations, Set<Long> existingAnnotatedCallLogIds) {
    long previousTimestampProcessed = sharedPreferences.getLong(PREF_LAST_TIMESTAMP_PROCESSED, 0L);
    DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
    // TODO(zachh): Really should be getting last 1000 by timestamp, not by last modified.
    try (Cursor cursor = appContext.getContentResolver().query(Calls.CONTENT_URI_WITH_VOICEMAIL, getProjection(), Calls.LAST_MODIFIED + " > ? AND " + Voicemails.DELETED + " = 0", new String[] { String.valueOf(previousTimestampProcessed) }, Calls.LAST_MODIFIED + " DESC LIMIT 1000")) {
        if (cursor == null) {
            LogUtil.e("SystemCallLogDataSource.handleInsertsAndUpdates", "null cursor");
            return;
        }
        if (!cursor.moveToFirst()) {
            LogUtil.i("SystemCallLogDataSource.handleInsertsAndUpdates", "no entries to insert/update");
            return;
        }
        LogUtil.i("SystemCallLogDataSource.handleInsertsAndUpdates", "found %d entries to insert/update", cursor.getCount());
        int idColumn = cursor.getColumnIndexOrThrow(Calls._ID);
        int dateColumn = cursor.getColumnIndexOrThrow(Calls.DATE);
        int lastModifiedColumn = cursor.getColumnIndexOrThrow(Calls.LAST_MODIFIED);
        int numberColumn = cursor.getColumnIndexOrThrow(Calls.NUMBER);
        int presentationColumn = cursor.getColumnIndexOrThrow(Calls.NUMBER_PRESENTATION);
        int typeColumn = cursor.getColumnIndexOrThrow(Calls.TYPE);
        int countryIsoColumn = cursor.getColumnIndexOrThrow(Calls.COUNTRY_ISO);
        int durationsColumn = cursor.getColumnIndexOrThrow(Calls.DURATION);
        int dataUsageColumn = cursor.getColumnIndexOrThrow(Calls.DATA_USAGE);
        int transcriptionColumn = cursor.getColumnIndexOrThrow(Calls.TRANSCRIPTION);
        int voicemailUriColumn = cursor.getColumnIndexOrThrow(Calls.VOICEMAIL_URI);
        int isReadColumn = cursor.getColumnIndexOrThrow(Calls.IS_READ);
        int newColumn = cursor.getColumnIndexOrThrow(Calls.NEW);
        int geocodedLocationColumn = cursor.getColumnIndexOrThrow(Calls.GEOCODED_LOCATION);
        int phoneAccountComponentColumn = cursor.getColumnIndexOrThrow(Calls.PHONE_ACCOUNT_COMPONENT_NAME);
        int phoneAccountIdColumn = cursor.getColumnIndexOrThrow(Calls.PHONE_ACCOUNT_ID);
        int featuresColumn = cursor.getColumnIndexOrThrow(Calls.FEATURES);
        int postDialDigitsColumn = cursor.getColumnIndexOrThrow(Calls.POST_DIAL_DIGITS);
        // The cursor orders by LAST_MODIFIED DESC, so the first result is the most recent timestamp
        // processed.
        lastTimestampProcessed = cursor.getLong(lastModifiedColumn);
        do {
            long id = cursor.getLong(idColumn);
            long date = cursor.getLong(dateColumn);
            String numberAsStr = cursor.getString(numberColumn);
            int type;
            if (cursor.isNull(typeColumn) || (type = cursor.getInt(typeColumn)) == 0) {
                // CallLog.Calls#TYPE lists the allowed values, which are non-null and non-zero.
                throw new IllegalStateException("call type is missing");
            }
            int presentation;
            if (cursor.isNull(presentationColumn) || (presentation = cursor.getInt(presentationColumn)) == 0) {
                // non-zero.
                throw new IllegalStateException("presentation is missing");
            }
            String countryIso = cursor.getString(countryIsoColumn);
            int duration = cursor.getInt(durationsColumn);
            int dataUsage = cursor.getInt(dataUsageColumn);
            String transcription = cursor.getString(transcriptionColumn);
            String voicemailUri = cursor.getString(voicemailUriColumn);
            int isRead = cursor.getInt(isReadColumn);
            int isNew = cursor.getInt(newColumn);
            String geocodedLocation = cursor.getString(geocodedLocationColumn);
            String phoneAccountComponentName = cursor.getString(phoneAccountComponentColumn);
            String phoneAccountId = cursor.getString(phoneAccountIdColumn);
            int features = cursor.getInt(featuresColumn);
            String postDialDigits = cursor.getString(postDialDigitsColumn);
            // Exclude Duo audio calls.
            if (isDuoAudioCall(phoneAccountComponentName, features)) {
                continue;
            }
            ContentValues contentValues = new ContentValues();
            contentValues.put(AnnotatedCallLog.TIMESTAMP, date);
            if (!TextUtils.isEmpty(numberAsStr)) {
                String numberWithPostDialDigits = postDialDigits == null ? numberAsStr : numberAsStr + postDialDigits;
                DialerPhoneNumber dialerPhoneNumber = dialerPhoneNumberUtil.parse(numberWithPostDialDigits, countryIso);
                contentValues.put(AnnotatedCallLog.NUMBER, dialerPhoneNumber.toByteArray());
                String formattedNumber = PhoneNumberUtils.formatNumber(numberWithPostDialDigits, countryIso);
                if (formattedNumber == null) {
                    formattedNumber = numberWithPostDialDigits;
                }
                contentValues.put(AnnotatedCallLog.FORMATTED_NUMBER, formattedNumber);
            } else {
                contentValues.put(AnnotatedCallLog.NUMBER, DialerPhoneNumber.getDefaultInstance().toByteArray());
            }
            contentValues.put(AnnotatedCallLog.NUMBER_PRESENTATION, presentation);
            contentValues.put(AnnotatedCallLog.CALL_TYPE, type);
            contentValues.put(AnnotatedCallLog.IS_READ, isRead);
            contentValues.put(AnnotatedCallLog.NEW, isNew);
            contentValues.put(AnnotatedCallLog.GEOCODED_LOCATION, geocodedLocation);
            contentValues.put(AnnotatedCallLog.PHONE_ACCOUNT_COMPONENT_NAME, phoneAccountComponentName);
            contentValues.put(AnnotatedCallLog.PHONE_ACCOUNT_ID, phoneAccountId);
            contentValues.put(AnnotatedCallLog.FEATURES, features);
            contentValues.put(AnnotatedCallLog.DURATION, duration);
            contentValues.put(AnnotatedCallLog.DATA_USAGE, dataUsage);
            contentValues.put(AnnotatedCallLog.TRANSCRIPTION, transcription);
            contentValues.put(AnnotatedCallLog.VOICEMAIL_URI, voicemailUri);
            contentValues.put(AnnotatedCallLog.CALL_MAPPING_ID, String.valueOf(date));
            setTranscriptionState(cursor, contentValues);
            if (existingAnnotatedCallLogIds.contains(id)) {
                mutations.update(id, contentValues);
            } else {
                mutations.insert(id, contentValues);
            }
        } while (cursor.moveToNext());
    }
}
Also used : ContentValues(android.content.ContentValues) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) Cursor(android.database.Cursor) DialerPhoneNumberUtil(com.android.dialer.phonenumberproto.DialerPhoneNumberUtil)

Example 18 with DialerPhoneNumber

use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.

the class VoicemailDataSource method fill.

@Override
@SuppressWarnings("missingPermission")
public ListenableFuture<Void> fill(CallLogMutations mutations) {
    if (!PermissionsUtil.hasReadPhoneStatePermissions(appContext)) {
        for (Entry<Long, ContentValues> insert : mutations.getInserts().entrySet()) {
            insert.getValue().put(AnnotatedCallLog.IS_VOICEMAIL_CALL, 0);
        }
        return Futures.immediateFuture(null);
    }
    return backgroundExecutor.submit(() -> {
        TelecomManager telecomManager = appContext.getSystemService(TelecomManager.class);
        for (Entry<Long, ContentValues> insert : mutations.getInserts().entrySet()) {
            ContentValues values = insert.getValue();
            PhoneAccountHandle phoneAccountHandle = TelecomUtil.composePhoneAccountHandle(values.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_COMPONENT_NAME), values.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_ID));
            DialerPhoneNumber dialerPhoneNumber;
            try {
                dialerPhoneNumber = DialerPhoneNumber.parseFrom(values.getAsByteArray(AnnotatedCallLog.NUMBER));
            } catch (InvalidProtocolBufferException e) {
                throw new IllegalStateException(e);
            }
            if (telecomManager.isVoiceMailNumber(phoneAccountHandle, dialerPhoneNumber.getNormalizedNumber())) {
                values.put(AnnotatedCallLog.IS_VOICEMAIL_CALL, 1);
                TelephonyManager telephonyManager = TelephonyManagerCompat.getTelephonyManagerForPhoneAccountHandle(appContext, phoneAccountHandle);
                values.put(AnnotatedCallLog.VOICEMAIL_CALL_TAG, telephonyManager.getVoiceMailAlphaTag());
            } else {
                values.put(AnnotatedCallLog.IS_VOICEMAIL_CALL, 0);
            }
        }
        return null;
    });
}
Also used : ContentValues(android.content.ContentValues) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelephonyManager(android.telephony.TelephonyManager) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TelecomManager(android.telecom.TelecomManager)

Example 19 with DialerPhoneNumber

use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.

the class SystemBlockedNumberPhoneLookup method queryNumbers.

@WorkerThread
private ImmutableMap<DialerPhoneNumber, SystemBlockedNumberInfo> queryNumbers(ImmutableSet<DialerPhoneNumber> numbers) {
    Assert.isWorkerThread();
    PartitionedNumbers partitionedNumbers = new PartitionedNumbers(numbers);
    Set<DialerPhoneNumber> blockedNumbers = new ArraySet<>();
    Selection normalizedSelection = Selection.column(BlockedNumbers.COLUMN_E164_NUMBER).in(partitionedNumbers.validE164Numbers());
    try (Cursor cursor = appContext.getContentResolver().query(BlockedNumbers.CONTENT_URI, new String[] { BlockedNumbers.COLUMN_E164_NUMBER }, normalizedSelection.getSelection(), normalizedSelection.getSelectionArgs(), null)) {
        while (cursor != null && cursor.moveToNext()) {
            blockedNumbers.addAll(partitionedNumbers.dialerPhoneNumbersForValidE164(cursor.getString(0)));
        }
    }
    Selection rawSelection = Selection.column(BlockedNumbers.COLUMN_ORIGINAL_NUMBER).in(partitionedNumbers.invalidNumbers());
    try (Cursor cursor = appContext.getContentResolver().query(BlockedNumbers.CONTENT_URI, new String[] { BlockedNumbers.COLUMN_ORIGINAL_NUMBER }, rawSelection.getSelection(), rawSelection.getSelectionArgs(), null)) {
        while (cursor != null && cursor.moveToNext()) {
            blockedNumbers.addAll(partitionedNumbers.dialerPhoneNumbersForInvalid(cursor.getString(0)));
        }
    }
    ImmutableMap.Builder<DialerPhoneNumber, SystemBlockedNumberInfo> result = ImmutableMap.builder();
    for (DialerPhoneNumber number : numbers) {
        result.put(number, SystemBlockedNumberInfo.newBuilder().setBlockedState(blockedNumbers.contains(number) ? BlockedState.BLOCKED : BlockedState.NOT_BLOCKED).build());
    }
    return result.build();
}
Also used : SystemBlockedNumberInfo(com.android.dialer.phonelookup.PhoneLookupInfo.SystemBlockedNumberInfo) PartitionedNumbers(com.android.dialer.phonenumberproto.PartitionedNumbers) ArraySet(android.util.ArraySet) Selection(com.android.dialer.common.database.Selection) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) Cursor(android.database.Cursor) ImmutableMap(com.google.common.collect.ImmutableMap) WorkerThread(android.support.annotation.WorkerThread)

Example 20 with DialerPhoneNumber

use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.

the class CequintPhoneLookup method lookup.

@Override
public ListenableFuture<CequintInfo> lookup(Context appContext, Call call) {
    if (!CequintCallerIdManager.isCequintCallerIdEnabled(appContext)) {
        return Futures.immediateFuture(CequintInfo.getDefaultInstance());
    }
    ListenableFuture<DialerPhoneNumber> dialerPhoneNumberFuture = backgroundExecutorService.submit(() -> {
        DialerPhoneNumberUtil dialerPhoneNumberUtil = new DialerPhoneNumberUtil();
        return dialerPhoneNumberUtil.parse(TelecomCallUtil.getNumber(call), GeoUtil.getCurrentCountryIso(appContext));
    });
    String callerDisplayName = call.getDetails().getCallerDisplayName();
    boolean isIncomingCall = (call.getState() == Call.STATE_RINGING);
    return Futures.transformAsync(dialerPhoneNumberFuture, dialerPhoneNumber -> backgroundExecutorService.submit(() -> buildCequintInfo(CequintCallerIdManager.getCequintCallerIdContactForCall(appContext, Assert.isNotNull(dialerPhoneNumber).getNormalizedNumber(), callerDisplayName, isIncomingCall))), lightweightExecutorService);
}
Also used : DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) DialerPhoneNumberUtil(com.android.dialer.phonenumberproto.DialerPhoneNumberUtil)

Aggregations

DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)26 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)8 ContentValues (android.content.ContentValues)7 Cursor (android.database.Cursor)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 ArrayList (java.util.ArrayList)7 ArraySet (android.support.v4.util.ArraySet)6 PhoneLookupInfo (com.android.dialer.phonelookup.PhoneLookupInfo)6 Cp2ContactInfo (com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 Set (java.util.Set)6 PartitionedNumbers (com.android.dialer.phonenumberproto.PartitionedNumbers)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)5 Context (android.content.Context)4 ArraySet (android.util.ArraySet)4 LogUtil (com.android.dialer.common.LogUtil)4 BackgroundExecutor (com.android.dialer.common.concurrent.Annotations.BackgroundExecutor)4 ApplicationContext (com.android.dialer.inject.ApplicationContext)4 PhoneLookup (com.android.dialer.phonelookup.PhoneLookup)4