diff options
author | Steve Paik <spaik@google.com> | 2018-02-09 17:42:00 -0800 |
---|---|---|
committer | Steve Paik <spaik@google.com> | 2018-02-14 23:10:46 -0800 |
commit | 0f9fc00ffb03bc8e88c0a55e2e21b4ffdba19edf (patch) | |
tree | cdf36f8257985dff03451a7d724f8fe689d87c23 | |
parent | 1c8ecb2cc5129d1098df40ef576b710ef00d0c1d (diff) | |
download | Car-0f9fc00ffb03bc8e88c0a55e2e21b4ffdba19edf.tar.gz |
Call forceSuspend from CarPowerManagementService
Bug: 32061842
Test: Manual instrumentation
Change-Id: Ib3ad05bb6e3f74a95ece693f2f3098e02a1d1158
8 files changed, 61 insertions, 22 deletions
diff --git a/service/src/com/android/car/CarPowerManagementService.java b/service/src/com/android/car/CarPowerManagementService.java index 16ece5181a..8b9d3bea72 100644 --- a/service/src/com/android/car/CarPowerManagementService.java +++ b/service/src/com/android/car/CarPowerManagementService.java @@ -417,7 +417,10 @@ public class CarPowerManagementService implements CarServiceBase, synchronized (this) { mLastSleepEntryTime = SystemClock.elapsedRealtime(); } - mSystemInterface.enterDeepSleep(wakeupTimeSec); + if (mSystemInterface.enterDeepSleep(wakeupTimeSec) == false) { + // System did not suspend. Need to shutdown + // TODO: Shutdown gracefully + } mHal.sendSleepExit(); for (PowerServiceEventListener listener : mListeners) { listener.onSleepExit(); diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java index 34a6c60fd6..0b7019fb76 100644 --- a/service/src/com/android/car/ICarImpl.java +++ b/service/src/com/android/car/ICarImpl.java @@ -78,6 +78,7 @@ public class ICarImpl extends ICar.Stub { private final PerUserCarServiceHelper mPerUserCarServiceHelper; private final CarDiagnosticService mCarDiagnosticService; private final CarStorageMonitoringService mCarStorageMonitoringService; + private final SystemInterface mSystemInterface; private VmsSubscriberService mVmsSubscriberService; private VmsPublisherService mVmsPublisherService; @@ -98,6 +99,7 @@ public class ICarImpl extends ICar.Stub { public ICarImpl(Context serviceContext, IVehicle vehicle, SystemInterface systemInterface, CanBusErrorNotifier errorNotifier) { mContext = serviceContext; + mSystemInterface = systemInterface; mHal = new VehicleHal(vehicle); mSystemActivityMonitoringService = new SystemActivityMonitoringService(serviceContext); mCarPowerManagementService = new CarPowerManagementService( @@ -203,6 +205,7 @@ public class ICarImpl extends ICar.Stub { } synchronized (this) { mICarServiceHelper = ICarServiceHelper.Stub.asInterface(helper); + mSystemInterface.setCarServiceHelper(mICarServiceHelper); } } diff --git a/service/src/com/android/car/systeminterface/SystemInterface.java b/service/src/com/android/car/systeminterface/SystemInterface.java index f1cb9ed704..a6af5d7525 100644 --- a/service/src/com/android/car/systeminterface/SystemInterface.java +++ b/service/src/com/android/car/systeminterface/SystemInterface.java @@ -22,6 +22,7 @@ import com.android.car.procfsinspector.ProcessInfo; import com.android.car.storagemonitoring.LifetimeWriteInfoProvider; import com.android.car.storagemonitoring.UidIoStatsProvider; import com.android.car.storagemonitoring.WearInformationProvider; +import com.android.internal.car.ICarServiceHelper; import java.io.File; import java.time.Duration; import java.util.List; @@ -60,6 +61,9 @@ public final class SystemInterface implements DisplayInterface, IOInterface, public SystemStateInterface getSystemStateInterface() { return mSystemStateInterface; } public TimeInterface getTimeInterface() { return mTimeInterface; } public WakeLockInterface getWakeLockInterface() { return mWakeLockInterface; } + public void setCarServiceHelper(ICarServiceHelper helper) { + mSystemStateInterface.setCarServiceHelper(helper); + } @Override public File getFilesDir() { @@ -142,8 +146,8 @@ public final class SystemInterface implements DisplayInterface, IOInterface, } @Override - public void enterDeepSleep(int wakeupTimeSec) { - mSystemStateInterface.enterDeepSleep(wakeupTimeSec); + public boolean enterDeepSleep(int wakeupTimeSec) { + return mSystemStateInterface.enterDeepSleep(wakeupTimeSec); } @Override diff --git a/service/src/com/android/car/systeminterface/SystemStateInterface.java b/service/src/com/android/car/systeminterface/SystemStateInterface.java index f7e15062c3..5fb71855c1 100644 --- a/service/src/com/android/car/systeminterface/SystemStateInterface.java +++ b/service/src/com/android/car/systeminterface/SystemStateInterface.java @@ -16,15 +16,6 @@ package com.android.car.systeminterface; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.PowerManager; -import android.os.SystemClock; -import android.util.Pair; -import com.android.car.procfsinspector.ProcessInfo; -import com.android.car.procfsinspector.ProcfsInspector; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; @@ -33,12 +24,26 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import com.android.car.procfsinspector.ProcessInfo; +import com.android.car.procfsinspector.ProcfsInspector; +import com.android.internal.car.ICarServiceHelper; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.PowerManager; +import android.os.SystemClock; +import android.util.Log; +import android.util.Pair; + /** * Interface that abstracts system status (booted, sleeping, ...) operations */ public interface SystemStateInterface { + static final String TAG = SystemStateInterface.class.getSimpleName(); void shutdown(); - void enterDeepSleep(int wakeupTimeSec); + boolean enterDeepSleep(int sleepDurationSec); void scheduleActionForBootCompleted(Runnable action, Duration delay); default boolean isWakeupCausedByTimer() { @@ -58,9 +63,15 @@ public interface SystemStateInterface { return ProcfsInspector.readProcessTable(); } + default void setCarServiceHelper(ICarServiceHelper helper) { + // Do nothing + } + class DefaultImpl implements SystemStateInterface { private final static Duration MIN_BOOT_COMPLETE_ACTION_DELAY = Duration.ofSeconds(10); + private final static int SUSPEND_TRY_TIMEOUT_MS = 1000; + private ICarServiceHelper mICarServiceHelper; private final Context mContext; private final PowerManager mPowerManager; private List<Pair<Runnable, Duration>> mActionsList = new ArrayList<>(); @@ -88,11 +99,19 @@ public interface SystemStateInterface { } @Override - public void enterDeepSleep(int wakeupTimeSec) { - //TODO set wake up time, bug: 32061842 - mPowerManager.goToSleep(SystemClock.uptimeMillis(), - PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN, - PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); + public boolean enterDeepSleep(int sleepDurationSec) { + boolean deviceEnteredSleep; + //TODO set wake up time via VHAL, bug: 32061842 + try { + int retVal; + retVal = mICarServiceHelper.forceSuspend(SUSPEND_TRY_TIMEOUT_MS); + deviceEnteredSleep = retVal == 0; + + } catch (Exception e) { + Log.e(TAG, "Unable to enter deep sleep", e); + deviceEnteredSleep = false; + } + return deviceEnteredSleep; } @Override @@ -110,5 +129,9 @@ public interface SystemStateInterface { mActionsList.add(Pair.create(action, delay)); } + @Override + public void setCarServiceHelper(ICarServiceHelper helper) { + mICarServiceHelper = helper; + } } } diff --git a/tests/carservice_test/src/com/android/car/CarStorageMonitoringTest.java b/tests/carservice_test/src/com/android/car/CarStorageMonitoringTest.java index 0b9fa488b9..4dc97bb1a3 100644 --- a/tests/carservice_test/src/com/android/car/CarStorageMonitoringTest.java +++ b/tests/carservice_test/src/com/android/car/CarStorageMonitoringTest.java @@ -858,7 +858,9 @@ public class CarStorageMonitoringTest extends MockedCarTestBase { public void shutdown() {} @Override - public void enterDeepSleep(int wakeupTimeSec) {} + public boolean enterDeepSleep(int wakeupTimeSec) { + return true; + } @Override public void scheduleActionForBootCompleted(Runnable action, Duration delay) { diff --git a/tests/carservice_test/src/com/android/car/MockedCarTestBase.java b/tests/carservice_test/src/com/android/car/MockedCarTestBase.java index 1e46ac4cca..24dc677775 100644 --- a/tests/carservice_test/src/com/android/car/MockedCarTestBase.java +++ b/tests/carservice_test/src/com/android/car/MockedCarTestBase.java @@ -404,7 +404,9 @@ public class MockedCarTestBase { public void shutdown() {} @Override - public void enterDeepSleep(int wakeupTimeSec) {} + public boolean enterDeepSleep(int wakeupTimeSec) { + return true; + } @Override public void scheduleActionForBootCompleted(Runnable action, Duration delay) {} diff --git a/tests/carservice_unit_test/src/com/android/car/CarPowerManagementServiceTest.java b/tests/carservice_unit_test/src/com/android/car/CarPowerManagementServiceTest.java index dda2f1d4f9..e12f8b8af0 100644 --- a/tests/carservice_unit_test/src/com/android/car/CarPowerManagementServiceTest.java +++ b/tests/carservice_unit_test/src/com/android/car/CarPowerManagementServiceTest.java @@ -321,13 +321,14 @@ public class CarPowerManagementServiceTest extends AndroidTestCase { } @Override - public void enterDeepSleep(int wakeupTimeSec) { + public boolean enterDeepSleep(int wakeupTimeSec) { mWakeupTime = wakeupTimeSec; mSleepWait.release(); try { mSleepExitWait.acquire(); } catch (InterruptedException e) { } + return true; } public int waitForSleepEntryAndWakeup(long timeoutMs) throws Exception { diff --git a/tests/carservice_unit_test/src/com/android/car/storagemonitoring/IoStatsTrackerTest.java b/tests/carservice_unit_test/src/com/android/car/storagemonitoring/IoStatsTrackerTest.java index 462fea9ac7..c7b2a0b9d4 100644 --- a/tests/carservice_unit_test/src/com/android/car/storagemonitoring/IoStatsTrackerTest.java +++ b/tests/carservice_unit_test/src/com/android/car/storagemonitoring/IoStatsTrackerTest.java @@ -299,7 +299,8 @@ public class IoStatsTrackerTest extends TestCase { } @Override - public void enterDeepSleep(int wakeupTimeSec) { + public boolean enterDeepSleep(int wakeupTimeSec) { + return true; } @Override |