Merge "Make UsbService optional" into klp-modular-dev

This commit is contained in:
Adam Lesinski
2014-02-19 19:38:33 +00:00
committed by Android (Google) Code Review
10 changed files with 227 additions and 149 deletions

View File

@@ -49,9 +49,32 @@ public abstract class SystemService {
* Boot Phases * Boot Phases
*/ */
public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100; // maybe should be a dependency? public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100; // maybe should be a dependency?
/**
* After receiving this boot phase, services can obtain lock settings data.
*/
public static final int PHASE_LOCK_SETTINGS_READY = 480; public static final int PHASE_LOCK_SETTINGS_READY = 480;
/**
* After receiving this boot phase, services can safely call into core system services
* such as the PowerManager or PackageManager.
*/
public static final int PHASE_SYSTEM_SERVICES_READY = 500; public static final int PHASE_SYSTEM_SERVICES_READY = 500;
/**
* After receiving this boot phase, services can broadcast Intents.
*/
public static final int PHASE_ACTIVITY_MANAGER_READY = 550;
/**
* After receiving this boot phase, services can start/bind to third party apps.
* Apps will be able to make Binder calls into services at this point.
*/
public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600; public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
/**
* After receiving this boot phase, services must have finished all boot-related work.
*/
public static final int PHASE_BOOT_COMPLETE = 1000; public static final int PHASE_BOOT_COMPLETE = 1000;
private final Context mContext; private final Context mContext;

View File

@@ -45,18 +45,13 @@ public class SystemServiceManager {
} }
/** /**
* Starts a service by name if the class exists, otherwise ignores it. * Starts a service by class name.
* *
* @return The service instance, or null if not found. * @return The service instance.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public SystemService startServiceIfExists(String className) { public SystemService startService(String className) throws ClassNotFoundException {
try { return startService((Class<SystemService>) Class.forName(className));
return startService((Class<SystemService>)Class.forName(className));
} catch (ClassNotFoundException cnfe) {
Slog.i(TAG, className + " not available, ignoring.");
return null;
}
} }
/** /**

View File

@@ -8,13 +8,23 @@ LOCAL_MODULE := services
LOCAL_SRC_FILES := $(call all-java-files-under,java) LOCAL_SRC_FILES := $(call all-java-files-under,java)
LOCAL_STATIC_JAVA_LIBRARIES := \ # Uncomment to enable output of certain warnings (deprecated, unchecked)
services.core \ # LOCAL_JAVACFLAGS := -Xlint
services.accessibility \
services.appwidget \ # Services that will be built as part of services.jar
services.backup \ # These should map to directory names relative to this
services.devicepolicy \ # Android.mk.
services.print services := \
core \
accessibility \
appwidget \
backup \
devicepolicy \
print \
usb
# The convention is to name each service module 'services.$(module_name)'
LOCAL_STATIC_JAVA_LIBRARIES := $(addprefix services.,$(services))
include $(BUILD_JAVA_LIBRARY) include $(BUILD_JAVA_LIBRARY)
@@ -39,7 +49,16 @@ LOCAL_MODULE:= libandroid_servers
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
# =============================================================
ifeq (,$(ONE_SHOT_MAKEFILE)) ifeq (,$(ONE_SHOT_MAKEFILE))
include $(call all-makefiles-under, $(LOCAL_PATH)) # A full make is happening, so make everything.
include $(call all-makefiles-under,$(LOCAL_PATH))
else
# If we ran an mm[m] command, we still want to build the individual
# services that we depend on. This differs from the above condition
# by only including service makefiles and not any tests or other
# modules.
include $(patsubst %,$(LOCAL_PATH)/%/Android.mk,$(services))
endif endif

View File

@@ -112,6 +112,8 @@ public final class SystemServer {
"com.android.server.appwidget.AppWidgetService"; "com.android.server.appwidget.AppWidgetService";
private static final String PRINT_MANAGER_SERVICE_CLASS = private static final String PRINT_MANAGER_SERVICE_CLASS =
"com.android.server.print.PrintManagerService"; "com.android.server.print.PrintManagerService";
private static final String USB_SERVICE_CLASS =
"com.android.server.usb.UsbService$Lifecycle";
private final int mFactoryTestMode; private final int mFactoryTestMode;
private Timer mProfilerSnapshotTimer; private Timer mProfilerSnapshotTimer;
@@ -534,8 +536,7 @@ public final class SystemServer {
try { try {
if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) { if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
mSystemServiceManager.startServiceIfExists( mSystemServiceManager.startService(DEVICE_POLICY_MANAGER_SERVICE_CLASS);
DEVICE_POLICY_MANAGER_SERVICE_CLASS);
} }
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting DevicePolicyService", e); reportWtf("starting DevicePolicyService", e);
@@ -761,10 +762,11 @@ public final class SystemServer {
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
try { try {
Slog.i(TAG, "USB Service"); if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST) ||
// Manage USB host and device support pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) {
usb = new UsbService(context); // Manage USB host and device support
ServiceManager.addService(Context.USB_SERVICE, usb); mSystemServiceManager.startService(USB_SERVICE_CLASS);
}
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting UsbService", e); reportWtf("starting UsbService", e);
} }
@@ -786,7 +788,7 @@ public final class SystemServer {
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
try { try {
if (pm.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { if (pm.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
mSystemServiceManager.startServiceIfExists(BACKUP_MANAGER_SERVICE_CLASS); mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
} }
} catch (Throwable e) { } catch (Throwable e) {
Slog.e(TAG, "Failure starting Backup Service", e); Slog.e(TAG, "Failure starting Backup Service", e);
@@ -794,7 +796,7 @@ public final class SystemServer {
try { try {
if (pm.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) { if (pm.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) {
mSystemServiceManager.startServiceIfExists(APPWIDGET_SERVICE_CLASS); mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
} }
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting AppWidget Service", e); reportWtf("starting AppWidget Service", e);
@@ -880,7 +882,7 @@ public final class SystemServer {
try { try {
if (pm.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { if (pm.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
mSystemServiceManager.startServiceIfExists(PRINT_MANAGER_SERVICE_CLASS); mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
} }
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Print Service", e); reportWtf("starting Print Service", e);
@@ -972,7 +974,6 @@ public final class SystemServer {
} }
// These are needed to propagate to the runnable below. // These are needed to propagate to the runnable below.
final Context contextF = context;
final MountService mountServiceF = mountService; final MountService mountServiceF = mountService;
final BatteryService batteryF = battery; final BatteryService batteryF = battery;
final NetworkManagementService networkManagementF = networkManagement; final NetworkManagementService networkManagementF = networkManagement;
@@ -980,7 +981,6 @@ public final class SystemServer {
final NetworkPolicyManagerService networkPolicyF = networkPolicy; final NetworkPolicyManagerService networkPolicyF = networkPolicy;
final ConnectivityService connectivityF = connectivity; final ConnectivityService connectivityF = connectivity;
final DockObserver dockF = dock; final DockObserver dockF = dock;
final UsbService usbF = usb;
final WallpaperManagerService wallpaperF = wallpaper; final WallpaperManagerService wallpaperF = wallpaper;
final InputMethodManagerService immF = imm; final InputMethodManagerService immF = imm;
final RecognitionManagerService recognitionF = recognition; final RecognitionManagerService recognitionF = recognition;
@@ -1000,132 +1000,138 @@ public final class SystemServer {
// where third party code can really run (but before it has actually // where third party code can really run (but before it has actually
// started launching the initial applications), for us to complete our // started launching the initial applications), for us to complete our
// initialization. // initialization.
final Handler handler = new Handler();
mActivityManagerService.systemReady(new Runnable() { mActivityManagerService.systemReady(new Runnable() {
@Override
public void run() { public void run() {
Slog.i(TAG, "Making services ready"); // We initiate all boot phases on the SystemServer thread.
handler.post(new Runnable() {
@Override
public void run() {
Slog.i(TAG, "Making services ready");
mSystemServiceManager.startBootPhase(
SystemService.PHASE_ACTIVITY_MANAGER_READY);
try { try {
mActivityManagerService.startObservingNativeCrashes(); mActivityManagerService.startObservingNativeCrashes();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("observing native crashes", e); reportWtf("observing native crashes", e);
} }
try { try {
startSystemUi(contextF); startSystemUi(context);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting System UI", e); reportWtf("starting System UI", e);
} }
try { try {
if (mountServiceF != null) mountServiceF.systemReady(); if (mountServiceF != null) mountServiceF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Mount Service ready", e); reportWtf("making Mount Service ready", e);
} }
try { try {
if (batteryF != null) batteryF.systemReady(); if (batteryF != null) batteryF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Battery Service ready", e); reportWtf("making Battery Service ready", e);
} }
try { try {
if (networkManagementF != null) networkManagementF.systemReady(); if (networkManagementF != null) networkManagementF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Managment Service ready", e); reportWtf("making Network Managment Service ready", e);
} }
try { try {
if (networkStatsF != null) networkStatsF.systemReady(); if (networkStatsF != null) networkStatsF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Stats Service ready", e); reportWtf("making Network Stats Service ready", e);
} }
try { try {
if (networkPolicyF != null) networkPolicyF.systemReady(); if (networkPolicyF != null) networkPolicyF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Policy Service ready", e); reportWtf("making Network Policy Service ready", e);
} }
try { try {
if (connectivityF != null) connectivityF.systemReady(); if (connectivityF != null) connectivityF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Connectivity Service ready", e); reportWtf("making Connectivity Service ready", e);
} }
try { try {
if (dockF != null) dockF.systemReady(); if (dockF != null) dockF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Dock Service ready", e); reportWtf("making Dock Service ready", e);
} }
try { try {
if (usbF != null) usbF.systemReady(); if (recognitionF != null) recognitionF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making USB Service ready", e); reportWtf("making Recognition Service ready", e);
} }
try { Watchdog.getInstance().start();
if (recognitionF != null) recognitionF.systemReady();
} catch (Throwable e) {
reportWtf("making Recognition Service ready", e);
}
Watchdog.getInstance().start();
// It is now okay to let the various system services start their // It is now okay to let the various system services start their
// third party code... // third party code...
mSystemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START); mSystemServiceManager.startBootPhase(
SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
try { try {
if (wallpaperF != null) wallpaperF.systemRunning(); if (wallpaperF != null) wallpaperF.systemRunning();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying WallpaperService running", e); reportWtf("Notifying WallpaperService running", e);
} }
try { try {
if (immF != null) immF.systemRunning(statusBarF); if (immF != null) immF.systemRunning(statusBarF);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying InputMethodService running", e); reportWtf("Notifying InputMethodService running", e);
} }
try { try {
if (locationF != null) locationF.systemRunning(); if (locationF != null) locationF.systemRunning();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying Location Service running", e); reportWtf("Notifying Location Service running", e);
} }
try { try {
if (countryDetectorF != null) countryDetectorF.systemRunning(); if (countryDetectorF != null) countryDetectorF.systemRunning();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying CountryDetectorService running", e); reportWtf("Notifying CountryDetectorService running", e);
} }
try { try {
if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning(); if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying NetworkTimeService running", e); reportWtf("Notifying NetworkTimeService running", e);
} }
try { try {
if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemRunning(); if (commonTimeMgmtServiceF != null) {
} catch (Throwable e) { commonTimeMgmtServiceF.systemRunning();
reportWtf("Notifying CommonTimeManagementService running", e); }
} } catch (Throwable e) {
try { reportWtf("Notifying CommonTimeManagementService running", e);
if (textServiceManagerServiceF != null) }
textServiceManagerServiceF.systemRunning(); try {
} catch (Throwable e) { if (textServiceManagerServiceF != null)
reportWtf("Notifying TextServicesManagerService running", e); textServiceManagerServiceF.systemRunning();
} } catch (Throwable e) {
try { reportWtf("Notifying TextServicesManagerService running", e);
if (atlasF != null) atlasF.systemRunning(); }
} catch (Throwable e) { try {
reportWtf("Notifying AssetAtlasService running", e); if (atlasF != null) atlasF.systemRunning();
} } catch (Throwable e) {
try { reportWtf("Notifying AssetAtlasService running", e);
// TODO(BT) Pass parameter to input manager }
if (inputManagerF != null) inputManagerF.systemRunning(); try {
} catch (Throwable e) { // TODO(BT) Pass parameter to input manager
reportWtf("Notifying InputManagerService running", e); 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 { mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETE);
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);
}
mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETE);
} }
}); });
} }

12
services/usb/Android.mk Normal file
View File

@@ -0,0 +1,12 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := services.usb
LOCAL_SRC_FILES += \
$(call all-java-files-under,java)
LOCAL_JAVA_LIBRARIES := services.core
include $(BUILD_STATIC_JAVA_LIBRARY)

View File

@@ -812,7 +812,7 @@ public class UsbDeviceManager {
if (mOemModeMap == null) { if (mOemModeMap == null) {
mOemModeMap = new HashMap<String, List<Pair<String, String>>>(); mOemModeMap = new HashMap<String, List<Pair<String, String>>>();
} }
List overrideList = mOemModeMap.get(items[0]); List<Pair<String, String>> overrideList = mOemModeMap.get(items[0]);
if (overrideList == null) { if (overrideList == null) {
overrideList = new LinkedList<Pair<String, String>>(); overrideList = new LinkedList<Pair<String, String>>();
mOemModeMap.put(items[0], overrideList); mOemModeMap.put(items[0], overrideList);

View File

@@ -32,6 +32,7 @@ import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.android.server.SystemService;
import java.io.File; import java.io.File;
import java.io.FileDescriptor; import java.io.FileDescriptor;
@@ -43,6 +44,28 @@ import java.io.PrintWriter;
* support is delegated to UsbDeviceManager. * support is delegated to UsbDeviceManager.
*/ */
public class UsbService extends IUsbManager.Stub { public class UsbService extends IUsbManager.Stub {
public static class Lifecycle extends SystemService {
private UsbService mUsbService;
public Lifecycle(Context context) {
super(context);
}
@Override
public void onStart() {
mUsbService = new UsbService(getContext());
publishBinderService(Context.USB_SERVICE, mUsbService);
}
@Override
public void onBootPhase(int phase) {
if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
mUsbService.systemReady();
}
}
}
private static final String TAG = "UsbService"; private static final String TAG = "UsbService";
private final Context mContext; private final Context mContext;