title: Preventing untrusted_app from accessing database
body: <p>I am running on Android 4.4.4 and have two processes. The security context of both the processes are :-</p>
  
  <pre><code>com.example.contentproviderexample having security context --&gt;  u:r:hm_phonebookaccess_app:s0  
  com.example.contentprovideruser having security context --&gt; u:r:untrusted_app:s0           
  </code></pre>
  
  <p>com.example.contentproviderexample is a content provider and the database which has security context as - </p>
  
  <pre><code>mydb --&gt; u:object_r:hm_phonebookaccess_data_file:s0 
  mydb-journal --&gt; u:object_r:hm_phonebookaccess_data_file:s0 
  </code></pre>
  
  <p>The above security context has been set using following rule - </p>
  
  <pre><code>type hm_phonebookaccess_app, domain;
  app_domain(hm_phonebookaccess_app)
  allow hm_phonebookaccess_app dalvikcache_data_file:file { write  setattr };
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file { read getattr open };
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir setattr;
  allow hm_phonebookaccess_app zygote:unix_stream_socket { getopt getattr };
  allow hm_phonebookaccess_app apk_data_file:dir getattr;
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir { write create add_name };
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file { write create setattr };
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir search;
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir { read open };
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file lock;
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:dir remove_name;
  allow hm_phonebookaccess_app hm_phonebookaccess_data_file:file unlink;
  allow installd hm_phonebookaccess_data_file:lnk_file create;
  </code></pre>
  
  <p>At run time, I am making setenforce as 1. </p>
  
  <p>My aim is to prevent any process which belongs to     domain-->untrusted_app from accessing the database which belongs to the domain-u:r:hm_phonebookaccess_app:s0</p>
  
  <p>NOTE: The content provider is exported as true.</p>
  
  <p>In the seapp_contexts, following entry has been made :-</p>
  
  <pre><code>user=_app domain=hm_phonebookaccess_app    name=com.example.contentproviderexample  type=hm_phonebookaccess_data_file
  </code></pre>
  
  <p>My observation is that in enforcement mode, the process "com.example.contentprovideruser" is able to access the database.</p>
  
  <p>Is there any way I can prevent "untrusted_app" domain from accessing that database? </p>
  
  <p>Thanks and Regards,
  Souvik</p>