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.packageinstaller.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 25 import androidx.fragment.app.Fragment; 26 import androidx.fragment.app.FragmentActivity; 27 28 import com.android.packageinstaller.DeviceUtils; 29 import com.android.packageinstaller.permission.ui.ConfirmActionDialogFragment 30 .OnActionConfirmedListener; 31 import com.android.packageinstaller.permission.ui.handheld.ReviewPermissionsFragment; 32 import com.android.packageinstaller.permission.ui.wear.ReviewPermissionsWearFragment; 33 import com.android.permissioncontroller.R; 34 35 public final class ReviewPermissionsActivity extends FragmentActivity 36 implements OnActionConfirmedListener { 37 38 @Override onCreate(Bundle savedInstanceState)39 protected void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 42 PackageInfo packageInfo = getTargetPackageInfo(); 43 if (packageInfo == null) { 44 finish(); 45 return; 46 } 47 48 if (DeviceUtils.isWear(this)) { 49 Fragment fragment = ReviewPermissionsWearFragment.newInstance(packageInfo); 50 getSupportFragmentManager().beginTransaction() 51 .replace(android.R.id.content, fragment).commit(); 52 } else { 53 setContentView(R.layout.review_permissions); 54 if (getSupportFragmentManager().findFragmentById(R.id.preferences_frame) == null) { 55 getSupportFragmentManager().beginTransaction().add(R.id.preferences_frame, 56 ReviewPermissionsFragment.newInstance(packageInfo)).commit(); 57 } 58 } 59 } 60 61 @Override onActionConfirmed(String action)62 public void onActionConfirmed(String action) { 63 Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.preferences_frame); 64 if (fragment instanceof OnActionConfirmedListener) { 65 ((OnActionConfirmedListener) fragment).onActionConfirmed(action); 66 } 67 } 68 getTargetPackageInfo()69 private PackageInfo getTargetPackageInfo() { 70 String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME); 71 if (TextUtils.isEmpty(packageName)) { 72 return null; 73 } 74 try { 75 return getPackageManager().getPackageInfo(packageName, 76 PackageManager.GET_PERMISSIONS); 77 } catch (PackageManager.NameNotFoundException e) { 78 return null; 79 } 80 } 81 } 82