1.问题:修改多用户中机主的图标,刷机生效了,但是OTA升级没生效。
2.具体描述
直接替换的资源:/frameworks/base/core/res/res/drawable/ic_account_circle.xml
刷机是OK的;未修改之前的版本差分升级到修改后的版本的framework-res.apk,和直接刷机到修改后的版本的framework-res.apk,
反编译后,ic_account_circle.xml是一样的,说明ota以后资源已经更新了,但是显示效果并没有生效。
3.分析
由于刷机是OK的,工厂复位也是OK的,只有OTA没有生效,怀疑是缓存的原因;但是重启/清除framework-res.apk缓存依旧问题;
最开始应用同事给出的反馈是他们调用的UserIcons.getDefaultUserIcon()接口,查看这个接口也没有看出异常以及缓存:
public static Drawable getDefaultUserIcon(Resources resources, int userId, boolean light) {
int colorResId = light ? R.color.user_icon_default_white : R.color.user_icon_default_gray;
if (userId != UserHandle.USER_NULL) {
// Return colored icon instead
colorResId = USER_ICON_COLORS[userId % USER_ICON_COLORS.length];
}
Drawable icon = resources.getDrawable(R.drawable.ic_account_circle, null).mutate();
icon.setColorFilter(resources.getColor(colorResId, null), Mode.SRC_IN);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
return icon;
}
通过分析UMS,看到系统有setUserIcon:
@Override
public void setUserIcon(int userId, Bitmap bitmap) {
long ident = Binder.clearCallingIdentity();
try {
synchronized (mPackagesLock) {
UserData userData = getUserDataNoChecks(userId);
if (userData == null || userData.info.partial) {
Slog.w(LOG_TAG, "setUserIcon: unknown user #" + userId);
return;
}
writeBitmapLP(userData.info, bitmap);//图标会保存在/data/system/user/[USER_ID]/photo.png
writeUserLP(userData);
}
sendUserInfoChangedBroadcast(userId);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
然后在/data/system/user/[USER_ID]/photo.png 查看这个图标,发现是没有变的(肯定也是不会变,因为属于用户数据,OTA升级不会改变用户数据)。
那通过接口getUserIcon得到图标就肯定也是没有改变的。
查看SytemUI及Settings代码,它们就是使用的getUserIcon接口获取的图标。
4.总结
多用户图标是个可以设置的,是属于用户数据,在用户创建之初用到了系统默认的图标,后续用户可设置新图标;
这个图标会保存在/data/system/user/[USER_ID]/photo.png
这个图片属于用户数据,不会随OTA升级而改变,只有重新创建新用户后,新用户才会用到新的默认图标。



