1:WindowManagerService:

platform\frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.class 

具体改动的地方看代码吧,

   public int getOrientationFromWindowsLocked() {        ....        -- return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);        ++ return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);    }
  /*     * Determine the new desired orientation of the display, returning     * a non-null new Configuration if it has changed from the current     * orientation.  IF TRUE IS RETURNED SOMEONE MUST CALL     * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE     * SCREEN.  This will typically be done for you if you call     * sendNewConfiguration().     *     * The orientation is computed from non-application windows first. If none of     * the non-application windows specify orientation, the orientation is computed from     * application tokens.     * @see android.view.IWindowManager#updateOrientationFromAppTokens(     * android.os.IBinder)     */    boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {        long ident = Binder.clearCallingIdentity();        try {            int req = getOrientationFromWindowsLocked();            if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {-- mForcedAppOrientation = req;-- req = getOrientationFromAppTokensLocked();         ++req=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;            }            if (req != mForcedAppOrientation) {                -- mForcedAppOrientation = req;                ++ mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;....    }
    boolean computeScreenConfigurationLocked(Configuration config) {....        if (config != null) {            -- config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT:Configuration.ORIENTATION_LANDSCAPE;            ++ config.orientation = Configuration.ORIENTATION_LANDSCAPE;        }....        return true;    }

修改这几处代码便能把系统默认的竖屏变成横屏,但是会有其他的应用出现问题,比如拨号盘原本竖屏显示的,但是在这种横屏模式下打开拨号盘会报空指针错误,进源码一看原来拨号盘也准备了两套的布局,一套横屏一套竖屏的,单独修改windowmanagerservice后不知道为什么这些系统应用没有变成竖屏模式,或许是时间仓促,并没有对windowmanagerservice的流程作很详细的分析,以后有时间再找机会研究下这个流程吧。

2:PhoneWindowManager

 

  1. public int rotationForOrientationLw(int orientation, int lastRotation,  
  2.            boolean displayEnabled) {  
  3.   
  4.        if (mPortraitRotation < 0) {  
  5.            // Initialize the rotation angles for each orientation once.  
  6.            Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))  
  7.                    .getDefaultDisplay();  
  8.            if (d.getWidth() > d.getHeight()) {  
  9.                mPortraitRotation = Surface.ROTATION_90;  
  10.                mLandscapeRotation = Surface.ROTATION_0;  
  11.                mUpsideDownRotation = Surface.ROTATION_270;  
  12.                mSeascapeRotation = Surface.ROTATION_180;  
  13.            } else {  
  14.                mPortraitRotation = Surface.ROTATION_0;  
  15.                mLandscapeRotation = Surface.ROTATION_90;  
  16.                mUpsideDownRotation = Surface.ROTATION_180;  
  17.                mSeascapeRotation = Surface.ROTATION_270;  
  18.            }  
  19.        }  
  20.   
  21.     {  
  22.         Log.i(TAG, "MediaPlayer.is not PlayingVideo");  
  23.         synchronized (mLock) {  
  24.             switch (orientation) {  
  25.                 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:  
  26.                     //always return portrait if orientation set to portrait  
  27.                     //return mPortraitRotation;  
  28.                     return mUpsideDownRotation;  
  29.                 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:  
  30.                     //always return landscape if orientation set to landscape  
  31.                     return mLandscapeRotation;  
  32.                 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:  
  33.                     //always return portrait if orientation set to portrait  
  34.                     //return mUpsideDownRotation;  
  35.                     return mPortraitRotation;  
  36.                 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:  
  37.                     //always return seascape if orientation set to reverse landscape  
  38.                     return mSeascapeRotation;  
  39.                 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:  
  40.                     //return either landscape rotation based on the sensor  
  41.                     mOrientationListener.setAllow180Rotation(  
  42.                             isLandscapeOrSeascape(Surface.ROTATION_180));  
  43.                     return getCurrentLandscapeRotation(lastRotation);  
  44.                 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:  
  45.                     mOrientationListener.setAllow180Rotation(  
  46.                             !isLandscapeOrSeascape(Surface.ROTATION_180));  
  47.                     return getCurrentPortraitRotation(lastRotation);  
  48.             }  
  49.   
  50.             mOrientationListener.setAllow180Rotation(  
  51.                    orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR  
  52.                    || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);  
  53.   
  54.             // case for nosensor meaning ignore sensor and consider only lid  
  55.             // or orientation sensor disabled  
  56.             //or case.unspecified  
  57.             if (mLidOpen) {  
  58.                 return mLidOpenRotation;  
  59.             } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {  
  60.                 return mCarDockRotation;  
  61.             } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {  
  62.                 return mDeskDockRotation;  
  63.             } else {  
  64.                 if (useSensorForOrientationLp(orientation)) {  
  65.                     return mOrientationListener.getCurrentRotation(lastRotation);  
  66.                 }  
  67.                 return Surface.ROTATION_0;  
  68.             }  
  69.         }  
  70. }  
  71.    }  


修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有

 

 

[java] view plaincopy

  1. if (mPortraitRotation < 0) {  
  2.     // Initialize the rotation angles for each orientation once.  
  3.     Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))  
  4.             .getDefaultDisplay();  
  5.     if (d.getWidth() > d.getHeight()) {  
  6.         mPortraitRotation = Surface.ROTATION_90;  
  7.         mLandscapeRotation = Surface.ROTATION_0;  
  8.         mUpsideDownRotation = Surface.ROTATION_270;  
  9.         mSeascapeRotation = Surface.ROTATION_180;  
  10.     } else {  
  11.         mPortraitRotation = Surface.ROTATION_0;  
  12.         mLandscapeRotation = Surface.ROTATION_90;  
  13.         mUpsideDownRotation = Surface.ROTATION_180;  
  14.         mSeascapeRotation = Surface.ROTATION_270;  
  15.     }  
  16. }  

 

让所有应用都横屏显示:

frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

 

    public int rotationForOrientationLw(int orientation, int lastRotation,

            boolean displayEnabled) {

            // Initialize the rotation angles for each orientation once.

            Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))

                    .getDefaultDisplay();

            if (d.getWidth() > d.getHeight()) {

                mPortraitRotation = Surface.ROTATION_0;  //jeff. ROTATION_90;

                mLandscapeRotation = Surface.ROTATION_0;

                mUpsideDownRotation = Surface.ROTATION_90;  //jeff. 270;

                mSeascapeRotation = Surface.ROTATION_180;

            }

更多相关文章

  1. Android应用程序安装过程源代码分析(4)
  2. Android平台mass storage相关代码
  3. 使用代码为textview设置drawableLeft
  4. [置顶] Android 2.3.5源代码 更新至android 6.0,可以下载,度娘网盘
  5. cocos2dx 调用java层代码
  6. 安卓学习(初)第三章(3)(《第一行代码》)
  7. 性能优化之Java(Android)代码优化
  8. 通过eclipse查看Android源代码(Java)
  9. 【Android】注解框架(四)-- 一行代码注入微信支付

随机推荐

  1. android RecyclerView 设置设置选中的一
  2. Android(安卓)Ui设计相关的网站推荐
  3. Android腾讯微薄客户端开发十一:博主的粉
  4. Cocos2dxActivity cannot be resolved to
  5. Android(安卓)Studio中Git的配置及协同开
  6. Android 数据存储与读取:文件
  7. Android中回调接口使用实例
  8. Android,HTTP请求中文乱码
  9. android版本自动检测更新 版本检测 自动
  10. android build kernel make menuconfig及