android 私密分区_新的Android 11工具使应用程序更加私密和稳定

android 私密分区

Contributors: Jing Ji and Ziv Snai

贡献者:静吉和斯奈·斯奈

As part of our continuing effort to help you build high quality apps, we often look for areas where we can invest in tools and resources that give you better insights into the performance of your apps.

作为我们不断努力帮助您构建高质量应用程序的一部分,我们经常寻找可以在工具和资源上进行投资的领域,这些工具和资源可以使您更好地了解应用程序的性能。

大新闻 (The big news)

In Android 11, we are introducing two new tools, Data Access Audit APIs and Process Exit Reasons, to give you more transparency into your private data access and causes of process exits.

在Android 11中,我们引入了两个新工具:数据访问审核API和流程退出原因,以使您对私有数据访问和流程退出的原因更加透明。

数据访问审核API (Data Access Auditing APIs)

Android encourages developers to be considerate and intentional with their sensitive data access. In Android 11 you will have access to new APIs that will give you more transparency into the usage of private and protected data. This could be useful, for example, for large apps that may have legacy code and those that use third-party libraries or SDKs.

Android鼓励开发人员谨慎敏感地访问敏感数据。 在Android 11中,您将可以访问新的API,从而使您对使用私有和受保护的数据更加透明。 例如,这对于可能具有遗留代码的大型应用程序以及使用第三方库或SDK的大型应用程序可能很有用。

Image for post
It may not be easy for large apps to attribute private data usage. 对于大型应用程序来说,归因于私有数据的使用可能并不容易。

The first API is a callback allowing apps to back trace the use of data protected by runtime permissions to the code that triggered the usage. To be notified, any app can set a callback in AppOpsManager which will be invoked each time a section of code uses private data, such as getting location updates. You can create specific logic to track, ingest, and analyze the data.

第一个API是回调,允许应用回溯由运行时权限保护的数据对触发使用的代码的使用。 要得到通知,任何应用程序都可以在AppOpsManager中设置一个回调,每次代码段使用私有数据(例如获取位置更新)时都会调用该回调。 您可以创建特定的逻辑来跟踪,提取和分析数据。

Image for post
Data access auditing API in Android 11 helps back track private data usage to your code. Android 11中的数据访问审核API有助于将私有数据的使用情况追溯到您的代码中。

The second API is targeted at complex apps with multiple features. A social app might have a find friends feature and a photo tagging feature. Each of the features use a subset of sensitive data, for example find friends uses location and contacts and photos tag uses location, contacts and camera. In Android 11 you can create a new Context object that allows you to attribute a subset of your app’s code to one or more features. So going forward, every permission usage would be traced to the features associated with the context.

第二个API面向具有多种功能的复杂应用。 社交应用程序可能具有“查找朋友”功能和照片标记功能。 每个功能都使用敏感数据的子集,例如,查找朋友使用位置和联系人,而照片标签使用位置,联系人和相机。 在Android 11中,您可以创建一个新的Context对象,该对象可以将应用程序代码的子集归因于一个或多个功能。 因此,今后,每个权限的使用都将追溯到与上下文关联的功能。

You can also see these APIs in action in our code sample.

您还可以在我们的代码示例中看到这些API的运行情况。

Image for post

In addition to helping you identify private data access, Android 11 also includes new APIs to help pinpoint those not-always-trivial crash issues in the field.

除了帮助您识别私有数据访问权限外,Android 11还包括新的API,以帮助查明现场中那些并非总是很严重的崩溃问题。

流程退出原因 (Process Exit Reasons)

You also tell us that it can be difficult to track down the cause of your apps getting terminated, which can be due to various reasons: an ANR, a crash, or the user choosing to force stop the app. To help diagnose the cause, some developers are adding customized code in order to build their own analytics to improve the app’s health.

您还告诉我们,可能很难找到导致应用终止的原因,原因可能有多种:ANR,崩溃或用户选择强制停止应用。 为了帮助诊断原因,一些开发人员正在添加自定义代码,以构建自己的分析程序以改善应用程序的运行状况。

With that in mind, we found a way to make the diagnosis part easier for you.

考虑到这一点,我们找到了一种使您的诊断更容易的方法。

Android 11 introduces a new ActivityManager API to report historical information related to an app process’s termination.

Android 11引入了新的ActivityManager API,以报告与应用程序进程终止相关的历史信息。

Your app can use the API to retrieve any available historical process exit diagnostic information, such as whether a process termination is due to ANRs, memory issues, or other reasons.

您的应用可以使用API​​检索任何可用的历史流程退出诊断信息,例如,流程终止是由于ANR,内存问题还是其他原因。

If the app was terminated due to ANR, the ApplicationExitInfo.getTraceInputStream() will return an InputStream to the stack trace dump of the app prior to the termination. This is especially helpful on newer OS versions, where there’s additional complexity for pulling ANR traces due to privacy and security considerations. After reading from the InputStream, just remember to close it in order to avoid resource leaks.

如果应用程序由于ANR而终止,则ApplicationExitInfo.getTraceInputStream()将在终止之前将InputStream返回到应用程序的堆栈跟踪转储。 这在较新的OS版本上尤其有用,由于隐私和安全方面的考虑,在这些版本中提取ANR跟踪会更加复杂。 从InputStream读取后,只需记住将其关闭以避免资源泄漏。

Additionally, you can use the new ActivityManager.setProcessStateSummary() method to store custom state information. This is a useful way to save arbitrary process data to debug a section of your code that is causing your app to crash. For some developers, knowing what the app’s state prior to the process’s termination is also vital — for example, a game developer might want to know what the current game level the user was on before the process is terminated — a common way is to persist it to storage constantly and read it in the next app launch. Note the size of the input data is very limited. Any saved process state information can be retrieved via the ApplicationExitInfo.getProcessStateSummary() method.

此外,您可以使用新的ActivityManager.setProcessStateSummary()方法存储自定义状态信息。 这是保存任意过程数据以调试导致应用程序崩溃的代码部分的有用方法。 对于某些开发人员而言,了解进程终止之前应用程序的状态也至关重要-例如,游戏开发人员可能想知道用户在终止进程之前所处的当前游戏级别是什么-一种常见的方法是保留该进程持续存储并在下一次应用启动时阅读。 请注意,输入数据的大小非常有限。 可以通过ApplicationExitInfo.getProcessStateSummary()方法检索任何保存的进程状态信息。

Resources

资源资源

We hope you find these additional tools helpful in making your apps more privacy-aware and stable. To learn more, check out our developer documentation on Data Access Auditing and Process Exit Reasons APIs.

我们希望您发现这些额外的工具有助于使您的应用更具隐私意识和稳定性。 要了解更多信息,请查看有关数据访问审核流程退出原因API的开发人员文档。

翻译自: https://medium.com/androiddevelopers/new-android-11-tools-to-make-apps-more-private-and-stable-c9dcea0af415

android 私密分区

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值