sdk: Trust: better warnings management

Allow fine-tuned management of trust warnings,
the user is now able to disable specific warnings
instead of blocking everything

Change-Id: I04c7aa5fba76fd7500fd70c0c874fa0c3e59e03a
Signed-off-by: Joey <joey@lineageos.org>
This commit is contained in:
Joey
2018-06-30 21:15:37 +02:00
committed by Joey Rizzoli
parent 55962105cf
commit c8a06b9ff7
5 changed files with 121 additions and 19 deletions

View File

@@ -44,6 +44,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import lineageos.trust.TrustInterface;
/**
* LineageSettings contains Lineage specific preferences in System, Secure, and Global.
*/
@@ -3053,13 +3055,29 @@ public final class LineageSettings {
/**
* Enable displaying the Trust service's notifications
* 0 = 0ff, 1 = on
* @deprecated Rely on {@link lineageos.providers.TRUST_WARNINGS} instead
*/
@Deprecated
public static final String TRUST_NOTIFICATIONS = "trust_notifications";
/** @hide */
@Deprecated
public static final Validator TRUST_NOTIFICATIONS_VALIDATOR =
sBooleanValidator;
/**
* Trust warnings status
*
* Stores flags for each feature
*
* @see {@link lineageos.trust.TrustInterface.TRUST_WARN_MAX_VALUE}
*/
public static final String TRUST_WARNINGS = "trust_warnings";
/** @hide */
public static final Validator TRUST_WARNINGS_VALIDATOR =
new InclusiveIntegerRangeValidator(0, TrustInterface.TRUST_WARN_MAX_VALUE);
// endregion
/**
@@ -3170,6 +3188,7 @@ public final class LineageSettings {
VALIDATORS.put(NETWORK_TRAFFIC_UNITS, NETWORK_TRAFFIC_UNITS_VALIDATOR);
VALIDATORS.put(NETWORK_TRAFFIC_SHOW_UNITS, NETWORK_TRAFFIC_SHOW_UNITS_VALIDATOR);
VALIDATORS.put(TRUST_NOTIFICATIONS, TRUST_NOTIFICATIONS_VALIDATOR);
VALIDATORS.put(TRUST_WARNINGS, TRUST_WARNINGS_VALIDATOR);
}
/**

View File

@@ -23,4 +23,5 @@ interface ITrustInterface {
boolean postNotificationForFeature(int feature);
boolean removeNotificationForFeature(int feature);
int getLevelForFeature(int feature);
void runTest();
}

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, The LineageOS Project
* Copyright (c) 2018, The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -140,6 +140,49 @@ public class TrustInterface {
*/
public static final int TRUST_FEATURE_KEYS = 5;
/**
* Trust warning: SELinux
*
* When {@link #TRUST_FEATURE_SELINUX} is not {@link #TRUST_FEATURE_LEVEL_GOOD}
* notify the user about the issue
*
* @see #postNotificationForFeature
*/
public static final int TRUST_WARN_SELINUX = 1;
/**
* Trust warning: Root access
*
* When {@link #TRUST_FEATURE_ROOT} is not {@link #TRUST_FEATURE_LEVEL_GOOD}
* notify the user about the issue
*
* @see #postNotificationForFeature
*/
public static final int TRUST_WARN_ROOT = 1 << 1;
/**
* Trust warning: Public Key build signature
*
* When {@link #TRUST_FEATURE_KEYS} is not {@link #TRUST_FEATURE_LEVEL_GOOD}
* notify the user about the issue
*
* @see #postNotificationForFeature
*/
public static final int TRUST_WARN_PUBLIC_KEY = 1 << 2;
/**
* Max / default value for warnings status
*
* Includes all the TRUST_WARN_
*
* @see #postNotificationForFeature
* @hide
*/
public static final int TRUST_WARN_MAX_VALUE =
TRUST_WARN_SELINUX |
TRUST_WARN_ROOT |
TRUST_WARN_PUBLIC_KEY;
private static final String TAG = "TrustInterface";
private static ITrustInterface sService;
@@ -224,5 +267,18 @@ public class TrustInterface {
}
return ERROR_UNDEFINED;
}
/** @hide */
public void runTest() {
if (sService == null) {
return;
}
try {
sService.runTest();
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return;
}
}