• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.net.Uri;
20 import android.os.IBinder;
21 import android.os.UserHandle;
22 import android.util.ArraySet;
23 
24 /**
25  * A record of inline reply (ex. RemoteInput) URI grants associated with a Notification.
26  */
27 public final class InlineReplyUriRecord {
28     private final IBinder mPermissionOwner;
29     private final ArraySet<Uri> mUris;
30     private final UserHandle mUser;
31     private final String mPackageName;
32     private final String mKey;
33 
34     /**
35      * Construct a new InlineReplyUriRecord.
36      * @param owner The PermissionOwner associated with this record.
37      * @param user The user associated with this record.
38      * @param packageName The name of the package which posted the notification.
39      * @param key The key of the original NotificationRecord this notification as created with.
40      */
InlineReplyUriRecord(IBinder owner, UserHandle user, String packageName, String key)41     public InlineReplyUriRecord(IBinder owner, UserHandle user, String packageName, String key) {
42         mPermissionOwner = owner;
43         mUris = new ArraySet<>();
44         mUser = user;
45         mPackageName = packageName;
46         mKey = key;
47     }
48 
49     /**
50      * Get the permission owner associated with this record.
51      */
getPermissionOwner()52     public IBinder getPermissionOwner() {
53         return mPermissionOwner;
54     }
55 
56     /**
57      * Get the content URIs associated with this record.
58      */
getUris()59     public ArraySet<Uri> getUris() {
60         return mUris;
61     }
62 
63     /**
64      * Associate a new content URI with this record.
65      */
addUri(Uri uri)66     public void addUri(Uri uri) {
67         mUris.add(uri);
68     }
69 
70     /**
71      * Get the user id associated with this record.
72      * If the UserHandle associated with this record belongs to USER_ALL, return the ID for
73      * USER_SYSTEM instead, to avoid errors around modifying URI permissions for an invalid user ID.
74      */
getUserId()75     public int getUserId() {
76         int userId = mUser.getIdentifier();
77         if (userId == UserHandle.USER_ALL) {
78             return UserHandle.USER_SYSTEM;
79         } else {
80             return userId;
81         }
82     }
83 
84     /**
85      * Get the name of the package associated with this record.
86      */
getPackageName()87     public String getPackageName() {
88         return mPackageName;
89     }
90 
91     /**
92      * Get the key associated with this record.
93      */
getKey()94     public String getKey() {
95         return mKey;
96     }
97 }
98