diff options
| author | Philip P. Moltmann <moltmann@google.com> | 2020-03-26 11:50:35 -0700 |
|---|---|---|
| committer | Philip P. Moltmann <moltmann@google.com> | 2020-04-20 18:00:03 -0700 |
| commit | 6bb9c7bdc488119c50269c8676d91a3617c3d0e9 (patch) | |
| tree | 7b053c08a215e0c319d4b9e23bffa8e854a556e9 /core/java/android | |
| parent | 506655294ecff07157789363dad7730a07c5e60a (diff) | |
Set attributionTag for noteOp(WRITE_SETTINGS) calls
Test: atest FrameworksNetTests TetheringTests:TetheringServiceTest
Bug: 136595429
Merged-In: I33f787644c44d7b0e5ce17a433820cfcd985cdfb
Change-Id: Ic3d937e7bb5141798234ed5b2852c1f768e97495
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothPan.java | 2 | ||||
| -rw-r--r-- | core/java/android/net/ConnectivityManager.java | 59 | ||||
| -rw-r--r-- | core/java/android/net/IConnectivityManager.aidl | 7 |
3 files changed, 55 insertions, 13 deletions
diff --git a/core/java/android/bluetooth/BluetoothPan.java b/core/java/android/bluetooth/BluetoothPan.java index a80f5b7f36d4..bfc28fae6e65 100644 --- a/core/java/android/bluetooth/BluetoothPan.java +++ b/core/java/android/bluetooth/BluetoothPan.java @@ -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())); } diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 6892a94a692f..ad07e7cf4d5f 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -2044,13 +2044,22 @@ 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 * foreground. Developers should respect this setting, and check the value @@ -2240,14 +2249,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"); @@ -2261,12 +2286,26 @@ 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. * @hide @@ -3706,7 +3745,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); @@ -3982,7 +4022,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) { diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index 14345608e94f..b0f79bcc0b23 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -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") @@ -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); |
