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.packageinstaller.permission.ui; 18 19 import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; 20 21 import static com.android.packageinstaller.Constants.INVALID_SESSION_ID; 22 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.os.UserHandle; 26 import android.util.Log; 27 import android.view.MenuItem; 28 29 import androidx.fragment.app.Fragment; 30 import androidx.fragment.app.FragmentActivity; 31 32 import com.android.packageinstaller.Constants; 33 import com.android.packageinstaller.DeviceUtils; 34 import com.android.packageinstaller.permission.ui.auto.AutoAppPermissionFragment; 35 import com.android.packageinstaller.permission.ui.handheld.AppPermissionFragment; 36 import com.android.packageinstaller.permission.utils.LocationUtils; 37 import com.android.packageinstaller.permission.utils.Utils; 38 import com.android.permissioncontroller.R; 39 40 /** 41 * Manage a single permission of a single app 42 */ 43 public final class AppPermissionActivity extends FragmentActivity { 44 private static final String LOG_TAG = AppPermissionActivity.class.getSimpleName(); 45 46 public static final String EXTRA_CALLER_NAME = 47 "com.android.packageinstaller.extra.CALLER_NAME"; 48 49 @Override onCreate(Bundle savedInstanceState)50 public void onCreate(Bundle savedInstanceState) { 51 if (DeviceUtils.isAuto(this)) { 52 // Automotive relies on a different theme. Apply before calling super so that 53 // fragments are restored properly on configuration changes. 54 setTheme(R.style.CarSettings); 55 } 56 super.onCreate(savedInstanceState); 57 58 getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 59 60 String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME); 61 if (packageName == null) { 62 Log.i(LOG_TAG, "Missing mandatory argument EXTRA_PACKAGE_NAME"); 63 finish(); 64 return; 65 } 66 67 String permissionName = getIntent().getStringExtra(Intent.EXTRA_PERMISSION_NAME); 68 if (permissionName == null) { 69 Log.i(LOG_TAG, "Missing mandatory argument EXTRA_PERMISSION_NAME"); 70 finish(); 71 return; 72 } 73 String groupName = Utils.getGroupOfPlatformPermission(permissionName); 74 75 UserHandle userHandle = getIntent().getParcelableExtra(Intent.EXTRA_USER); 76 if (userHandle == null) { 77 Log.i(LOG_TAG, "Missing mandatory argument EXTRA_USER"); 78 finish(); 79 return; 80 } 81 82 if (LocationUtils.isLocationGroupAndProvider(this, groupName, 83 packageName)) { 84 Intent intent = new Intent(this, LocationProviderInterceptDialog.class); 85 intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName); 86 startActivity(intent); 87 finish(); 88 return; 89 } 90 91 if (LocationUtils.isLocationGroupAndControllerExtraPackage( 92 this, groupName, packageName)) { 93 // Redirect to location controller extra package settings. 94 LocationUtils.startLocationControllerExtraPackageSettings(this); 95 finish(); 96 return; 97 } 98 99 String caller = getIntent().getStringExtra(EXTRA_CALLER_NAME); 100 101 Fragment androidXFragment; 102 if (DeviceUtils.isAuto(this)) { 103 androidXFragment = AutoAppPermissionFragment.newInstance(packageName, permissionName, 104 groupName, userHandle); 105 } else { 106 long sessionId = getIntent().getLongExtra(Constants.EXTRA_SESSION_ID, 107 INVALID_SESSION_ID); 108 androidXFragment = AppPermissionFragment.newInstance(packageName, permissionName, 109 groupName, userHandle, caller, sessionId); 110 } 111 112 getSupportFragmentManager().beginTransaction().replace(android.R.id.content, 113 androidXFragment).commit(); 114 } 115 116 @Override onOptionsItemSelected(MenuItem item)117 public boolean onOptionsItemSelected(MenuItem item) { 118 // in automotive mode, there's no system wide back button, so need to add that 119 if (DeviceUtils.isAuto(this)) { 120 switch (item.getItemId()) { 121 case android.R.id.home: 122 onBackPressed(); 123 return true; 124 default: 125 return super.onOptionsItemSelected(item); 126 } 127 } 128 return super.onOptionsItemSelected(item); 129 } 130 } 131