Merge "Turn on foregroundServiceType camera and microphone feature in permissive mode." into rvc-dev am: 4723328cee

Change-Id: I17aaf2285792a1479cc1dcd6d90da4031009b504
This commit is contained in:
Automerger Merge Worker
2020-03-16 19:27:36 +00:00
3 changed files with 54 additions and 14 deletions

View File

@@ -137,6 +137,10 @@ public final class ActiveServices {
private static final boolean SHOW_DUNGEON_NOTIFICATION = false;
//TODO: remove this when development is done.
private static final int DEBUG_FGS_ALLOW_WHILE_IN_USE = 0;
private static final int DEBUG_FGS_ENFORCE_TYPE = 1;
// How long we wait for a service to finish executing.
static final int SERVICE_TIMEOUT = 20*1000;
@@ -4915,10 +4919,20 @@ public final class ActiveServices {
if (!r.isForeground) {
continue;
}
if (!r.mAllowWhileInUsePermissionInFgs
&& r.mInfoDenyWhileInUsePermissionInFgs != null) {
final String msg = r.mInfoDenyWhileInUsePermissionInFgs
+ " affected while-in-use permission:"
if (mode == DEBUG_FGS_ALLOW_WHILE_IN_USE) {
if (!r.mAllowWhileInUsePermissionInFgs
&& r.mInfoDenyWhileInUsePermissionInFgs != null) {
final String msg = r.mInfoDenyWhileInUsePermissionInFgs
+ " affected while-in-use permission:"
+ AppOpsManager.opToPublicName(op);
Slog.wtf(TAG, msg);
}
} else if (mode == DEBUG_FGS_ENFORCE_TYPE) {
final String msg =
"FGS Missing foregroundServiceType in manifest file [callingPackage: "
+ r.mRecentCallingPackage
+ "; intent:" + r.intent.getIntent()
+ "] affected while-in-use permission:"
+ AppOpsManager.opToPublicName(op);
Slog.wtf(TAG, msg);
}

View File

@@ -75,7 +75,6 @@ import android.app.ActivityManager;
import android.app.ApplicationExitInfo;
import android.app.usage.UsageEvents;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledAfter;
import android.content.Context;
import android.content.pm.ServiceInfo;
@@ -149,12 +148,13 @@ public final class OomAdjuster {
* capabilities.
*/
@ChangeId
//TODO: change to @EnabledAfter when enforcing the feature.
@Disabled
@EnabledAfter(targetSdkVersion=android.os.Build.VERSION_CODES.Q)
static final long CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID = 136219221L;
//TODO: remove this when development is done.
private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1 << 31;
private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_CAMERA = 1 << 30;
private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 1 << 29;
/**
* For some direct access we need to power manager.
@@ -1513,10 +1513,12 @@ public final class OomAdjuster {
if (enabled) {
capabilityFromFGS |=
(fgsType & FOREGROUND_SERVICE_TYPE_CAMERA)
!= 0 ? PROCESS_CAPABILITY_FOREGROUND_CAMERA : 0;
!= 0 ? PROCESS_CAPABILITY_FOREGROUND_CAMERA
: TEMP_PROCESS_CAPABILITY_FOREGROUND_CAMERA;
capabilityFromFGS |=
(fgsType & FOREGROUND_SERVICE_TYPE_MICROPHONE)
!= 0 ? PROCESS_CAPABILITY_FOREGROUND_MICROPHONE : 0;
!= 0 ? PROCESS_CAPABILITY_FOREGROUND_MICROPHONE
: TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
} else {
capabilityFromFGS |= PROCESS_CAPABILITY_FOREGROUND_CAMERA
| PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;

View File

@@ -249,6 +249,11 @@ public class AppOpsService extends IAppOpsService.Stub {
//TODO: remove this when development is done.
private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1 << 31;
private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_CAMERA = 1 << 30;
private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 1 << 29;
private static final int DEBUG_FGS_ALLOW_WHILE_IN_USE = 0;
private static final int DEBUG_FGS_ENFORCE_TYPE = 1;
final Context mContext;
final AtomicFile mFile;
@@ -551,7 +556,7 @@ public class AppOpsService extends IAppOpsService.Stub {
// The FGS has the location capability, but due to FGS BG start
// restriction it lost the capability, use temp location capability
// to mark this case.
maybeShowWhileInUseDebugToast(op, mode);
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ALLOW_WHILE_IN_USE);
return MODE_IGNORED;
} else {
return MODE_IGNORED;
@@ -559,15 +564,25 @@ public class AppOpsService extends IAppOpsService.Stub {
case OP_CAMERA:
if ((capability & PROCESS_CAPABILITY_FOREGROUND_CAMERA) != 0) {
return MODE_ALLOWED;
} else if ((capability & TEMP_PROCESS_CAPABILITY_FOREGROUND_CAMERA)
!= 0) {
// CHANGE TO MODE_IGNORED when enforce this feature.
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ENFORCE_TYPE);
return MODE_ALLOWED;
} else {
maybeShowWhileInUseDebugToast(op, mode);
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ALLOW_WHILE_IN_USE);
return MODE_IGNORED;
}
case OP_RECORD_AUDIO:
if ((capability & PROCESS_CAPABILITY_FOREGROUND_MICROPHONE) != 0) {
return MODE_ALLOWED;
} else if ((capability & TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE)
!= 0) {
// CHANGE TO MODE_IGNORED when enforce this feature.
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ENFORCE_TYPE);
return MODE_ALLOWED;
} else {
maybeShowWhileInUseDebugToast(op, mode);
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ALLOW_WHILE_IN_USE);
return MODE_IGNORED;
}
default:
@@ -582,15 +597,24 @@ public class AppOpsService extends IAppOpsService.Stub {
case OP_CAMERA:
if ((capability & PROCESS_CAPABILITY_FOREGROUND_CAMERA) != 0) {
return MODE_ALLOWED;
} else if ((capability & TEMP_PROCESS_CAPABILITY_FOREGROUND_CAMERA) != 0) {
// CHANGE TO MODE_IGNORED when enforce this feature.
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ENFORCE_TYPE);
return MODE_ALLOWED;
} else {
maybeShowWhileInUseDebugToast(op, mode);
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ALLOW_WHILE_IN_USE);
return MODE_IGNORED;
}
case OP_RECORD_AUDIO:
if ((capability & PROCESS_CAPABILITY_FOREGROUND_MICROPHONE) != 0) {
return MODE_ALLOWED;
} else if ((capability & TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE)
!= 0) {
// CHANGE TO MODE_IGNORED when enforce this feature.
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ENFORCE_TYPE);
return MODE_ALLOWED;
} else {
maybeShowWhileInUseDebugToast(op, mode);
maybeShowWhileInUseDebugToast(op, DEBUG_FGS_ALLOW_WHILE_IN_USE);
return MODE_IGNORED;
}
default: