src/power/android/SDL_syspower.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 16 Feb 2013 13:33:58 -0800
changeset 6887 78ad5efd6786
parent 6450 cf62de5b978f
child 7164 893f7ef37f3d
permissions -rw-r--r--
Added license to Android power implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6887
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     1
/*
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     2
  Simple DirectMedia Layer
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     4
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     5
  This software is provided 'as-is', without any express or implied
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     7
  arising from the use of this software.
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     8
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    11
  freely, subject to the following restrictions:
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    12
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    14
     claim that you wrote the original software. If you use this software
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    16
     appreciated but is not required.
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    18
     misrepresented as being the original software.
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
78ad5efd6786 Added license to Android power implementation
Sam Lantinga <slouken@libsdl.org>
parents: 6450
diff changeset
    20
*/
6450
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#ifndef SDL_POWER_DISABLED
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#if SDL_POWER_ANDROID
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_power.h"
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "../../core/android/SDL_android.h"
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
SDL_bool
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
SDL_GetPowerInfo_Android(SDL_PowerState * state, int *seconds, int *percent)
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
{
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
    int battery;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
    int plugged;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
    int charged;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
    if (Android_JNI_GetPowerInfo(&plugged, &charged, &battery, seconds, percent) != -1) {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
        if (plugged) {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
            if (charged) {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
                *state = SDL_POWERSTATE_CHARGED;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
            } else if (battery) {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
                *state = SDL_POWERSTATE_CHARGING;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
            } else {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
                *state = SDL_POWERSTATE_NO_BATTERY;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
                *seconds = -1;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
                *percent = -1;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
            }
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
        } else {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
            *state = SDL_POWERSTATE_ON_BATTERY;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
        }
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
    } else {
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
        *state = SDL_POWERSTATE_UNKNOWN;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
        *seconds = -1;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
        *percent = -1;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    }
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    return SDL_TRUE;
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
}
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
#endif /* SDL_POWER_ANDROID */
cf62de5b978f Added missing Android source that was supposed to go with changeset 64a6297a8b93
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
#endif /* SDL_POWER_DISABLED */