dd

来源:互联网 发布:java初学者论坛 编辑:程序博客网 时间:2024/05/29 03:02


final int NACT = mActivities.size();
ActivityStack
LocalActivityManager
LocalActivityManager

 

        // Remove this application's activities from active lists.
        boolean hasVisibleActivities = mStackSupervisor.handleAppDiedLocked(app);
  
  
  
                  // If there was nothing to resume, and we are not already
                // restarting this process, but there is a visible activity that
                // is hosted by the process...  then make sure all visible
                // activities are running, taking care of restarting this
                // process.
                if (hasVisibleActivities) {
                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
                }
    
                                  // Need to do this on its own message because the stack may not
                                // be in a consistent state at this point.
                                // For these apps we will also finish their activities
                                // to help them free memory.
                                mStackSupervisor.scheduleDestroyAllActivities(app, "trim");  
    
    
    
    void moveUserToForeground(UserStartedState uss, int oldUserId, int newUserId) {
        boolean homeInFront = mStackSupervisor.switchUserLocked(newUserId, uss);
        if (homeInFront) {
            startHomeActivityLocked(newUserId);
        } else {
            mStackSupervisor.resumeTopActivitiesLocked();
        }
        EventLogTags.writeAmSwitchUser(newUserId);
        getUserManagerLocked().userForeground(newUserId);
        sendUserSwitchBroadcastsLocked(oldUserId, newUserId);
    }
 
 resumeTopActivityInnerLocked
 
 handleMessage

 

    private void handleWindowVisibility(IBinder token, boolean show) {
        ActivityClientRecord r = mActivities.get(token);
       
        if (r == null) {
            Log.w(TAG, "handleWindowVisibility: no activity for token " + token);
            return;
        }
       
        if (!show && !r.stopped) {
            performStopActivityInner(r, null, show, false);
        } else if (show && r.stopped) {
            // If we are getting ready to gc after going to the background, well
            // we are back active so skip it.
            unscheduleGcIdler();

            r.activity.performRestart();
            r.stopped = false;
        }
        if (r.activity.mDecor != null) {
            if (false) Slog.v(
                TAG, "Handle window " + r + " visibility: " + show);
            updateVisibility(r, show);
        }
        mSomeActivitiesChanged = true;
   


 
 handleDestroyActivity
 
 

    final void attach(Context context, ActivityThread aThread,
            Instrumentation instr, IBinder token, int ident,
            Application application, Intent intent, ActivityInfo info,
            CharSequence title, Activity parent, String id,
            NonConfigurationInstances lastNonConfigurationInstances,
            Configuration config, IVoiceInteractor voiceInteractor) {
        attachBaseContext(context);

        mFragments.attachActivity(this, mContainer, null);

        mWindow = PolicyManager.makeNewWindow(this); 
 
 activity.attach  is create window
 token windowManger token , created at ActivityRecord initial.
 //--------------------------------------------------------
 Context appContext = createBaseContextForActivity(r, activity);
 
 
 mReleasedWindow
 final void attachNewWindow(ActivityInfo info )
 mActivityInfo
 
 
 
                 if (r.window != null) {
                    r.window.closeAllPanels();
                }
    
  performDestroyWindow  
    getApplication getBaseContext
    
    handleLowMemory   ---- 释放bitmap and 字体
    
    handleTrimMemory
    void CanvasContext::trimMemory(RenderThread& thread, int level) {
    // No context means nothing to free
    if (!thread.eglManager().hasEglContext()) return;

    thread.eglManager().requireGlContext();
    if (level >= TRIM_MEMORY_COMPLETE) {
        Caches::getInstance().flush(Caches::kFlushMode_Full);
        thread.eglManager().destroy();
    } else if (level >= TRIM_MEMORY_UI_HIDDEN) {
        Caches::getInstance().flush(Caches::kFlushMode_Moderate);
    }
}
   mPreviousProcess
ProcessRecord   privDoTrim getPrivTrim setPrivTrim   setProcessForeground     
                        app.thread.scheduleTrimMemory(
                                    ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
 mStackSupervisor.scheduleDestroyAllActivities(null, "always-finish");
  ProcessStats implements Parcelable
  
  
  ActivityStackHandler    handleMessage
  resumeTopActivitiesLocked
  "#####WindowGlobal trimMemory !!!!!!"
  
            if (!r.app.getPrivTrim()){   //lhf
                Slog.e(TAG,"#######updatePreviousProcessLocked");
                mService.amsDoPrivTrim(r.app);
                r.app.setPrivTrim(true);
            }

                      if(pr !=null ){
                        Slog.e(TAG,"############set fg!!!");
                        pr.setPrivTrim(false);
                    } 
   
   
  注意,WindowManagerService类的成员变量mOpeningApps和mClosingApps保存的分别是系统当前正在打开和关闭的Activity组件
    1. 检查是否有窗口资源等待回收。如果有的话,那么就调用WindowManagerService类的成员函数removeWindowInnerLocked来将它们从系统中移除,以便可以回收它们所占用的资源。
    ensureActivitiesVisibleLocked
    performLayoutAndPlaceSurfacesLockedInner
   
    Activity窗口的当前宽度和高度有时候是被WindowManagerService服务主动请求应用程序进程修改的,修改后的值就会保存在ViewRoot类的成员变量mWinFrame中,它们可能会与ViewRoot类的成员变量mWidth和mHeight的值不同。
   
       1. 调用前,检查系统中是否存在强制删除的窗口。有内存不足的情况下,有一些窗口就会被回收,即要从系统中删除,这些窗口会保存在WindowManagerService类的成员变量mForceRemoves所描述的一个ArrayList中
    ws.mAppToken.clientHidden
   
    http://blog.csdn.net/xiaoxiaoshow/article/details/8516849
   
   
   
  (ThreadedRenderer extends HardwareRenderer)  threadRender.java---->   renderProxy  --->  CanvasContext::destroyHardwareResources()  ----->  mRootRenderNode->destroyHardwareResources();
  
  -----------------------------------------view---------------
  isVisibleToUser  isShown
  
      /**
     * Returns true if this view is currently attached to a window.
     */
    public boolean isAttachedToWindow() {
        return mAttachInfo != null;
    }
 PFLAG_SKIP_DRAW
 getDrawingCache
     private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE};
  
  mSystemUiVisibility
  dispatchDetachedFromWindow
  
   void setFlags(int flags, int mask)
   
      // Set to true if the owner of this window is in the stopped state,
    // so the window should no longer be active.
    boolean mStopped = false;       boolean mAppVisible = true;
 
      * The view must have already done a full layout before this function is
     * called.
 
  当销毁activity时, 会调用到嘛 ??
  dispatchDetachedFromWindow    dispatchAttachedToWindow
 
  enableHardwareAcceleration------------------setView
 
  WindowManagerGlobal
 
 
  activity -----mDecor   can be added as a window to the window manager
 
  -------------------------rotate---------------
  updateRotationUnchecked
  sendNewConfiguration
  scheduleWindowVisibility
 
 SurfaceControl  搜索, 看 创建surfce 需要哪些参数, 保存这些参数 但需要时重新创建。
 
public final class WindowManagerImpl implements WindowManager {
    private final WindowManagerGlobal mGlobal = WindowManagerGlobal.getInstance();
 
 
 window ,  setWindowManager:
 mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
 
 
 policy.java 
     public Window makeNewWindow(Context context) {
        return new PhoneWindow(context);
    }
 
 
 public class PhoneWindowManager implements WindowManagerPolicy {  WindowManagerPolicy implementation for the Android phone UI.
 如果该WindowState是一个Activity窗口,那么就返回mAppToken.appToken,否则返回null。
 ---\
 public class PhoneWindow extends Window implements MenuBuilder.Callback {
 
 ----view attachto window, windowstate, window,  PhoneWindow????
 
  ======================================

http://blog.csdn.net/luoshengyang/article/details/8661317/
  
  
 

0 0
原创粉丝点击