Merge "Services exit fg when bg-restricted app leaves top"
am: 4221333afe
Change-Id: Ifb353d3d73268215d4c3832c81eeb11c7635c02b
This commit is contained in:
@@ -192,34 +192,38 @@ public final class ActiveServices {
|
|||||||
@Override
|
@Override
|
||||||
public void stopForegroundServicesForUidPackage(final int uid, final String packageName) {
|
public void stopForegroundServicesForUidPackage(final int uid, final String packageName) {
|
||||||
synchronized (mAm) {
|
synchronized (mAm) {
|
||||||
final ServiceMap smap = getServiceMapLocked(UserHandle.getUserId(uid));
|
stopAllForegroundServicesLocked(uid, packageName);
|
||||||
final int N = smap.mServicesByInstanceName.size();
|
}
|
||||||
final ArrayList<ServiceRecord> toStop = new ArrayList<>(N);
|
}
|
||||||
for (int i = 0; i < N; i++) {
|
}
|
||||||
final ServiceRecord r = smap.mServicesByInstanceName.valueAt(i);
|
|
||||||
if (uid == r.serviceInfo.applicationInfo.uid
|
|
||||||
|| packageName.equals(r.serviceInfo.packageName)) {
|
|
||||||
if (r.isForeground) {
|
|
||||||
toStop.add(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now stop them all
|
void stopAllForegroundServicesLocked(final int uid, final String packageName) {
|
||||||
final int numToStop = toStop.size();
|
final ServiceMap smap = getServiceMapLocked(UserHandle.getUserId(uid));
|
||||||
if (numToStop > 0 && DEBUG_FOREGROUND_SERVICE) {
|
final int N = smap.mServicesByInstanceName.size();
|
||||||
Slog.i(TAG, "Package " + packageName + "/" + uid
|
final ArrayList<ServiceRecord> toStop = new ArrayList<>(N);
|
||||||
+ " entering FAS with foreground services");
|
for (int i = 0; i < N; i++) {
|
||||||
}
|
final ServiceRecord r = smap.mServicesByInstanceName.valueAt(i);
|
||||||
for (int i = 0; i < numToStop; i++) {
|
if (uid == r.serviceInfo.applicationInfo.uid
|
||||||
final ServiceRecord r = toStop.get(i);
|
|| packageName.equals(r.serviceInfo.packageName)) {
|
||||||
if (DEBUG_FOREGROUND_SERVICE) {
|
if (r.isForeground) {
|
||||||
Slog.i(TAG, " Stopping fg for service " + r);
|
toStop.add(r);
|
||||||
}
|
|
||||||
setServiceForegroundInnerLocked(r, 0, null, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now stop them all
|
||||||
|
final int numToStop = toStop.size();
|
||||||
|
if (numToStop > 0 && DEBUG_FOREGROUND_SERVICE) {
|
||||||
|
Slog.i(TAG, "Package " + packageName + "/" + uid
|
||||||
|
+ " in FAS with foreground services");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < numToStop; i++) {
|
||||||
|
final ServiceRecord r = toStop.get(i);
|
||||||
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
|
Slog.i(TAG, " Stopping fg for service " + r);
|
||||||
|
}
|
||||||
|
setServiceForegroundInnerLocked(r, 0, null, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1010,12 +1014,23 @@ public final class ActiveServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!aa.mAppOnTop) {
|
if (!aa.mAppOnTop) {
|
||||||
if (active == null) {
|
// Transitioning a fg-service host app out of top: if it's bg restricted,
|
||||||
active = new ArrayList<>();
|
// it loses the fg service state now.
|
||||||
|
if (!appRestrictedAnyInBackground(aa.mUid, aa.mPackageName)) {
|
||||||
|
if (active == null) {
|
||||||
|
active = new ArrayList<>();
|
||||||
|
}
|
||||||
|
if (DEBUG_FOREGROUND_SERVICE) Slog.d(TAG, "Adding active: pkg="
|
||||||
|
+ aa.mPackageName + ", uid=" + aa.mUid);
|
||||||
|
active.add(aa);
|
||||||
|
} else {
|
||||||
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
|
Slog.d(TAG, "bg-restricted app "
|
||||||
|
+ aa.mPackageName + "/" + aa.mUid
|
||||||
|
+ " exiting top; demoting fg services ");
|
||||||
|
}
|
||||||
|
stopAllForegroundServicesLocked(aa.mUid, aa.mPackageName);
|
||||||
}
|
}
|
||||||
if (DEBUG_FOREGROUND_SERVICE) Slog.d(TAG, "Adding active: pkg="
|
|
||||||
+ aa.mPackageName + ", uid=" + aa.mUid);
|
|
||||||
active.add(aa);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smap.removeMessages(ServiceMap.MSG_UPDATE_FOREGROUND_APPS);
|
smap.removeMessages(ServiceMap.MSG_UPDATE_FOREGROUND_APPS);
|
||||||
|
|||||||
Reference in New Issue
Block a user