Merge pull request #79 from AdrianLxM/viktoria-permissions
Viktoria permissions
This commit is contained in:
commit
2912d1cce1
2 changed files with 81 additions and 1 deletions
|
@ -1,12 +1,16 @@
|
||||||
package info.nightscout.androidaps;
|
package info.nightscout.androidaps;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
@ -22,6 +26,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
|
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
|
||||||
|
@ -36,6 +41,11 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static KeepAliveReceiver keepAliveReceiver;
|
private static KeepAliveReceiver keepAliveReceiver;
|
||||||
|
|
||||||
|
static final int CASE_STORAGE = 0x1;
|
||||||
|
static final int CASE_SMS = 0x2;
|
||||||
|
|
||||||
|
private boolean askForSMS = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -43,6 +53,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
LocaleHelper.onCreate(this, "en");
|
LocaleHelper.onCreate(this, "en");
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
checkEula();
|
checkEula();
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
askForPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE}, CASE_STORAGE);
|
||||||
|
}
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
log.debug("onCreate");
|
log.debug("onCreate");
|
||||||
|
|
||||||
|
@ -162,7 +176,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void registerBus() {
|
private void registerBus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().unregister(this);
|
MainApp.bus().unregister(this);
|
||||||
|
@ -181,4 +194,70 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check for sms permission if enable in prefernces
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
synchronized (this){
|
||||||
|
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||||
|
setAskForSMS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setAskForSMS() {
|
||||||
|
askForSMS = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume(){
|
||||||
|
super.onResume();
|
||||||
|
askForSMSPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void askForSMSPermissions(){
|
||||||
|
if (askForSMS) { //only when settings were changed an MainActivity resumes.
|
||||||
|
askForSMS = false;
|
||||||
|
SharedPreferences smssettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if (smssettings.getBoolean("smscommunicator_remotecommandsallowed", false)) {
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
|
askForPermission(new String[]{Manifest.permission.RECEIVE_SMS,
|
||||||
|
Manifest.permission.SEND_SMS,
|
||||||
|
Manifest.permission.RECEIVE_MMS}, CASE_SMS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void askForPermission(String[] permission, Integer requestCode) {
|
||||||
|
boolean test = false;
|
||||||
|
for (int i=0; i < permission.length; i++) {
|
||||||
|
test = test || (ContextCompat.checkSelfPermission(this, permission[i]) != PackageManager.PERMISSION_GRANTED);
|
||||||
|
}
|
||||||
|
if (test) {
|
||||||
|
ActivityCompat.requestPermissions(this, permission, requestCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
if (permissions.length != 0) {
|
||||||
|
if (ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
switch (requestCode) {
|
||||||
|
case CASE_STORAGE:
|
||||||
|
//show dialog after permission is granted
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
|
alert.setMessage(R.string.alert_dialog_storage_permission_text);
|
||||||
|
alert.setPositiveButton(R.string.ok, null);
|
||||||
|
alert.show();
|
||||||
|
break;
|
||||||
|
case CASE_SMS:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
<string name="danar_useextended_title">Use extended boluses for >200%</string>
|
<string name="danar_useextended_title">Use extended boluses for >200%</string>
|
||||||
<string name="danar_bt_name_title">DanaR Bluetooth device</string>
|
<string name="danar_bt_name_title">DanaR Bluetooth device</string>
|
||||||
<string name="ns_sync_use_absolute_title">Always use basal absolute values</string>
|
<string name="ns_sync_use_absolute_title">Always use basal absolute values</string>
|
||||||
|
<string name="alert_dialog_storage_permission_text">Please reboot your phone or restart AndroidAPS from the System Settings \notherwise Android APS will not have logging (important to track and verify that the algorithms are working correctly)!</string>
|
||||||
|
|
||||||
<string name="objectives_objective_label_string">Objective:</string>
|
<string name="objectives_objective_label_string">Objective:</string>
|
||||||
<string name="objectives_gate_label_string">Gate:</string>
|
<string name="objectives_gate_label_string">Gate:</string>
|
||||||
|
|
Loading…
Reference in a new issue