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

Commit 891a597b authored by Danesh Mondegarian's avatar Danesh Mondegarian Committed by Steve Kondik
Browse files

UserTile : Check if profile has a photo

In the event that the profile doesn't have a photo, don't default to the
user's photo, instead show a default avatar.

Change-Id: I80de324ae1e151693cf3716bf87d39a16096ca12
parent 7be77f9e
Loading
Loading
Loading
Loading
+26 −5
Original line number Diff line number Diff line
package com.android.systemui.quicksettings;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import android.app.ActivityManagerNative;
import android.content.Context;
import android.content.Intent;
@@ -7,8 +11,10 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -128,17 +134,19 @@ public class UserTile extends QuickSettingsTile {

                String name = null;
                Drawable avatar = null;
                String id = null;
                // 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_RAW_CONTACTS_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
                            RawContacts.DELETED + "=0", null, null);
                            Profile.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
                            null, null, null);
                    if (cursor != null) {
                        try {
                            if (cursor.moveToFirst()) {
                                name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
                                id = cursor.getString(cursor.getColumnIndex(Phone._ID));
                            }
                        } finally {
                            cursor.close();
@@ -149,11 +157,24 @@ public class UserTile extends QuickSettingsTile {
                            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) {
                            Bitmap rawAvatar = null;
                            InputStream is = null;
                            try {
                                Uri.Builder uriBuilder = ContactsContract.RawContacts.CONTENT_URI.buildUpon();
                                uriBuilder.appendPath(id);
                                uriBuilder.appendPath(Contacts.Photo.DISPLAY_PHOTO);
                                is = mContext.getContentResolver().openInputStream(uriBuilder.build());
                                rawAvatar = BitmapFactory.decodeStream(is);
                                avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
                            } else {
                            } catch (FileNotFoundException e) {
                                avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
                            } finally {
                                if (is != null) {
                                    try {
                                        is.close();
                                    } catch (IOException e) {
                                    }
                                }
                            }
                        }
                    }