Android Open Source - Pimp_my_Z1 System Properties Reflection






From Project

Back to project page Pimp_my_Z1.

License

The source code is released under:

GNU General Public License

If you think the Android project Pimp_my_Z1 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**   Copyright (C) 2013  Louis Teboul (a.k.a Androguide)
 */* w w w. j a  v a 2  s  . co  m*/
 *    admin@pimpmyrom.org  || louisteboul@gmail.com
 *    http://pimpmyrom.org || http://androguide.fr
 *    71 quai Clmenceau, 69300 Caluire-et-Cuire, FRANCE.
 *
 *     This program 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 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program 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.
 *
 *      You should have received a copy of the GNU General Public License along
 *      with this program; if not, write to the Free Software Foundation, Inc.,
 *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **/

package com.androguide.honamicontrol.helpers;

import android.content.Context;

import java.io.File;
import java.lang.reflect.Method;

import dalvik.system.DexFile;

/**
 * Class using reflection to grant access to the private hidden android.os.SystemProperties class
 */
public class SystemPropertiesReflection {

    /**
     * This class cannot be instantiated
     */
    private SystemPropertiesReflection() {

    }

    /**
     * Get the value for the given key.
     *
     * @return an empty string if the key isn't found
     * @throws IllegalArgumentException if the key exceeds 32 characters
     */
    public static String get(Context context, String key) throws IllegalArgumentException {

        String ret = "";

        try {

            ClassLoader cl = context.getClassLoader();
            @SuppressWarnings("rawtypes")
            Class SystemProperties = cl.loadClass("android.os.SystemProperties");

            //Parameters Types
            @SuppressWarnings("rawtypes")
            Class[] paramTypes = new Class[1];
            paramTypes[0] = String.class;

            Method get = SystemProperties.getMethod("get", paramTypes);

            //Parameters
            Object[] params = new Object[1];
            params[0] = new String(key);

            ret = (String) get.invoke(SystemProperties, params);

        } catch (IllegalArgumentException iAE) {
            throw iAE;
        } catch (Exception e) {
            ret = "";
            //TODO
        }

        return ret;

    }

    /**
     * Get the value for the given key.
     *
     * @return if the key isn't found, return def if it isn't null, or an empty string otherwise
     * @throws IllegalArgumentException if the key exceeds 32 characters
     */
    public static String get(Context context, String key, String def) throws IllegalArgumentException {

        String ret = def;

        try {

            ClassLoader cl = context.getClassLoader();
            @SuppressWarnings("rawtypes")
            Class SystemProperties = cl.loadClass("android.os.SystemProperties");

            //Parameters Types
            @SuppressWarnings("rawtypes")
            Class[] paramTypes = new Class[2];
            paramTypes[0] = String.class;
            paramTypes[1] = String.class;

            Method get = SystemProperties.getMethod("get", paramTypes);

            //Parameters
            Object[] params = new Object[2];
            params[0] = new String(key);
            params[1] = new String(def);

            ret = (String) get.invoke(SystemProperties, params);

        } catch (IllegalArgumentException iAE) {
            throw iAE;
        } catch (Exception e) {
            ret = def;
            //TODO
        }

        return ret;

    }

    /**
     * Get the value for the given key, and return as an integer.
     *
     * @param key the key to lookup
     * @param def a default value to return
     * @return the key parsed as an integer, or def if the key isn't found or
     * cannot be parsed
     * @throws IllegalArgumentException if the key exceeds 32 characters
     */
    public static Integer getInt(Context context, String key, int def) throws IllegalArgumentException {

        Integer ret = def;

        try {

            ClassLoader cl = context.getClassLoader();
            @SuppressWarnings("rawtypes")
            Class SystemProperties = cl.loadClass("android.os.SystemProperties");

            //Parameters Types
            @SuppressWarnings("rawtypes")
            Class[] paramTypes = new Class[2];
            paramTypes[0] = String.class;
            paramTypes[1] = int.class;

            Method getInt = SystemProperties.getMethod("getInt", paramTypes);

            //Parameters
            Object[] params = new Object[2];
            params[0] = new String(key);
            params[1] = new Integer(def);

            ret = (Integer) getInt.invoke(SystemProperties, params);

        } catch (IllegalArgumentException iAE) {
            throw iAE;
        } catch (Exception e) {
            ret = def;
            //TODO
        }

        return ret;

    }

