Android: Inject fake camera preview for testing purpose











up vote
5
down vote

favorite












I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback method of the android.hardware.Camera class. I am looking for a way to inject a fake preview picture to test the app's behavior.



I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback object, but unfortunately, the instance variable mPreviewCallback is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback object.



Another way I thought about was to send a Message to the Camera's EventHandler, but again the field mEventHandler is private, so the test code has no way to get a reference to the Handler.










share|improve this question


















  • 1




    I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
    – Machinarius
    Dec 16 '13 at 18:40










  • Is your device rooted?
    – Alex Cohn
    Dec 17 '13 at 0:03










  • @Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
    – lacton
    Dec 18 '13 at 14:02










  • @Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
    – lacton
    Dec 18 '13 at 14:03










  • @Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
    – Machinarius
    Dec 18 '13 at 16:46















up vote
5
down vote

favorite












I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback method of the android.hardware.Camera class. I am looking for a way to inject a fake preview picture to test the app's behavior.



I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback object, but unfortunately, the instance variable mPreviewCallback is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback object.



Another way I thought about was to send a Message to the Camera's EventHandler, but again the field mEventHandler is private, so the test code has no way to get a reference to the Handler.










share|improve this question


















  • 1




    I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
    – Machinarius
    Dec 16 '13 at 18:40










  • Is your device rooted?
    – Alex Cohn
    Dec 17 '13 at 0:03










  • @Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
    – lacton
    Dec 18 '13 at 14:02










  • @Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
    – lacton
    Dec 18 '13 at 14:03










  • @Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
    – Machinarius
    Dec 18 '13 at 16:46













up vote
5
down vote

favorite









up vote
5
down vote

favorite











I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback method of the android.hardware.Camera class. I am looking for a way to inject a fake preview picture to test the app's behavior.



I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback object, but unfortunately, the instance variable mPreviewCallback is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback object.



Another way I thought about was to send a Message to the Camera's EventHandler, but again the field mEventHandler is private, so the test code has no way to get a reference to the Handler.










share|improve this question













I am writing some black-box, acceptance tests that run on a physical android device. The application under test (AUT) relies on the camera's preview. Specifically, it uses the setOneShotPreviewCallback method of the android.hardware.Camera class. I am looking for a way to inject a fake preview picture to test the app's behavior.



I thought I could fool the Camera object by having the test code call the AUT's PreviewCallback object, but unfortunately, the instance variable mPreviewCallback is private to the Camera object and thus my test code has no way to get a reference to the PreviewCallback object.



Another way I thought about was to send a Message to the Camera's EventHandler, but again the field mEventHandler is private, so the test code has no way to get a reference to the Handler.







android android-camera android-testing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 16 '13 at 18:37









lacton

1,63611622




1,63611622








  • 1




    I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
    – Machinarius
    Dec 16 '13 at 18:40










  • Is your device rooted?
    – Alex Cohn
    Dec 17 '13 at 0:03










  • @Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
    – lacton
    Dec 18 '13 at 14:02










  • @Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
    – lacton
    Dec 18 '13 at 14:03










  • @Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
    – Machinarius
    Dec 18 '13 at 16:46














  • 1




    I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
    – Machinarius
    Dec 16 '13 at 18:40










  • Is your device rooted?
    – Alex Cohn
    Dec 17 '13 at 0:03










  • @Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
    – lacton
    Dec 18 '13 at 14:02










  • @Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
    – lacton
    Dec 18 '13 at 14:03










  • @Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
    – Machinarius
    Dec 18 '13 at 16:46








1




1




I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40




I think this suggestion might break your physical device rule but maybe running on genymotion can achieve the trick you desire. genymotion.com/features
– Machinarius
Dec 16 '13 at 18:40












Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03




Is your device rooted?
– Alex Cohn
Dec 17 '13 at 0:03












@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02




@Machinarius: I have followed your suggestion and have installed genymotion. Although it is a fine piece of software, I could not find a way to programmatically inject an image in the camera's preview stream. It seems the only action genymotions allows is to connect my physical webcam's stream to the simulated camera. Have I overlooked something?
– lacton
Dec 18 '13 at 14:02












@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03




@Alex My device is not (yet) rooted, but I am ready to do it if it solves my problem.
– lacton
Dec 18 '13 at 14:03












@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46




@Machinarius With some driver trickery you could trick genymotion into feeding android the image you want. That highly depends on the OS you want to run this on though
– Machinarius
Dec 18 '13 at 16:46












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.






share|improve this answer























  • The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
    – lacton
    Jan 28 '14 at 21:55










  • The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
    – Alex Cohn
    Jan 30 '14 at 11:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20618296%2fandroid-inject-fake-camera-preview-for-testing-purpose%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.






share|improve this answer























  • The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
    – lacton
    Jan 28 '14 at 21:55










  • The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
    – Alex Cohn
    Jan 30 '14 at 11:01















up vote
0
down vote













Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.






share|improve this answer























  • The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
    – lacton
    Jan 28 '14 at 21:55










  • The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
    – Alex Cohn
    Jan 30 '14 at 11:01













up vote
0
down vote










up vote
0
down vote









Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.






share|improve this answer














Please see Android mock Camera and How to mock a picture in Android Emulator Camera? Both methods don't need rooted device, but require a change of the application. I believe you can make the necessary modification even if you don't have access to the source code, by decompiling the dex.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 10:30









Community

11




11










answered Dec 19 '13 at 10:29









Alex Cohn

40.2k551182




40.2k551182












  • The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
    – lacton
    Jan 28 '14 at 21:55










  • The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
    – Alex Cohn
    Jan 30 '14 at 11:01


















  • The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
    – lacton
    Jan 28 '14 at 21:55










  • The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
    – Alex Cohn
    Jan 30 '14 at 11:01
















The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55




The first question (Android mock Camera) suggests using Mockito to mock the Camera class. Yet, the mockito offical doc states that "Mockito doesn't mock final methods". Most Camera's methods being final, it seems mocking Camera is not an option.
– lacton
Jan 28 '14 at 21:55












The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01




The final methods like setOneShotPreviewCallback() are only thin wrappers around native methods. You can create the mock Camera class that will load an alternative native library to implement this method.
– Alex Cohn
Jan 30 '14 at 11:01


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20618296%2fandroid-inject-fake-camera-preview-for-testing-purpose%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine