Android 8.1 多个launcher设置桌面always,重启设备还是会出现选择默认桌面框

最近给客户发样机几十台,测试同学手动操作安装了一个launcher,并设置默认launcher Always,然后重启设备发现概率性设置无效,还是会出现选择launcher弹框。但是我同样操作并没有复现问题,去和测试沟通,发现他们操作特别快,所以怀疑是否是设置后太快重启导致的设置失败,查看代码发现果真如此。下面是看到一篇别人写的文章,原文地址见文末:

  1. 设置默认桌面后,马上重启,有时出现无效,是因为设置后会延时10s才会将设置到结果保存到文件中。如下所示:

  2. public void addPreferredActivity(IntentFilter filter, int match,

  3. ComponentName[] set, ComponentName activity, int userId) {

  4. addPreferredActivityInternal(filter, match, set, activity, true, userId,

  5. "Adding preferred");

  6. }

  7.  
  8. private void addPreferredActivityInternal(IntentFilter filter, int match,

  9. ComponentName[] set, ComponentName activity, boolean always, int userId,

  10. String opname) {

  11. // writer

  12. int callingUid = Binder.getCallingUid();

  13. enforceCrossUserPermission(callingUid, userId, true, false, "add preferred activity");

  14. if (filter.countActions() == 0) {

  15. Slog.w(TAG, "Cannot set a preferred activity with no filter actions");

  16. return;

  17. }

  18. synchronized (mPackages) {

  19. if (mContext.checkCallingOrSelfPermission(

  20. android.Manifest.permission.SET_PREFERRED_APPLICATIONS)

  21. != PackageManager.PERMISSION_GRANTED) {

  22. if (getUidTargetSdkVersionLockedLPr(callingUid)

  23. < Build.VERSION_CODES.FROYO) {

  24. Slog.w(TAG, "Ignoring addPreferredActivity() from uid "

  25. + callingUid);

  26. return;

  27. }

  28. mContext.enforceCallingOrSelfPermission(

  29. android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);

  30. }

  31.  
  32. PreferredIntentResolver pir = mSettings.editPreferredActivitiesLPw(userId);

  33. Slog.i(TAG, opname + " activity " + activity.flattenToShortString() + " for user "

  34. + userId + ":");

  35. filter.dump(new LogPrinter(Log.INFO, TAG), " ");

  36. pir.addFilter(new PreferredActivity(filter, match, set, activity, always));

  37. scheduleWritePackageRestrictionsLocked(userId);//保存到data/system/users/0/package-restrictions.xml文件中

  38. }

  39. }

//10s后写入问题

 
  1. void scheduleWritePackageRestrictionsLocked(int userId) {

  2. if (!sUserManager.exists(userId)) return;

  3. mDirtyUsers.add(userId);

  4. if (!mHandler.hasMessages(WRITE_PACKAGE_RESTRICTIONS)) {

  5. mHandler.sendEmptyMessageDelayed(WRITE_PACKAGE_RESTRICTIONS, WRITE_SETTINGS_DELAY);//WRITE_SETTINGS_DELAY = 10*1000;

  6. }

  7. }

//写入data/system/users/0/package-restrictions.xml文件中

 
  1. case WRITE_PACKAGE_RESTRICTIONS: {

  2. Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);

  3. synchronized (mPackages) {

  4. removeMessages(WRITE_PACKAGE_RESTRICTIONS);

  5. for (int userId : mDirtyUsers) {

  6. mSettings.writePackageRestrictionsLPr(userId);

  7. }

  8. mDirtyUsers.clear();

  9. }

  10. Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

  11. } break;

原文地址:https://blog.csdn.net/u010867436/article/details/85050942

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值