0% found this document useful (0 votes)
16 views25 pages

Vision Mission of Department:: Android Battery Saver System.

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views25 pages

Vision Mission of Department:: Android Battery Saver System.

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Vision Mission Of Department:

Title: Android Battery Saver System..

Group Members:-
Name:-Nikita Chandrakant Panchal
Roll No:-112
Name:-Nikita Laxman Avchar
Roll No:-143
Content(Index)
 Project
Abstract---------------------------------------------------------------------------------
----------------------
 Problem
statement-------------------------------------------------------------------------------
---------------------
 Hardware
Requirements--------------------------------------------------------------------------
-------------------------------------------
 Software
Requirements--------------------------------------------------------------------------
-------------------------------------------
 Psesudo
Code------------------------------------------------------------------------------
--------------------------------------------------
 Tools and
Technology-----------------------------------------------------------------------------
-------------------------------------
 Proposed System design (UML)Use case
diagram---------------------------------------------------------------Activity
diagram Class diagram--------------------------------------------------------
Application
PROJECT ABSTRAC T

This System is an innovative Application allowing the System to take usage from Build
classes and put a list in front of the user for him to review. The List also
consists of the applications taking the battery usage and also determines the
battery level. If the Battery level is low and the consumption of apps is more
the system will trigger an alarm telling the user to force stop or close the
apps.
This System uses Android Studio as its front end and doesn’t use any backend
as this type of application doesn’t need one since it uses the data from the
phone itself and projects to the user.
So basically the system helps the user to refrain certain apps to consume
more battery power and drain it quickly and user can take some action

Introduction:

Battery Saver, Power Saving, or Power Saving Mode is a feature available on all Android
devices that aims to limit power consumption, so that your battery lasts a little longer until
you get to charge it again. When turned on, this feature can add another hour or two to
how much your battery lasts
The rapid development of technology has led to a shift in how we communicate with the world.
Computers themselves have also changed significantly since their inception, from analogue
machines, to large electromechanical computers and transistor computers. Nowadays, many people
own personal computers, varying from desktops to laptops. In addition, they are also using smaller,
portable computers such as tablets and smartphones. Each iteration of devices enabled us to
accomplish tasks that were previously not possible. The rise of smartphones has enabled us to
remain connec with everything, regardless of our location. They are capable of accessing the
internet, with applications ranging from social media networks to banking services. With over 3
billion users as of June 2014 [1], this technology has affected a significant portion of the world.
However, the smartphone itself was also developed through a series of iterations.
Problem Statement:
The smartphone can be viewed as an extension of the computer, allowing us to perform the same
tasks on a pocket-sized device. Developers have embraced this medium and created accessible
mobile equivalents of the online services that we use. In addition, they are also creating new,
unique applications by leveraging the variety of sensors on the device. However, they must
compensate for the lack of resources in comparison to traditional computers

Hardware Requirements:
 Processor :- i3

 Android phone with kitkat and higher

 Hard Disk :- 5GB or more

 RAM :- 1GB or more

Software Requirements:

 Operating System:-Window xp,window7


ultimate, enterprise)Android Studio
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the
"License");
* you may not use this file except in compliance with the
License.
* You may obtain a copy of the License at
*
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in
writing, software
* distributed under the License is distributed on an "AS
IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.
* See the License for the specific language governing
permissions and
* limitations under the License.
*/
package com. android. Server. power. Battery saver;

import android. Manifest;


import android. An notation. Null able;
import android. content. Broadcast Receiver;
import android. content. Context;
import and roid. content. Intent;
import android. content. IntentFilter;
import android. content. pm. Package Manager Internal;
import android. hardware. power. Mode;
import android. os. Battery Manager;
import android. os. Battery Saver Policy Config;
import android. os. Handler;
import android. os. Looper;
import android. os. Message;

import android. os. Power Manager;


import android. os. Power Manager Internal;
import android .os . Power Manager Internal.
Low Power Mode Listener;
import android. Os. Power Save State;
import android. os. User Handle;
import android. util. Slog;

