Thursday, January 31, 2013

My Phone Has a SIP Dialer

Traditional phones pass conversations over the Public Services Telephone Netwok (PSTN).

Anyone who's ever used Skype knows, though, that you can also transmit calls over computer lines. Voice gets digitized, passed as packets over IP networks to someone else's computer, and then decoded into sound on the other end.  This is Voice Over IP: VOIP.

Actually, it's more than just voice, of course. Skype also does video, but folks still call it VOIP.

Skype uses proprietary protocols for this, but there are international-standard protocols, too.  The most common buzz-TLA I hear in this arena is SIP, the Session Initiation Protocol.  People talk about "SIP calls," but SIP is actually just the protocol used to set up the calls. The calls themselves exchange RTP (Realtime Transfer Protocol) packets, which move the audio and video packets back and forth once the connection's established.


My Phone Can Read and Write RFID Tags

Radio-Frequency Identification (RFID)  is a special case of NFC.  The tags themselves are passive devices. Beaming energy at them in the right way turns them into little transponders that use the energy to transmit back information that's been stored in them.  It's technology that's used in everything from tags to track wayward secondary-school students, to the transponders you clip on your visor that governments use to bill you for travelling on toll roads.

NFC grew out of RFID, so Android devices that can talk to one another over NFC can also read RFID tags. You can download apps from the Google Play Store that'll do that.

What would you pay? But wait. There's more.  You can also download apps that will write RFID tags. Over beer, a week ago, Kevin Fenzi told me he'd done it.

"Where do you buy tags?" I asked him.

"Oh, pretty much anyplace. Amazon, for example. But wait, I probably even have one in my backpack."

Sure enough. And they're little, re-writeable stickers. Whuf.

In short order, I downloaded the right apps, and wrote one that said, "Launch Waze."  (Waze is a navigation app that Ryan Fortman and Patrick McCarron convinced me to install, that helps me avoid traffic jams.).

After I wrote it, I  rubbed it against the back of my phone, and -- Boom! -- there's Waze. Since it's a sticker, I could stick it on the dashboard or the steering wheel of my old Volvo, and launch Waze without having to navigate through menus while driving.

I can also put other things on the same tag. For example, I could turn off wireless, which I'm not going to receive in my car anyway.

Other tags, stuck up in appropriate places, could trigger other custom environments. Next morning, I showed it to Steve Cutbirth, our support/customer-service honcho, and he got so excited that he took me over to show his team. They started talking about putting stickers on airplanes that would let service techs download custom diagnostics.

One of the team, Rob Lane, said he already has a Samsung Galaxy on order, which will let him do things like that. I look forward to getting together when it arrives so we can trade tips.

Meanwhile, I ordered a batch of tags from Amazon.

I Try Tethering

I've seen people offer up their wireless phones as hotspots -- portable wireless access points (WAPs) -- when no other WAP was working.  It's slower than a normal, coffeeshop or home WAP since it just runs at phone-network speeds, but slow is a lot better than nothing.

The phone works as as a wireless router, provides DHCP addresses to other computers that connect to it , and shuttles traffic to the rest of the internet through the phone network.

Thinking, "I really ought to try that," I hunted through the Settings menus, and found (More... -> Tethering & portable hotspot) a place where I could turn on tethering.

I did it, had Kristina connect her Kindle Fireto my phone, and ... Presto!  It worked.  She could browse the web.

From now one, if I can get a cell signal, I can use my cell phone as a router and connect laptops or tablets the web.

What is "Near-Field Communications"?

I'm told that there are commercials on TV touting Near-Field Communications (NFC): you just hold Android phones back-to-back  and they exchange information.

I'd read about it, but never tried it. I woke up a week ago, thought, "I have a Nexus 7 tablet and a Nexus 4 phone. That should work, right?"

I brought up Google Maps on the phone, held it back-to-back to the tablet and, after a little fumbling, the same map appeared on the tablet.  All this before I got out of bed.

What's going on?

NFC, Bluetooth, Wireless, GPS, and the cell phone itself, are all radio communication. Each of these has a little radio receiver/transmitter in the device that transmits info. Different radios have different ranges, transmission rates, and so on.

Wikipedia offers lots of technical details.

Each one helps me slough wires.  Wireless keeps me from needing an ethernet cable. Bluetooth is shorter range, and keeps me from needing wires to your headphone, my mouse, and so on. NFC is very, very short range, but lets me swap information even if I don't have a wireless network with a router available. If I'm in my car, driving, I can hand my phone to my girlfriend and she can suck information off it onto her tablet.

Going one level deeper, the Nexus boxes are actually using Android Beam, which uses NFC but is actually mostly Bluetooth. The two boxes first exchange enough NFC info to set up a Bluetooth connection, and then pass information back-and-forth with Bluetooth, which is harder to set up, but higher bandwidth.

