• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
UBports Robot Logo UBports Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Kind of solved: Anbox: How to refresh Android gallery, "reboot" the sandbox?

Scheduled Pinned Locked Moved Support
5 Posts 3 Posters 567 Views 1 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      BodoW
      last edited by BodoW 1 May 2020, 13:31 31 Dec 2019, 20:21

      EDIT: Workaround was appended to the script (last three lines)
      Unfortunately WhatsApp is still neccesary to have as most people are totally incapable of grasping the concept of alternative programs. Well, here we go.
      As I'd like to sent a photo from time to time I wrote the script down below and have a cron job running to synchronize the Android DCIM directory with the UBports side every minute.
      This works great, however the Android side completely ignores any change in the DCIM directory. Only after a full reboot of the phone the files are in the gallery.

      So the question is: Do you have any idea how to force anbox to notice the changes? "Rebooting" anbox would be ok for the start. But how?

      import os
      import stat
      import shutil
      
      refresh_flag=0 
      ubports_dirname="/home/phablet/Pictures/com.ubuntu.camera/"
      android_dirname="/home/phablet/anbox-data/data/media/0/DCIM/"
      
      # Copy new images
      ubports_filenames=os.listdir(ubports_dirname)
      android_filenames=os.listdir(android_dirname)
      
      for ubports_filename in ubports_filenames:
      	try:
      		android_filenames.index(ubports_filename)
      	except: # If file is not yet in DCIM
      		if not stat.S_ISDIR(os.stat(ubports_dirname+ubports_filename).st_mode): # Ignore directories
      			shutil.copy(ubports_dirname+ubports_filename, android_dirname)
      			os.chown(android_dirname+ubports_filename, 1023, 1023)
      			refresh_flag=1
      
      # Delete deleted images
      ubports_filenames=os.listdir(ubports_dirname)
      android_filenames=os.listdir(android_dirname)
      
      for android_filename in android_filenames:
      	try:
      		ubports_filenames.index(android_filename)
      	except: # If file is deleted
      		if not stat.S_ISDIR(os.stat(android_dirname+android_filename).st_mode): # Ignore directories
      			os.remove(android_dirname+android_filename)
      			refresh_flag=1
      
      if refresh_flag==1: # If something changed "reboot" the anbox
      	os.popen("anbox-tool disable")
      	os.popen("anbox-tool enable")
      
      T 1 Reply Last reply 1 Jan 2020, 16:35 Reply Quote 1
      • I Offline
        Ingo
        last edited by 1 Jan 2020, 13:15

        IIRC you can use anbox-tool disable and anbox-tool enable. Haven't tried it myself as I currently have no phone running UT.

        B 1 Reply Last reply 2 Jan 2020, 22:21 Reply Quote 0
        • T Offline
          thrill_seeker @BodoW
          last edited by 1 Jan 2020, 16:35

          @BodoW I cannot help you, but I just can thank you, as I wanted to create the same script but did not have time 🙂 I will just copy yours.
          I also had the idea of creating a simple app that would include anbox "hack" features for UT, like this one, decide which android default apps to hide, etc.

          B 1 Reply Last reply 2 Jan 2020, 22:15 Reply Quote 0
          • B Offline
            BodoW @thrill_seeker
            last edited by 2 Jan 2020, 22:15

            @ThrillSeeker
            Good to know that someone else considers it useful too. Thank you.

            1 Reply Last reply Reply Quote 1
            • B Offline
              BodoW @Ingo
              last edited by 2 Jan 2020, 22:21

              Thank you @Ingo. I've added it to the code and it works.
              As this is the reboot approach I'd still leave the issue open as maybe someone might come up with the preferred refresh solution.

              1 Reply Last reply Reply Quote 1
              2 out of 5
              • First post
                2/5
                Last post