            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < -1 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }

package com.qiudaoyu.monitor.df;

import android.content.Context;
import com.qiudaoyu.monitor.Monitor;
import com.qiudaoyu.monitor.analysis.MasData;
import com.qiudaoyu.monitor.df.config.DFConfigManager;
import com.qiudaoyu.monitor.df.upload.MUploadService;
import com.qiudaoyu.monitor.log.MLog;
import com.qiudaoyu.monitor.log.mlog.MethodValueAopHandler;
import com.qiudaoyu.monitor.utils.AppUtils;
import com.qiudaoyu.monitor.utils.EmptyUtils;
import com.qiudaoyu.monitor.BuildConfig;
import org.json.JSONObject;
import java.util.Map;

public class MMonitor {

    public final static String TEST_URL = "10.1.27.50";

    public final static int TEST_PROT = 10000;

    private static MMonitor msInstance;

    private MUploadService.Info info;

    private MasData masData;

    private boolean debug;

    private MMonitor(MUploadService.Info info, boolean isDebug) {
        this.info = info;
        debug = isDebug;
        masData = MasData.getInstance();
        masData.setAppKey(info.appkey);
    }

    public static MMonitor getInstance() {
        if (msInstance == null) {
            throw new IllegalStateException("you should build MMonitor fisrt!!!");
        }
        return msInstance;
    }

    public MUploadService.Info getInfo() {
        return info;
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety);
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety, String parId) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety, parId);
    }

    /**
     * 获取当前线程前置操作的Id
     */
    public String getParentId() {
        return masData.getParentId();
    }

    /**
     * @param cusParentId
     */
    public void setParentId(String cusParentId) {
        masData.setParentId(cusParentId);
    }

    /**
     * 传递entityId和userId
     *
     * @param entityId
     * @param userId
     */
    public void setUserId(final String entityId, final String userId) {
        masData.setUserId(entityId, userId);
    }

    /**
     * 设置每个时间都携带的业务数据
     *
     * @param properties
     */
    public void setDynamicProperties(Map<String, String> properties) {
        masData.setDynamicProperties(properties);
    }

    public void start() {
        MUploadService.getInstance().initialize(info);
        if (AppUtils.isMainProcess(info.context, info.pkgName)) {
            Monitor.start();
        }
    }

    public String getAppKey() {
        return info.appkey;
    }

    public void destroy() {
        if (masData != null) {
            masData.shutDown();
        }
        Monitor.shutDown();
        MUploadService.getInstance().shutDown();
        DFConfigManager.getInstance().shutDown();
    }

    public boolean isDebug() {
        return debug;
    }

    public void onLowMemory() {
    }

    public void onTrimMemory(int level) {
    }

    public static class Builder {

        private Context context;

        private String appkey;

        private String appSecret;

        private String pkgName;

        private String appVer;

        private String path;

        private short heartBeatInterval;

        private boolean isDebug;

        private MethodValueAopHandler handler;

        private boolean level;

        private String prefix;

        private MLog.LogInterface logInterface;

        private String url;

        private int port = -1;

        private int[] types;

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder isDebugEnalbe(boolean isDebug) {
            this.isDebug = isDebug;
            return this;
        }

        public Builder context(Context context) {
            this.context = context;
            return this;
        }

        public Builder appKey(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
            return this;
        }

        public Builder appInfo(String pkgName, String appVer) {
            this.pkgName = pkgName;
            this.appVer = appVer;
            return this;
        }

        public Builder uploadService(String url, int port, String cachePath, short heartBeatInterval) {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < 0 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            this.url = url;
            this.port = port;
            this.path = cachePath;
            this.heartBeatInterval = heartBeatInterval;
            return this;
        }

        public Builder mAopHandler(MethodValueAopHandler handler) {
            this.handler = handler;
            return this;
        }

        public Builder MLog(boolean level, String prefix, MLog.LogInterface logInterface) {
            this.level = level;
            this.logInterface = logInterface;
            this.prefix = prefix;
            return this;
        }

        public Builder install(int[] types) {
            this.types = types;
            return this;
        }

        public MMonitor build() {

            Monitor.Builder.newBuilder().context(context).isDebugEnalbe(isDebug).uploadService(MUploadService.getInstance()).configManager(DFConfigManager.getInstance()).MLog(level, prefix, logInterface).mAopHandler(handler).install(types).build();
            // 生成初始化数据
            MUploadService.Info info = new MUploadService.Info(context, MasData.getDeviceId(context), pkgName, appkey, appSecret, appVer, BuildConfig.SDK_VER, path, heartBeatInterval, url, port);
            msInstance = new MMonitor(info, isDebug);
            return msInstance;
        }
    }
}


Monitor.Builder.newBuilder().context(context).isDebugEnalbe(isDebug).uploadService(MUploadService.getInstance()).configManager(DFConfigManager.getInstance()).MLog(level, prefix, logInterface).mAopHandler(handler).install(types).build();
            // 生成初始化数据
            MUploadService.Info info = new MUploadService.Info(context, MasData.getDeviceId(context), pkgName, appkey, appSecret, appVer, BuildConfig.SDK_VER, path, heartBeatInterval, url, port);

package com.qiudaoyu.monitor.df;

import android.content.Context;
import com.qiudaoyu.monitor.Monitor;
import com.qiudaoyu.monitor.analysis.MasData;
import com.qiudaoyu.monitor.df.config.DFConfigManager;
import com.qiudaoyu.monitor.df.upload.MUploadService;
import com.qiudaoyu.monitor.log.MLog;
import com.qiudaoyu.monitor.log.mlog.MethodValueAopHandler;
import com.qiudaoyu.monitor.utils.AppUtils;
import com.qiudaoyu.monitor.utils.EmptyUtils;
import com.qiudaoyu.monitor.BuildConfig;
import org.json.JSONObject;
import java.util.Map;

