1 /*
2  * Copyright (C) 2018 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.permissioncontroller.role.ui;
18 
19 import android.app.Application;
20 import android.os.Process;
21 
22 import androidx.annotation.NonNull;
23 import androidx.lifecycle.ViewModel;
24 import androidx.lifecycle.ViewModelProvider;
25 
26 import com.android.role.controller.model.Role;
27 
28 /**
29  * {@link ViewModel} for a role request.
30  */
31 public class RequestRoleViewModel extends DefaultAppViewModel {
32 
RequestRoleViewModel(@onNull Role role, @NonNull Application application)33     public RequestRoleViewModel(@NonNull Role role, @NonNull Application application) {
34         super(role, Process.myUserHandle(), application);
35     }
36 
37     /**
38      * {@link ViewModelProvider.Factory} for {@link RequestRoleViewModel}.
39      */
40     public static class Factory implements ViewModelProvider.Factory {
41 
42         @NonNull
43         private Role mRole;
44 
45         @NonNull
46         private Application mApplication;
47 
Factory(@onNull Role role, @NonNull Application application)48         public Factory(@NonNull Role role, @NonNull Application application) {
49             mRole = role;
50             mApplication = application;
51         }
52 
53         @NonNull
54         @Override
create(@onNull Class<T> modelClass)55         public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
56             //noinspection unchecked
57             return (T) new RequestRoleViewModel(mRole, mApplication);
58         }
59     }
60 }
61