简体   繁体   English

关于Android中自定义权限的几个问题

[英]Few questions about custom permissions in Android

I am learning Android programming and I have kind of understood the concept of custom permission. 我正在学习Android编程,我有点理解自定义权限的概念。

Based on my understanding this is how custom permissions works: 根据我的理解,这是自定义权限的工作原理:

'Base app' can protect some of its components (eg, activity and services) by declaring custom permissions (ie, using <permission> tags in the manifest file) and the 'client app' that calls the activities and services protected by custom permissions need to acquire necessary permissions (ie, using <uses-permission> tags in the manifest file) to call those components in the base app . 'Base app'可以通过声明自定义权限(即使用清单文件中的<permission>标记)和调用受自定义权限保护的活动和服务的'client app' 'Base app'来保护其某些组件(例如,活动和服务)需要获取必要的权限(即,使用清单文件中的<uses-permission>标签)来调用base app中的这些组件。

However, I have these questions regarding custom permissions: 但是,我有关于自定义权限的这些问题:

  1. If the custom permission is declared as dangerous (ie, android:protectionLevel="dangerous" ), does the client app needs to get the approval from the user during installation time? 如果自定义权限被声明为危险(即android:protectionLevel="dangerous" ), client app需要在安装期间获得用户的批准? If so, how does the user aware of these custom permissions because there won't be any documentation for the custom permissions. 如果是这样,用户如何知道这些自定义权限,因为没有任何自定义权限的文档。
  2. During installation time how does the client app knows that base app is already installed in the user's phone? 在安装期间, client app如何知道用户手机中已经安装了base app Is there anyway for the client app to know this information? 无论如何, client app是否知道此信息?
  3. Once the client app is installed, what will happen if the user decides to remove the base app ? 安装client app程序后,如果用户决定删除base app程序,会发生什么? In this case, if the user tries to use client app will it cause any security exception? 在这种情况下,如果用户尝试使用client app是否会导致任何安全性异常?

I don't know whether these questions make sense but it makes me wonder how custom permissions actually work in real scenario. 我不知道这些问题是否有意义,但它让我想知道自定义权限在实际场景中是如何实际工作的。

Thank you. 谢谢。

The answers to your questions is give below. 您的问题的答案如下。 But you may refer http://developer.android.com/guide/topics/manifest/permission-element.html for a better understanding of Android permissions. 但您可以参考http://developer.android.com/guide/topics/manifest/permission-element.html以更好地了解Android权限。

1.Yes, if you declare 是的,如果你宣布的话

android:protectionLevel="dangerous"

then the system may not automatically grant it to the requesting application.Any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding. 然后系统可能不会自动将其授予请求的应用程序。应用程序请求的任何危险权限可能会显示给用户并需要在继续之前进行确认。

The base app defining custom permission is supposed to provide a description via 定义自定义权限的基本应用程序应该提供描述

android:description="string resource"

Here is the an example permission definition. 这是一个示例权限定义。 Hope it is self explanatory. 希望它是自我解释的。

<permission android:description="string resource"
android:icon="drawable resource"
android:label="string resource"
android:name="string"
android:permissionGroup="string"
android:protectionLevel=["normal" | "dangerous" | 
 "signature" | "signatureOrSystem"] />

2.As far as I know, there is no way for the client app to see the presence of base app at the time of installation. 2.据我所知,客户端应用程序无法在安装时看到基本应用程序的存在。 But it is possible when the client App is started. 但是,当客户端应用程序启动时,它是可能的。 Anyway, permissions are granted by the Android system based on your android.xml file. 无论如何,Android系统根据您的android.xml文件授予权限。 So the client app don't have to bother about base app at the time of installation. 因此,客户端应用程序在安装时不必担心基本应用程序。

3.The base app can be removed even when client app is still installed. 3.即使仍安装了客户端应用程序,也可以删除基本应用程序。 It won't through any error messages or security exceptions at any stage. 它不会在任何阶段通过任何错误消息或安全异常。 But when you try to run client app again, you may get an 'Activity not found' exception at the point where you try to call a base app activity from client app. 但是当您尝试再次运行客户端应用程序时,您可能会在尝试从客户端应用程序调用基本应用程序活动时收到“未找到活动”异常。

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

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