summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTetsutoki Shiozawa <tetsutoki.x.shiozawa@sonymobile.com>2016-03-16 23:30:57 +0900
committerShunta Sato <shunta.sato@sonymobile.com>2017-04-19 16:50:33 +0900
commit335d2edee28fdd9991d87f3df8799c7ff1bcd3cd (patch)
tree0d7fbde157ae6b32e1ed332da5b688ea27ed6e5c /core
parent58b5789cdee9265453c20454219cf2fd927a7d73 (diff)
Make tetherChangePermission to be secured for AppOps permission
Symptom: AppOps verified the incorrect package of calling tether state changing API. It threw SecurityException by mistake. Solution: Pass the correct package name to enforceTetherChangePermission. Bug: 32931147 Change-Id: Ia1167f26f556678b189a24a4a716f1a7e5cb12eb
Diffstat (limited to 'core')
-rw-r--r--core/java/android/net/ConnectivityManager.java34
-rw-r--r--core/java/android/net/IConnectivityManager.aidl11
2 files changed, 31 insertions, 14 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 0e5d049c7891..e4b75c15fea7 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -1863,8 +1863,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)
@@ -1873,8 +1877,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 */);
}
}
@@ -1997,7 +2003,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();
}
@@ -2023,7 +2031,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();
}
@@ -2114,7 +2124,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);
@@ -2134,7 +2146,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();
}
@@ -2219,7 +2233,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);