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

Commit 879024a0 authored by Hall Liu's avatar Hall Liu
Browse files

Change ServiceState and TelephonyRegistry logging

When an app bypasses a location access check due to its target SDK for
queries to ServiceState or when we're pushing out info through
TelephonyRegistry, log it as info instead of error to avoid spamming the
logs too much.

Fixes: 130668054
Test: manual
Change-Id: Ia490f2de2f0b5d326e5290e166e6f97b25e6e187
parent 111ad6a1
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -2300,6 +2300,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                        .setCallingPid(r.callerPid)
                        .setCallingPid(r.callerPid)
                        .setCallingUid(r.callerUid)
                        .setCallingUid(r.callerUid)
                        .setMethod("TelephonyRegistry push")
                        .setMethod("TelephonyRegistry push")
                        .setLogAsInfo(true) // we don't need to log an error every time we push
                        .setMinSdkVersionForFine(minSdk)
                        .setMinSdkVersionForFine(minSdk)
                        .build();
                        .build();


@@ -2317,6 +2318,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                        .setCallingPid(r.callerPid)
                        .setCallingPid(r.callerPid)
                        .setCallingUid(r.callerUid)
                        .setCallingUid(r.callerUid)
                        .setMethod("TelephonyRegistry push")
                        .setMethod("TelephonyRegistry push")
                        .setLogAsInfo(true) // we don't need to log an error every time we push
                        .setMinSdkVersionForCoarse(minSdk)
                        .setMinSdkVersionForCoarse(minSdk)
                        .build();
                        .build();


+22 −5
Original line number Original line Diff line number Diff line
@@ -63,15 +63,18 @@ public final class LocationAccessPolicy {
        public final int callingPid;
        public final int callingPid;
        public final int minSdkVersionForCoarse;
        public final int minSdkVersionForCoarse;
        public final int minSdkVersionForFine;
        public final int minSdkVersionForFine;
        public final boolean logAsInfo;
        public final String method;
        public final String method;


        private LocationPermissionQuery(String callingPackage, int callingUid, int callingPid,
        private LocationPermissionQuery(String callingPackage, int callingUid, int callingPid,
                int minSdkVersionForCoarse, int minSdkVersionForFine, String method) {
                int minSdkVersionForCoarse, int minSdkVersionForFine, boolean logAsInfo,
                String method) {
            this.callingPackage = callingPackage;
            this.callingPackage = callingPackage;
            this.callingUid = callingUid;
            this.callingUid = callingUid;
            this.callingPid = callingPid;
            this.callingPid = callingPid;
            this.minSdkVersionForCoarse = minSdkVersionForCoarse;
            this.minSdkVersionForCoarse = minSdkVersionForCoarse;
            this.minSdkVersionForFine = minSdkVersionForFine;
            this.minSdkVersionForFine = minSdkVersionForFine;
            this.logAsInfo = logAsInfo;
            this.method = method;
            this.method = method;
        }
        }


@@ -81,6 +84,7 @@ public final class LocationAccessPolicy {
            private int mCallingPid;
            private int mCallingPid;
            private int mMinSdkVersionForCoarse = Integer.MAX_VALUE;
            private int mMinSdkVersionForCoarse = Integer.MAX_VALUE;
            private int mMinSdkVersionForFine = Integer.MAX_VALUE;
            private int mMinSdkVersionForFine = Integer.MAX_VALUE;
            private boolean mLogAsInfo = false;
            private String mMethod;
            private String mMethod;


            /**
            /**
@@ -135,14 +139,27 @@ public final class LocationAccessPolicy {
                return this;
                return this;
            }
            }


            /**
             * If called with {@code true}, log messages will only be printed at the info level.
             */
            public Builder setLogAsInfo(boolean logAsInfo) {
                mLogAsInfo = logAsInfo;
                return this;
            }

            public LocationPermissionQuery build() {
            public LocationPermissionQuery build() {
                return new LocationPermissionQuery(mCallingPackage, mCallingUid,
                return new LocationPermissionQuery(mCallingPackage, mCallingUid,
                        mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine, mMethod);
                        mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine,
                        mLogAsInfo, mMethod);
            }
            }
        }
        }
    }
    }


    private static void logError(Context context, String errorMsg) {
    private static void logError(Context context, LocationPermissionQuery query, String errorMsg) {
        if (query.logAsInfo) {
            Log.i(TAG, errorMsg);
            return;
        }
        Log.e(TAG, errorMsg);
        Log.e(TAG, errorMsg);
        try {
        try {
            if (Build.IS_DEBUGGABLE) {
            if (Build.IS_DEBUGGABLE) {
@@ -201,13 +218,13 @@ public final class LocationAccessPolicy {
                    + " because we're not enforcing API " + minSdkVersion + " yet."
                    + " because we're not enforcing API " + minSdkVersion + " yet."
                    + " Please fix this app because it will break in the future. Called from "
                    + " Please fix this app because it will break in the future. Called from "
                    + query.method;
                    + query.method;
            logError(context, errorMsg);
            logError(context, query, errorMsg);
            return null;
            return null;
        } else if (!isAppAtLeastSdkVersion(context, query.callingPackage, minSdkVersion)) {
        } else if (!isAppAtLeastSdkVersion(context, query.callingPackage, minSdkVersion)) {
            String errorMsg = "Allowing " + query.callingPackage + " " + locationTypeForLog
            String errorMsg = "Allowing " + query.callingPackage + " " + locationTypeForLog
                    + " because it doesn't target API " + minSdkVersion + " yet."
                    + " because it doesn't target API " + minSdkVersion + " yet."
                    + " Please fix this app. Called from " + query.method;
                    + " Please fix this app. Called from " + query.method;
            logError(context, errorMsg);
            logError(context, query, errorMsg);
            return null;
            return null;
        } else {
        } else {
            // If we're not allowing it due to the above two conditions, this means that the app
            // If we're not allowing it due to the above two conditions, this means that the app