| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package android.provider; |
| 19 |
|
| 20 |
import android.Manifest; |
| 21 |
import android.annotation.CallbackExecutor; |
| 22 |
import android.annotation.IntDef; |
| 23 |
import android.annotation.LongDef; |
| 24 |
import android.annotation.NonNull; |
| 25 |
import android.annotation.RequiresPermission; |
| 26 |
import android.annotation.SuppressLint; |
| 27 |
import android.annotation.SystemApi; |
| 28 |
import android.annotation.UserHandleAware; |
| 29 |
import android.compat.annotation.UnsupportedAppUsage; |
| 30 |
import android.content.ContentProvider; |
| 31 |
import android.content.ContentResolver; |
| 32 |
import android.content.ContentValues; |
| 33 |
import android.content.Context; |
| 34 |
import android.content.Intent; |
| 35 |
import android.content.pm.UserInfo; |
| 36 |
import android.database.Cursor; |
| 37 |
import android.location.Country; |
| 38 |
import android.location.CountryDetector; |
| 39 |
import android.net.Uri; |
| 40 |
import android.os.Build; |
| 41 |
import android.os.OutcomeReceiver; |
| 42 |
import android.os.ParcelFileDescriptor; |
| 43 |
import android.os.ParcelableException; |
| 44 |
import android.os.UserHandle; |
| 45 |
import android.os.UserManager; |
| 46 |
import android.provider.ContactsContract.CommonDataKinds.Callable; |
| 47 |
import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 48 |
import android.provider.ContactsContract.Data; |
| 49 |
import android.provider.ContactsContract.DataUsageFeedback; |
| 50 |
import android.telecom.CallerInfo; |
| 51 |
import android.telecom.PhoneAccount; |
| 52 |
import android.telecom.PhoneAccountHandle; |
| 53 |
import android.telecom.TelecomManager; |
| 54 |
import android.telephony.PhoneNumberUtils; |
| 55 |
import android.text.TextUtils; |
| 56 |
import android.util.Log; |
| 57 |
|
| 58 |
import java.io.ByteArrayOutputStream; |
| 59 |
import java.io.FileNotFoundException; |
| 60 |
import java.io.FileOutputStream; |
| 61 |
import java.io.IOException; |
| 62 |
import java.io.InputStream; |
| 63 |
import java.lang.annotation.Retention; |
| 64 |
import java.lang.annotation.RetentionPolicy; |
| 65 |
import java.util.List; |
| 66 |
import java.util.Objects; |
| 67 |
import java.util.concurrent.Executor; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public class CallLog { |
| 73 |
private static final String LOG_TAG = "CallLog"; |
| 74 |
private static final boolean VERBOSE_LOG = false; |
| 75 |
|
| 76 |
public static final String AUTHORITY = "call_log"; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static final Uri CONTENT_URI = |
| 82 |
Uri.parse("content://" + AUTHORITY); |
| 83 |
|
| 84 |
|
| 85 |
public static final String CALL_COMPOSER_SEGMENT = "call_composer"; |
| 86 |
|
| 87 |
|
| 88 |
public static final Uri CALL_COMPOSER_PICTURE_URI = |
| 89 |
CONTENT_URI.buildUpon().appendPath(CALL_COMPOSER_SEGMENT).build(); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public static final String SHADOW_AUTHORITY = "call_log_shadow"; |
| 100 |
|
| 101 |
|
| 102 |
public static final Uri SHADOW_CALL_COMPOSER_PICTURE_URI = CALL_COMPOSER_PICTURE_URI.buildUpon() |
| 103 |
.authority(SHADOW_AUTHORITY).build(); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
@SystemApi |
| 110 |
public static class CallComposerLoggingException extends Throwable { |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public static final int ERROR_UNKNOWN = 0; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public static final int ERROR_REMOTE_END_CLOSED = 1; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public static final int ERROR_STORAGE_FULL = 2; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public static final int ERROR_INPUT_CLOSED = 3; |
| 139 |
|
| 140 |
|
| 141 |
@IntDef(prefix = {"ERROR_"}, value = { |
| 142 |
ERROR_UNKNOWN, |
| 143 |
ERROR_REMOTE_END_CLOSED, |
| 144 |
ERROR_STORAGE_FULL, |
| 145 |
ERROR_INPUT_CLOSED, |
| 146 |
}) |
| 147 |
@Retention(RetentionPolicy.SOURCE) |
| 148 |
public @interface CallComposerLoggingError { } |
| 149 |
|
| 150 |
private final int mErrorCode; |
| 151 |
|
| 152 |
public CallComposerLoggingException(@CallComposerLoggingError int errorCode) { |
| 153 |
mErrorCode = errorCode; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public @CallComposerLoggingError int getErrorCode() { |
| 160 |
return mErrorCode; |
| 161 |
} |
| 162 |
|
| 163 |
@Override |
| 164 |
public String toString() { |
| 165 |
String errorString; |
| 166 |
switch (mErrorCode) { |
| 167 |
case ERROR_UNKNOWN: |
| 168 |
errorString = "UNKNOWN"; |
| 169 |
break; |
| 170 |
case ERROR_REMOTE_END_CLOSED: |
| 171 |
errorString = "REMOTE_END_CLOSED"; |
| 172 |
break; |
| 173 |
case ERROR_STORAGE_FULL: |
| 174 |
errorString = "STORAGE_FULL"; |
| 175 |
break; |
| 176 |
case ERROR_INPUT_CLOSED: |
| 177 |
errorString = "INPUT_CLOSED"; |
| 178 |
break; |
| 179 |
default: |
| 180 |
errorString = "[[" + mErrorCode + "]]"; |
| 181 |
break; |
| 182 |
} |
| 183 |
return "CallComposerLoggingException: " + errorString; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
@SystemApi |
| 209 |
@UserHandleAware |
| 210 |
@RequiresPermission(allOf = { |
| 211 |
Manifest.permission.WRITE_CALL_LOG, |
| 212 |
Manifest.permission.INTERACT_ACROSS_USERS |
| 213 |
}) |
| 214 |
public static void storeCallComposerPicture(@NonNull Context context, |
| 215 |
@NonNull InputStream input, |
| 216 |
@CallbackExecutor @NonNull Executor executor, |
| 217 |
@NonNull OutcomeReceiver<Uri, CallComposerLoggingException> callback) { |
| 218 |
Objects.requireNonNull(context); |
| 219 |
Objects.requireNonNull(input); |
| 220 |
Objects.requireNonNull(executor); |
| 221 |
Objects.requireNonNull(callback); |
| 222 |
|
| 223 |
executor.execute(() -> { |
| 224 |
ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(); |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
byte[] buffer = new byte[1024]; |
| 229 |
int bytesRead; |
| 230 |
while (true) { |
| 231 |
try { |
| 232 |
bytesRead = input.read(buffer); |
| 233 |
} catch (IOException e) { |
| 234 |
Log.e(LOG_TAG, "IOException while reading call composer pic from input: " |
| 235 |
+ e); |
| 236 |
callback.onError(new CallComposerLoggingException( |
| 237 |
CallComposerLoggingException.ERROR_INPUT_CLOSED)); |
| 238 |
return; |
| 239 |
} |
| 240 |
if (bytesRead < 0) { |
| 241 |
break; |
| 242 |
} |
| 243 |
tmpOut.write(buffer, 0, bytesRead); |
| 244 |
} |
| 245 |
byte[] picData = tmpOut.toByteArray(); |
| 246 |
|
| 247 |
UserManager userManager = context.getSystemService(UserManager.class); |
| 248 |
UserHandle user = context.getUser(); |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
UserHandle realUser = UserHandle.CURRENT.equals(user) |
| 253 |
? android.os.Process.myUserHandle() : user; |
| 254 |
if (realUser != UserHandle.ALL) { |
| 255 |
Uri baseUri = userManager.isUserUnlocked(realUser) ? CALL_COMPOSER_PICTURE_URI |
| 256 |
: SHADOW_CALL_COMPOSER_PICTURE_URI; |
| 257 |
Uri pictureInsertionUri = ContentProvider.maybeAddUserId(baseUri, |
| 258 |
realUser.getIdentifier()); |
| 259 |
Log.i(LOG_TAG, "Inserting call composer for single user at " |
| 260 |
+ pictureInsertionUri); |
| 261 |
|
| 262 |
try { |
| 263 |
Uri result = storeCallComposerPictureAtUri( |
| 264 |
context, pictureInsertionUri, false, picData); |
| 265 |
callback.onResult(result); |
| 266 |
} catch (CallComposerLoggingException e) { |
| 267 |
callback.onError(e); |
| 268 |
} |
| 269 |
return; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
if (!userManager.isUserUnlocked(UserHandle.SYSTEM)) { |
| 274 |
Uri pictureInsertionUri = ContentProvider.maybeAddUserId( |
| 275 |
SHADOW_CALL_COMPOSER_PICTURE_URI, |
| 276 |
UserHandle.SYSTEM.getIdentifier()); |
| 277 |
Log.i(LOG_TAG, "Inserting call composer for all users, but system locked at " |
| 278 |
+ pictureInsertionUri); |
| 279 |
try { |
| 280 |
Uri result = |
| 281 |
storeCallComposerPictureAtUri(context, pictureInsertionUri, |
| 282 |
true, picData); |
| 283 |
callback.onResult(result); |
| 284 |
} catch (CallComposerLoggingException e) { |
| 285 |
callback.onError(e); |
| 286 |
} |
| 287 |
return; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
Uri systemPictureInsertionUri = ContentProvider.maybeAddUserId( |
| 296 |
CALL_COMPOSER_PICTURE_URI, |
| 297 |
UserHandle.SYSTEM.getIdentifier()); |
| 298 |
Uri systemInsertedPicture; |
| 299 |
try { |
| 300 |
systemInsertedPicture = |
| 301 |
storeCallComposerPictureAtUri(context, systemPictureInsertionUri, |
| 302 |
true, picData); |
| 303 |
Log.i(LOG_TAG, "Inserting call composer for all users, succeeded with system," |
| 304 |
+ " result is " + systemInsertedPicture); |
| 305 |
} catch (CallComposerLoggingException e) { |
| 306 |
callback.onError(e); |
| 307 |
return; |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
Uri strippedInsertionUri = ContentProvider.getUriWithoutUserId(systemInsertedPicture); |
| 313 |
for (UserInfo u : userManager.getAliveUsers()) { |
| 314 |
UserHandle userHandle = u.getUserHandle(); |
| 315 |
if (userHandle.isSystem()) { |
| 316 |
|
| 317 |
continue; |
| 318 |
} |
| 319 |
|
| 320 |
if (!Calls.shouldHaveSharedCallLogEntries( |
| 321 |
context, userManager, userHandle.getIdentifier())) { |
| 322 |
|
| 323 |
continue; |
| 324 |
} |
| 325 |
|
| 326 |
if (userManager.isUserRunning(userHandle) |
| 327 |
&& userManager.isUserUnlocked(userHandle)) { |
| 328 |
Uri insertionUri = ContentProvider.maybeAddUserId(strippedInsertionUri, |
| 329 |
userHandle.getIdentifier()); |
| 330 |
Log.i(LOG_TAG, "Inserting call composer for all users, now on user " |
| 331 |
+ userHandle + " inserting at " + insertionUri); |
| 332 |
try { |
| 333 |
storeCallComposerPictureAtUri(context, insertionUri, false, picData); |
| 334 |
} catch (CallComposerLoggingException e) { |
| 335 |
Log.e(LOG_TAG, "Error writing for user " + userHandle.getIdentifier() |
| 336 |
+ ": " + e); |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
callback.onResult(strippedInsertionUri); |
| 344 |
}); |
| 345 |
} |
| 346 |
|
| 347 |
private static Uri storeCallComposerPictureAtUri( |
| 348 |
Context context, Uri insertionUri, |
| 349 |
boolean forAllUsers, byte[] picData) throws CallComposerLoggingException { |
| 350 |
Uri pictureFileUri; |
| 351 |
try { |
| 352 |
ContentValues cv = new ContentValues(); |
| 353 |
cv.put(Calls.ADD_FOR_ALL_USERS, forAllUsers ? 1 : 0); |
| 354 |
pictureFileUri = context.getContentResolver().insert(insertionUri, cv); |
| 355 |
} catch (ParcelableException e) { |
| 356 |
|
| 357 |
|
| 358 |
throw new CallComposerLoggingException(CallComposerLoggingException.ERROR_UNKNOWN); |
| 359 |
} |
| 360 |
if (pictureFileUri == null) { |
| 361 |
|
| 362 |
|
| 363 |
throw new CallComposerLoggingException(CallComposerLoggingException.ERROR_STORAGE_FULL); |
| 364 |
} |
| 365 |
|
| 366 |
try (ParcelFileDescriptor pfd = |
| 367 |
context.getContentResolver().openFileDescriptor(pictureFileUri, "w")) { |
| 368 |
FileOutputStream output = new FileOutputStream(pfd.getFileDescriptor()); |
| 369 |
try { |
| 370 |
output.write(picData); |
| 371 |
} catch (IOException e) { |
| 372 |
Log.e(LOG_TAG, "Got IOException writing to remote end: " + e); |
| 373 |
|
| 374 |
context.getContentResolver().delete(pictureFileUri, null); |
| 375 |
throw new CallComposerLoggingException( |
| 376 |
CallComposerLoggingException.ERROR_REMOTE_END_CLOSED); |
| 377 |
} |
| 378 |
} catch (FileNotFoundException e) { |
| 379 |
throw new CallComposerLoggingException(CallComposerLoggingException.ERROR_UNKNOWN); |
| 380 |
} catch (IOException e) { |
| 381 |
|
| 382 |
Log.e(LOG_TAG, "Got IOException closing remote descriptor: " + e); |
| 383 |
} |
| 384 |
return pictureFileUri; |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
private static void sendCallComposerError(OutcomeReceiver<?, CallComposerLoggingException> cb, |
| 389 |
int error) { |
| 390 |
cb.onError(new CallComposerLoggingException(error)); |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
public static class AddCallParams { |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
public static final class AddCallParametersBuilder { |
| 405 |
private CallerInfo mCallerInfo; |
| 406 |
private String mNumber; |
| 407 |
private String mPostDialDigits; |
| 408 |
private String mViaNumber; |
| 409 |
private int mPresentation = TelecomManager.PRESENTATION_UNKNOWN; |
| 410 |
private int mCallType = Calls.INCOMING_TYPE; |
| 411 |
private int mFeatures; |
| 412 |
private PhoneAccountHandle mAccountHandle; |
| 413 |
private long mStart; |
| 414 |
private int mDuration; |
| 415 |
private Long mDataUsage = Long.MIN_VALUE; |
| 416 |
private boolean mAddForAllUsers; |
| 417 |
private UserHandle mUserToBeInsertedTo; |
| 418 |
private boolean mIsRead; |
| 419 |
private int mCallBlockReason = Calls.BLOCK_REASON_NOT_BLOCKED; |
| 420 |
private CharSequence mCallScreeningAppName; |
| 421 |
private String mCallScreeningComponentName; |
| 422 |
private long mMissedReason = Calls.MISSED_REASON_NOT_MISSED; |
| 423 |
private int mPriority = Calls.PRIORITY_NORMAL; |
| 424 |
private String mSubject; |
| 425 |
private double mLatitude = Double.NaN; |
| 426 |
private double mLongitude = Double.NaN; |
| 427 |
private Uri mPictureUri; |
| 428 |
private int mIsPhoneAccountMigrationPending; |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
public @NonNull AddCallParametersBuilder setCallerInfo( |
| 434 |
@NonNull CallerInfo callerInfo) { |
| 435 |
mCallerInfo = callerInfo; |
| 436 |
return this; |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
public @NonNull AddCallParametersBuilder setNumber(@NonNull String number) { |
| 443 |
mNumber = number; |
| 444 |
return this; |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
public @NonNull AddCallParametersBuilder setPostDialDigits( |
| 452 |
@NonNull String postDialDigits) { |
| 453 |
mPostDialDigits = postDialDigits; |
| 454 |
return this; |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
public @NonNull AddCallParametersBuilder setViaNumber(@NonNull String viaNumber) { |
| 462 |
mViaNumber = viaNumber; |
| 463 |
return this; |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
public @NonNull AddCallParametersBuilder setPresentation(int presentation) { |
| 472 |
mPresentation = presentation; |
| 473 |
return this; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
public @NonNull AddCallParametersBuilder setCallType(int callType) { |
| 480 |
mCallType = callType; |
| 481 |
return this; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
public @NonNull AddCallParametersBuilder setFeatures(int features) { |
| 488 |
mFeatures = features; |
| 489 |
return this; |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
public @NonNull AddCallParametersBuilder setAccountHandle( |
| 496 |
@NonNull PhoneAccountHandle accountHandle) { |
| 497 |
mAccountHandle = accountHandle; |
| 498 |
return this; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
public @NonNull AddCallParametersBuilder setStart(long start) { |
| 505 |
mStart = start; |
| 506 |
return this; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
public @NonNull AddCallParametersBuilder setDuration(int duration) { |
| 513 |
mDuration = duration; |
| 514 |
return this; |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
public @NonNull AddCallParametersBuilder setDataUsage(long dataUsage) { |
| 523 |
mDataUsage = dataUsage; |
| 524 |
return this; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
public @NonNull AddCallParametersBuilder setAddForAllUsers( |
| 533 |
boolean addForAllUsers) { |
| 534 |
mAddForAllUsers = addForAllUsers; |
| 535 |
return this; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
@SuppressLint("UserHandleName") |
| 545 |
public @NonNull AddCallParametersBuilder setUserToBeInsertedTo( |
| 546 |
@NonNull UserHandle userToBeInsertedTo) { |
| 547 |
mUserToBeInsertedTo = userToBeInsertedTo; |
| 548 |
return this; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public @NonNull AddCallParametersBuilder setIsRead(boolean isRead) { |
| 556 |
mIsRead = isRead; |
| 557 |
return this; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
public @NonNull AddCallParametersBuilder setCallBlockReason(int callBlockReason) { |
| 564 |
mCallBlockReason = callBlockReason; |
| 565 |
return this; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
public @NonNull AddCallParametersBuilder setCallScreeningAppName( |
| 572 |
@NonNull CharSequence callScreeningAppName) { |
| 573 |
mCallScreeningAppName = callScreeningAppName; |
| 574 |
return this; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
public @NonNull AddCallParametersBuilder setCallScreeningComponentName( |
| 582 |
@NonNull String callScreeningComponentName) { |
| 583 |
mCallScreeningComponentName = callScreeningComponentName; |
| 584 |
return this; |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
public @NonNull AddCallParametersBuilder setMissedReason(long missedReason) { |
| 591 |
mMissedReason = missedReason; |
| 592 |
return this; |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
public @NonNull AddCallParametersBuilder setPriority(int priority) { |
| 600 |
mPriority = priority; |
| 601 |
return this; |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
public @NonNull AddCallParametersBuilder setSubject(@NonNull String subject) { |
| 608 |
mSubject = subject; |
| 609 |
return this; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
public @NonNull AddCallParametersBuilder setLatitude(double latitude) { |
| 616 |
mLatitude = latitude; |
| 617 |
return this; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
public @NonNull AddCallParametersBuilder setLongitude(double longitude) { |
| 624 |
mLongitude = longitude; |
| 625 |
return this; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
public @NonNull AddCallParametersBuilder setPictureUri(@NonNull Uri pictureUri) { |
| 633 |
mPictureUri = pictureUri; |
| 634 |
return this; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
public @NonNull AddCallParametersBuilder setIsPhoneAccountMigrationPending( |
| 641 |
int isPhoneAccountMigrationPending) { |
| 642 |
mIsPhoneAccountMigrationPending = isPhoneAccountMigrationPending; |
| 643 |
return this; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public @NonNull AddCallParams build() { |
| 650 |
return new AddCallParams(mCallerInfo, mNumber, mPostDialDigits, mViaNumber, |
| 651 |
mPresentation, mCallType, mFeatures, mAccountHandle, mStart, mDuration, |
| 652 |
mDataUsage, mAddForAllUsers, mUserToBeInsertedTo, mIsRead, mCallBlockReason, |
| 653 |
mCallScreeningAppName, mCallScreeningComponentName, mMissedReason, |
| 654 |
mPriority, mSubject, mLatitude, mLongitude, mPictureUri, |
| 655 |
mIsPhoneAccountMigrationPending); |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
private CallerInfo mCallerInfo; |
| 660 |
private String mNumber; |
| 661 |
private String mPostDialDigits; |
| 662 |
private String mViaNumber; |
| 663 |
private int mPresentation; |
| 664 |
private int mCallType; |
| 665 |
private int mFeatures; |
| 666 |
private PhoneAccountHandle mAccountHandle; |
| 667 |
private long mStart; |
| 668 |
private int mDuration; |
| 669 |
private long mDataUsage; |
| 670 |
private boolean mAddForAllUsers; |
| 671 |
private UserHandle mUserToBeInsertedTo; |
| 672 |
private boolean mIsRead; |
| 673 |
private int mCallBlockReason; |
| 674 |
private CharSequence mCallScreeningAppName; |
| 675 |
private String mCallScreeningComponentName; |
| 676 |
private long mMissedReason; |
| 677 |
private int mPriority; |
| 678 |
private String mSubject; |
| 679 |
private double mLatitude = Double.NaN; |
| 680 |
private double mLongitude = Double.NaN; |
| 681 |
private Uri mPictureUri; |
| 682 |
private int mIsPhoneAccountMigrationPending; |
| 683 |
|
| 684 |
private AddCallParams(CallerInfo callerInfo, String number, String postDialDigits, |
| 685 |
String viaNumber, int presentation, int callType, int features, |
| 686 |
PhoneAccountHandle accountHandle, long start, int duration, long dataUsage, |
| 687 |
boolean addForAllUsers, UserHandle userToBeInsertedTo, boolean isRead, |
| 688 |
int callBlockReason, |
| 689 |
CharSequence callScreeningAppName, String callScreeningComponentName, |
| 690 |
long missedReason, |
| 691 |
int priority, String subject, double latitude, double longitude, Uri pictureUri, |
| 692 |
int isPhoneAccountMigrationPending) { |
| 693 |
mCallerInfo = callerInfo; |
| 694 |
mNumber = number; |
| 695 |
mPostDialDigits = postDialDigits; |
| 696 |
mViaNumber = viaNumber; |
| 697 |
mPresentation = presentation; |
| 698 |
mCallType = callType; |
| 699 |
mFeatures = features; |
| 700 |
mAccountHandle = accountHandle; |
| 701 |
mStart = start; |
| 702 |
mDuration = duration; |
| 703 |
mDataUsage = dataUsage; |
| 704 |
mAddForAllUsers = addForAllUsers; |
| 705 |
mUserToBeInsertedTo = userToBeInsertedTo; |
| 706 |
mIsRead = isRead; |
| 707 |
mCallBlockReason = callBlockReason; |
| 708 |
mCallScreeningAppName = callScreeningAppName; |
| 709 |
mCallScreeningComponentName = callScreeningComponentName; |
| 710 |
mMissedReason = missedReason; |
| 711 |
mPriority = priority; |
| 712 |
mSubject = subject; |
| 713 |
mLatitude = latitude; |
| 714 |
mLongitude = longitude; |
| 715 |
mPictureUri = pictureUri; |
| 716 |
mIsPhoneAccountMigrationPending = isPhoneAccountMigrationPending; |
| 717 |
} |
| 718 |
|
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
public static class Calls implements BaseColumns { |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
public static final Uri CONTENT_URI = |
| 748 |
Uri.parse("content://call_log/calls"); |
| 749 |
|
| 750 |
|
| 751 |
public static final Uri SHADOW_CONTENT_URI = |
| 752 |
Uri.parse("content://call_log_shadow/calls"); |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
public static final Uri CONTENT_FILTER_URI = |
| 758 |
Uri.parse("content://call_log/calls/filter"); |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
public static final String LIMIT_PARAM_KEY = "limit"; |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
private static final Uri CONTENT_URI_LIMIT_1 = CONTENT_URI.buildUpon() |
| 771 |
.appendQueryParameter(LIMIT_PARAM_KEY, "1") |
| 772 |
.build(); |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
public static final String OFFSET_PARAM_KEY = "offset"; |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
public static final String ALLOW_VOICEMAILS_PARAM_KEY = "allow_voicemails"; |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
public static final String EXTRA_CALL_TYPE_FILTER = |
| 814 |
"android.provider.extra.CALL_TYPE_FILTER"; |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
public static final Uri CONTENT_URI_WITH_VOICEMAIL = CONTENT_URI.buildUpon() |
| 822 |
.appendQueryParameter(ALLOW_VOICEMAILS_PARAM_KEY, "true") |
| 823 |
.build(); |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
public static final String DEFAULT_SORT_ORDER = "date DESC"; |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/calls"; |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/calls"; |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
public static final String TYPE = "type"; |
| 860 |
|
| 861 |
|
| 862 |
public static final int INCOMING_TYPE = 1; |
| 863 |
|
| 864 |
public static final int OUTGOING_TYPE = 2; |
| 865 |
|
| 866 |
public static final int MISSED_TYPE = 3; |
| 867 |
|
| 868 |
public static final int VOICEMAIL_TYPE = 4; |
| 869 |
|
| 870 |
public static final int REJECTED_TYPE = 5; |
| 871 |
|
| 872 |
public static final int BLOCKED_TYPE = 6; |
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
public static final int ANSWERED_EXTERNALLY_TYPE = 7; |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
public static final String FEATURES = "features"; |
| 886 |
|
| 887 |
|
| 888 |
public static final int FEATURES_VIDEO = 1 << 0; |
| 889 |
|
| 890 |
|
| 891 |
public static final int FEATURES_PULLED_EXTERNALLY = 1 << 1; |
| 892 |
|
| 893 |
|
| 894 |
public static final int FEATURES_HD_CALL = 1 << 2; |
| 895 |
|
| 896 |
|
| 897 |
public static final int FEATURES_WIFI = 1 << 3; |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
public static final int FEATURES_ASSISTED_DIALING_USED = 1 << 4; |
| 904 |
|
| 905 |
|
| 906 |
public static final int FEATURES_RTT = 1 << 5; |
| 907 |
|
| 908 |
|
| 909 |
public static final int FEATURES_VOLTE = 1 << 6; |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
public static final String NUMBER = "number"; |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
public static final String NUMBER_PRESENTATION = "presentation"; |
| 934 |
|
| 935 |
|
| 936 |
public static final int PRESENTATION_ALLOWED = 1; |
| 937 |
|
| 938 |
public static final int PRESENTATION_RESTRICTED = 2; |
| 939 |
|
| 940 |
public static final int PRESENTATION_UNKNOWN = 3; |
| 941 |
|
| 942 |
public static final int PRESENTATION_PAYPHONE = 4; |
| 943 |
|
| 944 |
public static final int PRESENTATION_UNAVAILABLE = 5; |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
public static final String COUNTRY_ISO = "countryiso"; |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
public static final String DATE = "date"; |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
public static final String DURATION = "duration"; |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
public static final String DATA_USAGE = "data_usage"; |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
public static final String NEW = "new"; |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
public static final String CACHED_NAME = "name"; |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
public static final String CACHED_NUMBER_TYPE = "numbertype"; |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
public static final String CACHED_NUMBER_LABEL = "numberlabel"; |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
public static final String VOICEMAIL_URI = "voicemail_uri"; |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
public static final String TRANSCRIPTION = "transcription"; |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
public static final String TRANSCRIPTION_STATE = "transcription_state"; |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
public static final String IS_READ = "is_read"; |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
public static final String GEOCODED_LOCATION = "geocoded_location"; |
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
public static final String CACHED_LOOKUP_URI = "lookup_uri"; |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
public static final String CACHED_MATCHED_NUMBER = "matched_number"; |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
public static final String CACHED_NORMALIZED_NUMBER = "normalized_number"; |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
public static final String CACHED_PHOTO_ID = "photo_id"; |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
public static final String CACHED_PHOTO_URI = "photo_uri"; |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
public static final String CACHED_FORMATTED_NUMBER = "formatted_number"; |
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
public static final String PHONE_ACCOUNT_COMPONENT_NAME = "subscription_component_name"; |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
public static final String PHONE_ACCOUNT_ID = "subscription_id"; |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
public static final String PHONE_ACCOUNT_ADDRESS = "phone_account_address"; |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
public static final String PHONE_ACCOUNT_HIDDEN = "phone_account_hidden"; |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
public static final String SUB_ID = "sub_id"; |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
public static final String POST_DIAL_DIGITS = "post_dial_digits"; |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
public static final String VIA_NUMBER = "via_number"; |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
public static final String ADD_FOR_ALL_USERS = "add_for_all_users"; |
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
public static final String LAST_MODIFIED = "last_modified"; |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
private static final int MIN_DURATION_FOR_NORMALIZED_NUMBER_UPDATE_MS = 1000 * 10; |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
public static final int BLOCK_REASON_NOT_BLOCKED = 0; |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
public static final int BLOCK_REASON_CALL_SCREENING_SERVICE = 1; |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
public static final int BLOCK_REASON_DIRECT_TO_VOICEMAIL = 2; |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
public static final int BLOCK_REASON_BLOCKED_NUMBER = 3; |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
public static final int BLOCK_REASON_UNKNOWN_NUMBER = 4; |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
public static final int BLOCK_REASON_RESTRICTED_NUMBER = 5; |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
public static final int BLOCK_REASON_PAY_PHONE = 6; |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
public static final int BLOCK_REASON_NOT_IN_CONTACTS = 7; |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
public static final String CALL_SCREENING_COMPONENT_NAME = "call_screening_component_name"; |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
public static final String CALL_SCREENING_APP_NAME = "call_screening_app_name"; |
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
public static final String BLOCK_REASON = "block_reason"; |
| 1282 |
|
| 1283 |
|
| 1284 |
@LongDef(flag = true, value = { |
| 1285 |
MISSED_REASON_NOT_MISSED, |
| 1286 |
AUTO_MISSED_EMERGENCY_CALL, |
| 1287 |
AUTO_MISSED_MAXIMUM_RINGING, |
| 1288 |
AUTO_MISSED_MAXIMUM_DIALING, |
| 1289 |
USER_MISSED_NO_ANSWER, |
| 1290 |
USER_MISSED_SHORT_RING, |
| 1291 |
USER_MISSED_DND_MODE, |
| 1292 |
USER_MISSED_LOW_RING_VOLUME, |
| 1293 |
USER_MISSED_NO_VIBRATE, |
| 1294 |
USER_MISSED_CALL_SCREENING_SERVICE_SILENCED, |
| 1295 |
USER_MISSED_CALL_FILTERS_TIMEOUT, |
| 1296 |
USER_MISSED_NEVER_RANG |
| 1297 |
}) |
| 1298 |
@Retention(RetentionPolicy.SOURCE) |
| 1299 |
public @interface MissedReason {} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
public static final long MISSED_REASON_NOT_MISSED = 0; |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
public static final long AUTO_MISSED_EMERGENCY_CALL = 1 << 0; |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
public static final long AUTO_MISSED_MAXIMUM_RINGING = 1 << 1; |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
public static final long AUTO_MISSED_MAXIMUM_DIALING = 1 << 2; |
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
public static final long USER_MISSED_NO_ANSWER = 1 << 16; |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
public static final long USER_MISSED_SHORT_RING = 1 << 17; |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
public static final long SHORT_RING_THRESHOLD = 5000L; |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
public static final long USER_MISSED_DND_MODE = 1 << 18; |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
public static final long USER_MISSED_LOW_RING_VOLUME = 1 << 19; |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
public static final int LOW_RING_VOLUME = 0; |
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
public static final long USER_MISSED_NO_VIBRATE = 1 << 20; |
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
public static final long USER_MISSED_CALL_SCREENING_SERVICE_SILENCED = 1 << 21; |
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
public static final long USER_MISSED_CALL_FILTERS_TIMEOUT = 1 << 22; |
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
public static final long USER_MISSED_NEVER_RANG = 1 << 23; |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
public static final String MISSED_REASON = "missed_reason"; |
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
public static final String SUBJECT = "subject"; |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
public static final int PRIORITY_NORMAL = 0; |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
public static final int PRIORITY_URGENT = 1; |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
public static final String PRIORITY = "priority"; |
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
public static final String COMPOSER_PHOTO_URI = "composer_photo_uri"; |
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
public static final String LOCATION = "location"; |
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
public static final String IS_PHONE_ACCOUNT_MIGRATION_PENDING = |
| 1519 |
"is_call_log_phone_account_migration_pending"; |
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
public static Uri addCall(CallerInfo ci, Context context, String number, |
| 1544 |
int presentation, int callType, int features, |
| 1545 |
PhoneAccountHandle accountHandle, |
| 1546 |
long start, int duration, Long dataUsage, long missedReason, |
| 1547 |
int isPhoneAccountMigrationPending) { |
| 1548 |
return addCall(ci, context, number, "" , "" , |
| 1549 |
presentation, callType, features, accountHandle, start, duration, |
| 1550 |
dataUsage, false , null , |
| 1551 |
false , Calls.BLOCK_REASON_NOT_BLOCKED , |
| 1552 |
null , null , |
| 1553 |
missedReason, isPhoneAccountMigrationPending); |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
public static Uri addCall(CallerInfo ci, Context context, String number, |
| 1587 |
String postDialDigits, String viaNumber, int presentation, int callType, |
| 1588 |
int features, PhoneAccountHandle accountHandle, long start, int duration, |
| 1589 |
Long dataUsage, boolean addForAllUsers, UserHandle userToBeInsertedTo, |
| 1590 |
long missedReason, int isPhoneAccountMigrationPending) { |
| 1591 |
return addCall(ci, context, number, postDialDigits, viaNumber, presentation, callType, |
| 1592 |
features, accountHandle, start, duration, dataUsage, addForAllUsers, |
| 1593 |
userToBeInsertedTo, false , Calls.BLOCK_REASON_NOT_BLOCKED |
| 1594 |
, null , |
| 1595 |
null , missedReason, |
| 1596 |
isPhoneAccountMigrationPending); |
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1640 |
public static Uri addCall(CallerInfo ci, Context context, String number, |
| 1641 |
String postDialDigits, String viaNumber, int presentation, int callType, |
| 1642 |
int features, PhoneAccountHandle accountHandle, long start, int duration, |
| 1643 |
Long dataUsage, boolean addForAllUsers, UserHandle userToBeInsertedTo, |
| 1644 |
boolean isRead, int callBlockReason, CharSequence callScreeningAppName, |
| 1645 |
String callScreeningComponentName, long missedReason, |
| 1646 |
int isPhoneAccountMigrationPending) { |
| 1647 |
AddCallParams.AddCallParametersBuilder builder = |
| 1648 |
new AddCallParams.AddCallParametersBuilder(); |
| 1649 |
builder.setCallerInfo(ci); |
| 1650 |
builder.setNumber(number); |
| 1651 |
builder.setPostDialDigits(postDialDigits); |
| 1652 |
builder.setViaNumber(viaNumber); |
| 1653 |
builder.setPresentation(presentation); |
| 1654 |
builder.setCallType(callType); |
| 1655 |
builder.setFeatures(features); |
| 1656 |
builder.setAccountHandle(accountHandle); |
| 1657 |
builder.setStart(start); |
| 1658 |
builder.setDuration(duration); |
| 1659 |
builder.setDataUsage(dataUsage == null ? Long.MIN_VALUE : dataUsage); |
| 1660 |
builder.setAddForAllUsers(addForAllUsers); |
| 1661 |
builder.setUserToBeInsertedTo(userToBeInsertedTo); |
| 1662 |
builder.setIsRead(isRead); |
| 1663 |
builder.setCallBlockReason(callBlockReason); |
| 1664 |
builder.setCallScreeningAppName(callScreeningAppName); |
| 1665 |
builder.setCallScreeningComponentName(callScreeningComponentName); |
| 1666 |
builder.setMissedReason(missedReason); |
| 1667 |
builder.setIsPhoneAccountMigrationPending(isPhoneAccountMigrationPending); |
| 1668 |
|
| 1669 |
return addCall(context, builder.build()); |
| 1670 |
} |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
public static @NonNull Uri addCall( |
| 1680 |
@NonNull Context context, @NonNull AddCallParams params) { |
| 1681 |
if (VERBOSE_LOG) { |
| 1682 |
Log.v(LOG_TAG, String.format("Add call: number=%s, user=%s, for all=%s", |
| 1683 |
params.mNumber, params.mUserToBeInsertedTo, params.mAddForAllUsers)); |
| 1684 |
} |
| 1685 |
final ContentResolver resolver = context.getContentResolver(); |
| 1686 |
|
| 1687 |
String accountAddress = getLogAccountAddress(context, params.mAccountHandle); |
| 1688 |
|
| 1689 |
int numberPresentation = getLogNumberPresentation(params.mNumber, params.mPresentation); |
| 1690 |
String name = (params.mCallerInfo != null) ? params.mCallerInfo.getName() : ""; |
| 1691 |
if (numberPresentation != PRESENTATION_ALLOWED) { |
| 1692 |
params.mNumber = ""; |
| 1693 |
if (params.mCallerInfo != null) { |
| 1694 |
name = ""; |
| 1695 |
} |
| 1696 |
} |
| 1697 |
|
| 1698 |
|
| 1699 |
String accountComponentString = null; |
| 1700 |
String accountId = null; |
| 1701 |
if (params.mAccountHandle != null) { |
| 1702 |
accountComponentString = params.mAccountHandle.getComponentName().flattenToString(); |
| 1703 |
accountId = params.mAccountHandle.getId(); |
| 1704 |
} |
| 1705 |
|
| 1706 |
ContentValues values = new ContentValues(14); |
| 1707 |
|
| 1708 |
values.put(NUMBER, params.mNumber); |
| 1709 |
values.put(POST_DIAL_DIGITS, params.mPostDialDigits); |
| 1710 |
values.put(VIA_NUMBER, params.mViaNumber); |
| 1711 |
values.put(NUMBER_PRESENTATION, Integer.valueOf(numberPresentation)); |
| 1712 |
values.put(TYPE, Integer.valueOf(params.mCallType)); |
| 1713 |
values.put(FEATURES, params.mFeatures); |
| 1714 |
values.put(DATE, Long.valueOf(params.mStart)); |
| 1715 |
values.put(DURATION, Long.valueOf(params.mDuration)); |
| 1716 |
if (params.mDataUsage != Long.MIN_VALUE) { |
| 1717 |
values.put(DATA_USAGE, params.mDataUsage); |
| 1718 |
} |
| 1719 |
values.put(PHONE_ACCOUNT_COMPONENT_NAME, accountComponentString); |
| 1720 |
values.put(PHONE_ACCOUNT_ID, accountId); |
| 1721 |
values.put(PHONE_ACCOUNT_ADDRESS, accountAddress); |
| 1722 |
values.put(NEW, Integer.valueOf(1)); |
| 1723 |
values.put(CACHED_NAME, name); |
| 1724 |
values.put(ADD_FOR_ALL_USERS, params.mAddForAllUsers ? 1 : 0); |
| 1725 |
|
| 1726 |
if (params.mCallType == MISSED_TYPE) { |
| 1727 |
values.put(IS_READ, Integer.valueOf(params.mIsRead ? 1 : 0)); |
| 1728 |
} |
| 1729 |
|
| 1730 |
values.put(BLOCK_REASON, params.mCallBlockReason); |
| 1731 |
values.put(CALL_SCREENING_APP_NAME, charSequenceToString(params.mCallScreeningAppName)); |
| 1732 |
values.put(CALL_SCREENING_COMPONENT_NAME, params.mCallScreeningComponentName); |
| 1733 |
values.put(MISSED_REASON, Long.valueOf(params.mMissedReason)); |
| 1734 |
values.put(PRIORITY, params.mPriority); |
| 1735 |
values.put(SUBJECT, params.mSubject); |
| 1736 |
if (params.mPictureUri != null) { |
| 1737 |
values.put(COMPOSER_PHOTO_URI, params.mPictureUri.toString()); |
| 1738 |
} |
| 1739 |
values.put(IS_PHONE_ACCOUNT_MIGRATION_PENDING, params.mIsPhoneAccountMigrationPending); |
| 1740 |
|
| 1741 |
if ((params.mCallerInfo != null) && (params.mCallerInfo.getContactId() > 0)) { |
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
final Cursor cursor; |
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
if (params.mCallerInfo.normalizedNumber != null) { |
| 1751 |
final String normalizedPhoneNumber = params.mCallerInfo.normalizedNumber; |
| 1752 |
cursor = resolver.query(Phone.CONTENT_URI, |
| 1753 |
new String[] { Phone._ID }, |
| 1754 |
Phone.CONTACT_ID + " =? AND " + Phone.NORMALIZED_NUMBER + " =?", |
| 1755 |
new String[] { String.valueOf(params.mCallerInfo.getContactId()), |
| 1756 |
normalizedPhoneNumber}, |
| 1757 |
null); |
| 1758 |
} else { |
| 1759 |
final String phoneNumber = params.mCallerInfo.getPhoneNumber() != null |
| 1760 |
? params.mCallerInfo.getPhoneNumber() : params.mNumber; |
| 1761 |
cursor = resolver.query( |
| 1762 |
Uri.withAppendedPath(Callable.CONTENT_FILTER_URI, |
| 1763 |
Uri.encode(phoneNumber)), |
| 1764 |
new String[] { Phone._ID }, |
| 1765 |
Phone.CONTACT_ID + " =?", |
| 1766 |
new String[] { String.valueOf(params.mCallerInfo.getContactId()) }, |
| 1767 |
null); |
| 1768 |
} |
| 1769 |
|
| 1770 |
if (cursor != null) { |
| 1771 |
try { |
| 1772 |
if (cursor.getCount() > 0 && cursor.moveToFirst()) { |
| 1773 |
final String dataId = cursor.getString(0); |
| 1774 |
updateDataUsageStatForData(resolver, dataId); |
| 1775 |
if (params.mDuration >= MIN_DURATION_FOR_NORMALIZED_NUMBER_UPDATE_MS |
| 1776 |
&& params.mCallType == Calls.OUTGOING_TYPE |
| 1777 |
&& TextUtils.isEmpty(params.mCallerInfo.normalizedNumber)) { |
| 1778 |
updateNormalizedNumber(context, resolver, dataId, params.mNumber); |
| 1779 |
} |
| 1780 |
} |
| 1781 |
} finally { |
| 1782 |
cursor.close(); |
| 1783 |
} |
| 1784 |
} |
| 1785 |
} |
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
Uri result = null; |
| 1810 |
|
| 1811 |
final UserManager userManager = context.getSystemService(UserManager.class); |
| 1812 |
final int currentUserId = userManager.getProcessUserId(); |
| 1813 |
|
| 1814 |
if (params.mAddForAllUsers) { |
| 1815 |
if (userManager.isUserUnlocked(UserHandle.SYSTEM)) { |
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
Uri locationUri = maybeInsertLocation(params, resolver, UserHandle.SYSTEM); |
| 1821 |
if (locationUri != null) { |
| 1822 |
values.put(Calls.LOCATION, locationUri.toString()); |
| 1823 |
} |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
final Uri uriForSystem = addEntryAndRemoveExpiredEntries( |
| 1828 |
context, userManager, UserHandle.SYSTEM, values); |
| 1829 |
if (uriForSystem == null |
| 1830 |
|| SHADOW_AUTHORITY.equals(uriForSystem.getAuthority())) { |
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
return null; |
| 1835 |
} |
| 1836 |
if (UserHandle.USER_SYSTEM == currentUserId) { |
| 1837 |
result = uriForSystem; |
| 1838 |
} |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
final List<UserInfo> users = userManager.getAliveUsers(); |
| 1843 |
|
| 1844 |
final int count = users.size(); |
| 1845 |
for (int i = 0; i < count; i++) { |
| 1846 |
final UserInfo userInfo = users.get(i); |
| 1847 |
final UserHandle userHandle = userInfo.getUserHandle(); |
| 1848 |
final int userId = userHandle.getIdentifier(); |
| 1849 |
|
| 1850 |
if (userHandle.isSystem()) { |
| 1851 |
|
| 1852 |
continue; |
| 1853 |
} |
| 1854 |
|
| 1855 |
if (!shouldHaveSharedCallLogEntries(context, userManager, userId)) { |
| 1856 |
|
| 1857 |
continue; |
| 1858 |
} |
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
if (userManager.isUserRunning(userHandle) |
| 1864 |
&& userManager.isUserUnlocked(userHandle)) { |
| 1865 |
Uri locationUri = maybeInsertLocation(params, resolver, userHandle); |
| 1866 |
if (locationUri != null) { |
| 1867 |
values.put(Calls.LOCATION, locationUri.toString()); |
| 1868 |
} else { |
| 1869 |
values.put(Calls.LOCATION, (String) null); |
| 1870 |
} |
| 1871 |
final Uri uri = addEntryAndRemoveExpiredEntries(context, userManager, |
| 1872 |
userHandle, values); |
| 1873 |
if (userId == currentUserId) { |
| 1874 |
result = uri; |
| 1875 |
} |
| 1876 |
} |
| 1877 |
} |
| 1878 |
} else { |
| 1879 |
|
| 1880 |
|
| 1881 |
final UserHandle targetUserHandle = params.mUserToBeInsertedTo != null |
| 1882 |
? params.mUserToBeInsertedTo |
| 1883 |
: UserHandle.of(currentUserId); |
| 1884 |
|
| 1885 |
if (userManager.isUserRunning(targetUserHandle) |
| 1886 |
&& userManager.isUserUnlocked(targetUserHandle)) { |
| 1887 |
Uri locationUri = maybeInsertLocation(params, resolver, targetUserHandle); |
| 1888 |
if (locationUri != null) { |
| 1889 |
values.put(Calls.LOCATION, locationUri.toString()); |
| 1890 |
} else { |
| 1891 |
values.put(Calls.LOCATION, (String) null); |
| 1892 |
} |
| 1893 |
} |
| 1894 |
|
| 1895 |
result = addEntryAndRemoveExpiredEntries(context, userManager, targetUserHandle, |
| 1896 |
values); |
| 1897 |
} |
| 1898 |
return result; |
| 1899 |
} |
| 1900 |
|
| 1901 |
private static String charSequenceToString(CharSequence sequence) { |
| 1902 |
return sequence == null ? null : sequence.toString(); |
| 1903 |
} |
| 1904 |
|
| 1905 |
|
| 1906 |
public static boolean shouldHaveSharedCallLogEntries(Context context, |
| 1907 |
UserManager userManager, int userId) { |
| 1908 |
if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, |
| 1909 |
UserHandle.of(userId))) { |
| 1910 |
return false; |
| 1911 |
} |
| 1912 |
final UserInfo userInfo = userManager.getUserInfo(userId); |
| 1913 |
return userInfo != null && !userInfo.isManagedProfile(); |
| 1914 |
} |
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
public static String getLastOutgoingCall(Context context) { |
| 1923 |
final ContentResolver resolver = context.getContentResolver(); |
| 1924 |
Cursor c = null; |
| 1925 |
try { |
| 1926 |
c = resolver.query( |
| 1927 |
CONTENT_URI_LIMIT_1, |
| 1928 |
new String[] {NUMBER}, |
| 1929 |
TYPE + " = " + OUTGOING_TYPE, |
| 1930 |
null, |
| 1931 |
DEFAULT_SORT_ORDER); |
| 1932 |
if (c == null || !c.moveToFirst()) { |
| 1933 |
return ""; |
| 1934 |
} |
| 1935 |
return c.getString(0); |
| 1936 |
} finally { |
| 1937 |
if (c != null) c.close(); |
| 1938 |
} |
| 1939 |
} |
| 1940 |
|
| 1941 |
private static Uri addEntryAndRemoveExpiredEntries(Context context, UserManager userManager, |
| 1942 |
UserHandle user, ContentValues values) { |
| 1943 |
final ContentResolver resolver = context.getContentResolver(); |
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
final Uri uri = ContentProvider.maybeAddUserId( |
| 1948 |
userManager.isUserUnlocked(user) ? CONTENT_URI : SHADOW_CONTENT_URI, |
| 1949 |
user.getIdentifier()); |
| 1950 |
|
| 1951 |
if (VERBOSE_LOG) { |
| 1952 |
Log.v(LOG_TAG, String.format("Inserting to %s", uri)); |
| 1953 |
} |
| 1954 |
|
| 1955 |
try { |
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
final Uri result = resolver.insert(uri, values); |
| 1963 |
if (result != null) { |
| 1964 |
String lastPathSegment = result.getLastPathSegment(); |
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
if (lastPathSegment != null && lastPathSegment.equals("0")) { |
| 1973 |
Log.w(LOG_TAG, "Failed to insert into call log due to appops denial;" |
| 1974 |
+ " resultUri=" + result); |
| 1975 |
} |
| 1976 |
} else { |
| 1977 |
Log.w(LOG_TAG, "Failed to insert into call log; null result uri."); |
| 1978 |
} |
| 1979 |
|
| 1980 |
if (values.containsKey(PHONE_ACCOUNT_ID) |
| 1981 |
&& !TextUtils.isEmpty(values.getAsString(PHONE_ACCOUNT_ID)) |
| 1982 |
&& values.containsKey(PHONE_ACCOUNT_COMPONENT_NAME) |
| 1983 |
&& !TextUtils.isEmpty(values.getAsString(PHONE_ACCOUNT_COMPONENT_NAME))) { |
| 1984 |
|
| 1985 |
resolver.delete(uri, "_id IN " + |
| 1986 |
"(SELECT _id FROM calls" |
| 1987 |
+ " WHERE " + PHONE_ACCOUNT_COMPONENT_NAME + " = ?" |
| 1988 |
+ " AND " + PHONE_ACCOUNT_ID + " = ?" |
| 1989 |
+ " ORDER BY " + DEFAULT_SORT_ORDER |
| 1990 |
+ " LIMIT -1 OFFSET 500)", new String[] { |
| 1991 |
values.getAsString(PHONE_ACCOUNT_COMPONENT_NAME), |
| 1992 |
values.getAsString(PHONE_ACCOUNT_ID) |
| 1993 |
}); |
| 1994 |
} else { |
| 1995 |
|
| 1996 |
resolver.delete(uri, "_id IN " + |
| 1997 |
"(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER |
| 1998 |
+ " LIMIT -1 OFFSET 500)", null); |
| 1999 |
} |
| 2000 |
|
| 2001 |
return result; |
| 2002 |
} catch (IllegalArgumentException e) { |
| 2003 |
Log.w(LOG_TAG, "Failed to insert calllog", e); |
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
return null; |
| 2008 |
} |
| 2009 |
} |
| 2010 |
|
| 2011 |
private static Uri maybeInsertLocation(AddCallParams params, ContentResolver resolver, |
| 2012 |
UserHandle user) { |
| 2013 |
if (Double.isNaN(params.mLatitude) || Double.isNaN(params.mLongitude)) { |
| 2014 |
return null; |
| 2015 |
} |
| 2016 |
ContentValues locationValues = new ContentValues(); |
| 2017 |
locationValues.put(Locations.LATITUDE, params.mLatitude); |
| 2018 |
locationValues.put(Locations.LONGITUDE, params.mLongitude); |
| 2019 |
Uri locationUri = ContentProvider.maybeAddUserId(Locations.CONTENT_URI, |
| 2020 |
user.getIdentifier()); |
| 2021 |
try { |
| 2022 |
return resolver.insert(locationUri, locationValues); |
| 2023 |
} catch (SecurityException e) { |
| 2024 |
|
| 2025 |
|
| 2026 |
Log.w(LOG_TAG, "Skipping inserting location because caller lacks" |
| 2027 |
+ " ACCESS_FINE_LOCATION."); |
| 2028 |
return null; |
| 2029 |
} |
| 2030 |
} |
| 2031 |
|
| 2032 |
private static void updateDataUsageStatForData(ContentResolver resolver, String dataId) { |
| 2033 |
final Uri feedbackUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() |
| 2034 |
.appendPath(dataId) |
| 2035 |
.appendQueryParameter(DataUsageFeedback.USAGE_TYPE, |
| 2036 |
DataUsageFeedback.USAGE_TYPE_CALL) |
| 2037 |
.build(); |
| 2038 |
resolver.update(feedbackUri, new ContentValues(), null, null); |
| 2039 |
} |
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
private static void updateNormalizedNumber(Context context, ContentResolver resolver, |
| 2046 |
String dataId, String number) { |
| 2047 |
if (TextUtils.isEmpty(number) || TextUtils.isEmpty(dataId)) { |
| 2048 |
return; |
| 2049 |
} |
| 2050 |
final String countryIso = getCurrentCountryIso(context); |
| 2051 |
if (TextUtils.isEmpty(countryIso)) { |
| 2052 |
return; |
| 2053 |
} |
| 2054 |
final String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); |
| 2055 |
if (TextUtils.isEmpty(normalizedNumber)) { |
| 2056 |
return; |
| 2057 |
} |
| 2058 |
final ContentValues values = new ContentValues(); |
| 2059 |
values.put(Phone.NORMALIZED_NUMBER, normalizedNumber); |
| 2060 |
resolver.update(Data.CONTENT_URI, values, Data._ID + "=?", new String[] {dataId}); |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
private static int getLogNumberPresentation(String number, int presentation) { |
| 2071 |
if (presentation == TelecomManager.PRESENTATION_RESTRICTED) { |
| 2072 |
return presentation; |
| 2073 |
} |
| 2074 |
|
| 2075 |
if (presentation == TelecomManager.PRESENTATION_PAYPHONE) { |
| 2076 |
return presentation; |
| 2077 |
} |
| 2078 |
|
| 2079 |
if (presentation == TelecomManager.PRESENTATION_UNAVAILABLE) { |
| 2080 |
return PRESENTATION_UNAVAILABLE; |
| 2081 |
} |
| 2082 |
|
| 2083 |
if (TextUtils.isEmpty(number) |
| 2084 |
|| presentation == TelecomManager.PRESENTATION_UNKNOWN) { |
| 2085 |
return PRESENTATION_UNKNOWN; |
| 2086 |
} |
| 2087 |
|
| 2088 |
return PRESENTATION_ALLOWED; |
| 2089 |
} |
| 2090 |
|
| 2091 |
private static String getLogAccountAddress(Context context, |
| 2092 |
PhoneAccountHandle accountHandle) { |
| 2093 |
TelecomManager tm = null; |
| 2094 |
try { |
| 2095 |
tm = TelecomManager.from(context); |
| 2096 |
} catch (UnsupportedOperationException e) { |
| 2097 |
if (VERBOSE_LOG) { |
| 2098 |
Log.v(LOG_TAG, "No TelecomManager found to get account address."); |
| 2099 |
} |
| 2100 |
} |
| 2101 |
|
| 2102 |
String accountAddress = null; |
| 2103 |
if (tm != null && accountHandle != null) { |
| 2104 |
PhoneAccount account = tm.getPhoneAccount(accountHandle); |
| 2105 |
if (account != null) { |
| 2106 |
Uri address = account.getSubscriptionAddress(); |
| 2107 |
if (address != null) { |
| 2108 |
accountAddress = address.getSchemeSpecificPart(); |
| 2109 |
} |
| 2110 |
} |
| 2111 |
} |
| 2112 |
return accountAddress; |
| 2113 |
} |
| 2114 |
|
| 2115 |
private static String getCurrentCountryIso(Context context) { |
| 2116 |
String countryIso = null; |
| 2117 |
final CountryDetector detector = (CountryDetector) context.getSystemService( |
| 2118 |
Context.COUNTRY_DETECTOR); |
| 2119 |
if (detector != null) { |
| 2120 |
final Country country = detector.detectCountry(); |
| 2121 |
if (country != null) { |
| 2122 |
countryIso = country.getCountryIso(); |
| 2123 |
} |
| 2124 |
} |
| 2125 |
return countryIso; |
| 2126 |
} |
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
public static boolean isUserMissed(long missedReason) { |
| 2139 |
return missedReason >= (USER_MISSED_NO_ANSWER); |
| 2140 |
} |
| 2141 |
} |
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
public static class Locations implements BaseColumns { |
| 2150 |
private Locations() {} |
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
public static final String AUTHORITY = "call_composer_locations"; |
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_composer_location"; |
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
public static final String CONTENT_ITEM_TYPE = |
| 2165 |
"vnd.android.cursor.item/call_composer_location"; |
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
@NonNull |
| 2171 |
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); |
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
public static final String LATITUDE = "latitude"; |
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
public static final String LONGITUDE = "longitude"; |
| 2184 |
} |
| 2185 |
} |