Android 11 在重启的时候清除最近任务缓存
前言
在进行frameworks定制开发的时候,客户提出需要在重启时候将最近任务的缓存,全部清除掉,每次重新加载app进程。
一、问题解决
1.定位问题
客户提出需要在重启时候将最近任务的缓存,全部清除掉,每次重新加载app进程。经过查看得知在桌面的最近任务内有个全部清除的按钮,最终敲定在开机时接受开机广播,然后进行模拟按钮的点击时间。最终发现按钮是在加载在launcher3中,在我们点击最近任务加载的的时候会自动走我们新增的点击全部清除的流程,解决办法如下
2.解决问题
路径:
android/packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
通过查看RecentsView.java的代码发现在RecentsView(),实例化了这个按钮.
public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setPageSpacing(getResources().getDimensionPixelSize(R.dimen.recents_page_spacing));
setEnableFreeScroll(true);
mFastFlingVelocity = getResources()
.getDimensionPixelSize(R.dimen.recents_fast_fling_velocity);
mActivity = (T) BaseActivity.fromContext(context);
mModel = RecentsModel.INSTANCE.get(context);
mIdp = InvariantDeviceProfile.INSTANCE.get(context);
mTempClipAnimationHelper = new ClipAnimationHelper(context);
mClearAllButton = (ClearAllButton) LayoutInflater.from(context)
.inflate(R.layout.overview_clear_all_button, this, false);// 实例化全部清楚按钮
mClearAllButton.setOnClickListener(this::dismissAllTasks); // 设置点击事件
mTaskViewPool = new ViewPool<>(context, this, R.layout.task, 20 /* max size */,
10 /* initial size */);
mIsRtl = !Utilities.isRtl(getResources());
setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
mTaskTopMargin = getResources()
.getDimensionPixelSize(R.dimen.task_thumbnail_top_margin);
mSquaredTouchSlop = squaredTouchSlop(context);
mEmptyIcon = context.getDrawable(R.drawable.ic_empty_recents);
mEmptyIcon.setCallback(this);
mEmptyMessage = context.getText(R.string.recents_empty_message);
mEmptyMessagePaint = new TextPaint();
mEmptyMessagePaint.setColor(Themes.getAttrColor(context, android.R.attr.textColorPrimary));
mEmptyMessagePaint.setTextSize(getResources()
.getDimension(R.dimen.recents_empty_message_text_size));
mEmptyMessagePaint.setTypeface(Typeface.create(Themes.getDefaultBodyFont(context),
Typeface.NORMAL));
mEmptyMessagePadding = getResources()
.getDimensionPixelSize(R.dimen.recents_empty_message_text_padding);
setWillNotDraw(false);
updateEmptyMessage();
// Initialize quickstep specific cache params here, as this is constructed only once
mActivity.getViewCache().setCacheSize(R.layout.digital_wellbeing_toast, 5);
}
}
解决问题,在调用 mClearAllButton.setOnClickListener(this::dismissAllTasks); // 设置点击事件
的地方,增加模拟点击事件就可以解决这个问题。这样的话每次开机的时候都会走这个事件达到了客户的要求
--- a/android/packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/android/packages/apps/Launcher3/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -327,6 +327,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
mClearAllButton = (ClearAllButton) LayoutInflater.from(context)
.inflate(R.layout.overview_clear_all_button, this, false);
mClearAllButton.setOnClickListener(this::dismissAllTasks);
+ mClearAllButton.performClick();
mTaskViewPool = new ViewPool<>(context, this, R.layout.task, 20 /* max size */,
10 /* initial size */);
@@ -1233,7 +1234,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
}
总结
通过查询弹出框字段,通过grep 命令 找到字段id然后定位到弹出框位置,粗暴解决
每日赠言
有位智者说,学习是为了完善人生,而非享乐人生。追求卓越,成功自会随你而来