Amlogic平台开机时间优化-剥离连网部分代码
--- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -86,6 +86,7 @@ class ServerThread { private static final String ENCRYPTED_STATE = "1"; ContentResolver mContentResolver; + private boolean isNetworkFinished = false; void reportWtf(String msg, Throwable e) { Slog.w(TAG, "***********************************************"); @@ -140,13 +141,6 @@ class ServerThread { AlarmManagerService alarm = null; GpioManagerService gpio = null; MountService mountService = null; - NetworkManagementService networkManagement = null; - NetworkStatsService networkStats = null; - NetworkPolicyManagerService networkPolicy = null; - ConnectivityService connectivity = null; - WifiP2pService wifiP2p = null; - WifiService wifi = null; - NsdService serviceDiscovery= null; IPackageManager pm = null; Context context = null; WindowManagerService wm = null; @@ -164,6 +158,7 @@ class ServerThread { OverlayViewService overlayview = null; ConsumerIrService consumerIr = null; InstabootManagerService mInstabootService = null; + NetworkThread mNetThread = null; // Create a handler thread just for the window manager to enjoy. HandlerThread wmHandlerThread = new HandlerThread("WindowManager"); @@ -430,6 +425,10 @@ class ServerThread { Slog.e("System", "************ Failure starting core service", e); } + mNetThread = new NetworkThread(context, alarm, power); + mNetThread.start(); + + DevicePolicyManagerService devicePolicy = null; StatusBarManagerService statusBar = null; InputMethodManagerService imm = null; @@ -472,7 +471,7 @@ class ServerThread { } catch (Throwable e) { reportWtf("making display ready", e); } - + boolean tag = false; try { tag = pm.performBootDexOpt(); @@ -545,16 +544,6 @@ class ServerThread { } } - 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"); @@ -565,66 +554,8 @@ class ServerThread { } } - if (!disableNetwork) { - 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, ActivityManagerService.self(), power, - networkStats, networkManagement); - ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); - } catch (Throwable e) { - reportWtf("starting NetworkPolicy Service", e); - } - - try { - Slog.i(TAG, "Wi-Fi P2pService"); - wifiP2p = new WifiP2pService(context); - ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p); - } catch (Throwable e) { - reportWtf("starting Wi-Fi P2pService", e); - } - - try { - Slog.i(TAG, "Wi-Fi Service"); - wifi = new WifiService(context); - ServiceManager.addService(Context.WIFI_SERVICE, wifi); - } catch (Throwable e) { - reportWtf("starting Wi-Fi Service", e); - } - - 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); - - wifiP2p.connectivityServiceReady(); - if ( mInstabootService == null || !mInstabootService.isEnable()){ - wifi.checkAndStartWifiorAP(); - } - } 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); - } - } + // mNetThread = new NetworkThread(context, alarm, power); + // mNetThread.start(); if (!disableNonCoreServices) { try { @@ -663,7 +594,7 @@ class ServerThread { Slog.i(TAG, "Notification Manager"); notification = new NotificationManagerService(context, statusBar, lights); ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification); - networkPolicy.bindNotificationManager(notification); + //networkPolicy.bindNotificationManager(notification); } catch (Throwable e) { reportWtf("starting Notification Manager", e); } @@ -862,7 +793,7 @@ class ServerThread { } } - if (!disableNonCoreServices && + if (!disableNonCoreServices && context.getResources().getBoolean(R.bool.config_dreamsSupported)) { try { Slog.i(TAG, "Dreams Service"); @@ -995,14 +926,15 @@ class ServerThread { reportWtf("making Display Manager Service ready", e); } + mNetThread.getNetworkPolicy().bindNotificationManager(notification); + // These are needed to propagate to the runnable below. final Context contextF = context; final MountService mountServiceF = mountService; final BatteryService batteryF = battery; - final NetworkManagementService networkManagementF = networkManagement; - final NetworkStatsService networkStatsF = networkStats; - final NetworkPolicyManagerService networkPolicyF = networkPolicy; - final ConnectivityService connectivityF = connectivity; + final NetworkManagementService networkManagementF = mNetThread.getNetworkManagement(); + final NetworkStatsService networkStatsF = mNetThread.getNetworkStats(); + final NetworkPolicyManagerService networkPolicyF = mNetThread.getNetworkPolicy(); final DockObserver dockF = dock; final UsbService usbF = usb; final TwilightService twilightF = twilight; @@ -1023,10 +955,10 @@ class ServerThread { final TelephonyRegistry telephonyRegistryF = telephonyRegistry; final PrintManagerService printManagerF = printManager; final MediaRouterService mediaRouterF = mediaRouter; - final WifiService wifiF = wifi; + final WifiService wifiF = mNetThread.getWifi(); final InstabootManagerService instabootServiceF = mInstabootService; - if (mInstabootService != null){ + /*if (mInstabootService != null){ mInstabootService.setLaterServiceCallback(new Runnable() { public void run() { Slog.i(TAG, "Later start services ready"); @@ -1043,13 +975,14 @@ class ServerThread { } } }); - } + }*/ // 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. + final NetworkThread fnetThread = mNetThread; ActivityManagerService.self().systemReady(new Runnable() { public void run() { Slog.i(TAG, "BootStage Making services ready"); @@ -1061,9 +994,18 @@ class ServerThread { } } - if (!headless) { - startSystemUi(contextF); - } + Thread th = new Thread("test") { + public void run() { + try { + Thread.sleep(3000); + } catch (Exception e) {} + if (!headless) { + startSystemUi(contextF); + } + } + }; + th.start(); + try { if (mountServiceF != null) mountServiceF.systemReady(); } catch (Throwable e) { @@ -1090,6 +1032,9 @@ class ServerThread { reportWtf("making Network Policy Service ready", e); } + + final ConnectivityService connectivityF = fnetThread.getConnectivity(); + if ( instabootServiceF == null || !instabootServiceF.isEnable()) { try { if (connectivityF != null) connectivityF.systemReady(); @@ -1230,6 +1175,217 @@ class ServerThread { context.startServiceAsUser(intent, UserHandle.OWNER); } } +class NetworkThread extends Thread { + private Context mcontext; + private AlarmManagerService mAlarm; + private PowerManagerService mPower; + private static final String TAG = "SystemServer.Network"; + public static boolean finished; + + private NetworkManagementService networkManagement = null; + private NetworkStatsService networkStats = null; + private NetworkPolicyManagerService networkPolicy = null; + private ConnectivityService connectivity = null; + private WifiP2pService wifiP2p = null; + private WifiService wifi = null; + private NsdService serviceDiscovery= null; + + private Object mNmLock = new Object(); + private Object mNsLock = new Object(); + private Object mNpmLock = new Object(); + private Object mCsLock = new Object(); + private Object mWifiP2pLock = new Object(); + private Object mWifiLock = new Object(); + private Object mNsdiLock = new Object(); + + public NetworkThread(Context context, AlarmManagerService alarm, PowerManagerService power) { + super("ActivityManager"); + mcontext = context; + mAlarm = alarm; + mPower = power; + } + private void myWait(Object lock) { + try { + Slog.i(TAG, "wait.."); + lock.wait(); + Thread.sleep(4); + } catch (Exception e) { + Slog.i(TAG, "wait.."+e); + } + } + + private void myNotifyAll(Object lock) { + try { + lock.notifyAll(); + } catch (Exception e) + {} + } + + + + void reportWtf(String msg, Throwable e) { + Slog.w(TAG, "***********************************************"); + Log.wtf(TAG, "BOOT FAILURE " + msg, e); + } + + public NetworkManagementService getNetworkManagement() { + synchronized(mNmLock) { + while (networkManagement == null) + myWait(mNmLock); + + Slog.i(TAG, "getNetworkManagement"); + return networkManagement; + } + } + public NetworkPolicyManagerService getNetworkPolicy() { + synchronized(mNpmLock) { + while (networkPolicy == null) + myWait(mNpmLock); + Slog.i(TAG, "getNetworkPolicy"); + return networkPolicy; + } + } + + public NetworkStatsService getNetworkStats() { + synchronized(mNsLock) { + while (networkStats == null) + myWait(mNsLock); + + Slog.i(TAG, "getNetworkStats"); + return networkStats; + } + } + + public WifiService getWifi() { + synchronized(mWifiLock) { + while (wifi == null) + myWait(mWifiLock); + + Slog.i(TAG, "getWifi"); + return wifi; + } + } + + public ConnectivityService getConnectivity() { + synchronized(mCsLock) { + while (connectivity == null) + myWait(mCsLock); + + Slog.i(TAG, "getConnectivity"); + return connectivity; + } + } + + + @Override + public void run() { + boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false); + android.os.Process.setThreadPriority( + android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); + + Looper.prepare(); + + synchronized(mNmLock) { + if (!disableNetwork) { + try { + Slog.i(TAG, "NetworkManagement Service"); + networkManagement = NetworkManagementService.create(mcontext); + ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); + myNotifyAll(mNmLock); + } catch (Throwable e) { + reportWtf("starting NetworkManagement Service", e); + } + } + } + + + if (!disableNetwork) { + synchronized(mNsLock) { + try { + Slog.i(TAG, "NetworkStats Service"); + networkStats = new NetworkStatsService(mcontext, networkManagement, mAlarm); + ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats); + myNotifyAll(mNsLock); + } catch (Throwable e) { + reportWtf("starting NetworkStats Service", e); + } + } + + + synchronized(mNpmLock) { + try { + Slog.i(TAG, "NetworkPolicy Service"); + networkPolicy = new NetworkPolicyManagerService( + mcontext, ActivityManagerService.self(), mPower, + networkStats, networkManagement); + ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); + myNotifyAll(mNpmLock); + } catch (Throwable e) { + reportWtf("starting NetworkPolicy Service", e); + } + } + + + //synchronized(mWifiP2pLock) { // no get service, no lock! + try { + Slog.i(TAG, "Wi-Fi P2pService"); + wifiP2p = new WifiP2pService(mcontext); + ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p); + //myNotifyAll(); + } catch (Throwable e) { + reportWtf("starting Wi-Fi P2pService", e); + } + //} + + synchronized(mWifiLock) { + try { + Slog.i(TAG, "Wi-Fi Service"); + wifi = new WifiService(mcontext); + ServiceManager.addService(Context.WIFI_SERVICE, wifi); + myNotifyAll(mWifiLock); + } catch (Throwable e) { + reportWtf("starting Wi-Fi Service", e); + } + } + + + synchronized(mCsLock) { + try { + Slog.i(TAG, "Connectivity Service"); + connectivity = new ConnectivityService( + mcontext, networkManagement, networkStats, networkPolicy); + ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); + networkStats.bindConnectivityManager(connectivity); + networkPolicy.bindConnectivityManager(connectivity); + + wifiP2p.connectivityServiceReady(); + wifi.checkAndStartWifiorAP(); + + myNotifyAll(mCsLock); + } catch (Throwable e) { + reportWtf("starting Connectivity Service", e); + } + } + + + //synchronized(mLock) { // no getService, no lock + + try { + Slog.i(TAG, "Network Service Discovery Service"); + serviceDiscovery = NsdService.create(mcontext); + ServiceManager.addService( + Context.NSD_SERVICE, serviceDiscovery); + //myNotifyAll(); + } catch (Throwable e) { + reportWtf("starting Service Discovery Service", e); + }//} + android.os.Process.setThreadPriority( + android.os.Process.THREAD_PRIORITY_FOREGROUND); + + Looper.loop(); + } + } +} public class SystemServer { private static final String TAG = "SystemServer"; diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index cb68781..98f7f84 100755 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -1109,6 +1109,7 @@ public final class ActivityManagerService extends ActivityManagerNative msg.what = START_HOLD_ON_APP; mHandler.sendMessage(msg); mLauncherDisplayed = true; + startIPTVLauncherApp(); } } } @@ -3033,6 +3034,125 @@ public final class ActivityManagerService extends ActivityManagerNative return intent; } + boolean startIPTVLauncherApp() { + if (SystemProperties.getBoolean("sys.iptv_launcher.force_in", false)) { + + Thread thrd = new Thread( new Runnable() { + public void run() { + boolean b = false; + try { + Thread.sleep(200); + } catch(Exception e) {} + + synchronized(this) { + String epgActionName = SystemProperties.get("epg.action.name", ""); + if (epgActionName.equals("") || "null".equals(epgActionName)) { + String pageName = SystemProperties.get("epg.package.name", ""); + Slog.d(TAG, "pageName="+pageName); + if (pageName!=null && !pageName.equals("")) { + b = startAppWithPackageName(pageName); + } + } else { + b = startAppWithAction(epgActionName); + } + + Slog.d(TAG, "b="+b); + if (!b && !startAppWithAction("cn.cmvideo.action.ITV") + && !startAppWithAction("cn.cmvideo.action.sanping") + && !startAppWithPackageName("android.app.chinamobile.ott.itv")) { + Slog.d(TAG, "Error, cannot start iptv launcher directly"); + } + } + } + }); + + thrd.start(); + return true; + } + + return false; + } + + + private boolean startAppWithAction(String sActionName) { + try { + Intent intent = new Intent(); + ActivityInfo ai; + intent.setAction(sActionName); + List<ResolveInfo> list = mSelf.mContext.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + Slog.d(TAG, "======startAppWithAction()===== resolveinfo list:" + list); + Intent mi = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_LAUNCHER); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + if (list != null && list.size() > 0) { + ai = ((ResolveInfo) list.get(0)).activityInfo; + if (ai != null) { + String sPackageName = ai.packageName; + String clsname = ai.name; + Slog.d(TAG, "======startAppWithAction()===== get packagename:" + sPackageName); + if (sPackageName!=null && sPackageName.length()>3) { + Slog.d(TAG, "======startAppWithAction()===== setprop [epg.launcher.packagename]: " + sPackageName); + SystemProperties.set("epg.package.name", sPackageName); + + + ComponentName cn = new ComponentName(sPackageName, clsname); + intent.setComponent(cn); + } + } + } else { + return false; + } + + intent.putExtra("GoHome", "true"); + + mStackSupervisor.startActivityLocked(null, intent, null, ai, + null, null, 0, 0, 0, null, 0, null, false, null); + + return true; + } catch (Exception e) { + Slog.d(TAG, "start app with action:" + sActionName + " failed!"+e); + return false; + } + } + + private boolean startAppWithPackageName(String sPackageName) { + + try { + Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); + resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); + resolveIntent.setPackage(sPackageName); + List<ResolveInfo> list = mSelf.mContext.getPackageManager().queryIntentActivities(resolveIntent, 0); + Slog.d(TAG, "======startAppWithPackageName()===== resolveinfo list:" + list); + Intent intent = new Intent(Intent.ACTION_MAIN); + ResolveInfo ri = list.iterator().next(); + if (ri != null) { + String startappName = ri.activityInfo.packageName; + String className = ri.activityInfo.name; + + Slog.d(TAG, "activity:" + startappName+":"+className); + + intent.addCategory(Intent.CATEGORY_LAUNCHER); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ComponentName cn = new ComponentName(startappName, className); + intent.setComponent(cn); + } else { + return false; + } + + intent.putExtra("GoHome", "true"); + //startActivity(intent); + + mStackSupervisor.startActivityLocked(null, intent, null, ri.activityInfo, + null, null, 0, 0, 0, null, 0, null, false, null); + return true; + } catch (Exception e) { + + } + + return false; + } + boolean startHomeActivityLocked(int userId, boolean preStart) { if (mHeadless) { // Added because none of the other calls to ensureBootCompleted seem to fire @@ -10060,6 +10180,43 @@ public final class ActivityManagerService extends ActivityManagerNative } + private void startpersistservice_if_need(){ + if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL || + !SystemProperties.getBoolean("ro.sf.delay-persist-app", true)) { + return; + } + + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(5000); // 200 ms + } catch (InterruptedException e) {} + try { + List apps = AppGlobals.getPackageManager(). + getPersistentApplications(STOCK_PM_FLAGS); + if (apps != null) { + int N = apps.size(); + int i; + for (i=0; i<N; i++) { + ApplicationInfo info + = (ApplicationInfo)apps.get(i); + if (info != null && + !info.packageName.equals("android")) { + synchronized (ActivityManagerService.this) { + addAppLocked(info, false); + } + } + } + } + } catch (RemoteException ex) { + // pm is in same process, this will never happen. + } + } + }).start(); + } + + private void rmRecoveryDir(){ new Thread() { File command_file = new File("/cache/recovery/command");
posted on 2018-10-24 16:48 world_hello!!!! 阅读(673) 评论(0) 编辑 收藏 举报