1 // Copyright (C) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use crate::utils::check_permission; 15 16 static INTERNET_PERMISSION: &str = "ohos.permission.INTERNET"; 17 static QUERY_DOWNLOAD: &str = "ohos.permission.DOWNLOAD_SESSION_MANAGER"; 18 static QUERY_UPLOAD: &str = "ohos.permission.UPLOAD_SESSION_MANAGER"; 19 20 pub(crate) struct PermissionChecker; 21 22 impl PermissionChecker { check_internet() -> bool23 pub(crate) fn check_internet() -> bool { 24 check_permission(INTERNET_PERMISSION) 25 } 26 check_query() -> QueryPermission27 pub(crate) fn check_query() -> QueryPermission { 28 debug!("Checks QUERY permission"); 29 30 let query_download = check_permission(QUERY_DOWNLOAD); 31 let query_upload = check_permission(QUERY_UPLOAD); 32 info!( 33 "Checks query_download permission is {}, query_upload permission is {}", 34 query_download, query_upload 35 ); 36 37 match (query_download, query_upload) { 38 (true, true) => QueryPermission::QueryAll, 39 (true, false) => QueryPermission::QueryDownLoad, 40 (false, true) => QueryPermission::QueryUpload, 41 (false, false) => QueryPermission::NoPermission, 42 } 43 } 44 } 45 46 pub(crate) enum QueryPermission { 47 NoPermission = 0, 48 QueryDownLoad, 49 QueryUpload, 50 QueryAll, 51 } 52