import com. android. internal. R;


import com. android. internal. An notations. Guarded By;
import com. android. internal. An notations. Visible For
Testing;
import com. android. server. Event Log Tags;
import com. android. server. Local Services;
import com. android. server. power. Power Manager Service;
import
com.android.server.power.batterysaver.BatterySaverPolicy.Ba
tterySaverPolicyListener;
import
com.android.server.power.batterysaver.BatterySaverPolicy.Po
licy;
import
com.android.server.power.batterysaver.BatterySaverPolicy.Po
licyLevel;
import
com.android.server.power.batterysaver.BatterySavingStats.Ba
tterySaverState;
import
com.android.server.power.batterysaver.BatterySavingStats.Do
zeState;
import
com.android.server.power.batterysaver.BatterySavingStats.In
teractiveState;
import
com.android.server.power.batterysaver.BatterySavingStats.Pl
ugState;

import java. util. Array List;


import java. util. Objects;
import java. util. Optional;

/**
* Responsible for battery saver mode transition logic.
*
* IMPORTANT: This class shares the power manager lock,
which is very low in the lock hierarchy.
* Do not call out with the lock held. (Settings provider
is okay.)
*/
public class Battery Saver Controller implements Battery
Saver Policy Listener {
static final String TAG = "Battery Saver Controller";

static final boolean DEBUG = Battery Saver Policy.


DEBUG;

private final Object m Lock;


private final Context m Context;
private final My Handler m Handler;

private Power Manager m Power Manager;

private final Battery Saver Policy m Battery Saver


Policy;
private final Battery Saving Stats m Battery Saving
Stats;

@Guarded By ("m Lock")


private final Array List<Low Power Mode Listener> m
Listeners = new Array List<>();

/** * Do not access directly; always use {@link


#set Full Enabled Locked}
* and {@link #get Full Enabled Locked}
*/
@Guarded By ("m Lock")
private boolean m Full Enabled Raw;

/**
* Do not access directly; always use {@link #set
Adaptive Enabled Locked} and
* {@link #get Adaptive Enabled Locked}.
*/
@Guarded By ("m Lock")
private boolean m Adaptive Enabled Raw;

@Guarded By ("m Lock")


private boolean m Is Plugged In;

/**
* Whether full was previously enabled or not; only for
the event logging. Only use it from
* {@ link # handle Battery Saver State Changed}.
*/
private boolean m Full Previously Enabled;

/**
* Whether adaptive was previously enabled or not; only
for the event logging. Only use it from
* {@ link # handle Battery Saver State Changed}.
*/
private boolean m Adaptive Previously Enabled;

@Guarded By ("m Lock")


private boolean m Is Interactive;

/**
* Package name that will receive an explicit manifest
broadcast for
* {@link Power Manager #ACTION_POWER
_SAVE_MODE_CHANGED}. It's {@code null} if it hasn't been
* retrieved yet.
*/
@Null able
private Optional<String> m Power Save Mode Changed
Listener Package;

public static final int REASON_PERCENTAGE_AUTOMATIC_ON


= 0;
public static final int REASON_PERCENTAGE_AUTOMATIC_OFF
= 1;
public static final int REASON_MANUAL_ON = 2;
public static final int REASON_MANUAL_OFF = 3;
public static final int REASON_STICKY_RESTORE = 4;
public static final int REASON_INTERACTIVE_CHANGED = 5;
public static final int REASON_POLICY_CHANGED = 6;
public static final int REASON_PLUGGED_IN = 7;
public static final int REASON_SETTING_CHANGED = 8;
public static final int
REASON_DYNAMIC_POWER_SAVINGS_AUTOMATIC_ON = 9;
public static final int
REASON_DYNAMIC_POWER_SAVINGS_AUTOMATIC_OFF = 10;
public static final int
REASON_ADAPTIVE_DYNAMIC_POWER_SAVINGS_CHANGED = 11;
public static final int REASON_TIMEOUT = 12;
public static final int
REASON_FULL_POWER_SAVINGS_CHANGED = 13;

static String reason To String(int reason) {


switch (reason) {
case Battery Saver Controller.
REASON_PERCENTAGE_AUTOMATIC_ON:
return "Percentage Auto ON";
case Battery Saver Controller.
REASON_PERCENTAGE_AUTOMATIC_OFF:
return "Percentage Auto OFF";
case BatterySaverController.REASON_MANUAL_ON:
return "Manual ON";
case BatterySaverController.REASON_MANUAL_OFF:
return "Manual OFF";
case
BatterySaverController.REASON_STICKY_RESTORE:
return "Sticky restore";
case
BatterySaverController.REASON_INTERACTIVE_CHANGED:
return "Interactivity changed";
case
BatterySaverController.REASON_POLICY_CHANGED:
return "Policy changed";
case BatterySaverController.REASON_PLUGGED_IN:
return "Plugged in";
case
BatterySaverController.REASON_SETTING_CHANGED:
return "Setting changed";
case
BatterySaverController.REASON_DYNAMIC_POWER_SAVINGS_AUTOMAT
IC_ON:
return "Dynamic Warning Auto ON";
case
BatterySaverController.REASON_DYNAMIC_POWER_SAVINGS_AUTOMAT
IC_OFF:
return "Dynamic Warning Auto OFF";
case
BatterySaverController.REASON_ADAPTIVE_DYNAMIC_POWER_SAVING
S_CHANGED:
return "Adaptive Power Savings changed";
case BatterySaverController.REASON_TIMEOUT:
return "timeout";
case
BatterySaverController.REASON_FULL_POWER_SAVINGS_CHANGED:
return "Full Power Savings changed";
default:
return "Unknown reason: " + reason;
}
}

private final BroadcastReceiver mReceiver = new


BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent
intent) {
if (DEBUG) {
Slog.d(TAG, "onReceive: " + intent);
}
switch (intent.getAction()) {
case Intent.ACTION_SCREEN_ON:
case Intent.ACTION_SCREEN_OFF:
if (!isPolicyEnabled()) {
updateBatterySavingStats();
return; // No need to send it if
not enabled.
}
// We currently evaluate state only for
CPU frequency changes.
// Don't send the broadcast, because we
never did so in this case.

mHandler.postStateChanged(/*sendBroadcast=*/ false,
REASON_INTERACTIVE_CHANGED);
break;
case Intent.ACTION_BATTERY_CHANGED:
synchronized (mLock) {
mIsPluggedIn =
(intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0);
}
// Fall-through.
case
PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED:
case
PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED:
updateBatterySavingStats();
break;
}
}
};

