• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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.car.settings.applications.specialaccess;
18 
19 import android.car.drivingstate.CarUxRestrictions;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 import android.content.pm.ResolveInfo;
24 
25 import androidx.annotation.Nullable;
26 import androidx.preference.Preference;
27 
28 import com.android.car.settings.common.FragmentController;
29 import com.android.car.settings.common.PreferenceController;
30 
31 /**
32  * Launches into additional special access settings if they are supported by the permission
33  * controller package.
34  */
35 public class MoreSpecialAccessPreferenceController extends PreferenceController<Preference> {
36 
37     @Nullable
38     private final Intent mIntent;
39 
MoreSpecialAccessPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)40     public MoreSpecialAccessPreferenceController(Context context, String preferenceKey,
41             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
42         super(context, preferenceKey, fragmentController, uxRestrictions);
43         PackageManager packageManager = getContext().getPackageManager();
44         String packageName = packageManager.getPermissionControllerPackageName();
45         if (packageName != null) {
46             Intent intent = new Intent(Intent.ACTION_MANAGE_SPECIAL_APP_ACCESSES).setPackage(
47                     packageName);
48             ResolveInfo resolveInfo = packageManager.resolveActivity(intent,
49                     PackageManager.MATCH_DEFAULT_ONLY);
50             mIntent = (resolveInfo != null) ? intent : null;
51         } else {
52             mIntent = null;
53         }
54     }
55 
56     @Override
getPreferenceType()57     protected Class<Preference> getPreferenceType() {
58         return Preference.class;
59     }
60 
61     @Override
getAvailabilityStatus()62     protected int getAvailabilityStatus() {
63         return (mIntent != null) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
64     }
65 
66     @Override
handlePreferenceClicked(Preference preference)67     protected boolean handlePreferenceClicked(Preference preference) {
68         if (mIntent != null) {
69             getContext().startActivity(mIntent);
70             return true;
71         }
72         return false;
73     }
74 }
75