Remove ServiceManager usage from IpSecTransform
Remove ServiceManager hidden API dependency because this class is going to be moved into mainline module. Thus have IpSecTransform calls createTransform and deleteTransform through IpSecManager to remove the ServiceManager usage. Bug: 204153604 Test: FrameworksNetTests Change-Id: Iba48da4aecac1080684d5a7e7e7ca2e31219591a
This commit is contained in:
@@ -27,6 +27,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.annotations.PolicyDirection;
|
import android.net.annotations.PolicyDirection;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceSpecificException;
|
import android.os.ServiceSpecificException;
|
||||||
@@ -980,6 +981,29 @@ public final class IpSecManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public IpSecTransformResponse createTransform(IpSecConfig config, IBinder binder,
|
||||||
|
String callingPackage) {
|
||||||
|
try {
|
||||||
|
return mService.createTransform(config, binder, callingPackage);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void deleteTransform(int resourceId) {
|
||||||
|
try {
|
||||||
|
mService.deleteTransform(resourceId);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw e.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an instance of IpSecManager within an application context.
|
* Construct an instance of IpSecManager within an application context.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ import android.annotation.SystemApi;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.ServiceSpecificException;
|
import android.os.ServiceSpecificException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -93,16 +90,9 @@ public final class IpSecTransform implements AutoCloseable {
|
|||||||
mResourceId = INVALID_RESOURCE_ID;
|
mResourceId = INVALID_RESOURCE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IIpSecService getIpSecService() {
|
private IpSecManager getIpSecManager(Context context) {
|
||||||
IBinder b = ServiceManager.getService(android.content.Context.IPSEC_SERVICE);
|
return context.getSystemService(IpSecManager.class);
|
||||||
if (b == null) {
|
|
||||||
throw new RemoteException("Failed to connect to IpSecService")
|
|
||||||
.rethrowAsRuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return IIpSecService.Stub.asInterface(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the result status and throws an appropriate exception if the status is not Status.OK.
|
* Checks the result status and throws an appropriate exception if the status is not Status.OK.
|
||||||
*/
|
*/
|
||||||
@@ -130,8 +120,7 @@ public final class IpSecTransform implements AutoCloseable {
|
|||||||
IpSecManager.SpiUnavailableException {
|
IpSecManager.SpiUnavailableException {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
IIpSecService svc = getIpSecService();
|
IpSecTransformResponse result = getIpSecManager(mContext).createTransform(
|
||||||
IpSecTransformResponse result = svc.createTransform(
|
|
||||||
mConfig, new Binder(), mContext.getOpPackageName());
|
mConfig, new Binder(), mContext.getOpPackageName());
|
||||||
int status = result.status;
|
int status = result.status;
|
||||||
checkResultStatus(status);
|
checkResultStatus(status);
|
||||||
@@ -140,8 +129,6 @@ public final class IpSecTransform implements AutoCloseable {
|
|||||||
mCloseGuard.open("build");
|
mCloseGuard.open("build");
|
||||||
} catch (ServiceSpecificException e) {
|
} catch (ServiceSpecificException e) {
|
||||||
throw IpSecManager.rethrowUncheckedExceptionFromServiceSpecificException(e);
|
throw IpSecManager.rethrowUncheckedExceptionFromServiceSpecificException(e);
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowAsRuntimeException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,10 +164,7 @@ public final class IpSecTransform implements AutoCloseable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
IIpSecService svc = getIpSecService();
|
getIpSecManager(mContext).deleteTransform(mResourceId);
|
||||||
svc.deleteTransform(mResourceId);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowAsRuntimeException();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// On close we swallow all random exceptions since failure to close is not
|
// On close we swallow all random exceptions since failure to close is not
|
||||||
// actionable by the user.
|
// actionable by the user.
|
||||||
|
|||||||
Reference in New Issue
Block a user