Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bf8a693 authored by Sukanya Rajkhowa's avatar Sukanya Rajkhowa Committed by Linux Build Service Account
Browse files

ConfigResourceUtil: Add new utility methods

- Add methods to get string and array resources
- Move the util out of phone process

Change-Id: If3bbed3a04437173dc9783549c22544140b051a3
parent 5f2688d4
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -29,10 +29,9 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.frameworks.telresources"
    android:sharedUserId="android.uid.phone" >
    package="com.android.frameworks.telresources" >

    <application android:process="com.android.phone">
    <application android:process="com.qualcomm.telephony">
    </application>
</manifest>
+88 −2
Original line number Diff line number Diff line
@@ -34,12 +34,21 @@ import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import java.util.Arrays;

public class ConfigResourceUtil {
    public static final String TAG = "ConfigResourceUtil";
    public static String packageName = "com.android.frameworks.telresources";

    public boolean getBooleanValue(Context context, String resourceName) {
    /**
     * Utility method that gets a boolean resource declared in
     * frameworks/opt/telephony/resources/res/values/config.xml. This
     * resource may be replaced by an overlay of the same name.
     * @param context The context of the application calling the utility
     * @param resourceName The name of the resource that is requested
     * @return value of resource
     */
    public static boolean getBooleanValue(Context context, String resourceName) {
        try {
            Resources res = context.getPackageManager().getResourcesForApplication(packageName);
            if (res == null)
@@ -54,7 +63,15 @@ public class ConfigResourceUtil {
        }
    }

    public int getIntValue(Context context, String resourceName) {
    /**
     * Utility method that gets an integer resource declared in
     * frameworks/opt/telephony/resources/res/values/config.xml. This
     * resource may be replaced by an overlay of the same name.
     * @param context The context of the application calling the utility
     * @param resourceName The name of the resource that is requested
     * @return value of resource
     */
    public static int getIntValue(Context context, String resourceName) {
        try {
            Resources res = context.getPackageManager().getResourcesForApplication(packageName);
            if (res == null)
@@ -68,4 +85,73 @@ public class ConfigResourceUtil {
            throw new RuntimeException(e.getMessage());
        }
    }

    /**
     * Utility method that gets a string resource declared in
     * frameworks/opt/telephony/resources/res/values/config.xml. This
     * resource may be replaced by an overlay of the same name.
     * @param context The context of the application calling the utility
     * @param resourceName The name of the resource that is requested
     * @return value of resource
     */
    public static String getStringValue(Context context, String resourceName) {
        try {
            Resources res = context.getPackageManager().getResourcesForApplication(packageName);
            if (res == null)
                Log.e(TAG, "res is null");
            int resId = res.getIdentifier(resourceName, "string", packageName);
            String resValue = res.getString(resId);
            Log.v(TAG, "resourceName = " + resourceName + " resourceId = " + resId
                    + "resourceValue = " + resValue);
            return resValue;
        } catch (NameNotFoundException | NotFoundException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    /**
     * Utility method that gets an integer array resource declared in
     * frameworks/opt/telephony/resources/res/values/config.xml. This
     * resource may be replaced by an overlay of the same name.
     * @param context The context of the application calling the utility
     * @param resourceName The name of the resource that is requested
     * @return value of resource
     */
    public static int[] getIntArray(Context context, String resourceName) {
        try {
            Resources res = context.getPackageManager().getResourcesForApplication(packageName);
            if (res == null)
                Log.e(TAG, "res is null");
            int resId = res.getIdentifier(resourceName, "array", packageName);
            int[] resValue = res.getIntArray(resId);
            Log.v(TAG, "resourceName = " + resourceName + " resourceId = " + resId
                    + "resourceValue = " + Arrays.toString(resValue));
            return resValue;
        } catch (NameNotFoundException | NotFoundException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    /**
     * Utility method that gets a string array resource declared in
     * frameworks/opt/telephony/resources/res/values/config.xml. This
     * resource may be replaced by an overlay of the same name.
     * @param context The context of the application calling the utility
     * @param resourceName The name of the resource that is requested
     * @return value of resource
     */
    public static String[] getStringArray(Context context, String resourceName) {
        try {
            Resources res = context.getPackageManager().getResourcesForApplication(packageName);
            if (res == null)
                Log.e(TAG, "res is null");
            int resId = res.getIdentifier(resourceName, "array", packageName);
            String[] resValue = res.getStringArray(resId);
            Log.v(TAG, "resourceName = " + resourceName + " resourceId = " + resId
                    + "resourceValue = " + Arrays.toString(resValue));
            return resValue;
        } catch (NameNotFoundException | NotFoundException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}