Merge "Clear caller identity in IPC methods"

This commit is contained in:
Chiachang Wang 2023-05-22 07:04:16 +00:00 • committed by Gerrit Code Review
commit 696a2013f5

View file

@ -210,8 +210,12 @@ public class AutomaticOnOffKeepaliveTracker {
this.mKi = Objects.requireNonNull(ki);
mCallback = ki.mCallback;
mUnderpinnedNetwork = underpinnedNetwork;
if (autoOnOff && mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION,
true /* defaultEnabled */)) {
// Reading DeviceConfig will check if the calling uid and calling package name are the
// same. Clear calling identity to align the calling uid and package
final boolean enabled = BinderUtils.withCleanCallingIdentity(
() -> mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION,
true /* defaultEnabled */));
if (autoOnOff && enabled) {
mAutomaticOnOffState = STATE_ENABLED;
if (null == ki.mFd) {
throw new IllegalArgumentException("fd can't be null with automatic "
@ -583,8 +587,12 @@ public class AutomaticOnOffKeepaliveTracker {
*/
public void dump(IndentingPrintWriter pw) {
mKeepaliveTracker.dump(pw);
final boolean featureEnabled = mDependencies.isFeatureEnabled(
AUTOMATIC_ON_OFF_KEEPALIVE_VERSION, true /* defaultEnabled */);
// Reading DeviceConfig will check if the calling uid and calling package name are the same.
// Clear calling identity to align the calling uid and package so that it won't fail if cts
// would like to call dump()
final boolean featureEnabled = BinderUtils.withCleanCallingIdentity(
() -> mDependencies.isFeatureEnabled(AUTOMATIC_ON_OFF_KEEPALIVE_VERSION,
true /* defaultEnabled */));
pw.println("AutomaticOnOff enabled: " + featureEnabled);
pw.increaseIndent();
for (AutomaticOnOffKeepalive autoKi : mAutomaticOnOffKeepalives) {
@ -837,12 +845,8 @@ public class AutomaticOnOffKeepaliveTracker {
* @return whether the feature is enabled
*/
public boolean isFeatureEnabled(@NonNull final String name, final boolean defaultEnabled) {
// Reading DeviceConfig will check if the calling uid and calling package name are the
// same. Clear calling identity to align the calling uid and package so that it won't
// fail if cts would like to do the dump()
return BinderUtils.withCleanCallingIdentity(() ->
DeviceConfigUtils.isFeatureEnabled(mContext, NAMESPACE_TETHERING, name,
DeviceConfigUtils.TETHERING_MODULE_NAME, defaultEnabled));
return DeviceConfigUtils.isFeatureEnabled(mContext, NAMESPACE_TETHERING, name,
DeviceConfigUtils.TETHERING_MODULE_NAME, defaultEnabled);
}
/**