I Root My Phone and Tablet

Ah, heck.

It's been a month since I posted anything.  I've done things, but haven't said how. I wrote posts, but I can't find 'em.  I'll put up placeholders.

One thing I did was to root my phone and tablet. It was fun. The phone's unlocked to start out with, which means I'm not risking the half-million dollar fine that the Obama administration threatens for rooting a smartphone by myself.

"Freedom? That is Yang worship word!"

Even with that step done, that's just the carrier-lock gone, but not changed to provide root access. Somewhere, I have files describing the process. Ah well.

Now, when my phone and tablet come up, they displays a little "unlocked" padlock icon at the botom as they're booting.  Awesome.

Thursday, December 27, 2012

SL4A Turns My Phone Into a Spy Camera.

I go out for beer and supper with my pal, Jim Flanagan, and use what I've learned to explain why his attempt to put a random Java app onto his girlfriend's Android phone failed.

Teaching someone else what I know is a good way to review and uncover what I don't really understand well enough to explain.

"You thought I wanted to put a Java app onto Marcia's phone?" Jim has no idea what I'm talking about.

He has, he explains, read that he can use SL4A and JRuby to run Ruby programs on Android devices. Marcia has an Android phone, and he knows Ruby. A natural match.

He doesn't understand what SL4A is or why it would need JRuby, or, for that matter, even what Sinatra is, which is also required, "... But maybe you do."

Well, no, but at least this time I've paid close enough attention to know what the question is. I've heard of JRuby and Sinatra.  SL4A?  Nope, but it's "Scripting Layer For Android."

Jim says that the place he found this information has an example -- only a few lines of code -- that turn an Android phone into a spy camera. He could install it on Marcia's camera and spy on her from his laptop. Of course, he could just go over and see her whenever he wants, but okay, we're guys, so spy camera is enough to make this compelling.

After supper, we head back over to Caffe Sole, where they now have a band playing live, bad, jazz.

He shows me the code and yes, just a handful of lines of Ruby, running on the phone, are claimed  to tell the camera to take a picture, and then serve the picture up over the internet, on Webrick's port 4567. (Webrick is Ruby's built-in, light-weight web server).

Browsing to that port at the phone's IP address, from any browser, should show the picture. Somehow, the code also lets the laptop instruct the phone when to take pictures.

Only one way to find out.

I google for SL4A from my phone, and install it from Google Code.  SL4A, in turn, lets me install JRuby. The code samples that come with that installation work indifferently. The "Hello, World" app works okay, the app to toggle airplane mode seems to work once, but we can't repeat that.

But who cares about airplane mode if we can have a Spy Camera?

I connect the phone to his Mac with a USB cable, and the phone asks me if I want to allow him to  "Download files via USB."

Well, sure.

After some trial and error, we download the spy-camera app and and associated directory, uh, folder,  I poke around, turn on the phone's WiFi, and figure out the phone's IP address: 192.168.1.8.  Jim browses to it to 192.168.1.8:4567.  The phone's camera makes a loud shutter click.

Actually, that's just Android generating a "shutter-click sound" electronically, since the camera shutter is also entirely electronic, but we'll take it. Houston, we have ignition.

After a couple second or two, a picture appears on Jim's browser. It's almost black. The coffee shop is dark and the pictures are darker. We try a few more. I finally realize I'm trying to take a picture with the phone's rear-facing camera, but it doesn't have one.

I turn the phone around.

I try to take a picture of the woman sitting next to Jim. She says, "Why do you want to take my picture?" turns her head away, and puts up her hand. I bet real spies never have this sort of problem.

I go over to the counter, where the light's better, and take a picture of Katie, the barista. It works! We show her on the laptop. It's sideways, but she's still still pleased.

So are we. We leave the coffee shop in triumph.

The Application Lifecycle and Its Dual


Building an app was fun, so let's look at the next tutorial, on lifecycles. Maybe it'll modify the app I have to help me understand Karim's slide 46.

Slide 46 is the dual of the pyramid graphic, in the tutorial, which shows the states as nodes, with the functions that move between them as edges. Slide 46, in contrast, has the functions as nodes, and the states as edges.

Either way, I need to learn the states and how activities move among them.

Reading through the general description, I look back at my sources and find both of my activities have an OnCreate(), but none of the other functions. I wonder where those are.

Another mystery is the difference among what look like almost identical things, such as Paused and Stopped.  "Paused" means "partially obscured," but when does that ever happen? Apps always take up the whole screen, right?

The next step in the tutorial answers that one, right away! A popup, such as a dialogue box, partially obscures, so it pauses the app.

The rest of the tutorial talks in generalities. There are code snippets, but there's no real exercise.

Bummer.