App Permissions

70
App Permissions M Preview What's New in Android (I/O 2015)

Transcript of App Permissions

  1. 1. App Permissions - M Preview - What's New in Android (I/O 2015)
  2. 2. About Me Shinobu Okano @operandoOS Mercari, Inc. Android Engineer Garum https://github.com/operando/Garum
  3. 3. App Permissions Android M
  4. 4. Android M Permissions https://www.youtube.com/watch?v=f17qe9vZ8RM
  5. 5. Permissions http://developer.android.com/preview/features/ runtime-permissions.html
  6. 6. Google I/O 2015 http://www.taosoftware.co.jp/blog/2015/06/google-i- o-2015-new-permission_model.html
  7. 7. 3
  8. 8. App Permissions?
  9. 9. App Permissions? New App Permissions Model
  10. 10. App Permissions? user does not have to grant any permissions when they install or upgrade the app.
  11. 11. App Permissions? Instead, the app requests permissions as it needs them, and the system shows a dialog to the user asking for the permission.
  12. 12. App Permissions?
  13. 13. App Permissions? If an app supports the new permissions model, it can still be installed and run on devices running older versions of Android, using the old permissions model on those devices.
  14. 14. App Permissions? Users can revoke an app's permissions at any time. Permissions are Revocable
  15. 15. App Permissions? On devices running the M Developer Preview, a user can turn o permissions for any app (including legacy apps) from the app's Settings screen. If a user turns o permissions for a legacy app, the system silently disables the appropriate functionality. When the app attempts to perform an operation that requires that permission, the operation will not necessarily cause an exception. Instead, it might return an empty data set, signal an error, or otherwise exhibit unexpected behavior. For example, if you query a calendar without permission, the method returns an empty data set. Forwards and backwards compatibility
  16. 16. App Permissions? On devices running the M Developer Preview, a user can turn o permissions for any app (including legacy apps) from the app's Settings screen. If a user turns o permissions for a legacy app, the system silently disables the appropriate functionality. When the app attempts to perform an operation that requires that permission, the operation will not necessarily cause an exception. Instead, it might return an empty data set, signal an error, or otherwise exhibit unexpected behavior. For example, if you query a calendar without permission, the method returns an empty data set. Forwards and backwards compatibility
  17. 17. App Permissions? On devices running the M Developer Preview, a user can turn o permissions for any app (including legacy apps) from the app's Settings screen. If a user turns o permissions for a legacy app, the system silently disables the appropriate functionality. When the app attempts to perform an operation that requires that permission, the operation will not necessarily cause an exception. Instead, it might return an empty data set, signal an error, or otherwise exhibit unexpected behavior. For example, if you query a calendar without permission, the method returns an empty data set. Forwards and backwards compatibility App PermissionsOFF
  18. 18. App Permissions?
  19. 19.
  20. 20. iOS like Permission Model
  21. 21.
  22. 22. Location Camera Microphone Phone SMS Contacts Calendar Sensor
  23. 23. e.g. android.permission.READ_PHONE_STATE android.permission.CAMERA"
  24. 24. How to Permissions
  25. 25. How to Permissions Check Request Handling
  26. 26. How to Permissions Check Request Handling
  27. 27. Check permissions
  28. 28. String[] PERMISSIONS = new String[]{Manifest.permission.READ_PHONE_STATE}; if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { requestPermissions(PERMISSIONS,PERMISSIONS_REQUEST_READ_PHONE_STATE); } else { showLineNumber(); } Check permissions
  29. 31. if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission. READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED Check permissions checkSelfPermission ()
  30. 32. public abstract class PermissionUtil { /** * Returns true if the Activity has access to all given permissions. * Always returns true on platforms below M. * * @see Activity#checkSelfPermission(String) */ public static boolean hasSelfPermission(Activity activity, String[] permissions) { if (!isMNC()) { return true; } for (String permission : permissions) { if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { return false; } } return true; } public static boolean isMNC() { /* TODO: In the Android M Preview release, checking if the platform is M is done through the codename, not the version code. Once the API has been finalised, the following check should be used: */ // return Build.VERSION.SDK_INT == Build.VERSION_CODES.MNC return "MNC".equals(Build.VERSION.CODENAME); } } https://github.com/googlesamples/android-RuntimePermissions Sample CodeUtil
  31. 33. How to Permissions Check Request Handling
  32. 34. String[] PERMISSIONS = new String[]{Manifest.permission.READ_PHONE_STATE}; if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { requestPermissions(PERMISSIONS,PERMISSIONS_REQUEST_READ_PHONE_STATE); } else { showLineNumber(); } Request permissions requestPermissions Permission()
  33. 54. Permission /data/system/users/{userId}/runtime-permissions.xml /data/system/users/{userId} Settings