public class MMonitor {

    public final static String TEST_URL = "10.1.27.50";

    public final static int TEST_PROT = 10000;

    private static MMonitor msInstance;

    private MUploadService.Info info;

    private MasData masData;

    private boolean debug;

    private MMonitor(MUploadService.Info info, boolean isDebug) {
        this.info = info;
        debug = isDebug;
        masData = MasData.getInstance();
        masData.setAppKey(info.appkey);
    }

    public static MMonitor getInstance() {
        if (msInstance == null) {
            throw new IllegalStateException("you should build MMonitor fisrt!!!");
        }
        return msInstance;
    }

    public MUploadService.Info getInfo() {
        return info;
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety);
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety, String parId) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety, parId);
    }

    /**
     * 获取当前线程前置操作的Id
     */
    public String getParentId() {
        return masData.getParentId();
    }

    /**
     * @param cusParentId
     */
    public void setParentId(String cusParentId) {
        masData.setParentId(cusParentId);
    }

    /**
     * 传递entityId和userId
     *
     * @param entityId
     * @param userId
     */
    public void setUserId(final String entityId, final String userId) {
        masData.setUserId(entityId, userId);
    }

    /**
     * 设置每个时间都携带的业务数据
     *
     * @param properties
     */
    public void setDynamicProperties(Map<String, String> properties) {
        masData.setDynamicProperties(properties);
    }

    public void start() {
        MUploadService.getInstance().initialize(info);
        if (AppUtils.isMainProcess(info.context, info.pkgName)) {
            Monitor.start();
        }
    }

    public String getAppKey() {
        return info.appkey;
    }

    public void destroy() {
        if (masData != null) {
            masData.shutDown();
        }
        Monitor.shutDown();
        MUploadService.getInstance().shutDown();
        DFConfigManager.getInstance().shutDown();
    }

    public boolean isDebug() {
        return debug;
    }

    public void onLowMemory() {
    }

    public void onTrimMemory(int level) {
    }

    public static class Builder {

        private Context context;

        private String appkey;

        private String appSecret;

        private String pkgName;

        private String appVer;

        private String path;

        private short heartBeatInterval;

        private boolean isDebug;

        private MethodValueAopHandler handler;

        private boolean level;

        private String prefix;

        private MLog.LogInterface logInterface;

        private String url;

        private int port = -1;

        private int[] types;

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder isDebugEnalbe(boolean isDebug) {
            this.isDebug = isDebug;
            return this;
        }

        public Builder context(Context context) {
            this.context = context;
            return this;
        }

        public Builder appKey(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
            return this;
        }

        public Builder appInfo(String pkgName, String appVer) {
            this.pkgName = pkgName;
            this.appVer = appVer;
            return this;
        }

        public Builder uploadService(String url, int port, String cachePath, short heartBeatInterval) {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < 0 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            this.url = url;
            this.port = port;
            this.path = cachePath;
            this.heartBeatInterval = heartBeatInterval;
            return this;
        }

        public Builder mAopHandler(MethodValueAopHandler handler) {
            this.handler = handler;
            return this;
        }

        public Builder MLog(boolean level, String prefix, MLog.LogInterface logInterface) {
            this.level = level;
            this.logInterface = logInterface;
            this.prefix = prefix;
            return this;
        }

        public Builder install(int[] types) {
            this.types = types;
            return this;
        }

        public MMonitor build() {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < -1 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }

            msInstance = new MMonitor(info, isDebug);
            return msInstance;
        }
    }
}


msInstance = new MMonitor(info, isDebug);
            return msInstance;
        }

package com.qiudaoyu.monitor.df;

import android.content.Context;
import com.qiudaoyu.monitor.Monitor;
import com.qiudaoyu.monitor.analysis.MasData;
import com.qiudaoyu.monitor.df.config.DFConfigManager;
import com.qiudaoyu.monitor.df.upload.MUploadService;
import com.qiudaoyu.monitor.log.MLog;
import com.qiudaoyu.monitor.log.mlog.MethodValueAopHandler;
import com.qiudaoyu.monitor.utils.AppUtils;
import com.qiudaoyu.monitor.utils.EmptyUtils;
import com.qiudaoyu.monitor.BuildConfig;
import org.json.JSONObject;
import java.util.Map;

public class MMonitor {

    public final static String TEST_URL = "10.1.27.50";

    public final static int TEST_PROT = 10000;

    private static MMonitor msInstance;

    private MUploadService.Info info;

    private MasData masData;

    private boolean debug;

    private MMonitor(MUploadService.Info info, boolean isDebug) {
        this.info = info;
        debug = isDebug;
        masData = MasData.getInstance();
        masData.setAppKey(info.appkey);
    }

    public static MMonitor getInstance() {
        if (msInstance == null) {
            throw new IllegalStateException("you should build MMonitor fisrt!!!");
        }
        return msInstance;
    }

