東川印記

一本東川,笑看爭龍斗虎;寰茫兦者,度橫佰昧人生。

android源码编译之04android4.4.2版功能修改

2015年3月27日星期五



之前5.0版夭折了,现在搞4.4.2要轻松许多
继续按5.0的格式来。
1,不锁屏
跟5.0一模一样,以下直接copy from 02 start
①设置默认锁屏时间
文件
/home/senrsl/android/source/WORKING_DIRECTORY/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
修改
  1. <integer name="def_screen_off_timeout">-1</integer>
之前为60000,修改为-1不锁屏。

②开机不锁屏
这个文件跑的比较快
4.0版本的时候,在frameworks/base/policy/src/com/android/internal/policy /impl/KeyguardViewMediator.java
4.4版本的时候,在 frameworks/base/packages/Keyguard/src/com/android/keyguard/KeyguardViewMediator.java
5.0版本的时候,在/home/senrsl/android/source/WORKING_DIRECTORY/frameworks /base/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
就是改个不锁屏而已,谷歌你大爷的至于吗。。。。
我用的5.0版本,第206行,改值为false
  1. private boolean mExternallyEnabled = false;
这样便实现开机不锁屏,且长时间不用也不锁屏问题。
copy from 02 end
经验证,4.4.2的mExternallyEnabled在192行。
4.4.2改完发现开机还是锁屏。。。。
然后,还是这个文件,搞四步
1)当然是最经典的private boolean mExternallyEnabled = false;,大概是192行;
2)给他设置默认值private boolean mShowing = false;大概是205行;
3)大概是515行,这个赋值注释掉    
    //mShowing = (mUpdateMonitor.isDeviceProvisioned() || mLockPatternUtils.isSecure())
        //        && !mLockPatternUtils.isLockScreenDisabled();
4)大概是1067行,这个handle处理注释掉//handleShow((Bundle) msg.obj);
这样4.4.2的锁屏搞定。

2,开机画面
跟02基本类似
①第一屏
第一屏默认是不显示的,要编译内核的时候开启。
修改内核配置文件/home/senrsl/android/source/kernel/goldfish/arch/arm/configs /goldfish_armv7_defconfig
在最后面加上
  1. #CONFIG_FRAMEBUFFER_CONSOLE=y
  2. CONFIG_LOGO=y
这样启动的时候倒是显示了第一屏,但是一直闪,也能进系统操作,但是一直闪啊闪。。。。
好吧,换个方式,用make menuconfig来搞
  1. senrsl@senrsl-ubuntu:~/android/source/kernel/goldfish$ make menuconfig
  2.  *** Unable to find the ncurses libraries or the
  3.  *** required header files.
  4.  *** 'make menuconfig' requires the ncurses libraries.
  5.  ***
  6.  *** Install ncurses (ncurses-devel) and try again.
  7.  ***
  8. make[1]: *** [scripts/kconfig/dochecklxdialog] 错误 1
  9. make: *** [menuconfig] 错误 2
  10. senrsl@senrsl-ubuntu:~$ sudo apt-get install libncurses5-dev
  11. [sudo] password for senrsl:
  12. 正在读取软件包列表... 完成
  13. 正在分析软件包的依赖关系树      
  14. 正在读取状态信息... 完成      
  15. 建议安装的软件包:
  16.   ncurses-doc
  17. 下列【新】软件包将被安装:
  18.   libncurses5-dev
  19. 升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
  20. 需要下载 170 kB 的软件包。
  21. 解压缩后会消耗掉 1,056 kB 的额外空间。
  22. 获取:1 http://cn.archive.ubuntu.com/ubuntu/ trusty/main libncurses5-dev amd64 5.9+20140118-1ubuntu1 [170 kB]
  23. 下载 170 kB,耗时 0秒 (1,063 kB/s)     
  24. Selecting previously unselected package libncurses5-dev:amd64.
  25. (正在读取数据库 ... 系统当前共安装有 213031 个文件和目录。)
  26. Preparing to unpack .../libncurses5-dev_5.9+20140118-1ubuntu1_amd64.deb ...
  27. Unpacking libncurses5-dev:amd64 (5.9+20140118-1ubuntu1) ...
  28. 正在设置 libncurses5-dev:amd64 (5.9+20140118-1ubuntu1) ...
  29. senrsl@senrsl-ubuntu:~/android/source/kernel/goldfish$ make menuconfig
  30.   HOSTCC  scripts/kconfig/conf.o
  31.   HOSTCC  scripts/kconfig/lxdialog/checklist.o
  32.   HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  33.   HOSTCC  scripts/kconfig/lxdialog/menubox.o
  34.   HOSTCC  scripts/kconfig/lxdialog/textbox.o
  35.   HOSTCC  scripts/kconfig/lxdialog/util.o
  36.   HOSTCC  scripts/kconfig/lxdialog/yesno.o
  37.   HOSTCC  scripts/kconfig/mconf.o
  38.   HOSTCC  scripts/kconfig/zconf.tab.o
  39.   HOSTLD  scripts/kconfig/mconf
  40. scripts/kconfig/mconf Kconfig
  41. #
  42. # configuration written to .config
  43. #
  44. *** End of the configuration.
  45. *** Execute 'make' to start the build or try 'make help'.
  46. senrsl@senrsl-ubuntu:~/android/source/kernel/goldfish$ make
  47. 。。。。

