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

Commit 5b74c928 authored by Kevin Tang's avatar Kevin Tang Committed by Linux Build Service Account
Browse files

removing compile time dependency from izat module

currently there is a compile time dependency to IZat
Opt In library. This removes that hard linkage and
replaces it with run time linkage.

Change-Id: I393420f06e868f6257b0e3c26ea93b03718d6a4e
CRs-Fixed: 1039525
parent 40598949
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_JAVA_LIBRARIES := bouncycastle core-oj telephony-common ims-common izat.xt.srv
LOCAL_JAVA_LIBRARIES := bouncycastle core-oj telephony-common ims-common
LOCAL_STATIC_JAVA_LIBRARIES := \
    android-support-v4 \
    android-support-v13 \
+0 −1
Original line number Diff line number Diff line
@@ -3039,7 +3039,6 @@
            </intent-filter>
        </service>

        <uses-library android:name="izat.xt.srv"/>
        <!-- This is the longest AndroidManifest.xml ever. -->
    </application>
</manifest>
+103 −16
Original line number Diff line number Diff line
@@ -33,17 +33,73 @@ import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.util.Log;
import com.android.settings.DimmableIconPreference;
import com.qti.izat.XTProxy;
import com.qti.izat.IXTSrvCb;
import dalvik.system.DexClassLoader;
import java.lang.ClassNotFoundException;
import java.lang.ExceptionInInitializerError;
import java.lang.IllegalAccessException;
import java.lang.IllegalArgumentException;
import java.lang.LinkageError;
import java.lang.NoSuchFieldException;
import java.lang.NoSuchMethodException;
import java.lang.NullPointerException;
import java.lang.SecurityException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DimmableIZatIconPreference extends DimmableIconPreference {
    private static final String TAG = "DimmableIZatIconPreference";
    boolean mChecked;
    private XTProxy mXT;
    static private Class mXtProxyClz;
    static private Class mNotifierClz;
    static private Method mGetXtProxyMethod;
    static private Method mGetConsentMethod;
    static private Method mShowIzatMethod;
    static private String mIzatPackage;
    static private DexClassLoader mLoader;

    private static void load(Context context) {
        if (mLoader == null) {
            try {
                if (mXtProxyClz == null || mNotifierClz == null) {
                    mLoader = new DexClassLoader("/system/framework/izat.xt.srv.jar",
                                                 context.getFilesDir().getAbsolutePath(),
                                                 null,
                                                 ClassLoader.getSystemClassLoader());
                    mXtProxyClz = Class.forName("com.qti.izat.XTProxy",
                                                true,
                                                mLoader);
                    mNotifierClz = Class.forName("com.qti.izat.XTProxy$Notifier",
                                                 true,
                                                 mLoader);
                    mIzatPackage = (String)mXtProxyClz.getField("IZAT_XT_PACKAGE").get(null);
                    mGetXtProxyMethod = mXtProxyClz.getMethod("getXTProxy",
                                                              Context.class,
                                                              mNotifierClz);
                    mGetConsentMethod = mXtProxyClz.getMethod("getUserConsent");
                    mShowIzatMethod = mXtProxyClz.getMethod("showIzat",
                                                            Context.class,
                                                            String.class);
                }
            } catch (NoSuchMethodException | NullPointerException | SecurityException |
                     NoSuchFieldException | LinkageError | IllegalAccessException |
                     ClassNotFoundException e) {
                mXtProxyClz = null;
                mNotifierClz = null;
                mIzatPackage = null;
                mGetXtProxyMethod = null;
                mGetConsentMethod = null;
                mShowIzatMethod = null;
                e.printStackTrace();
            }
        }
    }

    public static DimmableIconPreference newInstance(Context context,
            @Nullable CharSequence contentDescription, InjectedSetting info) {
        if (XTProxy.IZAT_XT_PACKAGE.equals(info.packageName)) {
        load(context);
        if (mIzatPackage != null && mIzatPackage.equals(info.packageName)) {
            return new DimmableIZatIconPreference(context, null,
                           com.android.internal.R.attr.checkBoxPreferenceStyle);
        } else {
@@ -51,20 +107,51 @@ public class DimmableIZatIconPreference extends DimmableIconPreference {
        }
    }

    public DimmableIZatIconPreference(Context context, AttributeSet attrs,
    static boolean showIzat(Context context, String packageName) {
        load(context);
        boolean show = true;
        try {
            if (mShowIzatMethod != null) {
                show = (Boolean)mShowIzatMethod.invoke(null, context, packageName);
            }
        } catch (IllegalAccessException | IllegalArgumentException |
                 InvocationTargetException | ExceptionInInitializerError e) {
            e.printStackTrace();
        }
        return show;
    }

    private DimmableIZatIconPreference(Context context, AttributeSet attrs,
                                      int defStyleAttr) {
        super(context, attrs, defStyleAttr, null);

        mXT = XTProxy.getXTProxy(context, new IXTSrvCb.Stub() {
        Object notifier = Proxy.newProxyInstance(mLoader,
                                                 new Class[] { mNotifierClz },
                                                 new InvocationHandler() {
               @Override   
            public void userConsentNotify(boolean consent) {
                if (mChecked != mXT.getUserConsent()) {
                    mChecked = !mChecked;
               public Object invoke(Object proxy, Method method, Object[] args)
                   throws Throwable {
                   if (method.getName().equals("userConsentNotify") &&
                       args[0] != null && args[0] instanceof Boolean) {
                       boolean consent = (Boolean)args[0];
                       if (mChecked != consent) {
                           mChecked = consent;
                           dimIcon(!isEnabled() || !mChecked);
                       }
                   }
                   return null;
               }
                                                 });
        mChecked = mXT.getUserConsent();

        try {
            Object xt = mGetXtProxyMethod.invoke(null,
                                                 context,
                                                 notifier);
            mChecked = (Boolean)mGetConsentMethod.invoke(xt);
        } catch (IllegalAccessException | IllegalArgumentException |
                 InvocationTargetException | ExceptionInInitializerError e) {
            e.printStackTrace();
        }
    }

    @Override
+1 −3
Original line number Diff line number Diff line
@@ -52,8 +52,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.qti.izat.XTProxy;

/**
 * Adds the preferences specified by the {@link InjectedSetting} objects to a preference group.
 *
@@ -165,7 +163,7 @@ class SettingsInjector {
                        + service);
                return null;
            }
        } else if (!XTProxy.showIzat(mContext, si.packageName)) {
        } else if (!DimmableIZatIconPreference.showIzat(mContext, si.packageName)) {
            return null;
        }