    /**
     * Get the value for the given key, and return as a long.
     *
     * @param key the key to lookup
     * @param def a default value to return
     * @return the key parsed as a long, or def if the key isn't found or
     * cannot be parsed
     * @throws IllegalArgumentException if the key exceeds 32 characters
     */
    public static Long getLong(Context context, String key, long def) throws IllegalArgumentException {

        Long ret = def;

        try {

            ClassLoader cl = context.getClassLoader();
            @SuppressWarnings("rawtypes")
            Class SystemProperties = cl.loadClass("android.os.SystemProperties");

            //Parameters Types
            @SuppressWarnings("rawtypes")
            Class[] paramTypes = new Class[2];
            paramTypes[0] = String.class;
            paramTypes[1] = long.class;

            Method getLong = SystemProperties.getMethod("getLong", paramTypes);

            //Parameters
            Object[] params = new Object[2];
            params[0] = new String(key);
            params[1] = new Long(def);

            ret = (Long) getLong.invoke(SystemProperties, params);

        } catch (IllegalArgumentException iAE) {
            throw iAE;
        } catch (Exception e) {
            ret = def;
            //TODO
        }

        return ret;

    }

    /**
     * Get the value for the given key, returned as a boolean.
     * Values 'n', 'no', '0', 'false' or 'off' are considered false.
     * Values 'y', 'yes', '1', 'true' or 'on' are considered true.
     * (case insensitive).
     * If the key does not exist, or has any other value, then the default
     * result is returned.
     *
     * @param key the key to lookup
     * @param def a default value to return
     * @return the key parsed as a boolean, or def if the key isn't found or is
     * not able to be parsed as a boolean.
     * @throws IllegalArgumentException if the key exceeds 32 characters
     */
    public static Boolean getBoolean(Context context, String key, boolean def) throws IllegalArgumentException {

        Boolean ret = def;

        try {

            ClassLoader cl = context.getClassLoader();
            @SuppressWarnings("rawtypes")
            Class SystemProperties = cl.loadClass("android.os.SystemProperties");

            //Parameters Types
            @SuppressWarnings("rawtypes")
            Class[] paramTypes = new Class[2];
            paramTypes[0] = String.class;
            paramTypes[1] = boolean.class;

            Method getBoolean = SystemProperties.getMethod("getBoolean", paramTypes);

            //Parameters
            Object[] params = new Object[2];
            params[0] = new String(key);
            params[1] = new Boolean(def);

            ret = (Boolean) getBoolean.invoke(SystemProperties, params);

        } catch (IllegalArgumentException iAE) {
            throw iAE;
        } catch (Exception e) {
            ret = def;
            //TODO
        }

        return ret;

    }

    /**
     * Set the value for the given key.
     *
     * @throws IllegalArgumentException if the key exceeds 32 characters
     * @throws IllegalArgumentException if the value exceeds 92 characters
     */
    public static void set(Context context, String key, String val) throws IllegalArgumentException {

        try {

            @SuppressWarnings("unused")
            DexFile df = new DexFile(new File("/system/app/Settings.apk"));
            @SuppressWarnings("unused")
            ClassLoader cl = context.getClassLoader();
            @SuppressWarnings("rawtypes")
            Class SystemProperties = Class.forName("android.os.SystemProperties");

            //Parameters Types
            @SuppressWarnings("rawtypes")
            Class[] paramTypes = new Class[2];
            paramTypes[0] = String.class;
            paramTypes[1] = String.class;

            Method set = SystemProperties.getMethod("set", paramTypes);

            //Parameters
            Object[] params = new Object[2];
            params[0] = new String(key);
            params[1] = new String(val);

            set.invoke(SystemProperties, params);

        } catch (IllegalArgumentException iAE) {
            throw iAE;
        } catch (Exception e) {
            //TODO
        }

    }
}




Java Source Code List