这个地方的配置:
CONFIG_FRAMEBUFFER_CONSOLE:
Device Drivers ---> Graphics support ---> Console display driver support ---> Framebuffer Console support
CONFIG_LOGO:
Device Drivers ---> Graphics support ---> Bootup logo


make完成后使用,依旧是闪屏。。。。
//TODO 待解决的闪屏


②第二屏
默认不显示,开启了第一个的显示后显示了。
在android里改显示,位置在/home/senrsl/android/source/WORKING_DIRECTORY/system /core/init/init.c 第678行。
  1. "             你好,我是中文。 ";//A N D R O I D
用中文乱码,显示方块。。。。
  1. "             Hello,nice too meet you!\n\n\n\t\t\t Beijing ";//A N D R O I D


③第三屏
跟02的一样
动画位置
  1. /home/senrsl/android/source/WORKING_DIRECTORY/frameworks/base/core/res/assets/images/android-logo-mask.png
  2. /home/senrsl/android/source/WORKING_DIRECTORY/frameworks/base/core/res/assets/images/android-logo-shine.png
代码位置
  1. /home/senrsl/android/source/WORKING_DIRECTORY/frameworks/base/cmds/bootanimation/BootAnimation.cpp
这里面俩图片轮播是BootAnimation::android()这个方法,bootanimation.zip是bool BootAnimation::movie()这个方法,到底进哪个在bool BootAnimation::threadLoop()里进行判断。




3,系统UI定制
跟02相同
①SystemUI是
/home/senrsl/android/source/WORKING_DIRECTORY/frameworks/base/packages/SystemUI
这个是基本的UI相关


②设置是

/home/senrsl/android/source/WORKING_DIRECTORY/packages/apps/Settings



4,默认中文
文件
/home/senrsl/android/source/WORKING_DIRECTORY/build/target/product下的
full.mk或者full_base.mk
在后面增加
  1. #默认语言
  2. PRODUCT_LOCALES := zh_CN
如此

然后编译,清空用户数据启动
  1. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY$ emulator -wipe-data -kernel /home/senrsl/android/source/kernel/goldfish/arch/arm/boot/zImage &
效果


5,程序开机自启
①广播过滤
  1. /**
  2.  * 开机自启
  3.  * 1,写这个类监听开机广播
  4.  * 2,manifest里注册receiver事件
  5.  * 3,增加权限
  6.  *
  7.  * @ClassName: AutoBootReceiver
  8.  * @author senrsl
  9.  *
  10.  * @Package: dc.study
  11.  * @CreateTime: 2015-3-23 上午11:03:18
  12.  */
  13. public class AutoBootReceiver  extends BroadcastReceiver {
  14.     /*
  15.      * (non-Javadoc)
  16.      *
  17.      * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
  18.      * android.content.Intent)
  19.      */
  20.     @Override
  21.     public void onReceive(Context context, Intent intent) {
  22.         if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
  23.             Toast.makeText(context, "开机自启", Toast.LENGTH_LONG).show();
  24.             Intent mainActivityIntent = new Intent(context, WelcomeActivity.class);
  25.             mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  26.             context.startActivity(mainActivityIntent);
  27.         }
  28.     }
  29. }
