Program: 8279
Project: 8279
Buggy source:
/** 
 * Saves an UncachedKeyRing of the public variant into the db. <p/> This method will not delete all previous data for this masterKeyId from the database prior to inserting. All public data is effectively re-inserted, secret keyrings are left deleted and need to be saved externally to be preserved past the operation.
 */
@SuppressWarnings("String_Node_Str") private int saveCanonicalizedPublicKeyRing(CanonicalizedPublicKeyRing keyRing,Progressable progress,boolean selfCertsAreTrusted){
  int result=SaveKeyringResult.SAVED_PUBLIC;
  long masterKeyId=keyRing.getMasterKeyId();
  UncachedPublicKey masterKey=keyRing.getPublicKey();
  ArrayList<ContentProviderOperation> operations;
  try {
    log(LogType.MSG_IP_PREPARE);
    mIndent+=1;
    operations=new ArrayList<>();
    log(LogType.MSG_IP_INSERT_KEYRING);
{
      ContentValues values=new ContentValues();
      values.put(KeyRingData.MASTER_KEY_ID,masterKeyId);
      try {
        values.put(KeyRingData.KEY_RING_DATA,keyRing.getEncoded());
      }
 catch (      IOException e) {
        log(LogType.MSG_IP_ENCODE_FAIL);
        return SaveKeyringResult.RESULT_ERROR;
      }
      Uri uri=KeyRingData.buildPublicKeyRingUri(masterKeyId);
      operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
    }
    log(LogType.MSG_IP_INSERT_SUBKEYS);
    progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(),40,100);
    mIndent+=1;
{
      Uri uri=Keys.buildKeysUri(masterKeyId);
      int rank=0;
      for (      CanonicalizedPublicKey key : keyRing.publicKeyIterator()) {
        long keyId=key.getKeyId();
        log(keyId == masterKeyId ? LogType.MSG_IP_MASTER : LogType.MSG_IP_SUBKEY,KeyFormattingUtils.convertKeyIdToHex(keyId));
        mIndent+=1;
        ContentValues values=new ContentValues();
        values.put(Keys.MASTER_KEY_ID,masterKeyId);
        values.put(Keys.RANK,rank);
        values.put(Keys.KEY_ID,key.getKeyId());
        values.put(Keys.KEY_SIZE,key.getBitStrength());
        values.put(Keys.KEY_CURVE_OID,key.getCurveOid());
        values.put(Keys.ALGORITHM,key.getAlgorithm());
        values.put(Keys.FINGERPRINT,key.getFingerprint());
        boolean c=key.canCertify(), e=key.canEncrypt(), s=key.canSign(), a=key.canAuthenticate();
        values.put(Keys.CAN_CERTIFY,c);
        values.put(Keys.CAN_ENCRYPT,e);
        values.put(Keys.CAN_SIGN,s);
        values.put(Keys.CAN_AUTHENTICATE,a);
        values.put(Keys.IS_REVOKED,key.isRevoked());
        if (masterKeyId == keyId) {
          if (key.getKeyUsage() == null) {
            log(LogType.MSG_IP_MASTER_FLAGS_UNSPECIFIED);
          }
 else {
            log(LOG_TYPES_FLAG_MASTER[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0)+ (a ? 8 : 0)]);
          }
        }
 else {
          if (key.getKeyUsage() == null) {
            log(LogType.MSG_IP_SUBKEY_FLAGS_UNSPECIFIED);
          }
 else {
            log(LOG_TYPES_FLAG_SUBKEY[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0)+ (a ? 8 : 0)]);
          }
        }
        Date creation=key.getCreationTime();
        values.put(Keys.CREATION,creation.getTime() / 1000);
        Date expiryDate=key.getExpiryTime();
        if (expiryDate != null) {
          values.put(Keys.EXPIRY,expiryDate.getTime() / 1000);
          if (key.isExpired()) {
            log(keyId == masterKeyId ? LogType.MSG_IP_MASTER_EXPIRED : LogType.MSG_IP_SUBKEY_EXPIRED,expiryDate.toString());
          }
 else {
            log(keyId == masterKeyId ? LogType.MSG_IP_MASTER_EXPIRES : LogType.MSG_IP_SUBKEY_EXPIRES,expiryDate.toString());
          }
        }
        operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
        ++rank;
        mIndent-=1;
      }
    }
    mIndent-=1;
    LongSparseArray<CanonicalizedPublicKey> trustedKeys=getTrustedMasterKeys();
    List<UserPacketItem> uids=new ArrayList<>();
    if (trustedKeys.size() == 0) {
      log(LogType.MSG_IP_UID_CLASSIFYING_ZERO);
    }
 else {
      log(LogType.MSG_IP_UID_CLASSIFYING,trustedKeys.size());
    }
    mIndent+=1;
    for (    byte[] rawUserId : masterKey.getUnorderedRawUserIds()) {
      String userId=Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(rawUserId);
      UserPacketItem item=new UserPacketItem();
      uids.add(item);
      item.userId=userId;
      int unknownCerts=0;
      log(LogType.MSG_IP_UID_PROCESSING,userId);
      mIndent+=1;
      for (      WrappedSignature cert : new IterableIterator<>(masterKey.getSignaturesForRawId(rawUserId))) {
        long certId=cert.getKeyId();
        if (certId == masterKeyId) {
          if (!cert.isRevocation()) {
            item.selfCert=cert;
            item.isPrimary=cert.isPrimaryUserId();
          }
 else {
            item.selfRevocation=cert;
            log(LogType.MSG_IP_UID_REVOKED);
          }
          continue;
        }
        if (trustedKeys.indexOfKey(certId) < 0) {
          unknownCerts+=1;
          continue;
        }
        CanonicalizedPublicKey trustedKey=trustedKeys.get(certId);
        try {
          cert.init(trustedKey);
          if (!cert.verifySignature(masterKey,rawUserId)) {
            log(LogType.MSG_IP_UID_CERT_BAD);
            continue;
          }
          log(cert.isRevocation() ? LogType.MSG_IP_UID_CERT_GOOD_REVOKE : LogType.MSG_IP_UID_CERT_GOOD,KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()));
          WrappedSignature prev=item.trustedCerts.get(cert.getKeyId());
          if (prev != null) {
            if (prev.getCreationTime().after(cert.getCreationTime())) {
              log(LogType.MSG_IP_UID_CERT_OLD);
              continue;
            }
            if (!prev.isRevocation() && !prev.isRevokable()) {
              log(LogType.MSG_IP_UID_CERT_NONREVOKE);
              continue;
            }
            log(LogType.MSG_IP_UID_CERT_NEW);
          }
          item.trustedCerts.put(cert.getKeyId(),cert);
        }
 catch (        PgpGeneralException e) {
          log(LogType.MSG_IP_UID_CERT_ERROR,KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId()));
        }
      }
      if (unknownCerts > 0) {
        log(LogType.MSG_IP_UID_CERTS_UNKNOWN,unknownCerts);
      }
      mIndent-=1;
    }
    mIndent-=1;
    ArrayList<WrappedUserAttribute> userAttributes=masterKey.getUnorderedUserAttributes();
    if (!userAttributes.isEmpty()) {
      log(LogType.MSG_IP_UAT_CLASSIFYING);
    }
    mIndent+=1;
    for (    WrappedUserAttribute userAttribute : userAttributes) {
      UserPacketItem item=new UserPacketItem();
      uids.add(item);
      item.type=userAttribute.getType();
      item.attributeData=userAttribute.getEncoded();
      int unknownCerts=0;
switch (item.type) {
case WrappedUserAttribute.UAT_IMAGE:
        log(LogType.MSG_IP_UAT_PROCESSING_IMAGE);
      break;
default :
    log(LogType.MSG_IP_UAT_PROCESSING_UNKNOWN);
  break;
}
mIndent+=1;
for (WrappedSignature cert : new IterableIterator<>(masterKey.getSignaturesForUserAttribute(userAttribute))) {
long certId=cert.getKeyId();
if (certId == masterKeyId) {
  if (!cert.isRevocation()) {
    item.selfCert=cert;
  }
 else {
    item.selfRevocation=cert;
    log(LogType.MSG_IP_UAT_REVOKED);
  }
  continue;
}
if (trustedKeys.indexOfKey(certId) < 0) {
  unknownCerts+=1;
  continue;
}
CanonicalizedPublicKey trustedKey=trustedKeys.get(certId);
try {
  cert.init(trustedKey);
  if (!cert.verifySignature(masterKey,userAttribute)) {
    log(LogType.MSG_IP_UAT_CERT_BAD);
    continue;
  }
  log(cert.isRevocation() ? LogType.MSG_IP_UAT_CERT_GOOD_REVOKE : LogType.MSG_IP_UAT_CERT_GOOD,KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()));
  WrappedSignature prev=item.trustedCerts.get(cert.getKeyId());
  if (prev != null) {
    if (prev.getCreationTime().after(cert.getCreationTime())) {
      log(LogType.MSG_IP_UAT_CERT_OLD);
      continue;
    }
    if (!prev.isRevocation() && !prev.isRevokable()) {
      log(LogType.MSG_IP_UAT_CERT_NONREVOKE);
      continue;
    }
    log(LogType.MSG_IP_UAT_CERT_NEW);
  }
  item.trustedCerts.put(cert.getKeyId(),cert);
}
 catch (PgpGeneralException e) {
  log(LogType.MSG_IP_UAT_CERT_ERROR,KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId()));
}
}
if (unknownCerts > 0) {
log(LogType.MSG_IP_UAT_CERTS_UNKNOWN,unknownCerts);
}
mIndent-=1;
}
mIndent-=1;
progress.setProgress(LogType.MSG_IP_UID_REORDER.getMsgId(),65,100);
log(LogType.MSG_IP_UID_REORDER);
Collections.sort(uids);
for (int userIdRank=0; userIdRank < uids.size(); userIdRank++) {
UserPacketItem item=uids.get(userIdRank);
operations.add(buildUserIdOperations(masterKeyId,item,userIdRank));
if (item.selfRevocation != null) {
operations.add(buildCertOperations(masterKeyId,userIdRank,item.selfRevocation,Certs.VERIFIED_SELF));
continue;
}
if (item.selfCert == null) {
throw new AssertionError("String_Node_Str");
}
operations.add(buildCertOperations(masterKeyId,userIdRank,item.selfCert,selfCertsAreTrusted ? Certs.VERIFIED_SECRET : Certs.VERIFIED_SELF));
for (int i=0; i < item.trustedCerts.size(); i++) {
WrappedSignature sig=item.trustedCerts.valueAt(i);
if (sig.isRevocation()) {
  continue;
}
operations.add(buildCertOperations(masterKeyId,userIdRank,sig,Certs.VERIFIED_SECRET));
}
}
}
 catch (IOException e) {
log(LogType.MSG_IP_ERROR_IO_EXC);
Log.e(Constants.TAG,"String_Node_Str",e);
return SaveKeyringResult.RESULT_ERROR;
}
 finally {
mIndent-=1;
}
final int INDEX_MASTER_KEY_ID=0;
final int INDEX_LAST_UPDATED=1;
Cursor lastUpdatedCursor=mContentResolver.query(UpdatedKeys.CONTENT_URI,new String[]{UpdatedKeys.MASTER_KEY_ID,UpdatedKeys.LAST_UPDATED},UpdatedKeys.MASTER_KEY_ID + "String_Node_Str",new String[]{"String_Node_Str" + masterKeyId},null);
ContentValues lastUpdatedEntry=null;
if (lastUpdatedCursor.moveToNext()) {
lastUpdatedEntry=new ContentValues(2);
lastUpdatedEntry.put(UpdatedKeys.MASTER_KEY_ID,lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID));
lastUpdatedEntry.put(UpdatedKeys.LAST_UPDATED,lastUpdatedCursor.getLong(INDEX_LAST_UPDATED));
Log.e("String_Node_Str","String_Node_Str" + lastUpdatedEntry + "String_Node_Str"+ masterKeyId);
}
lastUpdatedCursor.close();
if (lastUpdatedEntry != null) {
operations.add(ContentProviderOperation.newInsert(UpdatedKeys.CONTENT_URI).withValues(lastUpdatedEntry).build());
}
try {
int deleted=mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId),null,null);
if (deleted > 0) {
log(LogType.MSG_IP_DELETE_OLD_OK);
result|=SaveKeyringResult.UPDATED;
}
 else {
log(LogType.MSG_IP_DELETE_OLD_FAIL);
}
log(LogType.MSG_IP_APPLY_BATCH);
progress.setProgress(LogType.MSG_IP_APPLY_BATCH.getMsgId(),75,100);
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY,operations);
log(LogType.MSG_IP_SUCCESS);
progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(),90,100);
return result;
}
 catch (RemoteException e) {
log(LogType.MSG_IP_ERROR_REMOTE_EX);
Log.e(Constants.TAG,"String_Node_Str",e);
return SaveKeyringResult.RESULT_ERROR;
}
catch (OperationApplicationException e) {
log(LogType.MSG_IP_ERROR_OP_EXC);
Log.e(Constants.TAG,"String_Node_Str",e);
return SaveKeyringResult.RESULT_ERROR;
}
}

