简体   繁体   English

如何为 Tizen 本机服务应用程序请求隐私权限

[英]How to Request Privacy Privileges for Tizen Native Service Application

I am working on a Hybrid App (Web UI with Native Service) of API version 4.0 for my Gear S3 Frontier.我正在为我的 Gear S3 Frontier 开发 API 版本 4.0 的混合应用程序(带有本机服务的 Web UI)。

  • The Web UI launches the Service. Web UI 启动服务。
  • Native Service uses the Sensor and Location data本机服务使用传感器和位置数据

My Service App has the privilege of Sensor and Location in the manifest file.我的服务应用程序在清单文件中具有传感器和位置的权限。 When I check the privileges in code, the results show that I need to get privilege from user, which is fine.当我检查代码中的权限时,结果显示我需要从用户那里获取权限,这很好。

I've implemented it using the Privacy Privilege Manager but when I request for privilege using the ppm_request_permission method, it doesn't show any message asking for the permission, and so it doesn't go the ppm_request_response_cb method.我已经使用Privacy Privilege Manager实现了它,但是当我使用ppm_request_permission方法请求权限时,它不会显示任何请求权限的消息,因此它不会使用ppm_request_response_cb方法。

Here's the relevant code:这是相关的代码:

Response Handler Implementation:响应处理程序实现:

void ppm_request_response_handler(ppm_call_cause_e cause, ppm_request_result_e result, const char *privilege, void *user_data)
{

    dlog_print(DLOG_DEBUG, TAG, "In the ppm_request_response_handler.");

    /*
     * The result of a response triggered by calling ppm_request_permission() is a valid value only if
     * the cause parameter is equal to PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ANSWER.
     */
    if(cause == PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ANSWER)
    {
        if(result == PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER)
        {
            if(!strcmp(privilege, "http://tizen.org/privilege/location"))
            {
                bIsLocationPrivilegeGranted = true;
                dlog_print(DLOG_DEBUG, TAG, "Service Application has been granted the Location privilege.");
            }

            if(!strcmp(privilege, "http://tizen.org/privilege/healthinfo"))
            {
                bIsHealthInfoPrivilegeGranted = true;
                dlog_print(DLOG_DEBUG, TAG, "Service Application has been granted the Health Info privilege.");
            }
        }
        else
        {
            if(!strcmp(privilege, "http://tizen.org/privilege/location"))
            {
                dlog_print(DLOG_DEBUG, TAG, "Service Application is denied to access the Location.");
            }

            if(!strcmp(privilege, "http://tizen.org/privilege/healthinfo"))
            {
                dlog_print(DLOG_DEBUG, TAG, "Service Application is denied to access the Health Information.");
            }
        }
    }
    else
    {
        if(!strcmp(privilege, "http://tizen.org/privilege/location"))
        {
            dlog_print(DLOG_DEBUG, TAG, "Service Application did not get any response to access the Location.");
        }

        if(!strcmp(privilege, "http://tizen.org/privilege/healthinfo"))
        {
            dlog_print(DLOG_DEBUG, TAG, "Service Application did not get any response to access the Health Information.");
        }
    }
}

typedef void(* ppm_request_response)(ppm_call_cause_e cause, ppm_request_result_e result, const char *privilege, void *user_data);

Method Call to Request for Permission:请求权限的方法调用:

//Set the function pointer value
ppm_request_response ppm_request_response_cb = ppm_request_response_handler;

//Request the user for the permission
ppm_request_permission(requiredPrivileges[i], ppm_request_response_cb, NULL);

Expected Behavior:预期行为:

Service App should show any message asking the user about the permission, the ppm_request_response_handler method should be invoked then to handle the response of the user.服务应用程序应该显示任何询问用户权限的消息,然后应该调用ppm_request_response_handler方法来处理用户的响应。

Web search revealed that it is possible that the privilege settings stored on the device do not get updated even after reinstalling the application. 网络搜索表明,即使重新安装应用程序后,存储在设备上的特权设置也可能不会得到更新。 A problem posted on Tizen Developers Forum was stating the same, Going through the discussion convinced me to reset the device which did the job for me. 在Tizen开发者论坛上发布的一个问题也说明了这一点,在讨论过程中,我说服我重设了对有用的设备

据我所知,多权限调用仅在 Tizen 5+ 中可用,因此如果您使用 Tizen 4.0 API,您需要单独询问每个权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM