Unverified Commit 74544b9e authored by Kevin F. Haggerty's avatar Kevin F. Haggerty

Merge tag 'android-11.0.0_r43' into staging/lineage-18.1_merge-android-11.0.0_r43

Android 11.0.0 release 43

* tag 'android-11.0.0_r43':
  Use IntentFilter CREATOR directly for serializing ParsedIntentInfo
  Don't export HeapDumpProvider.
  Don't attach private Notification to A11yEvent when user locked
  Merge "BG-FGS-start while-in-use permission restriction improvement." into rvc-dev am: e51f884f6a
  Avoid locking profile task when it is already lock
  Improve ellipsize performance
  Fix side effects of trace-ipc and dumpheap commands
  DO NOT MERGE Add cross-user check for getDefaultSmsPackage().
  Remove ParsedIntentInfo CREATOR
  Fix race condition between lockNow() and updateLockscreenTimeout

Conflicts:
	services/core/java/com/android/server/policy/PhoneWindowManager.java

Change-Id: I6a9a3e341be1fccaa568b875d4d9959d8f068794
parents 1bbd5668 2384fb32
...@@ -19,7 +19,6 @@ package android.content.pm.parsing.component; ...@@ -19,7 +19,6 @@ package android.content.pm.parsing.component;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable;
import android.util.Pair; import android.util.Pair;
import com.android.internal.util.DataClass; import com.android.internal.util.DataClass;
...@@ -168,19 +167,6 @@ public final class ParsedIntentInfo extends IntentFilter { ...@@ -168,19 +167,6 @@ public final class ParsedIntentInfo extends IntentFilter {
+ '}'; + '}';
} }
public static final Parcelable.Creator<ParsedIntentInfo> CREATOR =
new Parcelable.Creator<ParsedIntentInfo>() {
@Override
public ParsedIntentInfo createFromParcel(Parcel source) {
return new ParsedIntentInfo(source);
}
@Override
public ParsedIntentInfo[] newArray(int size) {
return new ParsedIntentInfo[size];
}
};
public boolean isHasDefault() { public boolean isHasDefault() {
return hasDefault; return hasDefault;
} }
......
...@@ -2350,7 +2350,10 @@ public abstract class Layout { ...@@ -2350,7 +2350,10 @@ public abstract class Layout {
final int ellipsisStringLen = ellipsisString.length(); final int ellipsisStringLen = ellipsisString.length();
// Use the ellipsis string only if there are that at least as many characters to replace. // Use the ellipsis string only if there are that at least as many characters to replace.
final boolean useEllipsisString = ellipsisCount >= ellipsisStringLen; final boolean useEllipsisString = ellipsisCount >= ellipsisStringLen;
for (int i = 0; i < ellipsisCount; i++) { final int min = Math.max(0, start - ellipsisStart - lineStart);
final int max = Math.min(ellipsisCount, end - ellipsisStart - lineStart);
for (int i = min; i < max; i++) {
final char c; final char c;
if (useEllipsisString && i < ellipsisStringLen) { if (useEllipsisString && i < ellipsisStringLen) {
c = ellipsisString.charAt(i); c = ellipsisString.charAt(i);
...@@ -2359,9 +2362,7 @@ public abstract class Layout { ...@@ -2359,9 +2362,7 @@ public abstract class Layout {
} }
final int a = i + ellipsisStart + lineStart; final int a = i + ellipsisStart + lineStart;
if (start <= a && a < end) { dest[destoff + a - start] = c;
dest[destoff + a - start] = c;
}
} }
} }
......
...@@ -346,7 +346,7 @@ ...@@ -346,7 +346,7 @@
<provider android:name=".HeapDumpProvider" <provider android:name=".HeapDumpProvider"
android:authorities="com.android.shell.heapdump" android:authorities="com.android.shell.heapdump"
android:grantUriPermissions="true" android:grantUriPermissions="true"
android:exported="true" /> android:exported="false" />
<activity <activity
android:name=".BugreportWarningActivity" android:name=".BugreportWarningActivity"
......
...@@ -734,11 +734,8 @@ public final class ActiveServices { ...@@ -734,11 +734,8 @@ public final class ActiveServices {
} }
ComponentName cmp = startServiceInnerLocked(smap, service, r, callerFg, addToStarting); ComponentName cmp = startServiceInnerLocked(smap, service, r, callerFg, addToStarting);
if (!r.mAllowWhileInUsePermissionInFgs) { setFgsRestrictionLocked(callingPackage, callingPid, callingUid, r,
r.mAllowWhileInUsePermissionInFgs = allowBackgroundActivityStarts);
shouldAllowWhileInUsePermissionInFgsLocked(callingPackage, callingPid,
callingUid, service, r, allowBackgroundActivityStarts);
}
return cmp; return cmp;
} }
...@@ -1411,14 +1408,6 @@ public final class ActiveServices { ...@@ -1411,14 +1408,6 @@ public final class ActiveServices {
+ String.format("0x%08X", manifestType) + String.format("0x%08X", manifestType)
+ " in service element of manifest file"); + " in service element of manifest file");
} }
// If the foreground service is not started from TOP process, do not allow it to
// have while-in-use location/camera/microphone access.
if (!r.mAllowWhileInUsePermissionInFgs) {
Slog.w(TAG,
"Foreground service started from background can not have "
+ "location/camera/microphone access: service "
+ r.shortInstanceName);
}
} }
boolean alreadyStartedOp = false; boolean alreadyStartedOp = false;
boolean stopProcStatsOp = false; boolean stopProcStatsOp = false;
...@@ -1466,6 +1455,57 @@ public final class ActiveServices { ...@@ -1466,6 +1455,57 @@ public final class ActiveServices {
ignoreForeground = true; ignoreForeground = true;
} }
if (!ignoreForeground) {
if (r.mStartForegroundCount == 0) {
/*
If the service was started with startService(), not
startForegroundService(), and if startForeground() isn't called within
mFgsStartForegroundTimeoutMs, then we check the state of the app
(who owns the service, which is the app that called startForeground())
again. If the app is in the foreground, or in any other cases where
FGS-starts are allowed, then we still allow the FGS to be started.
Otherwise, startForeground() would fail.
If the service was started with startForegroundService(), then the service
must call startForeground() within a timeout anyway, so we don't need this
check.
*/
if (!r.fgRequired) {
final long delayMs = SystemClock.elapsedRealtime() - r.createRealTime;
if (delayMs > mAm.mConstants.mFgsStartForegroundTimeoutMs) {
resetFgsRestrictionLocked(r);
setFgsRestrictionLocked(r.serviceInfo.packageName, r.app.pid,
r.appInfo.uid, r, false);
EventLog.writeEvent(0x534e4554, "183147114",
r.appInfo.uid,
"call setFgsRestrictionLocked again due to "
+ "startForegroundTimeout");
}
}
} else if (r.mStartForegroundCount >= 1) {
// The second or later time startForeground() is called after service is
// started. Check for app state again.
final long delayMs = SystemClock.elapsedRealtime() -
r.mLastSetFgsRestrictionTime;
if (delayMs > mAm.mConstants.mFgsStartForegroundTimeoutMs) {
resetFgsRestrictionLocked(r);
setFgsRestrictionLocked(r.serviceInfo.packageName, r.app.pid,
r.appInfo.uid, r, false);
EventLog.writeEvent(0x534e4554, "183147114", r.appInfo.uid,
"call setFgsRestrictionLocked for "
+ (r.mStartForegroundCount + 1) + "th startForeground");
}
}
// If the foreground service is not started from TOP process, do not allow it to
// have while-in-use location/camera/microphone access.
if (!r.mAllowWhileInUsePermissionInFgs) {
Slog.w(TAG,
"Foreground service started from background can not have "
+ "location/camera/microphone access: service "
+ r.shortInstanceName);
}
}
// Apps under strict background restrictions simply don't get to have foreground // Apps under strict background restrictions simply don't get to have foreground
// services, so now that we've enforced the startForegroundService() contract // services, so now that we've enforced the startForegroundService() contract
// we only do the machinery of making the service foreground when the app // we only do the machinery of making the service foreground when the app
...@@ -1501,6 +1541,7 @@ public final class ActiveServices { ...@@ -1501,6 +1541,7 @@ public final class ActiveServices {
active.mNumActive++; active.mNumActive++;
} }
r.isForeground = true; r.isForeground = true;
r.mStartForegroundCount++;
if (!stopProcStatsOp) { if (!stopProcStatsOp) {
ServiceState stracker = r.getTracker(); ServiceState stracker = r.getTracker();
if (stracker != null) { if (stracker != null) {
...@@ -1559,6 +1600,7 @@ public final class ActiveServices { ...@@ -1559,6 +1600,7 @@ public final class ActiveServices {
decActiveForegroundAppLocked(smap, r); decActiveForegroundAppLocked(smap, r);
} }
r.isForeground = false; r.isForeground = false;
resetFgsRestrictionLocked(r);
ServiceState stracker = r.getTracker(); ServiceState stracker = r.getTracker();
if (stracker != null) { if (stracker != null) {
stracker.setForeground(false, mAm.mProcessStats.getMemFactorLocked(), stracker.setForeground(false, mAm.mProcessStats.getMemFactorLocked(),
...@@ -2118,12 +2160,7 @@ public final class ActiveServices { ...@@ -2118,12 +2160,7 @@ public final class ActiveServices {
} }
} }
if (!s.mAllowWhileInUsePermissionInFgs) { setFgsRestrictionLocked(callingPackage, callingPid, callingUid, s, false);
s.mAllowWhileInUsePermissionInFgs =
shouldAllowWhileInUsePermissionInFgsLocked(callingPackage,
callingPid, callingUid,
service, s, false);
}
if (s.app != null) { if (s.app != null) {
if ((flags&Context.BIND_TREAT_LIKE_ACTIVITY) != 0) { if ((flags&Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
...@@ -3419,7 +3456,7 @@ public final class ActiveServices { ...@@ -3419,7 +3456,7 @@ public final class ActiveServices {
r.isForeground = false; r.isForeground = false;
r.foregroundId = 0; r.foregroundId = 0;
r.foregroundNoti = null; r.foregroundNoti = null;
r.mAllowWhileInUsePermissionInFgs = false; resetFgsRestrictionLocked(r);
// Clear start entries. // Clear start entries.
r.clearDeliveredStartsLocked(); r.clearDeliveredStartsLocked();
...@@ -4900,7 +4937,7 @@ public final class ActiveServices { ...@@ -4900,7 +4937,7 @@ public final class ActiveServices {
* @return true if allow, false otherwise. * @return true if allow, false otherwise.
*/ */
private boolean shouldAllowWhileInUsePermissionInFgsLocked(String callingPackage, private boolean shouldAllowWhileInUsePermissionInFgsLocked(String callingPackage,
int callingPid, int callingUid, Intent intent, ServiceRecord r, int callingPid, int callingUid, ServiceRecord r,
boolean allowBackgroundActivityStarts) { boolean allowBackgroundActivityStarts) {
// Is the background FGS start restriction turned on? // Is the background FGS start restriction turned on?
if (!mAm.mConstants.mFlagBackgroundFgsStartRestrictionEnabled) { if (!mAm.mConstants.mFlagBackgroundFgsStartRestrictionEnabled) {
...@@ -4986,6 +5023,28 @@ public final class ActiveServices { ...@@ -4986,6 +5023,28 @@ public final class ActiveServices {
boolean canAllowWhileInUsePermissionInFgsLocked(int callingPid, int callingUid, boolean canAllowWhileInUsePermissionInFgsLocked(int callingPid, int callingUid,
String callingPackage) { String callingPackage) {
return shouldAllowWhileInUsePermissionInFgsLocked( return shouldAllowWhileInUsePermissionInFgsLocked(
callingPackage, callingPid, callingUid, null, null, false); callingPackage, callingPid, callingUid, null, false);
}
/**
* In R, mAllowWhileInUsePermissionInFgs is to allow while-in-use permissions in foreground
* service or not. while-in-use permissions in FGS started from background might be restricted.
* @param callingPackage caller app's package name.
* @param callingUid caller app's uid.
* @param r the service to start.
* @return true if allow, false otherwise.
*/
private void setFgsRestrictionLocked(String callingPackage,
int callingPid, int callingUid, ServiceRecord r,
boolean allowBackgroundActivityStarts) {
r.mLastSetFgsRestrictionTime = SystemClock.elapsedRealtime();
if (!r.mAllowWhileInUsePermissionInFgs) {
r.mAllowWhileInUsePermissionInFgs = shouldAllowWhileInUsePermissionInFgsLocked(
callingPackage, callingPid, callingUid, r, allowBackgroundActivityStarts);
}
}
private void resetFgsRestrictionLocked(ServiceRecord r) {
r.mAllowWhileInUsePermissionInFgs = false;
} }
} }
...@@ -88,6 +88,7 @@ final class ActivityManagerConstants extends ContentObserver { ...@@ -88,6 +88,7 @@ final class ActivityManagerConstants extends ContentObserver {
static final String KEY_PROCESS_START_ASYNC = "process_start_async"; static final String KEY_PROCESS_START_ASYNC = "process_start_async";
static final String KEY_MEMORY_INFO_THROTTLE_TIME = "memory_info_throttle_time"; static final String KEY_MEMORY_INFO_THROTTLE_TIME = "memory_info_throttle_time";
static final String KEY_TOP_TO_FGS_GRACE_DURATION = "top_to_fgs_grace_duration"; static final String KEY_TOP_TO_FGS_GRACE_DURATION = "top_to_fgs_grace_duration";
static final String KEY_FGS_START_FOREGROUND_TIMEOUT = "fgs_start_foreground_timeout";
static final String KEY_PENDINGINTENT_WARNING_THRESHOLD = "pendingintent_warning_threshold"; static final String KEY_PENDINGINTENT_WARNING_THRESHOLD = "pendingintent_warning_threshold";
private static final int DEFAULT_MAX_CACHED_PROCESSES = 32; private static final int DEFAULT_MAX_CACHED_PROCESSES = 32;
...@@ -121,6 +122,7 @@ final class ActivityManagerConstants extends ContentObserver { ...@@ -121,6 +122,7 @@ final class ActivityManagerConstants extends ContentObserver {
private static final boolean DEFAULT_PROCESS_START_ASYNC = true; private static final boolean DEFAULT_PROCESS_START_ASYNC = true;
private static final long DEFAULT_MEMORY_INFO_THROTTLE_TIME = 5*60*1000; private static final long DEFAULT_MEMORY_INFO_THROTTLE_TIME = 5*60*1000;
private static final long DEFAULT_TOP_TO_FGS_GRACE_DURATION = 15 * 1000; private static final long DEFAULT_TOP_TO_FGS_GRACE_DURATION = 15 * 1000;
private static final int DEFAULT_FGS_START_FOREGROUND_TIMEOUT_MS = 10 * 1000;
private static final int DEFAULT_PENDINGINTENT_WARNING_THRESHOLD = 2000; private static final int DEFAULT_PENDINGINTENT_WARNING_THRESHOLD = 2000;
// Flag stored in the DeviceConfig API. // Flag stored in the DeviceConfig API.
...@@ -273,6 +275,12 @@ final class ActivityManagerConstants extends ContentObserver { ...@@ -273,6 +275,12 @@ final class ActivityManagerConstants extends ContentObserver {
// this long. // this long.
public long TOP_TO_FGS_GRACE_DURATION = DEFAULT_TOP_TO_FGS_GRACE_DURATION; public long TOP_TO_FGS_GRACE_DURATION = DEFAULT_TOP_TO_FGS_GRACE_DURATION;
/**
* When service started from background, before the timeout it can be promoted to FGS by calling
* Service.startForeground().
*/
volatile long mFgsStartForegroundTimeoutMs = DEFAULT_FGS_START_FOREGROUND_TIMEOUT_MS;
// Indicates whether the activity starts logging is enabled. // Indicates whether the activity starts logging is enabled.
// Controlled by Settings.Global.ACTIVITY_STARTS_LOGGING_ENABLED // Controlled by Settings.Global.ACTIVITY_STARTS_LOGGING_ENABLED
volatile boolean mFlagActivityStartsLoggingEnabled; volatile boolean mFlagActivityStartsLoggingEnabled;
...@@ -421,6 +429,9 @@ final class ActivityManagerConstants extends ContentObserver { ...@@ -421,6 +429,9 @@ final class ActivityManagerConstants extends ContentObserver {
case KEY_MIN_ASSOC_LOG_DURATION: case KEY_MIN_ASSOC_LOG_DURATION:
updateMinAssocLogDuration(); updateMinAssocLogDuration();
break; break;
case KEY_FGS_START_FOREGROUND_TIMEOUT:
updateFgsStartForegroundTimeout();
break;
default: default:
break; break;
} }
...@@ -697,6 +708,13 @@ final class ActivityManagerConstants extends ContentObserver { ...@@ -697,6 +708,13 @@ final class ActivityManagerConstants extends ContentObserver {
/* defaultValue */ DEFAULT_MIN_ASSOC_LOG_DURATION); /* defaultValue */ DEFAULT_MIN_ASSOC_LOG_DURATION);
} }
private void updateFgsStartForegroundTimeout() {
mFgsStartForegroundTimeoutMs = DeviceConfig.getLong(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
KEY_FGS_START_FOREGROUND_TIMEOUT,
DEFAULT_FGS_START_FOREGROUND_TIMEOUT_MS);
}
void dump(PrintWriter pw) { void dump(PrintWriter pw) {
pw.println("ACTIVITY MANAGER SETTINGS (dumpsys activity settings) " pw.println("ACTIVITY MANAGER SETTINGS (dumpsys activity settings) "
+ Settings.Global.ACTIVITY_MANAGER_CONSTANTS + ":"); + Settings.Global.ACTIVITY_MANAGER_CONSTANTS + ":");
...@@ -769,6 +787,8 @@ final class ActivityManagerConstants extends ContentObserver { ...@@ -769,6 +787,8 @@ final class ActivityManagerConstants extends ContentObserver {
pw.println(Arrays.toString(IMPERCEPTIBLE_KILL_EXEMPT_PACKAGES.toArray())); pw.println(Arrays.toString(IMPERCEPTIBLE_KILL_EXEMPT_PACKAGES.toArray()));
pw.print(" "); pw.print(KEY_MIN_ASSOC_LOG_DURATION); pw.print("="); pw.print(" "); pw.print(KEY_MIN_ASSOC_LOG_DURATION); pw.print("=");
pw.println(MIN_ASSOC_LOG_DURATION); pw.println(MIN_ASSOC_LOG_DURATION);
pw.print(" "); pw.print(KEY_FGS_START_FOREGROUND_TIMEOUT); pw.print("=");
pw.println(mFgsStartForegroundTimeoutMs);
pw.println(); pw.println();
if (mOverrideMaxCachedProcesses >= 0) { if (mOverrideMaxCachedProcesses >= 0) {
......
...@@ -94,7 +94,6 @@ import com.android.internal.util.MemInfoReader; ...@@ -94,7 +94,6 @@ import com.android.internal.util.MemInfoReader;
import com.android.server.compat.PlatformCompat; import com.android.server.compat.PlatformCompat;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -787,8 +786,7 @@ final class ActivityManagerShellCommand extends ShellCommand { ...@@ -787,8 +786,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
return -1; return -1;
} }
File file = new File(filename); // Writes an error message to stderr on failure
file.delete();
ParcelFileDescriptor fd = openFileForSystem(filename, "w"); ParcelFileDescriptor fd = openFileForSystem(filename, "w");
if (fd == null) { if (fd == null) {
return -1; return -1;
...@@ -942,16 +940,16 @@ final class ActivityManagerShellCommand extends ShellCommand { ...@@ -942,16 +940,16 @@ final class ActivityManagerShellCommand extends ShellCommand {
String logNameTimeString = LOG_NAME_TIME_FORMATTER.format(localDateTime); String logNameTimeString = LOG_NAME_TIME_FORMATTER.format(localDateTime);
heapFile = "/data/local/tmp/heapdump-" + logNameTimeString + ".prof"; heapFile = "/data/local/tmp/heapdump-" + logNameTimeString + ".prof";
} }
pw.println("File: " + heapFile);
pw.flush();
File file = new File(heapFile); // Writes an error message to stderr on failure
file.delete();
ParcelFileDescriptor fd = openFileForSystem(heapFile, "w"); ParcelFileDescriptor fd = openFileForSystem(heapFile, "w");
if (fd == null) { if (fd == null) {
return -1; return -1;
} }
pw.println("File: " + heapFile);
pw.flush();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final RemoteCallback finishCallback = new RemoteCallback(new OnResultListener() { final RemoteCallback finishCallback = new RemoteCallback(new OnResultListener() {
......
...@@ -142,6 +142,10 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN ...@@ -142,6 +142,10 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
// allow while-in-use permissions in foreground service or not. // allow while-in-use permissions in foreground service or not.
// while-in-use permissions in FGS started from background might be restricted. // while-in-use permissions in FGS started from background might be restricted.
boolean mAllowWhileInUsePermissionInFgs; boolean mAllowWhileInUsePermissionInFgs;
// The number of times Service.startForeground() is called;
int mStartForegroundCount;
// Last time mAllowWhileInUsePermissionInFgs is set.
long mLastSetFgsRestrictionTime;
// the most recent package that start/bind this service. // the most recent package that start/bind this service.
String mRecentCallingPackage; String mRecentCallingPackage;
...@@ -406,6 +410,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN ...@@ -406,6 +410,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
} }
pw.print(prefix); pw.print("allowWhileInUsePermissionInFgs="); pw.print(prefix); pw.print("allowWhileInUsePermissionInFgs=");
pw.println(mAllowWhileInUsePermissionInFgs); pw.println(mAllowWhileInUsePermissionInFgs);
pw.print(prefix); pw.print("startForegroundCount=");
pw.println(mStartForegroundCount);
pw.print(prefix); pw.print("recentCallingPackage="); pw.print(prefix); pw.print("recentCallingPackage=");
pw.println(mRecentCallingPackage); pw.println(mRecentCallingPackage);
if (delayed) { if (delayed) {
......
...@@ -125,6 +125,7 @@ import android.app.INotificationManager; ...@@ -125,6 +125,7 @@ import android.app.INotificationManager;
import android.app.ITransientNotification; import android.app.ITransientNotification;
import android.app.ITransientNotificationCallback; import android.app.ITransientNotificationCallback;
import android.app.IUriGrantsManager; import android.app.IUriGrantsManager;
import android.app.KeyguardManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationChannelGroup; import android.app.NotificationChannelGroup;
...@@ -488,6 +489,8 @@ public class NotificationManagerService extends SystemService { ...@@ -488,6 +489,8 @@ public class NotificationManagerService extends SystemService {
new ArrayMap<>(); new ArrayMap<>();
final ArrayMap<String, Long> mLastSoundTimestamps = new ArrayMap<>(); final ArrayMap<String, Long> mLastSoundTimestamps = new ArrayMap<>();
private KeyguardManager mKeyguardManager;
// The last key in this list owns the hardware. // The last key in this list owns the hardware.
ArrayList<String> mLights = new ArrayList<>(); ArrayList<String> mLights = new ArrayList<>();
...@@ -1742,6 +1745,11 @@ public class NotificationManagerService extends SystemService { ...@@ -1742,6 +1745,11 @@ public class NotificationManagerService extends SystemService {
mAudioManager = audioMananger; mAudioManager = audioMananger;
} }
@VisibleForTesting
void setKeyguardManager(KeyguardManager keyguardManager) {
mKeyguardManager = keyguardManager;
}
@VisibleForTesting @VisibleForTesting
ShortcutHelper getShortcutHelper() { ShortcutHelper getShortcutHelper() {
return mShortcutHelper; return mShortcutHelper;
...@@ -2356,6 +2364,7 @@ public class NotificationManagerService extends SystemService { ...@@ -2356,6 +2364,7 @@ public class NotificationManagerService extends SystemService {
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManagerInternal = getLocalService(AudioManagerInternal.class); mAudioManagerInternal = getLocalService(AudioManagerInternal.class);
mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
mKeyguardManager = getContext().getSystemService(KeyguardManager.class);
mZenModeHelper.onSystemReady(); mZenModeHelper.onSystemReady();
mRoleObserver = new RoleObserver(getContext().getSystemService(RoleManager.class), mRoleObserver = new RoleObserver(getContext().getSystemService(RoleManager.class),
mPackageManager, getContext().getMainExecutor()); mPackageManager, getContext().getMainExecutor());
...@@ -6949,7 +6958,6 @@ public class NotificationManagerService extends SystemService { ...@@ -6949,7 +6958,6 @@ public class NotificationManagerService extends SystemService {
boolean beep = false; boolean beep = false;
boolean blink = false; boolean blink = false;
final Notification notification = record.getSbn().getNotification();
final String key = record.getKey(); final String key = record.getKey();
// Should this notification make noise, vibe, or use the LED? // Should this notification make noise, vibe, or use the LED?
...@@ -6971,7 +6979,7 @@ public class NotificationManagerService extends SystemService { ...@@ -6971,7 +6979,7 @@ public class NotificationManagerService extends SystemService {
if (!record.isUpdate if (!record.isUpdate
&& record.getImportance() > IMPORTANCE_MIN && record.getImportance() > IMPORTANCE_MIN
&& !suppressedByDnd) { && !suppressedByDnd) {
sendAccessibilityEvent(notification, record.getSbn().getPackageName()); sendAccessibilityEvent(record);
sentAccessibilityEvent = true; sentAccessibilityEvent = true;
} }
...@@ -6994,7 +7002,7 @@ public class NotificationManagerService extends SystemService { ...@@ -6994,7 +7002,7 @@ public class NotificationManagerService extends SystemService {
if (hasAudibleAlert && !shouldMuteNotificationLocked(record) if (hasAudibleAlert && !shouldMuteNotificationLocked(record)
&& !isInSoundTimeoutPeriod(record)) { && !isInSoundTimeoutPeriod(record)) {
if (!sentAccessibilityEvent) { if (!sentAccessibilityEvent) {
sendAccessibilityEvent(notification, record.getSbn().getPackageName()); sendAccessibilityEvent(record);
sentAccessibilityEvent = true; sentAccessibilityEvent = true;
} }
if (DBG) Slog.v(TAG, "Interrupting!"); if (DBG) Slog.v(TAG, "Interrupting!");
...@@ -7727,17 +7735,30 @@ public class NotificationManagerService extends SystemService { ...@@ -7727,17 +7735,30 @@ public class NotificationManagerService extends SystemService {
return (x < low) ? low : ((x > high) ? high : x); return (x < low) ? low : ((x > high) ? high : x);
} }
void sendAccessibilityEvent(Notification notification, CharSequence packageName) { void sendAccessibilityEvent(NotificationRecord record) {
if (!mAccessibilityManager.isEnabled()) { if (!mAccessibilityManager.isEnabled()) {
return; return;
} }
AccessibilityEvent event = final Notification notification = record.getNotification();
final CharSequence packageName = record.getSbn().getPackageName();
final AccessibilityEvent event =
AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
event.setPackageName(packageName); event.setPackageName(packageName);
event.setClassName(Notification.class.getName()); event.setClassName(Notification.class.getName());
event.setParcelableData(notification); final int visibilityOverride = record.getPackageVisibilityOverride();
CharSequence tickerText = notification.tickerText; final int notifVisibility = visibilityOverride == NotificationManager.VISIBILITY_NO_OVERRIDE
? notification.visibility : visibilityOverride;
final int userId = record.getUser().getIdentifier();
final boolean needPublic = userId >= 0 && mKeyguardManager.isDeviceLocked(userId);
if (needPublic && notifVisibility != Notification.VISIBILITY_PUBLIC) {
// Emit the public version if we're on the lockscreen and this notification isn't
// publicly visible.
event.setParcelableData(notification.publicVersion);