    public MUploadService.Info getInfo() {
        return info;
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety);
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety, String parId) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety, parId);
    }

    /**
     * 获取当前线程前置操作的Id
     */
    public String getParentId() {
        return masData.getParentId();
    }

    /**
     * @param cusParentId
     */
    public void setParentId(String cusParentId) {
        masData.setParentId(cusParentId);
    }

    /**
     * 传递entityId和userId
     *
     * @param entityId
     * @param userId
     */
    public void setUserId(final String entityId, final String userId) {
        masData.setUserId(entityId, userId);
    }

    /**
     * 设置每个时间都携带的业务数据
     *
     * @param properties
     */
    public void setDynamicProperties(Map<String, String> properties) {
        masData.setDynamicProperties(properties);
    }

    public void start() {
        MUploadService.getInstance().initialize(info);
        if (AppUtils.isMainProcess(info.context, info.pkgName)) {
            Monitor.start();
        }
    }

    public String getAppKey() {
        return info.appkey;
    }

    public void destroy() {
        if (masData != null) {
            masData.shutDown();
        }
        Monitor.shutDown();
        MUploadService.getInstance().shutDown();
        DFConfigManager.getInstance().shutDown();
    }

    public boolean isDebug() {
        return debug;
    }

    public void onLowMemory() {
    }

    public void onTrimMemory(int level) {
    }

    public static class Builder {

        private Context context;

        private String appkey;

        private String appSecret;

        private String pkgName;

        private String appVer;

        private String path;

        private short heartBeatInterval;

        private boolean isDebug;

        private MethodValueAopHandler handler;

        private boolean level;

        private String prefix;

        private MLog.LogInterface logInterface;

        private String url;

        private int port = -1;

        private int[] types;

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder isDebugEnalbe(boolean isDebug) {
            this.isDebug = isDebug;
            return this;
        }

        public Builder context(Context context) {
            this.context = context;
            return this;
        }

        public Builder appKey(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
            return this;
        }

        public Builder appInfo(String pkgName, String appVer) {
            this.pkgName = pkgName;
            this.appVer = appVer;
            return this;
        }

        public Builder uploadService(String url, int port, String cachePath, short heartBeatInterval) {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < 0 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            this.url = url;
            this.port = port;
            this.path = cachePath;
            this.heartBeatInterval = heartBeatInterval;
            return this;
        }

        public Builder mAopHandler(MethodValueAopHandler handler) {
            this.handler = handler;
            return this;
        }

        public Builder MLog(boolean level, String prefix, MLog.LogInterface logInterface) {
            this.level = level;
            this.logInterface = logInterface;
            this.prefix = prefix;
            return this;
        }

        public Builder install(int[] types) {
            this.types = types;
            return this;
        }

        public MMonitor build() {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < -1 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            Monitor.Builder.newBuilder().context(context).isDebugEnalbe(isDebug).uploadService(MUploadService.getInstance()).configManager(DFConfigManager.getInstance()).MLog(level, prefix, logInterface).mAopHandler(handler).install(types).build();
            // 生成初始化数据
            MUploadService.Info info = new MUploadService.Info(context, MasData.getDeviceId(context), pkgName, appkey, appSecret, appVer, BuildConfig.SDK_VER, path, heartBeatInterval, url, port);


package com.qiudaoyu.monitor.df;

import android.content.Context;
import com.qiudaoyu.monitor.Monitor;
import com.qiudaoyu.monitor.analysis.MasData;
import com.qiudaoyu.monitor.df.config.DFConfigManager;
import com.qiudaoyu.monitor.df.upload.MUploadService;
import com.qiudaoyu.monitor.log.MLog;
import com.qiudaoyu.monitor.log.mlog.MethodValueAopHandler;
import com.qiudaoyu.monitor.utils.AppUtils;
import com.qiudaoyu.monitor.utils.EmptyUtils;
import com.qiudaoyu.monitor.BuildConfig;
import org.json.JSONObject;
import java.util.Map;

public class MMonitor {

    public final static String TEST_URL = "10.1.27.50";

    public final static int TEST_PROT = 10000;

    private static MMonitor msInstance;

    private MUploadService.Info info;

    private MasData masData;

    private boolean debug;

    private MMonitor(MUploadService.Info info, boolean isDebug) {
        this.info = info;
        debug = isDebug;
        masData = MasData.getInstance();
        masData.setAppKey(info.appkey);
    }

    public static MMonitor getInstance() {
        if (msInstance == null) {
            throw new IllegalStateException("you should build MMonitor fisrt!!!");
        }
        return msInstance;
    }

    public MUploadService.Info getInfo() {
        return info;
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety);
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety, String parId) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety, parId);
    }

    /**
     * 获取当前线程前置操作的Id
     */
    public String getParentId() {
        return masData.getParentId();
    }

    /**
     * @param cusParentId
     */
    public void setParentId(String cusParentId) {
        masData.setParentId(cusParentId);
    }

    /**
     * 传递entityId和userId
     *
     * @param entityId
     * @param userId
     */
    public void setUserId(final String entityId, final String userId) {
        masData.setUserId(entityId, userId);
    }

    /**
     * 设置每个时间都携带的业务数据
     *
     * @param properties
     */
    public void setDynamicProperties(Map<String, String> properties) {
        masData.setDynamicProperties(properties);
    }

    public void start() {
        MUploadService.getInstance().initialize(info);
        if (AppUtils.isMainProcess(info.context, info.pkgName)) {
            Monitor.start();
        }
    }

    public String getAppKey() {
        return info.appkey;
    }

    public void destroy() {
        if (masData != null) {
            masData.shutDown();
        }
        Monitor.shutDown();
        MUploadService.getInstance().shutDown();
        DFConfigManager.getInstance().shutDown();
    }

    public boolean isDebug() {
        return debug;
    }

    public void onLowMemory() {
    }

    public void onTrimMemory(int level) {
    }

    public static class Builder {

        private Context context;

        private String appkey;

        private String appSecret;

        private String pkgName;

        private String appVer;

        private String path;

        private short heartBeatInterval;

        private boolean isDebug;

        private MethodValueAopHandler handler;

        private boolean level;

        private String prefix;

        private MLog.LogInterface logInterface;

        private String url;

        private int port = -1;

        private int[] types;

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder isDebugEnalbe(boolean isDebug) {
            this.isDebug = isDebug;
            return this;
        }

        public Builder context(Context context) {
            this.context = context;
            return this;
        }

        public Builder appKey(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
            return this;
        }

        public Builder appInfo(String pkgName, String appVer) {
            this.pk

            this.appVer = appVer;
            return this;
        }

        public Builder uploadService(String url, int port, String cachePath, short heartBeatInterval) {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < 0 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            this.url = url;
            this.port = port;
            this.path = cachePath;
            this.heartBeatInterval = heartBeatInterval;
            return this;
        }

        public Builder mAopHandler(MethodValueAopHandler handler) {
            this.handler = handler;
            return this;
        }

        public Builder MLog(boolean level, String prefix, MLog.LogInterface logInterface) {
            this.level = level;
            this.logInterface = logInterface;
            this.prefix = prefix;
            return this;
        }

        public Builder install(int[] types) {
            this.types = types;
            return this;
        }

        public MMonitor build() {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < -1 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            Monitor.Builder.newBuilder().context(context).isDebugEnalbe(isDebug).uploadService(MUploadService.getInstance()).configManager(DFConfigManager.getInstance()).MLog(level, prefix, logInterface).mAopHandler(handler).install(types).build();
            // 生成初始化数据
            MUploadService.Info info = new MUploadService.Info(context, MasData.getDeviceId(context), pkgName, appkey, appSecret, appVer, BuildConfig.SDK_VER, path, heartBeatInterval, url, port);
            msInstance = new MMonitor(info, isDebug);
            return msInstance;
        }
    }
}


public String getParentId() {
        return masData.getParentId();
    }

package com.qiudaoyu.monitor.df;

import android.content.Context;
import com.qiudaoyu.monitor.Monitor;
import com.qiudaoyu.monitor.analysis.MasData;
import com.qiudaoyu.monitor.df.config.DFConfigManager;
import com.qiudaoyu.monitor.df.upload.MUploadService;
import com.qiudaoyu.monitor.log.MLog;
import com.qiudaoyu.monitor.log.mlog.MethodValueAopHandler;
import com.qiudaoyu.monitor.utils.AppUtils;
import com.qiudaoyu.monitor.utils.EmptyUtils;
import com.qiudaoyu.monitor.BuildConfig;
import org.json.JSONObject;
import java.util.Map;

public class MMonitor {

    public final static String TEST_URL = "10.1.27.50";

    public final static int TEST_PROT = 10000;

    private static MMonitor msInstance;

    private MUploadService.Info info;

    private MasData masData;

    private boolean debug;

    private MMonitor(MUploadService.Info info, boolean isDebug) {
        this.info = info;
        debug = isDebug;
        masData = MasData.getInstance();
        masData.setAppKey(info.appkey);
    }

    public static MMonitor getInstance() {
        if (msInstance == null) {
            throw new IllegalStateException("you should build MMonitor fisrt!!!");
        }
        return msInstance;
    }

    public MUploadService.Info getInfo() {
        return info;
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety);
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety, String parId) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety, parId);
    }

    /**
     * 获取当前线程前置操作的Id
     */

    /**
     * @param cusParentId
     */
    public void setParentId(String cusParentId) {
        masData.setParentId(cusParentId);
    }

    /**
     * 传递entityId和userId
     *
     * @param entityId
     * @param userId
     */
    public void setUserId(final String entityId, final String userId) {
        masData.setUserId(entityId, userId);
    }

    /**
     * 设置每个时间都携带的业务数据
     *
     * @param properties
     */
    public void setDynamicProperties(Map<String, String> properties) {
        masData.setDynamicProperties(properties);
    }

    public void start() {
        MUploadService.getInstance().initialize(info);
        if (AppUtils.isMainProcess(info.context, info.pkgName)) {
            Monitor.start();
        }
    }

    public String getAppKey() {
        return info.appkey;
    }

    public void destroy() {
        if (masData != null) {
            masData.shutDown();
        }
        Monitor.shutDown();
        MUploadService.getInstance().shutDown();
        DFConfigManager.getInstance().shutDown();
    }

    public boolean isDebug() {
        return debug;
    }

    public void onLowMemory() {
    }

    public void onTrimMemory(int level) {
    }

    public static class Builder {

        private Context context;

        private String appkey;

        private String appSecret;

        private String pkgName;

        private String appVer;

        private String path;

        private short heartBeatInterval;

        private boolean isDebug;

        private MethodValueAopHandler handler;

        private boolean level;

        private String prefix;

        private MLog.LogInterface logInterface;

        private String url;

        private int port = -1;

        private int[] types;

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder isDebugEnalbe(boolean isDebug) {
            this.isDebug = isDebug;
            return this;
        }

        public Builder context(Context context) {
            this.context = context;
            return this;
        }

        public Builder appKey(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
            return this;
        }

        public Builder appInfo(String pkgName, String appVer) {
            this.pkgName = pkgName;
            this.appVer = appVer;
            return this;
        }

        public Builder uploadService(String url, int port, String cachePath, short heartBeatInterval) {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < 0 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            this.url = url;
            this.port = port;
            this.path = cachePath;
            this.heartBeatInterval = heartBeatInterval;
            return this;
        }

        public Builder mAopHandler(MethodValueAopHandler handler) {
            this.handler = handler;
            return this;
        }

        public Builder MLog(boolean level, String prefix, MLog.LogInterface logInterface) {
            this.level = level;
            this.logInterface = logInterface;
            this.prefix = prefix;
            return this;
        }

        public Builder install(int[] types) {
            this.types = types;
            return this;
        }

        public MMonitor build() {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < -1 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            Monitor.Builder.newBuilder().context(context).isDebugEnalbe(isDebug).uploadService(MUploadService.getInstance()).configManager(DFConfigManager.getInstance()).MLog(level, prefix, logInterface).mAopHandler(handler).install(types).build();
            // 生成初始化数据
            MUploadService.Info info = new MUploadService.Info(context, MasData.getDeviceId(context), pkgName, appkey, appSecret, appVer, BuildConfig.SDK_VER, path, heartBeatInterval, url, port);
            msInstance = new MMonitor(info, isDebug);
            return msInstance;
        }
    }
}


