Fixing Camera issues with SODP/AOSP on the XA2 Ultra

c

Well, last post I was telling you how I started using the SODP material to build AOSP on the XA2 Ultra, and how well it worked. However, there were a few issues. One notable issue was with the camera preview, and how it would look green. The pictures themselves would be fine, but the display would look green while taking them. That obviously would not do.

One thing I came to realize is that the manifest I was using downloaded the 4.9 kernel source, but also a pre-built 4.9 kernel to be used during the build. Once it was deemed stable, they start using the pre-built kernel instead of building them from source while you build Android. This saves time and resources, but isn’t (in my opinion) a good idea.

So, I decided to build the kernel from source myself, instead of using the pre-built one. Long story short, I simply had to delete the kernel/sony/4.9/common-kernel/ folder and all of it’s contents to force the build process to also build the kernel from the already available source code.

Once I did that, not only did it build the 4.9 kernel from source, but, to God be the glory, it also fixed the green camera display issue! So, it looks like some code or another was updated somewhere along the line and the older pre-built kernel did not interact well with that code, or did not take advantage of it…. Either way, I’m quite pleased to have the kernel built from source and the camera working properly!

Linux – keep it simple.

Getting photos with intents on Android

During my class for app development, the instructor showed us how to get a photo from the phone’s gallery with intents. I wanted to take that one step farther, so I did. I also added getting a photo from the camera. To keep things small, I set the camera still to be returned as a thumbnail view, per the android instructions here:

https://developer.android.com/training/camera/photobasics.html

Here is what I have:

MainActivity.java

[CODE]

package com.example.alaskalinuxuser.photohowto;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    // Define our image view.
    ImageView myImage;

    @Override // On create, do this....
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Declare our image view.
        myImage = (ImageView)findViewById(R.id.imageView);

    }

    // If they click to choose a picture from the gallery....
    public void choosePic (View picView) {

        // Call the intent for the gallery.
        Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        // And start that intent for the result number 1.
        startActivityForResult(i, 1);

    }

    // If they click to take a picture button....
    public void takePic (View takeView) {

        // Call the intent for the camera.
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // And start that intent for the result number 2.
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, 2);
        }

    }

    @Override // Listen for the results from intents.
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // If it is result number 1, and it was ok, and they chose something, then...
        if (requestCode == 1 && resultCode == RESULT_OK && data != null) {

            // Get the uri.
            Uri myChosenImage = data.getData();

            // Try in case it fails.
            try {

                // Make a bitmap from the uri.
                Bitmap myBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), myChosenImage);

                // Set our chosen image to the view.
                myImage.setImageBitmap(myBitmap);

                // Give a catch in case there is a problem.
            } catch (IOException e) {
                e.printStackTrace();
            }

            // But if it is result number 2, and it is okay, and there is data, then....
        } else if (requestCode == 2 && resultCode == RESULT_OK && data != null) {

            try { // In case it fails.

                // Get the extras (a small thumbnail in this case).
                Bundle extras = data.getExtras();
                // Set our bitmap to that extra.
                Bitmap camImage = (Bitmap) extras.get("data");
                // Set our image with that bitmap.
                myImage.setImageBitmap(camImage);
                // A catch in case it fails.
            } catch (Exception e) {
                e.printStackTrace();
            }

        }


    }
}

[/CODE]

 

Pretty neat, huh? You can check this out on my GitHub under the small apps repository.

Linux – keep it simple.

Scann3d, making 3d models with your cell phone camera!

I am not an artist. Nor am I a 3d modeler. I tried using Blender and other 3d modeling programs, but it just isn’t something that I have a knack for. However, when I saw this app I had to check it out! It’s called Scann3d, and it can be very addicting!

Essentially, you walk around an object while taking pictures of it, then, the app uses your phone processor to put those photographs together to make a 3d object. You don’t need the internet, because this works on your phone itself. Here was my very first try:

