Search code examples
androidandroid-6.0-marshmallowuser-data

How to add file correct way to under /data section of android AOSP Marshmallow at rombuild


I'm making Marshmallow AOSP rom and trying to add device_owner.xml to /data/system to provisioning application directly to device owner.

I have added one of .mk files following product copy files

 PRODUCT_COPY_FILES += abc/cba:data/system/device_owner.xml

file can be found under out/data/system/ but it doesn't seem to be included to the rom.

I have also tried to replace PRODUCT_COPY_FILES with

PRODUCT_PACKAGES += device_owner.xml

and made own Android.mk file for the file

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE = device_owner.xml
LOCAL_SRC_FILES = $(LOCAL_MODULE)
LOCAL_MODULE_CLASS = ETC
LOCAL_MODULE_PATH = $(TARGET_OUT_DATA)/system
include $(BUILD_PREBUILT)

still it's not include on rom.

i have read that data partition would be part of the userdata.img but file is not there either.

I have tried also to include device_owner.xml to different location like under /system/ and then copy it in init.rc file under post-fs-data phase

copy /system/abc/device_owner.xml /data/system/device_owner.xml
chown system system /data/system/device_owner.xml
chmod 0600 /data/system/device_owner.xml

File will be then correct location but for some reason chown command doesn't change owner and group to system. by default file has root owner and group.

Any idea how this could be done?

EDIT 1.

I have now made one solution for this.

I have made set_device_owner.sh file where i have

 #!/system/bin/sh

 chown system:system /data/system/device_owner.xml
 chmod 0600 /data/system/device_owner.xml

then i added one of .mk files following product copy files

 PRODUCT_COPY_FILES += abc/cba/device_owner.xml:/system/xbin/device_owner.xml
 PRODUCT_COPY_FILES += abc/cba/set_device_owner.sh:/system/xbin/set_device_owner.sh

and in init.rc i have under post-fs-data

copy /system/xbin/device_owner.xml /data/system/device_owner.xml
exec - root root -- /system/bin/sh ./system/xbin/set_device_owner.sh

Now this works but i would still like to know what would be correct or preferable way of doing it.

And i don't know why that copy and chown and chmod didn't work directly on init.rc


Solution

  • The AOSP build process cannot put files into the data directory, so I believe your solution is the correct one. You'll see that init.rc actually creates the data directory, and also doing a factory reset will clear /data. So as far as I can tell, there's no other good way to do this and nothing really wrong with your approach.

    The chmod command should work directly in the init.rc file though, not sure why it's not working for you, it's used multiple times elsewhere in the file.

    I just implemented this myself, and was able to do it without using a separate script. Here are the lines I added to my init.rc file at the end of the post-fs-data section:

    copy /system/device_owner.xml /data/system/device_owner.xml
    copy /system/device_policies.xml /data/system/device_policies.xml
    chmod 0600 /data/system/device_owner.xml
    chmod 0600 /data/system/device_policies.xml
    chown system system /data/system/device_owner.xml
    chown system system /data/system/device_policies.xml
    

    Note that I have PRODUCT_COPY_FILES in my device config to copy the files to /system on build, or this obviously wouldn't work.

    Also to prevent the message to the user about immersive mode that shows up the first time your app launches, you can add your package id to the def_immersive_mode_confirmations section in packages/SettingsProvider/res/values/default.xml using a device overlay. More info on that here: How does the Android source overlays work?. Though for whatever reason, although I appear to have my overlay setup correctly, it still shows the message and I don't have time to debug it right now as I've found most "simple" things with AOSP somehow just don't work and then eat up entire days figuring out the random thing I'm doing wrong... When I figure it out, I'll edit this answer confirming it works.

    EDIT: So turns out the overlay works fine. It's the documentation that's wrong... To disable the warning, use the value confirmed for the def_immersive_mode_confirmations section in packages/SettingsProvider/res/values/default.xml

    Here's the issue tracker post about it: https://issuetracker.google.com/issues/37093452#c1

    So you actually need this:

    <string name="def_immersive_mode_confirmations" translatable="false">confirmed</string>