Thursday, May 9, 2013

Media Transfer Porotocol (MTP) pada Android v4.0 ICS keatas

Sudah lama banget pengen tulis artikel tentang MTP pada Android

Sebuah standarisasi yang ditetapkan oleh Google sebagai protocol media sharing antara PC dan Handheld Android sejak versi 4.0 release.
Sebenarnya MTP sendiri sudah muncul /diperkenalkan sejak Honeycomb, namun baru dijadikan standard semenjak versi 4.0 ICS. (Correct me if Im wrong).
Protocol ini agak berbeda dari USB Mass Storage (UMS) yang kita kenal dulu. Dimana setiap kali mencolok kabel data ke PC, kita harus memilih sebagai Mass Storage Mode.


Sebenarnya jujur, saya lebih prefer menggunakan Mass Storage Mode dibandingkan dengan MTP karena terlihat lebih mudah dan cepat. Tapi ternyata MTP lebih memiliki banyak benefit dibandingkan dengan USB Storage.
MTP adalah bagian dari custom extension PTP (Picture Transfer Protocol) yang memperbolehkan transfer file berikut "metada" nya. Jika belum tau metada, metada semacam informasi kecil yang menempel pada file. Contoh simplenya seperti file MP3 yang memiliki informasi Judul, Artist, Genre, Album, dll.

Tahun 2008, USB Implementer Forum Device melakukan standarisasi MTP sebagai tipe USB Device.
Jika anda menyadari, MP3 Player, PDA jadul sangat mungkin mereka menggunakan MTP. Kamera digital juga menggunakan PTP sebagai perantaranya. Loh, berarti ini teknologi lama dong?
Tepat, ini adalah teknologi yang lama namun baru diperkenalkan oleh Android versi 3.0 dan dijadikan standard sejak versi 4.0.




Singkatnya MTP menghentikan OEM dan operator (jika di US ato negara lain smartphone dijual dan dicustom oleh operator seluler) memberikan banyak "storage space" (sisa memory hp) tapi memberikan sedikit ruang / space untuk aplikasi.
Berikut kutipan dari Dan Morril seorang Android Engineer
We didn't do this because we wanted to use ext3 (although that is a side benefit.) We did it because we wanted to be able to merge the "public shared storage" (i.e. for music and photos) with the internal private app storage.
We got tired of seeing OEMs include many GB of internal storage for music, while users were still running out of space for apps and data. This approach lets us merge everything on one volume, which is way better. 

Intinya adalah Ia ingin storage untuk penyimpanan aplikasi dan user storage (music, video, document, foto) pada smartphone bisa saling sharing, sehingga kapasitas memori benar benar digunakan seluruhnya, tidak terpisah-pisah.

Dengan MTP, maka tidak ada lagi kapasitas (storage) yang dianggap partisi lain sehingga penggunaan jd maksimal. Android juga jadi bisa menggunakan partisi ext3 (Linux partition type) yg performanya lebih cepat.

OEM bisa menyediakan slot SDCard external untuk penambahan kapasitas. Karena itu kita sering melihat akan ada keanehan atau kerusakan jika kita menginstall aplikasi di external memory dan ini biasanya terjadi pada widget ato core aplikasi seperti monitoring dll.

Just collecting notes and sharing.. Please let me know if there are wrong statements in this article or a copy-paste one.


Sumber: http://www.androidcentral.com

IP ( Ingress Protection ) Rating

Latar Belakang:
IP57 dan IP67. Dua kode tersebut pernah saya dengar dari sebuah spesifikasi smartphone Android seperti Motorola Defy, Xperia Active, dan yang terakhir adalah hp sangat powerful saat tulisan ini ditulis yaitu Sony Xperia Z.
Sejauh yang saya tau jarang ada hp dengan sertifikasi IP57 namun memiliki hardware yang sangat high end (Xperia Z)
Ok, cukup promosinya mungkin, yang saya mao dokumentasikan disini adalah tentang sertifikasi tersebut.

