Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android MのPermissionの個別設定情報の保存場所について
Permissionのファイルは
/data/system/users/{userId}/runtime-permissions.xml
ここにこういうのが入ってる
```runtime-permissions.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<runtime-permissions>
<pkg name="com.android.launcher">
<item name="android.permission.CALL_PHONE" granted="true" flags="0" />
</pkg>
<pkg name="com.android.browser">
<item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="0" />
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="android.permission.READ_PROFILE" granted="true" flags="0" />
<item name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" granted="true" flags="0" />
<item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="0" />
<item name="android.permission.CAMERA" granted="true" flags="0" />
<item name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS" granted="true" flags="0" />
<item name="com.android.launcher.permission.INSTALL_SHORTCUT" granted="true" flags="0" />
<item name="android.permission.RECORD_AUDIO" granted="true" flags="0" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="0" />
</pkg>
<pkg name="com.android.soundrecorder">
<item name="android.permission.RECORD_AUDIO" granted="true" flags="0" />
</pkg>
<pkg name="com.android.vending">
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="com.google.android.googleapps.permission.GOOGLE_AUTH.android" granted="true" flags="0" />
</pkg>
<pkg name="com.android.certinstaller">
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="0" />
</pkg>
<pkg name="com.android.speechrecorder">
<item name="android.permission.RECORD_AUDIO" granted="true" flags="0" />
</pkg>
<pkg name="com.android.mms">
<item name="android.permission.READ_SMS" granted="true" flags="0" />
<item name="android.permission.RECEIVE_MMS" granted="true" flags="0" />
<item name="android.permission.RECEIVE_SMS" granted="true" flags="0" />
<item name="android.permission.READ_PROFILE" granted="true" flags="0" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="0" />
<item name="android.permission.SEND_SMS" granted="true" flags="0" />
<item name="android.permission.CALL_PHONE" granted="true" flags="0" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="0" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="0" />
</pkg>
<pkg name="com.android.camera">
<item name="android.permission.READ_SMS" granted="true" flags="0" />
<item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="0" />
<item name="android.permission.CAMERA" granted="true" flags="0" />
<item name="android.permission.RECORD_AUDIO" granted="true" flags="0" />
</pkg>
<pkg name="com.android.dialer">
<item name="android.permission.READ_CALL_LOG" granted="true" flags="0" />
<item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="0" />
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="android.permission.READ_PROFILE" granted="true" flags="0" />
<item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="0" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="0" />
<item name="android.permission.CALL_PHONE" granted="true" flags="0" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="0" />
<item name="android.permission.WRITE_CALL_LOG" granted="true" flags="0" />
<item name="android.permission.PROCESS_OUTGOING_CALLS" granted="true" flags="0" />
<item name="com.android.launcher.permission.INSTALL_SHORTCUT" granted="true" flags="0" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="0" />
<item name="com.android.voicemail.permission.ADD_VOICEMAIL" granted="true" flags="0" />
</pkg>
<pkg name="com.android.packageinstaller">
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="0" />
<item name="android.permission.CLEAR_APP_CACHE" granted="true" flags="0" />
</pkg>
<pkg name="com.android.managedprovisioning">
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="android.permission.BLUETOOTH" granted="true" flags="0" />
<item name="android.permission.BLUETOOTH_ADMIN" granted="true" flags="0" />
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="0" />
</pkg>
<pkg name="com.android.development">
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser" granted="true" flags="0" />
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="0" />
</pkg>
<shared-user name="android.media">
<item name="android.permission.CLEAR_APP_CACHE" granted="true" flags="0" />
</shared-user>
<shared-user name="android.uid.systemui">
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="10" />
<item name="android.permission.SYSTEM_ALERT_WINDOW" granted="true" flags="10" />
<item name="android.permission.READ_PROFILE" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH_ADMIN" granted="true" flags="10" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="10" />
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="10" />
<item name="android.permission.CAMERA" granted="true" flags="10" />
<item name="android.permission.USE_FINGERPRINT" granted="true" flags="10" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="10" />
</shared-user>
<shared-user name="com.google.uid.shared">
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="com.google.android.providers.talk.permission.WRITE_ONLY" granted="true" flags="0" />
<item name="android.permission.SUBSCRIBED_FEEDS_WRITE" granted="true" flags="0" />
<item name="android.permission.AUTHENTICATE_ACCOUNTS" granted="true" flags="0" />
<item name="com.google.android.googleapps.permission.GOOGLE_AUTH.mail" granted="true" flags="0" />
<item name="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser" granted="true" flags="0" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="0" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="0" />
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="0" />
<item name="com.google.android.googleapps.permission.GOOGLE_AUTH.youtube" granted="true" flags="0" />
<item name="com.google.android.providers.talk.permission.READ_ONLY" granted="true" flags="0" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="0" />
</shared-user>
<shared-user name="android.uid.shared">
<item name="android.permission.READ_SMS" granted="true" flags="0" />
<item name="android.permission.READ_CALENDAR" granted="true" flags="0" />
<item name="android.permission.READ_CALL_LOG" granted="true" flags="0" />
<item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="0" />
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="android.permission.READ_PROFILE" granted="true" flags="0" />
<item name="android.permission.WRITE_PROFILE" granted="true" flags="0" />
<item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="0" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="0" />
<item name="android.permission.CALL_PHONE" granted="true" flags="0" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="0" />
<item name="com.android.launcher.permission.INSTALL_SHORTCUT" granted="true" flags="0" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="0" />
<item name="com.android.voicemail.permission.ADD_VOICEMAIL" granted="true" flags="0" />
</shared-user>
<shared-user name="android.uid.system">
<item name="android.permission.READ_CALL_LOG" granted="true" flags="10" />
<item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="10" />
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="10" />
<item name="android.permission.READ_PROFILE" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH_ADMIN" granted="true" flags="10" />
<item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="10" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="10" />
<item name="android.permission.CALL_PHONE" granted="true" flags="10" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="10" />
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="10" />
<item name="android.permission.WRITE_CALL_LOG" granted="true" flags="10" />
<item name="android.permission.USE_FINGERPRINT" granted="true" flags="10" />
<item name="android.permission.READ_USER_DICTIONARY" granted="true" flags="10" />
<item name="android.permission.CHANGE_WIMAX_STATE" granted="true" flags="10" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="10" />
</shared-user>
<shared-user name="android.uid.phone">
<item name="android.permission.READ_SMS" granted="true" flags="10" />
<item name="android.permission.READ_CALL_LOG" granted="true" flags="10" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="10" />
<item name="android.permission.SYSTEM_ALERT_WINDOW" granted="true" flags="10" />
<item name="android.permission.RECEIVE_SMS" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH" granted="true" flags="10" />
<item name="android.permission.AUTHENTICATE_ACCOUNTS" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH_ADMIN" granted="true" flags="10" />
<item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="10" />
<item name="android.permission.READ_PHONE_STATE" granted="true" flags="10" />
<item name="android.permission.SEND_SMS" granted="true" flags="10" />
<item name="android.permission.CALL_PHONE" granted="true" flags="10" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="10" />
<item name="android.permission.CHANGE_WIFI_STATE" granted="true" flags="10" />
<item name="android.permission.WRITE_CALL_LOG" granted="true" flags="10" />
<item name="android.permission.USE_SIP" granted="true" flags="10" />
<item name="android.permission.PROCESS_OUTGOING_CALLS" granted="true" flags="10" />
<item name="android.permission.RECORD_AUDIO" granted="true" flags="10" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="10" />
<item name="com.android.voicemail.permission.ADD_VOICEMAIL" granted="true" flags="10" />
</shared-user>
<shared-user name="android.uid.shell">
<item name="android.permission.READ_CALENDAR" granted="true" flags="10" />
<item name="android.permission.ACCESS_FINE_LOCATION" granted="true" flags="10" />
<item name="android.permission.BLUETOOTH" granted="true" flags="10" />
<item name="android.permission.ACCESS_COARSE_LOCATION" granted="true" flags="10" />
<item name="android.permission.SEND_SMS" granted="true" flags="10" />
<item name="android.permission.CALL_PHONE" granted="true" flags="10" />
<item name="android.permission.WRITE_CONTACTS" granted="true" flags="10" />
<item name="android.permission.WRITE_CALENDAR" granted="true" flags="10" />
<item name="android.permission.READ_USER_DICTIONARY" granted="true" flags="10" />
<item name="android.permission.READ_CONTACTS" granted="true" flags="10" />
</shared-user>
<shared-user name="android.uid.calendar">
<item name="android.permission.READ_CALENDAR" granted="true" flags="0" />
<item name="android.permission.USE_CREDENTIALS" granted="true" flags="0" />
<item name="android.permission.MANAGE_ACCOUNTS" granted="true" flags="0" />
<item name="com.google.android.googleapps.permission.GOOGLE_AUTH.cl" granted="true" flags="0" />
<item name="android.permission.SUBSCRIBED_FEEDS_WRITE" granted="true" flags="0" />
<item name="android.permission.WRITE_CALENDAR" granted="true" flags="0" />
</shared-user>
</runtime-permissions>
```
## このファイルの定義場所
http://tools.oesf.biz/android-MNC/xref/com/android/server/pm/Settings.java#156
```
156 private static final String RUNTIME_PERMISSIONS_FILE_NAME = "runtime-permissions.xml";
```
## このファイルの読み込み場所
```
1117 private File getUserRuntimePermissionsFile(int userId) {
1118 // TODO: Implement a cleaner solution when adding tests.
1119 // This instead of Environment.getUserSystemDirectory(userId) to support testing.
1120 File userDir = new File(new File(mSystemDir, "users"), Integer.toString(userId));
1121 return new File(userDir, RUNTIME_PERMISSIONS_FILE_NAME); ★
1122 }
```
```
4359 public void readStateForUserSyncLPr(int userId) {
4360 File permissionsFile = getUserRuntimePermissionsFile(userId); ★★ ファイルを読み込む
4361 if (!permissionsFile.exists()) {
4362 return;
4363 }
4364
4365 FileInputStream in;
4366 try {
4367 in = new FileInputStream(permissionsFile);
4368 } catch (FileNotFoundException fnfe) {
4369 Slog.i(PackageManagerService.TAG, "No permissions state");
4370 return;
4371 }
4372
4373 try {
4374 XmlPullParser parser = Xml.newPullParser();
4375 parser.setInput(in, null);
4376 parseRuntimePermissionsLPr(parser, userId); ここでxmlをparseしている
4377
4378 } catch (XmlPullParserException | IOException e) {
4379 throw new IllegalStateException("Failed parsing permissions file: "
4380 + permissionsFile , e);
4381 } finally {
4382 IoUtils.closeQuietly(in);
4383 }
4384 }
```
parseRuntimePermissionsLPrでそれぞれのパッケージとパーミッションについて
`ArrayMap<String, PackageSetting> mPackages`のPackageSetting -> grantRuntimePermissionが呼ばれる。
## readStateForUserSyncLPrが呼ばれるタイミング
メソッド呼び出ししてる場所見つからず。。
RuntimePermissionPersistenceというクラスが同じメソッドを持ってるっぽいが、RuntimePermissionPersistenceの定義場所が見つからず。
```
2517 if (users == null) {
2518 readPackageRestrictionsLPr(0);
2519 mRuntimePermissionsPersistence.readStateForUserSyncLPr(UserHandle.USER_OWNER);
2520 } else {
2521 for (UserInfo user : users) {
2522 readPackageRestrictionsLPr(user.id);
2523 mRuntimePermissionsPersistence.readStateForUserSyncLPr(user.id);
2524 }
2525 }
```
## 書き出している場所
```
4250 private void writePermissionsSync(int userId) {
4251 AtomicFile destination = new AtomicFile(getUserRuntimePermissionsFile(userId));
4252
4253 ArrayMap<String, List<PermissionState>> permissionsForPackage = new ArrayMap<>();
4254 ArrayMap<String, List<PermissionState>> permissionsForSharedUser = new ArrayMap<>();
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment