From 46af33f2cd3d85ec2b367d0ff23b4671f0e82ede Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 3 Jun 2019 00:00:00 +0000 Subject: [PATCH] Extend device status action for q or later --- src/action/updatedevicestatus.ts | 23 +++++++++++++++---- src/api/validator.ts | 3 +++ .../updatedevicestatus.ts | 8 +++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/action/updatedevicestatus.ts b/src/action/updatedevicestatus.ts index 41c56f7..24abafb 100644 --- a/src/action/updatedevicestatus.ts +++ b/src/action/updatedevicestatus.ts @@ -28,8 +28,18 @@ export class UpdateDeviceStatusAction extends AppLogicAction { readonly newAccessibilityServiceEnabled?: boolean readonly newAppVersion?: number readonly didReboot: boolean + readonly isQOrLaterNow: boolean - constructor ({ newProtetionLevel, newUsageStatsPermissionStatus, newNotificationAccessPermission, newOverlayPermission, newAccessibilityServiceEnabled, newAppVersion, didReboot }: { + constructor ({ + newProtetionLevel, + newUsageStatsPermissionStatus, + newNotificationAccessPermission, + newOverlayPermission, + newAccessibilityServiceEnabled, + newAppVersion, + didReboot, + isQOrLaterNow + }: { newProtetionLevel?: ProtectionLevel newUsageStatsPermissionStatus?: RuntimePermissionStatus newNotificationAccessPermission?: NewPermissionStatus @@ -37,6 +47,7 @@ export class UpdateDeviceStatusAction extends AppLogicAction { newAccessibilityServiceEnabled?: boolean newAppVersion?: number didReboot: boolean + isQOrLaterNow: boolean }) { super() @@ -53,6 +64,7 @@ export class UpdateDeviceStatusAction extends AppLogicAction { this.newAccessibilityServiceEnabled = newAccessibilityServiceEnabled this.newAppVersion = newAppVersion this.didReboot = didReboot + this.isQOrLaterNow = isQOrLaterNow } serialize = (): SerializedUpdateDeviceStatusAction => ({ @@ -63,10 +75,11 @@ export class UpdateDeviceStatusAction extends AppLogicAction { overlayPermission: this.newOverlayPermission, accessibilityServiceEnabled: this.newAccessibilityServiceEnabled, appVersion: this.newAppVersion, - didReboot: this.didReboot + didReboot: this.didReboot, + isQOrLaterNow: this.isQOrLaterNow }) - static parse = ({ protectionLevel, usageStats, notificationAccess, overlayPermission, accessibilityServiceEnabled, appVersion, didReboot }: SerializedUpdateDeviceStatusAction) => ( + static parse = ({ protectionLevel, usageStats, notificationAccess, overlayPermission, accessibilityServiceEnabled, appVersion, didReboot, isQOrLaterNow }: SerializedUpdateDeviceStatusAction) => ( new UpdateDeviceStatusAction({ newProtetionLevel: protectionLevel, newUsageStatsPermissionStatus: usageStats, @@ -74,7 +87,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction { newOverlayPermission: overlayPermission, newAccessibilityServiceEnabled: accessibilityServiceEnabled, newAppVersion: appVersion, - didReboot: !!didReboot + didReboot: !!didReboot, + isQOrLaterNow: !!isQOrLaterNow }) ) } @@ -88,4 +102,5 @@ export interface SerializedUpdateDeviceStatusAction { accessibilityServiceEnabled?: boolean appVersion?: number didReboot?: boolean + isQOrLaterNow?: boolean } diff --git a/src/api/validator.ts b/src/api/validator.ts index a4992d7..96e96c6 100644 --- a/src/api/validator.ts +++ b/src/api/validator.ts @@ -1225,6 +1225,9 @@ const definitions = { }, "didReboot": { "type": "boolean" + }, + "isQOrLaterNow": { + "type": "boolean" } }, "additionalProperties": false, 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 a6f9235..444c345 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 @@ -140,6 +140,14 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: { deviceEntry.didReboot = true } + if (action.isQOrLaterNow) { + const hasChanged = deviceEntry.isQorLater === false + + if (hasChanged) { + deviceEntry.isQorLater = true + } + } + await deviceEntry.save({ transaction: cache.transaction }) if (hasDeviceManipulation(deviceEntry)) {