当前位置: 首页 > news >正文

重庆制作网站培训市场调研的重要性

重庆制作网站培训,市场调研的重要性,营销型网站建设的特色,大连模板建站平台前言 Android12对最近任务做了调整,将原本处于SystemUI模块的最近任务转移到了Launcher3QuickStep应用中。 本篇文章我们会结合源码一起来梳理一下最近任务的显示流程。 一、SystemUI模块显示最近任务的相关代码 1、在SystemUI模块调用CommandQueue的showRecentA…

前言

Android12对最近任务做了调整,将原本处于SystemUI模块的最近任务转移到了Launcher3QuickStep应用中。
本篇文章我们会结合源码一起来梳理一下最近任务的显示流程。

一、SystemUI模块显示最近任务的相关代码

1、在SystemUI模块调用CommandQueue的showRecentApps方法可以实现最近任务的显示。

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java

public class CommandQueue extends IStatusBar.Stub implementsCallbackController<Callbacks>,DisplayManager.DisplayListener {private Handler mHandler = new H(Looper.getMainLooper());public void showRecentApps(boolean triggeredFromAltTab) {synchronized (mLock) {mHandler.removeMessages(MSG_SHOW_RECENT_APPS);mHandler.obtainMessage(MSG_SHOW_RECENT_APPS, triggeredFromAltTab ? 1 : 0, 0,null).sendToTarget();}}}

showRecentApps方法会调用Handler发送类型为MSG_SHOW_RECENT_APPS的消息。

2、Handler对象在接收到MSG_SHOW_RECENT_APPS消息之后,会调用所有回调对象的showRecentApps方法。