②注册监听
android:priority="1000"为提升广播优先级,范围为-1000到+1000
  1.     <receiver android:name=".AutoBootReceiver" >
  2.             <intent-filter android:priority="1000">
  3.                 <action android:name="android.intent.action.BOOT_COMPLETED" />
  4.                 <category android:name="android.intent.category.HOME" />
  5.             </intent-filter>
  6.         </receiver>
③增加权限
  1.  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
上面的①和②可以改成这样,能省几行代码
①广播过滤
  1. /**
  2.  *
  3.  *
  4.  * @ClassName: AutoBootReceiver
  5.  * @author senrsl
  6.  *
  7.  * @Package: cn.senrsl.android.vsf.receiver
  8.  * @CreateTime: 2015-3-25 下午5:25:49
  9.  */
  10. public class AutoBootReceiver extends BroadcastReceiver {
  11.     /* (non-Javadoc)
  12.      * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
  13.      */
  14.     @Override
  15.     public void onReceive(Context context, Intent intent) {
  16.         Logger.w("开机自启");
  17.         //此处启动数据本地支持
  18.     }
  19. }

②注册监听
  1.         <receiver android:name=".receiver.AutoBootReceiver" >
  2.             <intent-filter android:priority="1000" >
  3.                 <action android:name="android.intent.action.BOOT_COMPLETED" />
  4.                 <category android:name="android.intent.category.LAUNCHER" />
  5.             </intent-filter>
  6.         </receiver>


6,源码下编译apk
①eclipse项目,把项目放进
/home/senrsl/android/source/WORKING_DIRECTORY/packages/apps/
②删除bin和gen之类的缓存,查看当前结构
  1. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/packages/apps/secondHallo$ ll
  2. 总用量 64
  3. drwxrwxr-x  5 senrsl senrsl  4096  3月 23 14:38 ./
  4. drwxrwxr-x 47 senrsl senrsl  4096  3月 23 13:42 ../
  5. -rw-rw-r--  1 senrsl senrsl  1495  3月 23 11:31 AndroidManifest.xml
  6. -rw-rw-r--  1 senrsl senrsl   350  3月 23 14:38 Android.mk
  7. -rw-rw-r--  1 senrsl senrsl   350  3月 23 14:38 Android.mk~
  8. -rw-rw-r--  1 senrsl senrsl   466 12月 15 15:25 .classpath
  9. -rw-rw-r--  1 senrsl senrsl  2227  3月 20 13:37 CleanSpec.mk
  10. -rw-rw-r--  1 senrsl senrsl     0  3月 20 13:37 MODULE_LICENSE_APACHE2
  11. -rw-rw-r--  1 senrsl senrsl 10695  3月 20 13:37 NOTICE
  12. -rw-rw-r--  1 senrsl senrsl  1248 12月 15 15:25 proguard.cfg
  13. -rw-rw-r--  1 senrsl senrsl   847 12月 15 15:25 .project
  14. -rw-rw-r--  1 senrsl senrsl   361 12月 15 15:25 project.properties
  15. drwxrwxr-x  7 senrsl senrsl  4096 12月 15 15:25 res/
  16. drwxrwxr-x  2 senrsl senrsl  4096 12月 15 15:25 .settings/
  17. drwxrwxr-x  3 senrsl senrsl  4096 12月 15 15:25 src/
上面那些~跟.*的也可以删。。。。
③创建Android.mk
  1. LOCAL_PATH:= $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_MODULE_TAGS := optional
  4. LOCAL_SRC_FILES := $(call all-java-files-under, src)
  5. LOCAL_PACKAGE_NAME := secondHallo
  6. LOCAL_SDK_VERSION := current
  7. LOCAL_CERTIFICATE := platform
  8. LOCAL_PROGUARD_FLAG_FILES := proguard.cfg
  9. include $(BUILD_PACKAGE)
  10. include $(call all-makefiles-under,$(LOCAL_PATH))
