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

Commit 112be202 authored by kaiyiz's avatar kaiyiz
Browse files

Settings: If there's no photo for user, set a default photo

The user photo that has been stored in the xml file isn't
updated when we detele the user profile. So it can be
retrived always.

Use the default photo to replace it when delete the user.

CRs-Fixed: 745990

Change-Id: I782f6272d229651d57556355c15218d7ed9ca755
parent bfb0f7a3
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -20,10 +20,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.ContactsContract.CommonDataKinds.Phone;

import com.android.internal.util.UserIcons;
import com.android.settings.Utils;


@@ -39,12 +41,21 @@ public class ProfileUpdateReceiver extends BroadcastReceiver {
        // Profile changed, lets get the photo and write to user manager
        new Thread() {
            public void run() {
                Utils.copyMeProfilePhoto(context, null);
                if (!Utils.copyMeProfilePhoto(context, null)) {
                    assignDefaultPhoto(context, UserHandle.myUserId());
                }
                copyProfileName(context);
            }
        }.start();
    }

    public static void assignDefaultPhoto(Context context, int userId) {
        Bitmap bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId,
                /* light= */ false));
        UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        um.setUserIcon(userId, bitmap);
    }

    static void copyProfileName(Context context) {
        SharedPreferences prefs = context.getSharedPreferences("profile", Context.MODE_PRIVATE);
        if (prefs.contains(KEY_PROFILE_NAME_COPIED_ONCE)) {