| /* |
| * Copyright 2019 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.car.settings.applications.specialaccess; |
| |
| import android.car.userlib.CarUserManagerHelper; |
| import android.content.Context; |
| import android.os.Bundle; |
| |
| import androidx.annotation.XmlRes; |
| |
| import com.android.car.settings.R; |
| import com.android.car.settings.applications.ApplicationPreferenceController; |
| import com.android.car.settings.common.SettingsFragment; |
| import com.android.settingslib.applications.ApplicationsState; |
| |
| import java.util.ArrayList; |
| |
| /** Displays directory access permissions for a specific package. */ |
| public class DirectoryAccessDetailsFragment extends SettingsFragment { |
| |
| public static final String ARG_PACKAGE_NAME = "package"; |
| |
| private CarUserManagerHelper mCarUserManagerHelper; |
| private String mPackageName; |
| private ApplicationsState mAppState; |
| private ApplicationsState.Session mSession; |
| private ApplicationsState.AppEntry mAppEntry; |
| |
| /** Creates an instance of this fragment, passing {@code packageName} as an argument. */ |
| public static DirectoryAccessDetailsFragment getInstance(String packageName) { |
| DirectoryAccessDetailsFragment directoryAccessDetailsFragment = |
| new DirectoryAccessDetailsFragment(); |
| Bundle bundle = new Bundle(); |
| bundle.putString(ARG_PACKAGE_NAME, packageName); |
| directoryAccessDetailsFragment.setArguments(bundle); |
| return directoryAccessDetailsFragment; |
| } |
| |
| @Override |
| @XmlRes |
| protected int getPreferenceScreenResId() { |
| return R.xml.directory_access_details_fragment; |
| } |
| |
| @Override |
| public void onAttach(Context context) { |
| super.onAttach(context); |
| mCarUserManagerHelper = new CarUserManagerHelper(context); |
| |
| mPackageName = getArguments().getString(ARG_PACKAGE_NAME); |
| |
| mAppState = ApplicationsState.getInstance(requireActivity().getApplication()); |
| mSession = mAppState.newSession(mApplicationStateCallbacks, getLifecycle()); |
| |
| retrieveAppEntry(); |
| |
| use(ApplicationPreferenceController.class, |
| R.string.pk_directory_access_details_app).setAppEntry(mAppEntry).setAppState( |
| mAppState); |
| use(DirectoryAccessDetailsPreferenceController.class, |
| R.string.pk_directory_access_details).setPackage(mPackageName); |
| } |
| |
| @Override |
| public void onStart() { |
| super.onStart(); |
| // Resume the session earlier than the lifecycle so that cached information is updated |
| // even if settings is not resumed (for example in multi-display). |
| mSession.onResume(); |
| refresh(); |
| } |
| |
| @Override |
| public void onStop() { |
| super.onStop(); |
| // Since we resume early in onStart, make sure we clean up even if we don't receive onPause. |
| mSession.onPause(); |
| } |
| |
| private void refresh() { |
| retrieveAppEntry(); |
| if (mAppEntry == null) { |
| goBack(); |
| } |
| } |
| |
| private void retrieveAppEntry() { |
| mAppEntry = mAppState.getEntry(mPackageName, |
| mCarUserManagerHelper.getCurrentProcessUserId()); |
| } |
| |
| private final ApplicationsState.Callbacks mApplicationStateCallbacks = |
| new ApplicationsState.Callbacks() { |
| @Override |
| public void onRunningStateChanged(boolean running) { |
| } |
| |
| @Override |
| public void onPackageListChanged() { |
| refresh(); |
| } |
| |
| @Override |
| public void onRebuildComplete(ArrayList<ApplicationsState.AppEntry> apps) { |
| } |
| |
| @Override |
| public void onPackageIconChanged() { |
| } |
| |
| @Override |
| public void onPackageSizeChanged(String packageName) { |
| } |
| |
| @Override |
| public void onAllSizesComputed() { |
| } |
| |
| @Override |
| public void onLauncherInfoChanged() { |
| } |
| |
| @Override |
| public void onLoadEntriesCompleted() { |
| } |
| }; |
| } |