sdk: add Trust usb restrictor
Change-Id: I8ba443606e83fcfc6f23e62f434f10f25eb69e1b Signed-off-by: Joey <joey@lineageos.org>
This commit is contained in:
@@ -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);
|
||||
@@ -370,6 +385,14 @@ public class TrustInterfaceService extends LineageSystemService {
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUsbRestrictor() {
|
||||
/*
|
||||
* No need to require permission for this one because it's harmless
|
||||
*/
|
||||
return hasUsbRestrictorInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevelForFeature(int feature) {
|
||||
/*
|
||||
|
||||
@@ -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.
|
||||
@@ -3087,6 +3087,18 @@ public final class LineageSettings {
|
||||
public static final Validator TRUST_NOTIFICATIONS_VALIDATOR =
|
||||
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
|
||||
*
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user