最近回顾的一些知识,补充了一下。
源码标准:API : 29「Android 10.0」
android手机是怎么开机的?
android 的底层是 linux kernel「内核」,由 BootLoader「系统启动加载器」 负责加载(类似于计算机的BIOS系统)。
/bootable/recovery/bootloader.h
首先启动 init「父进程,第一个进程」进程,接着运行init.rc脚本,脚本文件有个命令启动了Zygote进程,初始化时会启动虚拟机。
/system/core/rootdir/init.zygote.rc

Zygote进程fork出SystemServer进程,然后会调用SystemServer.main()方法。
/frameworks/base/services/java/com/android/server/SystemService.java
/** The main entry point from zygote.*/
public static void main(String[] args) {
new SystemServer().run();
}
run方法中,主要是在进程中启动系统的各项服务,比如ActivityManagerService,PackageManagerService,WindowManagerService服务等。
private void run() {
//创建主线程Looper、ActivityThread、SystemContext
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_FOREGROUND);
Looper.prepareMainLooper();
// Initialize native services.
System.loadLibrary("android_servers");
// Initialize the system context.
createSystemContext();
// Create the system service manager.
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.setStartInfo(mRuntimeRestart,mRuntimeStartElapsedTime, mRuntimeStartUptime);
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
// 并行线程池
SystemServerInitThreadPool.get();
// Start services.
traceBeginAndSlog("StartServices");
startBootstrapServices();
startCoreServices();
startOtherServices();
// Loop forever.
Looper.loop();
}
下面是一些主要的初始化方法。
/**
* 这些服务具有复杂的相互依赖关系,所以需要放一起全部初始化
*/
private void startBootstrapServices() {
// Start the watchdog as early as possible so we can crash the system server
final Watchdog watchdog = Watchdog.getInstance();
watchdog.start();
//启动AMS
ActivityTaskManagerService atm = mSystemServiceManager.startService(
ActivityTaskManagerService.Lifecycle.class).getService();
mActivityManagerService = ActivityManagerService.Lifecycle.startService(
mSystemServiceManager, atm);
//电源管理器需要提前启动,因为其他服务需要它
mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
// Start the package manager.
mPackageManagerService = PackageManagerService.main(mSystemContext, installer,
mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore);
//设置Application实例并开始
mActivityManagerService.setSystemProcess();
//使用 ActivityManager 实例完成看门狗设置并监听重启
watchdog.init(context, mActivityManagerService);
}
真正启动是在ActivityManagerService的中systemReady方法,调用resumeTopActivityLocked打开锁屏界面。
/**
* Starts a miscellaneous grab bag of stuff that has yet to be refactored and organized.
*/
private void startOtherServices() {
//启动WMS
wm = WindowManagerService.main();
mActivityManagerService.setWindowManager(wm);
//WMS 显示默认启动消息
ActivityManagerNative.getDefault().showBootMessage();
//开始启动初始应用程序
mActivityManagerService.systemReady(new Runnable(){
//SystemUI
startSystemUi(context, windowManagerF);
});
}
/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
/** 通过StackSupervisor运行所有 ActivityStacks */
final ActivityStackSupervisor mStackSupervisor;
public void systemReady(final Runnable goingCallback, TimingsTraceLog traceLog) {
mStackSupervisor.resumeFocusedStackTopActivityLocked();
}
到这里,android的开机流程结束。
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA
我早就知道Ruby中的“常量”(即大写的变量名)不是真正常量。与其他编程语言一样,对对象的引用是唯一存储在变量/常量中的东西。(侧边栏:Ruby确实具有“卡住”引用对象不被修改的功能,据我所知,许多其他语言都没有提供这种功能。)所以这是我的问题:当您将一个值重新分配给常量时,您会收到如下警告:>>FOO='bar'=>"bar">>FOO='baz'(irb):2:warning:alreadyinitializedconstantFOO=>"baz"有没有办法强制Ruby抛出异常而不是打印警告?很难弄清楚为什么有时会发生重新分配。 最佳答案
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我正在尝试将$stdout设置为临时写入一个文件,然后返回到一个文件。test.rb:old_stdout=$stdout$stdout.reopen("mytestfile.out",'w+')puts"thisgoesinmytestfile"$stdout=old_stdoutputs"thisshouldbeontheconsole"$stdout.reopen("mytestfile1.out",'w+')puts"thisgoesinmytestfile1:"$stdout=old_stdoutputs"thisshouldbebackontheconsole"这是输出。r
我有一个super简单的脚本,它几乎包含了FayeWebSocketGitHub页面上用于处理关闭连接的内容:ws=Faye::WebSocket::Client.new(url,nil,:headers=>headers)ws.on:opendo|event|p[:open]#sendpingcommand#sendtestcommand#ws.send({command:'test'}.to_json)endws.on:messagedo|event|#hereistheentrypointfordatacomingfromtheserver.pJSON.parse(event.d
例如,假设我有一个名为Products的模型,并且在ProductsController中,我有以下代码用于product_listView以显示已排序的产品。@products=Product.order(params[:order_by])让我们想象一下,在product_listView中,用户可以使用下拉菜单按价格、评级、重量等进行排序。数据库中的产品不会经常更改。我很难理解的是,每次用户选择新的order_by过滤器时,rails是否必须查询,或者rails是否能够以某种方式缓存事件记录以在服务器端重新排序?有没有一种方法可以编写它,以便在用户排序时rails不会重新查询结果
我已经按照https://github.com/wayneeseguin/rvm#installation上的说明通过RVM安装了Ruby.有关信息,我有所有文件(readline-5.2.tar.gz、readline-6.2.tar.gz、ruby-1.9.3-p327.tar.bz2、rubygems-1.8.24.tgz、wayneeseguin-rvm-stable.tgz和yaml-0.1.4.tar.gz)在~/.rvm/archives目录中,我不想在任何目录中重新下载它们方式。当我这样做时:sudo/usr/bin/apt-getinstallbuild-essent
关闭。这个问题是off-topic.它目前不接受答案。想改进这个问题吗?Updatethequestion所以它是on-topic用于堆栈溢出。关闭10年前。ImprovethisquestionLinux专家正在转向Mac(10.8)。因为我懒...我使用MacPorts安装MacVim。它似乎安装没有错误。我只需要mvim中的python、ruby和perl支持。$/opt/local/bin/mvim--version|egrep'patches|python|ruby|perl'Includedpatches:1-244,246-646+multi_lang-mzscheme+
我是一名前PHP开发人员,正在学习Rails和Sinatra。在PHP中,每个页面请求都会加载所有必需的文件。如果我更改了一些代码并刷新了页面,我可以确定代码是新的。在Rails3中,Controller代码在每次请求时都是最新的。但是,如果我修改/lib文件夹中的任何代码,我需要重新启动服务器以使更改生效。为什么会这样?这与Ruby的设计方式有关吗?Rails是否进行了一些优化以避免在每次请求时重新加载代码?谢谢!编辑:我最感兴趣的是幕后发生的事情。像Rails和Sinatra这样的框架是否为类做了一些特殊的缓存?如果是这样,他们做什么?Ruby中的默认行为是在每次请求时重新加载所有