if (port < -1 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }

package com.qiudaoyu.monitor.df;

import android.content.Context;
import com.qiudaoyu.monitor.Monitor;
import com.qiudaoyu.monitor.analysis.MasData;
import com.qiudaoyu.monitor.df.config.DFConfigManager;
import com.qiudaoyu.monitor.df.upload.MUploadService;
import com.qiudaoyu.monitor.log.MLog;
import com.qiudaoyu.monitor.log.mlog.MethodValueAopHandler;
import com.qiudaoyu.monitor.utils.AppUtils;
import com.qiudaoyu.monitor.utils.EmptyUtils;
import com.qiudaoyu.monitor.BuildConfig;
import org.json.JSONObject;
import java.util.Map;

public class MMonitor {

    public final static String TEST_URL = "10.1.27.50";

    public final static int TEST_PROT = 10000;

    private static MMonitor msInstance;

    private MUploadService.Info info;

    private MasData masData;

    private boolean debug;

    private MMonitor(MUploadService.Info info, boolean isDebug) {
        this.info = info;
        debug = isDebug;
        masData = MasData.getInstance();
        masData.setAppKey(info.appkey);
    }

    public static MMonitor getInstance() {
        if (msInstance == null) {
            throw new IllegalStateException("you should build MMonitor fisrt!!!");
        }
        return msInstance;
    }

    public MUploadService.Info getInfo() {
        return info;
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety);
    }

    /**
     * 发送自定义数据
     *
     * @param eventType
     * @param propety
     */
    public void trackBusUserEvent(String eventType, JSONObject propety, String parId) {
        if (msInstance == null) {
            throw new IllegalStateException("you should init monitor fisrt!!!");
        }
        if (EmptyUtils.isEmpty(eventType)) {
            throw new IllegalArgumentException("eventType can not be null or empty!!!");
        }
        if (propety == null) {
            propety = new JSONObject();
        }
        masData.trackBusUserEvent(eventType, propety, parId);
    }

    /**
     * 获取当前线程前置操作的Id
     */
    public String getParentId() {
        return masData.getParentId();
    }

    /**
     * @param cusParentId
     */
    public void setParentId(String cusParentId) {
        masData.setParentId(cusParentId);
    }

    /**
     * 传递entityId和userId
     *
     * @param entityId
     * @param userId
     */
    public void setUserId(final String entityId, final String userId) {
        masData.setUserId(entityId, userId);
    }

    /**
     * 设置每个时间都携带的业务数据
     *
     * @param properties
     */
    public void setDynamicProperties(Map<String, String> properties) {
        masData.setDynamicProperties(properties);
    }

    public void start() {
        MUploadService.getInstance().initialize(info);
        if (AppUtils.isMainProcess(info.context, info.pkgName)) {
            Monitor.start();
        }
    }

    public String getAppKey() {
        return info.appkey;
    }

    public void destroy() {
        if (masData != null) {
            masData.shutDown();
        }
        Monitor.shutDown();
        MUploadService.getInstance().shutDown();
        DFConfigManager.getInstance().shutDown();
    }

    public boolean isDebug() {
        return debug;
    }

    public void onLowMemory() {
    }

    public void onTrimMemory(int level) {
    }

    public static class Builder {

        private Context context;

        private String appkey;

        private String appSecret;

        private String pkgName;

        private String appVer;

        private String path;

        private short heartBeatInterval;

        private boolean isDebug;

        private MethodValueAopHandler handler;

        private boolean level;

        private String prefix;

        private MLog.LogInterface logInterface;

        private String url;

        private int port = -1;

        private int[] types;

        public static Builder newBuilder() {
            return new Builder();
        }

        public Builder isDebugEnalbe(boolean isDebug) {
            this.isDebug = isDebug;
            return this;
        }

        public Builder context(Context context) {
            this.context = context;
            return this;
        }

        public Builder appKey(String appkey, String appSecret) {
            this.appkey = appkey;
            this.appSecret = appSecret;
            return this;
        }

        public Builder appInfo(String pkgName, String appVer) {
            this.pkgName = pkgName;
            this.appVer = appVer;
            return this;
        }

        public Builder uploadService(String url, int port, String cachePath, short heartBeatInterval) {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }
            if (port < 0 || port > 66000) {
                throw new IllegalArgumentException("port can't be " + port);
            }
            this.url = url;
            this.port = port;
            this.path = cachePath;
            this.heartBeatInterval = heartBeatInterval;
            return this;
        }

        public Builder mAopHandler(MethodValueAopHandler handler) {
            this.handler = handler;
            return this;
        }

        public Builder MLog(boolean level, String prefix, MLog.LogInterface logInterface) {
            this.level = level;
            this.logInterface = logInterface;
            this.prefix = prefix;
            return this;
        }

        public Builder install(int[] types) {
            this.types = types;
            return this;
        }

        public MMonitor build() {
            if (EmptyUtils.isEmpty(url)) {
                throw new IllegalArgumentException("url can't be null or empty");
            }


public E poll(TimeDuration timeout) throws InterruptedException

package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }
    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */

{
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


{
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear()

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }
    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {

        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }
    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }

package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");

    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }
    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == nu

        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


if (!results.isEmpty()) {
                notFull.signal();
            }

