diff options
author | Joey <joey@lineageos.org> | 2019-01-09 22:27:01 +0100 |
---|---|---|
committer | Luca Stefani <luca.stefani.ge1@gmail.com> | 2019-02-04 20:48:15 +0100 |
commit | 0cf297348dff35e7f41dadb69fa8e35b833dff6c (patch) | |
tree | bbd3710d984c4c5f663547443f5108acb49619a8 | |
parent | d853f892aa85741040b1a868e3761343e62d4587 (diff) | |
download | lineage-sdk-0cf297348dff35e7f41dadb69fa8e35b833dff6c.tar.gz lineage-sdk-0cf297348dff35e7f41dadb69fa8e35b833dff6c.tar.bz2 lineage-sdk-0cf297348dff35e7f41dadb69fa8e35b833dff6c.zip |
sdk: add Trust usb restrictor
Change-Id: I8ba443606e83fcfc6f23e62f434f10f25eb69e1b
Signed-off-by: Joey <joey@lineageos.org>
4 files changed, 54 insertions, 5 deletions
diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java index c2c01712..2dcb9385 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 The LineageOS Project + * Copyright (C) 2018-2019 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. @@ -41,10 +41,13 @@ import lineageos.providers.LineageSettings; import lineageos.trust.ITrustInterface; import lineageos.trust.TrustInterface; +import vendor.lineage.trust.V1_0.IUsbRestrict; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.NoSuchElementException; /** @hide **/ public class TrustInterfaceService extends LineageSystemService { @@ -64,6 +67,8 @@ public class TrustInterfaceService extends LineageSystemService { private Context mContext; private NotificationManager mNotificationManager = null; + private IUsbRestrict mUsbRestrictor = null; + public TrustInterfaceService(Context context) { super(context); mContext = context; @@ -84,6 +89,12 @@ public class TrustInterfaceService extends LineageSystemService { public void onStart() { mNotificationManager = mContext.getSystemService(NotificationManager.class); + try { + mUsbRestrictor = IUsbRestrict.getService(); + } catch (NoSuchElementException | RemoteException e) { + // ignore, the hal is not available + } + // Onboard if (!hasOnboardedUser()) { postOnBoardingNotification(); @@ -142,6 +153,10 @@ public class TrustInterfaceService extends LineageSystemService { return true; } + private boolean hasUsbRestrictorInternal() { + return mUsbRestrictor != null; + } + private boolean postOnBoardingNotification() { String title = mContext.getString(R.string.trust_notification_title_onboarding); String message = mContext.getString(R.string.trust_notification_content_onboarding); @@ -371,6 +386,14 @@ public class TrustInterfaceService extends LineageSystemService { } @Override + public boolean hasUsbRestrictor() { + /* + * No need to require permission for this one because it's harmless + */ + return hasUsbRestrictorInternal(); + } + + @Override public int getLevelForFeature(int feature) { /* * No need to require permission for this one because it's harmless diff --git a/sdk/src/java/lineageos/providers/LineageSettings.java b/sdk/src/java/lineageos/providers/LineageSettings.java index 7feabb1c..812072a5 100644 --- a/sdk/src/java/lineageos/providers/LineageSettings.java +++ b/sdk/src/java/lineageos/providers/LineageSettings.java @@ -1,6 +1,6 @@ /** * Copyright (C) 2015-2016 The CyanogenMod Project - * Copyright (C) 2017-2018 The LineageOS Project + * Copyright (C) 2017-2019 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. @@ -3088,6 +3088,18 @@ public final class LineageSettings { sBooleanValidator; /** + * Restrict USB when the screen is locked + * 0 = Off, 1 = On + * + * @hide + */ + public static final String TRUST_RESTRICT_USB_KEYGUARD = "trust_restrict_usb"; + + /** @hide */ + public static final Validator TRUST_RESTRICT_USB_KEYGUARD_VALIDATOR = + sBooleanValidator; + + /** * Trust warnings status * * Stores flags for each feature @@ -3210,6 +3222,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_RESTRICT_USB_KEYGUARD, TRUST_RESTRICT_USB_KEYGUARD_VALIDATOR); VALIDATORS.put(TRUST_WARNINGS, TRUST_WARNINGS_VALIDATOR); } diff --git a/sdk/src/java/lineageos/trust/ITrustInterface.aidl b/sdk/src/java/lineageos/trust/ITrustInterface.aidl index 061bd16f..77fffbf6 100644 --- a/sdk/src/java/lineageos/trust/ITrustInterface.aidl +++ b/sdk/src/java/lineageos/trust/ITrustInterface.aidl @@ -1,6 +1,6 @@ /* ** -** Copyright (C) 2018 The LineageOS Project +** Copyright (C) 2018-2019 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. @@ -22,6 +22,7 @@ interface ITrustInterface { boolean postNotificationForFeature(int feature); boolean removeNotificationForFeature(int feature); + boolean hasUsbRestrictor(); int getLevelForFeature(int feature); void runTest(); } diff --git a/sdk/src/java/lineageos/trust/TrustInterface.java b/sdk/src/java/lineageos/trust/TrustInterface.java index 2df0b755..7f2d233e 100644 --- a/sdk/src/java/lineageos/trust/TrustInterface.java +++ b/sdk/src/java/lineageos/trust/TrustInterface.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018, The LineageOS Project + * Copyright (C) 2018-2019 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. @@ -232,6 +232,7 @@ public class TrustInterface { return sService; } + /** @hide **/ public boolean postNotificationForFeature(int feature) { if (sService == null) { return false; @@ -256,6 +257,18 @@ public class TrustInterface { return false; } + public boolean hasUsbRestrictor() { + if (sService == null) { + return false; + } + try { + return sService.hasUsbRestrictor(); + } catch (RemoteException e) { + Log.e(TAG, e.getLocalizedMessage(), e); + } + return false; + } + public int getLevelForFeature(int feature) { if (sService == null) { return ERROR_UNDEFINED; @@ -281,4 +294,3 @@ public class TrustInterface { return; } } - |