/**
* Constructor.
*/
public BatterySaverController(Object lock, Context
context, Looper looper,
BatterySaverPolicy policy, BatterySavingStats
batterySavingStats) {
mLock = lock;
mContext = context;
mHandler = new MyHandler(looper);
mBatterySaverPolicy = policy;
mBatterySaverPolicy.addListener(this);
mBatterySavingStats = batterySavingStats;

PowerManager.invalidatePowerSaveModeCaches();
}

/**
* Add a listener.
*/
public void addListener(LowPowerModeListener listener)
{
synchronized (mLock) {
mListeners.add(listener);
}
}

/**
* Called by {@link PowerManagerService} on system
ready, *with no lock held*.
*/
public void systemReady() {
final IntentFilter filter = new
IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BATTERY_CHANGED);

filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANG
ED);

filter.addAction(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE
_CHANGED);
mContext.registerReceiver(mReceiver, filter);

mHandler.postSystemReady();
}

private PowerManager getPowerManager() {


if (mPowerManager == null) {
mPowerManager =

Objects.requireNonNull(mContext.getSystemService(PowerManag
er.class));
}
return mPowerManager;
}

@Override
public void
onBatterySaverPolicyChanged(BatterySaverPolicy policy) {
if (!isPolicyEnabled()) {
return; // No need to send it if not enabled.
}
mHandler.postStateChanged(/*sendBroadcast=*/ true,
REASON_POLICY_CHANGED);
}
private class MyHandler extends Handler {
private static final int MSG_STATE_CHANGED = 1;

private static final int ARG_DONT_SEND_BROADCAST =


0;
private static final int ARG_SEND_BROADCAST = 1;

private static final int MSG_SYSTEM_READY = 2;

public MyHandler(Looper looper) {


super(looper);
}

void postStateChanged(boolean sendBroadcast, int


reason) {
obtainMessage(MSG_STATE_CHANGED,
sendBroadcast ?
ARG_SEND_BROADCAST :
ARG_DONT_SEND_BROADCAST, reason).sendToTarget();
}

public void postSystemReady() {


obtainMessage(MSG_SYSTEM_READY, 0,
0).sendToTarget();
}

@Override
public void dispatchMessage(Message msg) {
switch (msg.what) {
case MSG_STATE_CHANGED:
handleBatterySaverStateChanged(
msg.arg1 == ARG_SEND_BROADCAST,
msg.arg2);
break;
}
}
}

