Hacking Glass - Appendices - Designing and Developing for Google Glass (2015)

Designing and Developing for Google Glass (2015)

Part IV. Appendices

Appendix B. Hacking Glass

Glass was built with the intention that it would be taken apart and extended. This appendix is admittedly (and boastfully) esoteric—delving into what is viewed as a very much dark but highly respected art. Hackers are commonly misunderstood by the mainstream as being nefarious types who on principle exist to create chaos and unseat everything that organized groups have put together. That’s actually a half-true statement.

Hackers are talented technologists who enjoy tinkering endlessly with hardware, components, and software modules to find new and innovative ways to get more utility from out-of-box products, or by inventing from scratch—but for good. They’re a unique breed of people whose love of exploration and willingness to take things apart to see how they work is intensely vigilant. They use their considerable skills to investigate aspects of platforms that most people don’t care about, and then share information with others in their community as a coordinated effort to make products better.

Hackers tirelessly make technology more valuable by constantly working to expand its capabilities and functionality, as well as to uncover shortcomings and oversights to make a system more stable, more secure, and more performant. They sometimes expose security flaws, performance hindrances, and operational inefficiencies in order to improve the quality of a technology, and typically only ask for acknowledgment for having found the glitch. It’s a badge of honor.

Consequently, the Android lineage of Glass makes it a ripe environment for the hacker ethos to thrive.

The ability to hack Glass was made possible by Google fully supporting the curiosity to rebuild the system and expand upon its shipped capabilities or load a completely different Linux distribution. This was met with great zest from hackers worldwide, seeing that Google wasn’t afraid to officially let its product be taken apart. Hacking Glass wasn’t just possible—it was encouraged.

Those who dare to walk on the wild side can further expand the platform, even if doing so means possibly sacrificing their warranty. For those in whom the passion for hacking burns bright, it’s a fair trade in exchange for discovery, knowledge, and community.

So if you share this way of life, want to try something interesting, or want to get involved, this appendix lets you explore the limits of your creativity and have some wacky, hacky fun.

The DIY Movement: When the Status Quo Just Isn’t Good Enough

Hacking is fun, challenging, and rewarding. It’s a very nonconformist attitude to uphold, even as a white hat. So it was no surprise that when the Glass Explorer Edition units began being distributed, a great many people wanted more out of the platform. Android savants wanted a way to install a launcher and run applications written for that OS on Glass, leading to their quick discovery of Debug Mode and the enabling of Android Debug Bridge (ADB) to sideload apps. In marketing Glass, Google stresses that true to their own hacker heritage the product was deliberately left unlocked so that it could be messed with. Glass isn’t just a platform that can be hacked—it’s built to be hacker-friendly.

What’s more, the enthusiasm from Googlers shone through, as Glass team members nudged their fellow coders to go forth and challenge the limits of the system and take it into uncharted territory.

Sideloading Android Apps on Glass

Debug Mode, which you can enable from the Settings bundle under the Device info card, lets you install apps on your device outside of the normal MyGlass channel by copying Android Packages (APKs) onto the device. To get Android apps to run outside of MyGlass, you’ll need to enable Debug Mode and then have ADB running on a desktop or laptop computer while Glass is connected via its micro-USB cable.

§ To install native apps manually on Glass:

adb install -r <PACKAGE_NAME.apk>

§ To see what packages are installed on Glass:

adb shell pm list packages

§ To uninstall an app from Glass:

adb uninstall <PACKAGE_NAME.apk>

Note that installing apps onto Glass this way doesn’t at all give the user a heads-up about what permissions are required to run them.

Check out the ADB section on the Android Developers support site for a comprehensive list of commands and switches it can take. Further, you can use the ultra-cool ChromeADB extension, which is probably the easiest way to graphically manage the various packages installed on your headset.

Sharing Your Screen

Often, you’ll want to share what you see in Glass on other displays, whether for doing demos, working out UI/UX quirks with a Glassware project you’re building, helping a friend with tech support, or testing the system itself. In addition to MyGlass’s screencast feature that mirrors your screen through your phone, you’ve got a couple other options once you’ve connected Glass to a desktop computer via USB and enabled Debug Mode from the Settings bundle):

Live sharing

You can show your screen live on your computer by using the free Android Screen Monitor tool. Once you’ve downloaded it on your machine, enter the following at a command prompt:

----

java -jar asm.jar

----

Lance Nanek has a helpful post about setting up Android Screen Monitor or Droid@Screen, which is equally great.

Screen recording

You can also use the Android Debug Bridge (ADB) to record video of your screen usage for playback later, which is fantastic for social post sharing. Once you’ve got ADB installed on your computer, enter the following at a command prompt:

----

adb shell screenrecord /sdcard/<FILENAME>.mp4

----

Then, just start using Glass. Hit Ctrl-C when you’re done and a video file will be written to Glass in the directory that’s immediately accessible when you open Glass as a drive on your computer. You can also use ADB to download the captured video to your desktop by using the following:

----

adb shell pull /sdcard/<FILENAME>.mp4 downloaded_video.mp4

----

Android Studio

If you’re working with the GDK to build your Glassware, Android Studio includes the ability to capture screenshots or screencasts of your app in action.

For more about recording your screen, check out the ADB documentation.

Give Me JavaScript, or Give Me…

And all is not lost for those of you who just won’t go quietly into the night and accept the fact that JavaScript isn’t available within cards—there’s lots of interest in using the language on Glass. University of Maryland PhD candidate Brandyn White said, “To me, and ideal wearable computer would require almost no user input,” describing his motivation for cocreating WearScript, a JavaScript library that lets applications handle native operations on Glass through JavaScript. In addition to manipulating the timeline, WearScript gives you access to the Glass sensors and displays changes to them in real time. This results in development that’s on par with Android development, without all the complexities of native programming.

Similarly, developer Brenda Jin highlighted the ability to use PhoneGap to obtain real-time sensor data on Glass with JavaScript. In both cases, the libraries communicate with remote servers with impressive responsiveness.

So while we may not be able to do DOM or XMLHttpRequests directly from within cards or other types of client-side coding, there is work being done in our community by your fellow enthusiasts to give JavaScript a place. Check out their projects and get involved!

Officially Unofficial: Rooting Your Headset

This is the ultimate hack for our community. The feeding frenzy momentum of sideloading activity from the community led to one of the most anticipated sessions at Google I/O 2013, “Voiding Your Warranty: Hacking Glass”, which specifically addressed the hacking of Glass and the caveats that ensue. Not too long after Google publicly released the source code for the Google Glass kernel, which includes the core device drivers for the various hardware and system components. The kernel source and build instructions can be downloaded alongside a prebuilt GCC compiler and a prerooted bootloader. Google also mercifully provides the latest factory image so that if you brick your device you can always roll it back to the stock build.

However, Google issues a stern warning about hacking your device: “Rooting, unlocking, or flashing your Glass voids your warranty and can leave your device in an irrecoverable state. You will no longer receive OTA updates if you unlock or root your Glass. There is no guarantee that you will receive OTA updates even after flashing back to factory specifications. Proceed at your own risk.”

Rooting Glass is an advanced job that should only be undertaken by people that really know what they’re doing or whose projects have very specific requirements, so the letter of the law as defined by our friends in Mountain View is that if you do go this route, you’re on your own. That said, you can make Glass take on an entirely new personality by rooting it. Here’s how to do it, if you want to go where eagles dare.

You’ll need the file boot.img to be in the same directory as ADB. Next, perform these actions in sequence by typing the following commands at a command prompt:

§ Access the bootloader

§ Ensure your device is recognized:

adb devices

§ Reboot the device into bootloader mode:

adb reboot bootloader

§ Unlock the device and erase personal data

§ Ensure your device is recognized by fastboot:

fastboot devices

§ Execute OEM unlock

fastboot oem unlock

§ Swap out and override the boot partition

§ Flash the boot image:

fastboot flash boot boot.img

§ Reboot into normal state

§ Reboot the device again:

fastboot reboot

§ Access root mode

§ Gain root access:

adb root

If you need to restore the system software to its shipped state, make sure you have boot.img, recovery.img, and system.img in the same directory as ADB and type the following at the command prompt:

§ Ensure your device is recognized:

adb devices

§ Reboot into fastboot mode:

adb reboot-bootloader

§ Ensure your device is recognized by fastboot:

fastboot devices

§ Flash all of the IMG files:

fastboot flash boot boot.img

fastboot flash recovery recovery.img

fastboot flash system system.img

§ Erase user data and cache:

fastboot erase userdata

fastboot erase cache

§ Reboot the device:

fastboot oem lock

It’s also worth noting that even though we outline the steps here to root Glass (and certainly there are other resources in a variety of media formats that detail how to get it done), it’s still time well spent to take 36 minutes to (re)stream the I/O presentation and thoroughly consult Google’s documentation to make sure you do it right.

Enjoy, good luck, be careful…and have fun!

Living on the Bleeding Edge

Whew! See, we told you this was a fairly involved appendix with a lot of insider information. This appendix fully embraced that Glass isn’t merely an Android fork, but a product that stays true to its legacy from that OS, and proudly carries on the tradition of Android’s openness.

We showed you how to hack Glass, gain root access, and load Android applications on your headset—and how to revert everything back. We also made you aware of the fact that hacking your unit carries with it a certain amount of risk, but the payoff if you know what you’re doing can be really great.

Our parting shot would be that if you’ve got an idea, don’t dwell! Write it up, sketch it out, put a prototype together, and start talking about it! Hacking isn’t just a thing that coders do. There are wonderful resources in the maker community, and Maker Shed is an excellent resource to share and refine your ideas and see what others are doing.