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

Commit cdc4a55c authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge changes from topic "networklocationFeatureId"

* changes:
  Pipe through featureId for network location checks
  Support feature context in TelephonyManager
parents 46c9f28c 95a41b85
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
@@ -927,6 +928,11 @@ public class ContextWrapper extends Context {
        return mBase.createDisplayContext(display);
    }

    @Override
    public @NonNull Context createFeatureContext(@Nullable String featureId) {
        return mBase.createFeatureContext(featureId);
    }

    @Override
    public boolean isRestricted() {
        return mBase.isRestricted();
+19 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.telephony;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.AppOpsManager;
@@ -59,6 +60,7 @@ public final class LocationAccessPolicy {

    public static class LocationPermissionQuery {
        public final String callingPackage;
        public final String callingFeatureId;
        public final int callingUid;
        public final int callingPid;
        public final int minSdkVersionForCoarse;
@@ -66,10 +68,11 @@ public final class LocationAccessPolicy {
        public final boolean logAsInfo;
        public final String method;

        private LocationPermissionQuery(String callingPackage, int callingUid, int callingPid,
                int minSdkVersionForCoarse, int minSdkVersionForFine, boolean logAsInfo,
                String method) {
        private LocationPermissionQuery(String callingPackage, @Nullable String callingFeatureId,
                int callingUid, int callingPid, int minSdkVersionForCoarse,
                int minSdkVersionForFine, boolean logAsInfo, String method) {
            this.callingPackage = callingPackage;
            this.callingFeatureId = callingFeatureId;
            this.callingUid = callingUid;
            this.callingPid = callingPid;
            this.minSdkVersionForCoarse = minSdkVersionForCoarse;
@@ -80,6 +83,7 @@ public final class LocationAccessPolicy {

        public static class Builder {
            private String mCallingPackage;
            private String mCallingFeatureId;
            private int mCallingUid;
            private int mCallingPid;
            private int mMinSdkVersionForCoarse = Integer.MAX_VALUE;
@@ -95,6 +99,14 @@ public final class LocationAccessPolicy {
                return this;
            }

            /**
             * Mandatory parameter, used for performing permission checks.
             */
            public Builder setCallingFeatureId(@Nullable String callingFeatureId) {
                mCallingFeatureId = callingFeatureId;
                return this;
            }

            /**
             * Mandatory parameter, used for performing permission checks.
             */
@@ -148,8 +160,8 @@ public final class LocationAccessPolicy {
            }

            public LocationPermissionQuery build() {
                return new LocationPermissionQuery(mCallingPackage, mCallingUid,
                        mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine,
                return new LocationPermissionQuery(mCallingPackage, mCallingFeatureId,
                        mCallingUid, mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine,
                        mLogAsInfo, mMethod);
            }
        }
@@ -195,7 +207,7 @@ public final class LocationAccessPolicy {
            // Only check the app op if the app has the permission.
            int appOpMode = context.getSystemService(AppOpsManager.class)
                    .noteOpNoThrow(AppOpsManager.permissionToOpCode(permissionToCheck),
                            query.callingUid, query.callingPackage);
                            query.callingUid, query.callingPackage, query.callingFeatureId, null);
            if (appOpMode == AppOpsManager.MODE_ALLOWED) {
                // If the app did everything right, return without logging.
                return LocationPermissionResult.ALLOWED;
+28 −10
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
@@ -325,7 +326,11 @@ public class TelephonyManager {
        mSubId = subId;
        Context appContext = context.getApplicationContext();
        if (appContext != null) {
            if (Objects.equals(context.getFeatureId(), appContext.getFeatureId())) {
                mContext = appContext;
            } else {
                mContext = appContext.createFeatureContext(context.getFeatureId());
            }
        } else {
            mContext = context;
        }
@@ -360,6 +365,16 @@ public class TelephonyManager {
        return ActivityThread.currentOpPackageName();
    }

    private String getFeatureId() {
        // For legacy reasons the TelephonyManager has API for getting
        // a static instance with no context set preventing us from
        // getting the feature Id.
        if (mContext != null) {
            return mContext.getFeatureId();
        }
        return null;
    }

    private boolean isSystemProcess() {
        return Process.myUid() == Process.SYSTEM_UID;
    }
@@ -2024,7 +2039,8 @@ public class TelephonyManager {
                return null;
            }

            Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName());
            Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName(),
                    mContext.getFeatureId());
            if (bundle == null || bundle.isEmpty()) {
                Rlog.d(TAG, "getCellLocation returning null because CellLocation is unavailable");
                return null;
@@ -2112,7 +2128,8 @@ public class TelephonyManager {
            ITelephony telephony = getITelephony();
            if (telephony == null)
                return null;
            return telephony.getNeighboringCellInfo(mContext.getOpPackageName());
            return telephony.getNeighboringCellInfo(mContext.getOpPackageName(),
                    mContext.getFeatureId());
        } catch (RemoteException ex) {
            return null;
        } catch (NullPointerException ex) {
@@ -5514,8 +5531,7 @@ public class TelephonyManager {
            ITelephony telephony = getITelephony();
            if (telephony == null)
                return null;
            return telephony.getAllCellInfo(
                    getOpPackageName());
            return telephony.getAllCellInfo(getOpPackageName(), getFeatureId());
        } catch (RemoteException ex) {
        } catch (NullPointerException ex) {
        }
@@ -5607,7 +5623,7 @@ public class TelephonyManager {
                                            errorCode,
                                            createThrowableByClassName(exceptionName, message))));
                        }
                    }, getOpPackageName());
                    }, getOpPackageName(), getFeatureId());
        } catch (RemoteException ex) {
        }
    }
@@ -5649,7 +5665,7 @@ public class TelephonyManager {
                                            errorCode,
                                            createThrowableByClassName(exceptionName, message))));
                        }
                    }, getOpPackageName(), workSource);
                    }, getOpPackageName(), getFeatureId(), workSource);
        } catch (RemoteException ex) {
        }
    }