/** Enable or disable full battery saver. */


@VisibleForTesting
public void enableBatterySaver(boolean enable, int
reason) {
synchronized (mLock) {
if (getFullEnabledLocked() == enable) {
return;
}
setFullEnabledLocked(enable);

if (updatePolicyLevelLocked()) {

mHandler.postStateChanged(/*sendBroadcast=*/ true, reason);


}
}
}

private boolean updatePolicyLevelLocked() {


if (getFullEnabledLocked()) {
return
mBatterySaverPolicy.setPolicyLevel(BatterySaverPolicy.POLIC
Y_LEVEL_FULL);
} else if (getAdaptiveEnabledLocked()) {
return
mBatterySaverPolicy.setPolicyLevel(BatterySaverPolicy.POLIC
Y_LEVEL_ADAPTIVE);
} else {
return
mBatterySaverPolicy.setPolicyLevel(BatterySaverPolicy.POLIC
Y_LEVEL_OFF);
}
}

BatterySaverPolicyConfig getPolicyLocked(@PolicyLevel
int policyLevel) {
return
mBatterySaverPolicy.getPolicyLocked(policyLevel).toConfig()
;
}

/**
* @return whether battery saver is enabled or not.
This takes into
* account whether a policy says to advertise isEnabled
so this can be propagated externally.
*/
public boolean isEnabled() {
synchronized (mLock) {
return getFullEnabledLocked() ||
(getAdaptiveEnabledLocked()
&&
mBatterySaverPolicy.shouldAdvertiseIsEnabled());
}
}

/**
* @return whether battery saver policy is enabled or
not. This does not take into account
* whether a policy says to advertise isEnabled, so
this shouldn't be propagated externally.
*/
private boolean isPolicyEnabled() {
synchronized (mLock) {
return getFullEnabledLocked() ||
getAdaptiveEnabledLocked();
}
}

boolean isFullEnabled() {
synchronized (mLock) {
return getFullEnabledLocked();
}
}

boolean setFullPolicyLocked(BatterySaverPolicyConfig
config, int reason) {
return
setFullPolicyLocked(BatterySaverPolicy.Policy.fromConfig(co
nfig), reason);
}

boolean set Full Policy Locked(Policy policy, int


reason) {
if (m Battery Saver Policy. set Full Policy
Locked(policy)) {
m Handler. post State Changed(/*send
Broadcast=*/ true, reason);
return true;
}
return false;
}

boolean is Adaptive Enabled() {


synchronized (m Lock) {
return get Adaptive Enabled Locked();
}
}
boolean set Adaptive Policy Locked (Battery Saver
Policy Config config, int reason) {
return set
AdaptivePolicyLocked(BatterySaverPolicy.Policy.fromConfig(c
onfig), reason);
}

boolean set Adaptive Policy Locked (Policy policy, int


reason) {
if (m Battery Saver Policy. Set Adaptive Policy
Locked (policy)) {
m Handler. Post State Changed (/*send
Broadcast=*/ true, reason);
return true;
}
return false;
}

