SlideShare a Scribd company logo
App  Permissions  
-‐‑‒  M  Preview  -‐‑‒
What's  New  in  Android  (I/O  2015)
About  Me
• Shinobu  Okano  
• @operandoOS  
• Mercari,  Inc.  
• Android  Engineer  
• Garum

https://github.com/operando/Garum
App  Permissions  
Android  M
Android  M  Permissions
https://www.youtube.com/watch?v=f17qe9vZ8RM
Permissions
http://developer.android.com/preview/features/
runtime-‐‑‒permissions.html
Google  I/O  2015    
新しいパミッションモデルの超訳
http://www.taosoftware.co.jp/blog/2015/06/google-‐‑‒i-‐‑‒
o-‐‑‒2015-‐‑‒new-‐‑‒permission_̲model.html
だいたい  
この3つ読めば、問題ない
App  Permissions?
App  Permissions?
New  App  Permissions  Model  
App  Permissions?
“user  does  not  have  to  grant  any  
permissions  when  they    
install  or  upgrade  the  app.  “
App  Permissions?
“Instead,  the  app  requests  
permissions  as  it  needs  them,  
  and  the  system  shows  a  dialog  to  
the  user  asking  for  the  permission.  “
App  Permissions?
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.“
App  Permissions?
“Users  can  revoke  an  app's  
permissions  at  any  time.“
Permissions  are  Revocable
App  Permissions?
“On  devices  running  the  M  Developer  Preview,  a  user  can  turn  off  permissions  for  any  app  
(including  legacy  apps)  from  the  app's  Settings  screen.  If  a  user  turns  off  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  Permissions?
“On  devices  running  the  M  Developer  Preview,  a  user  can  turn  off  permissions  for  any  app  
(including  legacy  apps)  from  the  app's  Settings  screen.  If  a  user  turns  off  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  Permissions?
“On  devices  running  the  M  Developer  Preview,  a  user  can  turn  off  permissions  for  any  app  
(including  legacy  apps)  from  the  app's  Settings  screen.  If  a  user  turns  off  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  Permissionsに対応してないアプリで権限をOFFした時の話。  
例例外起きない。  
空データ返ってくる。
App  Permissions?
つまり…
iOS  like  Permission  Model
許可が必要な機能
• Location  
• Camera  
• Microphone  
• Phone  
• SMS  
• Contacts  
• Calendar  
• Sensor
許可が必要な機能
e.g.  
android.permission.READ_̲PHONE_̲STATE    
android.permission.CAMERA"  
How  to  Permissions
How  to  Permissions
• Check  
• Request  
• Handling
How  to  Permissions
• Check  
• Request  
• Handling
Check  permissions
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
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
checkSelfPermission
指定Permissionが許可されているかどうか
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
checkSelfPermission
ちなみに、これ  
⼀一つのPermissionしか指定できない…
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
(´́・ω・`)
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  CodeはUtilクラス作ってる
How  to  Permissions
• Check  
• Request  
• Handling
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の権限(許可)を求める
How  to  Permissions
• Check  
• Request  
• Handling
Handle  the    
permissions  request  response
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (MY_PERMISSIONS_REQUEST_READ_PHONE_STATE == requestCode) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showLineNumber();
Toast.makeText(this, "Phone Permission OK", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Phone Permission NG", Toast.LENGTH_SHORT).show();
}
}
}
private void showLineNumber() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Toast.makeText(this, telephonyManager.getLine1Number(), Toast.LENGTH_SHORT).show();
}
Handle  the    
permissions  request  response
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (MY_PERMISSIONS_REQUEST_READ_PHONE_STATE == requestCode) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showLineNumber();
Toast.makeText(this, "Phone Permission OK", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Phone Permission NG", Toast.LENGTH_SHORT).show();
}
}
}
private void showLineNumber() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Toast.makeText(this, telephonyManager.getLine1Number(), Toast.LENGTH_SHORT).show();
}
Handle  the    
permissions  request  response
onRequestPermissionResult
Permissionの許可・否許可の結果が返される  
結果によって処理理を分ける
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (MY_PERMISSIONS_REQUEST_READ_PHONE_STATE == requestCode) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showLineNumber();
Toast.makeText(this, "Phone Permission OK", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Phone Permission NG", Toast.LENGTH_SHORT).show();
}
}
}
private void showLineNumber() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Toast.makeText(this, telephonyManager.getLine1Number(), Toast.LENGTH_SHORT).show();
}
Handle  the    
permissions  request  response
onRequestPermissionResult
Permissionが許可されたら  
権限が必要なAPIへアクセスする
Request  from  Fragment
ほとんど同じ
Sample  Code
android-‐‑‒RuntimePermissions
https://github.com/googlesamples/android-
RuntimePermissions
• Only  ask  for  permissions  you  need  
• Don't  overwhelm  the  user  
• Explain  why  you  need  permissions
Best  Practices
App  Permissions対応してないアプリ  
Android  M  Previewで動かした
App  Permissions対応してないアプリ  
Android  M  Previewで動かした
意外とアプリ落落ちない
App  Permissions対応してないアプリ  
Android  M  Previewで動かした
意外とアプリ落落ちない
Forwards  and  backwards  compatibility
App  Permissions対応してないアプリ  
Android  M  Previewで動かした
ただ、サービスへの影響は  
でかい
App  Permissions対応してないアプリ  
Android  M  Previewで動かした
ユーザさんの声  
カメラが起動しません  
とにかく動きません
App  Permissions対応してないアプリ  
Android  M  Previewで動かした
Explain  why  you  need  permissions  
これ⼤大事
uses-‐‑‒permission-‐‑‒sdkに書かないで  
Permission  Requestしたらどうなるのか??
uses-‐‑‒permission-‐‑‒sdkに書かないで  
Permission  Requestしたらどうなるのか??
Permission  RequestのDialogが出なかった。  
権限は否許可されたことになって  
onRequestPermissionResultに返ってくる。  
例例外とかにはならない。
Permissionの許可・否許可って  
どこで管理理されてるの??
Permissionの許可・否許可って  
どこで管理理されてるの??
/data/system/users/{userId}/runtime-‐‑‒permissions.xml
Permissionの許可・否許可って  
どこで管理理されてるの??
/data/system/users/{userId}/runtime-‐‑‒permissions.xml
<pkg name="com.os.operando.m_preview_sample">
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="0" />
<item name="android.permission.CAMERA" granted="false" flags="0" />
</pkg>
Permissionの許可・否許可って  
どこで管理理されてるの??
/data/system/users/{userId}/runtime-‐‑‒permissions.xml
/data/system/users/{userId}配下には  
各ユーザの設定ファイル等がある。  
Settingsのファイルとかウィジットの位置とか⾊色々。
Permissionの許可・否許可って  
どこで管理理されてるの??
/data/system/users/{userId}/runtime-‐‑‒permissions.xml
ここに配置されてるからマルチユーザ意識識してる。  
マルチユーザでは、ユーザごとにPermissionの設定を持つ…はず
Permissionの許可・否許可って  
どこで管理理されてるの??
Class的には、PackageManagerが⾊色々管理理してる。  
http://tools.oesf.biz/android-‐‑‒MNC/xref/com/android/server/pm/
adb  shellから権限を変更更できる??
adb  shellから権限を変更更できる??
$  adb  shell  pm  grant  <package_̲name>  <permission_̲name>  
$  adb  shell  pm  revoke  <package_̲name>  <permission_̲name>
adb  shellから権限を変更更できる??
動かない…
Permissionを要求するAPI調べたい
Permissionを要求するAPI調べたい
Android  Studio  1.3から  
Permissionを要求するAPIには注釈が出る??  


Lintでもチェックできる??  
※検証してない…
App  Ops  
Android  4.3
App  Ops
App  Permission  Manager
App  Permision  =  App  Ops
?
App  Permision  ≠  App  Ops
?
App  Permision  
||  
Renewal  App  Ops
!!
※推測
Permission  Manager
Legacy??
まとめ
• とにかく既存のアプリをM  Previewで動かしてみ??  
• 正式にAndroid  M出たら、すぐ対応しないとダメそう  
• とにかく偉い⼈人に、今からApp  Permissionsの説明しよう  
• ユーザが混乱しないために、サービスに対する影響範囲とか
問い合わせ等の対応策は、今から考えておいた⽅方がいい
Thank  you

More Related Content

PDF
Android Wear-What's new in android
PDF
まったりAndroid framework code reading #1
PDF
例の縛るやつ(Data binding)
ODP
Android permission system
ODP
Android(1)
ODP
Android permission system
PDF
Web Services and Android - OSSPAC 2009
PPTX
Tips dan Third Party Library untuk Android - Part 1
Android Wear-What's new in android
まったりAndroid framework code reading #1
例の縛るやつ(Data binding)
Android permission system
Android(1)
Android permission system
Web Services and Android - OSSPAC 2009
Tips dan Third Party Library untuk Android - Part 1

Viewers also liked (20)

PPT
Sandbox Introduction
ODP
Android training day 4
PPTX
Security threats in Android OS + App Permissions
PDF
Anatomizing online payment systems: hack to shop
PPTX
Android secuirty permission - upload
PDF
Android 6.0 permission change
PPTX
Android AsyncTask Tutorial
ODP
Json Tutorial
PDF
Basic Android Push Notification
PDF
Android new permission model
PPTX
JSON overview and demo
PDF
Simple JSON parser
PDF
Android webservices
ODP
Android porting for dummies @droidconin 2011
PPTX
Android json parser tutorial – example
PDF
Android security
PDF
Screenshots Test spoon + espresso
PPTX
Android - Bluetooth
PDF
Android Security Development - Part 2: Malicious Android App Dynamic Analyzi...
PDF
Securing android applications
Sandbox Introduction
Android training day 4
Security threats in Android OS + App Permissions
Anatomizing online payment systems: hack to shop
Android secuirty permission - upload
Android 6.0 permission change
Android AsyncTask Tutorial
Json Tutorial
Basic Android Push Notification
Android new permission model
JSON overview and demo
Simple JSON parser
Android webservices
Android porting for dummies @droidconin 2011
Android json parser tutorial – example
Android security
Screenshots Test spoon + espresso
Android - Bluetooth
Android Security Development - Part 2: Malicious Android App Dynamic Analyzi...
Securing android applications
Ad

Similar to App Permissions (20)

PDF
Permissions
PDF
Performance Requirement Gathering
PDF
Runtime permissions handling with easy permissions
PPTX
Hieu Xamarin iOS9, Android M 3-11-2015
PPTX
performancetestingjmeter-121109061704-phpapp02 (1)
PPTX
performancetestingjmeter-121109061704-phpapp02
PPTX
A journey through android development
PPTX
Performance Testing using LoadRunner
DOCX
Performance testing interview questions and answers
PDF
Chapter 3 - Common Test Types and Test Process for Mobile Applications
DOC
QA Prayag
PPT
Getting Started with Apache Jmeter
PPTX
Bootstrapping an App for Launch
PPT
Performance testing and j meter
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
PPTX
Android Marshmallow APIs and Changes
PPTX
Test execution
PDF
1 aleksandr gritsevski - attd example using
PDF
Implementing Authorization
Permissions
Performance Requirement Gathering
Runtime permissions handling with easy permissions
Hieu Xamarin iOS9, Android M 3-11-2015
performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02
A journey through android development
Performance Testing using LoadRunner
Performance testing interview questions and answers
Chapter 3 - Common Test Types and Test Process for Mobile Applications
QA Prayag
Getting Started with Apache Jmeter
Bootstrapping an App for Launch
Performance testing and j meter
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - Devspace 2015
Android Marshmallow APIs and Changes
Test execution
1 aleksandr gritsevski - attd example using
Implementing Authorization
Ad

More from Shinobu Okano (20)

PDF
OnActivityResult - おまえら!もうonActivityResultでswitchとif書く時代は終わりだぞ!
PDF
Kotlinでマッチョする話
PDF
Android Framework Code Readingのしおり ver 1.2
PDF
まったりAndroid Framework Code Reading #4
PDF
Lightweight-Stream-APIのあるAndroidアプリ開発
PDF
shinobu.apk #3
PDF
Android + JSON-RPC
PDF
Inside Android N
PDF
Gradle PluginとCIと俺
PDF
shinobu.apk #2
PDF
まったりAndroid Framework Code Reading #3
PDF
Android Framework Code Readingのしおり ver 1.1
PDF
Kotlinにお触り
PDF
DroidKaigiアプリをSpoonで全画面スクショするぞい\(^o^)/
PDF
Gradle PluginとTwitterとズン ドコ キ・ヨ・シ!
PDF
ChromeとAndroidの過去・現在・未来
PDF
Android Dev Tools Knowledge
PDF
shinobu.apk #1
PDF
ChromeとAndroidの 過去・現在・未来 ver 0.1
PDF
5分で資料作ってSlideShareにアップロードする錬金術
OnActivityResult - おまえら!もうonActivityResultでswitchとif書く時代は終わりだぞ!
Kotlinでマッチョする話
Android Framework Code Readingのしおり ver 1.2
まったりAndroid Framework Code Reading #4
Lightweight-Stream-APIのあるAndroidアプリ開発
shinobu.apk #3
Android + JSON-RPC
Inside Android N
Gradle PluginとCIと俺
shinobu.apk #2
まったりAndroid Framework Code Reading #3
Android Framework Code Readingのしおり ver 1.1
Kotlinにお触り
DroidKaigiアプリをSpoonで全画面スクショするぞい\(^o^)/
Gradle PluginとTwitterとズン ドコ キ・ヨ・シ!
ChromeとAndroidの過去・現在・未来
Android Dev Tools Knowledge
shinobu.apk #1
ChromeとAndroidの 過去・現在・未来 ver 0.1
5分で資料作ってSlideShareにアップロードする錬金術

Recently uploaded (20)

PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Hybrid model detection and classification of lung cancer
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Architecture types and enterprise applications.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Tartificialntelligence_presentation.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Enhancing emotion recognition model for a student engagement use case through...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Hindi spoken digit analysis for native and non-native speakers
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Hybrid model detection and classification of lung cancer
Final SEM Unit 1 for mit wpu at pune .pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Modernising the Digital Integration Hub
Assigned Numbers - 2025 - Bluetooth® Document
Web App vs Mobile App What Should You Build First.pdf
Getting started with AI Agents and Multi-Agent Systems
Architecture types and enterprise applications.pdf
Chapter 5: Probability Theory and Statistics
OMC Textile Division Presentation 2021.pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
NewMind AI Weekly Chronicles - August'25-Week II
WOOl fibre morphology and structure.pdf for textiles
Tartificialntelligence_presentation.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf

App Permissions