Loading services/core/java/com/android/server/BatteryService.java +99 −50 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.DropBoxManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.Trace; import android.os.UEventObserver; import android.os.UserHandle; import android.provider.Settings; Loading Loading @@ -246,6 +247,7 @@ public final class BatteryService extends SystemService { } private void registerHealthCallback() { traceBegin("HealthInitWrapper"); mHealthServiceWrapper = new HealthServiceWrapper(); mHealthHalCallback = new HealthHalCallback(); // IHealth is lazily retrieved. Loading @@ -259,8 +261,11 @@ public final class BatteryService extends SystemService { } catch (NoSuchElementException ex) { Slog.e(TAG, "health: cannot register callback. (no supported health HAL service)"); throw ex; } finally { traceEnd(); } traceBegin("HealthInitWaitUpdate"); // init register for new service notifications, and IServiceManager should return the // existing service in a near future. Wait for this.update() to instantiate // the initial mHealthInfo. Loading @@ -280,6 +285,7 @@ public final class BatteryService extends SystemService { Slog.i(TAG, "health: Waited " + (SystemClock.uptimeMillis() - beforeWait) + "ms and received the update."); traceEnd(); } private void updateBatteryWarningLevelLocked() { Loading Loading @@ -375,6 +381,7 @@ public final class BatteryService extends SystemService { } private void update(HealthInfo info) { traceBegin("HealthInfoUpdate"); synchronized (mLock) { if (!mUpdatesStopped) { mHealthInfo = info; Loading @@ -385,6 +392,7 @@ public final class BatteryService extends SystemService { copy(mLastHealthInfo, info); } } traceEnd(); } private static void copy(HealthInfo dst, HealthInfo src) { Loading Loading @@ -932,6 +940,14 @@ public final class BatteryService extends SystemService { proto.flush(); } private static void traceBegin(String name) { Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, name); } private static void traceEnd() { Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); } private final class Led { private final Light mBatteryLight; Loading Loading @@ -997,6 +1013,7 @@ public final class BatteryService extends SystemService { String instance) { if (newService == null) return; traceBegin("HealthUnregisterCallback"); try { if (oldService != null) { int r = oldService.unregisterCallback(this); Loading @@ -1008,8 +1025,11 @@ public final class BatteryService extends SystemService { } catch (RemoteException ex) { Slog.w(TAG, "health: cannot unregister previous callback (transaction error): " + ex.getMessage()); } finally { traceEnd(); } traceBegin("HealthRegisterCallback"); try { int r = newService.registerCallback(this); if (r != Result.SUCCESS) { Loading @@ -1022,6 +1042,8 @@ public final class BatteryService extends SystemService { } catch (RemoteException ex) { Slog.e(TAG, "health: cannot register callback (transaction error): " + ex.getMessage()); } finally { traceEnd(); } } } Loading Loading @@ -1054,6 +1076,8 @@ public final class BatteryService extends SystemService { Slog.e(TAG, "health: must not call unregisterListener on battery properties"); } public int getProperty(int id, final BatteryProperty prop) throws RemoteException { traceBegin("HealthGetProperty"); try { IHealth service = mHealthServiceWrapper.getLastService(); if (service == null) throw new RemoteException("no health service"); final MutableInt outResult = new MutableInt(Result.NOT_SUPPORTED); Loading Loading @@ -1096,11 +1120,19 @@ public final class BatteryService extends SystemService { break; } return outResult.value; } finally { traceEnd(); } } public void scheduleUpdate() throws RemoteException { traceBegin("HealthScheduleUpdate"); try { IHealth service = mHealthServiceWrapper.getLastService(); if (service == null) throw new RemoteException("no health service"); service.update(); } finally { traceEnd(); } } } Loading Loading @@ -1203,16 +1235,28 @@ public final class BatteryService extends SystemService { if (callback == null || managerSupplier == null || healthSupplier == null) throw new NullPointerException(); IServiceManager manager; mCallback = callback; mHealthSupplier = healthSupplier; IServiceManager manager = managerSupplier.get(); traceBegin("HealthInitGetManager"); try { manager = managerSupplier.get(); } finally { traceEnd(); } for (String name : sAllInstances) { traceBegin("HealthInitGetTransport_" + name); try { if (manager.getTransport(IHealth.kInterfaceName, name) != IServiceManager.Transport.EMPTY) { mInstanceName = name; break; } } finally { traceEnd(); } } if (mInstanceName == null) { Loading @@ -1221,7 +1265,12 @@ public final class BatteryService extends SystemService { sAllInstances.toString())); } traceBegin("HealthInitRegisterNotification"); try { manager.registerForNotifications(IHealth.kInterfaceName, mInstanceName, mNotification); } finally { traceEnd(); } Slog.i(TAG, "health: HealthServiceWrapper listening to instance " + mInstanceName); } Loading Loading
services/core/java/com/android/server/BatteryService.java +99 −50 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.DropBoxManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.Trace; import android.os.UEventObserver; import android.os.UserHandle; import android.provider.Settings; Loading Loading @@ -246,6 +247,7 @@ public final class BatteryService extends SystemService { } private void registerHealthCallback() { traceBegin("HealthInitWrapper"); mHealthServiceWrapper = new HealthServiceWrapper(); mHealthHalCallback = new HealthHalCallback(); // IHealth is lazily retrieved. Loading @@ -259,8 +261,11 @@ public final class BatteryService extends SystemService { } catch (NoSuchElementException ex) { Slog.e(TAG, "health: cannot register callback. (no supported health HAL service)"); throw ex; } finally { traceEnd(); } traceBegin("HealthInitWaitUpdate"); // init register for new service notifications, and IServiceManager should return the // existing service in a near future. Wait for this.update() to instantiate // the initial mHealthInfo. Loading @@ -280,6 +285,7 @@ public final class BatteryService extends SystemService { Slog.i(TAG, "health: Waited " + (SystemClock.uptimeMillis() - beforeWait) + "ms and received the update."); traceEnd(); } private void updateBatteryWarningLevelLocked() { Loading Loading @@ -375,6 +381,7 @@ public final class BatteryService extends SystemService { } private void update(HealthInfo info) { traceBegin("HealthInfoUpdate"); synchronized (mLock) { if (!mUpdatesStopped) { mHealthInfo = info; Loading @@ -385,6 +392,7 @@ public final class BatteryService extends SystemService { copy(mLastHealthInfo, info); } } traceEnd(); } private static void copy(HealthInfo dst, HealthInfo src) { Loading Loading @@ -932,6 +940,14 @@ public final class BatteryService extends SystemService { proto.flush(); } private static void traceBegin(String name) { Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, name); } private static void traceEnd() { Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); } private final class Led { private final Light mBatteryLight; Loading Loading @@ -997,6 +1013,7 @@ public final class BatteryService extends SystemService { String instance) { if (newService == null) return; traceBegin("HealthUnregisterCallback"); try { if (oldService != null) { int r = oldService.unregisterCallback(this); Loading @@ -1008,8 +1025,11 @@ public final class BatteryService extends SystemService { } catch (RemoteException ex) { Slog.w(TAG, "health: cannot unregister previous callback (transaction error): " + ex.getMessage()); } finally { traceEnd(); } traceBegin("HealthRegisterCallback"); try { int r = newService.registerCallback(this); if (r != Result.SUCCESS) { Loading @@ -1022,6 +1042,8 @@ public final class BatteryService extends SystemService { } catch (RemoteException ex) { Slog.e(TAG, "health: cannot register callback (transaction error): " + ex.getMessage()); } finally { traceEnd(); } } } Loading Loading @@ -1054,6 +1076,8 @@ public final class BatteryService extends SystemService { Slog.e(TAG, "health: must not call unregisterListener on battery properties"); } public int getProperty(int id, final BatteryProperty prop) throws RemoteException { traceBegin("HealthGetProperty"); try { IHealth service = mHealthServiceWrapper.getLastService(); if (service == null) throw new RemoteException("no health service"); final MutableInt outResult = new MutableInt(Result.NOT_SUPPORTED); Loading Loading @@ -1096,11 +1120,19 @@ public final class BatteryService extends SystemService { break; } return outResult.value; } finally { traceEnd(); } } public void scheduleUpdate() throws RemoteException { traceBegin("HealthScheduleUpdate"); try { IHealth service = mHealthServiceWrapper.getLastService(); if (service == null) throw new RemoteException("no health service"); service.update(); } finally { traceEnd(); } } } Loading Loading @@ -1203,16 +1235,28 @@ public final class BatteryService extends SystemService { if (callback == null || managerSupplier == null || healthSupplier == null) throw new NullPointerException(); IServiceManager manager; mCallback = callback; mHealthSupplier = healthSupplier; IServiceManager manager = managerSupplier.get(); traceBegin("HealthInitGetManager"); try { manager = managerSupplier.get(); } finally { traceEnd(); } for (String name : sAllInstances) { traceBegin("HealthInitGetTransport_" + name); try { if (manager.getTransport(IHealth.kInterfaceName, name) != IServiceManager.Transport.EMPTY) { mInstanceName = name; break; } } finally { traceEnd(); } } if (mInstanceName == null) { Loading @@ -1221,7 +1265,12 @@ public final class BatteryService extends SystemService { sAllInstances.toString())); } traceBegin("HealthInitRegisterNotification"); try { manager.registerForNotifications(IHealth.kInterfaceName, mInstanceName, mNotification); } finally { traceEnd(); } Slog.i(TAG, "health: HealthServiceWrapper listening to instance " + mInstanceName); } Loading