public class CommandQueue extends IStatusBar.Stub implementsCallbackController<Callbacks>,DisplayManager.DisplayListener {private static final int MSG_SHOW_RECENT_APPS = 13 << MSG_SHIFT;//显示最近任务private ArrayList<Callbacks> mCallbacks = new ArrayList<>();//回调对象集合private final class H extends Handler {private H(Looper l) {super(l);}public void handleMessage(Message msg) {final int what = msg.what & MSG_MASK;switch (what) {case MSG_SHOW_RECENT_APPS:for (int i = 0; i < mCallbacks.size(); i++) {//调用左右回调对象的showRecentApps方法mCallbacks.get(i).showRecentApps(msg.arg1 != 0);}break;}}}public interface Callbacks {default void showRecentApps(boolean triggeredFromAltTab) {}}}

3、类型为Recents的SystemUI组件实现了CommandQueue.Callbacks接口,并将自身添加到了CommandQueue的监听回调对象集合中,
这样CommandQueue的showRecentApps方法会触发Recents组件的showRecentApps方法。

frameworks/base/packages/SystemUI/src/com/android/systemui/recents/Recents.java

public class Recents extends SystemUI implements CommandQueue.Callbacks {private final RecentsImplementation mImpl;private final CommandQueue mCommandQueue;public Recents(Context context, RecentsImplementation impl, CommandQueue commandQueue) {super(context);mImpl = impl;mCommandQueue = commandQueue;}@Overridepublic void start() {mCommandQueue.addCallback(this);mImpl.onStart(mContext);}//显示最近任务@Overridepublic void showRecentApps(boolean triggeredFromAltTab) {// Ensure the device has been provisioned before allowing the user to interact with// recentsif (!isUserSetup()) {return;}android.util.Log.d("SystemUI.Recents", "showRecentApps: triggeredFromAltTab = " + triggeredFromAltTab);mImpl.showRecentApps(triggeredFromAltTab);}}

Recents的showRecentApps方法会进一步调用RecentsImplementation的showRecentApps方法。

4、RecentsImplementation是一个接口。

frameworks/base/packages/SystemUI/src/com/android/systemui/recents/RecentsImplementation.java

public interface RecentsImplementation {default void onStart(Context context) {}default void onBootCompleted() {}default void onAppTransitionFinished() {}default void onConfigurationChanged(Configuration newConfig) {}default void preloadRecentApps() {}default void cancelPreloadRecentApps() {}default void showRecentApps(boolean triggeredFromAltTab) {}default void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {}default void toggleRecentApps() {}default void dump(PrintWriter pw) {}
}

5、在SystemUI模块的具体实现类是OverviewProxyRecentsImpl。

frameworks/base/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyRecentsImpl.java

public class OverviewProxyRecentsImpl implements RecentsImplementation {private final static String TAG = "OverviewProxyRecentsImpl";@Nullableprivate final Lazy<Optional<StatusBar>> mStatusBarOptionalLazy;private Context mContext;private Handler mHandler;private TrustManager mTrustManager;private OverviewProxyService mOverviewProxyService;@SuppressWarnings("OptionalUsedAsFieldOrParameterType")@Injectpublic OverviewProxyRecentsImpl(Lazy<Optional<StatusBar>> statusBarOptionalLazy) {mStatusBarOptionalLazy = statusBarOptionalLazy;}@Overridepublic void onStart(Context context) {mContext = context;mHandler = new Handler();mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE);//为OverviewProxyService赋值mOverviewProxyService = Dependency.get(OverviewProxyService.class);}@Overridepublic void showRecentApps(boolean triggeredFromAltTab) {android.util.Log.d("SystemUI.OverviewProxyRecentsImpl", "showRecentApps: triggeredFromAltTab = " + triggeredFromAltTab);//IOverviewProxy是一个aidl,最初是调用OverviewProxyService的getProxy方法进行赋值的IOverviewProxy overviewProxy = mOverviewProxyService.getProxy();if (overviewProxy != null) {try {//继续调用onOverviewShown方法overviewProxy.onOverviewShown(triggeredFromAltTab);return;} catch (RemoteException e) {Log.e(TAG, "Failed to send overview show event to launcher.", e);}} else {// Do nothing}}}

OverviewProxyRecentsImpl的showRecentApps方法会进一步调用代理者IOverviewProxy的onOverviewShown方法,IOverviewProxy是一个aidl。这里调用OverviewProxyService的getProxy方法为overviewProxy赋值。mOverviewProxyService最初是通过Dependency进行赋值的。

6、OverviewProxyService类和getProxy方法相关代码如下所示。

public class OverviewProxyService extends CurrentUserTracker implementsCallbackController<OverviewProxyListener>, NavigationModeController.ModeChangedListener,Dumpable {//唤起Launcher3模块TouchInteractionService的Actionprivate static final String ACTION_QUICKSTEP = "android.intent.action.QUICKSTEP_SERVICE";//唤起Launcher3模块TouchInteractionService的Intentprivate final Intent mQuickStepIntent;//远程IPC通信是实现类private IOverviewProxy mOverviewProxy;private boolean mBound;public OverviewProxyService(Context context, CommandQueue commandQueue,Lazy<NavigationBarController> navBarControllerLazy,Lazy<Optional<StatusBar>> statusBarOptionalLazy,NavigationModeController navModeController,NotificationShadeWindowController statusBarWinController, SysUiState sysUiState,Optional<Pip> pipOptional,Optional<LegacySplitScreen> legacySplitScreenOptional,Optional<SplitScreen> splitScreenOptional,Optional<OneHanded> oneHandedOptional,Optional<RecentTasks> recentTasks,Optional<StartingSurface> startingSurface,BroadcastDispatcher broadcastDispatcher,ShellTransitions shellTransitions,ScreenLifecycle screenLifecycle,SmartspaceTransitionController smartspaceTransitionController,UiEventLogger uiEventLogger,DumpManager dumpManager) {super(broadcastDispatcher);...代码省略...//获取最近任务组件名称mRecentsComponentName = ComponentName.unflattenFromString(context.getString(com.android.internal.R.string.config_recentsComponentName));//创建最近任务Activity的意图对象mQuickStepIntent = new Intent(ACTION_QUICKSTEP).setPackage(mRecentsComponentName.getPackageName());...代码省略...startConnectionToCurrentUser();...代码省略...}//成功绑定服务所返回的ServiceConnection对象private final ServiceConnection mOverviewServiceConnection = new ServiceConnection() {@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {...代码省略...//拿到IOverviewProxy对象,为后续跨进程通信做准备mOverviewProxy = IOverviewProxy.Stub.asInterface(service);...代码省略...}};private void internalConnectToCurrentUser() {...代码省略...       Intent launcherServiceIntent = new Intent(ACTION_QUICKSTEP).setPackage(mRecentsComponentName.getPackageName());try {//绑定服务mBound = mContext.bindServiceAsUser(launcherServiceIntent,mOverviewServiceConnection,Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,UserHandle.of(getCurrentUserId()));} catch (SecurityException e) {Log.e(TAG_OPS, "Unable to bind because of security error", e);}...代码省略...}public IOverviewProxy getProxy() {return mOverviewProxy;}        }

对以上代码做个简单总结:

1)为最近任务组件名称mRecentsComponentName赋值。

frameworks/base/core/res/res/values/config.xml

    <string name="config_recentsComponentName" translatable="false">com.android.launcher3/com.android.quickstep.RecentsActivity</string>

2)创建最近任务Activity的意图对象mQuickStepIntent
3)创建最近任务服务的意图对象launcherServiceIntent,并进行服务绑定,触发mOverviewServiceConnection的回调方法onServiceConnected,
为类型为远程IPC通信的实现类mOverviewProxy对象赋值。
4)调用的getProxy获得远程通信的实现类

