diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-08-31 16:17:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-31 16:17:04 +0000 |
commit | c39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch) | |
tree | e282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/dialer/databasepopulator/CallLogPopulator.java | |
parent | 68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff) | |
parent | 2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff) |
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/dialer/databasepopulator/CallLogPopulator.java')
-rw-r--r-- | java/com/android/dialer/databasepopulator/CallLogPopulator.java | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/java/com/android/dialer/databasepopulator/CallLogPopulator.java b/java/com/android/dialer/databasepopulator/CallLogPopulator.java new file mode 100644 index 000000000..7c387ecd1 --- /dev/null +++ b/java/com/android/dialer/databasepopulator/CallLogPopulator.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.databasepopulator; + +import android.content.ContentProviderOperation; +import android.content.ContentValues; +import android.content.Context; +import android.content.OperationApplicationException; +import android.os.RemoteException; +import android.provider.CallLog; +import android.provider.CallLog.Calls; +import android.support.annotation.NonNull; +import android.support.annotation.WorkerThread; +import com.android.dialer.common.Assert; +import com.google.auto.value.AutoValue; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; + +/** Populates the device database with call log entries. */ +public final class CallLogPopulator { + // Phone numbers from https://www.google.com/about/company/facts/locations/ + private static final CallEntry.Builder[] SIMPLE_CALL_LOG = { + CallEntry.builder().setType(Calls.MISSED_TYPE).setNumber("+1-302-6365454"), + CallEntry.builder() + .setType(Calls.MISSED_TYPE) + .setNumber("") + .setPresentation(Calls.PRESENTATION_UNKNOWN), + CallEntry.builder().setType(Calls.REJECTED_TYPE).setNumber("+1-302-6365454"), + CallEntry.builder().setType(Calls.INCOMING_TYPE).setNumber("+1-302-6365454"), + CallEntry.builder() + .setType(Calls.MISSED_TYPE) + .setNumber("1234") + .setPresentation(Calls.PRESENTATION_RESTRICTED), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("+1-302-6365454"), + CallEntry.builder().setType(Calls.BLOCKED_TYPE).setNumber("+1-302-6365454"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("(425) 739-5600"), + CallEntry.builder().setType(Calls.ANSWERED_EXTERNALLY_TYPE).setNumber("(425) 739-5600"), + CallEntry.builder().setType(Calls.MISSED_TYPE).setNumber("+1 (425) 739-5600"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("739-5600"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("711"), + CallEntry.builder().setType(Calls.INCOMING_TYPE).setNumber("711"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("(425) 739-5600"), + CallEntry.builder().setType(Calls.MISSED_TYPE).setNumber("+44 (0) 20 7031 3000"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("+1-650-2530000"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("+1 303-245-0086;123,456"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("+1 303-245-0086"), + CallEntry.builder().setType(Calls.INCOMING_TYPE).setNumber("+1-650-2530000"), + CallEntry.builder().setType(Calls.MISSED_TYPE).setNumber("650-2530000"), + CallEntry.builder().setType(Calls.REJECTED_TYPE).setNumber("2530000"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("+1 404-487-9000"), + CallEntry.builder().setType(Calls.INCOMING_TYPE).setNumber("+61 2 9374 4001"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("+33 (0)1 42 68 53 00"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("972-74-746-6245"), + CallEntry.builder().setType(Calls.INCOMING_TYPE).setNumber("+971 4 4509500"), + CallEntry.builder().setType(Calls.INCOMING_TYPE).setNumber("+971 4 4509500"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("55-31-2128-6800"), + CallEntry.builder().setType(Calls.MISSED_TYPE).setNumber("611"), + CallEntry.builder().setType(Calls.OUTGOING_TYPE).setNumber("*86 512-343-5283"), + }; + + @WorkerThread + public static void populateCallLog(@NonNull Context context) { + populateCallLog(context, false); + } + + @WorkerThread + public static void populateCallLogWithoutMissed(@NonNull Context context) { + populateCallLog(context, true); + } + + @WorkerThread + public static void populateCallLog(@NonNull Context context, boolean isWithoutMissedCalls) { + Assert.isWorkerThread(); + ArrayList<ContentProviderOperation> operations = new ArrayList<>(); + // Do this 4 times to make the call log 4 times bigger. + long timeMillis = System.currentTimeMillis(); + for (int i = 0; i < 4; i++) { + for (CallEntry.Builder builder : SIMPLE_CALL_LOG) { + CallEntry callEntry = builder.setTimeMillis(timeMillis).build(); + if (isWithoutMissedCalls && builder.build().getType() == Calls.MISSED_TYPE) { + continue; + } + operations.add( + ContentProviderOperation.newInsert(Calls.CONTENT_URI) + .withValues(callEntry.getAsContentValues()) + .withYieldAllowed(true) + .build()); + timeMillis -= TimeUnit.HOURS.toMillis(1); + } + } + try { + context.getContentResolver().applyBatch(CallLog.AUTHORITY, operations); + } catch (RemoteException | OperationApplicationException e) { + Assert.fail("error adding call entries: " + e); + } + } + + @WorkerThread + public static void deleteAllCallLog(@NonNull Context context) { + Assert.isWorkerThread(); + try { + context + .getContentResolver() + .applyBatch( + CallLog.AUTHORITY, + new ArrayList<>( + Arrays.asList(ContentProviderOperation.newDelete(Calls.CONTENT_URI).build()))); + } catch (RemoteException | OperationApplicationException e) { + Assert.fail("failed to delete call log: " + e); + } + } + + @AutoValue + abstract static class CallEntry { + @NonNull + abstract String getNumber(); + + abstract int getType(); + + abstract int getPresentation(); + + abstract long getTimeMillis(); + + static Builder builder() { + return new AutoValue_CallLogPopulator_CallEntry.Builder() + .setPresentation(Calls.PRESENTATION_ALLOWED); + } + + ContentValues getAsContentValues() { + ContentValues values = new ContentValues(); + values.put(Calls.TYPE, getType()); + values.put(Calls.NUMBER, getNumber()); + values.put(Calls.NUMBER_PRESENTATION, getPresentation()); + values.put(Calls.DATE, getTimeMillis()); + return values; + } + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setNumber(@NonNull String number); + + abstract Builder setType(int type); + + abstract Builder setPresentation(int presentation); + + abstract Builder setTimeMillis(long timeMillis); + + abstract CallEntry build(); + } + } + + private CallLogPopulator() {} +} |