From 1270d74a70079f9ea2990d9dc555a918fe6be0c3 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 25 Mar 2019 00:00:00 +0000 Subject: [PATCH] Add overlay permission to update device status action --- src/action/updatedevicestatus.ts | 10 ++++++++-- src/api/validator.ts | 8 ++++++++ .../updatedevicestatus.ts | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/action/updatedevicestatus.ts b/src/action/updatedevicestatus.ts index fe5dcad..ba4d2b9 100644 --- a/src/action/updatedevicestatus.ts +++ b/src/action/updatedevicestatus.ts @@ -24,13 +24,15 @@ export class UpdateDeviceStatusAction extends AppLogicAction { readonly newProtetionLevel?: ProtectionLevel readonly newUsageStatsPermissionStatus?: RuntimePermissionStatus readonly newNotificationAccessPermission?: NewPermissionStatus + readonly newOverlayPermission?: RuntimePermissionStatus readonly newAppVersion?: number readonly didReboot: boolean - constructor ({ newProtetionLevel, newUsageStatsPermissionStatus, newNotificationAccessPermission, newAppVersion, didReboot }: { + constructor ({ newProtetionLevel, newUsageStatsPermissionStatus, newNotificationAccessPermission, newOverlayPermission, newAppVersion, didReboot }: { newProtetionLevel?: ProtectionLevel newUsageStatsPermissionStatus?: RuntimePermissionStatus newNotificationAccessPermission?: NewPermissionStatus + newOverlayPermission?: RuntimePermissionStatus newAppVersion?: number didReboot: boolean }) { @@ -45,6 +47,7 @@ export class UpdateDeviceStatusAction extends AppLogicAction { this.newProtetionLevel = newProtetionLevel this.newUsageStatsPermissionStatus = newUsageStatsPermissionStatus this.newNotificationAccessPermission = newNotificationAccessPermission + this.newOverlayPermission = newOverlayPermission this.newAppVersion = newAppVersion this.didReboot = didReboot } @@ -54,15 +57,17 @@ export class UpdateDeviceStatusAction extends AppLogicAction { protectionLevel: this.newProtetionLevel, usageStats: this.newUsageStatsPermissionStatus, notificationAccess: this.newNotificationAccessPermission, + overlayPermission: this.newOverlayPermission, appVersion: this.newAppVersion, didReboot: this.didReboot }) - static parse = ({ protectionLevel, usageStats, notificationAccess, appVersion, didReboot }: SerializedUpdateDeviceStatusAction) => ( + static parse = ({ protectionLevel, usageStats, notificationAccess, overlayPermission, appVersion, didReboot }: SerializedUpdateDeviceStatusAction) => ( new UpdateDeviceStatusAction({ newProtetionLevel: protectionLevel, newUsageStatsPermissionStatus: usageStats, newNotificationAccessPermission: notificationAccess, + newOverlayPermission: overlayPermission, newAppVersion: appVersion, didReboot: !!didReboot }) @@ -74,6 +79,7 @@ export interface SerializedUpdateDeviceStatusAction { protectionLevel?: ProtectionLevel usageStats?: RuntimePermissionStatus notificationAccess?: NewPermissionStatus + overlayPermission?: RuntimePermissionStatus appVersion?: number didReboot?: boolean } diff --git a/src/api/validator.ts b/src/api/validator.ts index be24725..af82988 100644 --- a/src/api/validator.ts +++ b/src/api/validator.ts @@ -1112,6 +1112,14 @@ const definitions = { ], "type": "string" }, + "overlayPermission": { + "enum": [ + "granted", + "not granted", + "not required" + ], + "type": "string" + }, "appVersion": { "type": "number" }, diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts index afdd2d7..36229a2 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts @@ -91,6 +91,22 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: { } } + if (action.newOverlayPermission) { + const hasChanged = deviceEntry.currentOverlayPermission !== action.newOverlayPermission + + deviceEntry.currentOverlayPermission = action.newOverlayPermission + + deviceEntry.highestOverlayPermission = enumMax( + deviceEntry.currentOverlayPermission, + deviceEntry.highestOverlayPermission, + runtimePermissionStatusValues + ) + + if (hasChanged && (deviceEntry.currentOverlayPermission !== deviceEntry.highestOverlayPermission)) { + deviceEntry.hadManipulation = true + } + } + if (action.newAppVersion !== undefined) { const hasChanged = deviceEntry.currentAppVersion !== action.newAppVersion