其他的如CleanSpec.mk跟MODULE_LICENSE_APACHE2还有NOTICE什么的都可以无视。
④执行编译
  1. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/packages/apps/secondHallo$ mm
  2. ============================================
  3. PLATFORM_VERSION_CODENAME=REL
  4. PLATFORM_VERSION=4.4.2
  5. TARGET_PRODUCT=aosp_arm
  6. TARGET_BUILD_VARIANT=eng
  7. TARGET_BUILD_TYPE=release
  8. TARGET_BUILD_APPS=
  9. TARGET_ARCH=arm
  10. TARGET_ARCH_VARIANT=armv7-a
  11. TARGET_CPU_VARIANT=generic
  12. HOST_ARCH=x86
  13. HOST_OS=linux
  14. HOST_OS_EXTRA=Linux-3.13.0-37-generic-x86_64-with-Ubuntu-14.04-trusty
  15. HOST_BUILD_TYPE=release
  16. BUILD_ID=KVT49L
  17. OUT_DIR=out
  18. ============================================
  19. make:进入目录'/home/senrsl/android/source /WORKING_DIRECTORY'
  20. Proguard: out/target/common/obj/APPS/secondHallo_intermediates/proguard.classes.jar
  21. ProGuard, version 4.4
  22. Reading input...
  23. Reading program jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/APPS/secondHallo_intermediates/classes.jar]
  24. Reading library jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jar]
  25. Initializing...
  26. Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
  27. Note: there were 1 references to unknown classes.
  28.       You should check your configuration for typos.
  29. Ignoring unused library classes...
  30.   Original number of library classes: 3412
  31.   Final number of library classes:    3412
  32. Shrinking...
  33. Removing unused program classes and class elements...
  34.   Original number of program classes: 15
  35.   Final number of program classes:    8
  36. Writing output...
  37. Preparing output jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/APPS/secondHallo_intermediates/proguard.classes.jar]
  38.   Copying resources from program jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/APPS/secondHallo_intermediates/classes.jar]
  39. target Dex: secondHallo
  40. Copying: out/target/common/obj/APPS/secondHallo_intermediates/classes.dex
  41. target Package: secondHallo (out/target/product/generic/obj/APPS/secondHallo_intermediates/package.apk)
  42. Warning: AndroidManifest.xml already defines versionCode (in http://schemas.android.com/apk/res/android); using existing value in manifest.
  43. Warning: AndroidManifest.xml already defines versionName (in http://schemas.android.com/apk/res/android); using existing value in manifest.
  44. Warning: AndroidManifest.xml already defines minSdkVersion (in http://schemas.android.com/apk/res/android); using existing value in manifest.
  45. Processing target/product/generic/obj/APPS/secondHallo_intermediates/package.apk
  46. Done!
  47. Install: out/target/product/generic/system/app/secondHallo.odex
  48. Notice file: packages/apps/secondHallo/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/app/secondHallo.apk.txt
  49. Install: out/target/product/generic/system/app/secondHallo.apk
  50. make:离开目录"/home/senrsl/android/source /WORKING_DIRECTORY"senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/packages/apps/secondHallo$ mm
  51. ============================================
  52. PLATFORM_VERSION_CODENAME=REL
  53. PLATFORM_VERSION=4.4.2
  54. TARGET_PRODUCT=aosp_arm
  55. TARGET_BUILD_VARIANT=eng
  56. TARGET_BUILD_TYPE=release
  57. TARGET_BUILD_APPS=
  58. TARGET_ARCH=arm
  59. TARGET_ARCH_VARIANT=armv7-a
  60. TARGET_CPU_VARIANT=generic
  61. HOST_ARCH=x86
  62. HOST_OS=linux
  63. HOST_OS_EXTRA=Linux-3.13.0-37-generic-x86_64-with-Ubuntu-14.04-trusty
  64. HOST_BUILD_TYPE=release
  65. BUILD_ID=KVT49L
  66. OUT_DIR=out
  67. ============================================
  68. make:进入目录'/home/senrsl/android/source /WORKING_DIRECTORY'
  69. Proguard: out/target/common/obj/APPS/secondHallo_intermediates/proguard.classes.jar
  70. ProGuard, version 4.4
  71. Reading input...
  72. Reading program jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/APPS/secondHallo_intermediates/classes.jar]
  73. Reading library jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jar]
  74. Initializing...
  75. Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
  76. Note: there were 1 references to unknown classes.
  77.       You should check your configuration for typos.
  78. Ignoring unused library classes...
  79.   Original number of library classes: 3412
  80.   Final number of library classes:    3412
  81. Shrinking...
  82. Removing unused program classes and class elements...
  83.   Original number of program classes: 15
  84.   Final number of program classes:    8
  85. Writing output...
  86. Preparing output jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/APPS/secondHallo_intermediates/proguard.classes.jar]
  87.   Copying resources from program jar [/home/senrsl/android/source/WORKING_DIRECTORY/out/target/common/obj/APPS/secondHallo_intermediates/classes.jar]
  88. target Dex: secondHallo
  89. Copying: out/target/common/obj/APPS/secondHallo_intermediates/classes.dex
  90. target Package: secondHallo (out/target/product/generic/obj/APPS/secondHallo_intermediates/package.apk)
  91. Warning: AndroidManifest.xml already defines versionCode (in http://schemas.android.com/apk/res/android); using existing value in manifest.
  92. Warning: AndroidManifest.xml already defines versionName (in http://schemas.android.com/apk/res/android); using existing value in manifest.
  93. Warning: AndroidManifest.xml already defines minSdkVersion (in http://schemas.android.com/apk/res/android); using existing value in manifest.
  94. Processing target/product/generic/obj/APPS/secondHallo_intermediates/package.apk
  95. Done!
  96. Install: out/target/product/generic/system/app/secondHallo.odex
  97. Notice file: packages/apps/secondHallo/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src//system/app/secondHallo.apk.txt
  98. Install: out/target/product/generic/system/app/secondHallo.apk
  99. make:离开目录"/home/senrsl/android/source /WORKING_DIRECTORY"
⑤查看结果
生成的结果在
/home/senrsl/android/source/WORKING_DIRECTORY/out/target/product/generic/system/app/secondHallo.apk
可以直接安装
  1. senrsl@senrsl-ubuntu:~/android/source/WORKING_DIRECTORY/out/target/product/generic/system/app$ adb install secondHallo.apk
  2. 283 KB/s (13565 bytes in 0.046s)
  3.     pkg: /data/local/tmp/secondHallo.apk
  4. Success
⑥注意:中文乱码
项目应使用UTF-8编码,若使用GBK编码,中文会全部乱码。

7,预装软件
A,预装apk
①基于源码的预装
之前的配置基于6,源码下编译apk
默认的,编译完成后make -16源码不会把软件预装,这需要配置。
默认的/home/senrsl/android/source/WORKING_DIRECTORY/packages/apps下的大部分 app都在
/home/senrsl/android/source/WORKING_DIRECTORY/build/target/product /sdk.mk文件配置;
把secondHallo放进去发现不行,然后发现这个目录改过默认语言,是full.mk,在里面引用了emulator.mk
那就在emulator.mk里加试试
  1. # Host modules
  2. PRODUCT_PACKAGES += \
  3.     emulator \
  4.     emulator-x86 \
  5.     emulator-arm \
  6.     emulator-mips \
  7.     emulator64-x86 \
  8.     emulator64-arm \
  9.     emulator64-mips \
  10.     libOpenglRender \
  11.     libGLES_CM_translator \
  12.     libGLES_V2_translator \
  13.     libEGL_translator \
  14.     lib64OpenglRender \
  15.     lib64GLES_CM_translator \
  16.     lib64GLES_V2_translator \
  17.     lib64EGL_translator \
  18.     secondHallo
重新make -j16启动发现可行。
这个方案并不合适,应该根据实际情况来改,大致就是这么个意思。

②基于apk的预装
还是上面那个emulator.mk,后面增加
  1. PRODUCT_COPY_FILES += \
  2.     device/generic/goldfish/fstab.goldfish:root/fstab.goldfish \
  3.     device/generic/goldfish/init.goldfish.rc:root/init.goldfish.rc \
  4.     device/generic/goldfish/init.goldfish.sh:system/etc/init.goldfish.sh \
  5.     device/generic/goldfish/ueventd.goldfish.rc:root/ueventd.goldfish.rc \
  6.     vendor/SENRSL/emulator/apk/TestVD_Thread.apk:system/app/TestVD_Thread.apk
执行make -j16,报错
  1. build/core/Makefile:32: *** Prebuilt apk found in PRODUCT_COPY_FILES: vendor/SENRSL/emulator/apk/TestVD_Thread.apk:system/app/TestVD_Thread.apk, use BUILD_PREBUILT instead!。 停止。
这个问题,改这个文件/home/senrsl/android/source/WORKING_DIRECTORY/build/core /Makefile,第22行开始
加注释:
  1. #取消
  2. #拷贝文件如果是apk,报错
  3. #define check-product-copy-files
  4. #$(if $(filter %.apk, $(1)),$(error \
  5. #    Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!))

没有评论 :

发表评论