summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2014-07-08 14:13:23 -0700
committerMakoto Onuki <omakoto@google.com>2014-07-08 14:15:22 -0700
commit6bcd74c4bc4a14d848a8407562b10a14876082df (patch)
tree3819f61ab08924b9a21357f8e164a2a41854b404
parentcd38c397e0c59ae283c65147535eb728e29c0be4 (diff)
downloadpackages_providers_ContactsProvider-6bcd74c4bc4a14d848a8407562b10a14876082df.zip
packages_providers_ContactsProvider-6bcd74c4bc4a14d848a8407562b10a14876082df.tar.gz
packages_providers_ContactsProvider-6bcd74c4bc4a14d848a8407562b10a14876082df.tar.bz2
Enterprise: Add utility method to retrieve corp user handle.
Also show current user handle in verbose log. Bug 15779911 Change-Id: If9dac500da44b351232ac8af53dc011be043d010
-rw-r--r--AndroidManifest.xml1
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java12
-rw-r--r--src/com/android/providers/contacts/UserUtils.java77
3 files changed, 86 insertions, 4 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 771aba1..e335e40 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -20,6 +20,7 @@
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+ <uses-permission android:name="android.permission.MANAGE_USERS" />
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
<uses-permission android:name="com.android.voicemail.permission.READ_WRITE_ALL_VOICEMAIL" />
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index da005ff..431eb4d 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -3402,7 +3402,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
if (VERBOSE_LOGGING) {
Log.v(TAG, "deleteInTransaction: uri=" + uri +
" selection=[" + selection + "] args=" + Arrays.toString(selectionArgs) +
- " CPID=" + Binder.getCallingPid());
+ " CPID=" + Binder.getCallingPid() +
+ " User=" + UserUtils.getCurrentUserHandle(getContext()));
}
final SQLiteDatabase db = mDbHelper.get().getWritableDatabase();
@@ -3812,7 +3813,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
if (VERBOSE_LOGGING) {
Log.v(TAG, "updateInTransaction: uri=" + uri +
" selection=[" + selection + "] args=" + Arrays.toString(selectionArgs) +
- " values=[" + values + "] CPID=" + Binder.getCallingPid());
+ " values=[" + values + "] CPID=" + Binder.getCallingPid() +
+ " User=" + UserUtils.getCurrentUserHandle(getContext()));
}
final SQLiteDatabase db = mDbHelper.get().getWritableDatabase();
@@ -4967,7 +4969,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
if (VERBOSE_LOGGING) {
Log.v(TAG, "query: uri=" + uri + " projection=" + Arrays.toString(projection) +
" selection=[" + selection + "] args=" + Arrays.toString(selectionArgs) +
- " order=[" + sortOrder + "] CPID=" + Binder.getCallingPid());
+ " order=[" + sortOrder + "] CPID=" + Binder.getCallingPid() +
+ " User=" + UserUtils.getCurrentUserHandle(getContext()));
}
waitForAccess(mReadAccessLatch);
@@ -7556,7 +7559,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
} finally {
if (VERBOSE_LOGGING) {
Log.v(TAG, "openAssetFile uri=" + uri + " mode=" + mode + " success=" + success +
- " CPID=" + Binder.getCallingPid());
+ " CPID=" + Binder.getCallingPid() +
+ " User=" + UserUtils.getCurrentUserHandle(getContext()));
}
}
}
diff --git a/src/com/android/providers/contacts/UserUtils.java b/src/com/android/providers/contacts/UserUtils.java
new file mode 100644
index 0000000..b42ab8d
--- /dev/null
+++ b/src/com/android/providers/contacts/UserUtils.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2014 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.providers.contacts;
+
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserManager;
+import android.util.Log;
+
+public final class UserUtils {
+ public static final String TAG = ContactsProvider2.TAG;
+
+ public static final boolean VERBOSE_LOGGING = Log.isLoggable(TAG, Log.VERBOSE);
+
+ private UserUtils() {
+ }
+
+ private static UserManager getUserManager(Context context) {
+ return (UserManager) context.getSystemService(Context.USER_SERVICE);
+ }
+
+ public static int getCurrentUserHandle(Context context) {
+ return getUserManager(context).getUserHandle();
+ }
+
+ /**
+ * @return the user ID of the enterprise user that is linked to the current user, if any.
+ * If there's no such user, returns -1.
+ *
+ * STOPSHIP: Have amith look at it.
+ */
+ public static int getEnterpriseUserId(Context context) {
+ final UserManager um = getUserManager(context);
+ final int currentUser = um.getUserHandle();
+
+ if (VERBOSE_LOGGING) {
+ Log.v(TAG, "getEnterpriseUserId: current=" + currentUser);
+ }
+
+ // TODO: Skip if the current is not the primary user?
+
+ // Check each user.
+ for (UserInfo ui : um.getUsers()) {
+ if (!ui.isManagedProfile()) {
+ continue; // Not a managed user.
+ }
+ final UserInfo parent = um.getProfileParent(ui.id);
+ if (parent == null) {
+ continue; // No parent.
+ }
+ // Check if it's linked to the current user.
+ if (um.getProfileParent(ui.id).id == currentUser) {
+ if (VERBOSE_LOGGING) {
+ Log.v(TAG, "Corp user=" + ui.id);
+ }
+ return ui.id;
+ }
+ }
+ if (VERBOSE_LOGGING) {
+ Log.v(TAG, "Corp user not found.");
+ }
+ return -1;
+ }
+}