summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/net/ConnectivityManager.java34
-rw-r--r--core/java/android/net/IConnectivityManager.aidl11
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java24
3 files changed, 44 insertions, 25 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index c93b933b160e..faed64c241d3 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -1880,8 +1880,12 @@ public class ConnectivityManager {
.getPackageNameForUid(context, uid), true /* throwException */);
}
- /** {@hide */
- public static final void enforceTetherChangePermission(Context context) {
+ /** {@hide} */
+ public static final void enforceTetherChangePermission(Context context, String callingPkg) {
+ if (null == context || null == callingPkg) {
+ throw new IllegalArgumentException("arguments should not be null");
+ }
+
if (context.getResources().getStringArray(
com.android.internal.R.array.config_mobile_hotspot_provision_app).length == 2) {
// Have a provisioning app - must only let system apps (which check this app)
@@ -1890,8 +1894,10 @@ public class ConnectivityManager {
android.Manifest.permission.TETHER_PRIVILEGED, "ConnectivityService");
} else {
int uid = Binder.getCallingUid();
- Settings.checkAndNoteWriteSettingsOperation(context, uid, Settings
- .getPackageNameForUid(context, uid), true /* throwException */);
+ // If callingPkg's uid is not same as Binder.getCallingUid(),
+ // AppOpsService throws SecurityException.
+ Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPkg,
+ true /* throwException */);
}
}
@@ -2016,7 +2022,9 @@ public class ConnectivityManager {
*/
public int tether(String iface) {
try {
- return mService.tether(iface);
+ String pkgName = mContext.getOpPackageName();
+ Log.i(TAG, "tether caller:" + pkgName);
+ return mService.tether(iface, pkgName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2042,7 +2050,9 @@ public class ConnectivityManager {
*/
public int untether(String iface) {
try {
- return mService.untether(iface);
+ String pkgName = mContext.getOpPackageName();
+ Log.i(TAG, "untether caller:" + pkgName);
+ return mService.untether(iface, pkgName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2133,7 +2143,9 @@ public class ConnectivityManager {
};
try {
- mService.startTethering(type, wrappedCallback, showProvisioningUi);
+ String pkgName = mContext.getOpPackageName();
+ Log.i(TAG, "startTethering caller:" + pkgName);
+ mService.startTethering(type, wrappedCallback, showProvisioningUi, pkgName);
} catch (RemoteException e) {
Log.e(TAG, "Exception trying to start tethering.", e);
wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
@@ -2153,7 +2165,9 @@ public class ConnectivityManager {
@SystemApi
public void stopTethering(int type) {
try {
- mService.stopTethering(type);
+ String pkgName = mContext.getOpPackageName();
+ Log.i(TAG, "stopTethering caller:" + pkgName);
+ mService.stopTethering(type, pkgName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2238,7 +2252,9 @@ public class ConnectivityManager {
*/
public int setUsbTethering(boolean enable) {
try {
- return mService.setUsbTethering(enable);
+ String pkgName = mContext.getOpPackageName();
+ Log.i(TAG, "setUsbTethering caller:" + pkgName);
+ return mService.setUsbTethering(enable, pkgName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index 425e49407827..63a1f0513e20 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -69,17 +69,18 @@ interface IConnectivityManager
boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);
- int tether(String iface);
+ int tether(String iface, String callerPkg);
- int untether(String iface);
+ int untether(String iface, String callerPkg);
int getLastTetherError(String iface);
boolean isTetheringSupported();
- void startTethering(int type, in ResultReceiver receiver, boolean showProvisioningUi);
+ void startTethering(int type, in ResultReceiver receiver, boolean showProvisioningUi,
+ String callerPkg);
- void stopTethering(int type);
+ void stopTethering(int type, String callerPkg);
String[] getTetherableIfaces();
@@ -95,7 +96,7 @@ interface IConnectivityManager
String[] getTetherableBluetoothRegexs();
- int setUsbTethering(boolean enable);
+ int setUsbTethering(boolean enable, String callerPkg);
void reportInetCondition(int networkType, int percentage);
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 4e2f39600823..d77297075652 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -2821,8 +2821,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
// javadoc from interface
@Override
- public int tether(String iface) {
- ConnectivityManager.enforceTetherChangePermission(mContext);
+ public int tether(String iface, String callerPkg) {
+ ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
if (isTetheringSupported()) {
final int status = mTethering.tether(iface);
return status;
@@ -2833,8 +2833,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
// javadoc from interface
@Override
- public int untether(String iface) {
- ConnectivityManager.enforceTetherChangePermission(mContext);
+ public int untether(String iface, String callerPkg) {
+ ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
if (isTetheringSupported()) {
final int status = mTethering.untether(iface);
@@ -2888,8 +2888,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
@Override
- public int setUsbTethering(boolean enable) {
- ConnectivityManager.enforceTetherChangePermission(mContext);
+ public int setUsbTethering(boolean enable, String callerPkg) {
+ ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
if (isTetheringSupported()) {
return mTethering.setUsbTethering(enable);
} else {
@@ -2948,8 +2948,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
@Override
- public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi) {
- ConnectivityManager.enforceTetherChangePermission(mContext);
+ public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi,
+ String callerPkg) {
+ ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
if (!isTetheringSupported()) {
receiver.send(ConnectivityManager.TETHER_ERROR_UNSUPPORTED, null);
return;
@@ -2958,8 +2959,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
@Override
- public void stopTethering(int type) {
- ConnectivityManager.enforceTetherChangePermission(mContext);
+ public void stopTethering(int type, String callerPkg) {
+ ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
mTethering.stopTethering(type);
}
@@ -5337,8 +5338,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
// Untether
+ String pkgName = mContext.getOpPackageName();
for (String tether : getTetheredIfaces()) {
- untether(tether);
+ untether(tether, pkgName);
}
}