Merge "Do not allow FGS starts from sync" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f349d18f17
@@ -17,6 +17,7 @@
|
||||
package com.android.server;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.os.PowerWhitelistManager;
|
||||
import android.os.PowerWhitelistManager.ReasonCode;
|
||||
import android.os.PowerWhitelistManager.TempAllowListType;
|
||||
|
||||
@@ -32,10 +33,21 @@ public interface DeviceIdleInternal {
|
||||
|
||||
void exitIdle(String reason);
|
||||
|
||||
/**
|
||||
* Same as {@link #addPowerSaveTempWhitelistApp(int, String, long, int, boolean, int, String)}
|
||||
* with {@link PowerWhitelistManager#TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED}.
|
||||
*/
|
||||
void addPowerSaveTempWhitelistApp(int callingUid, String packageName,
|
||||
long durationMs, int userId, boolean sync, @ReasonCode int reasonCode,
|
||||
@Nullable String reason);
|
||||
|
||||
/**
|
||||
* Put a package in the temp-allowlist.
|
||||
*/
|
||||
void addPowerSaveTempWhitelistApp(int callingUid, String packageName,
|
||||
long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync,
|
||||
@ReasonCode int reasonCode, @Nullable String reason);
|
||||
|
||||
/**
|
||||
* Called by ActivityManagerService to directly add UID to DeviceIdleController's temp
|
||||
* allowlist.
|
||||
|
||||
@@ -1942,22 +1942,29 @@ public class DeviceIdleController extends SystemService
|
||||
exitIdleInternal(reason);
|
||||
}
|
||||
|
||||
// duration in milliseconds
|
||||
@Override
|
||||
public void addPowerSaveTempWhitelistApp(int callingUid, String packageName,
|
||||
long durationMs, int userId, boolean sync, @ReasonCode int reasonCode,
|
||||
@Nullable String reason) {
|
||||
addPowerSaveTempAllowlistAppInternal(callingUid, packageName, durationMs,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
userId, sync, reasonCode, reason);
|
||||
}
|
||||
|
||||
// duration in milliseconds
|
||||
@Override
|
||||
public void addPowerSaveTempWhitelistAppDirect(int uid, long duration,
|
||||
@TempAllowListType int type, boolean sync, @ReasonCode int reasonCode,
|
||||
public void addPowerSaveTempWhitelistApp(int callingUid, String packageName,
|
||||
long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync,
|
||||
@ReasonCode int reasonCode, @Nullable String reason) {
|
||||
addPowerSaveTempAllowlistAppInternal(callingUid, packageName, durationMs,
|
||||
tempAllowListType, userId, sync, reasonCode, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPowerSaveTempWhitelistAppDirect(int uid, long durationMs,
|
||||
@TempAllowListType int tempAllowListType, boolean sync, @ReasonCode int reasonCode,
|
||||
@Nullable String reason, int callingUid) {
|
||||
addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, duration, type, sync,
|
||||
reasonCode, reason);
|
||||
addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, durationMs,
|
||||
tempAllowListType, sync, reasonCode, reason);
|
||||
}
|
||||
|
||||
// duration in milliseconds
|
||||
@@ -2699,7 +2706,8 @@ public class DeviceIdleController extends SystemService
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
addPowerSaveTempAllowlistAppInternal(callingUid,
|
||||
packageName, duration, userId, true, reasonCode, reason);
|
||||
packageName, duration, TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
userId, true, reasonCode, reason);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
@@ -2731,8 +2739,8 @@ public class DeviceIdleController extends SystemService
|
||||
* app an exemption to access network and acquire wakelocks.
|
||||
*/
|
||||
void addPowerSaveTempAllowlistAppInternal(int callingUid, String packageName,
|
||||
long duration, int userId, boolean sync, @ReasonCode int reasonCode,
|
||||
@Nullable String reason) {
|
||||
long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync,
|
||||
@ReasonCode int reasonCode, @Nullable String reason) {
|
||||
synchronized (this) {
|
||||
int callingAppId = UserHandle.getAppId(callingUid);
|
||||
if (callingAppId >= Process.FIRST_APPLICATION_UID) {
|
||||
@@ -2745,8 +2753,8 @@ public class DeviceIdleController extends SystemService
|
||||
}
|
||||
try {
|
||||
int uid = getContext().getPackageManager().getPackageUidAsUser(packageName, userId);
|
||||
addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, duration,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, sync, reasonCode, reason);
|
||||
addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, durationMs,
|
||||
tempAllowListType, sync, reasonCode, reason);
|
||||
} catch (NameNotFoundException e) {
|
||||
}
|
||||
}
|
||||
@@ -2756,8 +2764,8 @@ public class DeviceIdleController extends SystemService
|
||||
* app an exemption to access network and acquire wakelocks.
|
||||
*/
|
||||
void addPowerSaveTempWhitelistAppDirectInternal(int callingUid, int uid,
|
||||
long duration, @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode,
|
||||
@Nullable String reason) {
|
||||
long duration, @TempAllowListType int tempAllowListType, boolean sync,
|
||||
@ReasonCode int reasonCode, @Nullable String reason) {
|
||||
final long timeNow = SystemClock.elapsedRealtime();
|
||||
boolean informWhitelistChanged = false;
|
||||
int appId = UserHandle.getAppId(uid);
|
||||
@@ -2782,8 +2790,8 @@ public class DeviceIdleController extends SystemService
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
postTempActiveTimeoutMessage(uid, duration);
|
||||
updateTempWhitelistAppIdsLocked(uid, true, duration, type, reasonCode,
|
||||
reason, callingUid);
|
||||
updateTempWhitelistAppIdsLocked(uid, true, duration, tempAllowListType,
|
||||
reasonCode, reason, callingUid);
|
||||
if (sync) {
|
||||
informWhitelistChanged = true;
|
||||
} else {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.server.content;
|
||||
|
||||
import static android.os.PowerWhitelistManager.REASON_SYNC_MANAGER;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED;
|
||||
|
||||
import static com.android.server.content.SyncLogger.logSafe;
|
||||
|
||||
@@ -1672,6 +1673,7 @@ public class SyncManager {
|
||||
dic.addPowerSaveTempWhitelistApp(Process.SYSTEM_UID,
|
||||
syncOperation.owningPackage,
|
||||
mConstants.getKeyExemptionTempWhitelistDurationInSeconds() * 1000,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED,
|
||||
UserHandle.getUserId(syncOperation.owningUid),
|
||||
/* sync=*/ false, REASON_SYNC_MANAGER, "sync by top app");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user