今天像往常一样上班,太阳照常东升西落,这两天深圳有台风,雨一直下,一大早上班路上各种堵,来到公司,打开我的电脑,这就是我吃饭的家伙,呵呵。公司电脑的配置还可以,不过硬盘不像我家里的,要是能搞个固态硬盘,那就绝对爽了,运行超流畅!
继续处理bug,天天有解不完的bug…………
先在framework层加上几句日志,然后编译service.jar,push,reboot,等着……不对啊,之前reboot一会就进入开机界面了,今天这是咋回事,一直在转圈,难道昨晚更新代码重新编译有问题?首先,从现象上和正常启动时进行对比,正常启动时的界面是这样的:eui界面加载,完成后,显示“正在优化第几个应用”,优化完成后,显示“正在启动应用”,就直接开机进入桌面了;而现在的情况是eui加载,加载完成后,界面就直接显示“正在启动应用”了。中间的过程全部没了。
好了,有了现象,就可以进一步查找原因了。我们来看一下代码执行,显示“正在优化第几个应用”的逻辑是在PackageManagerService类中的performBootDexOpt方法中的,该方法的代码如下:
private void performBootDexOpt(PackageParser.Package pkg, int curr, int total) {
if (DEBUG_DEXOPT) {
Log.i(TAG, "Optimizing app " + curr + " of " + total + ": " + pkg.packageName);
}
if (!isFirstBoot()) {
try {
ActivityManagerNative.getDefault().showBootMessage(
mContext.getResources().getString(R.string.android_upgrading_apk,
curr, total), true);
} catch (RemoteException e) {
}
}
PackageParser.Package p = pkg;
synchronized (mInstallLock) {
mPackageDexOptimizer.performDexOpt(p, null /* instruction sets */,
false /* force dex */, false /* defer */, true /* include dependencies */,
false /* boot complete */);
}
}
这个方法的逻辑也比较简单,通过isFirstBoot()方法判断当前是不是手机系统当前是不是首次加载,isFirstBoot()的实现也很简单,就是返回mRestoredSettings的值,mRestoredSettings则是在PackageManagerService的构造方法中初始化的,具体的PackageManagerService构造方法的代码就不贴出来了,mRestoredSettings = mSettings.readLPw(this, sUserManager.getUsers(false), mSdkVersion, mOnlyCore),mRestoredSettings的值只会在这里赋值一次,没有其它地方修改,意思也很明了,当构造PackageManagerService对象时候,我们肯定已经知道系统当前是否是首次初始化了。
显示“正在启动应用”的界面是SystemServer类的startOtherServices方法中执行的,该方法的代码如下:
private void startOtherServices() {
final Context context = mSystemContext;
AccountManagerService accountManager = null;
ContentService contentService = null;
VibratorService vibrator = null;
IAlarmManager alarm = null;
IMountService mountService = null;
NetworkManagementService networkManagement = null;
NetworkStatsService networkStats = null;
NetworkPolicyManagerService networkPolicy = null;
ConnectivityService connectivity = null;
NetworkScoreService networkScore = null;
NsdService serviceDiscovery= null;
WindowManagerService wm = null;
UsbService usb = null;
SerialService serial = null;
NetworkTimeUpdateService networkTimeUpdater = null;
CommonTimeManagementService commonTimeMgmtService = null;
AlipayCaService alipayCaManager = null;
InputManagerService inputManager = null;
TelephonyRegistry telephonyRegistry = null;
ConsumerIrService consumerIr = null;
AudioService audioService = null;
MmsServiceBroker mmsService = null;
EntropyMixer entropyMixer = null;
CameraService cameraService = null;
//modify by liujf for letv mute key
MuteKeyObserver mute = null;
//modify by liujf end
boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false);
boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
boolean disableAtlas = SystemProperties.getBoolean("config.disable_atlas", true);
try {
Slog.i(TAG, "Reading configuration...");
SystemConfig.getInstance();
Slog.i(TAG, "Scheduling Policy");
ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
mSystemServiceManager.startService(TelecomLoaderService.class);
Slog.i(TAG, "Telephony Registry");
telephonyRegistry = new TelephonyRegistry(context);
ServiceManager.addService("telephony.registry", telephonyRegistry);
Slog.i(TAG, "Entropy Mixer");
entropyMixer = new EntropyMixer(context);
mContentResolver = context.getContentResolver();
Slog.i(TAG, "Camera Service");
mSystemServiceManager.startService(CameraService.class);
// The AccountManager must come before the ContentService
try {
// TODO: seems like this should be disable-able, but req'd by ContentService
Slog.i(TAG, "Account Manager");
accountManager = new AccountManagerService(context);
ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
} catch (Throwable e) {
Slog.e(TAG, "Failure starting Account Manager", e);
}
Slog.i(TAG, "Content Manager");
contentService = ContentService.main(context,
mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL);
Slog.i(TAG, "System Content Providers");
mActivityManagerService.installSystemProviders();
Slog.i(TAG, "Vibrator Service");
vibrator = new VibratorService(context);
ServiceManager.addService("vibrator", vibrator);
Slog.i(TAG, "Consumer IR Service");
consumerIr = new ConsumerIrService(context);
ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
mSystemServiceManager.startService(AlarmManagerService.class);
alarm = IAlarmManager.Stub.asInterface(
ServiceManager.getService(Context.ALARM_SERVICE));
Slog.i(TAG, "Init Watchdog");
final Watchdog watchdog = Watchdog.getInstance();
watchdog.init(context, mActivityManagerService);
if (SystemProperties.get("ro.alipay.fp.version").equals("ifaa_1.0")) {
Slog.i(TAG, "AlipayCa Manager");
alipayCaManager = new AlipayCaService(context);
ServiceManager.addService(Context.ALIPAY_CA_SERVICE, alipayCaManager);
}
Slog.i(TAG, "Input Manager");
inputManager = new InputManagerService(context);
Slog.i(TAG, "Window Manager");
wm = WindowManagerService.main(context, inputManager,
mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL,
!mFirstBoot, mOnlyCore);
ServiceManager.addService(Context.WINDOW_SERVICE, wm);
ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
mActivityManagerService.setWindowManager(wm);
inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
inputManager.start();
// TODO: Use service dependencies instead.
mDisplayManagerService.windowManagerAndInputReady();
// Skip Bluetooth if we have an emulator kernel
// TODO: Use a more reliable check to see if this product should
// support Bluetooth - see bug 988521
if (isEmulator) {
Slog.i(TAG, "No Bluetooh Service (emulator)");
} else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
Slog.i(TAG, "No Bluetooth Service (factory test)");
} else if (!context.getPackageManager().hasSystemFeature
(PackageManager.FEATURE_BLUETOOTH)) {
Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
} else if (disableBluetooth) {
Slog.i(TAG, "Bluetooth Service disabled by config");
} else {
Slog.i(TAG, "Bluetooth Service");
mSystemServiceManager.startService(BluetoothService.class);
}
} catch (RuntimeException e) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting core service", e);
}
StatusBarManagerService statusBar = null;
INotificationManager notification = null;
InputMethodManagerService imm = null;
WallpaperManagerService wallpaper = null;
LocationManagerService location = null;
CountryDetectorService countryDetector = null;
TextServicesManagerService tsms = null;
LockSettingsService lockSettings = null;
AssetAtlasService atlas = null;
MediaRouterService mediaRouter = null;
//[+LEUI][nietong] added: perfboost
IPerfServiceManager perfServiceMgr = null;
//[-LEUI]
//+LEUI [REQ][LEUI-6586][fengzihua] added: add service for read key
PhoneBindService phoneBind = null;
//-LEUI
//+LEUI [REQ][MOBILEP-9892][baopengli] added: add service for color mode
ColorModeService colorMode = null;
//-LEUI
// Bring up services needed for UI.
if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
try {
Slog.i(TAG, "Input Method Service");
imm = new InputMethodManagerService(context, wm);
ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
} catch (Throwable e) {
reportWtf("starting Input Manager Service", e);
}
try {
Slog.i(TAG, "Accessibility Manager");
ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
new AccessibilityManagerService(context));
} catch (Throwable e) {
reportWtf("starting Accessibility Manager", e);
}
try {
Slog.i(TAG, "Audio Service");
audioService = new AudioService(context);
ServiceManager.addService(Context.AUDIO_SERVICE, audioService);
} catch (Throwable e) {
reportWtf("starting Audio Service", e);
}
}
try {
wm.displayReady();
} catch (Throwable e) {
reportWtf("making display ready", e);
}
Slog.i(TAG, "WindowManager display ready");
SystemProperties.set("service.display.ready", "1");
if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
if (!disableStorage &&
!"0".equals(SystemProperties.get("system_init.startmountservice"))) {
try {
/*
* NotificationManagerService is dependant on MountService,
* (for media / usb notifications) so we must start MountService first.
*/
mSystemServiceManager.startService(MOUNT_SERVICE_CLASS);
mountService = IMountService.Stub.asInterface(
ServiceManager.getService("mount"));
} catch (Throwable e) {
reportWtf("starting Mount Service", e);
}
}
}
// We start this here so that we update our configuration to set watch or television
// as appropriate.
mSystemServiceManager.startService(UiModeManagerService.class);
try {
mPackageManagerService.performBootDexOpt();
} catch (Throwable e) {
reportWtf("performing boot dexopt", e);
}
try {
ActivityManagerNative.getDefault().showBootMessage(
context.getResources().getText(
com.android.internal.R.string.android_upgrading_starting_apps),
false);
} catch (RemoteException e) {
}
//+LEUI [REQ][LEUI-6586][fengzihua] added: add service for read key
try {
Slog.i(TAG, "PhoneBindService");
phoneBind = new PhoneBindService(context);
ServiceManager.addService("leuiphonebind", phoneBind);
} catch (Throwable e) {
reportWtf("starting phoneBind service", e);
}
//-LEUI
//+LEUI [REQ][MOBILEP-9892][baopengli] added: add service for color mode
try {
Slog.i(TAG, "ColorMode");
colorMode = new ColorModeService(context);
ServiceManager.addService("leuicolormode", colorMode);
} catch (Throwable e) {
reportWtf("starting colorMode service", e);
}
//-LEUI
if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
if (!disableNonCoreServices) {
try {
Slog.i(TAG, "LockSettingsService");
lockSettings = new LockSettingsService(context);
ServiceManager.addService("lock_settings", lockSettings);
} catch (Throwable e) {
reportWtf("starting LockSettingsService service", e);
}
if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
mSystemServiceManager.startService(PersistentDataBlockService.class);
}
mSystemServiceManager.startService(DeviceIdleController.class);
// Always start the Device Policy Manager, so that the API is compatible with
// API8.
mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
}
if (!disableSystemUI) {
try {
Slog.i(TAG, "Status Bar");
statusBar = new StatusBarManagerService(context, wm);
ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
} catch (Throwable e) {
reportWtf("starting StatusBarManagerService", e);
}
}
if (!disableNonCoreServices) {
try {
Slog.i(TAG, "Clipboard Service");
ServiceManager.addService(Context.CLIPBOARD_SERVICE,
new ClipboardService(context));
} catch (Throwable e) {
reportWtf("starting Clipboard Service", e);
}
//[+LEUI-16185][dongshangyong] add: for system cliboard feature.
try {
Slog.i(TAG, "LeClipboard Manager Service");
ServiceManager.addService(Context.LE_CLIPBOARD_SERVICE,
new com.letv.leui.server.clipboard.LeClipboardManagerService(context));
} catch (Throwable e) {
reportWtf("starting LeClipboard Service", e);
}
//[-LEUI]
}
if (!disableNetwork) {
try {
Slog.i(TAG, "NetworkManagement Service");
networkManagement = NetworkManagementService.create(context);
ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
} catch (Throwable e) {
reportWtf("starting NetworkManagement Service", e);
}
}
if (!disableNonCoreServices) {
try {
Slog.i(TAG, "Text Service Manager Service");
tsms = new TextServicesManagerService(context);
ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
} catch (Throwable e) {
reportWtf("starting Text Service Manager Service", e);
}
}
if (!disableNetwork) {
try {
Slog.i(TAG, "Network Score Service");
networkScore = new NetworkScoreService(context);
ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
} catch (Throwable e) {
reportWtf("starting Network Score Service", e);
}
try {
Slog.i(TAG, "NetworkStats Service");
networkStats = new NetworkStatsService(context, networkManagement, alarm);
ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
} catch (Throwable e) {
reportWtf("starting NetworkStats Service", e);
}
try {
Slog.i(TAG, "NetworkPolicy Service");
networkPolicy = new NetworkPolicyManagerService(
context, mActivityManagerService,
(IPowerManager)ServiceManager.getService(Context.POWER_SERVICE),
networkStats, networkManagement);
ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
} catch (Throwable e) {
reportWtf("starting NetworkPolicy Service", e);
}
mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
mSystemServiceManager.startService(
"com.android.server.wifi.WifiScanningService");
mSystemServiceManager.startService("com.android.server.wifi.RttService");
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) ||
mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
}
try {
Slog.i(TAG, "Connectivity Service");
connectivity = new ConnectivityService(
context, networkManagement, networkStats, networkPolicy);
ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
networkStats.bindConnectivityManager(connectivity);
networkPolicy.bindConnectivityManager(connectivity);
} catch (Throwable e) {
reportWtf("starting Connectivity Service", e);
}
try {
Slog.i(TAG, "Network Service Discovery Service");
serviceDiscovery = NsdService.create(context);
ServiceManager.addService(
Context.NSD_SERVICE, serviceDiscovery);
} catch (Throwable e) {
reportWtf("starting Service Discovery Service", e);
}
}
if (!disableNonCoreServices) {
try {
Slog.i(TAG, "UpdateLock Service");
ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
new UpdateLockService(context));
} catch (Throwable e) {
reportWtf("starting UpdateLockService", e);
}
}
/*
* MountService has a few dependencies: Notification Manager and
* AppWidget Provider. Make sure MountService is completely started
* first before continuing.
*/
if (mountService != null && !mOnlyCore) {
try {
mountService.waitForAsecScan();
} catch (RemoteException ignored) {
}
}
try {
if (accountManager != null)
accountManager.systemReady();
} catch (Throwable e) {
reportWtf("making Account Manager Service ready", e);
}
try {
if (contentService != null)
contentService.systemReady();
} catch (Throwable e) {
reportWtf("making Content Service ready", e);
}
mSystemServiceManager.startService(NotificationManagerService.class);
notification = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
networkPolicy.bindNotificationManager(notification);
mSystemServiceManager.startService(DeviceStorageMonitorService.class);
if (!disableLocation) {
try {
Slog.i(TAG, "Location Manager");
location = new LocationManagerService(context);
ServiceManager.addService(Context.LOCATION_SERVICE, location);
} catch (Throwable e) {
reportWtf("starting Location Manager", e);
}
try {
Slog.i(TAG, "Country Detector");
countryDetector = new CountryDetectorService(context);
ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
} catch (Throwable e) {
reportWtf("starting Country Detector", e);
}
}
if (!disableNonCoreServices) {
try {
Slog.i(TAG, "Search Service");
ServiceManager.addService(Context.SEARCH_SERVICE,
new SearchManagerService(context));
} catch (Throwable e) {
reportWtf("starting Search Service", e);
}
}
try {
Slog.i(TAG, "DropBox Service");
ServiceManager.addService(Context.DROPBOX_SERVICE,
new DropBoxManagerService(context, new File("/data/system/dropbox")));
} catch (Throwable e) {
reportWtf("starting DropBoxManagerService", e);
}
if (!disableNonCoreServices && context.getResources().getBoolean(
R.bool.config_enableWallpaperService)) {
try {
Slog.i(TAG, "Wallpaper Service");
wallpaper = new WallpaperManagerService(context);
ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
} catch (Throwable e) {
reportWtf("starting Wallpaper Service", e);
}
}
if (!disableNonCoreServices) {
mSystemServiceManager.startService(DockObserver.class);
}
try {
Slog.i(TAG, "Wired Accessory Manager");
// Listen for wired headset changes
inputManager.setWiredAccessoryCallbacks(
new WiredAccessoryManager(context, inputManager));
} catch (Throwable e) {
reportWtf("starting WiredAccessoryManager", e);
}
if (!disableNonCoreServices) {
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
// Start MIDI Manager service
mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
|| mPackageManager.hasSystemFeature(
PackageManager.FEATURE_USB_ACCESSORY)) {
// Manage USB host and device support
mSystemServiceManager.startService(USB_SERVICE_CLASS);
}
try {
Slog.i(TAG, "Serial Service");
// Serial port support
serial = new SerialService(context);
ServiceManager.addService(Context.SERIAL_SERVICE, serial);
} catch (Throwable e) {
Slog.e(TAG, "Failure starting SerialService", e);
}
}
try {
Slog.i(TAG, "Mute Observer");
// Listen for hall station changes
mute = new MuteKeyObserver(context);
} catch (Throwable e) {
reportWtf("starting MuteKeyObserver", e);
}
mSystemServiceManager.startService(TwilightService.class);
mSystemServiceManager.startService(JobSchedulerService.class);
if (!disableNonCoreServices) {
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) {
mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) {
mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS);
}
if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) {
Slog.i(TAG, "Gesture Launcher Service");
mSystemServiceManager.startService(GestureLauncherService.class);
}
}
try {
Slog.i(TAG, "DiskStats Service");
ServiceManager.addService("diskstats", new DiskStatsService(context));
} catch (Throwable e) {
reportWtf("starting DiskStats Service", e);
}
try {
// need to add this service even if SamplingProfilerIntegration.isEnabled()
// is false, because it is this service that detects system property change and
// turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
// there is little overhead for running this service.
Slog.i(TAG, "SamplingProfiler Service");
ServiceManager.addService("samplingprofiler",
new SamplingProfilerService(context));
} catch (Throwable e) {
reportWtf("starting SamplingProfiler Service", e);
}
if (!disableNetwork && !disableNetworkTime) {
try {
Slog.i(TAG, "NetworkTimeUpdateService");
networkTimeUpdater = new NetworkTimeUpdateService(context);
} catch (Throwable e) {
reportWtf("starting NetworkTimeUpdate service", e);
}
}
try {
Slog.i(TAG, "CommonTimeManagementService");
commonTimeMgmtService = new CommonTimeManagementService(context);
ServiceManager.addService("commontime_management", commonTimeMgmtService);
} catch (Throwable e) {
reportWtf("starting CommonTimeManagementService service", e);
}
if (!disableNetwork) {
try {
Slog.i(TAG, "CertBlacklister");
CertBlacklister blacklister = new CertBlacklister(context);
} catch (Throwable e) {
reportWtf("starting CertBlacklister", e);
}
}
if (!disableNonCoreServices) {
// Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
mSystemServiceManager.startService(DreamManagerService.class);
}
if (!disableNonCoreServices && !disableAtlas) {
try {
Slog.i(TAG, "Assets Atlas Service");
atlas = new AssetAtlasService(context);
ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
} catch (Throwable e) {
reportWtf("starting AssetAtlasService", e);
}
}
if (!disableNonCoreServices) {
ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE,
new GraphicsStatsService(context));
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
}
mSystemServiceManager.startService(RestrictionsManagerService.class);
mSystemServiceManager.startService(MediaSessionService.class);
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
mSystemServiceManager.startService(HdmiControlService.class);
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) {
mSystemServiceManager.startService(TvInputManagerService.class);
}
if (!disableNonCoreServices) {
try {
Slog.i(TAG, "Media Router Service");
mediaRouter = new MediaRouterService(context);
ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
} catch (Throwable e) {
reportWtf("starting MediaRouterService", e);
}
mSystemServiceManager.startService(TrustManagerService.class);
mSystemServiceManager.startService(FingerprintService.class);
try {
Slog.i(TAG, "BackgroundDexOptService");
BackgroundDexOptService.schedule(context, 0);
} catch (Throwable e) {
reportWtf("starting BackgroundDexOptService", e);
}
}
mSystemServiceManager.startService(LauncherAppsService.class);
}
/// [+LEUI][nietong] Create PerfService manager thread and add service
try {
perfServiceMgr = new PerfServiceManager(context);
IPerfService perfService = null;
perfService = new PerfServiceImpl(context, perfServiceMgr);
Slog.d("perfservice", "perfService=" + perfService);
if (perfService != null) {
ServiceManager.addService(Context.PERFBOOST_SERVICE, perfService.asBinder());
}
} catch (Throwable e) {
Slog.e(TAG, "perfservice Failure starting PerfService", e);
}
/// [-LEUI]
if (!disableNonCoreServices) {
mSystemServiceManager.startService(MediaProjectionManagerService.class);
}
// Before things start rolling, be sure we have decided whether
// we are in safe mode.
final boolean safeMode = wm.detectSafeMode();
if (safeMode) {
mActivityManagerService.enterSafeMode();
// Disable the JIT for the system_server process
VMRuntime.getRuntime().disableJitCompilation();
} else {
// Enable the JIT for the system_server process
VMRuntime.getRuntime().startJitCompilation();
}
// MMS service broker
mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
// It is now time to start up the app processes...
try {
vibrator.systemReady();
} catch (Throwable e) {
reportWtf("making Vibrator Service ready", e);
}
//+LEUI [REQ][LEUI-6586][fengzihua] added: add service for read key
try {
phoneBind.systemReady();
} catch (Throwable e) {
reportWtf("making phone bind Service ready", e);
}
//-LEUI
if (lockSettings != null) {
try {
lockSettings.systemReady();
} catch (Throwable e) {
reportWtf("making Lock Settings Service ready", e);
}
}
// Needed by DevicePolicyManager for initialization
mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
try {
wm.systemReady();
} catch (Throwable e) {
reportWtf("making Window Manager Service ready", e);
}
if (safeMode) {
mActivityManagerService.showSafeModeOverlay();
}
// Update the configuration for this context by hand, because we're going
// to start using it before the config change done in wm.systemReady() will
// propagate to it.
Configuration config = wm.computeNewConfiguration();
DisplayMetrics metrics = new DisplayMetrics();
WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
w.getDefaultDisplay().getMetrics(metrics);
context.getResources().updateConfiguration(config, metrics);
try {
// TODO: use boot phase
mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
} catch (Throwable e) {
reportWtf("making Power Manager Service ready", e);
}
try {
mPackageManagerService.systemReady();
} catch (Throwable e) {
reportWtf("making Package Manager Service ready", e);
}
try {
// TODO: use boot phase and communicate these flags some other way
mDisplayManagerService.systemReady(safeMode, mOnlyCore);
} catch (Throwable e) {
reportWtf("making Display Manager Service ready", e);
}
// These are needed to propagate to the runnable below.
final NetworkManagementService networkManagementF = networkManagement;
final NetworkStatsService networkStatsF = networkStats;
final NetworkPolicyManagerService networkPolicyF = networkPolicy;
final ConnectivityService connectivityF = connectivity;
final NetworkScoreService networkScoreF = networkScore;
final WallpaperManagerService wallpaperF = wallpaper;
final InputMethodManagerService immF = imm;
final LocationManagerService locationF = location;
final CountryDetectorService countryDetectorF = countryDetector;
final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
final TextServicesManagerService textServiceManagerServiceF = tsms;
final StatusBarManagerService statusBarF = statusBar;
final AssetAtlasService atlasF = atlas;
final InputManagerService inputManagerF = inputManager;
final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
final MediaRouterService mediaRouterF = mediaRouter;
final AudioService audioServiceF = audioService;
final MmsServiceBroker mmsServiceF = mmsService;
//[+LEUI][nietong]
final IPerfServiceManager perfServiceF = perfServiceMgr;
//[-LEUI]
//modify by liujf for letv mute key
final MuteKeyObserver muteF = mute;
// We now tell the activity manager it is okay to run third party
// code. It will call back into us once it has gotten to the state
// where third party code can really run (but before it has actually
// started launching the initial applications), for us to complete our
// initialization.
mActivityManagerService.systemReady(new Runnable() {
@Override
public void run() {
Slog.i(TAG, "Making services ready");
mSystemServiceManager.startBootPhase(
SystemService.PHASE_ACTIVITY_MANAGER_READY);
try {
mActivityManagerService.startObservingNativeCrashes();
} catch (Throwable e) {
reportWtf("observing native crashes", e);
}
Slog.i(TAG, "WebViewFactory preparation");
WebViewFactory.prepareWebViewInSystemServer();
try {
startSystemUi(context);
} catch (Throwable e) {
reportWtf("starting System UI", e);
}
try {
if (networkScoreF != null) networkScoreF.systemReady();
} catch (Throwable e) {
reportWtf("making Network Score Service ready", e);
}
try {
if (networkManagementF != null) networkManagementF.systemReady();
} catch (Throwable e) {
reportWtf("making Network Managment Service ready", e);
}
try {
if (networkStatsF != null) networkStatsF.systemReady();
} catch (Throwable e) {
reportWtf("making Network Stats Service ready", e);
}
try {
if (networkPolicyF != null) networkPolicyF.systemReady();
} catch (Throwable e) {
reportWtf("making Network Policy Service ready", e);
}
try {
if (connectivityF != null) connectivityF.systemReady();
} catch (Throwable e) {
reportWtf("making Connectivity Service ready", e);
}
try {
if (audioServiceF != null) audioServiceF.systemReady();
} catch (Throwable e) {
reportWtf("Notifying AudioService running", e);
}
//modify by liujf for letv mute key
try {
if (muteF != null) muteF.systemReady();
} catch (Throwable e) {
reportWtf("Notifying mute service running", e);
}
//modify by liujf end
Watchdog.getInstance().start();
// It is now okay to let the various system services start their
// third party code...
mSystemServiceManager.startBootPhase(
SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
try {
if (wallpaperF != null) wallpaperF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying WallpaperService running", e);
}
try {
if (immF != null) immF.systemRunning(statusBarF);
} catch (Throwable e) {
reportWtf("Notifying InputMethodService running", e);
}
try {
if (locationF != null) locationF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying Location Service running", e);
}
try {
if (countryDetectorF != null) countryDetectorF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying CountryDetectorService running", e);
}
try {
if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying NetworkTimeService running", e);
}
try {
if (commonTimeMgmtServiceF != null) {
commonTimeMgmtServiceF.systemRunning();
}
} catch (Throwable e) {
reportWtf("Notifying CommonTimeManagementService running", e);
}
try {
if (textServiceManagerServiceF != null)
textServiceManagerServiceF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying TextServicesManagerService running", e);
}
try {
if (atlasF != null) atlasF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying AssetAtlasService running", e);
}
try {
// TODO(BT) Pass parameter to input manager
if (inputManagerF != null) inputManagerF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying InputManagerService running", e);
}
try {
if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying TelephonyRegistry running", e);
}
try {
if (mediaRouterF != null) mediaRouterF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying MediaRouterService running", e);
}
try {
if (mmsServiceF != null) mmsServiceF.systemRunning();
} catch (Throwable e) {
reportWtf("Notifying MmsService running", e);
}
}
});
//[+LEUI][nietong] Notify PerfService manager of system ready
try {
if (perfServiceF != null) perfServiceF.systemReady();
} catch (Throwable e) {
reportWtf("making PerfServiceManager ready", e);
}
//[-LEUI]
//+LEUI [REQ][MOBILEP-9892][baopengli] added: add service for color mode
try {
colorMode.systemReady();
} catch (Throwable e) {
reportWtf("making color mode Service ready", e);
}
//-LEUI
}
其中655行传入的字符串com.android.internal.R.string.android_upgrading_starting_apps就是正在启动应用。那直接从现象上看,好像中间初始化所有应用的过程没有了,是不是在这里出问题了呢?好,我们在PackageManagerService类的performBootDexOpt方法里边加上一句日志,重新mm,push,reboot再看一次日志,看看到底是不是被跳过了?
重启之后,再次adb logcat -v time > 1.txt,查看对应的日志,没有啊,系统安装的应用都有初始化的,只是界面没有显示而已。
Line 5170: 10-19 14:40:47.371 I/PackageManager( 3688): Optimizing app 71 of 112: com.android.providers.downloads
Line 5175: 10-19 14:40:48.115 I/PackageManager( 3688): Optimizing app 72 of 112: com.google.android.setupwizard
Line 5184: 10-19 14:40:52.853 I/PackageManager( 3688): Optimizing app 73 of 112: com.android.calendar
Line 5211: 10-19 14:41:09.533 I/PackageManager( 3688): Optimizing app 74 of 112: com.android.exchange
Line 5220: 10-19 14:41:14.835 I/PackageManager( 3688): Optimizing app 75 of 112: com.letv.leui.schpwronoff
Line 5225: 10-19 14:41:15.145 I/PackageManager( 3688): Optimizing app 76 of 112: com.qti.diagservices
Line 5228: 10-19 14:41:15.145 I/PackageManager( 3688): Optimizing app 77 of 112: com.google.android.partnersetup
Line 5233: 10-19 14:41:17.039 I/PackageManager( 3688): Optimizing app 78 of 112: com.google.android.gms
Line 5392: 10-19 14:43:31.077 I/PackageManager( 3688): Optimizing app 79 of 112: com.stv.stvpush
Line 5405: 10-19 14:43:40.851 I/PackageManager( 3688): Optimizing app 80 of 112: com.qualcomm.qti.phonefeature
那问题就不在这里了,继续再找,搜索一下日志,可以看到如下出错信息:
Line 6290: 10-19 14:48:13.590 I/SystemServiceManager( 3688): Starting com.android.server.fingerprint.FingerprintService
Line 6290: 10-19 14:48:13.590 I/SystemServiceManager( 3688): Starting com.android.server.fingerprint.FingerprintService
Line 6296: 10-19 14:48:13.592 E/System ( 3688): java.lang.RuntimeException: Failed to create service com.android.server.fingerprint.FingerprintService: service constructor threw an exception
Line 6296: 10-19 14:48:13.592 E/System ( 3688): java.lang.RuntimeException: Failed to create service com.android.server.fingerprint.FingerprintService: service constructor threw an exception
Line 6309: 10-19 14:48:13.592 E/System ( 3688):at com.android.server.fingerprint.FingerprintService.<init>(FingerprintService.java:188)
Line 6309: 10-19 14:48:13.592 E/System ( 3688):at com.android.server.fingerprint.FingerprintService.<init>(FingerprintService.java:188)
Line 6309: 10-19 14:48:13.592 E/System ( 3688):at com.android.server.fingerprint.FingerprintService.<init>(FingerprintService.java:188)
Line 6314: 10-19 14:48:13.592 E/AndroidRuntime( 3688): java.lang.RuntimeException: Failed to create service com.android.server.fingerprint.FingerprintService: service constructor threw an exception
Line 6314: 10-19 14:48:13.592 E/AndroidRuntime( 3688): java.lang.RuntimeException: Failed to create service com.android.server.fingerprint.FingerprintService: service constructor threw an exception
Line 6327: 10-19 14:48:13.592 E/AndroidRuntime( 3688):at com.android.server.fingerprint.FingerprintService.<init>(FingerprintService.java:188)
Line 6327: 10-19 14:48:13.592 E/AndroidRuntime( 3688):at com.android.server.fingerprint.FingerprintService.<init>(FingerprintService.java:188)
Line 6327: 10-19 14:48:13.592 E/AndroidRuntime( 3688):at com.android.server.fingerprint.FingerprintService.<init>(FingerprintService.java:188)
Line 6671: 10-19 14:48:14.903 I/ServiceManager( 450): service 'android.hardware.fingerprint.IFingerprintDaemon' died
Line 6671: 10-19 14:48:14.903 I/ServiceManager( 450): service 'android.hardware.fingerprint.IFingerprintDaemon' died
这里呢,多说两句,我们处理问题单的时候,一定要认真,我们确定一个问题单的原因,一定要确定,不能模糊,因为代码执行的时候,有很多地方的日志看着就是这个原因,但是如果你应付一下就这样糊弄过去的话,下次又会出现了,因为这个问题的根因的产生就不在这里,所以我们一定要认真,绝对确定找到问题的产生原因了,这个问题单才能放过。当然日志当中的信息太多,所以我们也要会看日志,要各种搜索,只要是有可能相关的,都搜索一下,多花些时间在日志上面,可能你就会偶然找到非常宝贵的东西。
好了,继续我们的分析,14:48:13.592 E/System ( 3688): java.lang.RuntimeException: Failed to create service com.android.server.fingerprint.FingerprintService: service constructor threw an exception,这句日志很明显,FingerprintService服务启动异常了。这个是指纹的系统服务,在上面SystemServer类的startOtherServices方法当中,就可以看到它的启动。系统服务异常,这个会不会是导致无法开机的原因呢?我们先来看一下,它为什么启动异常了?日志上面很明显,10-19 14:48:13.592 E/System ( 3688): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.ComponentName.getPackageName()' on a null object reference,在它的构造方法当中获取包名时候报空指针了,好,我们进去看一下,FingerprintService的构造方法的代码如下:
public FingerprintService(Context context) {
super(context);
mContext = context;
mKeyguardPackage = ComponentName.unflattenFromString(context.getResources().getString(
com.android.internal.R.string.config_keyguardComponent)).getPackageName();
mAppOps = context.getSystemService(AppOpsManager.class);
mPowerManager = mContext.getSystemService(PowerManager.class);
mAlarmManager = mContext.getSystemService(AlarmManager.class);
mContext.registerReceiver(mLockoutReceiver, new IntentFilter(ACTION_LOCKOUT_RESET),
RESET_FINGERPRINT_LOCKOUT, null /* handler */);
//[+LEUI] [RUBY-8108] [REQ] [chenzhiyong] add fingerprint thread
HandlerThread hthread = new HandlerThread(TAG);
hthread.start();
mHandler = new FingerprintHandler(hthread.getLooper());
//[-LEUI]
//chenzhiyong add fingerprint extend func
try {
Class[] params = {Context.class};
Object[] values = {mContext};
mFingerprintExtendClass = Class.forName("com.android.server.fingerprint.FingerprintExtendImpl");
Constructor constructor = mFingerprintExtendClass.getConstructor(params);
mFingerprintExtend = (FingerprintExtend)constructor.newInstance(values);
} catch (ClassNotFoundException e) {
Slog.e(TAG, "ClassNotFoundException :", e);
} catch (NoSuchMethodException e) {
Slog.e(TAG, "NoSuchMethodException :", e);
} catch (IllegalArgumentException e) {
Slog.e(TAG, "IllegalArgumentException :", e);
} catch (InstantiationException e) {
Slog.e(TAG, "InstantiationException :", e);
} catch (IllegalAccessException e) {
Slog.e(TAG, "IllegalAccessException :", e);
} catch (InvocationTargetException e) {
Slog.e(TAG, "InvocationTargetException :", e);
}
if (mFingerprintExtend == null) {
Slog.w("czy", "FingerprintExtend is null");
}
//chenzhiyong end
}
就是在给mKeyguardPackage变量赋值时,调用报空指针了,我们跟到ComponentName类中看一下它的处理:
public static ComponentName unflattenFromString(String str) {
int sep = str.indexOf('/');
if (sep < 0 || (sep+1) >= str.length()) {
return null;
}
String pkg = str.substring(0, sep);
String cls = str.substring(sep+1);
if (cls.length() > 0 && cls.charAt(0) == '.') {
cls = pkg + cls;
}
return new ComponentName(pkg, cls);
}
这里的处理很简单,先判断“/”在字符串str中的位置,如果位置小于0或者在最后,则直接返回空,否则就以“/”为分界,拆分str,然后构造一个ComponentName对象返回上调用者,那么肯定是我们获取的字符串出问题了,导致返回为空了。来看一下com.android.internal.R.string.config_keyguardComponent字符串的定义:<string name="config_keyguardComponent" translatable="false">com.android.systemui/com.android.systemui.keyguard.KeyguardService</string>,不对啊,定义没问题啊?难道context.getResources().getString()方法有问题了,这好像不可能吧?算了,索性把这句去掉,直接把com.android.systemui/com.android.systemui.keyguard.KeyguardService传进来,继续编译,push,reboot,再看一下,恩,这次确实没有这个问题了,FingerprintService服务正常启动了,但是无法开机的问题还是没解决。
到底是哪里的问题呢?
我们是不是需要一段完整的log日志,好,等,从开机adb成功连接开始,一直到一次启动完毕,把所有的日志全部保存下来。
再搜索。
Line 5894: 10-19 14:48:07.308 I/PackageManager( 3688): Optimizing app 112 of 112: com.google.android.inputmethod.pinyin
可以看到,系统当中安装的112个包已经全部解析完了,好,从这里往下找,又发现一段异常,
10-19 14:48:12.913 I/SystemServiceManager( 3688): Starting com.android.server.PersistentDataBlockService
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): not able to find package false
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): android.content.pm.PackageManager$NameNotFoundException: false
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at android.app.ApplicationPackageManager.getPackageUid(ApplicationPackageManager.java:235)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.server.PersistentDataBlockService.getAllowedUid(PersistentDataBlockService.java:99)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.server.PersistentDataBlockService.<init>(PersistentDataBlockService.java:90)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at java.lang.reflect.Constructor.newInstance(Native Method)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.server.SystemServiceManager.startService(SystemServiceManager.java:89)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.server.SystemServer.startOtherServices(SystemServer.java:693)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.server.SystemServer.run(SystemServer.java:287)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.server.SystemServer.main(SystemServer.java:185)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at java.lang.reflect.Method.invoke(Native Method)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-19 14:48:12.914 E/PersistentDataBlockService( 3688): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-19 14:48:12.922 I/SystemServiceManager( 3688): Starting com.android.server.DeviceIdleController
10-19 14:48:12.927 I/SystemServiceManager( 3688): Starting com.android.server.devicepolicy.DevicePolicyManagerService$Lifecycle
10-19 14:48:12.931 I/SystemServer( 3688): Status Bar
10-19 14:48:12.933 I/SystemServer( 3688): Clipboard Service
又一个系统服务异常,我靠,真是没完没了了。看来原因应该不在这里,这个服务出现异常,其他的应该也会出现异常的。我们先来看一下这个服务异常的地方。从日志上很明确可以得出,是在PersistentDataBlockService类的getAllowedUid方法出错了:
private int getAllowedUid(int userHandle) {
String allowedPackage = mContext.getResources()
.getString(R.string.config_persistentDataPackageName);
PackageManager pm = mContext.getPackageManager();
int allowedUid = -1;
try {
allowedUid = pm.getPackageUid(allowedPackage, userHandle);
} catch (PackageManager.NameNotFoundException e) {
// not expected
Slog.e(TAG, "not able to find package " + allowedPackage, e);
}
return allowedUid;
}
pm.getPackageUid(allowedPackage, userHandle),就是在调用这句时,抛出了PackageManager.NameNotFoundException异常,对 应的日志也很明
显, not able to find package false,最后的false就是代码当中的allowedPackage,从这里也可以明显看出,肯定是有问题的,获取回来的allowedPackage怎么
能是false呢?肯定又是上面getString(R.string.config_persistentDataPackageName)出问题了, 好,把这里也直接替换。继续mm,push,reboot……
还是不对啊?重启还是无法开机。
找找其他方面的原因吧,进入到/data/system/dropbox/目录看一下,看看系统有没有记录下一些什么东西。
我靠,一大堆系统异常,ActivityManagerService有问题了,那肯定不行了。打开一看,又是string字符串的问题,对了,有点灵感了,问题可能出在资源文件上了。昨晚重新编译了下,代码是最新的,但是资源已经不是了,是不是资源找不到,所以引起的问题呢?
好,将昨晚编译好的framework-res.apk替换push进手机,再次reboot,哇!!!!终于看到久违的正常开机画面了!!