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

Commit 9bb03ffe authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Allow renounce location permission" am: 373b687d

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1887652

Change-Id: I66e12d38d50dcf48685c86468462e3b9605c360b
parents fea850f7 373b687d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -42841,6 +42841,7 @@ package android.telephony {
    method public int getPhoneType();
    method @RequiresPermission(anyOf={"android.permission.READ_PRIVILEGED_PHONE_STATE", android.Manifest.permission.READ_PHONE_STATE}) public int getPreferredOpportunisticDataSubscription();
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_COARSE_LOCATION}) public android.telephony.ServiceState getServiceState();
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.ACCESS_COARSE_LOCATION}) public android.telephony.ServiceState getServiceState(boolean, boolean);
    method @Nullable public android.telephony.SignalStrength getSignalStrength();
    method public int getSimCarrierId();
    method @Nullable public CharSequence getSimCarrierIdName();
@@ -42893,8 +42894,10 @@ package android.telephony {
    method public boolean isWorldPhone();
    method @Deprecated public void listen(android.telephony.PhoneStateListener, int);
    method public void registerTelephonyCallback(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyCallback);
    method public void registerTelephonyCallback(boolean, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyCallback);
    method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public void requestCellInfoUpdate(@NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyManager.CellInfoCallback);
    method @RequiresPermission(allOf={android.Manifest.permission.MODIFY_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public android.telephony.NetworkScan requestNetworkScan(android.telephony.NetworkScanRequest, java.util.concurrent.Executor, android.telephony.TelephonyScanManager.NetworkScanCallback);
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.MODIFY_PHONE_STATE, android.Manifest.permission.ACCESS_FINE_LOCATION}) public android.telephony.NetworkScan requestNetworkScan(boolean, @NonNull android.telephony.NetworkScanRequest, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.TelephonyScanManager.NetworkScanCallback);
    method public void sendDialerSpecialCode(String);
    method public String sendEnvelopeWithStatus(String);
    method @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void sendUssdRequest(String, android.telephony.TelephonyManager.UssdResponseCallback, android.os.Handler);
+13 −7
Original line number Diff line number Diff line
@@ -247,8 +247,8 @@ public class TelephonyRegistryManager {
            } else if (listener.mSubId != null) {
                subId = listener.mSubId;
            }
            sRegistry.listenWithEventList(
                    subId, pkg, featureId, listener.callback, eventsList, notifyNow);
            sRegistry.listenWithEventList(false, false, subId, pkg, featureId,
                    listener.callback, eventsList, notifyNow);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -263,11 +263,13 @@ public class TelephonyRegistryManager {
     * @param events List events
     * @param notifyNow Whether to notify instantly
     */
    private void listenFromCallback(int subId, @NonNull String pkg, @NonNull String featureId,
    private void listenFromCallback(boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess, int subId,
            @NonNull String pkg, @NonNull String featureId,
            @NonNull TelephonyCallback telephonyCallback, @NonNull int[] events,
            boolean notifyNow) {
        try {
            sRegistry.listenWithEventList(
            sRegistry.listenWithEventList(renounceFineLocationAccess, renounceCoarseLocationAccess,
                    subId, pkg, featureId, telephonyCallback.callback, events, notifyNow);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -1161,14 +1163,17 @@ public class TelephonyRegistryManager {
     *
     * @param callback The {@link TelephonyCallback} object to register.
     */
    public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor,
    public void registerTelephonyCallback(boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess,
            @NonNull @CallbackExecutor Executor executor,
            int subId, String pkgName, String attributionTag, @NonNull TelephonyCallback callback,
            boolean notifyNow) {
        if (callback == null) {
            throw new IllegalStateException("telephony service is null.");
        }
        callback.init(executor);
        listenFromCallback(subId, pkgName, attributionTag, callback,
        listenFromCallback(renounceFineLocationAccess, renounceCoarseLocationAccess, subId,
                pkgName, attributionTag, callback,
                getEventsFromCallback(callback).stream().mapToInt(i -> i).toArray(), notifyNow);
    }

@@ -1179,6 +1184,7 @@ public class TelephonyRegistryManager {
     */
    public void unregisterTelephonyCallback(int subId, String pkgName, String attributionTag,
            @NonNull TelephonyCallback callback, boolean notifyNow) {
        listenFromCallback(subId, pkgName, attributionTag, callback, new int[0], notifyNow);
        listenFromCallback(false, false, subId,
                pkgName, attributionTag, callback, new int[0], notifyNow);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ interface ITelephonyRegistry {
    void removeOnSubscriptionsChangedListener(String pkg,
            IOnSubscriptionsChangedListener callback);

    void listenWithEventList(in int subId, String pkg, String featureId,
    void listenWithEventList(in boolean renounceFineLocationAccess,
            in boolean renounceCoarseLocationAccess, in int subId, String pkg, String featureId,
            IPhoneStateListener callback, in int[] events, boolean notifyNow);
    @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
    void notifyCallStateForAllSubs(int state, String incomingNumber);
+24 −3
Original line number Diff line number Diff line
@@ -152,6 +152,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

        int callerUid;
        int callerPid;
        boolean renounceFineLocationAccess;
        boolean renounceCoarseLocationAccess;

        Set<Integer> eventList;

@@ -995,14 +997,25 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
    }

    @Override
    public void listenWithEventList(int subId, String callingPackage, String callingFeatureId,
            IPhoneStateListener callback, int[] events, boolean notifyNow) {
    public void listenWithEventList(boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess, int subId, String callingPackage,
            String callingFeatureId, IPhoneStateListener callback,
            int[] events, boolean notifyNow) {
        Set<Integer> eventList = Arrays.stream(events).boxed().collect(Collectors.toSet());
        listen(callingPackage, callingFeatureId, callback, eventList, notifyNow, subId);
        listen(renounceFineLocationAccess, renounceFineLocationAccess, callingPackage,
                callingFeatureId, callback, eventList, notifyNow, subId);
    }

    private void listen(String callingPackage, @Nullable String callingFeatureId,
            IPhoneStateListener callback, Set<Integer> events, boolean notifyNow, int subId) {
        listen(false, false, callingPackage,
                callingFeatureId, callback, events, notifyNow, subId);
    }

    private void listen(boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess, String callingPackage,
            @Nullable String callingFeatureId, IPhoneStateListener callback,
            Set<Integer> events, boolean notifyNow, int subId) {
        int callerUserId = UserHandle.getCallingUserId();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        String str = "listen: E pkg=" + pii(callingPackage) + " uid=" + Binder.getCallingUid()
@@ -1047,6 +1060,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            r.callback = callback;
            r.callingPackage = callingPackage;
            r.callingFeatureId = callingFeatureId;
            r.renounceCoarseLocationAccess = renounceCoarseLocationAccess;
            r.renounceFineLocationAccess = renounceFineLocationAccess;
            r.callerUid = Binder.getCallingUid();
            r.callerPid = Binder.getCallingPid();
            // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
@@ -3199,6 +3214,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
     * If you don't need app compat logic, use {@link #checkFineLocationAccess(Record)}.
     */
    private boolean checkFineLocationAccess(Record r, int minSdk) {
        if (r.renounceFineLocationAccess) {
            return false;
        }
        LocationAccessPolicy.LocationPermissionQuery query =
                new LocationAccessPolicy.LocationPermissionQuery.Builder()
                        .setCallingPackage(r.callingPackage)
@@ -3225,6 +3243,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
     * If you don't need app compat logic, use {@link #checkCoarseLocationAccess(Record)}.
     */
    private boolean checkCoarseLocationAccess(Record r, int minSdk) {
        if (r.renounceCoarseLocationAccess) {
            return false;
        }
        LocationAccessPolicy.LocationPermissionQuery query =
                new LocationAccessPolicy.LocationPermissionQuery.Builder()
                        .setCallingPackage(r.callingPackage)
+150 −10
Original line number Diff line number Diff line
@@ -8321,12 +8321,58 @@ public class TelephonyManager {
    public NetworkScan requestNetworkScan(
            NetworkScanRequest request, Executor executor,
            TelephonyScanManager.NetworkScanCallback callback) {
        synchronized (this) {
        return requestNetworkScan(false, request, executor, callback);
    }
    /**
     * Request a network scan.
     *
     * This method is asynchronous, so the network scan results will be returned by callback.
     * The returned NetworkScan will contain a callback method which can be used to stop the scan.
     *
     * <p>Requires Permission:
     * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
     * app has carrier privileges (see {@link #hasCarrierPrivileges})
     * and {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
     *
     * If the system-wide location switch is off, apps may still call this API, with the
     * following constraints:
     * <ol>
     *     <li>The app must hold the {@code android.permission.NETWORK_SCAN} permission.</li>
     *     <li>The app must not supply any specific bands or channels to scan.</li>
     *     <li>The app must only specify MCC/MNC pairs that are
     *     associated to a SIM in the device.</li>
     *     <li>Returned results will have no meaningful info other than signal strength
     *     and MCC/MNC info.</li>
     * </ol>
     *
     * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
     * location related information which will be sent if the caller already possess
     * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permission
     * @param request Contains all the RAT with bands/channels that need to be scanned.
     * @param executor The executor through which the callback should be invoked. Since the scan
     *        request may trigger multiple callbacks and they must be invoked in the same order as
     *        they are received by the platform, the user should provide an executor which executes
     *        tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR.
     * @param callback Returns network scan results or errors.
     * @return A NetworkScan obj which contains a callback which can be used to stop the scan.
     */
    @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
    @RequiresPermission(allOf = {
            android.Manifest.permission.MODIFY_PHONE_STATE,
            Manifest.permission.ACCESS_FINE_LOCATION
    })
    public @Nullable NetworkScan requestNetworkScan(
            boolean renounceFineLocationAccess, @NonNull NetworkScanRequest request,
            @NonNull Executor executor,
            @NonNull TelephonyScanManager.NetworkScanCallback callback) {
        synchronized (sCacheLock) {
            if (mTelephonyScanManager == null) {
                mTelephonyScanManager = new TelephonyScanManager();
            }
        }
        return mTelephonyScanManager.requestNetworkScan(getSubId(), request, executor, callback,
        return mTelephonyScanManager.requestNetworkScan(getSubId(), renounceFineLocationAccess,
                request, executor, callback,
                getOpPackageName(), getAttributionTag());
    }
@@ -11387,7 +11433,6 @@ public class TelephonyManager {
     * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges})
     * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
     *
     * May return {@code null} when the subscription is inactive or when there was an error
     * communicating with the phone process.
     */
@@ -11397,7 +11442,39 @@ public class TelephonyManager {
            Manifest.permission.ACCESS_COARSE_LOCATION
    })
    public @Nullable ServiceState getServiceState() {
        return getServiceStateForSubscriber(getSubId());
        return getServiceState(false, false);
    }
    /**
     * Returns the current {@link ServiceState} information.
     *
     * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
     * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}
     *
     * If you want continuous updates of service state info, register a {@link PhoneStateListener}
     * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event.
     *
     * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges})
     * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
     * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
     * location related information which will be sent if the caller already possess
     * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permission
     * @param renounceCoarseLocationAccess Set this to true if the caller would not like to
     * receive location related information which will be sent if the caller already possess
     * {@link Manifest.permission#ACCESS_COARSE_LOCATION} and do not renounce the permissions.
     * May return {@code null} when the subscription is inactive or when there was an error
     * communicating with the phone process.
     */
    @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
    @RequiresPermission(allOf = {
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.ACCESS_COARSE_LOCATION
    })
    public @Nullable ServiceState getServiceState(boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess) {
        return getServiceStateForSubscriber(getSubId(), renounceFineLocationAccess,
                renounceCoarseLocationAccess);
    }
    /**
@@ -11406,15 +11483,22 @@ public class TelephonyManager {
     *
     * May return {@code null} when the subscription is inactive or when there was an error
     * communicating with the phone process.
     * @hide
     * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
     * location related information which will be sent if the caller already possess
     * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permission
     * @param renounceCoarseLocationAccess Set this to true if the caller would not like to
     * receive location related information which will be sent if the caller already possess
     * {@link Manifest.permission#ACCESS_COARSE_LOCATION} and do not renounce the permissions.
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
    public ServiceState getServiceStateForSubscriber(int subId) {
    private ServiceState getServiceStateForSubscriber(int subId,
            boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess) {
        try {
            ITelephony service = getITelephony();
            if (service != null) {
                return service.getServiceStateForSubscriber(subId, getOpPackageName(),
                        getAttributionTag());
                return service.getServiceStateForSubscriber(subId, renounceFineLocationAccess,
                        renounceCoarseLocationAccess,
                        getOpPackageName(), getAttributionTag());
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e);
@@ -11426,6 +11510,19 @@ public class TelephonyManager {
        return null;
    }
    /**
     * Returns the service state information on specified subscription. Callers require
     * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information.
     *
     * May return {@code null} when the subscription is inactive or when there was an error
     * communicating with the phone process.
     * @hide
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
    public ServiceState getServiceStateForSubscriber(int subId) {
        return getServiceStateForSubscriber(getSubId(), false, false);
    }
    /**
     * Returns the URI for the per-account voicemail ringtone set in Phone settings.
     *
@@ -15274,7 +15371,49 @@ public class TelephonyManager {
     */
    public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor,
            @NonNull TelephonyCallback callback) {
        registerTelephonyCallback(false, false, executor, callback);
    }
    /**
     * Registers a callback object to receive notification of changes in specified telephony states.
     * <p>
     * To register a callback, pass a {@link TelephonyCallback} which implements
     * interfaces of events. For example,
     * FakeServiceStateCallback extends {@link TelephonyCallback} implements
     * {@link TelephonyCallback.ServiceStateListener}.
     *
     * At registration, and when a specified telephony state changes, the telephony manager invokes
     * the appropriate callback method on the callback object and passes the current (updated)
     * values.
     * <p>
     *
     * If this TelephonyManager object has been created with {@link #createForSubscriptionId},
     * applies to the given subId. Otherwise, applies to
     * {@link SubscriptionManager#getDefaultSubscriptionId()}. To register events for multiple
     * subIds, pass a separate callback object to each TelephonyManager object created with
     * {@link #createForSubscriptionId}.
     *
     * Note: if you call this method while in the middle of a binder transaction, you <b>must</b>
     * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A
     * {@link SecurityException} will be thrown otherwise.
     *
     * This API should be used sparingly -- large numbers of callbacks will cause system
     * instability. If a process has registered too many callbacks without unregistering them, it
     * may encounter an {@link IllegalStateException} when trying to register more callbacks.
     *
     * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
     * location related information which will be sent if the caller already possess
     * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permissions.
     * @param renounceCoarseLocationAccess Set this to true if the caller would not like to
     * receive location related information which will be sent if the caller already possess
     * {@link Manifest.permission#ACCESS_COARSE_LOCATION} and do not renounce the permissions.
     * @param executor The executor of where the callback will execute.
     * @param callback The {@link TelephonyCallback} object to register.
     */
    public void registerTelephonyCallback(boolean renounceFineLocationAccess,
            boolean renounceCoarseLocationAccess,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull TelephonyCallback callback) {
        if (mContext == null) {
            throw new IllegalStateException("telephony service is null.");
        }
@@ -15285,7 +15424,8 @@ public class TelephonyManager {
        mTelephonyRegistryMgr = (TelephonyRegistryManager)
                mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
        if (mTelephonyRegistryMgr != null) {
            mTelephonyRegistryMgr.registerTelephonyCallback(executor, mSubId, getOpPackageName(),
            mTelephonyRegistryMgr.registerTelephonyCallback(renounceFineLocationAccess,
                    renounceCoarseLocationAccess, executor, mSubId, getOpPackageName(),
                    getAttributionTag(), callback, getITelephony() != null);
        } else {
            throw new IllegalStateException("telephony service is null.");
Loading