Intent.createFromParcel/battery

These hooks hide your current battery level and status by: - Reporting that the battery is not plugged, discharging, at 95%, 4200mV, 150Wh, 25°C, in good health, and with a charge count of 0. - Converting all POWER_CONNECTED events into POWER_DISCONNECTED. - Converting all BATTERY_LOW events into BATTERY_OK. Obviously, don't use on battery monitoring apps, but there's no reason to share battery levels with anyone else. Instructions: 1. Download these hooks: - BatteryManager.getIntProperty - BatteryManager.getLongProperty - BatteryManager.isCharging - Intent.createFromParcel/battery 2. Make sure that the Fif collection is enabled in XPL Pro. 3.a. In XPL, enable the (new) "Use battery" collection for apps for which you want to fake the battery status. 3.b. Or, in XPL Pro, enable the four hooks listed above. Changelog: v1 - 2018-10-09 First public release.

CollectionFif
GroupRead battery
NameIntent.createFromParcel/battery
AuthorFif
Version1
Updated (UTC)2018-10-10 01:36:15
Created (UTC)2018-10-10 01:34:39
Downloads932
Class nameandroid.content.Intent
Method nameCREATOR:createFromParcel
Parameter typesandroid.os.Parcel
Return typeandroid.content.Intent
Min SDK1
Max SDK999
Min APK0
Max APK2147483647
Excluded packages-
EnabledYes
OptionalNo
UsageYes
NotifyNo
Settings-
-- BatteryManager.* is a set of Lua hook definition designed to work                     
-- with XPrivacyLua.

-- BatteryManager.* is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.

-- BatteryManager.* is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.

function after(hook, param)
  local intent = param:getResult()
  if intent == nil then
    return false
  end

  local action = intent:getAction()
  if action == nil then
    return false
  end

  if action == 'android.intent.action.BATTERY_CHANGED' then

    local old_intent = tostring(intent)
    local clsBatteryMgr = luajava.bindClass('android.os.BatteryManager')
    local bundle = intent:getExtras()

    local scale =  bundle:getInt(clsBatteryMgr.EXTRA_SCALE, -1)
    if bundle:getInt(clsBatteryMgr.EXTRA_LEVEL, -1) ~= scale and scale >= 0 then
      bundle:putInt(clsBatteryMgr.EXTRA_LEVEL, math.floor(.95*scale))
    end
    bundle:remove(clsBatteryMgr.EXTRA_BATTERY_LOW)
    bundle:putInt(clsBatteryMgr.EXTRA_VOLTAGE, 4200)
    bundle:putInt(clsBatteryMgr.EXTRA_TEMPERATURE, 250)
    bundle:putInt(clsBatteryMgr.EXTRA_CHARGE_COUNTER, 0)
    bundle:putInt(clsBatteryMgr.EXTRA_STATUS, clsBatteryMgr.STATUS_GOOD)
    bundle:putInt(clsBatteryMgr.EXTRA_PLUGGED, 0)

    intent:replaceExtras(bundle)

    log('Deny ' .. old_intent .. ' -> ' .. tostring(intent))
    return true, old_intent, tostring(intent)

  elseif action == 'android.intent.action.ACTION_POWER_CONNECTED' then

    local old_intent = tostring(intent)
    intent:setAction('android.intent.action.ACTION_POWER_DISCONNECTED')
    log('Deny ' .. old_intent .. ' -> ' .. tostring(intent))
    return true, old_intent, tostring(intent)

  elseif action == 'android.intent.action.BATTERY_LOW' then

    local old_intent = tostring(intent)
    intent:setAction('android.intent.action.BATTERY_OKAY')
    log('Deny ' .. old_intent .. ' -> ' .. tostring(intent))
    return true, old_intent, tostring(intent)

  else
    return false
  end
end