package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }
    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }
        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);

            return results;
        }
    }
}


for (; ; ) {
                if (super.offer(element)) {
                    notEmpty.signal();
                    return true;
                }
                if (nanos <= 0) {
                    return false;
                }
                nanos = notFull.awaitNanos(nanos);
            }

package org.apache.ratis.util;

import org.apache.ratis.util.function.CheckedFunctionWithTimeout;
import org.apache.ratis.util.function.TriConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.ToIntFunction;

/**
 * A queue for data elements
 * such that the queue imposes limits on both number of elements and the data size in bytes.
 *
 * Null element is NOT supported.
 *
 * This class is threadsafe.
 */
public class DataBlockingQueue<E> extends DataQueue<E> {

    public static final Logger LOG = LoggerFactory.getLogger(DataBlockingQueue.class);

    private final Lock lock = new ReentrantLock();

    private final Condition notFull = lock.newCondition();

    private final Condition notEmpty = lock.newCondition();

    public DataBlockingQueue(Object name, SizeInBytes byteLimit, int elementLimit, ToIntFunction<E> getNumBytes) {
        super(name, byteLimit, elementLimit, getNumBytes);
    }

    @Override
    public int getNumBytes() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumBytes();
        }
    }

    @Override
    public int getNumElements() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            return super.getNumElements();
        }
    }

    @Override
    public void clear() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            super.clear();
            notFull.signal();
        }
    }

    @Override
    public boolean offer(E element) {
        Objects.requireNonNull(element, "element == null");
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            if (super.offer(element)) {
                notEmpty.signal();
                return true;
            }
            return false;
        }
    }

    /**
     * Adds an element to this queue, waiting up to the given timeout.
     *
     * @return true if the element is added successfully;
     *         otherwise, the element is not added, return false.
     */
    public boolean offer(E element, TimeDuration timeout) throws InterruptedException {
        Objects.requireNonNull(element, "element == null");
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {

        }
    }

    @Override
    public E poll() {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final E polled = super.poll();
            if (polled != null) {
                notFull.signal();
            }
            return polled;
        }
    }

    /**
     * Poll out the head element from this queue, waiting up to the given timeout.
     */
    public E poll(TimeDuration timeout) throws InterruptedException {
        long nanos = timeout.toLong(TimeUnit.NANOSECONDS);
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            for (; ; ) {
                final E polled = super.poll();
                if (polled != null) {
                    notFull.signal();
                    return polled;
                }
                if (nanos <= 0) {
                    return null;
                }
                nanos = notEmpty.awaitNanos(nanos);
            }
        }
    }

    @Override
    public <RESULT, THROWABLE extends Throwable> List<RESULT> pollList(long timeoutMs, CheckedFunctionWithTimeout<E, RESULT, THROWABLE> getResult, TriConsumer<E, TimeDuration, TimeoutException> timeoutHandler) throws THROWABLE {
        try (AutoCloseableLock auto = AutoCloseableLock.acquire(lock)) {
            final List<RESULT> results = super.pollList(timeoutMs, getResult, timeoutHandler);
            if (!results.isEmpty()) {
                notFull.signal();
            }
            return results;
        }
    }
}


@Override
    public Drawable getDrawable(Resources res, AccentPalette palette, int resId)

package com.negusoft.holoaccent.interceptor;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import com.negusoft.holoaccent.AccentPalette;
import com.negusoft.holoaccent.AccentResources;
import com.negusoft.holoaccent.R;
import com.negusoft.holoaccent.drawable.ContactBadgeDrawable;

public class ContactBadgeInterceptor implements AccentResources.Interceptor {

    private static final int FILL_COLOR_DARK = 0xccaaaaaa;

    private static final int LINE_COLOR_DARK = 0xcc090909;

    private static final int FILL_COLOR_LIGHT = 0x96333333;

    private static final int LINE_COLOR_LIGHT = 0xccffffff;

{
        if (resId == R.drawable.ha__contact_badge_normal_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_DARK, LINE_COLOR_DARK);
        if (resId == R.drawable.ha__contact_badge_focused_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_normal_light_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_LIGHT, LINE_COLOR_LIGHT);
        if (resId == R.drawable.ha__contact_badge_focused_light_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_LIGHT);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_light_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_LIGHT);
        }
        return null;
    }
}


        if (resId == R.drawable.ha__contact_badge_normal_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_DARK, LINE_COLOR_DARK);
        if (resId == R.drawable.ha__contact_badge_focused_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_DARK);
        }

package com.negusoft.holoaccent.interceptor;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import com.negusoft.holoaccent.AccentPalette;
import com.negusoft.holoaccent.AccentResources;
import com.negusoft.holoaccent.R;
import com.negusoft.holoaccent.drawable.ContactBadgeDrawable;

public class ContactBadgeInterceptor implements AccentResources.Interceptor {

    private static final int FILL_COLOR_DARK = 0xccaaaaaa;

    private static final int LINE_COLOR_DARK = 0xcc090909;

    private static final int FILL_COLOR_LIGHT = 0x96333333;

    private static final int LINE_COLOR_LIGHT = 0xccffffff;

    @Override
    public Drawable getDrawable(Resources res, AccentPalette palette, int resId) {

        if (resId == R.drawable.ha__contact_badge_pressed_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_normal_light_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_LIGHT, LINE_COLOR_LIGHT);
        if (resId == R.drawable.ha__contact_badge_focused_light_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_LIGHT);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_light_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_LIGHT);
        }
        return null;
    }
}


if (resId == R.drawable.ha__contact_badge_pressed_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_normal_light_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_LIGHT, LINE_COLOR_LIGHT);
        if (resId == R.drawable.ha__contact_badge_focused_light_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_LIGHT);
        }