IP atau Ingress Protection adalah sertifikasi suatu benda terhadap material debu dan air.
IP rating ini di develop oleh European Committee for Electro Technical Standardization (CENELEC(NEMA IEC 60529 Degrees of Protection Provided by Enclosures - IP Code) yang biasanya ditunjukkan oleh 2 atau 3 angka.
contoh: IP56, dll
Angka pertama menunjukkan rating terhadap benda/objek padat (solid objects). Sedangkan angka kedua menunjukan rating terhadap objek cair.
Angka ketiga (jika ada) menunjukkan ketahanan terhadap benturan mekanik (biasanya dihilangkan karena tidak sesuai spesifikasi IEC.

Berikut tabelnya yang saya ambil dari sumber terpercaya (tanpa diterjemahkan lagi)
IP First number - Protection against solid objects
0  No special protection
1  Protected against solid objects over 50 mm, e.g. accidental touch by persons hands.
2  Protected against solid objects over 12 mm, e.g. persons fingers.
3  Protected against solid objects over 2.5 mm (tools and wires).
4  Protected against solid objects over 1 mm (tools, wires, and small wires).
5  Protected against dust limited ingress (no harmful deposit).
6  Totally protected against dust.
IP Second number - Protection against liquids
0  No protection.
1  Protection against vertically falling drops of water e.g. condensation.
2  Protection against direct sprays of water up to 15o from the vertical.
3  Protected against direct sprays of water up to 60o from the vertical.
4  Protection against water sprayed from all directions - limited ingress permitted.
5  Protected against low pressure jets of water from all directions - limited ingress.
6  Protected against temporary flooding of water, e.g. for use on ship decks - limited ingress permitted.
7  Protected against the effect of immersion between 15 cm and 1 m.
8  Protects against long periods of immersion under pressure.

IP Third number - Protection against mechanical impacts (commonly omitted, the third number is not a part of IEC 60529)
0  No protection.
1  Protects against impact of 0.225 joule (e.g. 150 g weight falling from 15 cm height).
2  Protected against impact of 0.375 joule (e.g. 250 g weight falling from 15 cm height).
3  Protected against impact of 0.5 joule (e.g. 250 g weight falling from 20 cm height).
4  Protected against impact of 2.0 joule (e.g. 500 g weight falling from 40 cm height).
5  Protected against impact of 6.0 joule (e.g. 1.5 kg weight falling from 40 cm height).
6  Protected against impact of 20.0 joule (e.g. 5 kg weight falling from 40 cm height).
Jika dilihat, Xperia Z memiliki sertifikasi IP57 maka:
5 --->  Terlindung dari debu dalam jumlah terbatas dan aman?
7 -->   Terlindung jika ditenggelamkan / didiamkan antara 15cm - 1meter kedalaman air

Semoga informasi berguna buat saya dan juga buat pembaca.
Thanks!

Source:
http://www.engineeringtoolbox.com
http://gerranek.blogspot.com
http://www.sensorsone.co.uk

Just collecting notes and sharing..

Sunday, May 5, 2013

Adding or Removing IDENTITY in existing Column SQL Server


Hi all, this is just a documented version from http://stackoverflow.com/ question and the best answers.

We can't alter the existing columns for identity.

Approach 1
We have 2 options,
1. Create a new table with identity and drop the existing table 
2. Create a new column with identity and drop the existing column 
Option 1:
you can retain the existing data values on the newly created identity column.
CREATE TABLE dbo.Tmp_Names
    (
      Id int NOT NULL
             IDENTITY(1, 1),
      Name varchar(50) NULL
    )
ON  [PRIMARY]
go
SET IDENTITY_INSERT dbo.Tmp_Names ON
go
IF EXISTS ( SELECT  *
            FROM    dbo.Names ) 
    INSERT  INTO dbo.Tmp_Names ( Id, Name )
            SELECT  Id,
                    Name
            FROM    dbo.Names TABLOCKX
go
SET IDENTITY_INSERT dbo.Tmp_Names OFF
go
DROP TABLE dbo.Names
go
Exec sp_rename 'Tmp_Names', 'Names'

Option 2:
you can’t retain the existing data values on the newly created identity column, The identity column will hold the sequence of number.
Alter Table Names Add Id_new Int Identity(1, 1)
Go
Alter Table Names Drop Column ID
Go
Exec sp_rename 'Names.Id_new', 'ID', 'Column'


Approach 2:

In SQL 2005 and above, there's a trick to solve this problem without changing the table's data pages. This is important for large tables where touching every data page can take minutes or hours. The trick also works even if the identity column is a primary key, is part of a clustered or non-clustered index, or other gotchas which can trip up the the simpler "add/remove/rename column" solution.
Here's the trick: you can use SQL Server's ALTER TABLE...SWITCH statement to change the schema of a table without changing the data, meaning you can replace a table with an IDENTITY with an identical table schema, but without an IDENTITY column. The same trick works to add IDENTITY to an existing column.
Normally, ALTER TABLE...SWITCH is used to efficiently replace a full partition in a partitioned table with a new, empty partition. But it can also be used in non-partitioned tables too.
I've used this trick to convert, in under 5 seconds, a column of a of a 2.5 billion row table from IDENTITY to a non-IDENTITY (in order to run a multi-hour query whose query plan worked better for non-IDENTITY columns), and then restored the IDENTITY setting, again in less than 5 seconds.
Here's a code sample of how it works.
 CREATE TABLE Test
 (
   id int identity(1,1),
   somecolumn varchar(10)
 );

 INSERT INTO Test VALUES ('Hello');
 INSERT INTO Test VALUES ('World');

 -- copy the table. use same schema, but no identity
 CREATE TABLE Test2
 (
   id int NOT NULL,
   somecolumn varchar(10)
 );

 ALTER TABLE Test SWITCH TO Test2;

 -- drop the original (now empty) table
 DROP TABLE Test;

 -- rename new table to old table's name
 EXEC sp_rename 'Test2','Test';

 -- see same records
 SELECT * FROM Test; 
This is obviously more involved than the solutions in other answers, but if your table is large this can be a real life-saver. There are some caveats:
you'll need to drop foreign keys before you do the switch and restore them after.
same for WITH SCHEMABINDING functions, views, etc.
new table's indexes need to match exactly (same columns, same order, etc.)
old and new tables need to be on the same file group.
only works on SQL Server 2005 or later
I previously believed that this trick only works on the Enterprise or Developer editions of SQL Server (because partitions are only supported in Enterprise and Developer versions), but Mason G. Zhwiti in his comment below says that it also works in SQL Standard Edition too. I assume this means that the restriction to Enterprise or Developer doesn't apply to ALTER TABLE...SWITCH.
There's a good article on TechNet detailing the requirements above.

Just collecting notes and sharing..
Source: stackoverflow.com