Android content provider-create a content provider (implement the content provider permission)

Source: Internet
Author: User

The topic "security and permissions" comprehensively describes permissions and access to the Android system. The topic "Data Storage" also describes the impact of security and permissions on various storage types. The following briefly introduces several key points:

1. By default, the data files stored in the internal memory of the device are private to your applications and providers;

2. The sqlitedatabase you created is private to your applications and providers;

3. by default, data files stored in external storage are shared. You cannot use the content provider to restrict access to files in external storage, because other applications can use other API calls to read/write them;

4. For methods to open or create files or SQLite databases in the internal memory on the device, the read/write access is implicitly allocated to other applications. If you use an internal file or database as the resource library of your provider and grant it the "world-readable" or "world-writeable" access permission, the permissions you set for the providers' list files will not protect your data. For the default access to files and databases in the internal memory, you should not change this default setting for the memory of your provided device.

If you want to use the content provider permission to control access to your data, you should store your data in internal files, SQLite databases, or the cloud (such as remote servers) and keep these files and databases private to your applications.

Implement Permissions

Even if the underlying data is private, all applications can perform read and write operations on your providers'. By default, your providers' permissions are not set. To change this situation, use the attribute or sub-element of the <provider> element in your configuration file to set permissions for your providers. You can set the permissions applied to the whole provider, or for a table, or even for a record, or all three of them.

You can use one or more <permission> elements in the configuration file to define permissions for your provisioner. To make the permission unique to your provider, you must use a Java-style scope for the Android: Name attribute. For example, set the read permission: COM. example. App. provider. Permission. read_provider.

The following describes the scope of the provisioner permission, which gradually becomes more detailed from the permissions applied to the whole provisioner. Permissions with finer scopes always take precedence over those with larger scopes:

1. Single reader-level read/write permissions

This permission controls the read/write access of the entire provisioner. This permission is specified in the Android: Permission attribute of the <provider> element.

2. Separate provider-level read/write permissions

There is a read permission and a write permission for the entire provided server. You can specify the Android: readpermission and Android: writepermission attributes of the <provider> element respectively. They give priority to permission requirements through the Android: Permission attribute.

3. Path-level Permissions

Read, write, or read/write permissions for a content resource ID of your provider. You can use the <permission> sub-element of the <provider> element to specify each URI you want to control. You can specify the read/write permission, read permission, or write permission for each content resource ID you specify, or all three permissions. The read and write permissions take precedence over the read and write permissions. At the same time, the path-level permissions take precedence over the grant-level permissions.

4. Temporary Permissions

Even if the application does not have the required permissions, you can grant the application temporary access permissions. This temporary access permission feature reduces the number of permissions that an application must apply for in the list file. When you open the temporary permission, the application only needs the "persistent" permission of the provisioner for the data that is continuously accessed.

When you want to allow an External Image Viewer application to display image attachments in the providers', you need to consider this temporary permission when implementing an email provider and application. To make the image Viewer accessible without any permissions, you need to set temporary permissions for images identified by these resource IDs. Your email application needs this design so that the email application can send a Resource Identifier (URI) containing the photo when the user wants to display a photo) and the intent object marked with the permission to the image viewer. Then, the image viewer can query the email provider and obtain the photo, even if the viewer does not have the read permission of the usual provider.

To enable temporary permissions, you can set the Android: granturipermissions attribute of the <provider> element, or add one or more <grant-Uri-Permission> sub-elements to the <provider> element. If you use temporary permissions, you must call the context. revokeuripermission () method whenever you delete the Resource Identifier (URI) associated with the temporary permissions of the provider.

The value of the temporary permission attribute (Android: granturipermissions) determines how much content you provide is accessible. If this attribute is set to true, the system will grant temporary permissions to the whole provider, which will overwrite any other permissions applied for at the provider or path level.

If the attribute Android: granturipermissions is set to false, you must add the <grant-Uri-Permission> sub-element to the <provider> element. Each sub-element specifies one or more content resource IDs to be granted temporary access permissions.

To delegate temporary access permissions to an application, the intent object must contain the flag_grant_read_uri_permission or flag_grant_write_uri_permission identifier, or both. Use setflags () to set these tags.

If the Android: granturipermissions attribute does not appear, it is assumed that its value is false.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.