boolean reset Adaptive Policy Locked (int reason) {


if (m Battery Saver Policy. reset Adaptive Policy
Locked()) {
m Handler. post State Changed (/*send
Broadcast=*/ true, reason);
return true;
}

return false;
}

boolean set Adaptive Policy Enabled Locked(boolean


enabled, int reason) {
if (get Adaptive Enabled Locked() == enabled) {
return false;
}
Set Adaptive Enabled Locked (enabled);
if (update Policy Level Locked()) {
m Handler. Post State Changed (/*send
Broadcast=*/ true, reason);
return true;
}
return false;
}

/** @return whether device is in interactive state. */


public boolean is Interactive() {
synchronized (m Lock) {
return m Is Interactive;
}
}

/** @return Battery saver policy. */


public Battery Saver Policy get Battery Saver Policy()
{
return m Battery Saver Policy;
}

/**
* @return true if launch boost should currently be
disabled.
*/
public boolean is Launch Boost Disabled () {
return is Policy Enabled () && m Battery Saver
Policy. Is Launch Boost Disabled ();
}

/**
* Dispatch power save events to the listeners.
*
* This method is always called on the handler thread.
*
* This method is called only in the following cases:
* - When battery saver becomes activated.
* - When battery saver becomes deactivated.
* - When battery saver is on and the interactive state
changes.
* - When battery saver is on and the battery saver
policy changes.
* - When adaptive battery saver becomes activated.
* - When adaptive battery saver becomes deactivated.
* - When adaptive battery saver is active (and full
is off) and th e policy changes.
*/
void handle Battery Saver State Changed(boolean send
Broadcast, int reason) {
final Low Power Mode Listener[] listeners;

final boolean enabled;


final boolean is Interactive = get Power
Manager().is Interactive();

synchronized (m Lock) {
enabled = get Full Enabled Locked() || get
Adaptive Enabled Locked();

Event Log Tags. write Battery Saver Mode(


M Full Previously Enabled ? 1 : 0, //
Previously off or on.
M Adaptive Previously Enabled ? 1 : 0,
// Previously off or on.
Get Full Enabled Locked () ? 1 : 0, //
Now off or on.
Get Adaptive Enabled Locked () ? 1 : 0,
// Now off or on.
Is Interactive ? 1 : 0, // Device
interactive state.
enabled ? m Battery Saver Policy. To
Event Log String() : "",
reason);

m Full Previously Enabled = get Full Enabled


Locked();
m Adaptive Previously Enabled = get Adaptive
Enabled Locked();

listener = m Listeners. To Array (new Low Power


Mode Listener[0]);

m Is Interactive = is Interactive;
}

final Power Manager Internal pm i = Local Services.


Get Service(Power Manager Internal. class);
if (pm i != null) {
. set Power Mode(Mode. LOW_POWER, is
Enabled());
}

Update Battery Saving Stats();

if (send Broadcast) {

if (DEBUG) {
Slog.i(TAG, "Sending broadcasts for mode: "
+ ());
}
// Send the broadcasts and notify the
listeners. We only do this when the battery saver
// mode changes, but not when only the screen
state changes.
Intent intent = new Intent(Power Manager.
ACTION_ POWER_ SAVE_ MODE_ CHANGED);
Intent. add Flags (Intent. FLAG_
RECEIVER_REGISTERED_ ONLY);
m Context. Send Broadcast As User (intent, User
Handle. ALL);

// Send the broadcast to a manifest-registered


receiver that is specified in the config.
if (get Power Save Mode Changed Listener
Package().is Present()) {
intent = new Intent(Power Manager. ACTION
_POWER _SAVE_ MODE_ CHANGED)
.set Package(get Power Save Mode
Changed Listener Package().get())
.add Flags (Intent. FLAG_RECEIVER_
INCLUDE_ BACKGROUND
| Intent. FLAG_ RECEIVER_
FOREGROUND);
M Context. Send Broadcast As User (intent,
User Handle. ALL);
}

// Send internal version that requires


signature permission.
intent = new Intent (Power Manager.
ACTION_POWER_ SAVE _MODE_ CHANGED_INTERNAL);
intent. Add Flags (Intent. FLAG_RECEIVER_
REGISTERED_ ONLY);
m Context. Send Broadcast As User(intent, User
Handle. ALL,
Mani fest. permission. DEVICE_POWER);

for (Low Power Mode Listener listener :


listeners) {
final Power Save State result =
m Battery Saver Policy. get Battery
Saver Policy (listener. get Service Type ());
listener . on Low Power Mode Changed
(result);
}
}
}

