summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2014-01-07 20:58:16 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-01-07 20:58:16 +0000
commitdfc73e9c243092d395913737af622c89ad1830be (patch)
treeac008d727dc8126432d8d95f720c6867484a9460 /services
parent58a8a678bd72da68e6a21852926084fefbb3e02a (diff)
parent66e9b1e1178813037daf3798b8fe23467c4b91ab (diff)
downloadframeworks_base-dfc73e9c243092d395913737af622c89ad1830be.zip
frameworks_base-dfc73e9c243092d395913737af622c89ad1830be.tar.gz
frameworks_base-dfc73e9c243092d395913737af622c89ad1830be.tar.bz2
am 66e9b1e1: Merge "Move SystemService code to frameworks/base/core" into klp-modular-dev
* commit '66e9b1e1178813037daf3798b8fe23467c4b91ab': Move SystemService code to frameworks/base/core
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/LocalServices.java58
-rw-r--r--services/core/java/com/android/server/SystemService.java156
-rw-r--r--services/core/java/com/android/server/SystemServiceManager.java163
3 files changed, 0 insertions, 377 deletions
diff --git a/services/core/java/com/android/server/LocalServices.java b/services/core/java/com/android/server/LocalServices.java
deleted file mode 100644
index deff79d..0000000
--- a/services/core/java/com/android/server/LocalServices.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server;
-
-import android.util.ArrayMap;
-
-/**
- * This class is used in a similar way as ServiceManager, except the services registered here
- * are not Binder objects and are only available in the same process.
- *
- * Once all services are converted to the SystemService interface, this class can be absorbed
- * into SystemServiceManager.
- */
-public final class LocalServices {
- private LocalServices() {}
-
- private static final ArrayMap<Class<?>, Object> sLocalServiceObjects =
- new ArrayMap<Class<?>, Object>();
-
- /**
- * Returns a local service instance that implements the specified interface.
- *
- * @param type The type of service.
- * @return The service object.
- */
- @SuppressWarnings("unchecked")
- public static <T> T getService(Class<T> type) {
- synchronized (sLocalServiceObjects) {
- return (T) sLocalServiceObjects.get(type);
- }
- }
-
- /**
- * Adds a service instance of the specified interface to the global registry of local services.
- */
- public static <T> void addService(Class<T> type, T service) {
- synchronized (sLocalServiceObjects) {
- if (sLocalServiceObjects.containsKey(type)) {
- throw new IllegalStateException("Overriding service registration");
- }
- sLocalServiceObjects.put(type, service);
- }
- }
-}
diff --git a/services/core/java/com/android/server/SystemService.java b/services/core/java/com/android/server/SystemService.java
deleted file mode 100644
index b9d30ce..0000000
--- a/services/core/java/com/android/server/SystemService.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server;
-
-import android.content.Context;
-import android.os.IBinder;
-import android.os.ServiceManager;
-
-/**
- * System services respond to lifecycle events that help the services know what
- */
-public abstract class SystemService {
- /*
- * Boot Phases
- */
- public static final int PHASE_LOCK_SETTINGS_READY = 480;
- public static final int PHASE_SYSTEM_SERVICES_READY = 500;
- public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
- public static final int PHASE_BOOT_COMPLETE = 1000;
-
- private SystemServiceManager mManager;
- private Context mContext;
-
- final void init(Context context, SystemServiceManager manager) {
- mContext = context;
- mManager = manager;
- onCreate(context);
- }
-
- public final boolean isSafeMode() {
- return mManager.isSafeMode();
- }
-
- /**
- * Services are not yet available. This is a good place to do setup work that does
- * not require other services.
- *
- * @param context The system context.
- */
- public void onCreate(Context context) {}
-
- /**
- * Called when the dependencies listed in the @Service class-annotation are available
- * and after the chosen start phase.
- * When this method returns, the service should be published.
- */
- public abstract void onStart();
-
- /**
- * Called on each phase of the boot process. Phases before the service's start phase
- * (as defined in the @Service annotation) are never received.
- *
- * @param phase The current boot phase.
- */
- public void onBootPhase(int phase) {}
-
- /**
- * Publish the service so it is accessible to other services and apps.
- */
- protected final void publishBinderService(String name, IBinder service) {
- ServiceManager.addService(name, service);
- }
-
- /**
- * Get a binder service by its name.
- */
- protected final IBinder getBinderService(String name) {
- return ServiceManager.getService(name);
- }
-
- /**
- * Publish the service so it is only accessible to the system process.
- */
- protected final <T> void publishLocalService(Class<T> type, T service) {
- LocalServices.addService(type, service);
- }
-
- /**
- * Get a local service by interface.
- */
- protected final <T> T getLocalService(Class<T> type) {
- return LocalServices.getService(type);
- }
-
- public final Context getContext() {
- return mContext;
- }
-
-// /**
-// * Called when a new user has been created. If your service deals with multiple users, this
-// * method should be overridden.
-// *
-// * @param userHandle The user that was created.
-// */
-// public void onUserCreated(int userHandle) {
-// }
-//
-// /**
-// * Called when an existing user has started a new session. If your service deals with multiple
-// * users, this method should be overridden.
-// *
-// * @param userHandle The user who started a new session.
-// */
-// public void onUserStarted(int userHandle) {
-// }
-//
-// /**
-// * Called when a background user session has entered the foreground. If your service deals with
-// * multiple users, this method should be overridden.
-// *
-// * @param userHandle The user who's session entered the foreground.
-// */
-// public void onUserForeground(int userHandle) {
-// }
-//
-// /**
-// * Called when a foreground user session has entered the background. If your service deals with
-// * multiple users, this method should be overridden;
-// *
-// * @param userHandle The user who's session entered the background.
-// */
-// public void onUserBackground(int userHandle) {
-// }
-//
-// /**
-// * Called when a user's active session has stopped. If your service deals with multiple users,
-// * this method should be overridden.
-// *
-// * @param userHandle The user who's session has stopped.
-// */
-// public void onUserStopped(int userHandle) {
-// }
-//
-// /**
-// * Called when a user has been removed from the system. If your service deals with multiple
-// * users, this method should be overridden.
-// *
-// * @param userHandle The user who has been removed.
-// */
-// public void onUserRemoved(int userHandle) {
-// }
-}
diff --git a/services/core/java/com/android/server/SystemServiceManager.java b/services/core/java/com/android/server/SystemServiceManager.java
deleted file mode 100644
index 59f7e92..0000000
--- a/services/core/java/com/android/server/SystemServiceManager.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server;
-
-import android.content.Context;
-import android.util.Log;
-import android.util.Slog;
-
-import java.util.ArrayList;
-
-/**
- * Manages creating, starting, and other lifecycle events of system services.
- */
-public class SystemServiceManager {
- private static final String TAG = "SystemServiceManager";
-
- private final Context mContext;
- private boolean mSafeMode;
-
- // Services that should receive lifecycle events.
- private final ArrayList<SystemService> mServices = new ArrayList<SystemService>();
-
- private int mCurrentPhase = -1;
-
- public SystemServiceManager(Context context) {
- mContext = context;
- }
-
- public void startService(String className) {
- try {
- startService(Class.forName(className));
- } catch (ClassNotFoundException cnfe) {
- Slog.i(TAG, className + " not available, ignoring.");
- }
- }
-
- /**
- * Creates and starts a system service. The class must be a subclass of
- * {@link com.android.server.SystemService}.
- *
- * @param serviceClass A Java class that implements the SystemService interface.
- * @throws RuntimeException if the service fails to start.
- */
- public void startService(Class<?> serviceClass) {
- final SystemService serviceInstance = createInstance(serviceClass);
- try {
- Slog.i(TAG, "Creating " + serviceClass.getSimpleName());
- serviceInstance.init(mContext, this);
- } catch (Throwable e) {
- throw new RuntimeException("Failed to create service " + serviceClass.getName(), e);
- }
-
- mServices.add(serviceInstance);
-
- try {
- Slog.i(TAG, "Starting " + serviceClass.getSimpleName());
- serviceInstance.onStart();
- } catch (Throwable e) {
- throw new RuntimeException("Failed to start service " + serviceClass.getName(), e);
- }
- }
-
- /**
- * Starts the specified boot phase for all system services that have been started up to
- * this point.
- *
- * @param phase The boot phase to start.
- */
- public void startBootPhase(final int phase) {
- if (phase <= mCurrentPhase) {
- throw new IllegalArgumentException("Next phase must be larger than previous");
- }
- mCurrentPhase = phase;
-
- Slog.i(TAG, "Starting phase " + mCurrentPhase);
-
- final int serviceLen = mServices.size();
- for (int i = 0; i < serviceLen; i++) {
- final SystemService service = mServices.get(i);
- try {
- service.onBootPhase(mCurrentPhase);
- } catch (Throwable e) {
- reportWtf("Service " + service.getClass().getName() +
- " threw an Exception processing boot phase " + mCurrentPhase, e);
- }
- }
- }
-
- /** Sets the safe mode flag for services to query. */
- public void setSafeMode(boolean safeMode) {
- mSafeMode = safeMode;
- }
-
- /**
- * Returns whether we are booting into safe mode.
- * @return safe mode flag
- */
- public boolean isSafeMode() {
- return mSafeMode;
- }
-
- /**
- * Outputs the state of this manager to the System log.
- */
- public void dump() {
- StringBuilder builder = new StringBuilder();
- builder.append("Current phase: ").append(mCurrentPhase).append("\n");
- builder.append("Services:\n");
- final int startedLen = mServices.size();
- for (int i = 0; i < startedLen; i++) {
- final SystemService service = mServices.get(i);
- builder.append("\t")
- .append(service.getClass().getSimpleName())
- .append("\n");
- }
-
- Slog.e(TAG, builder.toString());
- }
-
- private SystemService createInstance(Class<?> clazz) {
- // Make sure it's a type we expect
- if (!SystemService.class.isAssignableFrom(clazz)) {
- reportWtf("Class " + clazz.getName() + " does not extend " +
- SystemService.class.getName());
- }
-
- try {
- return (SystemService) clazz.newInstance();
- } catch (InstantiationException e) {
- reportWtf("Class " + clazz.getName() + " is abstract", e);
- } catch (IllegalAccessException e) {
- reportWtf("Class " + clazz.getName() +
- " must have a public no-arg constructor", e);
- }
- return null;
- }
-
- private static void reportWtf(String message) {
- reportWtf(message, null);
- }
-
- private static void reportWtf(String message, Throwable e) {
- Slog.i(TAG, "******************************");
- Log.wtf(TAG, message, e);
-
- // Make sure we die
- throw new RuntimeException(message, e);
- }
-}