Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89ab0eb0 authored by Ethan Chen's avatar Ethan Chen Committed by Steve Kondik
Browse files

Show default profile name if no profile exists

Change-Id: I6b651d6b552ab3caf30102d289469eaf68f58a0e
parent aa04429b
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Profile;
import android.util.Log;
@@ -125,24 +126,15 @@ public class UserTile extends QuickSettingsTile {
                final UserManager um =
                        (UserManager) mContext.getSystemService(Context.USER_SERVICE);

                // Fall back to the UserManager nickname if we can't read the name from the local
                // profile below.
                String name = userName;
                String name = null;
                Drawable avatar = null;
                Bitmap rawAvatar = um.getUserIcon(userId);
                if (rawAvatar != null) {
                    avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
                } else {
                    avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
                }

                // If it's a single-user device, get the profile name, since the nickname is not
                // usually valid
                if (um.getUsers().size() <= 1) {
                    // Try and read the display name from the local profile
                    final Cursor cursor = context.getContentResolver().query(
                            Profile.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
                            null, null, null);
                            Profile.CONTENT_RAW_CONTACTS_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
                            RawContacts.DELETED + "=0", null, null);
                    if (cursor != null) {
                        try {
                            if (cursor.moveToFirst()) {
@@ -151,6 +143,19 @@ public class UserTile extends QuickSettingsTile {
                        } finally {
                            cursor.close();
                        }
                        // Fall back to the UserManager nickname if we can't read the name from the local
                        // profile below.
                        if (name == null) {
                            avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
                            name = mContext.getResources().getString(com.android.internal.R.string.owner_name);
                        } else {
                            Bitmap rawAvatar = um.getUserIcon(userId);
                            if (rawAvatar != null) {
                                avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
                            } else {
                                avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
                            }
                        }
                    }
                }
                return new Pair<String, Drawable>(name, avatar);