@@ -7473,7 +7489,8 @@ public class TelephonyManager {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return telephony.getCellNetworkScanResults(getSubId(), getOpPackageName());
                return telephony.getCellNetworkScanResults(getSubId(), getOpPackageName(),
                        getFeatureId());
            }
        } catch (RemoteException ex) {
            Rlog.e(TAG, "getAvailableNetworks RemoteException", ex);
@@ -7528,7 +7545,7 @@ public class TelephonyManager {
            }
        }
        return mTelephonyScanManager.requestNetworkScan(getSubId(), request, executor, callback,
                getOpPackageName());
                getOpPackageName(), getFeatureId());
    }

    /**
@@ -9659,7 +9676,8 @@ public class TelephonyManager {
        try {
            ITelephony service = getITelephony();
            if (service != null) {
                return service.getServiceStateForSubscriber(subId, getOpPackageName());
                return service.getServiceStateForSubscriber(subId, getOpPackageName(),
                        getFeatureId());
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e);
+6 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.telephony;

import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.Nullable;
import android.content.Context;
import android.os.Binder;
import android.os.Bundle;
@@ -195,18 +196,21 @@ public final class TelephonyScanManager {
     *
     * @param request Contains all the RAT with bands/channels that need to be scanned.
     * @param callback Returns network scan results or errors.
     * @param callingPackage The package name of the caller
     * @param callingFeatureId The feature id inside of the calling package
     * @return A NetworkScan obj which contains a callback which can stop the scan.
     * @hide
     */
    public NetworkScan requestNetworkScan(int subId,
            NetworkScanRequest request, Executor executor, NetworkScanCallback callback,
            String callingPackage) {
            String callingPackage, @Nullable String callingFeatureId) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                synchronized (mScanInfo) {
                    int scanId = telephony.requestNetworkScan(
                            subId, request, mMessenger, new Binder(), callingPackage);
                            subId, request, mMessenger, new Binder(), callingPackage,
                            callingFeatureId);
                    if (scanId == INVALID_SCAN_ID) {
                        Rlog.e(TAG, "Failed to initiate network scan");
                        return null;
+16 −9
Original line number Diff line number Diff line
@@ -295,7 +295,7 @@ interface ITelephony {
     */
    boolean isDataConnectivityPossible(int subId);

    Bundle getCellLocation(String callingPkg);
    Bundle getCellLocation(String callingPkg, String callingFeatureId);

    /**
     * Returns the ISO country code equivalent of the current registered
@@ -307,7 +307,7 @@ interface ITelephony {
    /**
     * Returns the neighboring cell information of the device.
     */
    List<NeighboringCellInfo> getNeighboringCellInfo(String callingPkg);
    List<NeighboringCellInfo> getNeighboringCellInfo(String callingPkg, String callingFeatureId);

    @UnsupportedAppUsage
    int getCallState();
@@ -556,13 +556,14 @@ interface ITelephony {
    /**
     * Returns all observed cell information of the device.
     */
    List<CellInfo> getAllCellInfo(String callingPkg);
    List<CellInfo> getAllCellInfo(String callingPkg, String callingFeatureId);

    /**
     * Request a cell information update for the specified subscription,
     * reported via the CellInfoCallback.
     */
    void requestCellInfoUpdate(int subId, in ICellInfoCallback cb, String callingPkg);
    void requestCellInfoUpdate(int subId, in ICellInfoCallback cb, String callingPkg,
            String callingFeatureId);

    /**
     * Request a cell information update for the specified subscription,
@@ -570,8 +571,8 @@ interface ITelephony {
     *
     * @param workSource the requestor to whom the power consumption for this should be attributed.
     */
    void requestCellInfoUpdateWithWorkSource(
            int subId, in ICellInfoCallback cb, in String callingPkg, in WorkSource ws);
    void requestCellInfoUpdateWithWorkSource(int subId, in ICellInfoCallback cb,
            in String callingPkg, String callingFeatureId, in WorkSource ws);

    /**
     * Sets minimum time in milli-seconds between onCellInfoChanged
@@ -882,9 +883,12 @@ interface ITelephony {
     * Perform a radio scan and return the list of avialble networks.
     *
     * @param subId the id of the subscription.
     * @param callingPackage the calling package
     * @param callingFeatureId The feature in the package
     * @return CellNetworkScanResult containing status of scan and networks.
     */
    CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage);
    CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
            String callingFeatureId);

    /**
     * Perform a radio network scan and return the id of this scan.
@@ -894,10 +898,11 @@ interface ITelephony {
     * @param messenger Callback messages will be sent using this messenger.
     * @param binder the binder object instantiated in TelephonyManager.
     * @param callingPackage the calling package
     * @param callingFeatureId The feature in the package
     * @return An id for this scan.
     */
    int requestNetworkScan(int subId, in NetworkScanRequest request, in Messenger messenger,
            in IBinder binder, in String callingPackage);
            in IBinder binder, in String callingPackage, String callingFeatureId);

    /**
     * Stop an existing radio network scan.
@@ -1346,9 +1351,11 @@ interface ITelephony {
     * Get the service state on specified subscription
     * @param subId Subscription id
     * @param callingPackage The package making the call
     * @param callingFeatureId The feature in the package
     * @return Service state on specified subscription.
     */
    ServiceState getServiceStateForSubscriber(int subId, String callingPackage);
    ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
            String callingFeatureId);

    /**
     * Returns the URI for the per-account voicemail ringtone set in Phone settings.