Monday, 15 December 2014

ADT-1 (Android TV) Development Story - Part 1 (+ Description about my JPHacks App)

Edit: Scroll down to see the description about my JPHacks App.

I made an Android TV application through Android Studio. When it auto-generated the project for me, I got an apparently known issue:

Error:A problem was found with the configuration of task ':tv:generateDebugBuildConfig'.
> No value has been specified for property 'buildConfigPackageName'.

What I did was simply select both TV and Phone/Tablet when I was making the application:


And the automatically generated project gave some kind of internal IDE error.

Around two weeks after this incident however, Android Studio 1.0 was released. I am really glad Android Studio 1.0 was released though. There are some bugs that I found (e.g. the button to add dependencies to your application was gone?!?!), but they fixed that within the same week with a new patch: Android Studio 1.0.1.

After downloading Android Studio 1.0.1, I decided to make an application utilizing my new ADT-1 in a hackathon I was conveniently going to. The hackathon is called JPHacks.

I am the one in the front row, third from the left!

Summary about JPHacks App - "Android x Health"

Me, and two other engineers hacked away at our project. Our project actually uses Android Wear, Android TV, and Android Smartphone! (all 3!) It is certainly an "internet of thing"-like project. This application is like a all-round fitness application that actually encourages you to exercise. It also uses the newest technologies. Android TV is still really new, and Android Wear is pretty new too. If Android Studio 1.0 wasn't released the week of that hackathon, we wouldn't have been able to even set up an Android TV project (though in the end we didn't really need it. More on that later in this post.) We also used the super new Google Fit API, which Google is currently holding a competition for us Android developers to start making apps that include Google Fit API. I am definitely sure that our project has the most recent and innovative technologies because of all the things I have listed.

We had no UI designers in our team, so forgive the bad design.

I will now try to explain what our application does. Basically, the application marks a "geofence" around your home. When you go out of your home boundaries and go on with your day, e.g. go to work, then it will start counting your steps using the Wear's pedometer. On Wear app, you will see your heartbeat and your number of steps. On the mobile app, you will see your number of steps, and a graph that graphs a history of the number of steps you took for that week. There is also a neat feature of our app that is on the mobile phone - a personal avatar feature. We plan for the user to customize the avatar so that it can look like them, and, by analyzing the user's fitness stats through the Google Fitness API, if the user gets fat/does not exercise, then the avatar will get fat. If the user gets skinnier/takes lots of steps, then the avatar will be happy.

So, when the user comes home, if he or she did not exercise enough to meet his/her daily requirements, then a notification will pop up on the Wear and the phone to start exercising, and the avatar will grow a bit fatter and cry. A notification will show up, asking the user to either exercise, by watching an exercise video on their phone or on their TV. This is where the Android TV comes in. But also, this is where (very simple) machine intelligence/learning comes in. Through Google Fitness API and a bit of logic we put into our app, the application will get a recommended video from our database of videos. Also, while the video is playing, if the video is too hard (e.g. if your heartrate is too high), then the application, real-time, will recommend you an easier exercise video, and you can switch to that one.

Anyway, if you choose to show the exercise video on Android TV, you can chromecast a video from your smartphone (the Sender) to your Android TV (the Receiver). Then, the video can play. Not only that, but you can play and pause the video through a button on the smartphone app. While you are wearing your Wear during the exercise video, it will continuously monitor your heart rate.

So yeah. Although I didn't really make an actual Android TV app, I had fun learning how chromecast worked. Next time, I will actually make an Android TV app using Leanback, et cetera. I can't wait!

Also, it is currently 2 days after the hackathon ended, and we got an email saying we will be moving on to the finals with our project! Will we get first place? I hope so!

You can see the source code of our hack here: https://github.com/GreenRobots/JPHacks

Edit: You can see the Japanese Google Slides presentation describing our app here: https://docs.google.com/presentation/d/1QJcfo8gaiokhoCT7ZoCWPPk890GynzRqRcftSXTreAE/edit#slide=id.p4

Tuesday, 2 December 2014

How Keybase.io Taught me Basic Public Key Cryptography/Asymmetric Cryptography



While on Facebook one day, I noticed a friend who is in first year software engineering posting publicly about how he has some invites to a certain website called "Keybase.io". Naturally, I was intrigued, and decided to visit the website, and also asked my friend for an invite (and he kindly gave me one). To be honest, the most intriguing and captivating thing about the website at first was just the amazing, wondrous, illustrations that looked like they were from a classic children's book. I subsequently visited the portfolio site of the brilliant designer who drew these heartwarming, Caroline Hadilaksono's site.

After wasting a few minutes on her site and seeing her pretty illustrations, I actually started to read the text/content on Keybase's main website. And let me tell you that I honestly had trouble wrapping my head around what exactly this service was offering to me, the user. I was even questioning whether I was a potential user of this website, since I didn't know what it was trying to explain, except for the fact that it allows you to connect various usernames from various popular social networks together in order to form a single social identity online. I was honestly confused as to what a "public key" was.

As a regular person who does not know a thing about cryptography until visiting this site, I do have to recommend that Keybase should have some sort of explanation about what public key cryptography is, and their service. I mean, the example on their homepage with Maria grabbing a pint with someone seems like it should explain the whole service wholly, but it just didn't. I didn't understand a thing, even after reading it quite a few times over. That's when I got a bit frustrated at the lack of a good explanation, and decided to Google by myself about this whole "public key" thing.

And boy did I learn a lot! That's one thing that I really like about Keybase - that it taught me something really cool and exciting in my opinion (even though they didn't do a good job of it themselves).

