@MainActivity.java
Toast.makeText(MainActivity.this, "xww make toast", Toast.LENGTH_SHORT)
@frameworks/base/core/java/android/widget/Toast.java
makeText(context, null, text, duration);
Toast result = new Toast(context, looper);
mContext = context; // Toast的context
mTN = new TN(context, context.getPackageName(), mToken, mCallbacks, looper);
@frameworks/base/core/java/android/widget/ToastPresenter.java
mPresenter = new ToastPresenter(context, accessibilityManager, getService(), packageName);
mContext = context; //ToastPresenter的context
@frameworks/base/core/java/android/app/ContextImpl.java
mWindowManager = context.getSystemService(WindowManager.class);
SystemServiceRegistry.getSystemServiceName(serviceClass);
final String serviceName = SYSTEM_SERVICE_NAMES.get(serviceClass);
return serviceName;
View v = ToastPresenter.getTextToastView(context, text);
View view = LayoutInflater.from(context).inflate(TEXT_TOAST_LAYOUT, null);
TextView textView = view.findViewById(com.android.internal.R.id.message);
textView.setText(text);
return view;
result.mNextView = v; // Toast的context
.show())
INotificationManager service = getService();
sService = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
TN tn = mTN;
tn.mNextView = mNextView; // 设置TN的mNextView
final int displayId = mContext.getDisplayId();
@frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
service.enqueueToast(pkg, mToken, tn, mDuration, displayId);
@frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
mWindowManagerInternal.addWindowToken(windowToken, TYPE_TOAST, displayId,null
record = getToastRecord(callingUid, callingPid, pkg, isSystemToast, token, text, callback, duration, windowToken, displayId, textCallback); // callback等于TN
return new CustomToastRecord(this, uid, pid, packageName,isSystemToast, token, callback, duration, windowToken, displayId);
final DisplayContent dc = getDisplayContentOrCreate(displayId, null /* token */);
new WindowToken.Builder(this, binder, type).setDisplayContent(dc) .setPersistOnEmpty(true).setOwnerCanManageAppTokens(true).setOptions(options).build();
mToastQueue.add(record);
showNextToastLocked(false);
ToastRecord record = mToastQueue.get(0);
tryShowToast(record, rateLimitingEnabled, isWithinQuota, isPackageInForeground))
@frameworks/base/services/core/java/com/android/server/notification/toast/CustomToastRecord.java
record.show();
@frameworks/base/core/java/android/widget/Toast.java
callback.show(windowToken); //TN.show
mHandler.obtainMessage(SHOW, windowToken).sendToTarget();
void handleMessage(Message msg) {
case SHOW: {
handleShow(token);
mView = mNextView; //获取TN的mNextView
mPresenter.show(mView, mToken, windowToken, mDuration, mGravity, mX, mY, mHorizontalMargin, mVerticalMargin, new CallbackBinder(getCallbacks(), mHandler));
addToastView();
@frameworks/base/core/java/android/view/WindowManagerImpl.java
mWindowManager.addView(mView, mParams);
@frameworks/base/core/java/android/view/WindowManagerGlobal.java
mGlobal.addView(view, params, mContext.getDisplayNoVerify(), mParentWindow, mContext.getUserId()); //WindowManagerImpl的mContext
08-16
752
03-31
1314