概述
Profile User用户创建成功后,只会在桌面显示寥寥几个应用的图标,而不是所有系统应用;在原生的系统上,profile user创建成功后,会在桌面显示两个profile user应用的图标
场景一:Profile User初次创建成功后,桌面图标显示##
以下以电子邮件应用为例,看下创建Profile user用户后,桌面图标显示的场景
Profile_user_icon
以下调用栈,表示,在Profile User启动后,该应用监听监听了ACTION_BOOT_COMPLETED广播,然后调用setComponentEnabledSetting去启用某些组件
调用栈信息
03-07 07:21:06.626 4982 5168 D user : java.lang.Throwable
03-07 07:21:06.626 4982 5168 D user : at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:2326)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.service.EmailServiceUtils.setComponentStatus(EmailServiceUtils.java:793)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.service.EmailServiceUtils.enableExchangeComponent(EmailServiceUtils.java:812)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.provider.AccountReconciler.reconcileAccountsInternal(AccountReconciler.java:211)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.provider.AccountReconciler.reconcileAccounts(AccountReconciler.java:146)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.service.EmailBroadcastProcessorService.reconcileAndStartServices(EmailBroadcastProcessorService.java:371)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.service.EmailBroadcastProcessorService.onBootCompleted(EmailBroadcastProcessorService.java:352)
03-07 07:21:06.626 4982 5168 D user : at com.android.email.service.EmailBroadcastProcessorService.onHandleIntent(EmailBroadcastProcessorService.java:159)
03-07 07:21:06.626 4982 5168 D user : at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
03-07 07:21:06.626 4982 5168 D user : at android.os.Handler.dispatchMessage(Handler.java:106)
03-07 07:21:06.626 4982 5168 D user : at android.os.Looper.loop(Looper.java:193)
03-07 07:21:06.626 4982 5168 D user : at android.os.HandlerThread.run(HandlerThread.java:65)
enableExchangeComponent
public static void enableExchangeComponent(final Context context) {
if (VendorPolicyLoader.getInstance(context).useAlternateExchangeStrings()) {
LogUtils.d(LogUtils.TAG, "Enabling alternate EAS authenticator");
setComponentStatus(context, EasAuthenticatorServiceAlternate.class, true);
setComponentStatus(context, EasAuthenticatorService.class, false);
} else {
LogUtils.d(LogUtils.TAG, "Enabling EAS authenticator");
setComponentStatus(context, EasAuthenticatorService.class, true);
setComponentStatus(context,
EasAuthenticatorServiceAlternate.class, false);
}
}
@Override
public void setComponentEnabledSetting(ComponentName componentName,int newState, int flags) {
try {
mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());//传递当前应用进程所在的userid,到pms
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
从广播发送到桌面去更新桌面图标的流程如下:
禁用或者使能组件流程
流程描述如下:
Profile User创建成功后,发送ACTION_BOOT_COMPLETED广播
电子邮件应用,接收ACTION_BOOT_COMPLETED广播,调用PMS#setComponentEnabledSetting去使能相关组件服务
PMS处理相关逻辑,使能相关组件服务后,发送ACTION_PACKAGE_CHANGED广播,回调IOnAppsChangeListener的onPacakgeChange方法
因为桌面注册了IOnAppsChangeListener监听,因此能够监听到改pacakgeChange变化,更新对应用户的桌面图标变化
桌面使用的注册监听的接口
LauncherApps.java
public void registerCallback(Callback callback, Handler handler) {
synchronized (this) {
if (callback != null && findCallbackLocked(callback) < 0) {
boolean addedFirstCallback = mCallbacks.size() == 0;
addCallbackLocked(callback, handler);
if (addedFirstCallback) {
try {
mService.addOnAppsChangedListener(mContext.getPackageName(),
mAppsChangedListener);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
}
}
}
最后
以上就是害羞水蜜桃为你收集整理的android 多用户 图库,Android9.x多用户机制#Profile user 桌面图标显示过程的全部内容,希望文章能够帮你解决android 多用户 图库,Android9.x多用户机制#Profile user 桌面图标显示过程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复