mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add support for manipulationFlags
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -33,11 +33,13 @@ export class IgnoreManipulationAction extends ParentAction {
|
||||
readonly ignoreDidReboot: boolean
|
||||
readonly ignoreHadManipulation: boolean
|
||||
readonly ignoreHadManipulationFlags: number
|
||||
readonly ignoreManipulationFlags: number
|
||||
|
||||
constructor ({
|
||||
deviceId, ignoreDeviceAdminManipulation, ignoreDeviceAdminManipulationAttempt,
|
||||
ignoreAppDowngrade, ignoreNotificationAccessManipulation, ignoreUsageStatsAccessManipulation,
|
||||
ignoreOverlayPermissionManipulation, ignoreAccessibilityServiceManipulation, ignoreDidReboot, ignoreHadManipulation, ignoreHadManipulationFlags
|
||||
ignoreOverlayPermissionManipulation, ignoreAccessibilityServiceManipulation, ignoreDidReboot,
|
||||
ignoreHadManipulation, ignoreHadManipulationFlags, ignoreManipulationFlags
|
||||
}: {
|
||||
deviceId: string
|
||||
ignoreDeviceAdminManipulation: boolean
|
||||
@@ -50,6 +52,7 @@ export class IgnoreManipulationAction extends ParentAction {
|
||||
ignoreDidReboot: boolean
|
||||
ignoreHadManipulation: boolean
|
||||
ignoreHadManipulationFlags: number
|
||||
ignoreManipulationFlags: number
|
||||
}) {
|
||||
super()
|
||||
|
||||
@@ -63,6 +66,8 @@ export class IgnoreManipulationAction extends ParentAction {
|
||||
throwOutOfRange({ actionType, field: 'ignoreHadManipulationFlags', value: ignoreHadManipulationFlags })
|
||||
}
|
||||
|
||||
assertSafeInteger({ actionType, field: 'ignoreManipulationFlags', value: ignoreManipulationFlags })
|
||||
|
||||
this.deviceId = deviceId
|
||||
this.ignoreDeviceAdminManipulation = ignoreDeviceAdminManipulation
|
||||
this.ignoreDeviceAdminManipulationAttempt = ignoreDeviceAdminManipulationAttempt
|
||||
@@ -74,9 +79,14 @@ export class IgnoreManipulationAction extends ParentAction {
|
||||
this.ignoreDidReboot = ignoreDidReboot
|
||||
this.ignoreHadManipulation = ignoreHadManipulation
|
||||
this.ignoreHadManipulationFlags = ignoreHadManipulationFlags
|
||||
this.ignoreManipulationFlags = ignoreManipulationFlags
|
||||
}
|
||||
|
||||
static parse = ({ deviceId, admin, adminA, downgrade, notification, usageStats, overlay, accessibilityService, reboot, hadManipulation, ignoreHadManipulationFlags }: SerializedIgnoreManipulationAction) => (
|
||||
static parse = ({
|
||||
deviceId, admin, adminA, downgrade, notification, usageStats, overlay,
|
||||
accessibilityService, reboot, hadManipulation, ignoreHadManipulationFlags,
|
||||
ignoreManipulationFlags
|
||||
}: SerializedIgnoreManipulationAction) => (
|
||||
new IgnoreManipulationAction({
|
||||
deviceId,
|
||||
ignoreDeviceAdminManipulation: admin,
|
||||
@@ -88,7 +98,8 @@ export class IgnoreManipulationAction extends ParentAction {
|
||||
ignoreAccessibilityServiceManipulation: !!accessibilityService,
|
||||
ignoreDidReboot: !!reboot,
|
||||
ignoreHadManipulation: hadManipulation,
|
||||
ignoreHadManipulationFlags: ignoreHadManipulationFlags || 0
|
||||
ignoreHadManipulationFlags: ignoreHadManipulationFlags || 0,
|
||||
ignoreManipulationFlags: ignoreManipulationFlags || 0
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -107,4 +118,5 @@ export interface SerializedIgnoreManipulationAction {
|
||||
overlay?: boolean
|
||||
accessibilityService?: boolean
|
||||
ignoreHadManipulationFlags?: number
|
||||
ignoreManipulationFlags?: number
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -32,6 +32,7 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
readonly newAppVersion?: number
|
||||
readonly didReboot: boolean
|
||||
readonly isQOrLaterNow: boolean
|
||||
readonly addedManipulationFlags: number
|
||||
|
||||
constructor ({
|
||||
newProtetionLevel,
|
||||
@@ -41,7 +42,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
newAccessibilityServiceEnabled,
|
||||
newAppVersion,
|
||||
didReboot,
|
||||
isQOrLaterNow
|
||||
isQOrLaterNow,
|
||||
addedManipulationFlags
|
||||
}: {
|
||||
newProtetionLevel?: ProtectionLevel
|
||||
newUsageStatsPermissionStatus?: RuntimePermissionStatus
|
||||
@@ -51,6 +53,7 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
newAppVersion?: number
|
||||
didReboot: boolean
|
||||
isQOrLaterNow: boolean
|
||||
addedManipulationFlags: number
|
||||
}) {
|
||||
super()
|
||||
|
||||
@@ -62,6 +65,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
}
|
||||
}
|
||||
|
||||
assertSafeInteger({ actionType, field: 'addedManipulationFlags', value: addedManipulationFlags })
|
||||
|
||||
this.newProtetionLevel = newProtetionLevel
|
||||
this.newUsageStatsPermissionStatus = newUsageStatsPermissionStatus
|
||||
this.newNotificationAccessPermission = newNotificationAccessPermission
|
||||
@@ -70,9 +75,20 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
this.newAppVersion = newAppVersion
|
||||
this.didReboot = didReboot
|
||||
this.isQOrLaterNow = isQOrLaterNow
|
||||
this.addedManipulationFlags = addedManipulationFlags
|
||||
}
|
||||
|
||||
static parse = ({ protectionLevel, usageStats, notificationAccess, overlayPermission, accessibilityServiceEnabled, appVersion, didReboot, isQOrLaterNow }: SerializedUpdateDeviceStatusAction) => (
|
||||
static parse = ({
|
||||
protectionLevel,
|
||||
usageStats,
|
||||
notificationAccess,
|
||||
overlayPermission,
|
||||
accessibilityServiceEnabled,
|
||||
appVersion,
|
||||
didReboot,
|
||||
isQOrLaterNow,
|
||||
addedManipulationFlags
|
||||
}: SerializedUpdateDeviceStatusAction) => (
|
||||
new UpdateDeviceStatusAction({
|
||||
newProtetionLevel: protectionLevel,
|
||||
newUsageStatsPermissionStatus: usageStats,
|
||||
@@ -81,7 +97,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
newAccessibilityServiceEnabled: accessibilityServiceEnabled,
|
||||
newAppVersion: appVersion,
|
||||
didReboot: !!didReboot,
|
||||
isQOrLaterNow: !!isQOrLaterNow
|
||||
isQOrLaterNow: !!isQOrLaterNow,
|
||||
addedManipulationFlags: addedManipulationFlags || 0
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -96,4 +113,5 @@ export interface SerializedUpdateDeviceStatusAction {
|
||||
appVersion?: number
|
||||
didReboot?: boolean
|
||||
isQOrLaterNow?: boolean
|
||||
addedManipulationFlags?: number
|
||||
}
|
||||
|
||||
@@ -442,6 +442,9 @@ const definitions = {
|
||||
},
|
||||
"ignoreHadManipulationFlags": {
|
||||
"type": "number"
|
||||
},
|
||||
"ignoreManipulationFlags": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -1750,6 +1753,9 @@ const definitions = {
|
||||
},
|
||||
"isQOrLaterNow": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"addedManipulationFlags": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -1907,6 +1913,9 @@ const definitions = {
|
||||
},
|
||||
"qOrLater": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"mFlags": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -1931,6 +1940,7 @@ const definitions = {
|
||||
"hadManipulation",
|
||||
"hadManipulationFlags",
|
||||
"isUserKeptSignedIn",
|
||||
"mFlags",
|
||||
"model",
|
||||
"name",
|
||||
"networkTime",
|
||||
|
||||
+28
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -32,6 +32,11 @@ export const DeviceHadManipulationFlags = {
|
||||
ALL: 1 | 2 | 4 | 8 | 16 | 32
|
||||
}
|
||||
|
||||
export const DeviceManipulationFlags = {
|
||||
USED_FGS_KILLER: 1,
|
||||
ALL: 1
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion1 {
|
||||
familyId: string
|
||||
deviceId: string
|
||||
@@ -102,10 +107,15 @@ export interface DeviceAttributesVersion11 {
|
||||
hadManipulationFlags: number
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion12 {
|
||||
manipulationFlags: number
|
||||
}
|
||||
|
||||
export type DeviceAttributes = DeviceAttributesVersion1 & DeviceAttributesVersion2 &
|
||||
DeviceAttributesVersion3 & DeviceAttributesVersion4 & DeviceAttributesVersion5 &
|
||||
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8 &
|
||||
DeviceAttributesVersion9 & DeviceAttributesVersion10 & DeviceAttributesVersion11
|
||||
DeviceAttributesVersion9 & DeviceAttributesVersion10 & DeviceAttributesVersion11 &
|
||||
DeviceAttributesVersion12
|
||||
|
||||
export type DeviceModel = Sequelize.Model<DeviceAttributes> & DeviceAttributes
|
||||
export type DeviceModelStatic = typeof Sequelize.Model & {
|
||||
@@ -259,6 +269,18 @@ export const attributesVersion11: SequelizeAttributes<DeviceAttributesVersion11>
|
||||
}
|
||||
}
|
||||
|
||||
export const attributesVersion12: SequelizeAttributes<DeviceAttributesVersion12> = {
|
||||
manipulationFlags: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
validate: {
|
||||
min: 0,
|
||||
max: DeviceManipulationFlags.ALL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
@@ -270,7 +292,8 @@ export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion8,
|
||||
...attributesVersion9,
|
||||
...attributesVersion10,
|
||||
...attributesVersion11
|
||||
...attributesVersion11,
|
||||
...attributesVersion12
|
||||
}
|
||||
|
||||
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModelStatic => sequelize.define('Device', attributes) as DeviceModelStatic
|
||||
@@ -291,7 +314,8 @@ export const hasDeviceManipulation = (device: DeviceAttributes) => {
|
||||
manipulationOfOverlayPermission ||
|
||||
manipulationOfAsPermission
|
||||
|
||||
const hasAnyManipulation = hasActiveManipulationWarning || device.hadManipulation
|
||||
const hasAnyManipulation = hasActiveManipulationWarning || device.hadManipulation ||
|
||||
device.manipulationFlags !== 0
|
||||
|
||||
return hasAnyManipulation
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
import { attributesVersion12 as deviceAttributes } from '../../device'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.addColumn('Devices', 'manipulationFlags', {
|
||||
...deviceAttributes.manipulationFlags
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('Devices', 'manipulationFlags', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -63,5 +63,6 @@ export const prepareDeviceEntry = ({ familyId, userId, deviceAuthToken, deviceId
|
||||
asEnabled: false,
|
||||
wasAsEnabled: false,
|
||||
activityLevelBlocking: false,
|
||||
isQorLater: false
|
||||
isQorLater: false,
|
||||
manipulationFlags: 0
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { UpdateDeviceStatusAction } from '../../../../action'
|
||||
import { DeviceHadManipulationFlags, hasDeviceManipulation } from '../../../../database/device'
|
||||
import { DeviceHadManipulationFlags, DeviceManipulationFlags, hasDeviceManipulation } from '../../../../database/device'
|
||||
import { newPermissionStatusValues } from '../../../../model/newpermissionstatus'
|
||||
import { protetionLevels } from '../../../../model/protectionlevel'
|
||||
import { runtimePermissionStatusValues } from '../../../../model/runtimepermissionstatus'
|
||||
@@ -155,6 +155,14 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const effectiveManipulationFlags = action.addedManipulationFlags & DeviceManipulationFlags.ALL
|
||||
|
||||
if (effectiveManipulationFlags !== 0) {
|
||||
deviceEntry.manipulationFlags = deviceEntry.manipulationFlags | effectiveManipulationFlags
|
||||
}
|
||||
}
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
|
||||
if (hasDeviceManipulation(deviceEntry)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -81,6 +81,10 @@ export async function dispatchIgnoreManipulation ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
if (action.ignoreManipulationFlags !== 0) {
|
||||
deviceEntry.manipulationFlags = deviceEntry.manipulationFlags & (~action.ignoreManipulationFlags)
|
||||
}
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
cache.invalidiateDeviceList = true
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -64,7 +64,8 @@ export async function getDeviceList ({ database, transaction, familyEntry }: {
|
||||
asEnabled: item.asEnabled,
|
||||
wasAsEnabled: item.wasAsEnabled,
|
||||
activityLevelBlocking: item.activityLevelBlocking,
|
||||
qOrLater: item.isQorLater
|
||||
qOrLater: item.isQorLater,
|
||||
mFlags: item.manipulationFlags
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ export interface ServerDeviceData {
|
||||
wasAsEnabled: boolean
|
||||
activityLevelBlocking: boolean
|
||||
qOrLater: boolean
|
||||
mFlags: number // manipulation flags
|
||||
}
|
||||
|
||||
export interface ServerUpdatedCategoryBaseData {
|
||||
|
||||
Reference in New Issue
Block a user