summaryrefslogtreecommitdiffstats
path: root/services/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'services/core/java')
-rw-r--r--services/core/java/com/android/server/DeviceIdleController.java117
-rw-r--r--services/core/java/com/android/server/DockObserver.java3
-rw-r--r--services/core/java/com/android/server/MountService.java11
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java40
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java15
-rw-r--r--services/core/java/com/android/server/am/BroadcastQueue.java183
-rw-r--r--services/core/java/com/android/server/am/BroadcastRecord.java15
-rw-r--r--services/core/java/com/android/server/dreams/DreamManagerService.java3
-rw-r--r--services/core/java/com/android/server/fingerprint/FingerprintService.java3
-rw-r--r--services/core/java/com/android/server/hdmi/HdmiControlService.java2
-rw-r--r--services/core/java/com/android/server/net/NetworkPolicyManagerService.java71
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java65
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java13
-rw-r--r--services/core/java/com/android/server/policy/PhoneWindowManager.java25
-rw-r--r--services/core/java/com/android/server/power/Notifier.java20
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java42
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java2
17 files changed, 425 insertions, 205 deletions
diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java
index fde1490..c7c9d29 100644
--- a/services/core/java/com/android/server/DeviceIdleController.java
+++ b/services/core/java/com/android/server/DeviceIdleController.java
@@ -36,6 +36,7 @@ import android.hardware.TriggerEventListener;
import android.hardware.display.DisplayManager;
import android.net.INetworkPolicyManager;
import android.net.Uri;
+import android.os.BatteryStats;
import android.os.Binder;
import android.os.Environment;
import android.os.FileUtils;
@@ -54,9 +55,11 @@ import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.KeyValueListParser;
+import android.util.MutableLong;
+import android.util.Pair;
import android.util.Slog;
+import android.util.SparseArray;
import android.util.SparseBooleanArray;
-import android.util.SparseLongArray;
import android.util.TimeUtils;
import android.util.Xml;
import android.view.Display;
@@ -177,7 +180,13 @@ public class DeviceIdleController extends SystemService
* List of end times for UIDs that are temporarily marked as being allowed to access
* the network and acquire wakelocks. Times are in milliseconds.
*/
- private final SparseLongArray mTempWhitelistAppIdEndTimes = new SparseLongArray();
+ private final SparseArray<Pair<MutableLong, String>> mTempWhitelistAppIdEndTimes
+ = new SparseArray<>();
+
+ /**
+ * Callback to the NetworkPolicyManagerService to tell it that the temp whitelist has changed.
+ */
+ Runnable mNetworkPolicyTempWhitelistCallback;
/**
* Current app IDs of temporarily whitelist apps for high-priority messages.
@@ -242,6 +251,8 @@ public class DeviceIdleController extends SystemService
private static final String KEY_MIN_TIME_TO_ALARM = "min_time_to_alarm";
private static final String KEY_MAX_TEMP_APP_WHITELIST_DURATION =
"max_temp_app_whitelist_duration";
+ private static final String KEY_MMS_TEMP_APP_WHITELIST_DURATION =
+ "mms_temp_app_whitelist_duration";
/**
* This is the time, after becoming inactive, at which we start looking at the
@@ -339,6 +350,13 @@ public class DeviceIdleController extends SystemService
*/
public long MAX_TEMP_APP_WHITELIST_DURATION;
+ /**
+ * Amount of time we would like to whitelist an app that is receiving an MMS.
+ * @see Settings.Global#DEVICE_IDLE_CONSTANTS
+ * @see #KEY_MMS_TEMP_APP_WHITELIST_DURATION
+ */
+ public long MMS_TEMP_APP_WHITELIST_DURATION;
+
private final ContentResolver mResolver;
private final KeyValueListParser mParser = new KeyValueListParser(',');
@@ -388,8 +406,10 @@ public class DeviceIdleController extends SystemService
2f);
MIN_TIME_TO_ALARM = mParser.getLong(KEY_MIN_TIME_TO_ALARM,
!COMPRESS_TIME ? 60 * 60 * 1000L : 6 * 60 * 1000L);
- MAX_TEMP_APP_WHITELIST_DURATION = mParser.getLong(KEY_MAX_TEMP_APP_WHITELIST_DURATION,
- 5 * 60 * 1000L);
+ MAX_TEMP_APP_WHITELIST_DURATION = mParser.getLong(
+ KEY_MAX_TEMP_APP_WHITELIST_DURATION, 5 * 60 * 1000L);
+ MMS_TEMP_APP_WHITELIST_DURATION = mParser.getLong(
+ KEY_MMS_TEMP_APP_WHITELIST_DURATION, 60 * 1000L);
}
}
@@ -441,6 +461,10 @@ public class DeviceIdleController extends SystemService
pw.print(" "); pw.print(KEY_MAX_TEMP_APP_WHITELIST_DURATION); pw.print("=");
TimeUtils.formatDuration(MAX_TEMP_APP_WHITELIST_DURATION, pw);
pw.println();
+
+ pw.print(" "); pw.print(KEY_MMS_TEMP_APP_WHITELIST_DURATION); pw.print("=");
+ TimeUtils.formatDuration(MMS_TEMP_APP_WHITELIST_DURATION, pw);
+ pw.println();
}
}
@@ -565,7 +589,7 @@ public class DeviceIdleController extends SystemService
}
@Override public void addPowerSaveTempWhitelistApp(String packageName, long duration,
- int userId) throws RemoteException {
+ int userId, String reason) throws RemoteException {
getContext().enforceCallingPermission(
Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST,
"No permission to change device idle whitelist");
@@ -580,12 +604,19 @@ public class DeviceIdleController extends SystemService
final long token = Binder.clearCallingIdentity();
try {
DeviceIdleController.this.addPowerSaveTempWhitelistAppInternal(callingUid,
- packageName, duration, userId);
+ packageName, duration, userId, true, reason);
} finally {
Binder.restoreCallingIdentity(token);
}
}
+ @Override public long addPowerSaveTempWhitelistAppForMms(String packageName,
+ int userId, String reason) throws RemoteException {
+ long duration = mConstants.MMS_TEMP_APP_WHITELIST_DURATION;
+ addPowerSaveTempWhitelistApp(packageName, duration, userId, reason);
+ return duration;
+ }
+
@Override public void exitIdle(String reason) {
getContext().enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER,
null);
@@ -598,8 +629,13 @@ public class DeviceIdleController extends SystemService
}
public final class LocalService {
- public void addPowerSaveTempWhitelistAppDirect(int appId, long duration) {
- addPowerSaveTempWhitelistAppDirectInternal(0, appId, duration);
+ public void addPowerSaveTempWhitelistAppDirect(int appId, long duration, boolean sync,
+ String reason) {
+ addPowerSaveTempWhitelistAppDirectInternal(0, appId, duration, sync, reason);
+ }
+
+ public void setNetworkPolicyTempWhitelistCallback(Runnable callback) {
+ setNetworkPolicyTempWhitelistCallbackInternal(callback);
}
}
@@ -777,11 +813,11 @@ public class DeviceIdleController extends SystemService
* app an exemption to access network and acquire wakelocks.
*/
public void addPowerSaveTempWhitelistAppInternal(int callingUid, String packageName,
- long duration, int userId) {
+ long duration, int userId, boolean sync, String reason) {
try {
int uid = getContext().getPackageManager().getPackageUid(packageName, userId);
int appId = UserHandle.getAppId(uid);
- addPowerSaveTempWhitelistAppDirectInternal(callingUid, appId, duration);
+ addPowerSaveTempWhitelistAppDirectInternal(callingUid, appId, duration, sync, reason);
} catch (NameNotFoundException e) {
}
}
@@ -791,8 +827,9 @@ public class DeviceIdleController extends SystemService
* app an exemption to access network and acquire wakelocks.
*/
public void addPowerSaveTempWhitelistAppDirectInternal(int callingUid, int appId,
- long duration) {
+ long duration, boolean sync, String reason) {
final long timeNow = SystemClock.elapsedRealtime();
+ Runnable networkPolicyTempWhitelistCallback = null;
synchronized (this) {
int callingAppId = UserHandle.getAppId(callingUid);
if (callingAppId >= Process.FIRST_APPLICATION_UID) {
@@ -802,19 +839,45 @@ public class DeviceIdleController extends SystemService
}
}
duration = Math.min(duration, mConstants.MAX_TEMP_APP_WHITELIST_DURATION);
- long currentEndTime = mTempWhitelistAppIdEndTimes.get(appId);
+ Pair<MutableLong, String> entry = mTempWhitelistAppIdEndTimes.get(appId);
+ final boolean newEntry = entry == null;
// Set the new end time
- mTempWhitelistAppIdEndTimes.put(appId, timeNow + duration);
+ if (newEntry) {
+ entry = new Pair<>(new MutableLong(0), reason);
+ mTempWhitelistAppIdEndTimes.put(appId, entry);
+ }
+ entry.first.value = timeNow + duration;
if (DEBUG) {
Slog.d(TAG, "Adding AppId " + appId + " to temp whitelist");
}
- if (currentEndTime == 0) {
+ if (newEntry) {
// No pending timeout for the app id, post a delayed message
+ try {
+ mBatteryStats.noteEvent(BatteryStats.HistoryItem.EVENT_TEMP_WHITELIST_START,
+ reason, appId);
+ } catch (RemoteException e) {
+ }
postTempActiveTimeoutMessage(appId, duration);
updateTempWhitelistAppIdsLocked();
+ if (mNetworkPolicyTempWhitelistCallback != null) {
+ if (!sync) {
+ mHandler.post(mNetworkPolicyTempWhitelistCallback);
+ } else {
+ networkPolicyTempWhitelistCallback = mNetworkPolicyTempWhitelistCallback;
+ }
+ }
reportTempWhitelistChangedLocked();
}
}
+ if (networkPolicyTempWhitelistCallback != null) {
+ networkPolicyTempWhitelistCallback.run();
+ }
+ }
+
+ public void setNetworkPolicyTempWhitelistCallbackInternal(Runnable callback) {
+ synchronized (this) {
+ mNetworkPolicyTempWhitelistCallback = callback;
+ }
}
private void postTempActiveTimeoutMessage(int uid, long delay) {
@@ -825,21 +888,26 @@ public class DeviceIdleController extends SystemService
void checkTempAppWhitelistTimeout(int uid) {
final long timeNow = SystemClock.elapsedRealtime();
synchronized (this) {
- long endTime = mTempWhitelistAppIdEndTimes.get(uid);
- if (endTime == 0) {
+ Pair<MutableLong, String> entry = mTempWhitelistAppIdEndTimes.get(uid);
+ if (entry == null) {
// Nothing to do
return;
}
- if (timeNow >= endTime) {
+ if (timeNow >= entry.first.value) {
mTempWhitelistAppIdEndTimes.delete(uid);
if (DEBUG) {
Slog.d(TAG, "Removing UID " + uid + " from temp whitelist");
}
updateTempWhitelistAppIdsLocked();
reportTempWhitelistChangedLocked();
+ try {
+ mBatteryStats.noteEvent(BatteryStats.HistoryItem.EVENT_TEMP_WHITELIST_FINISH,
+ entry.second, uid);
+ } catch (RemoteException e) {
+ }
} else {
// Need more time
- postTempActiveTimeoutMessage(uid, endTime - timeNow);
+ postTempActiveTimeoutMessage(uid, entry.first.value - timeNow);
}
}
}
@@ -1101,7 +1169,7 @@ public class DeviceIdleController extends SystemService
}
void readConfigFileLocked() {
- Slog.d(TAG, "Reading config from " + mConfigFile.getBaseFile());
+ if (DEBUG) Slog.d(TAG, "Reading config from " + mConfigFile.getBaseFile());
mPowerSaveWhitelistUserApps.clear();
FileInputStream stream;
try {
@@ -1370,11 +1438,14 @@ public class DeviceIdleController extends SystemService
while (i < args.length) {
arg = args[i];
i++;
- addPowerSaveTempWhitelistAppInternal(0, arg, 10000L, userId);
+ addPowerSaveTempWhitelistAppInternal(0, arg, 10000L, userId, true,
+ "shell");
+ pw.println("Added: " + arg);
}
} finally {
Binder.restoreCallingIdentity(token);
}
+ return;
} else if (arg.length() > 0 && arg.charAt(0) == '-'){
pw.println("Unknown option: " + arg);
return;
@@ -1421,8 +1492,10 @@ public class DeviceIdleController extends SystemService
pw.print(" UID=");
pw.print(mTempWhitelistAppIdEndTimes.keyAt(i));
pw.print(": ");
- TimeUtils.formatDuration(mTempWhitelistAppIdEndTimes.valueAt(i), timeNow, pw);
- pw.println();
+ Pair<MutableLong, String> entry = mTempWhitelistAppIdEndTimes.valueAt(i);
+ TimeUtils.formatDuration(entry.first.value, timeNow, pw);
+ pw.print(" - ");
+ pw.println(entry.second);
}
}
size = mTempWhitelistAppIdArray != null ? mTempWhitelistAppIdArray.length : 0;
diff --git a/services/core/java/com/android/server/DockObserver.java b/services/core/java/com/android/server/DockObserver.java
index 41ce25d..5388f10 100644
--- a/services/core/java/com/android/server/DockObserver.java
+++ b/services/core/java/com/android/server/DockObserver.java
@@ -134,7 +134,8 @@ final class DockObserver extends SystemService {
if (mAllowTheaterModeWakeFromDock
|| Settings.Global.getInt(getContext().getContentResolver(),
Settings.Global.THEATER_MODE_ON, 0) == 0) {
- mPowerManager.wakeUp(SystemClock.uptimeMillis());
+ mPowerManager.wakeUp(SystemClock.uptimeMillis(),
+ "android.server:DOCK");
}
updateLocked();
}
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
index bc61c3d..0e158a2 100644
--- a/services/core/java/com/android/server/MountService.java
+++ b/services/core/java/com/android/server/MountService.java
@@ -2602,8 +2602,15 @@ class MountService extends IMountService.Stub
boolean foundPrimary = false;
final int userId = UserHandle.getUserId(uid);
- final boolean reportUnmounted = !mMountServiceInternal.hasExternalStorage(
- uid, packageName);
+ final boolean reportUnmounted;
+
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ reportUnmounted = !mMountServiceInternal.hasExternalStorage(
+ uid, packageName);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
synchronized (mLock) {
for (int i = 0; i < mVolumes.size(); i++) {
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 5bfca10..37aa408 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -6355,7 +6355,7 @@ public final class ActivityManagerService extends ActivityManagerNative
}
},
0, null, null,
- android.Manifest.permission.RECEIVE_BOOT_COMPLETED,
+ new String[] {android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
AppOpsManager.OP_NONE, null, true, false,
MY_PID, Process.SYSTEM_UID, userId);
}
@@ -11773,7 +11773,7 @@ public final class ActivityManagerService extends ActivityManagerNative
throws RemoteException {
}
}, 0, null, null,
- INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
+ new String[] {INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE,
null, true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
} catch (Throwable t) {
Slog.wtf(TAG, "Failed sending first user broadcasts", t);
@@ -16327,7 +16327,7 @@ public final class ActivityManagerService extends ActivityManagerNative
private final int broadcastIntentLocked(ProcessRecord callerApp,
String callerPackage, Intent intent, String resolvedType,
IIntentReceiver resultTo, int resultCode, String resultData,
- Bundle resultExtras, String requiredPermission, int appOp, Bundle options,
+ Bundle resultExtras, String[] requiredPermissions, int appOp, Bundle options,
boolean ordered, boolean sticky, int callingPid, int callingUid, int userId) {
intent = new Intent(intent);
@@ -16580,9 +16580,9 @@ public final class ActivityManagerService extends ActivityManagerNative
Slog.w(TAG, msg);
throw new SecurityException(msg);
}
- if (requiredPermission != null) {
+ if (requiredPermissions != null && requiredPermissions.length > 0) {
Slog.w(TAG, "Can't broadcast sticky intent " + intent
- + " and enforce permission " + requiredPermission);
+ + " and enforce permissions " + Arrays.toString(requiredPermissions));
return ActivityManager.BROADCAST_STICKY_CANT_HAVE_PERMISSION;
}
if (intent.getComponent() != null) {
@@ -16690,7 +16690,7 @@ public final class ActivityManagerService extends ActivityManagerNative
// components to be launched.
final BroadcastQueue queue = broadcastQueueForIntent(intent);
BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
- callerPackage, callingPid, callingUid, resolvedType, requiredPermission,
+ callerPackage, callingPid, callingUid, resolvedType, requiredPermissions,
appOp, brOptions, registeredReceivers, resultTo, resultCode, resultData,
resultExtras, ordered, sticky, false, userId);
if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Enqueueing parallel broadcast " + r);
@@ -16780,7 +16780,7 @@ public final class ActivityManagerService extends ActivityManagerNative
BroadcastQueue queue = broadcastQueueForIntent(intent);
BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
callerPackage, callingPid, callingUid, resolvedType,
- requiredPermission, appOp, brOptions, receivers, resultTo, resultCode,
+ requiredPermissions, appOp, brOptions, receivers, resultTo, resultCode,
resultData, resultExtras, ordered, sticky, false, userId);
if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Enqueueing ordered broadcast " + r
@@ -16829,7 +16829,7 @@ public final class ActivityManagerService extends ActivityManagerNative
public final int broadcastIntent(IApplicationThread caller,
Intent intent, String resolvedType, IIntentReceiver resultTo,
int resultCode, String resultData, Bundle resultExtras,
- String requiredPermission, int appOp, Bundle options,
+ String[] requiredPermissions, int appOp, Bundle options,
boolean serialized, boolean sticky, int userId) {
enforceNotIsolatedCaller("broadcastIntent");
synchronized(this) {
@@ -16842,13 +16842,14 @@ public final class ActivityManagerService extends ActivityManagerNative
int res = broadcastIntentLocked(callerApp,
callerApp != null ? callerApp.info.packageName : null,
intent, resolvedType, resultTo, resultCode, resultData, resultExtras,
- requiredPermission, appOp, null, serialized, sticky,
+ requiredPermissions, appOp, null, serialized, sticky,
callingPid, callingUid, userId);
Binder.restoreCallingIdentity(origId);
return res;
}
}
+
int broadcastIntentInPackage(String packageName, int uid,
Intent intent, String resolvedType, IIntentReceiver resultTo,
int resultCode, String resultData, Bundle resultExtras,
@@ -16858,9 +16859,12 @@ public final class ActivityManagerService extends ActivityManagerNative
intent = verifyBroadcastLocked(intent);
final long origId = Binder.clearCallingIdentity();
+ String[] requiredPermissions = requiredPermission == null ? null
+ : new String[] {requiredPermission};
int res = broadcastIntentLocked(null, packageName, intent, resolvedType,
- resultTo, resultCode, resultData, resultExtras, requiredPermission,
- AppOpsManager.OP_NONE, options, serialized, sticky, -1, uid, userId);
+ resultTo, resultCode, resultData, resultExtras,
+ requiredPermissions, AppOpsManager.OP_NONE, options, serialized,
+ sticky, -1, uid, userId);
Binder.restoreCallingIdentity(origId);
return res;
}
@@ -19795,7 +19799,7 @@ public final class ActivityManagerService extends ActivityManagerNative
int sendingUser) throws RemoteException {
}
}, 0, null, null,
- INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
+ new String[] {INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE,
null, true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
}
}
@@ -19857,8 +19861,9 @@ public final class ActivityManagerService extends ActivityManagerNative
intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId);
broadcastIntentLocked(null, null, intent,
null, null, 0, null, null,
- android.Manifest.permission.MANAGE_USERS, AppOpsManager.OP_NONE,
- null, false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+ new String[] {android.Manifest.permission.MANAGE_USERS},
+ AppOpsManager.OP_NONE, null, false, false, MY_PID, Process.SYSTEM_UID,
+ UserHandle.USER_ALL);
}
} finally {
Binder.restoreCallingIdentity(ident);
@@ -20041,8 +20046,9 @@ public final class ActivityManagerService extends ActivityManagerNative
intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT);
broadcastIntentLocked(null, null, intent,
null, null, 0, null, null,
- android.Manifest.permission.RECEIVE_BOOT_COMPLETED, AppOpsManager.OP_NONE,
- null, true, false, MY_PID, Process.SYSTEM_UID, userId);
+ new String[] {android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
+ AppOpsManager.OP_NONE, null, true, false, MY_PID, Process.SYSTEM_UID,
+ userId);
}
}
}
@@ -20180,7 +20186,7 @@ public final class ActivityManagerService extends ActivityManagerNative
// Kick things off.
broadcastIntentLocked(null, null, stoppingIntent,
null, stoppingReceiver, 0, null, null,
- INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
+ new String[] {INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE,
null, true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
} finally {
Binder.restoreCallingIdentity(ident);
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index 070813b..4b0b924 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -101,8 +101,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
mUpdateFlags = 0;
}
updateExternalStats((String)msg.obj, updateFlags);
- synchronized (this) {
- synchronized (mStats) {
+
+ // other parts of the system could be calling into us
+ // from mStats in order to report of changes. We must grab the mStats
+ // lock before grabbing our own or we'll end up in a deadlock.
+ synchronized (mStats) {
+ synchronized (this) {
final int numUidsToRemove = mUidsToRemove.size();
for (int i = 0; i < numUidsToRemove; i++) {
mStats.removeIsolatedUidLocked(mUidsToRemove.get(i));
@@ -489,6 +493,13 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
}
+ public void noteWakeUp(String reason, int reasonUid) {
+ enforceCallingPermission();
+ synchronized (mStats) {
+ mStats.noteWakeUpLocked(reason, reasonUid);
+ }
+ }
+
public void noteInteractive(boolean interactive) {
enforceCallingPermission();
synchronized (mStats) {
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
index 30aa411..91d97ef 100644
--- a/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -175,7 +175,7 @@ public final class BroadcastQueue {
DeviceIdleController.LocalService dic = mService.mLocalDeviceIdleController;
if (dic != null) {
dic.addPowerSaveTempWhitelistAppDirect(UserHandle.getAppId(msg.arg1),
- msg.arg2);
+ msg.arg2, true, (String)msg.obj);
}
} break;
}
@@ -493,59 +493,74 @@ public final class BroadcastQueue {
}
}
}
- if (!skip) {
- int perm = mService.checkComponentPermission(r.requiredPermission,
- filter.receiverList.pid, filter.receiverList.uid, -1, true);
- if (perm != PackageManager.PERMISSION_GRANTED) {
- Slog.w(TAG, "Permission Denial: receiving "
- + r.intent.toString()
- + " to " + filter.receiverList.app
- + " (pid=" + filter.receiverList.pid
- + ", uid=" + filter.receiverList.uid + ")"
- + " requires " + r.requiredPermission
- + " due to sender " + r.callerPackage
- + " (uid " + r.callingUid + ")");
- skip = true;
- }
- int appOp = AppOpsManager.OP_NONE;
- if (r.requiredPermission != null) {
- appOp = AppOpsManager.permissionToOpCode(r.requiredPermission);
- if (appOp != AppOpsManager.OP_NONE
- && mService.mAppOpsService.noteOperation(appOp,
- filter.receiverList.uid, filter.packageName)
- != AppOpsManager.MODE_ALLOWED) {
- Slog.w(TAG, "Appop Denial: receiving "
+ if (!skip && r.requiredPermissions != null && r.requiredPermissions.length > 0) {
+ for (int i = 0; i < r.requiredPermissions.length; i++) {
+ String requiredPermission = r.requiredPermissions[i];
+ int perm = mService.checkComponentPermission(requiredPermission,
+ filter.receiverList.pid, filter.receiverList.uid, -1, true);
+ if (perm != PackageManager.PERMISSION_GRANTED) {
+ Slog.w(TAG, "Permission Denial: receiving "
+ r.intent.toString()
+ " to " + filter.receiverList.app
+ " (pid=" + filter.receiverList.pid
+ ", uid=" + filter.receiverList.uid + ")"
- + " requires appop " + AppOpsManager.permissionToOp(
- r.requiredPermission)
+ + " requires " + requiredPermission
+ " due to sender " + r.callerPackage
+ " (uid " + r.callingUid + ")");
skip = true;
+ break;
}
- }
- if (!skip && r.appOp != appOp && r.appOp != AppOpsManager.OP_NONE
- && mService.mAppOpsService.noteOperation(r.appOp,
- filter.receiverList.uid, filter.packageName)
- != AppOpsManager.MODE_ALLOWED) {
+ int appOp = AppOpsManager.permissionToOpCode(requiredPermission);
+ if (appOp != r.appOp
+ && mService.mAppOpsService.noteOperation(appOp,
+ filter.receiverList.uid, filter.packageName)
+ != AppOpsManager.MODE_ALLOWED) {
Slog.w(TAG, "Appop Denial: receiving "
+ r.intent.toString()
+ " to " + filter.receiverList.app
+ " (pid=" + filter.receiverList.pid
+ ", uid=" + filter.receiverList.uid + ")"
+ " requires appop " + AppOpsManager.permissionToOp(
- r.requiredPermission)
+ requiredPermission)
+ " due to sender " + r.callerPackage
+ " (uid " + r.callingUid + ")");
skip = true;
+ break;
+ }
}
}
+ if (!skip && (r.requiredPermissions == null || r.requiredPermissions.length == 0)) {
+ int perm = mService.checkComponentPermission(null,
+ filter.receiverList.pid, filter.receiverList.uid, -1, true);
+ if (perm != PackageManager.PERMISSION_GRANTED) {
+ Slog.w(TAG, "Permission Denial: security check failed when receiving "
+ + r.intent.toString()
+ + " to " + filter.receiverList.app
+ + " (pid=" + filter.receiverList.pid
+ + ", uid=" + filter.receiverList.uid + ")"
+ + " due to sender " + r.callerPackage
+ + " (uid " + r.callingUid + ")");
+ skip = true;
+ }
+ }
+ if (!skip && r.appOp != AppOpsManager.OP_NONE
+ && mService.mAppOpsService.noteOperation(r.appOp,
+ filter.receiverList.uid, filter.packageName)
+ != AppOpsManager.MODE_ALLOWED) {
+ Slog.w(TAG, "Appop Denial: receiving "
+ + r.intent.toString()
+ + " to " + filter.receiverList.app
+ + " (pid=" + filter.receiverList.pid
+ + ", uid=" + filter.receiverList.uid + ")"
+ + " requires appop " + AppOpsManager.opToName(r.appOp)
+ + " due to sender " + r.callerPackage
+ + " (uid " + r.callingUid + ")");
+ skip = true;
+ }
- if (!skip) {
- skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid,
- r.callingPid, r.resolvedType, filter.receiverList.uid);
+ if (!mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid,
+ r.callingPid, r.resolvedType, filter.receiverList.uid)) {
+ return;
}
if (filter.receiverList.app == null || filter.receiverList.app.crashing) {
@@ -597,7 +612,7 @@ public final class BroadcastQueue {
}
}
- final void scheduleTempWhitelistLocked(int uid, long duration) {
+ final void scheduleTempWhitelistLocked(int uid, long duration, BroadcastRecord r) {
if (duration > Integer.MAX_VALUE) {
duration = Integer.MAX_VALUE;
}
@@ -607,7 +622,19 @@ public final class BroadcastQueue {
// not that big a deal, however, because the main purpose here is to allow apps
// to hold wake locks, and they will be able to acquire their wake lock immediately
// it just won't be enabled until we get through this work.
- mHandler.obtainMessage(SCHEDULE_TEMP_WHITELIST_MSG, uid, (int)duration).sendToTarget();
+ StringBuilder b = new StringBuilder();
+ b.append("broadcast:");
+ UserHandle.formatUid(b, r.callingUid);
+ b.append(":");
+ if (r.intent.getAction() != null) {
+ b.append(r.intent.getAction());
+ } else if (r.intent.getComponent() != null) {
+ b.append(r.intent.getComponent().flattenToShortString());
+ } else if (r.intent.getData() != null) {
+ b.append(r.intent.getData());
+ }
+ mHandler.obtainMessage(SCHEDULE_TEMP_WHITELIST_MSG, uid, (int)duration, b.toString())
+ .sendToTarget();
}
final void processNextBroadcast(boolean fromMsg) {
@@ -807,7 +834,7 @@ public final class BroadcastQueue {
} else {
if (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0) {
scheduleTempWhitelistLocked(filter.owningUid,
- brOptions.getTemporaryAppWhitelistDuration());
+ brOptions.getTemporaryAppWhitelistDuration(), r);
}
}
return;
@@ -860,51 +887,53 @@ public final class BroadcastQueue {
}
}
if (!skip && info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID &&
- r.requiredPermission != null) {
- try {
- perm = AppGlobals.getPackageManager().
- checkPermission(r.requiredPermission,
- info.activityInfo.applicationInfo.packageName,
- UserHandle.getUserId(info.activityInfo.applicationInfo.uid));
- } catch (RemoteException e) {
- perm = PackageManager.PERMISSION_DENIED;
- }
- if (perm != PackageManager.PERMISSION_GRANTED) {
- Slog.w(TAG, "Permission Denial: receiving "
- + r.intent + " to "
- + component.flattenToShortString()
- + " requires " + r.requiredPermission
- + " due to sender " + r.callerPackage
- + " (uid " + r.callingUid + ")");
- skip = true;
- }
- }
- int appOp = AppOpsManager.OP_NONE;
- if (!skip && r.requiredPermission != null) {
- appOp = AppOpsManager.permissionToOpCode(r.requiredPermission);
- if (appOp != AppOpsManager.OP_NONE
- && mService.mAppOpsService.noteOperation(appOp,
- info.activityInfo.applicationInfo.uid, info.activityInfo.packageName)
- != AppOpsManager.MODE_ALLOWED) {
- Slog.w(TAG, "Appop Denial: receiving "
- + r.intent + " to "
- + component.flattenToShortString()
- + " requires appop " + AppOpsManager.permissionToOp(
- r.requiredPermission)
- + " due to sender " + r.callerPackage
- + " (uid " + r.callingUid + ")");
- skip = true;
+ r.requiredPermissions != null && r.requiredPermissions.length > 0) {
+ for (int i = 0; i < r.requiredPermissions.length; i++) {
+ String requiredPermission = r.requiredPermissions[i];
+ try {
+ perm = AppGlobals.getPackageManager().
+ checkPermission(requiredPermission,
+ info.activityInfo.applicationInfo.packageName,
+ UserHandle
+ .getUserId(info.activityInfo.applicationInfo.uid));
+ } catch (RemoteException e) {
+ perm = PackageManager.PERMISSION_DENIED;
+ }
+ if (perm != PackageManager.PERMISSION_GRANTED) {
+ Slog.w(TAG, "Permission Denial: receiving "
+ + r.intent + " to "
+ + component.flattenToShortString()
+ + " requires " + requiredPermission
+ + " due to sender " + r.callerPackage
+ + " (uid " + r.callingUid + ")");
+ skip = true;
+ break;
+ }
+ int appOp = AppOpsManager.permissionToOpCode(requiredPermission);
+ if (appOp != AppOpsManager.OP_NONE && appOp != r.appOp
+ && mService.mAppOpsService.noteOperation(appOp,
+ info.activityInfo.applicationInfo.uid, info.activityInfo.packageName)
+ != AppOpsManager.MODE_ALLOWED) {
+ Slog.w(TAG, "Appop Denial: receiving "
+ + r.intent + " to "
+ + component.flattenToShortString()
+ + " requires appop " + AppOpsManager.permissionToOp(
+ requiredPermission)
+ + " due to sender " + r.callerPackage
+ + " (uid " + r.callingUid + ")");
+ skip = true;
+ break;
+ }
}
}
- if (!skip && r.appOp != appOp && r.appOp != AppOpsManager.OP_NONE
+ if (!skip && r.appOp != AppOpsManager.OP_NONE
&& mService.mAppOpsService.noteOperation(r.appOp,
- info.activityInfo.applicationInfo.uid, info.activityInfo.packageName)
- != AppOpsManager.MODE_ALLOWED) {
+ info.activityInfo.applicationInfo.uid, info.activityInfo.packageName)
+ != AppOpsManager.MODE_ALLOWED) {
Slog.w(TAG, "Appop Denial: receiving "
+ r.intent + " to "
+ component.flattenToShortString()
- + " requires appop " + AppOpsManager.permissionToOp(
- r.requiredPermission)
+ + " requires appop " + AppOpsManager.opToName(r.appOp)
+ " due to sender " + r.callerPackage
+ " (uid " + r.callingUid + ")");
skip = true;
@@ -988,7 +1017,7 @@ public final class BroadcastQueue {
if (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0) {
scheduleTempWhitelistLocked(receiverUid,
- brOptions.getTemporaryAppWhitelistDuration());
+ brOptions.getTemporaryAppWhitelistDuration(), r);
}
// Broadcast is being executed, its package can't be stopped.
diff --git a/services/core/java/com/android/server/am/BroadcastRecord.java b/services/core/java/com/android/server/am/BroadcastRecord.java
index b943222..a7e6471 100644
--- a/services/core/java/com/android/server/am/BroadcastRecord.java
+++ b/services/core/java/com/android/server/am/BroadcastRecord.java
@@ -32,6 +32,7 @@ import android.util.PrintWriterPrinter;
import android.util.TimeUtils;
import java.io.PrintWriter;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -51,7 +52,7 @@ final class BroadcastRecord extends Binder {
final boolean initialSticky; // initial broadcast from register to sticky?
final int userId; // user id this broadcast was for
final String resolvedType; // the resolved data type
- final String requiredPermission; // a permission the caller has required
+ final String[] requiredPermissions; // permissions the caller has required
final int appOp; // an app op that is associated with this broadcast
final BroadcastOptions options; // BroadcastOptions supplied by caller
final List receivers; // contains BroadcastFilter and ResolveInfo
@@ -103,9 +104,11 @@ final class BroadcastRecord extends Binder {
pw.print(callerApp != null ? callerApp.toShortString() : "null");
pw.print(" pid="); pw.print(callingPid);
pw.print(" uid="); pw.println(callingUid);
- if (requiredPermission != null || appOp != AppOpsManager.OP_NONE) {
- pw.print(prefix); pw.print("requiredPermission="); pw.print(requiredPermission);
- pw.print(" appOp="); pw.println(appOp);
+ if ((requiredPermissions != null && requiredPermissions.length > 0)
+ || appOp != AppOpsManager.OP_NONE) {
+ pw.print(prefix); pw.print("requiredPermissions=");
+ pw.print(Arrays.toString(requiredPermissions));
+ pw.print(" appOp="); pw.println(appOp);
}
if (options != null) {
pw.print(prefix); pw.print("options="); pw.println(options.toBundle());
@@ -184,7 +187,7 @@ final class BroadcastRecord extends Binder {
BroadcastRecord(BroadcastQueue _queue,
Intent _intent, ProcessRecord _callerApp, String _callerPackage,
- int _callingPid, int _callingUid, String _resolvedType, String _requiredPermission,
+ int _callingPid, int _callingUid, String _resolvedType, String[] _requiredPermissions,
int _appOp, BroadcastOptions _options, List _receivers, IIntentReceiver _resultTo,
int _resultCode, String _resultData, Bundle _resultExtras, boolean _serialized,
boolean _sticky, boolean _initialSticky,
@@ -197,7 +200,7 @@ final class BroadcastRecord extends Binder {
callingPid = _callingPid;
callingUid = _callingUid;
resolvedType = _resolvedType;
- requiredPermission = _requiredPermission;
+ requiredPermissions = _requiredPermissions;
appOp = _appOp;
options = _options;
receivers = _receivers;
diff --git a/services/core/java/com/android/server/dreams/DreamManagerService.java b/services/core/java/com/android/server/dreams/DreamManagerService.java
index 458928f..8813a61 100644
--- a/services/core/java/com/android/server/dreams/DreamManagerService.java
+++ b/services/core/java/com/android/server/dreams/DreamManagerService.java
@@ -648,7 +648,8 @@ public final class DreamManagerService extends SystemService {
if (mCurrentDreamName != null && mCurrentDreamCanDoze
&& !mCurrentDreamName.equals(getDozeComponent())) {
// May have updated the doze component, wake up
- mPowerManager.wakeUp(SystemClock.uptimeMillis());
+ mPowerManager.wakeUp(SystemClock.uptimeMillis(),
+ "android.server.dreams:SYSPROP");
}
}
}
diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java
index 4d8d105..a71dfcd 100644
--- a/services/core/java/com/android/server/fingerprint/FingerprintService.java
+++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java
@@ -565,7 +565,8 @@ public class FingerprintService extends SystemService implements IBinder.DeathRe
// For fingerprint devices that support touch-to-wake, this will ensure the device
// wakes up and turns the screen on when fingerprint is authenticated.
if (mIsKeyguard && authenticated) {
- mPowerManager.wakeUp(SystemClock.uptimeMillis());
+ mPowerManager.wakeUp(SystemClock.uptimeMillis(),
+ "android.server.fingerprint:AUTH");
}
return result;
}
diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java
index c37f619..cfc5f7d 100644
--- a/services/core/java/com/android/server/hdmi/HdmiControlService.java
+++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java
@@ -1969,7 +1969,7 @@ public final class HdmiControlService extends SystemService {
void wakeUp() {
assertRunOnServiceThread();
mWakeUpMessageReceived = true;
- mPowerManager.wakeUp(SystemClock.uptimeMillis());
+ mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.hdmi:WAKE");
// PowerManger will send the broadcast Intent.ACTION_SCREEN_ON and after this gets
// the intent, the sequence will continue at onWakeUp().
}
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index f8f00ef..395aa27 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -147,6 +147,7 @@ import android.util.SparseIntArray;
import android.util.TrustedTime;
import android.util.Xml;
+import com.android.server.DeviceIdleController;
import com.android.server.EventLogTags;
import libcore.io.IoUtils;
@@ -462,9 +463,12 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
// listen for changes to power save whitelist
final IntentFilter whitelistFilter = new IntentFilter(
PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED);
- whitelistFilter.addAction(PowerManager.ACTION_POWER_SAVE_TEMP_WHITELIST_CHANGED);
mContext.registerReceiver(mPowerSaveWhitelistReceiver, whitelistFilter, null, mHandler);
+ DeviceIdleController.LocalService deviceIdleService
+ = LocalServices.getService(DeviceIdleController.LocalService.class);
+ deviceIdleService.setNetworkPolicyTempWhitelistCallback(mTempPowerSaveChangedCallback);
+
// watch for network interfaces to be claimed
final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION);
mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
@@ -512,7 +516,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
- private IUidObserver mUidObserver = new IUidObserver.Stub() {
+ final private IUidObserver mUidObserver = new IUidObserver.Stub() {
@Override public void onUidStateChanged(int uid, int procState) throws RemoteException {
synchronized (mRulesLock) {
updateUidStateLocked(uid, procState);
@@ -526,24 +530,29 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
};
- private BroadcastReceiver mPowerSaveWhitelistReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mPowerSaveWhitelistReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and POWER_SAVE_WHITELIST_CHANGED is protected
synchronized (mRulesLock) {
- if (PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED.equals(intent.getAction())) {
- updatePowerSaveWhitelistLocked();
- updateRulesForGlobalChangeLocked(false);
- } else {
- updatePowerSaveTempWhitelistLocked();
- updateRulesForTempWhitelistChangeLocked();
- purgePowerSaveTempWhitelistLocked();
- }
+ updatePowerSaveWhitelistLocked();
+ updateRulesForGlobalChangeLocked(false);
}
}
};
- private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
+ final private Runnable mTempPowerSaveChangedCallback = new Runnable() {
+ @Override
+ public void run() {
+ synchronized (mRulesLock) {
+ updatePowerSaveTempWhitelistLocked();
+ updateRulesForTempWhitelistChangeLocked();
+ purgePowerSaveTempWhitelistLocked();
+ }
+ }
+ };
+
+ final private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// screen-related broadcasts are protected by system, no need
@@ -552,7 +561,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
};
- private BroadcastReceiver mPackageReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mPackageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and PACKAGE_ADDED is protected
@@ -572,7 +581,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
};
- private BroadcastReceiver mUidRemovedReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mUidRemovedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and UID_REMOVED is protected
@@ -590,7 +599,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
};
- private BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and USER_ADDED and USER_REMOVED
@@ -619,7 +628,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
* Receiver that watches for {@link INetworkStatsService} updates, which we
* use to check against {@link NetworkPolicy#warningBytes}.
*/
- private BroadcastReceiver mStatsReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mStatsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and verified
@@ -637,7 +646,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
* Receiver that watches for {@link Notification} control of
* {@link #mRestrictBackground}.
*/
- private BroadcastReceiver mAllowReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mAllowReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and verified MANAGE_NETWORK_POLICY
@@ -651,7 +660,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
* Receiver that watches for {@link Notification} control of
* {@link NetworkPolicy#lastWarningSnooze}.
*/
- private BroadcastReceiver mSnoozeWarningReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mSnoozeWarningReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and verified MANAGE_NETWORK_POLICY
@@ -665,7 +674,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
/**
* Receiver that watches for {@link WifiConfiguration} to be changed.
*/
- private BroadcastReceiver mWifiConfigReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mWifiConfigReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and verified CONNECTIVITY_INTERNAL
@@ -692,7 +701,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
* Receiver that watches {@link WifiInfo} state changes to infer metered
* state. Ignores hints when policy is user-defined.
*/
- private BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
+ final private BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// on background handler thread, and verified CONNECTIVITY_INTERNAL
@@ -732,7 +741,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
/**
* Observer that watches for {@link INetworkManagementService} alerts.
*/
- private INetworkManagementEventObserver mAlertObserver = new BaseNetworkObserver() {
+ final private INetworkManagementEventObserver mAlertObserver
+ = new BaseNetworkObserver() {
@Override
public void limitReached(String limitName, String iface) {
// only someone like NMS should be calling us
@@ -1985,6 +1995,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
// state changed, push updated rules
mUidState.put(uid, uidState);
updateRulesForUidStateChangeLocked(uid, oldUidState, uidState);
+ if (mDeviceIdleMode && isProcStateAllowedWhileIdle(oldUidState)
+ != isProcStateAllowedWhileIdle(uidState)) {
+ updateRulesForDeviceIdleLocked();
+ }
}
}
@@ -1996,6 +2010,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
if (oldUidState != ActivityManager.PROCESS_STATE_CACHED_EMPTY) {
updateRulesForUidStateChangeLocked(uid, oldUidState,
ActivityManager.PROCESS_STATE_CACHED_EMPTY);
+ if (mDeviceIdleMode) {
+ updateRulesForDeviceIdleLocked();
+ }
}
}
}
@@ -2033,13 +2050,18 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
}
+ static boolean isProcStateAllowedWhileIdle(int procState) {
+ return procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
+ }
+
void updateRulesForDeviceIdleLocked() {
if (mDeviceIdleMode) {
// sync the whitelists before enable dozable chain. We don't care about the rules if
// we are disabling the chain.
SparseIntArray uidRules = new SparseIntArray();
final List<UserInfo> users = mUserManager.getUsers();
- for (UserInfo user : users) {
+ for (int ui = users.size() - 1; ui >= 0; ui--) {
+ UserInfo user = users.get(ui);
for (int i = mPowerSaveTempWhitelistAppIds.size() - 1; i >= 0; i--) {
int appId = mPowerSaveTempWhitelistAppIds.keyAt(i);
int uid = UserHandle.getUid(user.id, appId);
@@ -2051,6 +2073,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
uidRules.put(uid, FIREWALL_RULE_ALLOW);
}
}
+ for (int i = mUidState.size() - 1; i >= 0; i--) {
+ if (isProcStateAllowedWhileIdle(mUidState.valueAt(i))) {
+ uidRules.put(mUidState.keyAt(i), FIREWALL_RULE_ALLOW);
+ }
+ }
setUidFirewallRules(FIREWALL_CHAIN_DOZABLE, uidRules);
}
enableFirewallChainLocked(FIREWALL_CHAIN_DOZABLE, mDeviceIdleMode);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b23b856..7a6895f 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1837,7 +1837,7 @@ public class NotificationManagerService extends SystemService {
void dumpImpl(PrintWriter pw, DumpFilter filter) {
pw.print("Current Notification Manager state");
- if (filter != null) {
+ if (filter.filtered) {
pw.print(" (filtered to "); pw.print(filter); pw.print(")");
}
pw.println(':');
@@ -1865,7 +1865,7 @@ public class NotificationManagerService extends SystemService {
for (int i=0; i<N; i++) {
final NotificationRecord nr = mNotificationList.get(i);
if (filter != null && !filter.matches(nr.sbn)) continue;
- nr.dump(pw, " ", getContext());
+ nr.dump(pw, " ", getContext(), filter.redact);
}
pw.println(" ");
}
@@ -1948,7 +1948,7 @@ public class NotificationManagerService extends SystemService {
pw.println(" " + entry.getKey() + " -> " + r.getKey());
if (mNotificationsByKey.get(r.getKey()) != r) {
pw.println("!!!!!!LEAK: Record not found in mNotificationsByKey.");
- r.dump(pw, " ", getContext());
+ r.dump(pw, " ", getContext(), filter.redact);
}
}
@@ -3499,46 +3499,59 @@ public class NotificationManagerService extends SystemService {
}
public static final class DumpFilter {
+ public boolean filtered = false;
public String pkgFilter;
public boolean zen;
public long since;
public boolean stats;
- private boolean all;
+ public boolean redact = true;
public static DumpFilter parseFromArguments(String[] args) {
- if (args != null && args.length == 2 && "p".equals(args[0])
- && args[1] != null && !args[1].trim().isEmpty()) {
- final DumpFilter filter = new DumpFilter();
- filter.pkgFilter = args[1].trim().toLowerCase();
- return filter;
- }
- if (args != null && args.length == 1 && "zen".equals(args[0])) {
- final DumpFilter filter = new DumpFilter();
- filter.zen = true;
- filter.all = true;
- return filter;
- }
- if (args != null && args.length >= 1 && "--stats".equals(args[0])) {
- final DumpFilter filter = new DumpFilter();
- filter.stats = true;
- filter.since = args.length == 2 ? Long.valueOf(args[1]) : 0;
- filter.all = true;
- return filter;
+ final DumpFilter filter = new DumpFilter();
+ for (int ai = 0; ai < args.length; ai++) {
+ final String a = args[ai];
+ if ("--noredact".equals(a) || "--reveal".equals(a)) {
+ filter.redact = false;
+ } else if ("p".equals(a) || "pkg".equals(a) || "--package".equals(a)) {
+ if (ai < args.length-1) {
+ ai++;
+ filter.pkgFilter = args[ai].trim().toLowerCase();
+ if (filter.pkgFilter.isEmpty()) {
+ filter.pkgFilter = null;
+ } else {
+ filter.filtered = true;
+ }
+ }
+ } else if ("--zen".equals(a) || "zen".equals(a)) {
+ filter.filtered = true;
+ filter.zen = true;
+ } else if ("--stats".equals(a)) {
+ filter.stats = true;
+ if (ai < args.length-1) {
+ ai++;
+ filter.since = Long.valueOf(args[ai]);
+ } else {
+ filter.since = 0;
+ }
+ }
}
- return null;
+ return filter;
}
public boolean matches(StatusBarNotification sbn) {
- return all ? true : sbn != null
+ if (!filtered) return true;
+ return zen ? true : sbn != null
&& (matches(sbn.getPackageName()) || matches(sbn.getOpPkg()));
}
public boolean matches(ComponentName component) {
- return all ? true : component != null && matches(component.getPackageName());
+ if (!filtered) return true;
+ return zen ? true : component != null && matches(component.getPackageName());
}
public boolean matches(String pkg) {
- return all ? true : pkg != null && pkg.toLowerCase().contains(pkgFilter);
+ if (!filtered) return true;
+ return zen ? true : pkg != null && pkg.toLowerCase().contains(pkgFilter);
}
@Override
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
index b7aea9d..f37702c 100644
--- a/services/core/java/com/android/server/notification/NotificationRecord.java
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -114,7 +114,7 @@ public final class NotificationRecord {
/** @deprecated Use {@link #getUser()} instead. */
public int getUserId() { return sbn.getUserId(); }
- void dump(PrintWriter pw, String prefix, Context baseContext) {
+ void dump(PrintWriter pw, String prefix, Context baseContext, boolean redact) {
final Notification notification = sbn.getNotification();
final Icon icon = notification.getSmallIcon();
String iconStr = String.valueOf(icon);
@@ -164,7 +164,7 @@ public final class NotificationRecord {
pw.println("null");
} else {
pw.print(val.getClass().getSimpleName());
- if (val instanceof CharSequence || val instanceof String) {
+ if (redact && (val instanceof CharSequence || val instanceof String)) {
// redact contents from bugreports
} else if (val instanceof Bitmap) {
pw.print(String.format(" (%dx%d)",
@@ -172,7 +172,14 @@ public final class NotificationRecord {
((Bitmap) val).getHeight()));
} else if (val.getClass().isArray()) {
final int N = Array.getLength(val);
- pw.println(" (" + N + ")");
+ pw.print(" (" + N + ")");
+ if (!redact) {
+ for (int j=0; j<N; j++) {
+ pw.println();
+ pw.print(String.format("%s [%d] %s",
+ prefix, j, String.valueOf(Array.get(val, j))));
+ }
+ }
} else {
pw.print(" (" + String.valueOf(val) + ")");
}
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 9e41f70..978ed51 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -753,7 +753,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
synchronized (mLock) {
if (shouldEnableWakeGestureLp()) {
performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
- wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
+ wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
+ "android.policy:GESTURE");
}
}
}
@@ -4691,7 +4692,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
updateRotation(true);
if (lidOpen) {
- wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
+ wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
+ "android.policy:LID");
} else if (!mLidControlsSleep) {
mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
}
@@ -4713,7 +4715,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
} else {
intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
}
- wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
+ wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
+ "android.policy:CAMERA_COVER");
startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
}
mCameraLensCoverState = lensCoverState;
@@ -4892,7 +4895,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (isValidGlobalKey(keyCode)
&& mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
if (isWakeKey) {
- wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
+ wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
}
return result;
}
@@ -5123,7 +5126,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
if (isWakeKey) {
- wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
+ wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
}
return result;
@@ -5184,7 +5187,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
@Override
public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
if ((policyFlags & FLAG_WAKE) != 0) {
- if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
+ if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
+ "android.policy:MOTION")) {
return 0;
}
}
@@ -5197,7 +5201,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// there will be no dream to intercept the touch and wake into ambient. The device should
// wake up in this case.
if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
- wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
+ wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
+ "android.policy:MOTION");
}
return 0;
@@ -5493,10 +5498,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
private void wakeUpFromPowerKey(long eventTime) {
- wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
+ wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
}
- private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
+ private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
final boolean theaterModeEnabled = isTheaterModeEnabled();
if (!wakeInTheaterMode && theaterModeEnabled) {
return false;
@@ -5507,7 +5512,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Settings.Global.THEATER_MODE_ON, 0);
}
- mPowerManager.wakeUp(wakeTime);
+ mPowerManager.wakeUp(wakeTime, reason);
return true;
}
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index d21c6d2..c5ad7fe 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -472,6 +472,26 @@ final class Notifier {
}
/**
+ * Called when the screen has turned on.
+ */
+ public void onWakeUp(String reason, int reasonUid, String opPackageName, int opUid) {
+ if (DEBUG) {
+ Slog.d(TAG, "onWakeUp: event=" + reason + ", reasonUid=" + reasonUid
+ + " opPackageName=" + opPackageName + " opUid=" + opUid);
+ }
+
+ try {
+ mBatteryStats.noteWakeUp(reason, reasonUid);
+ if (opPackageName != null) {
+ mAppOps.noteOperation(AppOpsManager.OP_TURN_SCREEN_ON, opUid, opPackageName);
+ }
+ } catch (RemoteException ex) {
+ // Ignore
+ }
+
+ }
+
+ /**
* Called when wireless charging has started so as to provide user feedback.
*/
public void onWirelessChargingStarted() {
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 3f59755..88476ce 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -830,7 +830,18 @@ public final class PowerManagerService extends SystemService
private void applyWakeLockFlagsOnAcquireLocked(WakeLock wakeLock, int uid) {
if ((wakeLock.mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0
&& isScreenLock(wakeLock)) {
- wakeUpNoUpdateLocked(SystemClock.uptimeMillis(), uid);
+ String opPackageName;
+ int opUid;
+ if (wakeLock.mWorkSource != null && wakeLock.mWorkSource.getName(0) != null) {
+ opPackageName = wakeLock.mWorkSource.getName(0);
+ opUid = wakeLock.mWorkSource.get(0);
+ } else {
+ opPackageName = wakeLock.mPackageName;
+ opUid = wakeLock.mWorkSource != null ? wakeLock.mWorkSource.get(0)
+ : wakeLock.mOwnerUid;
+ }
+ wakeUpNoUpdateLocked(SystemClock.uptimeMillis(), wakeLock.mTag, opUid,
+ opPackageName, opUid);
}
}
@@ -1042,17 +1053,19 @@ public final class PowerManagerService extends SystemService
return false;
}
- private void wakeUpInternal(long eventTime, int uid) {
+ private void wakeUpInternal(long eventTime, String reason, int uid, String opPackageName,
+ int opUid) {
synchronized (mLock) {
- if (wakeUpNoUpdateLocked(eventTime, uid)) {
+ if (wakeUpNoUpdateLocked(eventTime, reason, uid, opPackageName, opUid)) {
updatePowerStateLocked();
}
}
}
- private boolean wakeUpNoUpdateLocked(long eventTime, int uid) {
+ private boolean wakeUpNoUpdateLocked(long eventTime, String reason, int reasonUid,
+ String opPackageName, int opUid) {
if (DEBUG_SPEW) {
- Slog.d(TAG, "wakeUpNoUpdateLocked: eventTime=" + eventTime + ", uid=" + uid);
+ Slog.d(TAG, "wakeUpNoUpdateLocked: eventTime=" + eventTime + ", uid=" + reasonUid);
}
if (eventTime < mLastSleepTime || mWakefulness == WAKEFULNESS_AWAKE
@@ -1064,21 +1077,22 @@ public final class PowerManagerService extends SystemService
try {
switch (mWakefulness) {
case WAKEFULNESS_ASLEEP:
- Slog.i(TAG, "Waking up from sleep (uid " + uid +")...");
+ Slog.i(TAG, "Waking up from sleep (uid " + reasonUid +")...");
break;
case WAKEFULNESS_DREAMING:
- Slog.i(TAG, "Waking up from dream (uid " + uid +")...");
+ Slog.i(TAG, "Waking up from dream (uid " + reasonUid +")...");
break;
case WAKEFULNESS_DOZING:
- Slog.i(TAG, "Waking up from dozing (uid " + uid +")...");
+ Slog.i(TAG, "Waking up from dozing (uid " + reasonUid +")...");
break;
}
mLastWakeTime = eventTime;
setWakefulnessLocked(WAKEFULNESS_AWAKE, 0);
+ mNotifier.onWakeUp(reason, reasonUid, opPackageName, opUid);
userActivityNoUpdateLocked(
- eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, uid);
+ eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, reasonUid);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER);
}
@@ -1334,7 +1348,8 @@ public final class PowerManagerService extends SystemService
final long now = SystemClock.uptimeMillis();
if (shouldWakeUpWhenPluggedOrUnpluggedLocked(wasPowered, oldPlugType,
dockedOnWirelessCharger)) {
- wakeUpNoUpdateLocked(now, Process.SYSTEM_UID);
+ wakeUpNoUpdateLocked(now, "android.server.power:POWER", Process.SYSTEM_UID,
+ mContext.getOpPackageName(), Process.SYSTEM_UID);
}
userActivityNoUpdateLocked(
now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
@@ -1788,7 +1803,8 @@ public final class PowerManagerService extends SystemService
PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, 0, Process.SYSTEM_UID);
updatePowerStateLocked();
} else {
- wakeUpNoUpdateLocked(SystemClock.uptimeMillis(), Process.SYSTEM_UID);
+ wakeUpNoUpdateLocked(SystemClock.uptimeMillis(), "android.server.power:DREAM",
+ Process.SYSTEM_UID, mContext.getOpPackageName(), Process.SYSTEM_UID);
updatePowerStateLocked();
}
} else if (wakefulness == WAKEFULNESS_DOZING) {
@@ -3136,7 +3152,7 @@ public final class PowerManagerService extends SystemService
}
@Override // Binder call
- public void wakeUp(long eventTime) {
+ public void wakeUp(long eventTime, String reason, String opPackageName) {
if (eventTime > SystemClock.uptimeMillis()) {
throw new IllegalArgumentException("event time must not be in the future");
}
@@ -3147,7 +3163,7 @@ public final class PowerManagerService extends SystemService
final int uid = Binder.getCallingUid();
final long ident = Binder.clearCallingIdentity();
try {
- wakeUpInternal(eventTime, uid);
+ wakeUpInternal(eventTime, reason, uid, opPackageName, uid);
} finally {
Binder.restoreCallingIdentity(ident);
}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index ec566bc..05c111c 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -10307,7 +10307,7 @@ public class WindowManagerService extends IWindowManager.Stub
if (DEBUG_VISIBILITY || DEBUG_POWER) {
Slog.v(TAG, "Turning screen on after layout!");
}
- mPowerManager.wakeUp(SystemClock.uptimeMillis());
+ mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.wm:TURN_ON");
}
mTurnOnScreen = false;
}