您的位置:首页 > 移动开发 > Android开发

android developer tiny share-20160715

2016-07-15 15:20 453 查看
今天分享android的签名和UserId。

关于android的签名,包括一个证书和一个私钥。一个android签名用于标识一个app的开发者。

具体官方说明如下:

All APKs (.apk files) must be signed with a certificate whose private key is held by their developer. This certificate identifies the author of the application. The certificate does not need to be signed by a certificate authority; it is perfectly allowable,
and typical, for Android applications to use self-signed certificates. The purpose of certificates in Android is to distinguish application authors. This allows the system to grant or deny applications access to signature-level permissions and to grant or
deny an application's request to be given the same Linux identity as another application.

另外,说一下app和Linux的UserId。

在安装时,android系统会为每个app分配一个独立的Linux User ID,在同一台手机上,每个app的Linux User ID都不同。

两个不同的app,通常不能运行在同一进程中,因为它们的User ID不同。但是,你可以在AndroidManifest.xml中指定sharedUserId属性来使得两个app使用同样的User ID,这样,他们就可以运行在同一个进程中,进而由了文件访问等权限。

具体的官方说明如下:

At install time, Android gives each package a distinct Linux user ID. The identity remains constant for the duration of the package's life on that device. On a different device, the same package may have a different UID; what matters is that each package
has a distinct UID on a given device.

Because security enforcement happens at the process level, the code of any two packages cannot normally run in the same process, since they need to run as different Linux users. You can use the sharedUserId attribute in the AndroidManifest.xml's manifest tag
of each package to have them assigned the same user ID. By doing this, for purposes of security the two packages are then treated as being the same application, with the same user ID and file permissions. Note that in order to retain security, only two applications
signed with the same signature (and requesting the same sharedUserId) will be given the same user ID.

Any data stored by an application will be assigned that application's user ID, and not normally accessible to other packages. When creating a new file with getSharedPreferences(String, int), openFileOutput(String, int), or openOrCreateDatabase(String, int,
SQLiteDatabase.CursorFactory), you can use the MODE_WORLD_READABLE and/or MODE_WORLD_WRITEABLE flags to allow any other package to read/write the file. When setting these flags, the file is still owned by your application, but its global read and/or write
permissions have been set appropriately so any other application can see it.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息