二、Launcher3模块显示最近任务的相关代码

梳理完了SystemUI模块和最近任务相关的代码,我们再来看下Launcher3模块相关的代码。

1、通过上面我们可以知道SystemUI模块启动的时候会启动Launcher3模块的最近任务服务,另外还有提到了最近任务Activity组件, 二者的声明如下所示。

packages/apps/Launcher3/quickstep/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"package="com.android.launcher3"><application android:backupAgent="com.android.launcher3.LauncherBackupAgent"><service android:name="com.android.quickstep.TouchInteractionService"android:permission="android.permission.STATUS_BAR_SERVICE"android:directBootAware="true"android:exported="true"><intent-filter><action android:name="android.intent.action.QUICKSTEP_SERVICE"/></intent-filter></service><activity android:name="com.android.quickstep.RecentsActivity"android:excludeFromRecents="true"android:launchMode="singleTask"android:clearTaskOnLaunch="true"android:stateNotNeeded="true"android:theme="@style/LauncherTheme"android:screenOrientation="unspecified"android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize"android:resizeableActivity="true"android:resumeWhilePausing="true"android:taskAffinity=""/></application></manifest>

2、第一节我们讲过要想显示最近任务,需要调用CommandQueue的showRecentApps方法,而该方法最终调用的其实是IOverviewProxy的onOverviewShown。
这里我们具体看一下这个aidl的具体内容。

frameworks/base/packages/SystemUI/shared/src/com/android/systemui/shared/recents/IOverviewProxy.aidl

oneway interface IOverviewProxy {void onActiveNavBarRegionChanges(in Region activeRegion) = 11;void onInitialize(in Bundle params) = 12;/*** Sent when overview button is pressed to toggle show/hide of overview.*/void onOverviewToggle() = 6;/*** 显示最近任务*/void onOverviewShown(boolean triggeredFromAltTab) = 7;/*** Sent when overview is to be hidden.*/void onOverviewHidden(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) = 8;/*** Sent when there was an action on one of the onboarding tips view.* TODO: Move this implementation to SystemUI completely*/void onTip(int actionType, int viewType) = 10;/*** Sent when device assistant changes its default assistant whether it is available or not.*/void onAssistantAvailable(boolean available) = 13;/*** Sent when the assistant changes how visible it is to the user.*/void onAssistantVisibilityChanged(float visibility) = 14;/*** Sent when back is triggered.* TODO: Move this implementation to SystemUI completely*/void onBackAction(boolean completed, int downX, int downY, boolean isButton,boolean gestureSwipeLeft) = 15;/*** Sent when some system ui state changes.*/void onSystemUiStateChanged(int stateFlags) = 16;/*** Sent when the split screen is resized*/void onSplitScreenSecondaryBoundsChanged(in Rect bounds, in Rect insets) = 17;/*** Sent when suggested rotation button could be shown*/void onRotationProposal(int rotation, boolean isValid) = 18;/*** Sent when disable flags change*/void disable(int displayId, int state1, int state2, boolean animate) = 19;/*** Sent when behavior changes. See WindowInsetsController#@Behavior*/void onSystemBarAttributesChanged(int displayId, int behavior) = 20;/*** Sent when screen turned on and ready to use (blocker scrim is hidden)*/void onScreenTurnedOn() = 21;/*** Sent when the desired dark intensity of the nav buttons has changed*/void onNavButtonsDarkIntensityChanged(float darkIntensity) = 22;
}

3、Launcher3模块的最近任务服务TouchInteractionService和onOverviewShown方法相关的代码如下所示。

packages/apps/Launcher3/quickstep/src/com/android/quickstep/TouchInteractionService.java

public class TouchInteractionService extends Serviceimplements ProtoTraceable<LauncherTraceProto.Builder> {private OverviewCommandHelper mOverviewCommandHelper;private final TISBinder mTISBinder = new TISBinder();/*** Local IOverviewProxy implementation with some methods for local components*/public class TISBinder extends IOverviewProxy.Stub {@BinderThread@Overridepublic void onOverviewShown(boolean triggeredFromAltTab) {android.util.Log.d("Launcher3.TouchInteractionService", "onOverviewShown: triggeredFromAltTab = " + triggeredFromAltTab);if (triggeredFromAltTab) {TaskUtils.closeSystemWindowsAsync(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS);mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_SHOW_NEXT_FOCUS);} else {mOverviewCommandHelper.addCommand(OverviewCommandHelper.TYPE_SHOW);}}}@Overridepublic IBinder onBind(Intent intent) {Log.d(TAG, "Touch service connected: user=" + getUserId());return mTISBinder;}
}       