So, just what exactly is this "public key" thing, and what exactly is Keybase? Well, this post is to basically explain it in simple English. No need for fancy words in this post - just straight up facts.

Tl;dr Short Lesson on What is Public Key Cryptography, and Cryptography in General, For Dummies (Like Me)



So, I'm guessing everyone already knows about the whole fiasco with the NSA and how they're spying on everyone's emails. So, how would you prevent people like the NSA, or "hackers" from reading your email? Well, that's where cryptography comes in.

So basically, let's say you want to send an email to someone, but you are afraid that a hacker can hack and might get that email while it is sent to the receiver. So, a good way to prevent the hacker from knowing the contents of your email is to encrypt it. A really good and simple example of what "encrypting" is would be if the hacker didn't know the Chinese language at all and did not have access to a Chinese-English dictionary, but you and the person you want to send the email to do have dictionaries. So, you translate your message word by word in Chinese, send it to the receiver, and they can translate it back to English and read it. Along the way, even IF the hacker gets the email, the contents are unreadable to him. Of course, actual encryption uses lots of complex and very interesting math, and are very very hard to "crack".

So, basically, I learnt that Keybase offers a service that provides this kind of easy service to communicate to other people by using their encrypting and decrypting methods. But, they provide a certain type of cryptographic method called public key cryptography. Some people also call "public key cryptography" as "asymmetric cryptography".

I will explain now about how public key cryptography actually "encrypts" your messages and allows the recipient of your messages to "decrypt" the messages.

Basically, in this type of cryptographic method, you have a public key that anyone can see and "use" (I will explain this in just a second).  This key is usually a big and long sequence of words and numbers that you can copy and paste to anyone. In addition to this public key, you also have a private key. You should never show this private key to anyone, or else the public key cryptography method of safely encrypting/decrypting will just not work - so be sure to keep the private key safe!

Both your public key and private key are mathematically related to each other, but this math is very hard to crack, so for all intensive purposes, no one can "solve" or find out what your private key is just from looking/analyzing your public key.

The public and private keys are mathematically related in such a way so that if you encrypt a message using the public key, you can decrypt the same message using your private key.

So, let's say you want to give your friend Joe an encrypted message that only HE can read. So what do you do? You actually USE Joe's public key to encrypt your message, and then give this encrypted message to him. If anyone accidentally sees this message and obtains it, they cannot read it or decipher it. This is because the encrypted message can only be decrypted by Joe's private key.

Now that I have explained the very very basics of public key cryptography, if anyone is actually reading this, and if they actually want to read more about this interesting subject (including learning about digital signatures, digital certificates, etc.), please click here to read more about it!

To whomever reads this post, I hope you learned a little something about public key cryptography, as I did. Disregarding some of the criticisms that exist for Keybase, I still think it's a very neat service. It's very entertaining to write a message, encrypt it, copy and paste the encrypted message to someone, and have them decrypt it. It's also very fun vice versa. (I like to pretend that I'm some sort of spy!) Overall, I am delighted about how fun Keybase was. I have read that its purpose was to create a service for ordinary people like me or you to encrypt and decrypt messages easily. Well, I certainly think Keybase has hit its target in that regard.