package com.negusoft.holoaccent.interceptor;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import com.negusoft.holoaccent.AccentPalette;
import com.negusoft.holoaccent.AccentResources;
import com.negusoft.holoaccent.R;
import com.negusoft.holoaccent.drawable.ContactBadgeDrawable;

public class ContactBadgeInterceptor implements AccentResources.Interceptor {

    private static final int FILL_COLOR_DARK = 0xccaaaaaa;

    private static final int LINE_COLOR_DARK = 0xcc090909;

    private static final int FILL_COLOR_LIGHT = 0x96333333;

    private static final int LINE_COLOR_LIGHT = 0xccffffff;

    @Override
    public Drawable getDrawable(Resources res, AccentPalette palette, int resId) {
        if (resId == R.drawable.ha__contact_badge_normal_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_DARK, LINE_COLOR_DARK);
        if (resId == R.drawable.ha__contact_badge_focused_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_DARK);
        }

        if (resId == R.drawable.ha__contact_badge_pressed_light_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_LIGHT);
        }
        return null;
    }
}


if (resId == R.drawable.ha__contact_badge_pressed_light_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_LIGHT);
        }
        return null;
    }

package com.negusoft.holoaccent.interceptor;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import com.negusoft.holoaccent.AccentPalette;
import com.negusoft.holoaccent.AccentResources;
import com.negusoft.holoaccent.R;
import com.negusoft.holoaccent.drawable.ContactBadgeDrawable;

public class ContactBadgeInterceptor implements AccentResources.Interceptor {

    private static final int FILL_COLOR_DARK = 0xccaaaaaa;

    private static final int LINE_COLOR_DARK = 0xcc090909;

    private static final int FILL_COLOR_LIGHT = 0x96333333;

    private static final int LINE_COLOR_LIGHT = 0xccffffff;

    @Override
    public Drawable getDrawable(Resources res, AccentPalette palette, int resId) {
        if (resId == R.drawable.ha__contact_badge_normal_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_DARK, LINE_COLOR_DARK);
        if (resId == R.drawable.ha__contact_badge_focused_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_normal_light_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_LIGHT, LINE_COLOR_LIGHT);
        if (resId == R.drawable.ha__contact_badge_focused_light_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_LIGHT);
        }


package com.negusoft.holoaccent.interceptor;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import com.negusoft.holoaccent.AccentPalette;
import com.negusoft.holoaccent.AccentResources;
import com.negusoft.holoaccent.R;
import com.negusoft.holoaccent.drawable.ContactBadgeDrawable;

public class ContactBadgeInterceptor implements AccentResources.Interceptor {

    private static final int FILL_COLOR_DARK = 0xccaaaaaa;

    private static final int LINE_COLOR_DARK = 0xcc090909;

    private static final int FILL_COLOR_LIGHT = 0x96333333;

    private static final int LINE_COLOR_LIGHT = 0xccffffff;

    @Override
    public Drawable getDrawable(Resources res, AccentPalette palette, int resId) {
        if (resId == R.drawable.ha__contact_badge_normal_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_DARK, LINE_COLOR_DARK);
        if (resId == R.drawable.ha__contact_badge_focused_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_normal_light_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_LIGHT, LINE_COLOR_LIGHT);
        if (resId == R.drawable.ha__contact_badge_focused_light_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_LIGHT);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_light_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_LIGHT);
        }
        ret


if (resId == R.drawable.ha__contact_badge_normal_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_DARK, LINE_COLOR_DARK);

        if (resId == R.drawable.ha__contact_badge_focused_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_DARK);
        }
        if (resId == R.drawable.ha__contact_badge_normal_light_reference)
            return new ContactBadgeDrawable(res, 0, 0f, 0, FILL_COLOR_LIGHT, LINE_COLOR_LIGHT);
        if (resId == R.drawable.ha__contact_badge_focused_light_reference) {
            int backColor = palette.getActionBarAccentColor(0x55);
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, backColor, 2f, borderColor, palette.accentColor, LINE_COLOR_LIGHT);
        }
        if (resId == R.drawable.ha__contact_badge_pressed_light_reference) {
            int borderColor = palette.getActionBarAccentColor(0xAA);
            return new ContactBadgeDrawable(res, borderColor, 0f, 0, palette.accentColor, LINE_COLOR_LIGHT);
        }
        return null;
    }
}


@Override
    public boolean isAvailable()

package com.android.settings.development;

import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.storage.IStorageManager;
import android.text.TextUtils;
import android.sysprop.CryptoProperties;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class FileEncryptionPreferenceController extends DeveloperOptionsPreferenceController implements PreferenceControllerMixin {

    private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";

    private static final String KEY_STORAGE_MANAGER = "mount";

    private final IStorageManager mStorageManager;

    public FileEncryptionPreferenceController(Context context) {
        super(context);
        mStorageManager = getStorageManager();
    }

{
        if (mStorageManager == null) {
            return false;
        }
        try {
            return mStorageManager.isConvertibleToFBE();
        } catch (RemoteException e) {
            return false;
        }
    }

    @Override
    public String getPreferenceKey() {
        return KEY_CONVERT_FBE;
    }

    @Override
    public void updateState(Preference preference) {
        if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) != CryptoProperties.type_values.FILE) {
            return;
        }
        mPreference.setEnabled(false);
        mPreference.setSummary(mContext.getResources().getString(R.string.convert_to_file_encryption_done));
    }

    private IStorageManager getStorageManager() {
        try {
            return IStorageManager.Stub.asInterface(ServiceManager.getService(KEY_STORAGE_MANAGER));
        } catch (VerifyError e) {
            // Used for tests since Robolectric cannot initialize this class.
            return null;
        }
    }
}


