Commit 970a3eb2 by Lee Jaebin

Merge branch 'contract/sato/1.0.101' into contract/sato/1.0.200

# Conflicts:
#	ABVJE_Res_Default_Android/res/values-ja/strings.xml
#	ABVJE_Res_Default_Android/res/values-ko/strings.xml
#	ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
#	ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVCheckContentViewActivity.java
#	ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/BlePairingSettingActivity.java
parents 112bda13 618e40eb
......@@ -1431,4 +1431,5 @@
<string name="msg_no_support_nfc">NFC機能が利用できない端末です。</string>
<string name="msg_no_nfc_setting">端末の設定からNFCを有効にする必要があります。\n端末の設定画面へ遷移しますか?</string>
<string name="select_spp_device_title">シリアル通信機器選択</string>
<string name="msg_bluetooth_connect_timeout_error">%1$sとの接続が切れました。%1$sの電源や距離を確認し、再度お試し下さい。(%2$s)</string>
</resources>
......@@ -1439,4 +1439,5 @@
<string name="msg_no_support_nfc">NFC기능을 이용할 수 없는 단말기입니다.</string>
<string name="msg_no_nfc_setting">단말기의 설정에서 NFC을 \n단말기의 설정화면으로 이동하시겠습니까?</string>
<string name="select_spp_device_title">시리얼 통신 기기 선택</string>
<string name="msg_bluetooth_connect_timeout_error">%1$s와의 연결이 끊겼습니다. %1$s의 전원과 거리를 확인하고 다시 시도해주세요.(%s)</string>
</resources>
\ No newline at end of file
......@@ -1437,5 +1437,6 @@
<string name="msg_no_support_nfc">NFC機能が利用できない端末です。</string>
<string name="msg_no_nfc_setting">端末の設定からNFCを有効にする必要があります。\n端末の設定画面へ遷移しますか?</string>
<string name="select_spp_device_title">シリアル通信機器選択</string>
<string name="msg_bluetooth_connect_timeout_error">%1$s with the central thermometer has been lost. Check the power and distance of %1$s and try again.(%2$s)</string>
</resources>
\ No newline at end of file
......@@ -9,8 +9,11 @@ import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.widget.Toast;
import java.nio.ByteBuffer;
......@@ -21,6 +24,9 @@ import java.util.UUID;
import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVActivity;
import jp.agentec.abook.abv.ui.common.activity.ABVAuthenticatedActivity;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType;
import jp.agentec.adf.util.StringUtil;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
......@@ -30,8 +36,9 @@ public class BleManagerUtil {
private final String TAG = "BleManagerUtil";
private BluetoothManager bluetoothManager;
private Context context;
private BleManagerUtilListener listener;
private Context mContext;
private BleManagerUtilListener mListener;
private Handler mHandler;
// 定数(Bluetooth LE Gatt UUID)
// Private Service
......@@ -43,53 +50,54 @@ public class BleManagerUtil {
// メンバー変数
public BluetoothAdapter mBluetoothAdapter; // BluetoothAdapter : Bluetooth処理で必要
private String mDeviceAddress = ""; // デバイスアドレス
public BluetoothGatt mBluetoothGatt = null; // Gattサービスの検索、キャラスタリスティックの読み書き
private int mBleConnectDeviceType;
public BleManagerUtil(Context context, BleManagerUtilListener listener) {
this.context = context;
this.listener = listener;
mContext = context;
mListener = listener;
mHandler = new Handler();
}
// BluetoothGattコールバック
private final BluetoothGattCallback mGattcallback = new BluetoothGattCallback() {
// 接続状態変更(connectGatt()の結果として呼ばれる。)
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState ) {
super.onConnectionStateChange(gatt, status, newState);
final int fStatus = status;
public void onConnectionStateChange(BluetoothGatt gatt, final int status, final int newState ) {
Logger.d("onConnectionStateChange status = " + status + " newState = " + newState);
// デバイスと接続されていない場合のメッセージコード:133, 62
// デバイスと離れて応答がなく、タイムアウトになる場合:8
// デバイスと接続が切れた場合のメッセージコード:19
if (status == 133 || status == 62) { // 接続失敗
if (status == 133 || status == 62 || status == 8 || status == 19) { // 接続失敗
runOnUiThread( new Runnable() {
@Override
public void run() {
Logger.e("onConnectionStateChange status = " + fStatus);
listener.onConnectionError(fStatus);
mListener.onConnectionError(status);
}
});
return;
}
if( status == BluetoothGatt.GATT_SUCCESS && BluetoothProfile.STATE_CONNECTED == newState ) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
// 接続完了
if (!mBluetoothGatt.discoverServices()) { // サービス検索
if (mBluetoothGatt == null || !mBluetoothGatt.discoverServices()) { // サービス検索
runOnUiThread( new Runnable() { // 接続失敗
@Override
public void run() {
listener.onGetDeviceInfoFailed(fStatus);
Logger.e("onConnectionStateChange2 status = " + fStatus);
mListener.onGetDeviceInfoFailed(status);
Logger.e("onConnectionStateChange2 status = " + status);
}
});
}
runOnUiThread( new Runnable() {
@Override
public void run() {
// 接続成功
listener.onConnectionState();
}
} );
}, 600);
return;
}
......@@ -107,8 +115,15 @@ public class BleManagerUtil {
return;
}
Logger.d(TAG, "--gattSize : " + gatt.getServices().size());
if (gatt.getServices().size() == 0) {
mListener.onGetDeviceInfoFailed(-1);
return;
}
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
// 発見されたサービスのループ
for( BluetoothGattService service : gatt.getServices() ) {
for(BluetoothGattService service : gatt.getServices()) {
// サービスごとに個別の処理
if((service == null) || (service.getUuid() == null)) {
continue;
......@@ -122,10 +137,17 @@ public class BleManagerUtil {
}
// プライベートサービス
if( UUID_SERVICE_PRIVATE.equals( service.getUuid() ) ) {
if(UUID_SERVICE_PRIVATE.equals(service.getUuid())) {
// 最初の読み取り
readCharacteristic(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE);
runOnUiThread( new Runnable() {
@Override
public void run() {
// 操作可能
mListener.onConnectionState();
}
});
continue;
}
}
......@@ -138,16 +160,16 @@ public class BleManagerUtil {
return;
}
if( UUID_CHARACTERISTIC_PRIVATE.equals(characteristic.getUuid())) {
final String strTemperature = byteToString(characteristic.getValue());
// final String strTemperature = byteToString(characteristic.getValue());
runOnUiThread( new Runnable() {
@Override
public void run() {
// 芯温計の温度を渡す。
// 端末と接続時に呼ばれるのでコメント処理
// listener.onGetDeviceInfo(strTemperature);
}
});
// runOnUiThread( new Runnable() {
// @Override
// public void run() {
// // 芯温計の温度を渡す。
// // 端末と接続時に呼ばれるのでコメント処理
//// mListener.onGetDeviceInfo(strTemperature);
// }
// });
// 通知設定
setCharacteristicNotification(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE, true);
......@@ -165,18 +187,17 @@ public class BleManagerUtil {
@Override
public void run() {
// 複数呼ばれるため、mBluetoothGattがnullの場合、以下の処理を行わない
if( null == mBluetoothGatt ) {
if(mBluetoothGatt == null) {
return;
}
// 芯温計の温度を渡す。
listener.onGetDeviceInfo(strTemperature);
mListener.onGetDeviceInfo(strTemperature);
}
});
return;
}
}
};
/**
* 接続してるデバイスタイプを取得
* @return
......@@ -185,6 +206,61 @@ public class BleManagerUtil {
return mBleConnectDeviceType;
}
// スキャンコールバック
private final ScanCallback mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, final ScanResult result) {
super.onScanResult(callbackType, result);
runOnUiThread(new Runnable() {
@Override
public void run() {
BluetoothDevice device = result.getDevice();
Logger.d(TAG, "--scaning : " + device.getName() );
if (device.getAddress().equals(mDeviceAddress)) {
// 異常と見做し、stopScanでエラーを返す。
stopScan(device.getAddress());
}
}
});
}
// スキャンに失敗
@Override
public void onScanFailed(final int errorCode) {
super.onScanFailed(errorCode);
Logger.e(TAG, "scan failed errorCode : " + errorCode);
runOnUiThread( new Runnable() {
@Override
public void run() {
mListener.onConnectionError(errorCode);
}
});
}
};
/**
* スキャンを中止
*/
private void stopScan(String deviceAddress) {
Logger.d(TAG, "stop ble scan");
// 一定期間後にスキャン停止するためのHandlerのRunnableの削除
mHandler.removeCallbacksAndMessages(null);
if (StringUtil.isNullOrEmpty(deviceAddress)) {
// deviceAddressが見つからなかったと見做し、エラーで返す。
mListener.onConnectionError(-1);
return;
}
// スキャン停止
mBluetoothAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
// ble接続
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceAddress);
bleGattConnect(device);
}
/**
* ディバイス情報の取得を開始します<br>
* 成功時にlistenerのonGetDeviceInfo、失敗時にlistenerのonGetDeviceInfoFailedが呼び出されます。
......@@ -197,17 +273,13 @@ public class BleManagerUtil {
void onDisConnectionState(); // ディバイスと切断時
void onConnectionError(int status); // ディバイス接続エラー
}
/**
* 接続
* @param connectTargetDeviceType bluetoothDeviceType 接続するデバイスタイプ
* @param deviceAddress デバイスアドレス
*/
// 接続
public void connect(int connectTargetDeviceType, String deviceAddress) {
mDeviceAddress = deviceAddress;
// デバイスタイプセット
mBleConnectDeviceType = connectTargetDeviceType;
setUUID();
if(StringUtil.isNullOrEmpty(deviceAddress)) { // deviceAddressが空の場合は処理しない
if(StringUtil.isNullOrEmpty(mDeviceAddress)) { // DeviceAddressが空の場合は処理しない
return;
}
......@@ -216,19 +288,40 @@ public class BleManagerUtil {
}
// mBluetoothGattのサービスと接続
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice( deviceAddress );
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceAddress);
if (device.getName() == null) {
// deviceの名称がない場合、接続エラーになるため、再スキャンすることで検知したらgetRemoteDeviceメソッドに名称がセットされる
mBluetoothAdapter.getBluetoothLeScanner().startScan(mScanCallback);
// スキャン開始(一定時間後にスキャン停止する)
mHandler.postDelayed( new Runnable() {
@Override
public void run() {
// 20秒後に呼ばれた時はスキャンで端末を取得できなかったと見做す。
stopScan(null);
Logger.d(TAG, "scan in 20 sec");
}
}, 20000 );
} else {
bleGattConnect(device);
}
}
/**
* GATT BLE接続処理
* @param device
*/
private void bleGattConnect(BluetoothDevice device) {
// GATT BLEを利用する時Androidのバージョン「23」をチェックしてGATTと接続する。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mBluetoothGatt = device.connectGatt( context, false, mGattcallback, TRANSPORT_LE);
mBluetoothGatt = device.connectGatt(mContext, false, mGattcallback, TRANSPORT_LE);
} else {
mBluetoothGatt = device.connectGatt( context, false, mGattcallback );
mBluetoothGatt = device.connectGatt(mContext, false, mGattcallback );
}
}
// 切断
public void disconnect() {
if( mBluetoothGatt == null ) {
if(mBluetoothGatt == null) {
return;
}
......@@ -238,17 +331,17 @@ public class BleManagerUtil {
// ①「ユーザーの意思による切断」は、mBluetoothGattオブジェクトを解放する。再接続は、オブジェクト構築から。
// ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。
// 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。
// mBluetoothGatt.close();
mBluetoothGatt.disconnect();
mBluetoothGatt.close();
mBluetoothGatt = null;
runOnUiThread( new Runnable() {
@Override
public void run() {
// 切断トーストメッセージを表示する。
listener.onDisConnectionState();
mListener.onDisConnectionState();
}
} );
});
}
// キャラクタリスティックの読み込み
......@@ -290,11 +383,11 @@ public class BleManagerUtil {
// Bluetoothアダプタの取得処理
public void startDeviceInfo() {
// Bluetoothアダプタの取得
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService( Context.BLUETOOTH_SERVICE );
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService( Context.BLUETOOTH_SERVICE );
if (bluetoothManager != null) {
mBluetoothAdapter = bluetoothManager.getAdapter();
if( mBluetoothAdapter == null ) { // Android端末がBluetoothをサポートしていない
Toast.makeText( context, R.string.bluetooth_is_not_supported, Toast.LENGTH_SHORT ).show();
Toast.makeText( mContext, R.string.bluetooth_is_not_supported, Toast.LENGTH_SHORT ).show();
return;
}
} else {
......
......@@ -210,11 +210,20 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
// bluetoothのデバイスタイプ(中心温度計・放射温度計)
int bluetoothDeviceType = bleManagerUtil.getBluetoothDeviceType();
// タイプによってメッセージ内容をセット
if (status == 8) {
// タイムアウトのステータス
if (bluetoothDeviceType == DeviceType.centerThermomete) {
errorAfterAbookCheckAip(String.format(getString(R.string.msg_bluetooth_timeout_error), getString(R.string.center_thermometer), String.valueOf(status)));
} else if (bluetoothDeviceType == DeviceType.radiationThermomete) {
errorAfterAbookCheckAip(String.format(getString(R.string.msg_bluetooth_timeout_error), getString(R.string.radiation_thermometer), String.valueOf(status)));
}
} else {
if (bluetoothDeviceType == DeviceType.centerThermomete) {
errorAfterAbookCheckAip(String.format(getString(R.string.msg_bluetooth_connect_error), getString(R.string.center_thermometer)));
} else if (bluetoothDeviceType == DeviceType.radiationThermomete) {
errorAfterAbookCheckAip(String.format(getString(R.string.msg_bluetooth_connect_error), getString(R.string.radiation_thermometer)));
}
}
bleManagerDisconnect();
}
......@@ -304,11 +313,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
unregisterReceiver(mReceiver);
// 接続されている機器と切断する。
if( null != bleManagerUtil.mBluetoothGatt ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
bleManagerUtil.mBluetoothGatt.disconnect();
}
}
bleManagerDisconnect();
super.onDestroy();
}
......
......@@ -69,7 +69,9 @@ public class BlePairingSettingActivity extends ABVUIActivity {
@Override
public void run() {
BluetoothDevice device = result.getDevice();
if (device.getName() != null) {
Logger.d("mScanCallback device.getName() = " + device.getName());
}
// 識別商品名に絞る
if(device.getName() != null && (device.getName().startsWith(CENTER_THERMOMETE_DEVICE_NAME) || device.getName().startsWith(RADIATION_THERMOMETE_DEVICE_NAME))) {
if (!mSavedDeviceAddressList.contains(device.getAddress())) { //登録されたデバイスの場合、スキャン情報から除外する。
......
......@@ -86,8 +86,8 @@ is_check_invalid_passward_limit=true
repeat_default=true
#Setting Info(設定画面のABookについての設定情報)
version_name=1.0.100
release_date=2019/09/25
version_name=1.0.101
release_date=2020/01/30
copy_right=SATO CORPORATION
hope_page=http://www.sato.co.jp
contact_email=grp-atform_support@sato-global.com
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment