• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
16import Want from '@ohos.app.ability.Want';
17import dlpPermission from '@ohos.dlpPermission';
18import { HiLog } from '../common/HiLog';
19import { clearDlpInfoBatch } from '../OpenDlpFile/common/DataUtils/DataUtils';
20
21const TAG = 'DataAbility';
22
23export default class DataAbility extends ServiceExtensionAbility {
24  private static isSubscriber = false;
25  onCreate(want: Want): void {
26    HiLog.info(TAG, 'DataAbility onCreate');
27  }
28
29  onRequest(want: Want, startId: number): void {
30    HiLog.info(TAG, 'DataAbility onRequest');
31    if (!DataAbility.isSubscriber) {
32      HiLog.info(TAG, 'createSubscriber start');
33      try {
34        dlpPermission.on('uninstallDLPSandbox', (data: dlpPermission.DLPSandboxState) => {
35          HiLog.info(TAG, 'uninstallDLPSandboxCallback');
36          clearDlpInfoBatch(data.bundleName, data.appIndex, this.context);
37        });
38        DataAbility.isSubscriber = true;
39      } catch (err) {
40        HiLog.wrapError(TAG, err, 'createSubscriber uninstallDLPSandbox error');
41      }
42    }
43  }
44
45  onDestroy(): void {
46    HiLog.info(TAG, 'DataAbility onDestroy');
47    if (DataAbility.isSubscriber) {
48      HiLog.info(TAG, 'cancelSubscriber uninstallDLPSandbox');
49      try {
50        dlpPermission.off('uninstallDLPSandbox');
51        DataAbility.isSubscriber = false;
52      } catch (err) {
53        HiLog.wrapError(TAG, err, 'cancelSubscriber uninstallDLPSandbox error');
54      }
55    }
56  }
57}
58