1/*
2 * Copyright (C) 2014 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
17package com.android.tv.settings.device.apps;
18
19import com.android.tv.settings.R;
20
21import android.app.Fragment;
22import android.os.Bundle;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.view.ViewGroup;
26import android.widget.AppSecurityPermissions;
27
28/**
29 * Fragment that shows the app permissions.
30 */
31public class PermissionsFragment extends Fragment {
32
33    private static final String PACKAGE_NAME_KEY = "packageName";
34
35    static PermissionsFragment newInstance(String packageName) {
36
37        PermissionsFragment f = new PermissionsFragment();
38        Bundle args = new Bundle();
39        args.putString(PACKAGE_NAME_KEY, packageName);
40        f.setArguments(args);
41        return f;
42    }
43
44    @Override
45    public View onCreateView(
46            LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
47
48        View content = inflater.inflate(R.layout.device_apps_app_management_permissions, null);
49
50        AppSecurityPermissions asp = new AppSecurityPermissions(getActivity(), getPackageName());
51        if (asp.getPermissionCount() > 0 && content instanceof ViewGroup) {
52            ViewGroup vg = (ViewGroup) content;
53            vg.removeAllViews();
54            vg.addView(asp.getPermissionsView());
55        }
56
57        return content;
58    }
59
60    private String getPackageName() {
61        return getArguments().getString(PACKAGE_NAME_KEY);
62    }
63}
64