Tuesday, February 16, 2016

Android watch programming - Overview


    Using Android wearables, you can write applications for Android TV, Watch and glass applications - this article focuses on Android variables for SmartWatch. 
Since Wearables is built on top of Android most of the core features in Android works on Android watch as well. Using android Watch API you can create applicatins for different watch sizes such as round dial, or a square Dial Watch. Apart from creating the watch face you can also create notifications, synchronize data with the watch - send and receive data. 
The notifications that comes for the apps in the mobile is also received by the watch. If you close the message on one device, the message gets removed on the other device as well. 

 What can you do using an Android watch

  • Your phone notifications such as meeting, traffic update, weather update, music, reminders are automatically synched with Android watch.
  • You can control actions on your notifications / pages – such as open the meeting on the meeting notification or play/pause your music app from your watch.
  • Use voice commands to ask questions, initiate app, send / reply to an email, create meetings right from your watch – just like you do using your phone.

What can you do using Android wear API:

  •  Make applications for round and square structured watches.
  • Create new watch faces
  •  Act on wearable notifications
  •  Use voice message as an action.
  • Build Notification messages.
  • Send and receive data from/to the phone/ tablet using the Data layer API and the message API. This allows you to communicate with your phone wirelessly over Bluetooth
  • Detect location data on watches.



Basic Design principles:

  • Performance in loading the watch page: This should not take more than a couple of seconds as the user is not going to hold the wrist to see the page if it takes more than a couple of seconds. Hence avoid rich data and concentrate on the data that is going to be shown.
  • Do not cram the screen with too much information.
  •  Keep the android screen type in mind – round or square and design accordingly.
  •   Keep notifications to the minimum in case of watch. Show only important and required information in the watch. Use suggest notifications.
  • Omit too much text – use icons to convey what you want. For example you can display a cloud with snowy icon to show the weather status as snowy instead of the text “snowy”.
  • \Provide confirmation notifications whenever required. The user should know what he did what happened to the action he performed.
  •  Since wearable devices run on Bluetooth low energy devices, developers need to ensure they design the applications in such a way to not affect the battery. You have to consider the battery closely when 

            - you design watch faces and the data in them, how often they get refreshed
            - you use location based features.
  

Thursday, February 11, 2016

Getting started with Android watch programming


This article explains you how to create a project in android studio, and run them using the emulator. 

Steps:
1.       Create a new wearable project using the wizard in Android studio, Select “Phone and tablet” and “Watch” in the project type.

2.       You will find 2 projects in the android project – Mobile and wear.

a.       Mobile project should be installed in the mobile or tablet.
b.      Wear project should be installed in the watch.



3.       Since android watch comes in both round and square forms, we have 2 separate layout files –
app:rectLayout="@layout/rect_activity_main"
app:roundLayout="@layout/round_activity_main"

Only one of the layout is rendered depending upon the watch you choose.


4.       If you go to the design view of the the activity files, you will be able to choose the layout type and see the project you have created.

Round view layout (or) Square view





5.       Choose an Android virtual device which you want to run.
This again comes in different formats.




Create the AVD you want.




6.       If you have not installed the system image for the selected android version, you might need to download it first in your PC.


7.       You can now run the project you have created in the emulator


 




Tuesday, February 9, 2016

Blockchain - How it works

While the detailed functionality of how Blockchain works depends on the individual framework / tool you choose for implementing block chain.

Blockchain mainly consists of 2 components – the P2P network and the distributed database.

·         P2P network: A mechanism used by different computers in the network to communicate the change in the database. This change to the state may be called as transaction.
 o    This network consists of different nodes which are connected to each other and is decentralized from the other node.
o    If any node fails or shuts down, no problem, we still have the data and the processing happens on the other available node.
o    Since the data is available is available on any node, we cannot clearly tell from where the data is coming from, which is good since you cannot censor based on where the data is or who sent it.

·         Database: This is the distributed database which is present in different nodes in the network and it stores the entire history of the data.

o    As and when the users create transactions, the transactions are are added to the pool of pending transactions. The transactions are collected as blocks, and when it creates the block, the block stores the transactions in the same order in which it retrieves. A signature is placed on the block which is modified every time someone changes the transaction or tamper the transaction in the block. In this case, the block notifies all the other nodes that the tampering has happened.
o    The block also maintains a pointer to the previous block to maintain the history of changes happened in the Blockchain.

When a new message (transaction) is sent to the block chain, the following happens.

