当前位置:网站首页>User 10 must be unlocked for widgets to be available
User 10 must be unlocked for widgets to be available
2022-06-08 23:50:00 【Connivance_ Beautiful shadow】
Reference article :
https://blog.csdn.net/weixin_31786973/article/details/117552325
https://blog.csdn.net/w1070216393/article/details/72722759
The problem background :
Android 12 In the customer project , When switching visitors ,launcher Probability occurrence crash.
Problem analysis
crash log:
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.tblenovo.launcher, PID: 13963
E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{
com.tblenovo.launcher/com.android.searchlauncher.SearchLauncher}: java.lang.RuntimeException: java.lang.IllegalStateException: User 10 must be unlocked for widgets to be available
E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3678)
E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3835)
E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5780)
E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5672)
E AndroidRuntime: at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
E AndroidRuntime: at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2248)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7883)
E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
E AndroidRuntime: Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: User 10 must be unlocked for widgets to be available
E AndroidRuntime: at com.android.launcher3.widget.LauncherAppWidgetHost.startListening(LauncherAppWidgetHost.java:115)
E AndroidRuntime: at com.android.launcher3.Launcher.onCreate(Launcher.java:790)
E AndroidRuntime: at com.android.launcher3.BaseQuickstepLauncher.onCreate(BaseQuickstepLauncher.java:124)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8334)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8314)
E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3649)
E AndroidRuntime: ... 15 more
E AndroidRuntime: Caused by: java.lang.IllegalStateException: User 10 must be unlocked for widgets to be available
E AndroidRuntime: at android.os.Parcel.createExceptionOrNull(Parcel.java:2463)
E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2439)
E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2422)
E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2364)
E AndroidRuntime: at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.startListening(IAppWidgetService.java:784)
E AndroidRuntime: at android.appwidget.AppWidgetHost.startListening(AppWidgetHost.java:222)
E AndroidRuntime: at com.android.launcher3.widget.LauncherAppWidgetHost.startListening(LauncherAppWidgetHost.java:112)
E AndroidRuntime: ... 21 more
Obviously crash yes Launcher onCreate Called when LauncherAppWidgetHost.startListening, Underlayer occurrence crash.
User 10 must be unlocked for widgets to be available
this log stay framework/base below AppWidgetServiceImpl.java in
private void ensureGroupStateLoadedLocked(int userId, boolean enforceUserUnlockingOrUnlocked) {
if (enforceUserUnlockingOrUnlocked && !isUserRunningAndUnlocked(userId)) {
throw new IllegalStateException(
"User " + userId + " must be unlocked for widgets to be available");
}
if (enforceUserUnlockingOrUnlocked && isProfileWithLockedParent(userId)) {
throw new IllegalStateException(
"Profile " + userId + " must have unlocked parent");
}
}
Log The prompt message is because the device has not been unlocked , To refresh widget Cause this problem .
Android 7.0 Introduced Direct Boot Pattern , When the phone is powered on but the user does not have the unlock lock screen ,Android N Run in a safe mode , That is to say Dierect Boot Pattern .
That is, you can't update it at this time widget. If launcher Advance loading , This place needs special treatment .
Solution
stay LauncherAppWidgetHost.startListening Add judgement , If not unlocked , Then no relevant processing will be carried out , Execute after unlocking .
private static final int FLAG_UNLOCK_DELAY_LISTENING = 1 << 4;
...
// Add unlock listening , Judge whether to execute corresponding logic after unlocking startListening
screenListener = new ScreenListener(mContext);
screenListener.begin(new ScreenListener.ScreenStateListener() {
@Override
public void onUserPresent() {
if (isUnlockDelayListening()){
startListening();
}
mFlags &= ~FLAG_UNLOCK_DELAY_LISTENING;
}
});
...
@Override
public void startListening() {
if (WidgetsModel.GO_DISABLE_WIDGETS) {
return;
}
final int userId = UserHandle.myUserId();
// Determine whether to unlock , If not unlocked , Update flag bit , Unlock and execute .
Log.d(TAG,"startListening# userId: "+userId);
if(!StorageManager.isUserKeyUnlocked(userId)){
mFlags |= FLAG_UNLOCK_DELAY_LISTENING;
return;
}else{
mFlags &= ~FLAG_UNLOCK_DELAY_LISTENING;
}
mFlags |= FLAG_LISTENING;
try {
super.startListening();
} catch (Exception e) {
if (!Utilities.isBinderSizeError(e)) {
throw new RuntimeException(e);
}
// We're willing to let this slide. The exception is being caused by the list of
// RemoteViews which is being passed back. The startListening relationship will
// have been established by this point, and we will end up populating the
// widgets upon bind anyway. See issue 14255011 for more context.
}
// We go in reverse order and inflate any deferred widget
for (int i = mViews.size() - 1; i >= 0; i--) {
LauncherAppWidgetHostView view = mViews.valueAt(i);
if (view instanceof DeferredAppWidgetHostView) {
view.reInflate();
}
}
}
crash log 2
After solving the above problems , The test again , There are other places crash problem . Error reporting is still User 10 must be unlocked for widgets to be available.
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.tblenovo.launcher, PID: 15694
E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{
com.tblenovo.launcher/com.android.searchlauncher.SearchLauncher}: java.lang.IllegalStateException: User 10 must be unlocked for widgets to be available
E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3678)
E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3835)
E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5780)
E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5672)
E AndroidRuntime: at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71)
E AndroidRuntime: at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2248)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7883)
E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
E AndroidRuntime: Caused by: java.lang.IllegalStateException: User 10 must be unlocked for widgets to be available
E AndroidRuntime: at android.os.Parcel.createExceptionOrNull(Parcel.java:2463)
E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2439)
E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2422)
E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2364)
E AndroidRuntime: at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.getAppWidgetInfo(IAppWidgetService.java:1240)
E AndroidRuntime: at android.appwidget.AppWidgetManager.getAppWidgetInfo(AppWidgetManager.java:909)
E AndroidRuntime: at com.android.launcher3.widget.WidgetManagerHelper.getLauncherAppWidgetInfo(WidgetManagerHelper.java:64)
E AndroidRuntime: at com.android.launcher3.Launcher.inflateAppWidget(Launcher.java:3184)
E AndroidRuntime: at com.android.launcher3.Launcher.bindItems(Launcher.java:3048)
E AndroidRuntime: at com.android.launcher3.Launcher.bindItems(Launcher.java:2999)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder.lambda$bindAppWidgets$8(BaseLoaderResults.java:258)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder$$ExternalSyntheticLambda4.execute(Unknown Source:2)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder.lambda$executeCallbacksTask$9$com-android-launcher3-model-BaseLoaderResults$WorkspaceBinder(BaseLoaderResults.java:268)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder$$ExternalSyntheticLambda8.run(Unknown Source:4)
E AndroidRuntime: at com.android.launcher3.util.LooperExecutor.execute(LooperExecutor.java:45)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder.executeCallbacksTask(BaseLoaderResults.java:263)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder.bindAppWidgets(BaseLoaderResults.java:257)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder.bind(BaseLoaderResults.java:205)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults$WorkspaceBinder.access$000(BaseLoaderResults.java:128)
E AndroidRuntime: at com.android.launcher3.model.BaseLoaderResults.bindWorkspace(BaseLoaderResults.java:92)
E AndroidRuntime: at com.android.launcher3.LauncherModel.startLoader(LauncherModel.java:391)
E AndroidRuntime: at com.android.launcher3.LauncherModel.addCallbacksAndLoad(LauncherModel.java:352)
E AndroidRuntime: at com.android.launcher3.Launcher.onCreate(Launcher.java:817)
E AndroidRuntime: at com.android.launcher3.BaseQuickstepLauncher.onCreate(BaseQuickstepLauncher.java:124)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8334)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8314)
E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
log analysis :
Launcher.inflateAppWidget fill widget Information , An error is reported when calling the underlying method .
The solution is the same as above .
stay LauncherModel.startLoader in ,bindWorkspace Go ahead and judge .
public boolean startLoader() {
// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
ItemInstallQueue.INSTANCE.get(mApp.getContext())
.pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
synchronized (mLock) {
// Don't bother to start the thread if we know it's not going to do anything
final Callbacks[] callbacksList = getCallbacks();
if (callbacksList.length > 0) {
// Clear any pending bind-runnables from the synchronized load process.
for (Callbacks cb : callbacksList) {
MAIN_EXECUTOR.execute(cb::clearPendingBinds);
}
// If there is already one running, tell it to stop.
stopLoader();
LoaderResults loaderResults = new LoaderResults(
mApp, mBgDataModel, mBgAllAppsList, callbacksList);
final int userId = UserHandle.myUserId();
isUserRunningAndUnlocked = UserCache.INSTANCE.get(mApp.getContext()).isUserRunningAndUnlocked(userId);
Log.d(TAG,"startLoader# userId: "+userId + " isUserRunningAndUnlocked: "+isUserRunningAndUnlocked);
if (isUserRunningAndUnlocked){
// Add judgement , If not unlocked , Do not deal with , Don't start bind Desktop icons and widget
if (mModelLoaded && !mIsLoaderTaskRunning) {
// Divide the set of loaded items into those that we are binding synchronously,
// and everything else that is to be bound normally (asynchronously).
loaderResults.bindWorkspace();
// For now, continue posting the binding of AllApps as there are other
// issues that arise from that.
loaderResults.bindAllApps();
loaderResults.bindDeepShortcuts();
loaderResults.bindWidgets();
return true;
} else {
startLoaderForResults(loaderResults);
}
}
}
}
return false;
}
public void validateModelDataOnResume() {
MODEL_EXECUTOR.getHandler().removeCallbacks(mDataValidationCheck);
MODEL_EXECUTOR.post(mDataValidationCheck);
final int userId = UserHandle.myUserId();
boolean isUserRunningAndUnlocked = UserCache.INSTANCE.get(mApp.getContext()).isUserRunningAndUnlocked(userId);
Log.d(TAG,"validateModelDataOnResume# userId: "+userId + " isUserRunningAndUnlocked: "+isUserRunningAndUnlocked + " this.isUserRunningAndUnlocked: "+this.isUserRunningAndUnlocked+" mLoaderTask "+mLoaderTask);
if (!this.isUserRunningAndUnlocked && isUserRunningAndUnlocked){
//onResume When , Judgment flags ,rebind
Log.d(TAG,"validateModelDataOnResume isUserRunningAndUnlocked# widget not bind,need reload ");
rebindCallbacks();
}
}
To this , At present, no other problems are found in the self-test crash. If there are similar errors reported in other places , Just do the same .
Follow up summary
The problem is because launcher Load too early , Give Way launcher stay Direct Boot mode , Advance call widget Related methods lead to .
need launcher Do it yourself widget Related logic .
边栏推荐
- Deployment (12): testing disk performance
- [high concurrency] the life cycle of threads is not as simple as we think!!
- Zcmu--1775: sequence of XX (C language)
- 最大子段问题
- 小黑舔一口尝尝torchText
- LeetCode-1809. A series without advertising
- User 10 must be unlocked for widgets to be available
- 云原生技术---高可用etcd数据库集群搭建
- 滑环在全自动口罩机设备中的运用
- shell(30) : yum导出依赖包并离线安装
猜你喜欢
随机推荐
Digital IC Design - makefile script (example)
环境配置问题
AHB_ SRAM_ TB test file
良好的编程风格(习惯)
Day07/08/09 depth first search and breadth first search
Build step ‘Execute shell’ marked build as failure
The epigentek second generation sequencing boxes with their own characteristics!
New technology (1): 2021
MVC模式 &三层架构思想完成增删改查.
selenium By的8种定位方式
Non-constant range: argument must be an integer literal
Required course for network engineer, detailed explanation of DHCP principle, and required course for job interview
表单标签
使用Tensorflow实现EfficientNetV2-S结构
fastlane build 版本号自增
CF1505C Fibonacci Words
[high concurrency] the life cycle of threads is not as simple as we think!!
Leetcode 349 两个数组的交集 ( Intersection of Two Arrays *Easy* ) 题解分析
[untitled]
实体、协议、服务和服务访问点








