Loading core/java/android/bluetooth/BluetoothPan.java +1 −1 Original line number Diff line number Diff line Loading @@ -367,7 +367,7 @@ public final class BluetoothPan implements BluetoothProfile { final IBluetoothPan service = getService(); if (service != null && isEnabled()) { try { service.setBluetoothTethering(value, pkgName); service.setBluetoothTethering(value, pkgName, null); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); } Loading core/java/android/net/ConnectivityManager.java +50 −9 Original line number Diff line number Diff line Loading @@ -2043,12 +2043,21 @@ public class ConnectivityManager { public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { checkLegacyRoutingApiAccess(); try { return mService.requestRouteToHostAddress(networkType, hostAddress.getAddress()); return mService.requestRouteToHostAddress(networkType, hostAddress.getAddress(), mContext.getOpPackageName(), getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * @return the context's attribution tag */ // TODO: Remove method and replace with direct call once R code is pushed to AOSP private @Nullable String getAttributionTag() { return null; } /** * Returns the value of the setting for background data usage. If false, * applications should not use the network if the application is not in the Loading Loading @@ -2239,14 +2248,30 @@ public class ConnectivityManager { * services.jar, possibly in com.android.server.net. */ /** {@hide} */ public static final void enforceChangePermission(Context context) { public static final void enforceChangePermission(Context context, String callingPkg, String callingAttributionTag) { int uid = Binder.getCallingUid(); Settings.checkAndNoteChangeNetworkStateOperation(context, uid, Settings .getPackageNameForUid(context, uid), true /* throwException */); checkAndNoteChangeNetworkStateOperation(context, uid, callingPkg, callingAttributionTag, true /* throwException */); } /** * Check if the package is a allowed to change the network state. This also accounts that such * an access happened. * * @return {@code true} iff the package is allowed to change the network state. */ // TODO: Remove method and replace with direct call once R code is pushed to AOSP private static boolean checkAndNoteChangeNetworkStateOperation(@NonNull Context context, int uid, @NonNull String callingPackage, @Nullable String callingAttributionTag, boolean throwException) { return Settings.checkAndNoteChangeNetworkStateOperation(context, uid, callingPackage, throwException); } /** {@hide} */ public static final void enforceTetherChangePermission(Context context, String callingPkg) { public static final void enforceTetherChangePermission(Context context, String callingPkg, String callingAttributionTag) { Preconditions.checkNotNull(context, "Context cannot be null"); Preconditions.checkNotNull(callingPkg, "callingPkg cannot be null"); Loading @@ -2260,11 +2285,25 @@ public class ConnectivityManager { int uid = Binder.getCallingUid(); // If callingPkg's uid is not same as Binder.getCallingUid(), // AppOpsService throws SecurityException. Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPkg, true /* throwException */); checkAndNoteWriteSettingsOperation(context, uid, callingPkg, callingAttributionTag, true /* throwException */); } } /** * Check if the package is a allowed to write settings. This also accounts that such an access * happened. * * @return {@code true} iff the package is allowed to write settings. */ // TODO: Remove method and replace with direct call once R code is pushed to AOSP private static boolean checkAndNoteWriteSettingsOperation(@NonNull Context context, int uid, @NonNull String callingPackage, @Nullable String callingAttributionTag, boolean throwException) { return Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPackage, throwException); } /** * @deprecated - use getSystemService. This is a kludge to support static access in certain * situations where a Context pointer is unavailable. Loading Loading @@ -3705,7 +3744,8 @@ public class ConnectivityManager { need, messenger, binder, callingPackageName); } else { request = mService.requestNetwork( need, messenger, timeoutMs, binder, legacyType, callingPackageName); need, messenger, timeoutMs, binder, legacyType, callingPackageName, getAttributionTag()); } if (request != null) { sCallbacks.put(request, callback); Loading Loading @@ -3981,7 +4021,8 @@ public class ConnectivityManager { checkPendingIntentNotNull(operation); try { mService.pendingRequestForNetwork( request.networkCapabilities, operation, mContext.getOpPackageName()); request.networkCapabilities, operation, mContext.getOpPackageName(), getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } catch (ServiceSpecificException e) { Loading core/java/android/net/IConnectivityManager.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -77,7 +77,8 @@ interface IConnectivityManager NetworkQuotaInfo getActiveNetworkQuotaInfo(); boolean isActiveNetworkMetered(); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress, String callingPackageName, String callingAttributionTag); @UnsupportedAppUsage(maxTargetSdk = 29, publicAlternatives = "Use {@code TetheringManager#getLastTetherError} as alternative") Loading Loading @@ -168,10 +169,10 @@ interface IConnectivityManager NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities, in Messenger messenger, int timeoutSec, in IBinder binder, int legacy, String callingPackageName); String callingPackageName, String callingAttributionTag); NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities, in PendingIntent operation, String callingPackageName); in PendingIntent operation, String callingPackageName, String callingAttributionTag); void releasePendingNetworkRequest(in PendingIntent operation); Loading packages/Tethering/common/TetheringLib/src/android/net/ITetheringConnector.aidl +14 −8 Original line number Diff line number Diff line Loading @@ -22,25 +22,31 @@ import android.os.ResultReceiver; /** @hide */ oneway interface ITetheringConnector { void tether(String iface, String callerPkg, IIntResultListener receiver); void tether(String iface, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void untether(String iface, String callerPkg, IIntResultListener receiver); void untether(String iface, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void setUsbTethering(boolean enable, String callerPkg, IIntResultListener receiver); void setUsbTethering(boolean enable, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void startTethering(in TetheringRequestParcel request, String callerPkg, IIntResultListener receiver); String callingAttributionTag, IIntResultListener receiver); void stopTethering(int type, String callerPkg, IIntResultListener receiver); void stopTethering(int type, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void requestLatestTetheringEntitlementResult(int type, in ResultReceiver receiver, boolean showEntitlementUi, String callerPkg); boolean showEntitlementUi, String callerPkg, String callingAttributionTag); void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); void isTetheringSupported(String callerPkg, IIntResultListener receiver); void isTetheringSupported(String callerPkg, String callingAttributionTag, IIntResultListener receiver); void stopAllTethering(String callerPkg, IIntResultListener receiver); void stopAllTethering(String callerPkg, String callingAttributionTag, IIntResultListener receiver); } packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +27 −16 Original line number Diff line number Diff line Loading @@ -484,13 +484,20 @@ public class TetheringManager { return dispatcher.waitForResult((connector, listener) -> { try { connector.tether(iface, callerPkg, listener); connector.tether(iface, callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } }); } /** * @return the context's attribution tag */ private @Nullable String getAttributionTag() { return null; } /** * Stop tethering the named interface. * Loading @@ -509,7 +516,7 @@ public class TetheringManager { return dispatcher.waitForResult((connector, listener) -> { try { connector.untether(iface, callerPkg, listener); connector.untether(iface, callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } Loading @@ -536,7 +543,8 @@ public class TetheringManager { return dispatcher.waitForResult((connector, listener) -> { try { connector.setUsbTethering(enable, callerPkg, listener); connector.setUsbTethering(enable, callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } Loading Loading @@ -735,7 +743,8 @@ public class TetheringManager { }); } }; getConnector(c -> c.startTethering(request.getParcel(), callerPkg, listener)); getConnector(c -> c.startTethering(request.getParcel(), callerPkg, getAttributionTag(), listener)); } /** Loading Loading @@ -775,7 +784,8 @@ public class TetheringManager { final String callerPkg = mContext.getOpPackageName(); Log.i(TAG, "stopTethering caller:" + callerPkg); getConnector(c -> c.stopTethering(type, callerPkg, new IIntResultListener.Stub() { getConnector(c -> c.stopTethering(type, callerPkg, getAttributionTag(), new IIntResultListener.Stub() { @Override public void onResult(int resultCode) { // TODO: provide an API to obtain result Loading Loading @@ -861,7 +871,7 @@ public class TetheringManager { Log.i(TAG, "getLatestTetheringEntitlementResult caller:" + callerPkg); getConnector(c -> c.requestLatestTetheringEntitlementResult( type, receiver, showEntitlementUi, callerPkg)); type, receiver, showEntitlementUi, callerPkg, getAttributionTag())); } /** Loading Loading @@ -1312,7 +1322,7 @@ public class TetheringManager { final RequestDispatcher dispatcher = new RequestDispatcher(); final int ret = dispatcher.waitForResult((connector, listener) -> { try { connector.isTetheringSupported(callerPkg, listener); connector.isTetheringSupported(callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } Loading @@ -1335,13 +1345,14 @@ public class TetheringManager { final String callerPkg = mContext.getOpPackageName(); Log.i(TAG, "stopAllTethering caller:" + callerPkg); getConnector(c -> c.stopAllTethering(callerPkg, new IIntResultListener.Stub() { getConnector(c -> c.stopAllTethering(callerPkg, getAttributionTag(), new IIntResultListener.Stub() { @Override public void onResult(int resultCode) { // TODO: add an API parameter to send result to caller. // This has never been possible as stopAllTethering has always been void and never // taken a callback object. The only indication that callers have is if the call // results in a TETHER_STATE_CHANGE broadcast. // This has never been possible as stopAllTethering has always been void // and never taken a callback object. The only indication that callers have // is if the call results in a TETHER_STATE_CHANGE broadcast. } })); } Loading Loading
core/java/android/bluetooth/BluetoothPan.java +1 −1 Original line number Diff line number Diff line Loading @@ -367,7 +367,7 @@ public final class BluetoothPan implements BluetoothProfile { final IBluetoothPan service = getService(); if (service != null && isEnabled()) { try { service.setBluetoothTethering(value, pkgName); service.setBluetoothTethering(value, pkgName, null); } catch (RemoteException e) { Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); } Loading
core/java/android/net/ConnectivityManager.java +50 −9 Original line number Diff line number Diff line Loading @@ -2043,12 +2043,21 @@ public class ConnectivityManager { public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { checkLegacyRoutingApiAccess(); try { return mService.requestRouteToHostAddress(networkType, hostAddress.getAddress()); return mService.requestRouteToHostAddress(networkType, hostAddress.getAddress(), mContext.getOpPackageName(), getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * @return the context's attribution tag */ // TODO: Remove method and replace with direct call once R code is pushed to AOSP private @Nullable String getAttributionTag() { return null; } /** * Returns the value of the setting for background data usage. If false, * applications should not use the network if the application is not in the Loading Loading @@ -2239,14 +2248,30 @@ public class ConnectivityManager { * services.jar, possibly in com.android.server.net. */ /** {@hide} */ public static final void enforceChangePermission(Context context) { public static final void enforceChangePermission(Context context, String callingPkg, String callingAttributionTag) { int uid = Binder.getCallingUid(); Settings.checkAndNoteChangeNetworkStateOperation(context, uid, Settings .getPackageNameForUid(context, uid), true /* throwException */); checkAndNoteChangeNetworkStateOperation(context, uid, callingPkg, callingAttributionTag, true /* throwException */); } /** * Check if the package is a allowed to change the network state. This also accounts that such * an access happened. * * @return {@code true} iff the package is allowed to change the network state. */ // TODO: Remove method and replace with direct call once R code is pushed to AOSP private static boolean checkAndNoteChangeNetworkStateOperation(@NonNull Context context, int uid, @NonNull String callingPackage, @Nullable String callingAttributionTag, boolean throwException) { return Settings.checkAndNoteChangeNetworkStateOperation(context, uid, callingPackage, throwException); } /** {@hide} */ public static final void enforceTetherChangePermission(Context context, String callingPkg) { public static final void enforceTetherChangePermission(Context context, String callingPkg, String callingAttributionTag) { Preconditions.checkNotNull(context, "Context cannot be null"); Preconditions.checkNotNull(callingPkg, "callingPkg cannot be null"); Loading @@ -2260,11 +2285,25 @@ public class ConnectivityManager { int uid = Binder.getCallingUid(); // If callingPkg's uid is not same as Binder.getCallingUid(), // AppOpsService throws SecurityException. Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPkg, true /* throwException */); checkAndNoteWriteSettingsOperation(context, uid, callingPkg, callingAttributionTag, true /* throwException */); } } /** * Check if the package is a allowed to write settings. This also accounts that such an access * happened. * * @return {@code true} iff the package is allowed to write settings. */ // TODO: Remove method and replace with direct call once R code is pushed to AOSP private static boolean checkAndNoteWriteSettingsOperation(@NonNull Context context, int uid, @NonNull String callingPackage, @Nullable String callingAttributionTag, boolean throwException) { return Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPackage, throwException); } /** * @deprecated - use getSystemService. This is a kludge to support static access in certain * situations where a Context pointer is unavailable. Loading Loading @@ -3705,7 +3744,8 @@ public class ConnectivityManager { need, messenger, binder, callingPackageName); } else { request = mService.requestNetwork( need, messenger, timeoutMs, binder, legacyType, callingPackageName); need, messenger, timeoutMs, binder, legacyType, callingPackageName, getAttributionTag()); } if (request != null) { sCallbacks.put(request, callback); Loading Loading @@ -3981,7 +4021,8 @@ public class ConnectivityManager { checkPendingIntentNotNull(operation); try { mService.pendingRequestForNetwork( request.networkCapabilities, operation, mContext.getOpPackageName()); request.networkCapabilities, operation, mContext.getOpPackageName(), getAttributionTag()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } catch (ServiceSpecificException e) { Loading
core/java/android/net/IConnectivityManager.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -77,7 +77,8 @@ interface IConnectivityManager NetworkQuotaInfo getActiveNetworkQuotaInfo(); boolean isActiveNetworkMetered(); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress); boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress, String callingPackageName, String callingAttributionTag); @UnsupportedAppUsage(maxTargetSdk = 29, publicAlternatives = "Use {@code TetheringManager#getLastTetherError} as alternative") Loading Loading @@ -168,10 +169,10 @@ interface IConnectivityManager NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities, in Messenger messenger, int timeoutSec, in IBinder binder, int legacy, String callingPackageName); String callingPackageName, String callingAttributionTag); NetworkRequest pendingRequestForNetwork(in NetworkCapabilities networkCapabilities, in PendingIntent operation, String callingPackageName); in PendingIntent operation, String callingPackageName, String callingAttributionTag); void releasePendingNetworkRequest(in PendingIntent operation); Loading
packages/Tethering/common/TetheringLib/src/android/net/ITetheringConnector.aidl +14 −8 Original line number Diff line number Diff line Loading @@ -22,25 +22,31 @@ import android.os.ResultReceiver; /** @hide */ oneway interface ITetheringConnector { void tether(String iface, String callerPkg, IIntResultListener receiver); void tether(String iface, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void untether(String iface, String callerPkg, IIntResultListener receiver); void untether(String iface, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void setUsbTethering(boolean enable, String callerPkg, IIntResultListener receiver); void setUsbTethering(boolean enable, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void startTethering(in TetheringRequestParcel request, String callerPkg, IIntResultListener receiver); String callingAttributionTag, IIntResultListener receiver); void stopTethering(int type, String callerPkg, IIntResultListener receiver); void stopTethering(int type, String callerPkg, String callingAttributionTag, IIntResultListener receiver); void requestLatestTetheringEntitlementResult(int type, in ResultReceiver receiver, boolean showEntitlementUi, String callerPkg); boolean showEntitlementUi, String callerPkg, String callingAttributionTag); void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); void isTetheringSupported(String callerPkg, IIntResultListener receiver); void isTetheringSupported(String callerPkg, String callingAttributionTag, IIntResultListener receiver); void stopAllTethering(String callerPkg, IIntResultListener receiver); void stopAllTethering(String callerPkg, String callingAttributionTag, IIntResultListener receiver); }
packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +27 −16 Original line number Diff line number Diff line Loading @@ -484,13 +484,20 @@ public class TetheringManager { return dispatcher.waitForResult((connector, listener) -> { try { connector.tether(iface, callerPkg, listener); connector.tether(iface, callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } }); } /** * @return the context's attribution tag */ private @Nullable String getAttributionTag() { return null; } /** * Stop tethering the named interface. * Loading @@ -509,7 +516,7 @@ public class TetheringManager { return dispatcher.waitForResult((connector, listener) -> { try { connector.untether(iface, callerPkg, listener); connector.untether(iface, callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } Loading @@ -536,7 +543,8 @@ public class TetheringManager { return dispatcher.waitForResult((connector, listener) -> { try { connector.setUsbTethering(enable, callerPkg, listener); connector.setUsbTethering(enable, callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } Loading Loading @@ -735,7 +743,8 @@ public class TetheringManager { }); } }; getConnector(c -> c.startTethering(request.getParcel(), callerPkg, listener)); getConnector(c -> c.startTethering(request.getParcel(), callerPkg, getAttributionTag(), listener)); } /** Loading Loading @@ -775,7 +784,8 @@ public class TetheringManager { final String callerPkg = mContext.getOpPackageName(); Log.i(TAG, "stopTethering caller:" + callerPkg); getConnector(c -> c.stopTethering(type, callerPkg, new IIntResultListener.Stub() { getConnector(c -> c.stopTethering(type, callerPkg, getAttributionTag(), new IIntResultListener.Stub() { @Override public void onResult(int resultCode) { // TODO: provide an API to obtain result Loading Loading @@ -861,7 +871,7 @@ public class TetheringManager { Log.i(TAG, "getLatestTetheringEntitlementResult caller:" + callerPkg); getConnector(c -> c.requestLatestTetheringEntitlementResult( type, receiver, showEntitlementUi, callerPkg)); type, receiver, showEntitlementUi, callerPkg, getAttributionTag())); } /** Loading Loading @@ -1312,7 +1322,7 @@ public class TetheringManager { final RequestDispatcher dispatcher = new RequestDispatcher(); final int ret = dispatcher.waitForResult((connector, listener) -> { try { connector.isTetheringSupported(callerPkg, listener); connector.isTetheringSupported(callerPkg, getAttributionTag(), listener); } catch (RemoteException e) { throw new IllegalStateException(e); } Loading @@ -1335,13 +1345,14 @@ public class TetheringManager { final String callerPkg = mContext.getOpPackageName(); Log.i(TAG, "stopAllTethering caller:" + callerPkg); getConnector(c -> c.stopAllTethering(callerPkg, new IIntResultListener.Stub() { getConnector(c -> c.stopAllTethering(callerPkg, getAttributionTag(), new IIntResultListener.Stub() { @Override public void onResult(int resultCode) { // TODO: add an API parameter to send result to caller. // This has never been possible as stopAllTethering has always been void and never // taken a callback object. The only indication that callers have is if the call // results in a TETHER_STATE_CHANGE broadcast. // This has never been possible as stopAllTethering has always been void // and never taken a callback object. The only indication that callers have // is if the call results in a TETHER_STATE_CHANGE broadcast. } })); } Loading