use of android.os.ServiceSpecificException in project android_frameworks_base by AOSPA.
the class CameraDeviceBinderTest method testCreateStreamTwo.
@SmallTest
public void testCreateStreamTwo() throws Exception {
// Create first stream
int streamId = mCameraUser.createStream(mOutputConfiguration);
assertEquals(0, streamId);
try {
mCameraUser.createStream(mOutputConfiguration);
fail("Created same stream twice");
} catch (ServiceSpecificException e) {
assertEquals("Created same stream twice", ICameraService.ERROR_ALREADY_EXISTS, e.errorCode);
}
// Create second stream with a different surface.
SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */
0);
surfaceTexture.setDefaultBufferSize(640, 480);
Surface surface2 = new Surface(surfaceTexture);
OutputConfiguration output2 = new OutputConfiguration(surface2);
int streamId2 = mCameraUser.createStream(output2);
assertEquals(1, streamId2);
// Clean up streams
mCameraUser.deleteStream(streamId);
mCameraUser.deleteStream(streamId2);
}
use of android.os.ServiceSpecificException in project android_frameworks_base by AOSPA.
the class CameraDeviceBinderTest method testSubmitBadRequest.
@SmallTest
public void testSubmitBadRequest() throws Exception {
CaptureRequest.Builder builder = createDefaultBuilder(/* needStream */
false);
CaptureRequest request1 = builder.build();
try {
SubmitInfo requestInfo = mCameraUser.submitRequest(request1, /* streaming */
false);
fail("Exception expected");
} catch (ServiceSpecificException e) {
assertEquals("Expected submitRequest to throw ServiceSpecificException with BAD_VALUE " + "since we had 0 surface targets set.", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
}
builder.addTarget(mSurface);
CaptureRequest request2 = builder.build();
try {
SubmitInfo requestInfo = mCameraUser.submitRequest(request2, /* streaming */
false);
fail("Exception expected");
} catch (ServiceSpecificException e) {
assertEquals("Expected submitRequest to throw ILLEGAL_ARGUMENT " + "ServiceSpecificException since the target wasn't registered with createStream.", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
}
}
use of android.os.ServiceSpecificException in project android_frameworks_base by AOSPA.
the class CameraDeviceBinderTest method testSubmitStreamingRequest.
@SmallTest
public void testSubmitStreamingRequest() throws Exception {
CaptureRequest.Builder builder = createDefaultBuilder(/* needStream */
true);
CaptureRequest request = builder.build();
// Submit valid request once (non-streaming), and another time
// (streaming)
SubmitInfo requestInfo1 = submitCameraRequest(request, /* streaming */
false);
SubmitInfo requestInfoStreaming = submitCameraRequest(request, /* streaming */
true);
assertNotSame("Request IDs should be unique for multiple requests", requestInfo1.getRequestId(), requestInfoStreaming.getRequestId());
try {
long lastFrameNumber = mCameraUser.cancelRequest(-1);
fail("Expected exception");
} catch (ServiceSpecificException e) {
assertEquals("Invalid request IDs should not be cancellable", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
}
try {
long lastFrameNumber = mCameraUser.cancelRequest(requestInfo1.getRequestId());
fail("Expected exception");
} catch (ServiceSpecificException e) {
assertEquals("Non-streaming request IDs should not be cancellable", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
}
long lastFrameNumber = mCameraUser.cancelRequest(requestInfoStreaming.getRequestId());
}
use of android.os.ServiceSpecificException in project android_frameworks_base by AOSPA.
the class CameraDeviceUserShim method connectBinderShim.
public static CameraDeviceUserShim connectBinderShim(ICameraDeviceCallbacks callbacks, int cameraId) {
if (DEBUG) {
Log.d(TAG, "Opening shim Camera device");
}
/*
* Put the camera open on a separate thread with its own looper; otherwise
* if the main thread is used then the callbacks might never get delivered
* (e.g. in CTS which run its own default looper only after tests)
*/
CameraLooper init = new CameraLooper(cameraId);
CameraCallbackThread threadCallbacks = new CameraCallbackThread(callbacks);
// TODO: Make this async instead of blocking
int initErrors = init.waitForOpen(OPEN_CAMERA_TIMEOUT_MS);
Camera legacyCamera = init.getCamera();
// Check errors old HAL initialization
LegacyExceptionUtils.throwOnServiceError(initErrors);
// Disable shutter sounds (this will work unconditionally) for api2 clients
legacyCamera.disableShutterSound();
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(cameraId, info);
Camera.Parameters legacyParameters = null;
try {
legacyParameters = legacyCamera.getParameters();
} catch (RuntimeException e) {
throw new ServiceSpecificException(ICameraService.ERROR_INVALID_OPERATION, "Unable to get initial parameters: " + e.getMessage());
}
CameraCharacteristics characteristics = LegacyMetadataMapper.createCharacteristics(legacyParameters, info);
LegacyCameraDevice device = new LegacyCameraDevice(cameraId, legacyCamera, characteristics, threadCallbacks);
return new CameraDeviceUserShim(cameraId, device, characteristics, init, threadCallbacks);
}
use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.
the class NetworkManagementService method closeSocketsForFirewallChainLocked.
private void closeSocketsForFirewallChainLocked(int chain, String chainName) {
// UID ranges to close sockets on.
UidRange[] ranges;
// UID ranges whose sockets we won't touch.
int[] exemptUids;
final SparseIntArray rules = getUidFirewallRules(chain);
int numUids = 0;
if (getFirewallType(chain) == FIREWALL_TYPE_WHITELIST) {
// Close all sockets on all non-system UIDs...
ranges = new UidRange[] { // specify their ranges here.
new UidRange(Process.FIRST_APPLICATION_UID, Integer.MAX_VALUE) };
// ... except for the UIDs that have allow rules.
exemptUids = new int[rules.size()];
for (int i = 0; i < exemptUids.length; i++) {
if (rules.valueAt(i) == NetworkPolicyManager.FIREWALL_RULE_ALLOW) {
exemptUids[numUids] = rules.keyAt(i);
numUids++;
}
}
// fix setFirewallEnabled to grab mQuotaLock and clear rules.
if (numUids != exemptUids.length) {
exemptUids = Arrays.copyOf(exemptUids, numUids);
}
} else {
// Close sockets for every UID that has a deny rule...
ranges = new UidRange[rules.size()];
for (int i = 0; i < ranges.length; i++) {
if (rules.valueAt(i) == NetworkPolicyManager.FIREWALL_RULE_DENY) {
int uid = rules.keyAt(i);
ranges[numUids] = new UidRange(uid, uid);
numUids++;
}
}
// As above; usually numUids == ranges.length, but not always.
if (numUids != ranges.length) {
ranges = Arrays.copyOf(ranges, numUids);
}
// ... with no exceptions.
exemptUids = new int[0];
}
try {
mNetdService.socketDestroy(ranges, exemptUids);
} catch (RemoteException | ServiceSpecificException e) {
Slog.e(TAG, "Error closing sockets after enabling chain " + chainName + ": " + e);
}
}
Aggregations