com.androguide.honamicontrol.MainActivity.java
com.androguide.honamicontrol.PresentationActivity.java
com.androguide.honamicontrol.SettingsActivity.java
com.androguide.honamicontrol.bootservice.BootHelper.java
com.androguide.honamicontrol.bootservice.BootReceiver.java
com.androguide.honamicontrol.cards.CardDoubleSeekBarPA.java
com.androguide.honamicontrol.cards.CardDoubleSeekBar.java
com.androguide.honamicontrol.cards.CardImageLocal.java
com.androguide.honamicontrol.cards.CardSeekBarGeneric.java
com.androguide.honamicontrol.cards.CardSeekBarReadahead.java
com.androguide.honamicontrol.cards.CardSeekBarSC.java
com.androguide.honamicontrol.cards.CardSeekBarSysctl.java
com.androguide.honamicontrol.cards.CardSeekBarVibrator.java
com.androguide.honamicontrol.cards.CardSeekBar.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMCDisabled.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMC.java
com.androguide.honamicontrol.cards.CardSpinnerVoltage.java
com.androguide.honamicontrol.cards.CardSpinner.java
com.androguide.honamicontrol.cards.CardSwitchDisabled.java
com.androguide.honamicontrol.cards.CardSwitchPlugin.java
com.androguide.honamicontrol.cards.CardTopImageLocal.java
com.androguide.honamicontrol.fragments.CardsFragment.java
com.androguide.honamicontrol.fragments.HelpFragment.java
com.androguide.honamicontrol.fragments.WelcomeFragment.java
com.androguide.honamicontrol.helpers.CPUHelper.java
com.androguide.honamicontrol.helpers.FileHelper.java
com.androguide.honamicontrol.helpers.Helpers.java
com.androguide.honamicontrol.helpers.NegativeSeekBar.java
com.androguide.honamicontrol.helpers.ShellInterface.java
com.androguide.honamicontrol.helpers.SystemPropertiesReflection.java
com.androguide.honamicontrol.helpers.CMDProcessor.AbstractAsyncSuCMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.CMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.ChildProcess.java
com.androguide.honamicontrol.helpers.CMDProcessor.CommandResult.java
com.androguide.honamicontrol.helpers.CMDProcessor.Constants.java
com.androguide.honamicontrol.helpers.CMDProcessor.Shell.java
com.androguide.honamicontrol.kernel.KernelFragment.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlActivity.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUFragment.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.GovernorDialog.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUActivity.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUInterface.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksActivity.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksInterface.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementActivity.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementInterface.java
com.androguide.honamicontrol.kernel.misc.MiscActivity.java
com.androguide.honamicontrol.kernel.misc.MiscInterface.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementActivity.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementInterface.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageActivity.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageInterface.java
com.androguide.honamicontrol.profiles.BalancedProfile.java
com.androguide.honamicontrol.profiles.BatteryMaxProfile.java
com.androguide.honamicontrol.profiles.BatteryProfile.java
com.androguide.honamicontrol.profiles.BenchmarkProfile.java
com.androguide.honamicontrol.profiles.PerformanceProfile.java
com.androguide.honamicontrol.profiles.ProfileEnabler.java
com.androguide.honamicontrol.profiles.Profile.java
com.androguide.honamicontrol.soundcontrol.SoundControlActivity.java
com.androguide.honamicontrol.soundcontrol.SoundControlFragment.java
com.androguide.honamicontrol.soundcontrol.SoundControlInterface.java
com.androguide.honamicontrol.soundcontrol.SoundFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenInterface.java
com.astuetz.viewpager.extensions.PagerSlidingTabStrip.java
com.echo.holographlibrary.BarGraph.java
com.echo.holographlibrary.Bar.java
com.echo.holographlibrary.LineGraph.java
com.echo.holographlibrary.LinePoint.java
com.echo.holographlibrary.Line.java
com.echo.holographlibrary.PieGraph.java
com.echo.holographlibrary.PieSlice.java
com.fima.cardsui.StackAdapter.java
com.fima.cardsui.SwipeDismissTouchListener.java
com.fima.cardsui.Utils.java
com.fima.cardsui.objects.AbstractCard.java
com.fima.cardsui.objects.CardStack.java
com.fima.cardsui.objects.Card.java
com.fima.cardsui.views.CardCategory.java
com.fima.cardsui.views.CardDownload.java
com.fima.cardsui.views.CardEditText.java
com.fima.cardsui.views.CardEdit.java
com.fima.cardsui.views.CardImage.java
com.fima.cardsui.views.CardPresentation.java
com.fima.cardsui.views.CardSeekBar.java
com.fima.cardsui.views.CardSpinner.java
com.fima.cardsui.views.CardTextStripe.java
com.fima.cardsui.views.CardText.java
com.fima.cardsui.views.CardTopImage.java
com.fima.cardsui.views.CardUI.java
com.fima.cardsui.views.QuickReturnListView.java