Don’t laugh too hard, it actually is really difficult to make a good model. The interface is really simple and it even has a numbered circle for the pictures while you walk around the object. What makes it difficult is the need for even spacing between shots, as well as great lighting and steady hands. This child’s chair was something I took in about 45 seconds with no regard to the instructions.

Once the model is built, you can twist and turn it with your finger or stylus, and the resulting object is a standard file that you can import into programs like Blender as well. Obviously my skills need a little more work, but if you want to make real objects part of your digital library, then this is a really fun way to do it!

Linux – keep it simple.

Updated the S4Camera app!

As we spoke about last time, there were two problems with my custom S4 camera app:

  1. No way to stop the recording, you had to wait for the 1 or 3 minute timer to elapse.
  2. No audio was recorded.

Well, I haven’t fixed everything yet, but I was able to fix issue #1, stopping the recording. Essentially, I added a button which was invisible all of the time, unless you were recording. Once you start recording (still for 1 or 3 minutes), the stop recording button will become visible in the corner of the screen.

Pressing that stop recording button causes a super user command to be sent using pkill -2 to kill the screenrecord function. A -2 pkill command is the same as a ^c (control-c) command. That is a very nice command which tells it to wrap up and then stop, but do so now! I tried other pkill commands, which literally kill the process in a less than nice fashion, but when I do that, the video is not “ended” properly and becomes unreadable. This method allows the screenrecord function to properly close writing to the video so it is readable!

You can check out the changes and download the latest version on my Github:

https://github.com/alaskalinuxuser/S4camera_app

https://github.com/alaskalinuxuser/S4camera_app/commit/51f0934ee7eed612f1fd168e20b27afc148e6a17

Linux – keep it simple.

Enabling the old Camera api and apps in Android 5 and up

While trying to figure out the problems with video recordings (which were resolved – Praise God!) on the SGH-M919 AOKP Marshmallow ROM, I learned a lot of great things about Android’s camera systems. Not the least of which was how to enable or disable camera and camera2 api’s.

Android has a built in api that handles camera requests. To be more accurate, Android currently has 2. Originally, Android used the camera api, which had a handler that was built into Android, under the source code, and controlled by camera, nested in “packages/apps/camera”. Later, Android phones stated to come with better cameras with more functions, so the camera2 api was built, and controlled from camera2, nested in “packages/apps/camera2”. What exactly is different between the two, I am not sure. Needless to say camera2 has more functionality with modern cameras.

However, despite having more functionality, what I did find is that Android, all the way up to Marshmallow, still has the old built in camera api. What I also found, though, is that it isn’t used anymore. That’s right, if your rom/source/etc. comes with Camera2, that is what the system calls on to handle the camera for things like photos, video recording, skype, etc.

In my travels and trial, though, I also learned that you can “turn on” the old camera api, and “turn off” the new camera2 api, but building and not building the appropriate packages. Most of the roms I deal with still have “packages/apps/camera” there, but the contents are edited or missing so it will not build. I successfully built the old camera api controller by downloading this and putting it in the “packages/apps/camera” folder.

https://github.com/AOKP/packages_apps_Camera/tree/ics

After unzipping it and placing those files in that folder, I then had to edit the “packages/apps/camera2/Android.mk” file like so:

[CODE]
LOCAL_PATH := $(call my-dir)

# leaving the makefile emtpy to prevent the build
# system from traversing the project
[/CODE]

Another option is to delete the camera2 folder entirely, but you may need it later. You can also rename the Android.mk files in the camera2 folder to Android.bak instead. Any of these options will work. In either event, after compiling my ROM, the camera2 app did not get built, so, using OpenCamera, it then worked as before, but with the old camera api! To be honest, I didn’t take too much time for comparisons, but I couldn’t tell the difference in the photo quality. Then again, my phone is a bit older, and perhaps only brand new phones will have cameras that this would actually make a difference.

Linux – keep it simple.