Android 2.3 Rotation and Orientation

Service:
28 window: [ android.view.IWindowManager]
38 activity: [ android.app.IActivityManager]
46 SurfaceFlinger: [ android.ui.ISurfaceComposer]

1) Init services
system/core/init/init.c
restart_processes()@system/core/init/init.c
    service_start()
      execve()   【service zygote /system/bin/app_process -Xzygote/system/bin --zygote--start-system-server init.rc
        main()@frameworks\base\cmds\app_main.cpp
          runtime.start("com.android.internal.os.ZygoteInit",startSystemServer);
            startSystemServer()@com.android.internal.os.ZygoteInit
              main()@com/android/server/SystemServer
                init1()
                  android_server_SystemServer_init1()@com_android_server_SystemServer.cpp
                    system_init()   {SurfaceFlinger::instantiate()}
                      runtime->callStatic("com/android/server/SystemServer", "init2");
                        init2()@com/android/server/SystemServer
                          new ServerThread()
                            ActivityManagerService.main()
                            wm = WindowManagerService.main()
                               new WMThread()@WindowManagerService.java
                                new WindowManagerService()
                                  { final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
                                      PolicyManager.makeNewWindowManager()
                                        makeNewWindowManager()@com.android.internal.policy.impl.Policy
                                          return new PhoneWindowManager
                                            { class MyOrientationListener extends WindowOrientationListener }
                                   }


2) Set Orientation
WindowOrientationListener.java
  onSensorChanged() [
ROTATION_XXX -> Surface.ROTATION_XXX ]
    onOrientationChanged(
Surface.ROTATION_XXX )
      setRotation()@WindowManagerService
        setRotationUnchecked()
          setRotationUncheckedLocked()
            Surface::setOrientation()
              setOrientation( Surface.ROTATION_XXX )@Surface.java
                Surface_setOrientation()@android_view_Surface.cpp
                  setOrientation()@SurfaceComposerClient.cpp
                    SurfaceFlinger::setOrientation()
                     setTransactionFlags()@SurfaceFlinger.cpp
                       handleTransaction()@SurfaceFlinger.cpp
                         handleTransactionLocked()@SurfaceFlinger.cpp
                            dcblk->orientation = orientation;
                             GraphicPlane::setOrientation( ISurfaceComposer::eOrientation_XXX )@SurfaceFlinger.cpp
                               GraphicPlane::orientationToTransfrom()[
ISurfaceComposer::eOrientationXXX -> Transform::ROT_XXX ]

3) Get Orientation
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager(). getDefaultDisplay(). getMetrics(metrics);
getWindowManager(). getDefaultDisplay(). getOrientation()@Activity.java
  getSystemService(Context.WINDOW_SERVICE)@Activity.java  [== getWindowManager()@Activity.java]
    {return mWindowManager
      attach()@androi.app.Activity
        mWindow = PolicyManager.makeNewWindow(this)
          mWindow.setWindowManager(null)
            wm = WindowManagerImpl.getDefault();
              return new
WindowManagerImpl ()
                mWindowManager = new LocalWindowManager(wm);
    }

    getDefaultDisplay()@ android.view.WindowManagerImpl
      return new Display()
        init()@ android.view.Display
          android_view_Display_init()@android_view_Display.cpp
            SurfaceComposerClient.cpp:: getDisplayInfo()
              get_cblk()
                ISurfaceComposer-> getCblk()
                  getCblk()@SurfaceFlinger.cpp  (SurfaceFlinger: [android.ui.ISurfaceComposer])
                    readyToRun()
                      const GraphicPlane& plane(graphicPlane(dpy));
                      const DisplayHardware& hw = plane.displayHardware();

                      dcblk->orientation = ISurfaceComposer::eOrientationDefault;
       getOrientation()@ android.view.Display
         android_view_Display_getOrientation()@android.view.Display
           SurfaceComposerClient::getDisplayOrientation()
             get_cblk()
                return dcblk->orientation

WindowOrientationListener.java
    private static final int ROTATION_0 = 0;
    private static final int ROTATION_90 = 1;
    private static final int ROTATION_270 = 2;
    private static final int ROTATION_180 = 3;

Surface.java
    public static final int ROTATION_0       = 0;
    public static final int ROTATION_90      = 1;
    public static final int ROTATION_180     = 2;
    public static final int ROTATION_270     = 3;

ISurfaceComposer.h
enum {
    eOrientationDefault     = 0,
    eOrientation90          = 1,
    eOrientation180         = 2,
    eOrientation270         = 3,
    eOrientationSwapMask    = 0x01
};

Transform.h
enum orientation_flags {
    ROT_0   = 0x00000000,
    FLIP_H  = HAL_TRANSFORM_FLIP_H,
    FLIP_V  = HAL_TRANSFORM_FLIP_V,
    ROT_90  = HAL_TRANSFORM_ROT_90,
    ROT_180 = FLIP_H|FLIP_V,
    ROT_270 = ROT_180|ROT_90,
    ROT_INVALID = 0x80

};


getRequestedOrientation()@Activity.java
  ActivityManagerNative.getDefault().getRequestedOrientation()
    ServiceManager.getService("activity").asInterface()
      getRequestedOrientation()@ActivityManagerService.java
        getAppOrientation()@WindowManagerService
          findAppWindowToken()
            getAppOrientation()
              return wtoken.requestedOrientation;

setRequestedOrientation()@Activity.java
  ActivityManagerNative.getDefault().setRequestedOrientation()
    ServiceManager.getService("activity").asInterface()
      setRequestedOrientation()@ActivityManagerService.java
        setAppOrientation()@WindowManagerService
          findAppWindowToken()
            setAppOrientation()
              wtoken.requestedOrientation = requestedOrientation;
        updateOrientationFromAppTokens()@WindowManagerService
          setRotationUncheckedLocked()

            Surface.setOrientation()


http://blog.csdn.net/watchnight/article/details/6701260


你可能感兴趣的:(android,server,service,System,Class,frameworks)