Loading core/java/android/telephony/TelephonyRegistryManager.java +4 −6 Original line number Original line Diff line number Diff line Loading @@ -239,10 +239,8 @@ public class TelephonyRegistryManager { * @param events Events * @param events Events * @param notifyNow Whether to notify instantly * @param notifyNow Whether to notify instantly */ */ public void listenFromListener(int subId, @NonNull boolean renounceFineLocationAccess, public void listenFromListener(int subId, @NonNull String pkg, @NonNull String featureId, @NonNull boolean renounceCoarseLocationAccess, @NonNull String pkg, @NonNull PhoneStateListener listener, @NonNull int events, boolean notifyNow) { @NonNull String featureId, @NonNull PhoneStateListener listener, @NonNull int events, boolean notifyNow) { if (listener == null) { if (listener == null) { throw new IllegalStateException("telephony service is null."); throw new IllegalStateException("telephony service is null."); } } Loading @@ -259,8 +257,8 @@ public class TelephonyRegistryManager { } else if (listener.mSubId != null) { } else if (listener.mSubId != null) { subId = listener.mSubId; subId = listener.mSubId; } } sRegistry.listenWithEventList(renounceFineLocationAccess, renounceCoarseLocationAccess, sRegistry.listenWithEventList(false, false, subId, pkg, featureId, subId, pkg, featureId, listener.callback, eventsList, notifyNow); listener.callback, eventsList, notifyNow); } catch (RemoteException e) { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer(); } } Loading telephony/java/android/telephony/TelephonyManager.java +16 −70 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,6 @@ import android.compat.annotation.EnabledAfter; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.ContextParams; import android.content.Intent; import android.content.Intent; import android.database.Cursor; import android.database.Cursor; import android.net.ConnectivityManager; import android.net.ConnectivityManager; Loading Loading @@ -141,7 +140,6 @@ import java.util.List; import java.util.Locale; import java.util.Locale; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException; Loading Loading @@ -379,8 +377,16 @@ public class TelephonyManager { @UnsupportedAppUsage @UnsupportedAppUsage public TelephonyManager(Context context, int subId) { public TelephonyManager(Context context, int subId) { mSubId = subId; mSubId = subId; mContext = mergeAttributionAndRenouncedPermissions(context.getApplicationContext(), Context appContext = context.getApplicationContext(); context); if (appContext != null) { if (Objects.equals(context.getAttributionTag(), appContext.getAttributionTag())) { mContext = appContext; } else { mContext = appContext.createAttributionContext(context.getAttributionTag()); } } else { mContext = context; } mSubscriptionManager = SubscriptionManager.from(mContext); mSubscriptionManager = SubscriptionManager.from(mContext); } } Loading @@ -401,34 +407,6 @@ public class TelephonyManager { return sInstance; return sInstance; } } // This method takes the Application context and adds the attributionTag // and renouncedPermissions from the given context. private Context mergeAttributionAndRenouncedPermissions(Context to, Context from) { Context contextToReturn = from; if (to != null) { if (!Objects.equals(from.getAttributionTag(), to.getAttributionTag())) { contextToReturn = to.createAttributionContext(from.getAttributionTag()); } else { contextToReturn = to; } Set<String> renouncedPermissions = from.getAttributionSource().getRenouncedPermissions(); if (!renouncedPermissions.isEmpty()) { if (to.getParams() != null) { contextToReturn = contextToReturn.createContext( new ContextParams.Builder(to.getParams()) .setRenouncedPermissions(renouncedPermissions).build()); } else { contextToReturn = contextToReturn.createContext( new ContextParams.Builder() .setRenouncedPermissions(renouncedPermissions).build()); } } } return contextToReturn; } private String getOpPackageName() { private String getOpPackageName() { // For legacy reasons the TelephonyManager has API for getting // For legacy reasons the TelephonyManager has API for getting // a static instance with no context set preventing us from // a static instance with no context set preventing us from Loading Loading @@ -459,16 +437,6 @@ public class TelephonyManager { return null; return null; } } private Set<String> getRenouncedPermissions() { // For legacy reasons the TelephonyManager has API for getting // a static instance with no context set preventing us from // getting the attribution source. if (mContext != null) { return mContext.getAttributionSource().getRenouncedPermissions(); } return Collections.emptySet(); } /** /** * Post a runnable to the BackgroundThread. * Post a runnable to the BackgroundThread. * * Loading Loading @@ -6170,14 +6138,8 @@ public class TelephonyManager { (TelephonyRegistryManager) (TelephonyRegistryManager) mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); if (telephonyRegistry != null) { if (telephonyRegistry != null) { Set<String> renouncedPermissions = getRenouncedPermissions(); telephonyRegistry.listenFromListener(mSubId, getOpPackageName(), boolean renounceFineLocationAccess = renouncedPermissions getAttributionTag(), listener, events, notifyNow); .contains(Manifest.permission.ACCESS_FINE_LOCATION); boolean renounceCoarseLocationAccess = renouncedPermissions .contains(Manifest.permission.ACCESS_COARSE_LOCATION); telephonyRegistry.listenFromListener(mSubId, renounceFineLocationAccess, renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag(), listener, events, notifyNow); } else { } else { Rlog.w(TAG, "telephony registry not ready."); Rlog.w(TAG, "telephony registry not ready."); } } Loading Loading @@ -11640,10 +11602,7 @@ public class TelephonyManager { Manifest.permission.ACCESS_COARSE_LOCATION Manifest.permission.ACCESS_COARSE_LOCATION }) }) public @Nullable ServiceState getServiceState() { public @Nullable ServiceState getServiceState() { return getServiceState(getRenouncedPermissions() return getServiceState(false, false); .contains(Manifest.permission.ACCESS_FINE_LOCATION), getRenouncedPermissions() .contains(Manifest.permission.ACCESS_COARSE_LOCATION)); } } /** /** Loading @@ -11655,11 +11614,6 @@ public class TelephonyManager { * If you want continuous updates of service state info, register a {@link PhoneStateListener} * If you want continuous updates of service state info, register a {@link PhoneStateListener} * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. * * * There's another way to renounce permissions with a custom context * {@link AttributionSource.Builder#setRenouncedPermissions(Set<String>)} but only for system * apps. To avoid confusion, calling this method supersede renouncing permissions with a * custom context. * * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Loading Loading @@ -11703,7 +11657,8 @@ public class TelephonyManager { ITelephony service = getITelephony(); ITelephony service = getITelephony(); if (service != null) { if (service != null) { return service.getServiceStateForSubscriber(subId, renounceFineLocationAccess, return service.getServiceStateForSubscriber(subId, renounceFineLocationAccess, renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag()); renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag()); } } } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); Loading Loading @@ -15539,10 +15494,7 @@ public class TelephonyManager { */ */ public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor, public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor, @NonNull TelephonyCallback callback) { @NonNull TelephonyCallback callback) { registerTelephonyCallback( registerTelephonyCallback(false, false, executor, callback); getRenouncedPermissions().contains(Manifest.permission.ACCESS_FINE_LOCATION), getRenouncedPermissions().contains(Manifest.permission.ACCESS_COARSE_LOCATION), executor, callback); } } /** /** Loading Loading @@ -15572,12 +15524,6 @@ public class TelephonyManager { * instability. If a process has registered too many callbacks without unregistering them, it * instability. If a process has registered too many callbacks without unregistering them, it * may encounter an {@link IllegalStateException} when trying to register more callbacks. * may encounter an {@link IllegalStateException} when trying to register more callbacks. * * * <p> * There's another way to renounce permissions with a custom context * {@link AttributionSource.Builder#setRenouncedPermissions(Set<String>)} but only for system * apps. To avoid confusion, calling this method supersede renouncing permissions with a * custom context. * * @param renounceFineLocationAccess Set this to true if the caller would not like to receive * @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 * 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. * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permissions. Loading
core/java/android/telephony/TelephonyRegistryManager.java +4 −6 Original line number Original line Diff line number Diff line Loading @@ -239,10 +239,8 @@ public class TelephonyRegistryManager { * @param events Events * @param events Events * @param notifyNow Whether to notify instantly * @param notifyNow Whether to notify instantly */ */ public void listenFromListener(int subId, @NonNull boolean renounceFineLocationAccess, public void listenFromListener(int subId, @NonNull String pkg, @NonNull String featureId, @NonNull boolean renounceCoarseLocationAccess, @NonNull String pkg, @NonNull PhoneStateListener listener, @NonNull int events, boolean notifyNow) { @NonNull String featureId, @NonNull PhoneStateListener listener, @NonNull int events, boolean notifyNow) { if (listener == null) { if (listener == null) { throw new IllegalStateException("telephony service is null."); throw new IllegalStateException("telephony service is null."); } } Loading @@ -259,8 +257,8 @@ public class TelephonyRegistryManager { } else if (listener.mSubId != null) { } else if (listener.mSubId != null) { subId = listener.mSubId; subId = listener.mSubId; } } sRegistry.listenWithEventList(renounceFineLocationAccess, renounceCoarseLocationAccess, sRegistry.listenWithEventList(false, false, subId, pkg, featureId, subId, pkg, featureId, listener.callback, eventsList, notifyNow); listener.callback, eventsList, notifyNow); } catch (RemoteException e) { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer(); } } Loading
telephony/java/android/telephony/TelephonyManager.java +16 −70 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,6 @@ import android.compat.annotation.EnabledAfter; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.ComponentName; import android.content.Context; import android.content.Context; import android.content.ContextParams; import android.content.Intent; import android.content.Intent; import android.database.Cursor; import android.database.Cursor; import android.net.ConnectivityManager; import android.net.ConnectivityManager; Loading Loading @@ -141,7 +140,6 @@ import java.util.List; import java.util.Locale; import java.util.Locale; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException; Loading Loading @@ -379,8 +377,16 @@ public class TelephonyManager { @UnsupportedAppUsage @UnsupportedAppUsage public TelephonyManager(Context context, int subId) { public TelephonyManager(Context context, int subId) { mSubId = subId; mSubId = subId; mContext = mergeAttributionAndRenouncedPermissions(context.getApplicationContext(), Context appContext = context.getApplicationContext(); context); if (appContext != null) { if (Objects.equals(context.getAttributionTag(), appContext.getAttributionTag())) { mContext = appContext; } else { mContext = appContext.createAttributionContext(context.getAttributionTag()); } } else { mContext = context; } mSubscriptionManager = SubscriptionManager.from(mContext); mSubscriptionManager = SubscriptionManager.from(mContext); } } Loading @@ -401,34 +407,6 @@ public class TelephonyManager { return sInstance; return sInstance; } } // This method takes the Application context and adds the attributionTag // and renouncedPermissions from the given context. private Context mergeAttributionAndRenouncedPermissions(Context to, Context from) { Context contextToReturn = from; if (to != null) { if (!Objects.equals(from.getAttributionTag(), to.getAttributionTag())) { contextToReturn = to.createAttributionContext(from.getAttributionTag()); } else { contextToReturn = to; } Set<String> renouncedPermissions = from.getAttributionSource().getRenouncedPermissions(); if (!renouncedPermissions.isEmpty()) { if (to.getParams() != null) { contextToReturn = contextToReturn.createContext( new ContextParams.Builder(to.getParams()) .setRenouncedPermissions(renouncedPermissions).build()); } else { contextToReturn = contextToReturn.createContext( new ContextParams.Builder() .setRenouncedPermissions(renouncedPermissions).build()); } } } return contextToReturn; } private String getOpPackageName() { private String getOpPackageName() { // For legacy reasons the TelephonyManager has API for getting // For legacy reasons the TelephonyManager has API for getting // a static instance with no context set preventing us from // a static instance with no context set preventing us from Loading Loading @@ -459,16 +437,6 @@ public class TelephonyManager { return null; return null; } } private Set<String> getRenouncedPermissions() { // For legacy reasons the TelephonyManager has API for getting // a static instance with no context set preventing us from // getting the attribution source. if (mContext != null) { return mContext.getAttributionSource().getRenouncedPermissions(); } return Collections.emptySet(); } /** /** * Post a runnable to the BackgroundThread. * Post a runnable to the BackgroundThread. * * Loading Loading @@ -6170,14 +6138,8 @@ public class TelephonyManager { (TelephonyRegistryManager) (TelephonyRegistryManager) mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); if (telephonyRegistry != null) { if (telephonyRegistry != null) { Set<String> renouncedPermissions = getRenouncedPermissions(); telephonyRegistry.listenFromListener(mSubId, getOpPackageName(), boolean renounceFineLocationAccess = renouncedPermissions getAttributionTag(), listener, events, notifyNow); .contains(Manifest.permission.ACCESS_FINE_LOCATION); boolean renounceCoarseLocationAccess = renouncedPermissions .contains(Manifest.permission.ACCESS_COARSE_LOCATION); telephonyRegistry.listenFromListener(mSubId, renounceFineLocationAccess, renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag(), listener, events, notifyNow); } else { } else { Rlog.w(TAG, "telephony registry not ready."); Rlog.w(TAG, "telephony registry not ready."); } } Loading Loading @@ -11640,10 +11602,7 @@ public class TelephonyManager { Manifest.permission.ACCESS_COARSE_LOCATION Manifest.permission.ACCESS_COARSE_LOCATION }) }) public @Nullable ServiceState getServiceState() { public @Nullable ServiceState getServiceState() { return getServiceState(getRenouncedPermissions() return getServiceState(false, false); .contains(Manifest.permission.ACCESS_FINE_LOCATION), getRenouncedPermissions() .contains(Manifest.permission.ACCESS_COARSE_LOCATION)); } } /** /** Loading @@ -11655,11 +11614,6 @@ public class TelephonyManager { * If you want continuous updates of service state info, register a {@link PhoneStateListener} * If you want continuous updates of service state info, register a {@link PhoneStateListener} * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. * * * There's another way to renounce permissions with a custom context * {@link AttributionSource.Builder#setRenouncedPermissions(Set<String>)} but only for system * apps. To avoid confusion, calling this method supersede renouncing permissions with a * custom context. * * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. Loading Loading @@ -11703,7 +11657,8 @@ public class TelephonyManager { ITelephony service = getITelephony(); ITelephony service = getITelephony(); if (service != null) { if (service != null) { return service.getServiceStateForSubscriber(subId, renounceFineLocationAccess, return service.getServiceStateForSubscriber(subId, renounceFineLocationAccess, renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag()); renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag()); } } } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); Loading Loading @@ -15539,10 +15494,7 @@ public class TelephonyManager { */ */ public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor, public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor, @NonNull TelephonyCallback callback) { @NonNull TelephonyCallback callback) { registerTelephonyCallback( registerTelephonyCallback(false, false, executor, callback); getRenouncedPermissions().contains(Manifest.permission.ACCESS_FINE_LOCATION), getRenouncedPermissions().contains(Manifest.permission.ACCESS_COARSE_LOCATION), executor, callback); } } /** /** Loading Loading @@ -15572,12 +15524,6 @@ public class TelephonyManager { * instability. If a process has registered too many callbacks without unregistering them, it * instability. If a process has registered too many callbacks without unregistering them, it * may encounter an {@link IllegalStateException} when trying to register more callbacks. * may encounter an {@link IllegalStateException} when trying to register more callbacks. * * * <p> * There's another way to renounce permissions with a custom context * {@link AttributionSource.Builder#setRenouncedPermissions(Set<String>)} but only for system * apps. To avoid confusion, calling this method supersede renouncing permissions with a * custom context. * * @param renounceFineLocationAccess Set this to true if the caller would not like to receive * @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 * 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. * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permissions.