1 /* 2 * Copyright (C) 2015 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.permission.ui; 18 19 import android.content.Intent; 20 import android.content.pm.PackageInfo; 21 import android.content.pm.PackageManager; 22 import android.os.Bundle; 23 import android.text.TextUtils; 24 import android.view.WindowManager; 25 26 import androidx.fragment.app.Fragment; 27 import androidx.fragment.app.FragmentActivity; 28 import androidx.navigation.NavGraph; 29 import androidx.navigation.NavInflater; 30 import androidx.navigation.fragment.NavHostFragment; 31 32 import com.android.permissioncontroller.DeviceUtils; 33 import com.android.permissioncontroller.R; 34 import com.android.permissioncontroller.permission.ui.ConfirmActionDialogFragment.OnActionConfirmedListener; 35 import com.android.permissioncontroller.permission.ui.handheld.ReviewPermissionsFragment; 36 import com.android.permissioncontroller.permission.ui.wear.ReviewPermissionsWearFragment; 37 38 /** 39 * A dialog listing which permissions are grant to an app 40 */ 41 public final class ReviewPermissionsActivity extends FragmentActivity 42 implements OnActionConfirmedListener { 43 44 @Override onCreate(Bundle savedInstanceState)45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 getWindow().addSystemFlags( 49 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 50 51 PackageInfo packageInfo = getTargetPackageInfo(); 52 if (packageInfo == null) { 53 finish(); 54 return; 55 } 56 57 if (DeviceUtils.isWear(this)) { 58 Fragment fragment = ReviewPermissionsWearFragment.newInstance(packageInfo); 59 getSupportFragmentManager().beginTransaction() 60 .replace(android.R.id.content, fragment).commit(); 61 } else { 62 setContentView(R.layout.nav_host_fragment); 63 NavHostFragment navHost = (NavHostFragment) getSupportFragmentManager() 64 .findFragmentById(R.id.nav_host_fragment); 65 NavInflater inflater = navHost.getNavController().getNavInflater(); 66 NavGraph graph = inflater.inflate(R.navigation.nav_graph); 67 graph.setStartDestination(R.id.review_permissions_dest); 68 navHost.getNavController().setGraph(graph, 69 ReviewPermissionsFragment.getArgs(packageInfo)); 70 } 71 } 72 73 @Override onActionConfirmed(String action)74 public void onActionConfirmed(String action) { 75 Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.preferences_frame); 76 if (fragment instanceof OnActionConfirmedListener) { 77 ((OnActionConfirmedListener) fragment).onActionConfirmed(action); 78 } 79 } 80 getTargetPackageInfo()81 private PackageInfo getTargetPackageInfo() { 82 String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME); 83 if (TextUtils.isEmpty(packageName)) { 84 return null; 85 } 86 try { 87 return getPackageManager().getPackageInfo(packageName, 88 PackageManager.GET_PERMISSIONS); 89 } catch (PackageManager.NameNotFoundException e) { 90 return null; 91 } 92 } 93 } 94