private Optional<String> get Power Save Mode Changed


Listener Package () {
if (m Power Save Mode Changed Listener Package ==
null) {
String config Power Save Mode Changed Listener
Package =
M Context. get String (R. string.
config_power Save Mode Changed Listener Package);
m Power Save Mode Changed Listener Package =
Local Services
.get Service (Package Manager
Internal. class)
.is System Package (config
Power Save Mode Changed Listener Package)
? Optional. Of (config Power
Save Mode Changed Listener Package)
: Optional. Empty ();
}
return m Power Save Mode Changed Listener Package;
}

private void update Battery Saving Stats () {


final Power Manager p m = get Power Manager ();
if (pm == null) {
Slog. Wtf (TAG, "Power Manager not
initialized");

return;
}
final boolean is Interactive = pm. Is
Interactive();
final int doze Mode =
pm.is Device Idle Mode() ? Doze State. DEEP
: pm. Is Light Device Idle Mode() ?
Doze State. LIGHT
: Doze State. NOT_DOZING;

synchronized (m Lock) {
m Battery Saving Stats. Transition State(
get Full Enabled Locked () ? Battery
Saver State. ON :
(get Adaptive Enabled
Locked() ? Battery Saver State. ADAPTIVE : Battery Saver
State. OFF),
Is Interactive ? Interactive
State. INTERACTIVE :Interactive State. NON_INTERACTIVE,
doze Mode,
m Is Plugged In ? Plug State. PLUGGED :
Plug State. UNPLUGGED);
}
}

@Guarded By ("m Lock")


private void set Full Enabled Locked (boolean value) {
if (m Full Enabled Raw == value) {
return;
}
Power Manager. Invalidate Power Save Mode Caches();
M Full Enabled Raw = value;
}

/** Non-blocking getter exists as a reminder not to


directly modify the cached field */
private boolean get Full Enabled Locked () {
return m Full Enabled Raw;
}

@Guarded By ("m Lock")


private void set Adaptive Enabled Locked (boolean
value) {
if (m Adaptive Enabled Raw == value) {
return;
}

Power Manager. Invalidate Power Save Mode Caches ();


M Adaptive Enabled Raw = value;
}

/** Non-blocking getter exists as a reminder not to


directly modify the cached field */
private boolean get Adaptive Enabled Locked() {
return m Adaptive Enabled Raw;
}
}
Proposed System Architecture:

 Diagram design

(UML):
Class diagram:
Application:
All Android smartphones and tablets have a battery-saving feature that you can activate
manually or automatically to give you a little more time until the battery discharges
completely. This feature has different names (Battery Saver, Power Saving, Power Saving
Mode) depending on the device, Android version, and manufacturer. If you want to save
energy on your device, you don’t need to install a Battery Saver app; all you need to do
is enable and configure the built-in Battery Saver feature on your Android smartphone
or tablet, like this:

Disadvantages
 This system doesn’t use any back end This system doesn’t use any backend.
 The system provides with less information then the phones build in app.

Advantages:

 The user gets a list of application usage in a single place.


The consumption rate is accurate

Conclusion:

Battery saver , power saving , or power saving mode is a feature


available on all android devices that aims to limit power
consumption, so that you battery lasts a little longer until you go
to lasts
Future Scope :
Battery saver and extreme battery saver never turn off essential
system apps like phone, clock, and setting. Apps refresh their content ,
like email or news, only when you open the app. Location services
stop when your screen is off. Apps don’t run in the background unless
you turn off battery optimization

Thank You….

You might also like