Merge pull request #1936 from MilosKozak/batteryopt
Battery permission fix
This commit is contained in:
commit
3808e4b48b
9 changed files with 515 additions and 643 deletions
|
@ -335,7 +335,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
case AndroidPermission.CASE_LOCATION:
|
case AndroidPermission.CASE_LOCATION:
|
||||||
case AndroidPermission.CASE_SMS:
|
case AndroidPermission.CASE_SMS:
|
||||||
case AndroidPermission.CASE_BATTERY:
|
case AndroidPermission.CASE_BATTERY:
|
||||||
case AndroidPermission.CASE_PHONESTATE:
|
case AndroidPermission.CASE_PHONE_STATE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,7 @@ class RequestDexcomPermissionActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
requestPermissions(arrayOf(SourceDexcomPlugin.PERMISSION), requestCode)
|
||||||
requestPermissions(arrayOf(SourceDexcomPlugin.PERMISSION), requestCode)
|
|
||||||
} else {
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
|
|
|
@ -1,15 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.dialog;
|
package info.nightscout.androidaps.plugins.pump.common.dialog;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
@ -21,7 +11,6 @@ import android.bluetooth.le.ScanSettings;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.ParcelUuid;
|
import android.os.ParcelUuid;
|
||||||
|
@ -41,6 +30,16 @@ import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
|
@ -89,7 +88,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
|
|
||||||
mLeDeviceListAdapter = new LeDeviceListAdapter();
|
mLeDeviceListAdapter = new LeDeviceListAdapter();
|
||||||
listBTScan = (ListView)findViewById(R.id.rileylink_listBTScan);
|
listBTScan = (ListView) findViewById(R.id.rileylink_listBTScan);
|
||||||
listBTScan.setAdapter(mLeDeviceListAdapter);
|
listBTScan.setAdapter(mLeDeviceListAdapter);
|
||||||
listBTScan.setOnItemClickListener((parent, view, position, id) -> {
|
listBTScan.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
mLEScanner.stopScan(mScanCallback2);
|
mLEScanner.stopScan(mScanCallback2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView textview = (TextView)view.findViewById(R.id.rileylink_device_address);
|
TextView textview = (TextView) view.findViewById(R.id.rileylink_device_address);
|
||||||
String bleAddress = textview.getText().toString();
|
String bleAddress = textview.getText().toString();
|
||||||
|
|
||||||
SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
|
SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
|
||||||
|
@ -114,7 +113,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbarBTScan = (Toolbar)findViewById(R.id.rileylink_toolbarBTScan);
|
toolbarBTScan = (Toolbar) findViewById(R.id.rileylink_toolbarBTScan);
|
||||||
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
|
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
|
||||||
setSupportActionBar(toolbarBTScan);
|
setSupportActionBar(toolbarBTScan);
|
||||||
|
|
||||||
|
@ -161,8 +160,8 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
// you can selectively disable BLE-related features.
|
// you can selectively disable BLE-related features.
|
||||||
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
// your code that requires permission
|
// your code that requires permission
|
||||||
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
|
||||||
PERMISSION_REQUEST_COARSE_LOCATION);
|
PERMISSION_REQUEST_COARSE_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensures Bluetooth is available on the device and it is enabled. If not,
|
// Ensures Bluetooth is available on the device and it is enabled. If not,
|
||||||
|
@ -171,20 +170,15 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
Toast.makeText(this, R.string.rileylink_scanner_ble_not_enabled, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.rileylink_scanner_ble_not_enabled, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
// Will request that GPS be enabled for devices running Marshmallow or newer.
|
||||||
// Will request that GPS be enabled for devices running Marshmallow or newer.
|
if (!LocationHelper.isLocationEnabled(this)) {
|
||||||
if (!LocationHelper.isLocationEnabled(this)) {
|
LocationHelper.requestLocationForBluetooth(this);
|
||||||
LocationHelper.requestLocationForBluetooth(this);
|
|
||||||
}
|
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
|
||||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
|
mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
|
||||||
settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
|
settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
|
||||||
filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid(
|
filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid(
|
||||||
ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build());
|
ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +262,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private String getDeviceDebug(BluetoothDevice device) {
|
private String getDeviceDebug(BluetoothDevice device) {
|
||||||
return "BluetoothDevice [name=" + device.getName() + ", address=" + device.getAddress() + //
|
return "BluetoothDevice [name=" + device.getName() + ", address=" + device.getAddress() + //
|
||||||
", type=" + device.getType(); // + ", alias=" + device.getAlias();
|
", type=" + device.getType(); // + ", alias=" + device.getAlias();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,7 +270,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
public void onScanFailed(int errorCode) {
|
public void onScanFailed(int errorCode) {
|
||||||
Log.e("Scan Failed", "Error Code: " + errorCode);
|
Log.e("Scan Failed", "Error Code: " + errorCode);
|
||||||
Toast.makeText(mContext, MainApp.gs(R.string.rileylink_scanner_scanning_error, errorCode),
|
Toast.makeText(mContext, MainApp.gs(R.string.rileylink_scanner_scanning_error, errorCode),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -384,11 +378,11 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = mInflator.inflate(R.layout.rileylink_scan_item, null);
|
view = mInflator.inflate(R.layout.rileylink_scan_item, null);
|
||||||
viewHolder = new ViewHolder();
|
viewHolder = new ViewHolder();
|
||||||
viewHolder.deviceAddress = (TextView)view.findViewById(R.id.rileylink_device_address);
|
viewHolder.deviceAddress = (TextView) view.findViewById(R.id.rileylink_device_address);
|
||||||
viewHolder.deviceName = (TextView)view.findViewById(R.id.rileylink_device_name);
|
viewHolder.deviceName = (TextView) view.findViewById(R.id.rileylink_device_name);
|
||||||
view.setTag(viewHolder);
|
view.setTag(viewHolder);
|
||||||
} else {
|
} else {
|
||||||
viewHolder = (ViewHolder)view.getTag();
|
viewHolder = (ViewHolder) view.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
BluetoothDevice device = mLeDevices.get(i);
|
BluetoothDevice device = mLeDevices.get(i);
|
||||||
|
|
|
@ -24,11 +24,11 @@ public class LocationHelper {
|
||||||
* @return true if location is enabled, false otherwise.
|
* @return true if location is enabled, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isLocationEnabled(Context context) {
|
public static boolean isLocationEnabled(Context context) {
|
||||||
LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
return (locationManager != null && //
|
return (locationManager != null && //
|
||||||
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || //
|
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || //
|
||||||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)));
|
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)));
|
||||||
|
|
||||||
// return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
// return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,7 @@ public class LocationHelper {
|
||||||
*/
|
*/
|
||||||
public static void requestLocationForBluetooth(Activity activity) {
|
public static void requestLocationForBluetooth(Activity activity) {
|
||||||
// Location needs to be enabled for Bluetooth discovery on Marshmallow.
|
// Location needs to be enabled for Bluetooth discovery on Marshmallow.
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
LocationHelper.requestLocation(activity);
|
||||||
LocationHelper.requestLocation(activity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static Boolean locationPermission(ActivityWithMenu act) {
|
// public static Boolean locationPermission(ActivityWithMenu act) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(MainApp.instance(), PERMISSION) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(MainApp.instance(), PERMISSION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
val intent = Intent(MainApp.instance(), RequestDexcomPermissionActivity::class.java)
|
val intent = Intent(MainApp.instance(), RequestDexcomPermissionActivity::class.java)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
MainApp.instance().startActivity(intent)
|
MainApp.instance().startActivity(intent)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,8 @@ package info.nightscout.androidaps.setupwizard;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
@ -223,4 +225,10 @@ public class SetupWizardActivity extends AppCompatActivity {
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == AndroidPermission.CASE_BATTERY)
|
||||||
|
updateButtons();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package info.nightscout.androidaps.utils;
|
package info.nightscout.androidaps.utils;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
@ -21,47 +27,62 @@ public class AndroidPermission {
|
||||||
public static final int CASE_SMS = 0x2;
|
public static final int CASE_SMS = 0x2;
|
||||||
public static final int CASE_LOCATION = 0x3;
|
public static final int CASE_LOCATION = 0x3;
|
||||||
public static final int CASE_BATTERY = 0x4;
|
public static final int CASE_BATTERY = 0x4;
|
||||||
public static final int CASE_PHONESTATE = 0x5;
|
public static final int CASE_PHONE_STATE = 0x5;
|
||||||
|
|
||||||
public static void askForPermission(Activity activity, String[] permission, Integer requestCode) {
|
@SuppressLint("BatteryLife")
|
||||||
|
private static void askForPermission(Activity activity, String[] permission, Integer requestCode) {
|
||||||
boolean test = false;
|
boolean test = false;
|
||||||
for (int i = 0; i < permission.length; i++) {
|
boolean testBattery = false;
|
||||||
test = test || (ContextCompat.checkSelfPermission(activity, permission[i]) != PackageManager.PERMISSION_GRANTED);
|
for (String s : permission) {
|
||||||
|
test = test || (ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED);
|
||||||
|
if (s.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
||||||
|
PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
|
||||||
|
String packageName = activity.getPackageName();
|
||||||
|
testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (test) {
|
if (test) {
|
||||||
ActivityCompat.requestPermissions(activity, permission, requestCode);
|
ActivityCompat.requestPermissions(activity, permission, requestCode);
|
||||||
}
|
}
|
||||||
|
if (testBattery) {
|
||||||
|
Intent i = new Intent();
|
||||||
|
i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
||||||
|
i.setData(Uri.parse("package:" + activity.getPackageName()));
|
||||||
|
activity.startActivityForResult(i, CASE_BATTERY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void askForPermission(Activity activity, String permission, Integer requestCode) {
|
public static void askForPermission(Activity activity, String permission, Integer requestCode) {
|
||||||
String[] permissions = {permission};
|
String[] permissions = {permission};
|
||||||
|
askForPermission(activity, permissions, requestCode);
|
||||||
if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED)
|
|
||||||
ActivityCompat.requestPermissions(activity, permissions, requestCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkForPermission(Context context, String permission) {
|
public static boolean permissionNotGranted(Context context, String permission) {
|
||||||
return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
boolean selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
if (permission.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
||||||
|
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
|
String packageName = context.getPackageName();
|
||||||
|
selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName);
|
||||||
|
}
|
||||||
|
return !selfCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void notifyForSMSPermissions(Activity activity) {
|
public static synchronized void notifyForSMSPermissions(Activity activity) {
|
||||||
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
if (SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)) {
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) {
|
||||||
if (!checkForPermission(activity, Manifest.permission.RECEIVE_SMS)) {
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT);
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SMS, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT);
|
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS,
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS,
|
Manifest.permission.SEND_SMS,
|
||||||
Manifest.permission.SEND_SMS,
|
Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS));
|
||||||
Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
} else
|
||||||
} else
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_SMS));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_SMS));
|
|
||||||
}
|
|
||||||
// Following is a bug in Android 8
|
// Following is a bug in Android 8
|
||||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
||||||
if (!checkForPermission(activity, Manifest.permission.READ_PHONE_STATE)) {
|
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT);
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT);
|
||||||
notification.action(MainApp.gs(R.string.request), () ->
|
notification.action(MainApp.gs(R.string.request), () ->
|
||||||
AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONESTATE));
|
AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONE_STATE));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
} else
|
} else
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_PHONESTATE));
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_PHONESTATE));
|
||||||
|
@ -70,36 +91,30 @@ public class AndroidPermission {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) {
|
public static synchronized void notifyForBatteryOptimizationPermission(Activity activity) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
||||||
if (!checkForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT);
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT);
|
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY));
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
} else
|
||||||
} else
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void notifyForStoragePermission(Activity activity) {
|
public static synchronized void notifyForStoragePermission(Activity activity) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
if (!checkForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT);
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT);
|
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE));
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
} else
|
||||||
} else
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_STORAGE));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_STORAGE));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void notifyForLocationPermissions(Activity activity) {
|
public static synchronized void notifyForLocationPermissions(Activity activity) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||||
if (!checkForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT);
|
||||||
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT);
|
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION));
|
||||||
notification.action(MainApp.gs(R.string.request), () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
} else
|
||||||
} else
|
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1150,7 +1150,6 @@
|
||||||
<string name="adjustprofileinns">Changes must be done in NS</string>
|
<string name="adjustprofileinns">Changes must be done in NS</string>
|
||||||
<string name="exitwizard">Skip setup wizard</string>
|
<string name="exitwizard">Skip setup wizard</string>
|
||||||
<string name="setupwizard_loop_description">Press the button below to enable AndroidAPS to suggest/make basal changes</string>
|
<string name="setupwizard_loop_description">Press the button below to enable AndroidAPS to suggest/make basal changes</string>
|
||||||
<string name="setupwizard_objectives_description">Press the button below to enable Objectives. Look in the Objectives tab, after you finish this wizard, to make AndroidAPS completely functional.\n</string>
|
|
||||||
<string name="enableobjectives">Enable Objectives</string>
|
<string name="enableobjectives">Enable Objectives</string>
|
||||||
<string name="apssetup">Configure APS plugin</string>
|
<string name="apssetup">Configure APS plugin</string>
|
||||||
<string name="key_setupwizard_processed" translatable="false">startupwizard_processed</string>
|
<string name="key_setupwizard_processed" translatable="false">startupwizard_processed</string>
|
||||||
|
|
Loading…
Reference in a new issue