§  The message is sent to the nodes in the Blockchain. The message may be sent to any node(s). Each nodes sends the message to the neighbouring nodes.
§  Quickly the message gets distributed to different nodes in the network.
§  The Actual database which is distributed across different nodes.
§  The nodes in the Blockchain process the transaction and communicates that it is successful or failed.

How the nodes are processed, how many nodes process the transactions, how the bidding works depends on the Blockchain platform you choose.
Since Bitcoin is an implementation of Blockchain, we can see how bitcoin works at a high level.
-          A wants to send 5$ to B.
-          Every user has his own private key to prove his identity and create a signature. A get’s B’s public key and creates a transaction and send it to the Blockchain using the wallet application. A wallet is an app (may be mobile app) which knows the user as it has the private key and knows how to send the transaction to the Blockchain.
-          Bitcoin requires the signature of the user to prove the user of the account. The signature is created based on the private key of the user and the transactional message.
-          These signatures cannot be copied and reused since the signatures are unique to each transaction.
-          As and when the transactions occur, the transactions are sent to the pool of pending transactions (blocks) which also maintains the order in which it receives the transaction. The transactions execute in the same order in which it is received.
-          The bit coin miners (or participants) choose a transaction from the pending pool and try to solve a mathematical problem which they use to bid for processing the transaction.
-          The miner then verifies if A has enough bitcoin to make a transaction to B.
-          When the bitcoin miner is then choosen and validates the transaction, a small % of bitcoin is rewarded for the processing. Finally B’s account is updated with A’s transaction amount.
-          If someone tries to tamper the B’s public key to a different public key, then the block signature is modified and other nodes are notified of the tampered activity. Thus the system works even if one node fails or not trustable or slow.

Blockchain technologies


The Blockchain implementation can be public or private depending upon the use case:
There are many Blockchain technologies that can be categorized under Blockchain 2.0 protocol projects such as NXT, Master coin, ethereum, Bitshares, Blocksign, Codius.
While most of the projects in the Blockchain technologies seem to be solving a problem for a particular use case or adding as a new feature, Ethereum takes a different approach.
Ethereum is a platform and a programming language that helps users to build decentralized applications. It is a general purpose crypto currency platform that can run all blockchains and protocols Each node in the network runs a full EVM (Ethereum virtual machine) for smart contract execution.

A smart contract is a program written by Blockchain developers and pushed to the Ethereum which gets deployed in multiple nodes for execution. This internally uses peer to peer protocol and libraries to exchange information between different nodes. Multiple nodes bid for running the process and executed the contract. The information is shared between other nodes. If a node is tampered, the other nodes in the network is aware of this change. 

Blockchain and startups

Following are some of the startups who are using blockchain. 
  1. Ethereum: Ethereum is a decentralized platform   that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference. Ethereum also contains a programming language which developers can use to build their own Blockchain applications.

  2. 2.       tØ is a blockchain-based trading platform created by online retail giant Overstock which aims to revolutionise securities by making trade and settlement occur simultaneously using blockchain technology. 

    3.       OpenBazaar: Is a decentralized marketplace which tries to eliminate government and organizations that restricts free, censor transactions and get their own cut. 

    4.        Storj: Is a decentralized cloud storage service that stores data not in cloud servers, but in nodes using Blockchain technology and P2P protocols. Each file is shredded and encrypted and stored in different nodes and hence it is more secure. You can be sure that it is safe since the keys to read the file are in your pocket. The nodes participating in the network can earn more by renting their hard drive to store data, it’s like opening your own Hard drive hotel.  

    5.       Blockai: a Blockchain publishing platform which helps the authors of digital asset to create them, publish and claim ownership for the assets so that they can turn into monetizable assets. 

    6.       Lazooz: an attempt to implement real-time ridesharing, but without the company.

    7.       BlockCypher: helps developers to quickly build Blockchain applications using the framework webservices blockcypher provides. 

    8.       Filament: is trying to build the first decentralized IOT stack, which helps device to interact without a central server or authority. 

    9.       ShoCard: a virtual identity card platform which consumers use a mobile application which is built on top of Blockchain data layer. The shocard uses public/private key encryption and data hashing to store and exchange identity data. 

    10.   CloudPay: helps users to make mobile payments using Ethereum and digital currencies. 

Applications of Blockchain

Applications of Blockchain:

