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

    How to change background image programatically?

    Scheduled Pinned Locked Moved App Development
    background
    9 Posts 3 Posters 282 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.
    • A Offline
      AdFundum
      last edited by

      Hello everyone,

      I am a noob, trying to become more familiar with making apps and i created a test project for myself in which i am trying to make an app that changes the background to a random image in a specific folder each hour of the day.

      This seemed like it should not be too difficult but I am running into some issues. I am currently messing around in an adb shell with gsettings and also trying dbus-send and gdbus with org.freedesktop.Accounts.User BackgroundFile but when i try to Set the value, it does not update since i don't have write ability. I am assuming this is due to sandboxing. Is there a recommended way of interacting with the system to change the background programatically?

      I tried looking through the documentation but I can't find anything that really describes any of this.

      brenno.almeidaB C 2 Replies Last reply Reply Quote 0
      • brenno.almeidaB Offline
        brenno.almeida @AdFundum
        last edited by

        @AdFundum did you find a command that works from the terminal/adb shell? If so, does that command work if you make your app unconfined?

        Its possible that UT does not have an app armor policy that fits your use case, and that's the cause of your problem. From the list of policy groups I cannot see anything that would allow a confined app to change the background image.

        https://docs.ubports.com/no/latest/appdev/platform/apparmor.html

        A 1 Reply Last reply Reply Quote 0
        • C Offline
          ChromiumOS-Guy @AdFundum
          last edited by

          @AdFundum i dont know about confined use but i know how to do it, its not a single command and has a couple of steps. look at lss background module its basically the how to for it.

          1 Reply Last reply Reply Quote 0
          • A Offline
            AdFundum @brenno.almeida
            last edited by AdFundum

            Hi, sorry for the late response, I don't have a lot of spare time so progress on this goes very slowly.

            @brenno.almeida

            Not yet, I now going to try running in the app directly because maybe the adb shell is sandboxed differently from an unconfined app.

            @ChromiumOS-Guy

            That is an interesting suggestion, I had not thought of it. When I try to interact via the command line with lomiri-system-settings I am getting errors, but I found the background plugin folder in the source code.
            https://gitlab.com/AdamSchrey/lomiri-system-settings/-/tree/main/plugins/background?ref_type=heads
            I am going to see if I can bruteforce it by copying the logic from the source code for my own app and running it unconfined.
            Probably won't work but I might learn something interesting in the attempt.

            C 1 Reply Last reply Reply Quote 0
            • C Offline
              ChromiumOS-Guy @AdFundum
              last edited by

              @AdFundum thats essentially what i did, ill upload my implemention once i get home to my laptop in roughly 3h.

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                AdFundum @ChromiumOS-Guy
                last edited by

                @ChromiumOS-Guy

                That would be awesome, thanks!

                C 1 Reply Last reply Reply Quote 0
                • C Offline
                  ChromiumOS-Guy @AdFundum
                  last edited by ChromiumOS-Guy

                  @AdFundum here is the code, it doesn't work yet for what i want it to do but the change background part works:
                  https://pastebin.com/EHuAkQvb

                  EDIT:
                  ignore the comment // for some reason lss goes stale and we don't see the new background. its an lss bug, the background will be set but if you have lss open on the background page while you set it it will not update you'll need to refresh the page (by going out and in again)

                  A 1 Reply Last reply Reply Quote 0
                  • A Offline
                    AdFundum @ChromiumOS-Guy
                    last edited by

                    @ChromiumOS-Guy

                    Amazing, I will take a look at it and see if I can get it to work as well. You are a hero!

                    C 1 Reply Last reply Reply Quote 0
                    • C Offline
                      ChromiumOS-Guy @AdFundum
                      last edited by ChromiumOS-Guy

                      @AdFundum no problem!

                      the process is basically 3 steps:

                      1. verify image/PATH
                      2. copy to lss wallpaper directory (so user can see the background in lss), this is optional if you don't care about the user being able to reset the background from lss its not necessary but still useful as a place the user wont casually delete unless they want the wallpaper gone.
                      3. send the correct dbus calls to set URI (from new PATH of step 2) then call update on two services via dbus calls.

                      EDIT: i think, or its close to that its been a month since i touched the background code in wallpaper.cpp

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • First post
                        Last post