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

Commit 7a6355b6 authored by Winson Chung's avatar Winson Chung
Browse files

Fixing issue where Quick Settings user profile was not showing name or default...

Fixing issue where Quick Settings user profile was not showing name or default picture. (Bug 7308719)

Change-Id: Idbaf377d1cd086cf5d8244d6c7ca084145ccf217
parent 6f2cdcdb
Loading
Loading
Loading
Loading
+28 −22
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ class QuickSettings {
    private int mBrightnessDialogShortTimeout;
    private int mBrightnessDialogLongTimeout;

    private AsyncTask<Void, Void, Pair<String, BitmapDrawable>> mUserInfoTask;
    private AsyncTask<Void, Void, Pair<String, Drawable>> mUserInfoTask;

    private LevelListDrawable mBatteryLevels;
    private LevelListDrawable mChargingBatteryLevels;
@@ -203,19 +203,29 @@ class QuickSettings {
        final int userId = userInfo.id;

        final Context context = currentUserContext;
        mUserInfoTask = new AsyncTask<Void, Void, Pair<String, BitmapDrawable>>() {
        mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
            @Override
            protected Pair<String, BitmapDrawable> doInBackground(Void... params) {
                Cursor cursor = context.getContentResolver().query(
            protected Pair<String, Drawable> doInBackground(Void... params) {
                final Cursor cursor = context.getContentResolver().query(
                        Profile.CONTENT_URI, new String[] {Phone._ID, Phone.DISPLAY_NAME},
                        null, null, null);
                final UserManager um =
                        (UserManager) mContext.getSystemService(Context.USER_SERVICE);

                if (cursor == null) {
                    // Info not available. Should become available later.
                    return new Pair<String, BitmapDrawable>(null, null);
                // Fall back to the UserManager nickname if we can't read the name from the local
                // profile below.
                String nickName = um.getUserName();
                String name = nickName;
                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);
                }

                String name = null;
                // Try and read the display name from the local profile
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
@@ -223,15 +233,13 @@ class QuickSettings {
                    } finally {
                        cursor.close();
                    }
                final UserManager userManager =
                    (UserManager) mContext.getSystemService(Context.USER_SERVICE);
                final BitmapDrawable icon = new BitmapDrawable(mContext.getResources(),
                        userManager.getUserIcon(userId));
                return new Pair<String, BitmapDrawable>(name, icon);
                }

                return new Pair<String, Drawable>(name, avatar);
            }

            @Override
            protected void onPostExecute(Pair<String, BitmapDrawable> result) {
            protected void onPostExecute(Pair<String, Drawable> result) {
                super.onPostExecute(result);
                mModel.setUserTileInfo(result.first, result.second);
                mUserInfoTask = null;
@@ -305,9 +313,7 @@ class QuickSettings {
                ImageView iv = (ImageView) view.findViewById(R.id.user_imageview);
                TextView tv = (TextView) view.findViewById(R.id.user_textview);
                tv.setText(state.label);
                if (us.avatar != null) {
                iv.setImageDrawable(us.avatar);
                }
                view.setContentDescription(mContext.getString(
                        R.string.accessibility_quick_settings_user, state.label));
            }