What can you do using Blockchain


  • Manage contracts in a smarter way by not depending upon one server or organization. With smart contracts, you can directly deal with your partners and store contracts and rules in blockchain network Smart contracts
  • Tracking products: You can track a product exactly where it originated from - say a food item can now be tracked where it was farmed from how it was maintained and this information can be stored in public.
  • Ownership details: You can store information like I am willing to buy your house for 1000$ on this date in block chain - it will be stored in this public ledger for everyone to see - you cannot go back and change this to 500$ or the date. 
  • Storing public records such as land & property titles, marriage certificates, death certificates, vehicle registrations, notarized documents etc.,
  • Identity: Identiy a person, thing by verifying data against the person. For example Onename.com is a Blockchain id registrar that links users and validate by using them using different ways – visit onename.com for more information. https://onename.com/deiveehan
  • Store identification records such as driver licences, ID cards, passports and voter registrations.
  • IOT – Internate of things:
    • Device to device transactions, for example the device such as television or washing machine can have its own identity and can make re-order, make transactions on its own. Who owns what device can be stored in Blockchain.
    •  Of course, Money transactions: Blockchain can help you in transferring money to another country as it will be faster and cheaper. With this technology it will be faster and cheaper. Bitcoin is already an implementation of Blockchain which helps users to transfer quickly without a middleman.

Some interesting links:

  • Lazooz – block chain based ride sharing platform.
  • Nasdaq share trade using Blockchain – read more
  • Smart contracts - youtube
  • IBM Adept’s POC demo shows how do they implement this technology to make devices do smart payments – View demo
  • Couple got married on Blockchain – read more
  • How block chain will change the real-estate market – Read more
  • Crowd funding using Blockchain: Blockchain based crowd funding: Blockchain-based crowdfunding is similar to traditional crowdfunding, however, collected funds are accounted for and tracked via a Blockchain – Read more



Blockchain - basics

A decentralized application is an application where the data required for processing is not owned by government or companies, but by individuals from different parts of the world, who get paid for lending their processing power to run those programs. 

Some of the main characteristics of a decentralized application include: 
  • Data may not be owned by a single company or an organization. 
  • Tamper proof: Once a transaction happens on a decentralized application, no one should be able to alter the data, and even if they do, it is not affected by that as many nodes does the processing. 
  • Data cannot be controlled, censored by a company or country. 
  • Data may not be limited to only monetary transactions, but can have any data such as ownership details. 
  • No need to trust a single node in the decentralized application. 


So what is Blockchain?

Blockchain is a technology that helps developers build decentralized applications – It allows two people or thing who does not know each other to trust and make transactions with each other. 

Blockchain is a distributed database that contains shared record of transactions that cannot be censored, tampered with, erased or duplicated. It’s a new way to store and record transactions. These transactions can be certificate of ownership of an item, bank's financial transaction, person's will information etc.

This distributed database is collaboratively maintained by peers on the network, called nodes. A node is a machine where the validation & processing happens. Individual nodes verify the sender and the transaction and approve them. This removes the need for a third party to intermediate. 

These nodes are stored in public which means this is not owned by a country or an organization. Users lend their processing power to process these data, in turn get their incentive for their processing power. 

The transactions involved can be anything from certificate of ownership of an item, bank's financial transaction, person's will information etc. 
  
Blockchain can be thought of as a public ledger which holds all important transactions that is stored in a distributed way. You can do a lot more with the Blockchain than exchange value. Once a transaction appears on the Blockchain, it is impossible to deny that it has happened. Hence it cannot be censored, tampered with, erased or duplicated. It is a technology that fundamentally influences the way trade ownership and trust has been functioning. 

Blockchain works well even when some of the operators are dishonest, some nodes run slowly or tampered. 

We will look more on block chain applications in the next article. 

Sunday, January 3, 2016

SAML explained

You might have seen lot of web sites / services you access requesting you to login with an login page that you have used before.

To understand SAML, you might need to understand the following terms.

Identity Provider (IP): The company / enterprise holding the user credentials.
Service provder (SP): The company providing the service - say salesforce.
User: the person going to use the service.

Traditionally the credentials are maintained by Identity provider, but the credentials are also maintained in the Service provider so that whenever the user tries to access the SP he is authenticated within the service provider itself.
You might have seen in some sites where they ask you to register with a username and password to access the service.

Now the problems of using this approach is:
- the service provider have to maintain the user credentials even though the user credentials are in the Identity provider.
- the user has to remember different user credientials for the IP and the SPs.
- The identity provider has to follow a cumbersome process of disconnecting the access to the SPs whenever the user goes out of the company or his roles changed.

How its solved.

