mirror of
https://gitee.com/openharmony/usb_usb_manager
synced 2024-11-27 00:41:39 +00:00
mtp feature
Signed-off-by: Atsws <pangjiahao@h-partners.com>
This commit is contained in:
parent
132638faf7
commit
3c18fe9e2e
@ -15,7 +15,8 @@
|
||||
"subsystem": "usb",
|
||||
"features": [
|
||||
"usb_manager_feature_pop_up_func_switch_model",
|
||||
"usb_manager_feature_usb_right_dialog"
|
||||
"usb_manager_feature_usb_right_dialog",
|
||||
"usb_manager_feature_support_mtp"
|
||||
],
|
||||
"syscap": [
|
||||
"SystemCapability.USB.USBManager"
|
||||
|
@ -27,6 +27,7 @@ const COLOR_MODE_NOT_SET = -1;
|
||||
export default class UsbFunctionSwitchAbility extends UIExtensionAbility {
|
||||
onSessionCreate(want, session): void {
|
||||
console.log(TAG + 'UsbFunctionSwitchAbility onSessionCreate');
|
||||
globalThis.want = want;
|
||||
let callingTokenId: number = rpc.IPCSkeleton.getCallingTokenId();
|
||||
if (!this.isSystemAbility(callingTokenId)) {
|
||||
console.error('check permission fail');
|
||||
|
@ -33,6 +33,39 @@ struct IndexHapComponent {
|
||||
private currentChoice: number = 2;
|
||||
private content: string = ''
|
||||
private thisWant: string = ''
|
||||
private supportMtp: boolean = false
|
||||
private contentWithMtp:Array<SheetInfo> = [
|
||||
{
|
||||
title: $r('app.string.USB_func_mtp'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_XFER_FILE;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $r('app.string.USB_func_ptp'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_XFER_PIC;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $r('app.string.USB_func_charge'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_CHARGE_ONLY;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
];
|
||||
private contentEmptyMtp:Array<SheetInfo> = [
|
||||
{
|
||||
title: $r('app.string.USB_func_charge'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_CHARGE_ONLY;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
];
|
||||
dialogControllerList: CustomDialogController = new CustomDialogController({
|
||||
builder: SelectDialog({
|
||||
title: $r('app.string.USB_hint'),
|
||||
@ -46,29 +79,7 @@ struct IndexHapComponent {
|
||||
}
|
||||
},
|
||||
},
|
||||
radioContent: [
|
||||
{
|
||||
title: $r('app.string.USB_func_mtp'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_XFER_FILE;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $r('app.string.USB_func_ptp'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_XFER_PIC;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: $r('app.string.USB_func_charge'),
|
||||
action: () => {
|
||||
let tmpChooseNumber:number = USBSERVICESWITCH_ID_CHARGE_ONLY;
|
||||
this.setUsbFunction(tmpChooseNumber);
|
||||
}
|
||||
},
|
||||
]
|
||||
radioContent: this.supportMtp ? this.contentWithMtp : this.contentEmptyMtp,
|
||||
}),
|
||||
alignment: DialogAlignment.Center,
|
||||
autoCancel: true,
|
||||
@ -87,6 +98,16 @@ struct IndexHapComponent {
|
||||
|
||||
async aboutToAppear() {
|
||||
setTimeout(() => {
|
||||
if (!globalThis.want || !globalThis.want.parameters) {
|
||||
console.error(TAG + 'get globalThis.want error ');
|
||||
} else {
|
||||
if (!globalThis.want.parameters['SupportMtp']) {
|
||||
this.supportMtp = false;
|
||||
console.warn(TAG + 'The device may not support mtp');
|
||||
} else {
|
||||
this.supportMtp = true;
|
||||
}
|
||||
}
|
||||
this.dialogControllerList.open();
|
||||
});
|
||||
}
|
||||
|
@ -95,6 +95,9 @@ ohos_shared_library("usbservice") {
|
||||
if (usb_manager_feature_pop_up_func_switch_model) {
|
||||
defines += [ "USB_FUNC_SWITCH_MODE" ]
|
||||
}
|
||||
if (usb_manager_feature_support_mtp) {
|
||||
defines += [ "USB_FUNC_SUPPORT_MTP" ]
|
||||
}
|
||||
shlib_type = "sa"
|
||||
version_script = "usbservice.map"
|
||||
subsystem_name = "usb"
|
||||
|
@ -143,6 +143,10 @@ void UsbFunctionSwitchWindow::UsbFuncAbilityConn::OnAbilityConnectDone(const App
|
||||
data.WriteString16(u"UsbFunctionSwitchExtAbility");
|
||||
data.WriteString16(u"parameters");
|
||||
cJSON* paramJson = cJSON_CreateObject();
|
||||
#ifdef USB_FUNC_SUPPORT_MTP
|
||||
USB_HILOGI(MODULE_USB_SERVICE, "SupportMtp is true");
|
||||
cJSON_AddStringToObject(paramJson, "SupportMtp", "true");
|
||||
#endif // USB_FUNC_SUPPORT_MTP
|
||||
std::string uiExtensionTypeStr = "sysDialog/common";
|
||||
cJSON_AddStringToObject(paramJson, "ability.want.params.uiExtensionType", uiExtensionTypeStr.c_str());
|
||||
char *pParamJson = cJSON_PrintUnformatted(paramJson);
|
||||
|
@ -19,4 +19,5 @@ utils_path = "${usb_manager_path}/utils"
|
||||
|
||||
declare_args() {
|
||||
usb_manager_feature_pop_up_func_switch_model = true
|
||||
usb_manager_feature_support_mtp = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user