[Xperia Z4/Z3+ Original Android Development] DiscMan55:
[MENTION=6979267]nailyk[/MENTION]

I got encryption working (apparently Sony Z3+ doesn't support File Based Encryption. It is always Full Disk Encryption, same as marshmallow) and my TWRP is able to decrypt it with no problems.

It needs the following selinux rules:

allow vold tee_prop:file { getattr open read };
allow vold firmware_file:file { getattr open read };

But again I face the problem of modem failing and getting No sim card when encryption is enabled, I tried adb logcat -b radio and got the attached log.

From the log there seems to be a failure very early in the process:

01-02 05:06:10.521 498 498 D RILD : **RIL Daemon Started**
01-02 05:06:10.521 498 498 D RILD : **RILd param count=3**
01-02 05:06:10.567 517 517 D RILD : **RIL Daemon Started**
01-02 05:06:10.567 517 517 D RILD : **RILd param count=1**
01-02 05:06:10.905 517 517 D RILD : RIL_Init argc = 5 clientId = 0
01-02 05:06:10.910 517 517 E RILQ : log to /data/misc/radio/ril_log for QCRIL logging is not enabled
01-02 05:06:10.998 498 498 D RILD : RIL_Init argc = 5 clientId = 2
01-02 05:06:10.999 498 498 E RILQ : log to /data/misc/radio/ril_log for QCRIL logging is not enabled
01-02 05:06:13.019 498 498 E RILQ : (1/498): RIL[1][rild] qcril_db_sqlite3_exec: sql_stmt select VALUE from qcril_properties_table where PROPERTY='dbmigration'
01-02 05:06:13.020 498 498 E RILQ : (1/498): RIL[1][rild] qcril_db_sqlite3_exec: Operation failed 1 no such table: qcril_properties_table
01-02 05:06:13.020 498 498 E RILQ : (1/498): RIL[1][rild] qcril_db_query_properties_table: Could not query 1
01-02 05:06:13.020 517 517 E RILQ : (0/517): RIL[0][rild] qcril_db_sqlite3_exec: sql_stmt select VALUE from qcril_properties_table where PROPERTY='dbmigration'
01-02 05:06:13.020 517 517 E RILQ : (0/517): RIL[0][rild] qcril_db_sqlite3_exec: Operation failed 1 no such table: qcril_properties_table
01-02 05:06:13.020 517 517 E RILQ : (0/517): RIL[0][rild] qcril_db_query_properties_table: Could not query 1
01-02 05:06:13.043 517 517 I RILQ : (0/517):RIL[0][rild] qmi_ril_qmi_client_pre_initialization_acquire: entry
01-02 05:06:13.044 517 517 I RILQ : (0/517):RIL[0][rild] qmi_ril_qmi_client_pre_initialization_acquire: exit
01-02 05:06:13.052 517 517 I RILQ : (0/517):RIL[0][rild] void settingsd_client_start(): Starting settingsd client thread
01-02 05:06:13.052 517 517 I RILQ : (0/517):RIL[0][rild] void settingsd_client_start(): After starting the settingsd client thread
01-02 05:06:13.052 517 857 I RILQ : (0/517):RIL[0] void main_loop_thread(): main_loop_thread started
01-02 05:06:13.052 517 857 V use-Rlog/RLOG-RILQ: [359]> void main_loop_thread(): Starting main Loop thread for settings client
01-02 05:06:13.053 517 857 E use-Rlog/RLOG-RILQ: [359]Unable to start settings client
01-02 05:06:13.053 517 857 V use-Rlog/RLOG-RILQ: [359]< void main_loop_thread():
01-02 05:06:13.058 517 605 W RILC : RIL_onUnsolicitedResponse called before RIL_register
01-02 05:06:13.058 517 517 D RILD : RIL_Init rilInit completed
01-02 05:06:13.058 517 517 I RILC : SIM_COUNT: 1
01-02 05:06:13.058 517 517 E RILC : RIL_register: RIL version 13
01-02 05:06:13.058 517 517 I RILC : s_registerCalled flag set, 1
01-02 05:06:13.058 517 517 I RILC : Start to listen RIL_SOCKET_1
01-02 05:06:13.058 517 517 D RILD : RIL_Init RIL_register completed
01-02 05:06:13.058 517 517 D RILD : RIL_register_socket started
01-02 05:06:13.059 517 517 D RIL_UIM_SOCKET: Adding socket with id: 0
01-02 05:06:13.059 517 517 D RILD : RIL_register_socket completed
01-02 05:06:13.059 517 517 D RILD : RIL_Init starting sleep loop
01-02 05:06:13.061 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_lte_direct_disc_pack_msg_tag: encoding the MsgHeader
01-02 05:06:13.538 496 496 W SSLM : HIGH: SIM: [17/04/22 19:44:18]: 8079: mmgsdi.c: MMGSDI_CARD_INSERTED_EVT (slot_id=0x1)
01-02 05:06:13.672 496 496 W SSLM : HIGH: SIM: [17/04/22 19:44:18]: 7971: mmgsdi.c: MMGSDI_PIN1_EVT (slot_id=0x1, status=0x1)
01-02 05:06:13.674 496 496 W SSLM : HIGH: SIM: [17/04/22 19:44:18]: 7988: mmgsdi.c: MMGSDI_PIN2_EVT (slot_id=0x1, status=0x1)
01-02 05:06:14.039 498 498 I RILQ : (1/498):RIL[1][rild] qmi_ril_qmi_client_pre_initialization_acquire: entry
01-02 05:06:14.039 498 498 I RILQ : (1/498):RIL[1][rild] qmi_ril_qmi_client_pre_initialization_acquire: exit
01-02 05:06:14.041 498 498 I RILQ : (1/498):RIL[1][rild] void settingsd_client_start(): Starting settingsd client thread
01-02 05:06:14.042 498 498 I RILQ : (1/498):RIL[1][rild] void settingsd_client_start(): After starting the settingsd client thread
01-02 05:06:14.043 498 924 I RILQ : (1/498):RIL[1] void main_loop_thread(): main_loop_thread started
01-02 05:06:14.043 498 924 V use-Rlog/RLOG-RILQ: [39c]> void main_loop_thread(): Starting main Loop thread for settings client
01-02 05:06:14.044 498 498 D RILD : RIL_Init rilInit completed
01-02 05:06:14.044 498 498 I RILC : SIM_COUNT: 1
01-02 05:06:14.044 498 498 E RILC : RIL_register: RIL version 13
01-02 05:06:14.044 498 498 I RILC : s_registerCalled flag set, 1
01-02 05:06:14.044 498 498 I RILC : Start to listen RIL_SOCKET_1
01-02 05:06:14.044 498 498 D RILD : RIL_Init RIL_register completed
01-02 05:06:14.045 498 498 D RILD : RIL_register_socket started
01-02 05:06:14.045 498 498 D RIL_UIM_SOCKET: Adding socket with id: 0
01-02 05:06:14.045 498 498 E : Failed to listen on sap_uim_socket1 socket '-1': Bad file descriptor
01-02 05:06:14.045 498 498 D RILD : RIL_register_socket completed
01-02 05:06:14.045 498 498 D RILD : RIL_Init starting sleep loop
01-02 05:06:14.045 498 924 E use-Rlog/RLOG-RILQ: [39c]Unable to start settings client
01-02 05:06:14.045 498 924 V use-Rlog/RLOG-RILQ: [39c]< void main_loop_thread():
01-02 05:06:14.046 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_lte_direct_disc_pack_msg_tag: encoding the MsgHeader
01-02 05:06:14.071 498 680 I RILQ : (1/498):RIL[1][main] qmi_ril_qmi_client_pre_initialization_release: entry
01-02 05:06:14.072 498 680 I RILQ : (1/498):RIL[1][main] qmi_ril_qmi_client_pre_initialization_release: exit
01-02 05:06:14.089 517 605 I RILQ : (0/517):RIL[0][main] qmi_ril_qmi_client_pre_initialization_release: entry
01-02 05:06:14.090 517 605 I RILQ : (0/517):RIL[0][main] qmi_ril_qmi_client_pre_initialization_release: exit
01-02 05:06:14.127 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_init_core_client_handles: qcril_qmi_presence_init returned failure(-3)
01-02 05:06:14.130 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_init_core_client_handles: qcril_qmi_presence_init returned failure(-3)
01-02 05:06:14.203 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_nas_init: QCRIL_OPERATOR_NAME is persist.env.spec, property_name is persist.env.spec. Failed to get operator name
01-02 05:06:14.203 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_nas_init: QCRIL_OPERATOR_NAME is persist.env.spec, property_name is persist.env.spec. Failed to get operator name
01-02 05:06:14.210 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_gw_rscp]
01-02 05:06:14.210 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_gw_rssi]
01-02 05:06:14.210 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_l_snr]
01-02 05:06:14.210 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_l_rsrp]
01-02 05:06:14.210 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_l_rsrq]
01-02 05:06:14.210 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_gw_rscp]
01-02 05:06:14.210 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_gw_rssi]
01-02 05:06:14.210 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_l_snr]
01-02 05:06:14.210 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_l_rsrp]
01-02 05:06:14.210 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_nas_get_threshold_list: not property_get() key = [ro.sony.th_list_l_rsrq]

01-02 05:06:14.127 498 680 E RILQ : (1/498): RIL[1][main] qcril_qmi_init_core_client_handles: qcril_qmi_presence_init returned failure(-3)
01-02 05:06:14.130 517 605 E RILQ : (0/517): RIL[0][main] qcril_qmi_init_core_client_handles: qcril_qmi_presence_init returned failure(-3)

I think that is the root cause of the problem, I don't know how to troubleshoot this. Can I restart "RILQ" with strace ? where's the binary for it ?

Also there's also another missing sepolicy but seems unrelated (but maybe related to battery drain:

allow zygote self:capability sys_nice;

There's also avc failure for init-power-sh wanting dac_override (but I don't want to give this, seems like file permission problem) and logd also wants dac_override:

01-01 11:46:57.779 354 354 I logd : type=1400 audit(0.0:3): avc: denied { dac_override } for capability=1 scontext=u:r:logd:s0 tcontext=u:r:logd:s0 tclass=capability permissive=1
01-01 11:46:59.019 419 419 I init.qcom.power: type=1400 audit(0.0:4): avc: denied { dac_override } for capability=1 scontext=u:r:init-power-sh:s0 tcontext=u:r:init-power-sh:s0 tclass=capability permissive=1
04-22 04:25:34.449 2154 2154 I main : type=1400 audit(0.0:5): avc: denied { sys_nice } for capability=23 scontext=u:r:zygote:s0 tcontext=u:r:zygote:s0 tclass=capability permissive=1

It is not clear to me what is the file being accessed with wrong ownership for init-power-sh (corresponds to device/sony/ivy/rootdir/init.qcom.power.sh from context files).

Any ideas ?

EDIT: Forgot mention, I tried stop netmgrd and start netmgrd from adb shell but nothing happened, tried also stop rild and start rild. Maybe the command is wrong.