Merge "Make tetherChangePermission to be secured for AppOps permission"
This commit is contained in:
@@ -1862,8 +1862,12 @@ public class ConnectivityManager {
|
|||||||
.getPackageNameForUid(context, uid), true /* throwException */);
|
.getPackageNameForUid(context, uid), true /* throwException */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@hide */
|
/** {@hide} */
|
||||||
public static final void enforceTetherChangePermission(Context context) {
|
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(
|
if (context.getResources().getStringArray(
|
||||||
com.android.internal.R.array.config_mobile_hotspot_provision_app).length == 2) {
|
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)
|
// Have a provisioning app - must only let system apps (which check this app)
|
||||||
@@ -1872,8 +1876,10 @@ public class ConnectivityManager {
|
|||||||
android.Manifest.permission.TETHER_PRIVILEGED, "ConnectivityService");
|
android.Manifest.permission.TETHER_PRIVILEGED, "ConnectivityService");
|
||||||
} else {
|
} else {
|
||||||
int uid = Binder.getCallingUid();
|
int uid = Binder.getCallingUid();
|
||||||
Settings.checkAndNoteWriteSettingsOperation(context, uid, Settings
|
// If callingPkg's uid is not same as Binder.getCallingUid(),
|
||||||
.getPackageNameForUid(context, uid), true /* throwException */);
|
// AppOpsService throws SecurityException.
|
||||||
|
Settings.checkAndNoteWriteSettingsOperation(context, uid, callingPkg,
|
||||||
|
true /* throwException */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1996,7 +2002,9 @@ public class ConnectivityManager {
|
|||||||
*/
|
*/
|
||||||
public int tether(String iface) {
|
public int tether(String iface) {
|
||||||
try {
|
try {
|
||||||
return mService.tether(iface);
|
String pkgName = mContext.getOpPackageName();
|
||||||
|
Log.i(TAG, "tether caller:" + pkgName);
|
||||||
|
return mService.tether(iface, pkgName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -2022,7 +2030,9 @@ public class ConnectivityManager {
|
|||||||
*/
|
*/
|
||||||
public int untether(String iface) {
|
public int untether(String iface) {
|
||||||
try {
|
try {
|
||||||
return mService.untether(iface);
|
String pkgName = mContext.getOpPackageName();
|
||||||
|
Log.i(TAG, "untether caller:" + pkgName);
|
||||||
|
return mService.untether(iface, pkgName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -2113,7 +2123,9 @@ public class ConnectivityManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Exception trying to start tethering.", e);
|
Log.e(TAG, "Exception trying to start tethering.", e);
|
||||||
wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
|
wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
|
||||||
@@ -2133,7 +2145,9 @@ public class ConnectivityManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
public void stopTethering(int type) {
|
public void stopTethering(int type) {
|
||||||
try {
|
try {
|
||||||
mService.stopTethering(type);
|
String pkgName = mContext.getOpPackageName();
|
||||||
|
Log.i(TAG, "stopTethering caller:" + pkgName);
|
||||||
|
mService.stopTethering(type, pkgName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -2218,7 +2232,9 @@ public class ConnectivityManager {
|
|||||||
*/
|
*/
|
||||||
public int setUsbTethering(boolean enable) {
|
public int setUsbTethering(boolean enable) {
|
||||||
try {
|
try {
|
||||||
return mService.setUsbTethering(enable);
|
String pkgName = mContext.getOpPackageName();
|
||||||
|
Log.i(TAG, "setUsbTethering caller:" + pkgName);
|
||||||
|
return mService.setUsbTethering(enable, pkgName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,17 +69,18 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);
|
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);
|
int getLastTetherError(String iface);
|
||||||
|
|
||||||
boolean isTetheringSupported();
|
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();
|
String[] getTetherableIfaces();
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
String[] getTetherableBluetoothRegexs();
|
String[] getTetherableBluetoothRegexs();
|
||||||
|
|
||||||
int setUsbTethering(boolean enable);
|
int setUsbTethering(boolean enable, String callerPkg);
|
||||||
|
|
||||||
void reportInetCondition(int networkType, int percentage);
|
void reportInetCondition(int networkType, int percentage);
|
||||||
|
|
||||||
|
|||||||
@@ -2949,8 +2949,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
// javadoc from interface
|
// javadoc from interface
|
||||||
@Override
|
@Override
|
||||||
public int tether(String iface) {
|
public int tether(String iface, String callerPkg) {
|
||||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||||
if (isTetheringSupported()) {
|
if (isTetheringSupported()) {
|
||||||
final int status = mTethering.tether(iface);
|
final int status = mTethering.tether(iface);
|
||||||
return status;
|
return status;
|
||||||
@@ -2961,8 +2961,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
// javadoc from interface
|
// javadoc from interface
|
||||||
@Override
|
@Override
|
||||||
public int untether(String iface) {
|
public int untether(String iface, String callerPkg) {
|
||||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||||
|
|
||||||
if (isTetheringSupported()) {
|
if (isTetheringSupported()) {
|
||||||
final int status = mTethering.untether(iface);
|
final int status = mTethering.untether(iface);
|
||||||
@@ -3016,8 +3016,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int setUsbTethering(boolean enable) {
|
public int setUsbTethering(boolean enable, String callerPkg) {
|
||||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||||
if (isTetheringSupported()) {
|
if (isTetheringSupported()) {
|
||||||
return mTethering.setUsbTethering(enable);
|
return mTethering.setUsbTethering(enable);
|
||||||
} else {
|
} else {
|
||||||
@@ -3076,8 +3076,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi) {
|
public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi,
|
||||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
String callerPkg) {
|
||||||
|
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||||
if (!isTetheringSupported()) {
|
if (!isTetheringSupported()) {
|
||||||
receiver.send(ConnectivityManager.TETHER_ERROR_UNSUPPORTED, null);
|
receiver.send(ConnectivityManager.TETHER_ERROR_UNSUPPORTED, null);
|
||||||
return;
|
return;
|
||||||
@@ -3086,8 +3087,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopTethering(int type) {
|
public void stopTethering(int type, String callerPkg) {
|
||||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||||
mTethering.stopTethering(type);
|
mTethering.stopTethering(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5465,8 +5466,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
|
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
|
||||||
// Untether
|
// Untether
|
||||||
|
String pkgName = mContext.getOpPackageName();
|
||||||
for (String tether : getTetheredIfaces()) {
|
for (String tether : getTetheredIfaces()) {
|
||||||
untether(tether);
|
untether(tether, pkgName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user