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

Commit e89a9a3f authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "Introduce a Lifecycle for system services" into klp-modular-dev

parents 800d4d72 182f73fc
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
LOCAL_PATH:= $(call my-dir)


# the library
# Build services.jar
# ============================================================
# ============================================================
include $(CLEAR_VARS)
include $(CLEAR_VARS)


LOCAL_MODULE:= services
LOCAL_MODULE_CLASS := JAVA_LIBRARIES

LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := \
		$(call all-subdir-java-files) \
		$(call all-subdir-java-files) \
		com/android/server/EventLogTags.logtags \
		com/android/server/EventLogTags.logtags \
		com/android/server/am/EventLogTags.logtags
		com/android/server/am/EventLogTags.logtags


LOCAL_MODULE:= services

LOCAL_JAVA_LIBRARIES := android.policy conscrypt telephony-common
LOCAL_JAVA_LIBRARIES := android.policy conscrypt telephony-common


include $(BUILD_JAVA_LIBRARY)
include $(BUILD_JAVA_LIBRARY)

include $(BUILD_DROIDDOC)
include $(BUILD_DROIDDOC)
+296 −279

File changed.

Preview size limit exceeded, changes collapsed.

+18 −15
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.server;
import android.os.BatteryStats;
import android.os.BatteryStats;
import com.android.internal.app.IBatteryStats;
import com.android.internal.app.IBatteryStats;
import com.android.server.am.BatteryStatsService;
import com.android.server.am.BatteryStatsService;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;


import android.app.ActivityManagerNative;
import android.app.ActivityManagerNative;
import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -134,13 +136,10 @@ public final class BatteryService extends Binder {


    private boolean mSentLowBatteryBroadcast = false;
    private boolean mSentLowBatteryBroadcast = false;


    private BatteryListener mBatteryPropertiesListener;
    public BatteryService(Context context, LightsManager lightsManager) {
    private IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;

    public BatteryService(Context context, LightsService lights) {
        mContext = context;
        mContext = context;
        mHandler = new Handler(true /*async*/);
        mHandler = new Handler(true /*async*/);
        mLed = new Led(context, lights);
        mLed = new Led(context, lightsManager);
        mBatteryStats = BatteryStatsService.getService();
        mBatteryStats = BatteryStatsService.getService();


        mCriticalBatteryLevel = mContext.getResources().getInteger(
        mCriticalBatteryLevel = mContext.getResources().getInteger(
@@ -158,13 +157,11 @@ public final class BatteryService extends Binder {
                    "DEVPATH=/devices/virtual/switch/invalid_charger");
                    "DEVPATH=/devices/virtual/switch/invalid_charger");
        }
        }


        mBatteryPropertiesListener = new BatteryListener();

        IBinder b = ServiceManager.getService("batterypropreg");
        IBinder b = ServiceManager.getService("batterypropreg");
        mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface(b);
        final IBatteryPropertiesRegistrar batteryPropertiesRegistrar =

                IBatteryPropertiesRegistrar.Stub.asInterface(b);
        try {
        try {
            mBatteryPropertiesRegistrar.registerListener(mBatteryPropertiesListener);
            batteryPropertiesRegistrar.registerListener(new BatteryListener());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            // Should never happen.
            // Should never happen.
        }
        }
@@ -688,7 +685,7 @@ public final class BatteryService extends Binder {
    };
    };


    private final class Led {
    private final class Led {
        private final LightsService.Light mBatteryLight;
        private final Light mBatteryLight;


        private final int mBatteryLowARGB;
        private final int mBatteryLowARGB;
        private final int mBatteryMediumARGB;
        private final int mBatteryMediumARGB;
@@ -696,8 +693,8 @@ public final class BatteryService extends Binder {
        private final int mBatteryLedOn;
        private final int mBatteryLedOn;
        private final int mBatteryLedOff;
        private final int mBatteryLedOff;


        public Led(Context context, LightsService lights) {
        public Led(Context context, LightsManager lights) {
            mBatteryLight = lights.getLight(LightsService.LIGHT_ID_BATTERY);
            mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);


            mBatteryLowARGB = context.getResources().getInteger(
            mBatteryLowARGB = context.getResources().getInteger(
                    com.android.internal.R.integer.config_notificationsBatteryLowARGB);
                    com.android.internal.R.integer.config_notificationsBatteryLowARGB);
@@ -723,7 +720,7 @@ public final class BatteryService extends Binder {
                    mBatteryLight.setColor(mBatteryLowARGB);
                    mBatteryLight.setColor(mBatteryLowARGB);
                } else {
                } else {
                    // Flash red when battery is low and not charging
                    // Flash red when battery is low and not charging
                    mBatteryLight.setFlashing(mBatteryLowARGB, LightsService.LIGHT_FLASH_TIMED,
                    mBatteryLight.setFlashing(mBatteryLowARGB, Light.LIGHT_FLASH_TIMED,
                            mBatteryLedOn, mBatteryLedOff);
                            mBatteryLedOn, mBatteryLedOff);
                }
                }
            } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
            } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
@@ -743,8 +740,14 @@ public final class BatteryService extends Binder {
    }
    }


    private final class BatteryListener extends IBatteryPropertiesListener.Stub {
    private final class BatteryListener extends IBatteryPropertiesListener.Stub {
        @Override
        public void batteryPropertiesChanged(BatteryProperties props) {
        public void batteryPropertiesChanged(BatteryProperties props) {
            final long identity = Binder.clearCallingIdentity();
            try {
                BatteryService.this.update(props);
                BatteryService.this.update(props);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
       }
       }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ import com.android.internal.view.IInputMethodClient;
import com.android.internal.view.IInputMethodManager;
import com.android.internal.view.IInputMethodManager;
import com.android.internal.view.IInputMethodSession;
import com.android.internal.view.IInputMethodSession;
import com.android.internal.view.InputBindResult;
import com.android.internal.view.InputBindResult;
import com.android.server.EventLogTags;
import com.android.server.statusbar.StatusBarManagerService;
import com.android.server.wm.WindowManagerService;
import com.android.server.wm.WindowManagerService;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
+58 −0
Original line number Original line Diff line number Diff line
/*
 * 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);
        }
    }
}
Loading