mirror of
https://github.com/openharmony/applications_admin_provisioning.git
synced 2026-07-21 01:05:23 -04:00
fix hap error Signed-off-by: liwuli <liwuli@huawei.com>
This commit is contained in:
@@ -18,15 +18,15 @@ import logger from '../common/logger';
|
||||
import type Want from '@ohos.app.ability.Want';
|
||||
import type AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import type window from '@ohos.window';
|
||||
import { GlobalContext } from './MainAbility';
|
||||
|
||||
const TAG = 'AutoManagerAbility';
|
||||
|
||||
export default class AutoManagerAbility extends UIAbility {
|
||||
private localStorage: LocalStorage = new LocalStorage();
|
||||
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
logger.info(TAG, 'onCreate');
|
||||
GlobalContext.getContext().setObject('autoManagerAbilityWant', want);
|
||||
GlobalContext.getContext().setObject('autoManagerAbilityContext', this.context);
|
||||
this.localStorage.setOrCreate('autoManagerAbilityWant', want);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
@@ -36,7 +36,7 @@ export default class AutoManagerAbility extends UIAbility {
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
logger.info(TAG, 'onWindowStageCreate');
|
||||
windowStage.loadContent('pages/autoManager/managerStart', null);
|
||||
windowStage.loadContent('pages/autoManager/managerStart', this.localStorage);
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
|
||||
@@ -16,34 +16,14 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import Logger from '../common/logger';
|
||||
|
||||
export class GlobalContext {
|
||||
private constructor() {}
|
||||
private static instance: GlobalContext;
|
||||
private _objects = new Map<string, Object>();
|
||||
|
||||
public static getContext(): GlobalContext {
|
||||
if (!GlobalContext.instance) {
|
||||
GlobalContext.instance = new GlobalContext();
|
||||
}
|
||||
return GlobalContext.instance;
|
||||
}
|
||||
|
||||
getObject(value: string): Object | undefined {
|
||||
return this._objects.get(value);
|
||||
}
|
||||
|
||||
setObject(key: string, objectClass: Object): void {
|
||||
this._objects.set(key, objectClass);
|
||||
}
|
||||
}
|
||||
|
||||
const TAG = 'MainAbility';
|
||||
|
||||
export default class MainAbility extends UIAbility {
|
||||
private localStorage: LocalStorage = new LocalStorage();
|
||||
|
||||
onCreate(want, launchParam): void {
|
||||
Logger.info(TAG, 'onCreate');
|
||||
GlobalContext.getContext().setObject('adminProvisioningWant', want);
|
||||
GlobalContext.getContext().setObject('adminProvisioningContext', this.context);
|
||||
this.localStorage.setOrCreate('adminProvisioningWant', want);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
@@ -53,7 +33,7 @@ export default class MainAbility extends UIAbility {
|
||||
onWindowStageCreate(windowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
Logger.info(TAG, 'onWindowStageCreate');
|
||||
windowStage.setUIContent(this.context, 'pages/applicationInfo', null);
|
||||
windowStage.setUIContent(this.context, 'pages/applicationInfo', this.localStorage);
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
|
||||
@@ -21,7 +21,6 @@ import utils from '../utils'
|
||||
import { AppPermission, MyApplicationInfo } from '../myApplicationInfo'
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import { GlobalContext } from '../../MainAbility/MainAbility';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
let icon_default = $r('app.media.icon');
|
||||
@@ -54,7 +53,7 @@ export class AppDetailData {
|
||||
}
|
||||
let data: Array<bundle.ExtensionAbilityInfo> = [];
|
||||
try {
|
||||
bundle.queryExtensionAbilityInfo(want, bundle.ExtensionAbilityType.ENTERPRISE_ADMIN,
|
||||
await bundle.queryExtensionAbilityInfo(want, bundle.ExtensionAbilityType.ENTERPRISE_ADMIN,
|
||||
bundle.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION, userId.localId).then((result)=>{
|
||||
data = result;
|
||||
})
|
||||
@@ -141,7 +140,7 @@ export class AppDetailData {
|
||||
|
||||
async terminateAbilityPage() {
|
||||
logger.info(TAG, 'terminateAbilityPage in:');
|
||||
await (GlobalContext.getContext().getObject("adminProvisioningContext") as common.UIAbilityContext).terminateSelf();
|
||||
await (getContext(this) as common.UIAbilityContext).terminateSelf();
|
||||
}
|
||||
|
||||
getPermissionInfoVal(permissionName: string): number {
|
||||
|
||||
@@ -26,7 +26,7 @@ import { AppPermission, MyApplicationInfo } from '../common/myApplicationInfo'
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import adminManager from '@ohos.enterprise.adminManager';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { GlobalContext } from '../MainAbility/MainAbility';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
let appInfo: MyApplicationInfo;
|
||||
let elementNameVal: Want;
|
||||
@@ -51,6 +51,7 @@ struct ApplicationInfo {
|
||||
@State deviceAdminDisActive: string = '';
|
||||
@State enterpriseName: string = '';
|
||||
@State enterpriseDescription: string = '';
|
||||
private storage = LocalStorage.getShared();
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@@ -116,7 +117,7 @@ struct ApplicationInfo {
|
||||
});
|
||||
|
||||
List() {
|
||||
ForEach(appInfo.appPermissionList, (item: AppPermission) => {
|
||||
ForEach(this.applicationInfo.appPermissionList, (item: AppPermission) => {
|
||||
ListItem() {
|
||||
permissionListComponent({
|
||||
permissionName: item.permissionLabel,
|
||||
@@ -208,14 +209,7 @@ struct ApplicationInfo {
|
||||
.backgroundColor($r('sys.color.ohos_id_color_sub_background'))
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
appInfo = {
|
||||
appIcon: '',
|
||||
appTitle: '',
|
||||
appBundleName: '',
|
||||
appPermissionList: [],
|
||||
};
|
||||
|
||||
async aboutToAppear(): Promise<void> {
|
||||
elementNameVal = {
|
||||
abilityName: '',
|
||||
bundleName: '',
|
||||
@@ -228,7 +222,7 @@ struct ApplicationInfo {
|
||||
|
||||
isAdminTypeVal = 0;
|
||||
logger.info(TAG, 'aboutToAppear in');
|
||||
this.getCheckAbilityList(appInfo, elementNameVal, isAdminTypeVal);
|
||||
await this.getCheckAbilityList(this.applicationInfo, elementNameVal, isAdminTypeVal);
|
||||
logger.info(TAG, 'aboutToAppear out');
|
||||
}
|
||||
|
||||
@@ -340,7 +334,8 @@ struct ApplicationInfo {
|
||||
|
||||
async getAbilityWantVal(appInfo: MyApplicationInfo, elementNameVal: Want, adminType: adminManager.AdminType) {
|
||||
logger.info(TAG, 'getAbilityWantVal in:');
|
||||
let data = GlobalContext.getContext().getObject("adminProvisioningWant") as Want;
|
||||
this.storage = LocalStorage.getShared();
|
||||
let data = this.storage.get<Want>('adminProvisioningWant');
|
||||
|
||||
if (!utils.checkObjPropertyValid(data, 'parameters.elementName.abilityName')
|
||||
|| !utils.checkObjPropertyValid(data, 'parameters.enterprise.name')
|
||||
@@ -348,6 +343,7 @@ struct ApplicationInfo {
|
||||
|| !utils.isValid(data.parameters?.activeType)
|
||||
|| !utils.isValid((data.parameters?.enterprise as Record<string, string>).description)) {
|
||||
logger.warn(TAG, 'data.parameters = ' + JSON.stringify(data.parameters));
|
||||
(getContext(this) as common.UIAbilityContext).terminateSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -387,13 +383,10 @@ struct ApplicationInfo {
|
||||
await appDetailData.getBundleInfoItem(appInfo.appBundleName, appInfo);
|
||||
}
|
||||
|
||||
deviceActiveOne = await this.getSelfResourceVal($r('app.string.device_active_1'));
|
||||
deviceActiveTwo = await this.getSelfResourceVal($r('app.string.device_active_2'));
|
||||
deviceDeactivate = await this.getSelfResourceVal($r('app.string.device_deactivate'));
|
||||
enterName = await this.getSelfResourceVal($r('app.string.enterprise_name'));
|
||||
enterDescription = await this.getSelfResourceVal($r('app.string.enterprise_description'));
|
||||
this.deviceAdminActive = deviceActiveOne + `${appInfo.appTitle}` + deviceActiveTwo;
|
||||
this.deviceAdminDisActive = deviceDeactivate + `${appInfo.appTitle}` + deviceActiveTwo;
|
||||
this.deviceAdminActive = getContext().resourceManager.getStringSync($r('app.string.textApplicationInfoActive').id, `${appInfo.appTitle}`);
|
||||
this.deviceAdminDisActive = getContext().resourceManager.getStringSync($r('app.string.textApplicationInfoInactive').id, `${appInfo.appTitle}`);
|
||||
|
||||
let want: Want = {
|
||||
bundleName: elementNameVal.bundleName,
|
||||
|
||||
@@ -17,8 +17,8 @@ import router from '@ohos.router';
|
||||
import utils from '../../common/utils'
|
||||
import doubleButtonComponent from '../component/autoManager/doubleButtonComponent'
|
||||
import logger from '../../common/logger'
|
||||
import { GlobalContext } from '../../MainAbility/MainAbility';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
const TAG = 'ManagerStart';
|
||||
|
||||
@@ -31,6 +31,7 @@ struct ManagerStart {
|
||||
@State textManagerAfter: Resource = $r('app.string.textManagerAfter');
|
||||
@State textTerms: Resource = $r('app.string.textTerms');
|
||||
@State textTermsBefore: Resource = $r('app.string.textTermsBefore');
|
||||
private storage = LocalStorage.getShared();
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@@ -176,7 +177,8 @@ struct ManagerStart {
|
||||
}
|
||||
|
||||
parseManageParameter() {
|
||||
let data = GlobalContext.getContext().getObject('autoManagerAbilityWant') as Want;
|
||||
this.storage = LocalStorage.getShared();
|
||||
let data = this.storage.get<Want>('autoManagerAbilityWant');
|
||||
|
||||
if (!utils.checkObjPropertyValid(data, 'parameters.elementName.abilityName')
|
||||
|| !utils.checkObjPropertyValid(data, 'parameters.enterprise.name')
|
||||
@@ -185,7 +187,8 @@ struct ManagerStart {
|
||||
|| !utils.isValid(data.parameters?.termsName)
|
||||
|| (!utils.isValid(data.parameters?.termsContent) || !(data.parameters?.termsContent instanceof Array))
|
||||
|| !utils.isValid((data.parameters?.enterprise as Record<string, string>).description)) {
|
||||
logger.error(TAG, 'parseManageParameter fail! parameters is not valid')
|
||||
logger.error(TAG, 'parseManageParameter fail! parameters is not valid');
|
||||
(getContext(this) as common.UIAbilityContext).terminateSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,20 @@ import utils from '../../common/utils'
|
||||
@Component
|
||||
struct SetFinishSuccess {
|
||||
@State textContext: Resource = $r('app.string.setupComplete');
|
||||
@State textManager: Resource = $r('app.string.unitManage');
|
||||
@State textManagerBefore: Resource = $r('app.string.textManagerBeforeFinish');
|
||||
@State textManagerAfter: Resource = $r('app.string.textManagerAfter');
|
||||
@State textManager: string = getContext().resourceManager.getStringSync($r('app.string.unitManage').id);
|
||||
private textContent: string = getContext().resourceManager.getStringSync($r('app.string.textManageSuccessContent').id, this.textManager);
|
||||
private getTextList: (source: string, target: string) => Array<string> = (source: string, target: string) => {
|
||||
let result: Array<string> = new Array<string>();
|
||||
if (source) {
|
||||
let position: number = source.indexOf(target);
|
||||
let before: string = source.substring(0, position);
|
||||
let after: string = source.substring(position + target.length);
|
||||
result.push(before);
|
||||
result.push(target);
|
||||
result.push(after);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@@ -58,26 +69,19 @@ struct SetFinishSuccess {
|
||||
Column() {
|
||||
Row() {
|
||||
Text() {
|
||||
Span(this.textManagerBefore)
|
||||
.fontWeight(FontWeight.Regular)
|
||||
.fontSize($r('app.float.font_vp_16'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
|
||||
Span(this.textManager)
|
||||
.decoration({ type: TextDecorationType.None })
|
||||
.fontColor(0x007DFF)
|
||||
.fontSize($r('app.float.font_vp_16'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontWeight(FontWeight.Regular)
|
||||
.onClick(() => {
|
||||
router.pushUrl({url: 'pages/autoManager/unitManagerShowPage'})
|
||||
})
|
||||
|
||||
Span(this.textManagerAfter)
|
||||
.fontWeight(FontWeight.Regular)
|
||||
.fontSize($r('app.float.font_vp_16'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
ForEach(this.getTextList(this.textContent, this.textManager), (item: string) => {
|
||||
Span(item)
|
||||
.fontColor(item === this.textManager ? 0x007DFF: 0x000000)
|
||||
.onClick(() => {
|
||||
if (item === this.textManager) {
|
||||
router.pushUrl({url: 'pages/autoManager/unitManagerShowPage'})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
.fontWeight(FontWeight.Regular)
|
||||
.fontSize($r('app.float.font_vp_16'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.lineHeight($r('app.float.lineHeight_vp_21_5'))
|
||||
}
|
||||
.useSizeType({
|
||||
|
||||
@@ -14,13 +14,11 @@
|
||||
*/
|
||||
|
||||
import bundle from '@ohos.bundle.bundleManager';
|
||||
import router from '@ohos.router';
|
||||
import baseData from '../../../common/baseData'
|
||||
import logger from '../../../common/logger'
|
||||
import resetFactory from '../../../common/resetFactory'
|
||||
import utils from '../../../common/utils'
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import { GlobalContext } from '../../../MainAbility/MainAbility';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
const TAG = 'DoubleButtonComponent';
|
||||
@@ -58,7 +56,7 @@ export default struct DoubleButtonComponent {
|
||||
if (this.returnDialogFlag) {
|
||||
this.buttonDialog.open();
|
||||
} else {
|
||||
router.back();
|
||||
(getContext(this) as common.UIAbilityContext).terminateSelf();
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -111,8 +109,7 @@ export default struct DoubleButtonComponent {
|
||||
logger.info(TAG, 'startSpecificActionAbility data len='
|
||||
+ data.length + ' | data content=' + data[0].name)
|
||||
try {
|
||||
await (GlobalContext.getContext()
|
||||
.getObject("autoManagerAbilityContext") as common.UIAbilityContext).startAbility({
|
||||
await (getContext(this) as common.UIAbilityContext).startAbility({
|
||||
bundleName: this.nextBundleName,
|
||||
abilityName: data[0].name
|
||||
});
|
||||
@@ -120,8 +117,7 @@ export default struct DoubleButtonComponent {
|
||||
logger.error(TAG, "startSpecificActionAbility startAbility fail! " + e)
|
||||
}
|
||||
}
|
||||
await (GlobalContext.getContext()
|
||||
.getObject("autoManagerAbilityContext") as common.UIAbilityContext).terminateSelf();
|
||||
await (getContext(this) as common.UIAbilityContext).terminateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
@Component
|
||||
export default struct HeadComponent {
|
||||
@@ -32,7 +32,7 @@ export default struct HeadComponent {
|
||||
.backgroundColor($r('app.color.color_00000000_transparent'))
|
||||
.visibility(Visibility.Visible)
|
||||
.onClick(() => {
|
||||
router.back();
|
||||
(getContext(this) as common.UIAbilityContext).terminateSelf();
|
||||
})
|
||||
Text(this.headName)
|
||||
.height($r('app.float.wh_value_56'))
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
"name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN"
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
"name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN"
|
||||
|
||||
@@ -162,23 +162,23 @@
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContentVal1",
|
||||
"value": "%1$s"
|
||||
"value": "%s"
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContentVal2",
|
||||
"value": "%2$s"
|
||||
"value": "%s"
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContent",
|
||||
"value": "如有疑问,请与您的%1$s联系。"
|
||||
"value": "如有疑问,请与您的%s联系。"
|
||||
},
|
||||
{
|
||||
"name": "textApplicationInfoActive",
|
||||
"value": "此管理器已激活,允许应用\"%1$s\"执行以下操作:"
|
||||
"value": "此管理器已激活,允许应用\"%s\"执行以下操作:"
|
||||
},
|
||||
{
|
||||
"name": "textApplicationInfoInactive",
|
||||
"value": "激活此管理器可允许应用\"%1$s\"执行以下操作:"
|
||||
"value": "激活此管理器可允许应用\"%s\"执行以下操作:"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -162,23 +162,23 @@
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContentVal1",
|
||||
"value": "%1$s"
|
||||
"value": "%s"
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContentVal2",
|
||||
"value": "%2$s"
|
||||
"value": "%s"
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContent",
|
||||
"value": "if you have any questions, please contact your %1$s contact."
|
||||
"value": "if you have any questions, please contact your %s contact."
|
||||
},
|
||||
{
|
||||
"name": "textApplicationInfoActive",
|
||||
"value": "This device administrator is currently active and allows \"%1$s\" to perform the following operations:"
|
||||
"value": "This device administrator is currently active and allows \"%s\" to perform the following operations:"
|
||||
},
|
||||
{
|
||||
"name": "textApplicationInfoInactive",
|
||||
"value": "Activating this administrator will allow \"%1$s\" to perform the following operations:"
|
||||
"value": "Activating this administrator will allow \"%s\" to perform the following operations:"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -162,23 +162,23 @@
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContentVal1",
|
||||
"value": "%1$s"
|
||||
"value": "%s"
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContentVal2",
|
||||
"value": "%2$s"
|
||||
"value": "%s"
|
||||
},
|
||||
{
|
||||
"name": "textManageSuccessContent",
|
||||
"value": "如有疑问,请与您的%1$s联系。"
|
||||
"value": "如有疑问,请与您的%s联系。"
|
||||
},
|
||||
{
|
||||
"name": "textApplicationInfoActive",
|
||||
"value": "此管理器已激活,允许应用\"%1$s\"执行以下操作:"
|
||||
"value": "此管理器已激活,允许应用\"%s\"执行以下操作:"
|
||||
},
|
||||
{
|
||||
"name": "textApplicationInfoInactive",
|
||||
"value": "激活此管理器可允许应用\"%1$s\"执行以下操作:"
|
||||
"value": "激活此管理器可允许应用\"%s\"执行以下操作:"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user