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