Merge branch 'dev' into double_bolus_debug
This commit is contained in:
commit
ef9ac7dd42
|
@ -14,6 +14,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -43,6 +44,7 @@ import info.nightscout.androidaps.activities.PreferencesActivity;
|
|||
import info.nightscout.androidaps.activities.SingleFragmentActivity;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRebuildTabs;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
|
@ -50,8 +52,8 @@ import info.nightscout.androidaps.logging.L;
|
|||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt;
|
||||
import info.nightscout.androidaps.setupwizard.SetupWizardActivity;
|
||||
import info.nightscout.androidaps.tabs.TabPageAdapter;
|
||||
import info.nightscout.androidaps.utils.AndroidPermission;
|
||||
|
@ -89,6 +91,9 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
drawerLayout.addDrawerListener(actionBarDrawerToggle);
|
||||
actionBarDrawerToggle.syncState();
|
||||
|
||||
// initialize screen wake lock
|
||||
processPreferenceChange(new EventPreferenceChange(R.string.key_keep_screen_on));
|
||||
|
||||
doMigrations();
|
||||
|
||||
final ViewPager viewPager = findViewById(R.id.pager);
|
||||
|
@ -146,8 +151,15 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
setupTabs();
|
||||
setupViews();
|
||||
}
|
||||
setWakeLock();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::processPreferenceChange, FabricPrivacy::logException)
|
||||
);
|
||||
|
||||
if (!SP.getBoolean(R.string.key_setupwizard_processed, false)) {
|
||||
Intent intent = new Intent(this, SetupWizardActivity.class);
|
||||
startActivity(intent);
|
||||
|
@ -169,6 +181,19 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
disposable.clear();
|
||||
}
|
||||
|
||||
private void setWakeLock() {
|
||||
boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false);
|
||||
if (keepScreenOn)
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
public void processPreferenceChange(final EventPreferenceChange ev) {
|
||||
if (ev.isChanged(R.string.key_keep_screen_on))
|
||||
setWakeLock();
|
||||
}
|
||||
|
||||
private void setupViews() {
|
||||
TabPageAdapter pageAdapter = new TabPageAdapter(getSupportFragmentManager(), this);
|
||||
NavigationView navigationView = findViewById(R.id.navigation_view);
|
||||
|
|
|
@ -2,10 +2,8 @@ package info.nightscout.androidaps;
|
|||
|
||||
import android.app.Application;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.PluralsRes;
|
||||
|
@ -25,7 +23,6 @@ import java.util.ArrayList;
|
|||
|
||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
|
@ -34,7 +31,6 @@ import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
|||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
|
||||
|
@ -52,9 +48,9 @@ import info.nightscout.androidaps.plugins.general.nsclient.receivers.AckAlarmRec
|
|||
import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessReceiver;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.signatureVerifier.SignatureVerifier;
|
||||
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerPlugin;
|
||||
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
|
||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
|
||||
|
@ -92,20 +88,13 @@ import info.nightscout.androidaps.receivers.NSAlarmReceiver;
|
|||
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver;
|
||||
import info.nightscout.androidaps.services.Intents;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt.triggerCheckVersion;
|
||||
import static info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt.triggerCheckVersion;
|
||||
|
||||
|
||||
public class MainApp extends Application {
|
||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
|
||||
private static KeepAliveReceiver keepAliveReceiver;
|
||||
|
||||
private static MainApp sInstance;
|
||||
|
@ -203,7 +192,7 @@ public class MainApp extends Application {
|
|||
if (!Config.NSCLIENT) pluginsList.add(SafetyPlugin.getPlugin());
|
||||
if (!Config.NSCLIENT) pluginsList.add(VersionCheckerPlugin.INSTANCE);
|
||||
if (!Config.NSCLIENT) pluginsList.add(StorageConstraintPlugin.getPlugin());
|
||||
if (!Config.NSCLIENT) pluginsList.add(SignatureVerifier.getPlugin());
|
||||
if (!Config.NSCLIENT) pluginsList.add(SignatureVerifierPlugin.getPlugin());
|
||||
if (!Config.APS) pluginsList.add(ObjectivesPlugin.INSTANCE);
|
||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||
|
@ -242,15 +231,6 @@ public class MainApp extends Application {
|
|||
startKeepAliveService();
|
||||
}).start();
|
||||
}
|
||||
|
||||
// initialize screen wake lock
|
||||
processPreferenceChange(new EventPreferenceChange(R.string.key_keep_screen_on));
|
||||
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::processPreferenceChange, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
private void registerLocalBroadcastReceiver() {
|
||||
|
@ -336,21 +316,6 @@ public class MainApp extends Application {
|
|||
return sConstraintsChecker;
|
||||
}
|
||||
|
||||
public void processPreferenceChange(final EventPreferenceChange ev) {
|
||||
if (ev.isChanged(R.string.key_keep_screen_on)) {
|
||||
boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false);
|
||||
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (keepScreenOn) {
|
||||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AndroidAPS:MainApp_processPreferenceChange");
|
||||
if (!mWakeLock.isHeld())
|
||||
mWakeLock.acquire();
|
||||
} else {
|
||||
if (mWakeLock != null && mWakeLock.isHeld())
|
||||
mWakeLock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<PluginBase> getPluginsList() {
|
||||
return pluginsList;
|
||||
}
|
||||
|
@ -459,8 +424,6 @@ public class MainApp extends Application {
|
|||
unregisterReceiver(timeDateOrTZChangeReceiver);
|
||||
}
|
||||
|
||||
if (mWakeLock != null && mWakeLock.isHeld())
|
||||
mWakeLock.release();
|
||||
}
|
||||
|
||||
public static int dpToPx(int dp) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.general.signatureVerifier;
|
||||
package info.nightscout.androidaps.plugins.constraints.signatureVerifier;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
|
@ -42,23 +42,23 @@ import info.nightscout.androidaps.utils.SP;
|
|||
* In case someone decides to leak a ready-to-use APK nonetheless, we can still disable it.
|
||||
* Self-compiled APKs with privately held certificates cannot and will not be disabled.
|
||||
*/
|
||||
public class SignatureVerifier extends PluginBase implements ConstraintsInterface {
|
||||
public class SignatureVerifierPlugin extends PluginBase implements ConstraintsInterface {
|
||||
|
||||
private static final String REVOKED_CERTS_URL = "https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/src/main/assets/revoked_certs.txt";
|
||||
private static final long UPDATE_INTERVAL = TimeUnit.DAYS.toMillis(1);
|
||||
|
||||
private static SignatureVerifier plugin = new SignatureVerifier();
|
||||
private static SignatureVerifierPlugin plugin = new SignatureVerifierPlugin();
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(L.CORE);
|
||||
private final Object $lock = new Object[0];
|
||||
private File revokedCertsFile;
|
||||
private List<byte[]> revokedCerts;
|
||||
|
||||
public static SignatureVerifier getPlugin() {
|
||||
public static SignatureVerifierPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
private SignatureVerifier() {
|
||||
private SignatureVerifierPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.CONSTRAINTS)
|
||||
.neverVisible(true)
|
||||
|
@ -124,14 +124,51 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
log.error("Error in SignatureVerifier", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.error("Error in SignatureVerifier", e);
|
||||
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
|
||||
log.error("Error in SignatureVerifierPlugin", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> shortHashes() {
|
||||
List<String> hashes = new ArrayList<>();
|
||||
try {
|
||||
Signature[] signatures = MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), PackageManager.GET_SIGNATURES).signatures;
|
||||
if (signatures != null) {
|
||||
for (Signature signature : signatures) {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA256");
|
||||
byte[] fingerprint = digest.digest(signature.toByteArray());
|
||||
String hash = Hex.toHexString(fingerprint);
|
||||
log.debug("Found signature: " + hash);
|
||||
log.debug("Found signature (short): " + singleCharMap(fingerprint));
|
||||
hashes.add(singleCharMap(fingerprint));
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
|
||||
log.error("Error in SignatureVerifierPlugin", e);
|
||||
}
|
||||
return hashes;
|
||||
}
|
||||
|
||||
String map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?,.-;:_<>|°^`´\\@€*'#+~{}[]¿¡áéíóúàèìòùöäü`ÁÉÍÓÚÀÈÌÒÙÖÄÜßÆÇÊËÎÏԌ۟æçêëîïôœûÿĆČĐŠŽćđšžñΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ\u03A2ΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗ";
|
||||
|
||||
private String singleCharMap(byte[] array) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : array) {
|
||||
sb.append(map.charAt(b & 0xFF));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String singleCharUnMap(String shortHash) {
|
||||
byte[] array = new byte[shortHash.length()];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
sb.append(String.format("%02x",(int) map.charAt(map.indexOf(shortHash.charAt(i)))));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean shouldDownloadCerts() {
|
||||
return System.currentTimeMillis() - SP.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL;
|
||||
}
|
||||
|
@ -153,7 +190,7 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
|
|||
this.revokedCerts = parseRevokedCertsFile(revokedCerts);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error in SignatureVerifier", e);
|
||||
log.error("Error in SignatureVerifierPlugin", e);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.general.versionChecker
|
||||
package info.nightscout.androidaps.plugins.constraints.versionChecker
|
||||
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.general.versionChecker
|
||||
package info.nightscout.androidaps.plugins.constraints.versionChecker
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
|
@ -8,10 +8,13 @@ import com.google.firebase.analytics.FirebaseAnalytics;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin;
|
||||
|
||||
/**
|
||||
* Created by jamorham on 21/02/2018.
|
||||
|
@ -112,9 +115,9 @@ public class FabricPrivacy {
|
|||
|
||||
String closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed().value() ? "CLOSED_LOOP_ENABLED" : "CLOSED_LOOP_DISABLED";
|
||||
// Size is limited to 36 chars
|
||||
String remote = BuildConfig.REMOTE
|
||||
.replace("https://","")
|
||||
.replace("http://","")
|
||||
String remote = BuildConfig.REMOTE.toLowerCase()
|
||||
.replace("https://", "")
|
||||
.replace("http://", "")
|
||||
.replace(".git", "")
|
||||
.replace(".com/", ":")
|
||||
.replace(".org/", ":")
|
||||
|
@ -125,6 +128,10 @@ public class FabricPrivacy {
|
|||
MainApp.getFirebaseAnalytics().setUserProperty("Version", BuildConfig.VERSION);
|
||||
MainApp.getFirebaseAnalytics().setUserProperty("HEAD", BuildConfig.HEAD);
|
||||
MainApp.getFirebaseAnalytics().setUserProperty("Remote", remote);
|
||||
List<String> hashes = SignatureVerifierPlugin.getPlugin().shortHashes();
|
||||
if (hashes.size() >= 1)
|
||||
MainApp.getFirebaseAnalytics().setUserProperty("Hash", hashes.get(0));
|
||||
|
||||
if (ConfigBuilderPlugin.getPlugin().getActivePump() != null)
|
||||
MainApp.getFirebaseAnalytics().setUserProperty("Pump", ConfigBuilderPlugin.getPlugin().getActivePump().getClass().getSimpleName());
|
||||
if (ConfigBuilderPlugin.getPlugin().getActiveAPS() != null)
|
||||
|
@ -137,7 +144,6 @@ public class FabricPrivacy {
|
|||
MainApp.getFirebaseAnalytics().setUserProperty("Sensitivity", ConfigBuilderPlugin.getPlugin().getActiveSensitivity().getClass().getSimpleName());
|
||||
if (ConfigBuilderPlugin.getPlugin().getActiveInsulin() != null)
|
||||
MainApp.getFirebaseAnalytics().setUserProperty("Insulin", ConfigBuilderPlugin.getPlugin().getActiveInsulin().getClass().getSimpleName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.general.versionChecker
|
||||
package info.nightscout.androidaps.plugins.constraints.versionChecker
|
||||
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
Loading…
Reference in a new issue