[CP-3917] Clear device data system action (#2689)

This commit is contained in:
slawomir-werner
2025-10-10 11:16:39 +02:00
committed by GitHub
parent 98c535b879
commit 04daae8633
6 changed files with 31 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ import {
import { clearContact } from "./helpers/clear-contact-data"
import { exec } from "child_process"
import util from "util"
import { clearDeviceData } from "./helpers/clear-device-data"
export const execPromise = util.promisify(exec)
jest.mock("shared/utils", () => {
@@ -48,8 +49,8 @@ describe("Contact entities", () => {
}, 10000)
beforeEach(async () => {
await clearContactsDatabase()
deviceProtocol = setActiveDevice(await setKompaktConnection())
await clearDatabase(deviceProtocol)
})
afterEach(async () => {
@@ -242,12 +243,9 @@ describe("Contact entities", () => {
return undefined
}
const clearContactsDatabase = async (): Promise<void> => {
try {
const command = `adb shell pm clear com.android.providers.contacts`
await execPromise(command)
} catch (err) {
console.log(err)
}
const clearDatabase = async (
deviceProtocol: DeviceProtocol
): Promise<void> => {
await clearDeviceData(deviceProtocol)
}
})

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/
import { DeviceProtocol } from "device-protocol/feature"
import { DeviceSystemActionsService } from "device/feature"
export const clearDeviceData = async (deviceProtocol: DeviceProtocol) => {
const systemActionsService = new DeviceSystemActionsService(deviceProtocol)
return await systemActionsService.clearDeviceData()
}

View File

@@ -18,3 +18,4 @@ export * from "./lib/data-transfer"
export * from "./lib/msc-device"
export * from "./lib/service-bridge"
export * from "./lib/api-test-tools"
export * from "./lib/device-system-actions"

View File

@@ -53,4 +53,9 @@ export class DeviceSystemActionsService {
public powerOff({ deviceId }: { deviceId?: string } = {}) {
return this.sendSystemRequest("powerOff", { deviceId })
}
@IpcEvent(DeviceSystemActionsServiceEvents.ClearData)
public clearDeviceData({ deviceId }: { deviceId?: string } = {}) {
return this.sendSystemRequest("clearData", { deviceId })
}
}

View File

@@ -0,0 +1,6 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/
export * from "./device-system-actions.service"

View File

@@ -7,4 +7,5 @@ export enum DeviceSystemActionsServiceEvents {
Reboot = "apiservice_device_system_actions-reboot",
Lock = "apiservice_device_system_actions-lock",
PowerOff = "apiservice_device_system_actions-power-off",
ClearData = "apiservice_device_system_actions-clear-data",
}