@@ -202,21 +202,18 @@ private void queryForUserInformation() {
202202 Log .e (TAG , "Couldn't get user info" , e );
203203 }
204204 final int userId = userInfo .id ;
205+ final String userName = userInfo .name ;
205206
206207 final Context context = currentUserContext ;
207208 mUserInfoTask = new AsyncTask <Void , Void , Pair <String , Drawable >>() {
208209 @ Override
209210 protected Pair <String , Drawable > doInBackground (Void ... params ) {
210- final Cursor cursor = context .getContentResolver ().query (
211- Profile .CONTENT_URI , new String [] {Phone ._ID , Phone .DISPLAY_NAME },
212- null , null , null );
213211 final UserManager um =
214212 (UserManager ) mContext .getSystemService (Context .USER_SERVICE );
215213
216214 // Fall back to the UserManager nickname if we can't read the name from the local
217215 // profile below.
218- String nickName = um .getUserName ();
219- String name = nickName ;
216+ String name = userName ;
220217 Drawable avatar = null ;
221218 Bitmap rawAvatar = um .getUserIcon (userId );
222219 if (rawAvatar != null ) {
@@ -225,17 +222,23 @@ protected Pair<String, Drawable> doInBackground(Void... params) {
225222 avatar = mContext .getResources ().getDrawable (R .drawable .ic_qs_default_user );
226223 }
227224
228- // Try and read the display name from the local profile
229- if (cursor != null ) {
230- try {
231- if (cursor .moveToFirst ()) {
232- name = cursor .getString (cursor .getColumnIndex (Phone .DISPLAY_NAME ));
225+ // If it's a single-user device, get the profile name, since the nickname is not
226+ // usually valid
227+ if (um .getUsers ().size () <= 1 ) {
228+ // Try and read the display name from the local profile
229+ final Cursor cursor = context .getContentResolver ().query (
230+ Profile .CONTENT_URI , new String [] {Phone ._ID , Phone .DISPLAY_NAME },
231+ null , null , null );
232+ if (cursor != null ) {
233+ try {
234+ if (cursor .moveToFirst ()) {
235+ name = cursor .getString (cursor .getColumnIndex (Phone .DISPLAY_NAME ));
236+ }
237+ } finally {
238+ cursor .close ();
233239 }
234- } finally {
235- cursor .close ();
236240 }
237241 }
238-
239242 return new Pair <String , Drawable >(name , avatar );
240243 }
241244
0 commit comments