Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Private by design Android apps

https://d.android.com/design-for-safety

Requesting runtime permissions


ContextCompat.checkSelfPermission(
Permission denials Use photo picker Choose the right storage
https://d.android.com/training/permissions/requesting context,
If the user denies a permission, gracefully degrade your https://d.android.com/training/data-storage/shared/photopicker
Manifest.permission. REQUESTED_PERMISSION

https://d.android.com/training/data-storage
app’s experience Use Photo Picker to provide a seamless and permissonless user experience to select visual media
Declare permission ) == PackageManager. PERMISSION_GRANTED
Plan your storage and file locations carefully
files and simplify developer costs
Increase situational context & wait for user actio Clearly highlight the feature / part of your
Check for permissio v al re qu estPermission =     
 app with limited functionality due to the App-specific storage

register F orActi v it y Res u lt ( Re qu estPermission ( )) {


permission denial

// or PickMultipleVisualMedia(num) for multiple selection

Show rationale if require


isGrante d : B oolean ->
val pickMedia = registerForActivityResult(PickVisualMedia()) { uri ->
Shared storage

Request permissio if ( isGrante d ) { … } else { … }


    // If media selected URI != null

}
Let users continue to use other features in }

Preferences

Handle Response your app normally


pickMedia.launch(PickVisualMediaRequest(PickVisualMedia.ImageAndVideo)) Databases
re qu estPermission L a u ncher.la u nch (

Manifest.permission. REQUESTED_PERMISSION

Gracefully degrade experience


Do Action
)

Understanding where and how your app is accessing user data


Data Safety Labels https://d.android.com/training/guide/topics/data/audit-access

Permission minimized requests register F orActi v it y Res u lt ( PickContact ( )) { u ri -> … }


https://d.android.com/guide/topics/data/collect-share Use data access audit APIs to gain insights into how your app & Set up callback to log different forms of data access

https://d.android.com/training/permissions/evaluating its dependencies (including SDKs + 3rd party libraries) access


The Data safety section on Google Play specifies private data from users
val appOpsCallback = object : AppOpsManager.OnOpNotedCallback() {

the user data your app collects or shares



override fun onNoted(syncNotedAppOp: SyncNotedAppOp){ 

// log synchronous data access (eg. microphone access)

Fill out the form in Play Console (Policy > App Set up callback to log different forms of data access
}

content) based on your app and 3rd party SDK override fun on AsyncNoted(asyncNotedAppOp: AsyncNotedAppOp){ 

bluetooth data usage.


val appOpsManager = getSystemService<AppOpsManager>()


// log asynchronous data access (eg. getting location)

}

appOpsManager.setOnOpNotedCallback( 

Info from your app’s Data safety form will be mainExecutor, 

Manage phone override fun onSelfNoted(syncNotedAppOp: SyncNotedAppOp) {

Show nearby places Create & access files Identify device Pair over Bluetooth appOpsCallback

calls & text highlighted in your app’s Play Store page and for // log self data access - fairly rare occurrence}

)
certain critical in-app permission requests. }
More at https://d.android.com/reference/androidx/activity/result/contract/ActivityResultContracts

Revoke permissions Package visibility Location minimization Background location

On Android 13 onward, remove previously granted https://d.android.com/training/package-visibility


https://d.android.com/training/location/permissions https://d.android.com/training/location/background

Declare package visibility needs when requesting information from


permission when no longer needed. Always request ACCESS_COARSE_LOCATION only/first
Only a few use cases allowed (such as geofencing)

other apps (outside of the ones that are visible by default)


Ensure your app still works if user grants coarse access only
Before requesting, user must grant fine and/or coarse permissions first

re v okeSelfPermissionOn K ill (

Manifest.permission. CA LL _P H ONE 

Reduce location computation by choosing the best location estimate
Requires ACCESS_BACKGROUND_LOCATION permission

)
<manifest package="com.example.game">
Use FusedLocationProvider to ensure compat across form factors (e.g. tablets) Location frequency might be affected by background location limits
<queries>

<!-- Specific package names -->

<package android:name="com.example.store" />

<manifest>

  val locationService = LocationServices.getFusedLocationProviderClient()

   < u ses -permission 



an d roi d: name= " an d roi d .permission.ACCESS_ B AC K GROUND_ L OCATION " / >

<!-- Match an intent filter signature -->


  val lastKnownLocation = locationService.getLastLocation()
Testing permissions </manifest>

<intent>

Use ADB commands to grant/revoke permissions for <action android:name="android.intent.action.SEND" />

testing purposes. <data android:mimeType="image/jpeg" />

  </intent>

// Grants all apk permissions


<!-- Specific authority -->

a db shell install - g PAT H _TO_AP K _ F I LE


a db shell pm grant com.name.app /


<provider 

android:authorities="com.example.settings.files" />

Android 14
an d roi d .permission. CAMER A

</queries>

    ...
Scoped storage enhancements
 Approximate location
N otification permission
Selected media access

a db shell pm re v oke com.name.app /


</manifest>

an d roi d .permission. CAMER A


Separate request for background location
Privacy dashboard
W i-Fi and storage permissions
Data safety in permissions

Data access auditing Bluetooth permissions Photo picker Screenshot detection

Last update: 13 March 2023

You might also like