Typically, the user requests access to the Service (SP), the SP redirects him to the Identity provider (IP), the user gets his userid and password validated from the Identity provider.
The Identity provider provides a token (a file which contains user information - but not password) to the service provider.
The service provider now knows that its a valid user and allows him to access the service.

Now using this approach, the SP dont have to maintain password, the user has to remember only one password, and its easy for IP to manage user information and he has control over the services.

Now what is SAML: 
SAML is the token we talked about. Its the XML based data format for exchanging user information between the Identity provider and the service provider.

When the user is authenticated by the IP, the user can then access the services with the token provided by the IP.

How long can the user access the service with the token provided by IP, what if the user goes out of the company.
The token issued by the IP also has the expiry time. Whenever the SP receives the token, it is valid only till the time, after that the service provider redirects back to the identity provider. The user has to get another token with a revised expiry time on the token.


What does SAML describe:
- describe the structure of the data.
- explains how the data should get transported between the IP and SP


How does communication happens between the IP and the SP:

In the above picture you can see the sequence flow how the user is authenticated and he is allowed to access the resource in SP. 

Friday, January 1, 2016

AWS Glacier - Overview

Glacier storage service is meant for storing archival data. It is best suited for data that is not frequently accessed.

It is priced very low when compared to S3. Accessing the object in glacier is very slow - for example, the checkout job can take several hours for data to be available.
Integrates will with S3 life cycle.
With glacier you dont have to worry about the server provisioning, you can store as much data as you want - as usual.

A single archive can be as large as 40 TB.

You can configure glacier to be like "Write once read many" to prevent losing data by mistake.
You can also set the data retrieval policies such as maximum retrieval rate. you can also see which users have accessed the vault over the last one month, or identify who deleted the data.

You can use AWS console or use the AWS SDK APIs to store data into Glacier.
you can also setup policies in S3 so that every month data is archived back from S3 to Glacier. AWS Import / export product can be used to accelerate moving large amount of data.

Pricing is based on how much data you are planning to store and how much time you are planing to retrieve. Data transfer costs and PUT requests also matters but its low.

For example, if you want to store 100GB of data with no retrieval, it might approximately cost 7 cents per month.
You can use the AWS calculator to calculate how much it is going to cost you based on your data requirements.


Amazon S3 - overview

S3 is a storage product from AWS to help users store documents such as pdfs, pngs and any other files. An object in S3 can be called as a single file.

Characteristics: 
- an object can be up to 5TB.
- you can encrypt data before saving into S3 and decrypt before downloading into your desk.
- supports unlimited data upload and multi-threaded uploads.
- High availability: Automatically stores data in multiple zones within your region.
- you can add policies to a bucket, for example you can say after 2 months of data upload, you can configure to move the data to another storage such as glacier.
- supports versioning of objects within S3, which means when you accidentally delete an object, you can recover by accessing old versions of the object.
- secured storage, which means you can be sure that only you can store or set priveleges that only you can access the data.
- you can store as much data you want, it will scale based on your needs.

What operations you can perform using S3. 
- CRUD operations on Bucket.
- you can choose your region/zone you want to store the data and use S3 APIs to store the data.
- you can send event notifications whenever someone uploads a data into an bucket.
- Can be integrated with other AWS services such as "whenever an object is loaded into a bucket, you can send the data into Kinesis".
- use S3 as a backup storage or host static files for your web page.
- perform disaster recovery of your systems by storing backup images in S3.
- host static web sites or files.

S3 pricing: 
- Storage cost: You pay approximately $0.03 for every GB for the first 1 TB
- Request pricing:
you pay $0.004 per 10,000 requests for all GET requests.
You pay $0.005 per 1,000 requests for all PUT, COPY, POST requests, delete requests are not priced.
- Data transfer pricing:
Data transfer in to S3 is not charged
Data transfer OUT to same region is not charged.
Data transfer OUT to another region or over to internet is charged, first 1 GB transfer is free, after that it will be charged at 9 cents per GB.

You can use the AWS calculator to approximately determine how much it will cost for the services you choose based on the data you provide.
http://calculator.s3.amazonaws.com/index.html

Full pricing information can be found here - https://aws.amazon.com/s3/pricing/

How do you operate on S3: 
- use the AWS console to operate on S3
- use AWS SDK, supports different languages such as Java, .net, python, php, nodejs, ruby. You can also use AWS mobile SDK to directly upload data into S3 from the mobile.

S3 FAQ: https://aws.amazon.com/s3/faqs/