From 7cb4d694f03379657f9de1b7e23f48f934d23245 Mon Sep 17 00:00:00 2001 From: Grace Jia Date: Wed, 16 Sep 2020 16:01:52 -0700 Subject: Fix selecting phone account dialog show error. AOSP dialer used to ignore UserHandle of a PhoneAccountHandle when building the selection list. When secondary user or guest mode is in use, dialer composed a wrong PhoneAccountHandle with current UserHandle so Telecom cannot provide correct information of this PhoneAccountHandle. Bug: 157499347 Test: Manually switch to guest mode or secondary user to check if the dialog show correctly. Change-Id: I8a9f9bcf5192f69ca270def48fb850106aa717fb --- .../SelectPhoneAccountDialogOptionsUtil.java | 24 +++++++++++++++++++++- .../select_phone_account_dialog_options.proto | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'java/com/android/contacts/common') diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java index 5a44ae7f8..1880d6538 100644 --- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java +++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java @@ -16,9 +16,15 @@ package com.android.contacts.common.widget; +import android.os.Parcel; +import android.os.UserHandle; +import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import com.android.dialer.common.Assert; import com.android.dialer.telecom.TelecomUtil; + +import com.google.protobuf.ByteString; + import java.util.Collection; /** Provides common operation on a {@link SelectPhoneAccountDialogOptions} */ @@ -27,9 +33,21 @@ public final class SelectPhoneAccountDialogOptionsUtil { public static PhoneAccountHandle getPhoneAccountHandle( SelectPhoneAccountDialogOptions.Entry entry) { + UserHandle userHandle; + Parcel parcel = Parcel.obtain(); + try { + byte[] marshalledUserHandle = entry.getUserHandle().toByteArray(); + parcel.unmarshall(marshalledUserHandle, 0, marshalledUserHandle.length); + parcel.setDataPosition(0); + userHandle = parcel.readParcelable(UserHandle.class.getClassLoader()); + } catch (NullPointerException e) { + userHandle = null; + } + parcel.recycle(); return Assert.isNotNull( TelecomUtil.composePhoneAccountHandle( - entry.getPhoneAccountHandleComponentName(), entry.getPhoneAccountHandleId())); + entry.getPhoneAccountHandleComponentName(), entry.getPhoneAccountHandleId(), + userHandle)); } public static SelectPhoneAccountDialogOptions.Entry.Builder setPhoneAccountHandle( @@ -38,6 +56,10 @@ public final class SelectPhoneAccountDialogOptionsUtil { entryBuilder.setPhoneAccountHandleComponentName( phoneAccountHandle.getComponentName().flattenToString()); entryBuilder.setPhoneAccountHandleId(phoneAccountHandle.getId()); + Parcel parcel = Parcel.obtain(); + parcel.writeParcelable(phoneAccountHandle.getUserHandle(), 0); + entryBuilder.setUserHandle(ByteString.copyFrom(parcel.marshall())); + parcel.recycle(); return entryBuilder; } diff --git a/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto b/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto index f96e31f2e..fc443f0cd 100644 --- a/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto +++ b/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto @@ -49,5 +49,7 @@ message SelectPhoneAccountDialogOptions { // in a call so the other SIM cannot be used. Hint should also be set to // inform the user why the account is unavailable. optional bool enabled = 4 [default = true]; + + optional bytes user_handle = 5; } } \ No newline at end of file -- cgit v1.2.3