TISBinder对象的onOverviewShown方法被SystemUI所触发的时候,会进一步调用OverviewCommandHelper对象的addCommand方法,传入TYPE_SHOW。

4、OverviewCommandHelper和显示最近任务相关的代码如下所示。

public class OverviewCommandHelper {public static final int TYPE_SHOW = 1;//显示public static final int TYPE_SHOW_NEXT_FOCUS = 2;public static final int TYPE_HIDE = 3;//隐藏public static final int TYPE_TOGGLE = 4;//切换public static final int TYPE_HOME = 5;//首页public void addCommand(int type) {CommandInfo cmd = new CommandInfo(type);MAIN_EXECUTOR.execute(() -> addCommand(cmd));}private void addCommand(CommandInfo cmd) {boolean wasEmpty = mPendingCommands.isEmpty();mPendingCommands.add(cmd);if (wasEmpty) {executeNext();}}private void executeNext() {if (mPendingCommands.isEmpty()) {return;}CommandInfo cmd = mPendingCommands.get(0);//层层调用,最终触发executeCommand方法。if (executeCommand(cmd)) {scheduleNextTask(cmd);}}private <T extends StatefulActivity<?>> boolean executeCommand(CommandInfo cmd) {BaseActivityInterface<?, T> activityInterface =mOverviewComponentObserver.getActivityInterface();RecentsView recents = activityInterface.getVisibleRecentsView();if (recents == null) {//如果视图为空,说明最近任务视图不可见if (cmd.type == TYPE_HIDE) {// already hiddenreturn true;}if (cmd.type == TYPE_HOME) {android.util.Log.d("Launcher3.OverviewCommandHelper", "executeCommand cmd.type == TYPE_HOME");mService.startActivity(mOverviewComponentObserver.getHomeIntent());LauncherSplitScreenListener.INSTANCE.getNoCreate().notifySwipingToHome();return true;}} else {//如果视图不为空,说明最近任务视图可见switch (cmd.type) {case TYPE_SHOW:// already visiblereturn true;case TYPE_HIDE: {int currentPage = recents.getNextPage();TaskView tv = (currentPage >= 0 && currentPage < recents.getTaskViewCount())? (TaskView) recents.getPageAt(currentPage): null;return launchTask(recents, tv, cmd);}case TYPE_TOGGLE:return launchTask(recents, getNextTask(recents), cmd);case TYPE_HOME:android.util.Log.d("Launcher3.OverviewCommandHelper", "executeCommand TYPE_HOME");recents.startHome();LauncherSplitScreenListener.INSTANCE.getNoCreate().notifySwipingToHome();return true;}}...代码省略...return false;}}
http://www.zhongyajixie.com/news/566.html

相关文章:

  • 网站运维工作内容ueeshop建站费用
  • 哈尔滨营销型网站建设公司友情链接站长平台
  • 中山网站建设哪家好百度网页版电脑版
  • 策划公司口号广州seo推广培训
  • 安徽网站建设维护银徽seo
  • 安装php网站广州企业网站推广
  • 手机网站建设怎样建站模板
  • 做网站如何选主机西安seo培训机构
  • 做网站是怎么收费的是按点击率青岛网络优化费用
  • 如何利用ps做网站网络营销渠道有哪几种
  • 如何制作公司网站免费ip域名查询
  • 音频文件放到网站空间里生成链接怎么做站长之家域名查询官网
  • 泉州网站建设电话淘宝运营培训多少钱
  • 政府网站建设调查问卷目前推广软件
  • 网站文字循环滚动代码百度网站登录
  • 中国建设银行网上银行网站特点怎么制作网站二维码
  • 英语网站推广策划书深度优化
  • 服装网络营销方案策划seo优化软件
  • wordpress 基于 网店seo工作是什么意思
  • 做神马网站优化快速排推广渠道有哪些
  • 织梦手机网站教程视频教程数据统计网站有哪些
  • 做网站时链接的网页无法显示代理怎么引流推广
  • 网站开发前景西安关键词排名优化
  • 网站公司 转型排名优化seo
  • 国建设银行e路通网站申今日新闻50字
  • 政府网站集约化建设存在的问题搜索引擎简称seo
  • 字节跳动员工人数2020做网站关键词优化的公司
  • 做一个网页难不难网站产品怎么优化
  • 织梦网站需要优化百度云搜索引擎入口官网
  • 淘宝网站建设的目标是什么意思广东免费网络推广软件