1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.notification; 18 19 import android.app.ActivityManager; 20 import android.net.Uri; 21 import android.os.IBinder; 22 import android.os.UserHandle; 23 import android.os.UserManager; 24 import android.util.ArraySet; 25 26 /** 27 * A record of inline reply (ex. RemoteInput) URI grants associated with a Notification. 28 */ 29 public final class InlineReplyUriRecord { 30 private final IBinder mPermissionOwner; 31 private final ArraySet<Uri> mUris; 32 private final UserHandle mUser; 33 private final String mPackageName; 34 private final String mKey; 35 36 /** 37 * Construct a new InlineReplyUriRecord. 38 * @param owner The PermissionOwner associated with this record. 39 * @param user The user associated with this record. 40 * @param packageName The name of the package which posted the notification. 41 * @param key The key of the original NotificationRecord this notification as created with. 42 */ InlineReplyUriRecord(IBinder owner, UserHandle user, String packageName, String key)43 public InlineReplyUriRecord(IBinder owner, UserHandle user, String packageName, String key) { 44 mPermissionOwner = owner; 45 mUris = new ArraySet<>(); 46 mUser = user; 47 mPackageName = packageName; 48 mKey = key; 49 } 50 51 /** 52 * Get the permission owner associated with this record. 53 */ getPermissionOwner()54 public IBinder getPermissionOwner() { 55 return mPermissionOwner; 56 } 57 58 /** 59 * Get the content URIs associated with this record. 60 */ getUris()61 public ArraySet<Uri> getUris() { 62 return mUris; 63 } 64 65 /** 66 * Associate a new content URI with this record. 67 */ addUri(Uri uri)68 public void addUri(Uri uri) { 69 mUris.add(uri); 70 } 71 72 /** 73 * Get the user id associated with this record. 74 * If the UserHandle associated with this record belongs to USER_ALL, return the ID for 75 * USER_SYSTEM instead, to avoid errors around modifying URI permissions for an invalid user ID. 76 */ getUserId()77 public int getUserId() { 78 int userId = mUser.getIdentifier(); 79 if (UserManager.isHeadlessSystemUserMode() && userId == UserHandle.USER_ALL) { 80 return ActivityManager.getCurrentUser(); 81 } else if (userId == UserHandle.USER_ALL) { 82 return UserHandle.USER_SYSTEM; 83 } else { 84 return userId; 85 } 86 } 87 88 /** 89 * Get the name of the package associated with this record. 90 */ getPackageName()91 public String getPackageName() { 92 return mPackageName; 93 } 94 95 /** 96 * Get the key associated with this record. 97 */ getKey()98 public String getKey() { 99 return mKey; 100 } 101 } 102