aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Mai <garymai@google.com>2021-05-19 14:17:19 -0700
committerGary Mai <garymai@google.com>2021-06-28 13:29:33 -0700
commitb5ac9e48b9bb1ebddc0badb8059fa13466ad4c08 (patch)
tree14abe8bdae813b7333ad9a9d2aa271146f2cfd5e
parent20c996581db80e07b10af9763ab569be05df2ad4 (diff)
downloadContactsProvider-b5ac9e48b9bb1ebddc0badb8059fa13466ad4c08.tar.gz
DO NOT MERGE
Add SIM categorization logging Test: Unit tests and log output from statsd_testdrive -p com.android.providers.contacts 301 Bug: 187070689 Change-Id: Ib965e4168f2ae17fc5ce1d029b8e8d1367a6cfcd
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java56
-rw-r--r--src/com/android/providers/contacts/util/LogFields.java13
-rw-r--r--src/com/android/providers/contacts/util/LogUtils.java11
3 files changed, 69 insertions, 11 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 4b2b37ae..0c6e8192 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -20,7 +20,6 @@ import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
-import android.os.Looper;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
@@ -65,6 +64,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
+import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor.AutoCloseInputStream;
import android.os.RemoteException;
@@ -126,7 +126,6 @@ import android.util.Log;
import com.android.common.content.ProjectionMap;
import com.android.common.content.SyncStateContentProviderHelper;
import com.android.common.io.MoreCloseables;
-import com.android.i18n.phonenumbers.Phonenumber;
import com.android.internal.util.ArrayUtils;
import com.android.providers.contacts.ContactLookupKey.LookupKeySegment;
import com.android.providers.contacts.ContactsDatabaseHelper.AccountsColumns;
@@ -2273,6 +2272,10 @@ public class ContactsProvider2 extends AbstractContactsProvider
@Override
public Bundle call(String method, String arg, Bundle extras) {
+ LogFields.Builder logBuilder =
+ LogFields.Builder.aLogFields()
+ .setApiType(LogUtils.ApiType.CALL)
+ .setStartNanos(SystemClock.elapsedRealtimeNanos());
waitForAccess(mReadAccessLatch);
switchToContactMode();
if (Authorization.AUTHORIZATION_METHOD.equals(method)) {
@@ -2313,34 +2316,54 @@ public class ContactsProvider2 extends AbstractContactsProvider
throw new IllegalArgumentException("Account name or type is empty");
}
+ long resultId = -1;
final Bundle response = new Bundle();
final SQLiteDatabase db = mDbHelper.get().getWritableDatabase();
db.beginTransaction();
try {
- mDbHelper.get().createSimAccountIdInTransaction(
+ resultId = mDbHelper.get().createSimAccountIdInTransaction(
AccountWithDataSet.get(accountName, accountType, null), simSlot, efType);
db.setTransactionSuccessful();
+ } catch (Exception e) {
+ logBuilder.setException(e);
+ throw e;
} finally {
+ LogUtils.log(
+ logBuilder
+ .setMethodCall(LogUtils.MethodCall.ADD_SIM_ACCOUNTS)
+ .setResultCount(resultId > -1 ? 1 : 0)
+ .build());
db.endTransaction();
}
+
getContext().sendBroadcast(new Intent(SimContacts.ACTION_SIM_ACCOUNTS_CHANGED));
return response;
} else if (SimContacts.REMOVE_SIM_ACCOUNT_METHOD.equals(method)) {
- ContactsPermissions.enforceCallingOrSelfPermission(getContext(),
- MANAGE_SIM_ACCOUNTS_PERMISSION);
+ ContactsPermissions.enforceCallingOrSelfPermission(
+ getContext(), MANAGE_SIM_ACCOUNTS_PERMISSION);
final int simSlot = extras.getInt(SimContacts.KEY_SIM_SLOT_INDEX, -1);
if (simSlot < 0) {
throw new IllegalArgumentException("Sim slot is negative");
}
+
+ int removedCount = 0;
final Bundle response = new Bundle();
final SQLiteDatabase db = mDbHelper.get().getWritableDatabase();
db.beginTransaction();
try {
- mDbHelper.get().removeSimAccounts(simSlot);
+ removedCount = mDbHelper.get().removeSimAccounts(simSlot);
scheduleBackgroundTask(BACKGROUND_TASK_UPDATE_ACCOUNTS);
db.setTransactionSuccessful();
+ } catch (Exception e) {
+ logBuilder.setException(e);
+ throw e;
} finally {
+ LogUtils.log(
+ logBuilder
+ .setMethodCall(LogUtils.MethodCall.REMOVE_SIM_ACCOUNTS)
+ .setResultCount(removedCount)
+ .build());
db.endTransaction();
}
getContext().sendBroadcast(new Intent(SimContacts.ACTION_SIM_ACCOUNTS_CHANGED));
@@ -2348,11 +2371,22 @@ public class ContactsProvider2 extends AbstractContactsProvider
} else if (SimContacts.QUERY_SIM_ACCOUNTS_METHOD.equals(method)) {
ContactsPermissions.enforceCallingOrSelfPermission(getContext(), READ_PERMISSION);
final Bundle response = new Bundle();
-
- final List<SimAccount> simAccounts = mDbHelper.get().getAllSimAccounts();
- response.putParcelableList(SimContacts.KEY_SIM_ACCOUNTS, simAccounts);
-
- return response;
+ int accountsCount = 0;
+ try {
+ final List<SimAccount> simAccounts = mDbHelper.get().getAllSimAccounts();
+ response.putParcelableList(SimContacts.KEY_SIM_ACCOUNTS, simAccounts);
+ accountsCount = simAccounts.size();
+ return response;
+ } catch (Exception e) {
+ logBuilder.setException(e);
+ throw e;
+ } finally {
+ LogUtils.log(
+ logBuilder
+ .setMethodCall(LogUtils.MethodCall.GET_SIM_ACCOUNTS)
+ .setResultCount(accountsCount)
+ .build());
+ }
}
return null;
}
diff --git a/src/com/android/providers/contacts/util/LogFields.java b/src/com/android/providers/contacts/util/LogFields.java
index f4a60fe7..4d07ca4b 100644
--- a/src/com/android/providers/contacts/util/LogFields.java
+++ b/src/com/android/providers/contacts/util/LogFields.java
@@ -34,6 +34,8 @@ public final class LogFields {
private int resultCount;
+ private int methodCall;
+
public LogFields(int apiType, int uriType, boolean callerIsSyncAdapter, long startNanos) {
this.apiType = apiType;
this.uriType = uriType;
@@ -69,6 +71,10 @@ public final class LogFields {
return resultCount;
}
+ public int getMethodCall() {
+ return methodCall;
+ }
+
public static final class Builder {
private int apiType;
private int uriType;
@@ -77,6 +83,7 @@ public final class LogFields {
private Exception exception;
private Uri resultUri;
private int resultCount;
+ private int methodCall;
private Builder() {
}
@@ -120,11 +127,17 @@ public final class LogFields {
return this;
}
+ public Builder setMethodCall(int methodCall) {
+ this.methodCall = methodCall;
+ return this;
+ }
+
public LogFields build() {
LogFields logFields = new LogFields(apiType, uriType, callerIsSyncAdapter, startNanos);
logFields.resultCount = this.resultCount;
logFields.exception = this.exception;
logFields.resultUri = this.resultUri;
+ logFields.methodCall = this.methodCall;
return logFields;
}
}
diff --git a/src/com/android/providers/contacts/util/LogUtils.java b/src/com/android/providers/contacts/util/LogUtils.java
index 9e123257..a564a359 100644
--- a/src/com/android/providers/contacts/util/LogUtils.java
+++ b/src/com/android/providers/contacts/util/LogUtils.java
@@ -37,6 +37,7 @@ public class LogUtils {
int INSERT = 2;
int UPDATE = 3;
int DELETE = 4;
+ int CALL = 5;
}
// Keep in sync with ContactsProviderStatus#CallerType in
@@ -46,6 +47,14 @@ public class LogUtils {
int CALLER_IS_NOT_SYNC_ADAPTER = 2;
}
+ // Keep in sync with ContactsProviderStatus#MethodCall in
+ // frameworks/proto_logging/stats/atoms.proto file.
+ public interface MethodCall {
+ int ADD_SIM_ACCOUNTS = 1;
+ int REMOVE_SIM_ACCOUNTS = 2;
+ int GET_SIM_ACCOUNTS = 3;
+ }
+
private static final int STATSD_LOG_ATOM_ID = 301;
public static void log(LogFields logFields) {
@@ -57,6 +66,8 @@ public class LogUtils {
.writeInt(getResultType(logFields.getException()))
.writeInt(logFields.getResultCount())
.writeLong(getLatencyMicros(logFields.getStartNanos()))
+ .writeInt(0) // Empty value for TaskType
+ .writeInt(logFields.getMethodCall())
.usePooledBuffer()
.build());
}