Commit 6000ee1f by Takatoshi Miura

Merge branch 'hotfix/1.4.401_50121' into 'hotfix/1.4.401'

Bug #50121【府中屋】eXFrameAC1 アルコールチェッカー設定をタップした際にアプリが落ちる

See merge request !257
parents 56f4d137 b3af43b6
......@@ -15,7 +15,6 @@ import android.os.Environment;
import android.os.StatFs;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.text.TextUtils;
import android.util.Base64;
import android.view.Display;
import android.view.WindowManager;
......@@ -31,6 +30,7 @@ import jp.agentec.abook.abv.bl.common.exception.ABVExceptionCode;
import jp.agentec.abook.abv.bl.common.exception.NetworkDisconnectedException;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.common.util.SecurityUtil;
import jp.agentec.abook.abv.cl.util.LocationManagerUtil;
import jp.agentec.abook.abv.cl.util.PreferenceUtil;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType.UserPrefKey;
import jp.agentec.adf.util.StringUtil;
......@@ -273,7 +273,6 @@ public class DeviceInfo {
*/
public static boolean isDeviceLocationEnabled(Context context) {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
try {
......@@ -287,8 +286,7 @@ public class DeviceInfo {
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
}else{
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
return LocationManagerUtil.isLocationGpsEnabled(context);
}
}
}
......@@ -19,6 +19,8 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Build;
import android.provider.Settings;
public class LocationManagerUtil {
private final String TAG = "LocationManagerUtil";
......@@ -64,8 +66,8 @@ public class LocationManagerUtil {
return;
}
final boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
final boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
final boolean gps = isLocationGpsEnabled();
final boolean network = isLocationNetWorkEnabled();
if (!gps && !network) {
// この時点で位置情報サービスが有効でない場合は何もしない。
......@@ -232,8 +234,8 @@ 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);
final boolean gps = isLocationGpsEnabled();
final boolean network = isLocationNetWorkEnabled();
if (!gps && !network) {
ABVUIDataCache appDataCache = ABVApplication.getABVUIDataCache(context);
if (appDataCache.checkLocationServiceFlg) {
......@@ -294,4 +296,78 @@ public class LocationManagerUtil {
listener.onGetLocationFailed();
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
}
......@@ -29,6 +29,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.home.adapter.BleListAdapter;
......@@ -217,19 +218,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.alcohol_checker, 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