android,工厂版本未插USB 到时关机
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xmlindex e1a602b53d9..841030a2f03 100644--- a/packages/SettingsProvider/res/values/defaul
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index e1a602b53d9..841030a2f03 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -19,7 +19,7 @@
<resources>
<bool name="def_dim_screen">true</bool>
<integer name="def_screen_off_timeout">60000</integer>
- <integer name="def_sleep_timeout">-1</integer>
+ <integer name="def_sleep_timeout">600000</integer>
<bool name="def_airplane_mode_on">false</bool>
<bool name="def_theater_mode_on">false</bool>
<!-- Comma-separated list of bluetooth, wifi, and cell. -->
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 697801f7787..e4cda4f791b 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -79,6 +79,10 @@ import android.view.Display;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IAppOpsService;
+import android.casthal.CasthalManager;
+
+
+
import com.android.internal.app.IBatteryStats;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.MetricsLogger;
@@ -108,6 +112,10 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
/**
* The power manager service is responsible for coordinating power management
@@ -299,6 +307,8 @@ public final class PowerManagerService extends SystemService
private long mLastScreenBrightnessBoostTime;
private boolean mScreenBrightnessBoostInProgress;
+ private boolean mMcuPlugIn = false;
+
// A bitfield that summarizes the effect of the user activity timer.
private int mUserActivitySummary;
@@ -1590,6 +1600,7 @@ public final class PowerManagerService extends SystemService
}
Trace.traceBegin(Trace.TRACE_TAG_POWER, "updatePowerState");
+ Slog.e(TAG, "cyx updatePowerState");
try {
// Phase 0: Basic state updates.
updateIsPoweredLocked(mDirty);
@@ -1603,10 +1614,40 @@ public final class PowerManagerService extends SystemService
int dirtyPhase2 = 0;
for (;;) {
int dirtyPhase1 = mDirty;
+ String usbinfo = null;// 默认值
+
dirtyPhase2 |= dirtyPhase1;
mDirty = 0;
updateWakeLockSummaryLocked(dirtyPhase1);
+//add for shutdown
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader("/proc/bus/input/devices"));
+ while ((usbinfo = reader.readLine()) != null){
+ if (usbinfo.contains("Product=5101")) {
+ if (mMcuPlugIn == true) {
+ mMcuPlugIn = false;
+ Slog.e(TAG, "cyx mcu have pluged out!");
+ mLastUserActivityTime = SystemClock.uptimeMillis();
+ }
+ break;
+ }
+ }
+ if (usbinfo == null) {
+ mMcuPlugIn = true;
+ Slog.e(TAG, "cyx mcu have pluged in!");
+ mLastUserActivityTime = SystemClock.uptimeMillis();
+ }
+ reader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (CasthalManager.getInstance(mContext).isBostonChargerConnected()){
+ Slog.e(TAG, "cyx in charging");
+ mLastUserActivityTime = SystemClock.uptimeMillis();
+ }
+//add for shutdown end
+
updateUserActivitySummaryLocked(now, dirtyPhase1);
if (!updateWakefulnessLocked(dirtyPhase1)) {
break;
@@ -1955,6 +1996,8 @@ public final class PowerManagerService extends SystemService
final boolean userInactiveOverride = mUserInactiveOverrideFromWindowManager;
final long nextProfileTimeout = getNextProfileTimeoutLocked(now);
+ Slog.e(TAG, "updateUserActivitySummaryLocked: cyx screenOffTimeout=" + screenOffTimeout);
+
mUserActivitySummary = 0;
if (mLastUserActivityTime >= mLastWakeTime) {
nextTimeout = mLastUserActivityTime
@@ -2021,12 +2064,13 @@ public final class PowerManagerService extends SystemService
mUserActivitySummary = 0;
}
- if (DEBUG_SPEW) {
- Slog.d(TAG, "updateUserActivitySummaryLocked: mWakefulness="
+
+ //if (1) {
+ Slog.e(TAG, "updateUserActivitySummaryLocked: mWakefulness="
+ PowerManagerInternal.wakefulnessToString(mWakefulness)
+ ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
+ ", nextTimeout=" + TimeUtils.formatUptime(nextTimeout));
- }
+ //}
}
}
@@ -2081,6 +2125,8 @@ public final class PowerManagerService extends SystemService
private long getScreenOffTimeoutLocked(long sleepTimeout) {
long timeout = mScreenOffTimeoutSetting;
+
+ Slog.e(TAG, "cyx mScreenOffTimeoutSetting " + mScreenOffTimeoutSetting);
if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
}
@@ -2113,16 +2159,28 @@ public final class PowerManagerService extends SystemService
| DIRTY_WAKEFULNESS | DIRTY_STAY_ON | DIRTY_PROXIMITY_POSITIVE
| DIRTY_DOCK_STATE)) != 0) {
if (mWakefulness == WAKEFULNESS_AWAKE && isItBedTimeYetLocked()) {
- if (DEBUG_SPEW) {
- Slog.d(TAG, "updateWakefulnessLocked: Bed time...");
- }
+ IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+ Intent batteryStatus = mContext.registerReceiver(null, ifilter);
+
+ // 是否在充电
+ int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+ boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
final long time = SystemClock.uptimeMillis();
+
+ //关机
+ SystemProperties.set("sys.powerctl", "shutdown, screen off timeout");
+ //if (1) {
+ Slog.e(TAG, "cyx updateWakefulnessLocked: Bed time...,battery status=" + status);
+ //}
if (shouldNapAtBedTimeLocked()) {
+ Slog.e(TAG, "cyx updateWakefulnessLocked: jinru pinbao");
changed = napNoUpdateLocked(time, Process.SYSTEM_UID);
} else {
+ Slog.e(TAG, "cyx updateWakefulnessLocked: kaishi xiumian");
changed = goToSleepNoUpdateLocked(time,
PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, 0, Process.SYSTEM_UID);
}
+
}
}
return changed;
更多推荐
所有评论(0)