Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 341b223f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "FGS BG start restriction permissive mode."

parents 8af7bb81 0620a333
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
package com.android.server.am;

import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_CAMERA;
import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL_IMPLICIT;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_CAMERA;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE;
@@ -36,9 +36,7 @@ import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ActivityManager.PROCESS_STATE_SERVICE;
import static android.app.ActivityManager.PROCESS_STATE_TOP;
import static android.app.ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
import static android.os.Process.SCHED_OTHER;
import static android.os.Process.THREAD_GROUP_BACKGROUND;
import static android.os.Process.THREAD_GROUP_DEFAULT;
@@ -78,7 +76,6 @@ import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledAfter;
import android.content.Context;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.Debug;
import android.os.Handler;
import android.os.IBinder;
@@ -151,6 +148,9 @@ public final class OomAdjuster {
    @Disabled
    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;

    /**
     * For some direct access we need to power manager.
     */
@@ -1477,14 +1477,25 @@ public final class OomAdjuster {
                }
            }

            if (s.isForeground && s.mAllowWhileInUsePermissionInFgs) {
            if (s.isForeground) {
                final int fgsType = s.foregroundServiceType;
                if (s.mAllowWhileInUsePermissionInFgs) {
                    capabilityFromFGS |=
                            (fgsType & FOREGROUND_SERVICE_TYPE_LOCATION)
                                    != 0 ? PROCESS_CAPABILITY_FOREGROUND_LOCATION : 0;
                } else {
                    //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.
                    //TODO: remove this block when development is done.
                    capabilityFromFGS |=
                            (fgsType & FOREGROUND_SERVICE_TYPE_LOCATION)
                                    != 0 ? TEMP_PROCESS_CAPABILITY_FOREGROUND_LOCATION : 0;
                }
                if (s.mAllowWhileInUsePermissionInFgs) {
                    capabilityFromFGS |= PROCESS_CAPABILITY_FOREGROUND_CAMERA
                            | PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
                }
            }

            ArrayMap<IBinder, ArrayList<ConnectionRecord>> serviceConnections = s.getConnections();
            for (int conni = serviceConnections.size() - 1;
+12 −2
Original line number Diff line number Diff line
@@ -213,6 +213,9 @@ public class AppOpsService extends IAppOpsService.Stub {
    private static final int MAX_UNFORWARED_OPS = 10;
    private static final int MAX_UNUSED_POOLED_OBJECTS = 3;

    //TODO: remove this when development is done.
    private static final int TEMP_PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1 << 31;

    Context mContext;
    final AtomicFile mFile;
    final Handler mHandler;
@@ -480,8 +483,15 @@ public class AppOpsService extends IAppOpsService.Stub {
                        case AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION:
                            if ((capability & PROCESS_CAPABILITY_FOREGROUND_LOCATION) != 0) {
                                return AppOpsManager.MODE_ALLOWED;
                            } else {
                            } else if ((capability
                                    & TEMP_PROCESS_CAPABILITY_FOREGROUND_LOCATION) != 0) {
                                // 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.
                                // TODO change to MODE_IGNORED when enforcing the feature.
                                maybeShowWhileInUseDebugToast(op, mode);
                                return AppOpsManager.MODE_ALLOWED;
                            } else {
                                return AppOpsManager.MODE_IGNORED;
                            }
                        case OP_CAMERA:
@@ -586,7 +596,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                return;
            }
            final long now = System.currentTimeMillis();
            if (lastTimeShowDebugToast == 0 ||  now - lastTimeShowDebugToast > 600000) {
            if (lastTimeShowDebugToast == 0 ||  now - lastTimeShowDebugToast > 3600000) {
                lastTimeShowDebugToast = now;
                mHandler.sendMessage(PooledLambda.obtainMessage(
                        ActivityManagerInternal::showWhileInUseDebugToast,