Commit 078a4134 by onuma

#47854 【@Form】Android12で機器連携するとアプリが落ちる

parent 01b1cdc0
......@@ -4,7 +4,6 @@ import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.launcher.android.ABVApplication;
import jp.agentec.abook.abv.launcher.android.ABVUIDataCache;
......@@ -18,6 +17,7 @@ import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
......@@ -50,6 +50,54 @@ public class LocationManagerUtil {
}
/**
* GPSが有効かチェックする
* @return 有効の場合true
*/
public boolean isLocationGpsEnabled() {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager == null) {
return false;
}
boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean secureLocationGpsEnabled;
if (Build.VERSION.SDK_INT < 31) {
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
secureLocationGpsEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
} else {
secureLocationGpsEnabled = gps;
}
if (!gps || !secureLocationGpsEnabled) {
return false;
}
return true;
}
/**
* NetWorkによる位置測定が有効かチェックする
* @return 有効の場合true
*/
public boolean isLocationNetWorkEnabled() {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager == null) {
return false;
}
boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
boolean secureLocationNetWorkEnabled;
if (Build.VERSION.SDK_INT < 31) {
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
secureLocationNetWorkEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("network");
} else {
secureLocationNetWorkEnabled = network;
}
if (!network || !secureLocationNetWorkEnabled) {
return false;
}
return true;
}
/**
* 位置情報の取得を開始します<br>
* 成功時にlistenerのonGetLocation、失敗時にlistenerのonGetLocationFailedが呼び出されます。
*
......@@ -65,15 +113,10 @@ public class LocationManagerUtil {
setLocationFailed();
return;
}
final boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
final boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
final boolean secureLocationGpsEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
final boolean secureLocationNetWorkEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("network");
if (!(gps || network) || !(secureLocationGpsEnabled || secureLocationNetWorkEnabled)) {
// 位置情報サービスが有効か?
boolean isGpsEnabled = isLocationGpsEnabled();
boolean isNetWorkEnabled = isLocationNetWorkEnabled();
if (!(isGpsEnabled || isNetWorkEnabled)) {
// この時点で位置情報サービスが有効でない場合は何もしない。
setLocationFailed();
return;
......@@ -113,7 +156,7 @@ public class LocationManagerUtil {
}, TIMER_DELAY, TIMER_INTERVAL);
// 位置情報の取得を開始します。
if (gps) {
if (isGpsEnabled) {
gpsLocationListener = new LocationListener() {
@Override
public void onLocationChanged(final Location location) {
......@@ -137,7 +180,7 @@ public class LocationManagerUtil {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsLocationListener);
}
if (network) {
if (isNetWorkEnabled) {
networkLocationListener = new LocationListener() {
@Override
public void onLocationChanged(final Location location) {
......@@ -238,14 +281,11 @@ public class LocationManagerUtil {
public void showLoactionServiceAlert() {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null) {
final boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
final boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
final boolean secureLocationGpsEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
final boolean secureLocationNetWorkEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("network");
// 位置情報サービスが有効か?
boolean isGpsEnabled = isLocationGpsEnabled();
boolean isNetWorkEnabled = isLocationNetWorkEnabled();
if (!(gps || network) || !(secureLocationGpsEnabled || secureLocationNetWorkEnabled)) {
if (!(isGpsEnabled || isNetWorkEnabled)) {
ABVUIDataCache appDataCache = ABVApplication.getABVUIDataCache(context);
if (appDataCache.checkLocationServiceFlg) {
// 位置情報が有効になっていない場合は、Google Maps アプリライクなダイアログを起動します。
......@@ -305,4 +345,29 @@ public class LocationManagerUtil {
listener.onGetLocationFailed();
}
}
/**
* GPSが有効でかどうかをチェックします。
* @param context アプリのcontext
* @return 有効の場合はtrue
*/
public static boolean isLocationGpsEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager == null) {
return false;
}
boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean secureLocationGpsEnabled;
if (Build.VERSION.SDK_INT < 31) {
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
secureLocationGpsEnabled = android.provider.Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
} else {
secureLocationGpsEnabled = gpsEnabled;
}
if (!(gpsEnabled || secureLocationGpsEnabled)) {
return false;
}
return true;
}
}
......@@ -9,12 +9,10 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.AssetFileDescriptor;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.Settings;
......@@ -32,8 +30,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jp.agentec.abook.abv.bl.common.CommonExecutor;
import jp.agentec.abook.abv.bl.common.Constant.ABookPermissionType;
......@@ -44,6 +40,7 @@ import jp.agentec.abook.abv.bl.data.dao.AbstractDao;
import jp.agentec.abook.abv.bl.data.dao.SppDeviceDao;
import jp.agentec.abook.abv.bl.dto.SppDeviceDto;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.cl.util.LocationManagerUtil;
import jp.agentec.abook.abv.cl.util.SppBluetoothConnectThread;
import jp.agentec.abook.abv.cl.util.YamatoBluetoothReceiveTask;
import jp.agentec.abook.abv.launcher.android.R;
......@@ -51,7 +48,6 @@ import jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
import jp.agentec.abook.abv.ui.home.activity.BarCodeReaderActivity;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
import jp.agentec.adf.util.NumericUtil;
import jp.agentec.adf.util.StringUtil;
public class ABVCheckContentViewActivity extends ABVContentViewActivity {
......@@ -528,14 +524,8 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
private void startOkudakeBeaconScan() {
//Linkingアプリと置くだけセンサーがBluetoothで通信するのでチェック必要
if (requestBluetoothFeature(REQUEST_CODE_ENABLEBLUETOOTH_OKUDAKE)) {
LocationManager lm = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
final boolean gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
final boolean secureLocationGpsEnabled = android.provider.Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
//端末側の位置情報許可チェック
if (gpsEnabled || secureLocationGpsEnabled) {
if (LocationManagerUtil.isLocationGpsEnabled(this)) {
ABookPermissionHelper helper = new ABookPermissionHelper(this, ABookPermissionType.AccessFineLocation, null);
//アプリ側の位置情報許可チェック(置くだけセンサーとLinkingアプリの通信できないため)
......
......@@ -6,14 +6,10 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
......@@ -30,6 +26,7 @@ import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.cl.util.LocationManagerUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
......@@ -218,19 +215,8 @@ public class BlePairingSettingActivity extends ABVUIActivity {
//BlueTooth許可チェック
if (!requestBluetoothFeature()) return;
LocationManager lm = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
boolean gpsEnabled = false;
if (lm != null) {
gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} else {
Logger.w(TAG, "LocationManager is null");
}
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
final boolean secureLocationGpsEnabled = android.provider.Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
//端末側の位置情報許可チェック
if (!(gpsEnabled || secureLocationGpsEnabled)) {
//端末側の位置情報許可チェッ
if (!LocationManagerUtil.isLocationGpsEnabled(this)) {
showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow);
return;
}
......
......@@ -8,10 +8,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
......@@ -24,13 +22,12 @@ import java.util.ArrayList;
import java.util.List;
import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.data.dao.AbstractDao;
import jp.agentec.abook.abv.bl.data.dao.SppDeviceDao;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.bl.dto.SppDeviceDto;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.cl.util.LocationManagerUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
......@@ -175,14 +172,8 @@ public class SppBluetoothPairingSettingActivity extends ABVUIActivity {
//BlueTooth許可チェック
if (!requestBluetoothFeature()) return;
LocationManager lm = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
final boolean gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
// GPSの状態を取得(getSystemtServiceからのGPS ON/OFF取得が取れない場合があるため、secureで取得したgpsも判定するため)
final boolean secureLocationGpsEnabled = android.provider.Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED).contains("gps");
//端末側の位置情報許可チェック
if (!(gpsEnabled || secureLocationGpsEnabled)) {
if (!LocationManagerUtil.isLocationGpsEnabled(this)) {
showSimpleAlertDialog(R.string.spp_machine, R.string.msg_location_device_no_allow);
return;
}
......
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