From 3443cafa98c4c3608cf488d632fc1af4fc08fff1 Mon Sep 17 00:00:00 2001
From: Mark Salyzyn <salyzyn@google.com>
Date: Sat, 24 Oct 2015 16:20:18 -0700
Subject: [PATCH] FrameworksServicesTests: allow access to test.sys.boot.reason
 property

com.android.server.power.PowerManagerServiceTest#testGetLastShutdownReasonInternal due to "RuntimeException: failed to set system property"

W/roidJUnitRunner: type=1400 audit(0.0:6): avc: denied { write } for name="property_service" dev="tmpfs" ino=13178 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
W/libc    : Unable to set property "test.sys.boot.reason" to "shutdown,thermal": connection failed; errno=13 (Permission denied)

Had to use precise property definition as com.android.phone accesses
test properties as well.

Test: compile
Bug: 78245377
Change-Id: I2cc810846f8615f2a2fae8e0d4f41de585b7abd7
---
 private/compat/26.0/26.0.ignore.cil | 1 +
 private/compat/27.0/27.0.ignore.cil | 1 +
 private/platform_app.te             | 3 +++
 private/property_contexts           | 1 +
 public/property.te                  | 1 +
 5 files changed, 7 insertions(+)

diff --git a/private/compat/26.0/26.0.ignore.cil b/private/compat/26.0/26.0.ignore.cil
index 42071c9a4..f918b5b4d 100644
--- a/private/compat/26.0/26.0.ignore.cil
+++ b/private/compat/26.0/26.0.ignore.cil
@@ -98,6 +98,7 @@
     system_boot_reason_prop
     system_net_netd_hwservice
     system_update_service
+    test_boot_reason_prop
     thermal_service
     thermalcallback_hwservice
     thermalserviced
diff --git a/private/compat/27.0/27.0.ignore.cil b/private/compat/27.0/27.0.ignore.cil
index d74139a0c..fc00e9599 100644
--- a/private/compat/27.0/27.0.ignore.cil
+++ b/private/compat/27.0/27.0.ignore.cil
@@ -82,6 +82,7 @@
     storaged_data_file
     system_boot_reason_prop
     system_update_service
+    test_boot_reason_prop
     tombstone_wifi_data_file
     trace_data_file
     traced
diff --git a/private/platform_app.te b/private/platform_app.te
index b147bd9c2..31c5741a8 100644
--- a/private/platform_app.te
+++ b/private/platform_app.te
@@ -77,6 +77,9 @@ read_runtime_log_tags(platform_app)
 allow platform_app system_server:udp_socket {
         connect getattr read recvfrom sendto write getopt setopt };
 
+# allow platform apps to connect to the property service
+set_prop(platform_app, test_boot_reason_prop)
+
 ###
 ### Neverallow rules
 ###
diff --git a/private/property_contexts b/private/property_contexts
index 4433bdf7d..de09d4a60 100644
--- a/private/property_contexts
+++ b/private/property_contexts
@@ -71,6 +71,7 @@ ro.boot.bootreason      u:object_r:bootloader_boot_reason_prop:s0
 persist.sys.boot.reason u:object_r:last_boot_reason_prop:s0
 sys.boot.reason         u:object_r:system_boot_reason_prop:s0
 pm.                     u:object_r:pm_prop:s0
+test.sys.boot.reason    u:object_r:test_boot_reason_prop:s0
 
 # Boolean property set by system server upon boot indicating
 # if device owner is provisioned.
diff --git a/public/property.te b/public/property.te
index 5dd88dccb..de8e4bec9 100644
--- a/public/property.te
+++ b/public/property.te
@@ -51,6 +51,7 @@ type shell_prop, property_type, core_property_type;
 type system_boot_reason_prop, property_type;
 type system_prop, property_type, core_property_type;
 type system_radio_prop, property_type, core_property_type;
+type test_boot_reason_prop, property_type;
 type traced_enabled_prop, property_type;
 type vold_prop, property_type, core_property_type;
 type wifi_log_prop, property_type, log_property_type;
-- 
GitLab