{
        try {
            return IStorageManager.Stub.asInterface(ServiceManager.getService(KEY_STORAGE_MANAGER));
        } catch (VerifyError e) {
            // Used for tests since Robolectric cannot initialize this class.
            return null;
        }
    }

package com.android.settings.development;

import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.storage.IStorageManager;
import android.text.TextUtils;
import android.sysprop.CryptoProperties;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class FileEncryptionPreferenceController extends DeveloperOptionsPreferenceController implements PreferenceControllerMixin {

    private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";

    private static final String KEY_STORAGE_MANAGER = "mount";

    private final IStorageManager mStorageManager;

    public FileEncryptionPreferenceController(Context context) {
        super(context);
        mStorageManager = getStorageManager();
    }

    @Override
    public boolean isAvailable() {
        if (mStorageManager == null) {
            return false;
        }
        try {
            return mStorageManager.isConvertibleToFBE();
        } catch (RemoteException e) {
            return false;
        }
    }

    @Override
    public String getPreferenceKey() {
        return KEY_CONVERT_FBE;
    }

    @Override
    public void updateState(Preference preference) {
        if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) != CryptoProperties.type_values.FILE) {
            return;
        }
        mPreference.setEnabled(false);
        mPreference.setSummary(mContext.getResources().getString(R.string.convert_to_file_encryption_done));
    }

    private IStorageManager getStorageManager()


package com.android.settings.development;

import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.storage.IStorageManager;
import android.text.TextUtils;
import android.sysprop.CryptoProperties;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class FileEncryptionPreferenceController extends DeveloperOptionsPreferenceController implements PreferenceControllerMixin {

    private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";

    private static final String KEY_STORAGE_MANAGER = "mount";

    private final IStorageManager mStorageManager;

    public FileEncryptionPreferenceController(Context context) {
        super(context);
        mStorageManager = getStorageManager();
    }

    @Override
    public boolean isAvailable() {
        if (mStorageManager == null) {
            return false;
        }
        try {
            return mStorageManager.isConvertibleToFBE();
        } catch (RemoteException e) {
            return false;
        }
    }

    @Override
    public String getPreferenceKey() {
        return KEY_CONVERT_FBE;
    }

    @Override
    public void updateState(Preference preference) {
        if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) != CryptoProperties.type_values.FILE) {
            return;
        }
        mPreference.setEnabled(false);
        mPreference.setSummary(mContext.getResources().getString(R.string.convert_to_file_encryption_done));
    }

    private IStorageManager getStorageManager() {

        try {
            return IStorageManager.Stub.asInterface(ServiceManager.getService(KEY_STORAGE_MANAGER));
        } catch (VerifyError e) {
            // Used for tests since Robolectric cannot initialize this class.
            return null;
        }
    }
}


try {
            return IStorageManager.Stub.asInterface(ServiceManager.getService(KEY_STORAGE_MANAGER));
        } catch (VerifyError e) {
            // Used for tests since Robolectric cannot initialize this class.
            return null;
        }


package com.android.settings.development;

import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.storage.IStorageManager;
import android.text.TextUtils;
import android.sysprop.CryptoProperties;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class FileEncryptionPreferenceController extends DeveloperOptionsPreferenceController implements PreferenceControllerMixin {

    private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";

    private static final String KEY_STORAGE_MANAGER = "mount";

    private final IStorageManager mStorageManager;

    public FileEncryptionPreferenceController(Context context) {
        super(context);
        mStorageManager = getStorageManager();
    }

    @Override
    public boolean isAvailable() {
        if (mStorageManager == null) {
            return false;
        }
        try {
            return mStorageManager.isConvertibleToFBE();
        } catch (RemoteException e) {
            return false;
        }
    }

    @Override
    public String getPreferenceKey() {
        return KEY_CONVERT_FBE;
    }

    @Override
    public void updateState(Preference preference) {
        if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) != CryptoProperties.type_values.FILE) {
            return;
        }
        mPreference.setEnabled(false);
        mPreference.setSummary(mContext.getResources().getString(R.string.convert_to_file_encryption_done));
    }

    private IStorageManager getStorageManager() {
        try {
            return IStorageManager.Stub.asInterface(ServiceManager.getService(KEY_STORAGE_MANAGER));
        } catch (VerifyError e) {
            // Used for tests since Robolectric cannot initialize this class.
            return null;
        }


package com.android.settings.development;

import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.storage.IStorageManager;
import android.text.TextUtils;
import android.sysprop.CryptoProperties;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class FileEncryptionPreferenceController extends DeveloperOptionsPreferenceController implements PreferenceControllerMixin {

    private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";

    private static final String KEY_STORAGE_MANAGER = "mount";

    private final IStorageManager mStorageManager;

    public FileEncryptionPreferenceController(Context context) {
        super(context);
        mStorageManager = getStorageManager();
    }

    @Override
    public boolean isAvailable() {
        if (mStorageManager == null) {
            return false;
        }
        try {
            return mStorageManager.isConvertibleToFBE();
        } catch (RemoteException e) {
            return false;
        }
    }

    @Override
    public String getPreferenceKey() {

    }

    @Override
    public void updateState(Preference preference) {
        if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) != CryptoProperties.type_values.FILE) {
            return;
        }
        mPreference.setEnabled(false);
        mPreference.setSummary(mContext.getResources().getString(R.string.convert_to_file_encryption_done));
    }

    private IStorageManager getStorageManager() {
        try {
            return IStorageManager.Stub.asInterface(ServiceManager.getService(KEY_STORAGE_MANAGER));
        } catch (VerifyError e) {
            // Used for tests since Robolectric cannot initialize this class.
            return null;
        }
    }
}