2

I am trying to get the value of a system setting in a XPrivacyLua custom hook.

Settings.Secure | Android Developers #getInt()

function after(hook, param)
    local result = param:getResult()
    if result == null or result:getItemCount() == 0 then
        return false
    end
    -- 
    local context = param:getApplicationContext()
    local cls = luajava.bindClass('android.provider.Settings$Secure')
    local isColorInverted = cls:getInt(context, cls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
    if isColorInverted == 1 then
        return true
    end
    --
    local fake = result:newPlainText('XPrivacyLua', 'Private')
    param:setResult(fake)
    return true
end

Attempt 1: cls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED

local isColorInverted = cls:getInt(context, cls:ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- [string "script"]:9: function arguments expected

Attempt 2: cls.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED

local isColorInverted = cls:getInt(context, cls.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- Exception:
-- org.luaj.vm2.LuaError: script:9 no coercible public method at org.luaj.vm2.LuaValue.error(SourceFile:1041)
-- ...
-- <full stack trace>

Attempt 3: ACCESSIBILITY_DISPLAY_INVERSION_ENABLED

local isColorInverted = cls:getInt(context, ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
-- Same as attempt 2

What is the correct syntax in luajava to get the value of ACCESSIBILITY_DISPLAY_INVERSION_ENABLED?

Steven
  • 13,501
  • 27
  • 102
  • 146

1 Answers1

0

My first parameter to getInt was wrong.

It called for a ContentResolver and I passed it an ApplicationContext.

Below is the working code.

function after(hook, param)
    local result = param:getResult()
    if result == null or result:getItemCount() == 0 then
        return false
    end
    -- 
    local context = param:getApplicationContext()
    local cr = context:getContentResolver()
    local cls = luajava.bindClass('android.provider.Settings$Secure')
    local isColorInverted = cls:getInt(cr, ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)
    if isColorInverted == 1 then
        return true
    end
    --
    local fake = result:newPlainText('XPrivacyLua', 'Private')
    param:setResult(fake)
    return true
end
Steven
  • 13,501
  • 27
  • 102
  • 146