Skip to content

Commit

Permalink
PowerProfile: allow reading from a file instead of resource
Browse files Browse the repository at this point in the history
Unified builds may require reading different power profile for each variants.

Allow reading power profile from a file instead of resource by querying
ro.power_profile prop.

Device maintainers can opt-in by using the init extension.

Change-Id: I346bb3e5a71edfe7570af495b73ffd854042367f
Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
  • Loading branch information
arter97 authored and varund7726 committed Jun 20, 2017
1 parent 73645e5 commit bf079b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
28 changes: 25 additions & 3 deletions core/java/com/android/internal/os/PowerProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.SystemProperties;
import android.util.Xml;

import com.android.internal.util.XmlUtils;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import libcore.io.IoUtils;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -210,14 +216,27 @@ public PowerProfile(Context context) {
}

private void readPowerValuesFromXml(Context context) {
int id = com.android.internal.R.xml.power_profile;
final String profilePath = SystemProperties.get("ro.power_profile",
"/system/etc/power_profile.xml");
final Resources resources = context.getResources();
XmlResourceParser parser = resources.getXml(id);
XmlResourceParser resParser = null;
XmlPullParser parser = null;
boolean parsingArray = false;
ArrayList<Double> array = new ArrayList<Double>();
String arrayName = null;
FileReader profileReader = null;

try {
if (new File(profilePath).exists()) {
profileReader = new FileReader(profilePath);
parser = Xml.newPullParser();
parser.setInput(profileReader);
} else {
int id = com.android.internal.R.xml.power_profile;
resParser = resources.getXml(id);
parser = resParser;
}

XmlUtils.beginDocument(parser, TAG_DEVICE);

while (true) {
Expand Down Expand Up @@ -261,7 +280,10 @@ private void readPowerValuesFromXml(Context context) {
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
parser.close();
if (resParser != null) {
resParser.close();
}
IoUtils.closeQuietly(profileReader);
}

// Now collect other config variables.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ protected void observe() {
protected void unobserve() {
super.unobserve();
ContentResolver resolver = mContext.getContentResolver();
resolver.unregisterContentObserver(this);
}

@Override
Expand Down

0 comments on commit bf079b8

Please sign in to comment.