BindService.java 2.45 KB
package com.ectrip.cyt.config;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;

import com.basewin.services.DeviceInfoBinder;
import com.basewin.services.PrinterBinder;
import com.basewin.services.ScanBinder;
import com.basewin.services.ServiceManager;

/**
 * 仅使用于盛本的红色pos机
 * 用于绑定系统AIDL服务
 * @author Administrator
 *
 */

public class BindService {
	private DeviceInfoBinder deviceinfo = null; // 设备信息
	private PrinterBinder printer=null; //打印模块
	private ScanBinder scan = null;  //扫描模块
	private static BindService instance = null;
	private boolean bindService;
	public static BindService getInstance() {
		if (instance==null) {
			synchronized (BindService.class) {
				instance=new BindService();
			}
		}

		return instance;
	}
	public DeviceInfoBinder getDeviceInfo() {
		if (deviceinfo==null) {
			synchronized (BindService.class) {
				try {
					deviceinfo = ServiceManager.getInstence().getDeviceinfo();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return deviceinfo;
	}
	public PrinterBinder getPrinter() {
		if (printer==null) {
			synchronized (BindService.class) {
				try {
					printer = ServiceManager.getInstence().getPrinter();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return printer;

	}
	public ScanBinder getScan() {

		if (printer==null) {
			synchronized (BindService.class) {
				try {
					scan = ServiceManager.getInstence().getScan();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return scan;

	}
	public boolean isBasewin() {
		if (deviceinfo==null) {
			synchronized (BindService.class) {
				try {
					deviceinfo = ServiceManager.getInstence().getDeviceinfo();
				} catch (Exception e) {
					bindService = false;
					e.printStackTrace();
				}
			}
		}
		try {
			String sn = deviceinfo.getDeviceType();
			Log.d("SN",sn);
			if (TextUtils.isEmpty(sn)){
				bindService=false;
			}else {
				if (sn.equals("P2000L")){
					bindService=true;
				}else {
					bindService=false;
				}
			}
		} catch (RemoteException e) {
			bindService = false;
			e.printStackTrace();
		}

		return bindService;

	}

}