Fixed version (ground truth):
/** 
 * Saves an UncachedKeyRing of the public variant into the db. <p/> This method will not delete all previous data for this masterKeyId from the database prior to inserting. All public data is effectively re-inserted, secret keyrings are left deleted and need to be saved externally to be preserved past the operation.
 */
@SuppressWarnings("String_Node_Str") private int saveCanonicalizedPublicKeyRing(CanonicalizedPublicKeyRing keyRing,Progressable progress,boolean selfCertsAreTrusted){
  int result=SaveKeyringResult.SAVED_PUBLIC;
  long masterKeyId=keyRing.getMasterKeyId();
  UncachedPublicKey masterKey=keyRing.getPublicKey();
  ArrayList<ContentProviderOperation> operations;
  try {
    log(LogType.MSG_IP_PREPARE);
    mIndent+=1;
    operations=new ArrayList<>();
    log(LogType.MSG_IP_INSERT_KEYRING);
{
      ContentValues values=new ContentValues();
      values.put(KeyRingData.MASTER_KEY_ID,masterKeyId);
      try {
        values.put(KeyRingData.KEY_RING_DATA,keyRing.getEncoded());
      }
 catch (      IOException e) {
        log(LogType.MSG_IP_ENCODE_FAIL);
        return SaveKeyringResult.RESULT_ERROR;
      }
      Uri uri=KeyRingData.buildPublicKeyRingUri(masterKeyId);
      operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
    }
    log(LogType.MSG_IP_INSERT_SUBKEYS);
    progress.setProgress(LogType.MSG_IP_INSERT_SUBKEYS.getMsgId(),40,100);
    mIndent+=1;
{
      Uri uri=Keys.buildKeysUri(masterKeyId);
      int rank=0;
      for (      CanonicalizedPublicKey key : keyRing.publicKeyIterator()) {
        long keyId=key.getKeyId();
        log(keyId == masterKeyId ? LogType.MSG_IP_MASTER : LogType.MSG_IP_SUBKEY,KeyFormattingUtils.convertKeyIdToHex(keyId));
        mIndent+=1;
        ContentValues values=new ContentValues();
        values.put(Keys.MASTER_KEY_ID,masterKeyId);
        values.put(Keys.RANK,rank);
        values.put(Keys.KEY_ID,key.getKeyId());
        values.put(Keys.KEY_SIZE,key.getBitStrength());
        values.put(Keys.KEY_CURVE_OID,key.getCurveOid());
        values.put(Keys.ALGORITHM,key.getAlgorithm());
        values.put(Keys.FINGERPRINT,key.getFingerprint());
        boolean c=key.canCertify(), e=key.canEncrypt(), s=key.canSign(), a=key.canAuthenticate();
        values.put(Keys.CAN_CERTIFY,c);
        values.put(Keys.CAN_ENCRYPT,e);
        values.put(Keys.CAN_SIGN,s);
        values.put(Keys.CAN_AUTHENTICATE,a);
        values.put(Keys.IS_REVOKED,key.isRevoked());
        if (masterKeyId == keyId) {
          if (key.getKeyUsage() == null) {
            log(LogType.MSG_IP_MASTER_FLAGS_UNSPECIFIED);
          }
 else {
            log(LOG_TYPES_FLAG_MASTER[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0)+ (a ? 8 : 0)]);
          }
        }
 else {
          if (key.getKeyUsage() == null) {
            log(LogType.MSG_IP_SUBKEY_FLAGS_UNSPECIFIED);
          }
 else {
            log(LOG_TYPES_FLAG_SUBKEY[(c ? 1 : 0) + (e ? 2 : 0) + (s ? 4 : 0)+ (a ? 8 : 0)]);
          }
        }
        Date creation=key.getCreationTime();
        values.put(Keys.CREATION,creation.getTime() / 1000);
        Date expiryDate=key.getExpiryTime();
        if (expiryDate != null) {
          values.put(Keys.EXPIRY,expiryDate.getTime() / 1000);
          if (key.isExpired()) {
            log(keyId == masterKeyId ? LogType.MSG_IP_MASTER_EXPIRED : LogType.MSG_IP_SUBKEY_EXPIRED,expiryDate.toString());
          }
 else {
            log(keyId == masterKeyId ? LogType.MSG_IP_MASTER_EXPIRES : LogType.MSG_IP_SUBKEY_EXPIRES,expiryDate.toString());
          }
        }
        operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
        ++rank;
        mIndent-=1;
      }
    }
    mIndent-=1;
    LongSparseArray<CanonicalizedPublicKey> trustedKeys=getTrustedMasterKeys();
    List<UserPacketItem> uids=new ArrayList<>();
    if (trustedKeys.size() == 0) {
      log(LogType.MSG_IP_UID_CLASSIFYING_ZERO);
    }
 else {
      log(LogType.MSG_IP_UID_CLASSIFYING,trustedKeys.size());
    }
    mIndent+=1;
    for (    byte[] rawUserId : masterKey.getUnorderedRawUserIds()) {
      String userId=Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(rawUserId);
      UserPacketItem item=new UserPacketItem();
      uids.add(item);
      item.userId=userId;
      int unknownCerts=0;
      log(LogType.MSG_IP_UID_PROCESSING,userId);
      mIndent+=1;
      for (      WrappedSignature cert : new IterableIterator<>(masterKey.getSignaturesForRawId(rawUserId))) {
        long certId=cert.getKeyId();
        if (certId == masterKeyId) {
          if (!cert.isRevocation()) {
            item.selfCert=cert;
            item.isPrimary=cert.isPrimaryUserId();
          }
 else {
            item.selfRevocation=cert;
            log(LogType.MSG_IP_UID_REVOKED);
          }
          continue;
        }
        if (trustedKeys.indexOfKey(certId) < 0) {
          unknownCerts+=1;
          continue;
        }
        CanonicalizedPublicKey trustedKey=trustedKeys.get(certId);
        try {
          cert.init(trustedKey);
          if (!cert.verifySignature(masterKey,rawUserId)) {
            log(LogType.MSG_IP_UID_CERT_BAD);
            continue;
          }
          log(cert.isRevocation() ? LogType.MSG_IP_UID_CERT_GOOD_REVOKE : LogType.MSG_IP_UID_CERT_GOOD,KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()));
          WrappedSignature prev=item.trustedCerts.get(cert.getKeyId());
          if (prev != null) {
            if (prev.getCreationTime().after(cert.getCreationTime())) {
              log(LogType.MSG_IP_UID_CERT_OLD);
              continue;
            }
            if (!prev.isRevocation() && !prev.isRevokable()) {
              log(LogType.MSG_IP_UID_CERT_NONREVOKE);
              continue;
            }
            log(LogType.MSG_IP_UID_CERT_NEW);
          }
          item.trustedCerts.put(cert.getKeyId(),cert);
        }
 catch (        PgpGeneralException e) {
          log(LogType.MSG_IP_UID_CERT_ERROR,KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId()));
        }
      }
      if (unknownCerts > 0) {
        log(LogType.MSG_IP_UID_CERTS_UNKNOWN,unknownCerts);
      }
      mIndent-=1;
    }
    mIndent-=1;
    ArrayList<WrappedUserAttribute> userAttributes=masterKey.getUnorderedUserAttributes();
    if (!userAttributes.isEmpty()) {
      log(LogType.MSG_IP_UAT_CLASSIFYING);
    }
    mIndent+=1;
    for (    WrappedUserAttribute userAttribute : userAttributes) {
      UserPacketItem item=new UserPacketItem();
      uids.add(item);
      item.type=userAttribute.getType();
      item.attributeData=userAttribute.getEncoded();
      int unknownCerts=0;
switch (item.type) {
case WrappedUserAttribute.UAT_IMAGE:
        log(LogType.MSG_IP_UAT_PROCESSING_IMAGE);
      break;
default :
    log(LogType.MSG_IP_UAT_PROCESSING_UNKNOWN);
  break;
}
mIndent+=1;
for (WrappedSignature cert : new IterableIterator<>(masterKey.getSignaturesForUserAttribute(userAttribute))) {
long certId=cert.getKeyId();
if (certId == masterKeyId) {
  if (!cert.isRevocation()) {
    item.selfCert=cert;
  }
 else {
    item.selfRevocation=cert;
    log(LogType.MSG_IP_UAT_REVOKED);
  }
  continue;
}
if (trustedKeys.indexOfKey(certId) < 0) {
  unknownCerts+=1;
  continue;
}
CanonicalizedPublicKey trustedKey=trustedKeys.get(certId);
try {
  cert.init(trustedKey);
  if (!cert.verifySignature(masterKey,userAttribute)) {
    log(LogType.MSG_IP_UAT_CERT_BAD);
    continue;
  }
  log(cert.isRevocation() ? LogType.MSG_IP_UAT_CERT_GOOD_REVOKE : LogType.MSG_IP_UAT_CERT_GOOD,KeyFormattingUtils.convertKeyIdToHexShort(trustedKey.getKeyId()));
  WrappedSignature prev=item.trustedCerts.get(cert.getKeyId());
  if (prev != null) {
    if (prev.getCreationTime().after(cert.getCreationTime())) {
      log(LogType.MSG_IP_UAT_CERT_OLD);
      continue;
    }
    if (!prev.isRevocation() && !prev.isRevokable()) {
      log(LogType.MSG_IP_UAT_CERT_NONREVOKE);
      continue;
    }
    log(LogType.MSG_IP_UAT_CERT_NEW);
  }
  item.trustedCerts.put(cert.getKeyId(),cert);
}
 catch (PgpGeneralException e) {
  log(LogType.MSG_IP_UAT_CERT_ERROR,KeyFormattingUtils.convertKeyIdToHex(cert.getKeyId()));
}
}
if (unknownCerts > 0) {
log(LogType.MSG_IP_UAT_CERTS_UNKNOWN,unknownCerts);
}
mIndent-=1;
}
mIndent-=1;
progress.setProgress(LogType.MSG_IP_UID_REORDER.getMsgId(),65,100);
log(LogType.MSG_IP_UID_REORDER);
Collections.sort(uids);
for (int userIdRank=0; userIdRank < uids.size(); userIdRank++) {
UserPacketItem item=uids.get(userIdRank);
operations.add(buildUserIdOperations(masterKeyId,item,userIdRank));
if (item.selfRevocation != null) {
operations.add(buildCertOperations(masterKeyId,userIdRank,item.selfRevocation,Certs.VERIFIED_SELF));
continue;
}
if (item.selfCert == null) {
throw new AssertionError("String_Node_Str");
}
operations.add(buildCertOperations(masterKeyId,userIdRank,item.selfCert,selfCertsAreTrusted ? Certs.VERIFIED_SECRET : Certs.VERIFIED_SELF));
for (int i=0; i < item.trustedCerts.size(); i++) {
WrappedSignature sig=item.trustedCerts.valueAt(i);
if (sig.isRevocation()) {
  continue;
}
operations.add(buildCertOperations(masterKeyId,userIdRank,sig,Certs.VERIFIED_SECRET));
}
}
}
 catch (IOException e) {
log(LogType.MSG_IP_ERROR_IO_EXC);
Log.e(Constants.TAG,"String_Node_Str",e);
return SaveKeyringResult.RESULT_ERROR;
}
 finally {
mIndent-=1;
}
final int INDEX_MASTER_KEY_ID=0;
final int INDEX_LAST_UPDATED=1;
Cursor lastUpdatedCursor=mContentResolver.query(UpdatedKeys.CONTENT_URI,new String[]{UpdatedKeys.MASTER_KEY_ID,UpdatedKeys.LAST_UPDATED},UpdatedKeys.MASTER_KEY_ID + "String_Node_Str",new String[]{"String_Node_Str" + masterKeyId},null);
if (lastUpdatedCursor.moveToNext()) {
ContentValues lastUpdatedEntry=new ContentValues(2);
lastUpdatedEntry.put(UpdatedKeys.MASTER_KEY_ID,lastUpdatedCursor.getLong(INDEX_MASTER_KEY_ID));
lastUpdatedEntry.put(UpdatedKeys.LAST_UPDATED,lastUpdatedCursor.getLong(INDEX_LAST_UPDATED));
operations.add(ContentProviderOperation.newInsert(UpdatedKeys.CONTENT_URI).withValues(lastUpdatedEntry).build());
}
lastUpdatedCursor.close();
try {
int deleted=mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId),null,null);
if (deleted > 0) {
log(LogType.MSG_IP_DELETE_OLD_OK);
result|=SaveKeyringResult.UPDATED;
}
 else {
log(LogType.MSG_IP_DELETE_OLD_FAIL);
}
log(LogType.MSG_IP_APPLY_BATCH);
progress.setProgress(LogType.MSG_IP_APPLY_BATCH.getMsgId(),75,100);
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY,operations);
log(LogType.MSG_IP_SUCCESS);
progress.setProgress(LogType.MSG_IP_SUCCESS.getMsgId(),90,100);
return result;
}
 catch (RemoteException e) {
log(LogType.MSG_IP_ERROR_REMOTE_EX);
Log.e(Constants.TAG,"String_Node_Str",e);
return SaveKeyringResult.RESULT_ERROR;
}
catch (OperationApplicationException e) {
log(LogType.MSG_IP_ERROR_OP_EXC);
Log.e(Constants.TAG,"String_Node_Str",e);
return SaveKeyringResult.RESULT_ERROR;
}
}