Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f357d32 authored by Jeff Brown's avatar Jeff Brown
Browse files

Start untangling system server early bootstrapping.

Refactored SystemServer to get rid of a bunch of legacy cruft related
to how the ServerThread used to be started up.

Create system context first when system server starts.  This removes
the tangled initialization order dependency that forced us to start
the activity manager service before most anything else.

Moved factory test related constants into the FactoryTest class.

Partially migrated Installer, ActivityManagerService, and
PowerManagerService to the new SystemService pattern.  There's more
work to be done here, particularly around the lifecycle of the
power manager.

Bug: 12172368
Change-Id: Ia527dd56e3b3fd90f9eeb41289dbe044921230d4
parent 02cc684e
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -25,6 +25,20 @@ package android.os;
 * {@hide}
 */
public final class FactoryTest {
    public static final int FACTORY_TEST_OFF = 0;
    public static final int FACTORY_TEST_LOW_LEVEL = 1;
    public static final int FACTORY_TEST_HIGH_LEVEL = 2;

    /**
     * Gets the current factory test mode.
     *
     * @return One of: {@link #FACTORY_TEST_OFF}, {@link #FACTORY_TEST_LOW_LEVEL},
     * or {@link #FACTORY_TEST_HIGH_LEVEL}.
     */
    public static int getMode() {
        return SystemProperties.getInt("ro.factorytest", FACTORY_TEST_OFF);
    }

    /**
     * When true, long-press on power should immediately cause the device to
     * shut down, without prompting the user.
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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 android.os;

import android.view.WindowManagerPolicy;

/**
 * Power manager local system service interface.
 *
 * @hide Only for use within the system server.
 */
public interface PowerManagerInternal {
    /**
     * Used by the window manager to override the screen brightness based on the
     * current foreground activity.
     *
     * This method must only be called by the window manager.
     *
     * @param brightness The overridden brightness, or -1 to disable the override.
     */
    public void setScreenBrightnessOverrideFromWindowManager(int brightness);

    /**
     * Used by the window manager to override the button brightness based on the
     * current foreground activity.
     *
     * This method must only be called by the window manager.
     *
     * @param brightness The overridden brightness, or -1 to disable the override.
     */
    public void setButtonBrightnessOverrideFromWindowManager(int brightness);

    /**
     * Used by the window manager to override the user activity timeout based on the
     * current foreground activity.  It can only be used to make the timeout shorter
     * than usual, not longer.
     *
     * This method must only be called by the window manager.
     *
     * @param timeoutMillis The overridden timeout, or -1 to disable the override.
     */
    public void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);

    // TODO: Remove this and retrieve as a local service instead.
    public void setPolicy(WindowManagerPolicy policy);
}
+7 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.FileUtils;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.ParcelFormatException;
@@ -113,6 +114,10 @@ public final class BatteryStatsImpl extends BatteryStats {
    }

    final class MyHandler extends Handler {
        public MyHandler(Looper looper) {
            super(looper, null, true);
        }

        @Override
        public void handleMessage(Message msg) {
            BatteryCallback cb = mCallback;
@@ -4487,9 +4492,9 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
    }

    public BatteryStatsImpl(String filename) {
    public BatteryStatsImpl(String filename, Handler handler) {
        mFile = new JournaledFile(new File(filename), new File(filename + ".tmp"));
        mHandler = new MyHandler();
        mHandler = new MyHandler(handler.getLooper());
        mStartCount++;
        mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables);
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
+0 −7
Original line number Diff line number Diff line
@@ -16,18 +16,11 @@

package com.android.internal.os;

import android.os.Binder;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.EventLog;
import android.util.Log;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.Modifier;

/**
 * Private and debugging Binder APIs.
+15 −4
Original line number Diff line number Diff line
@@ -43,11 +43,18 @@ public class SystemServiceManager {
        mContext = context;
    }

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

@@ -56,10 +63,12 @@ public class SystemServiceManager {
     * {@link com.android.server.SystemService}.
     *
     * @param serviceClass A Java class that implements the SystemService interface.
     * @return The service instance, never null.
     * @throws RuntimeException if the service fails to start.
     */
    public void startService(Class<?> serviceClass) {
        final SystemService serviceInstance = createInstance(serviceClass);
    @SuppressWarnings("unchecked")
    public <T extends SystemService> T startService(Class<T> serviceClass) {
        final T serviceInstance = (T)createInstance(serviceClass);
        try {
            Slog.i(TAG, "Creating " + serviceClass.getSimpleName());
            serviceInstance.init(mContext, this);
@@ -75,6 +84,8 @@ public class SystemServiceManager {
        } catch (Throwable e) {
            throw new RuntimeException("Failed to start service " + serviceClass.getName(), e);
        }

        return serviceInstance;
    }

    /**
Loading