通过 luajava 获取 Android 系统设置

我正在尝试在 XPrivacyLua 自定义挂钩中获取系统设置的值。

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

尝试 1: cls : ACCESSIBILITY_DISPLAY_INVERSION_ENABLED

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

尝试 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>

尝试 3: ACCESSIBILITY_DISPLAY_INVERSION_ENABLED

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

在 luajava 中获取 ACCESSIBILITY_DISPLAY_INVERSION_ENABLED 的正确语法是什么?

点赞
用户91769
用户91769

我的 getInt 函数的第一个参数是错误的。

它需要一个 ContentResolver,但我传递了一个 ApplicationContext

以下是正确的代码。

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
2019-02-03 21:00:07