/* * Copyright (C) 2015 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.permissioncontroller.permission.ui.handheld; import static com.android.permissioncontroller.permission.ui.handheld.UtilsKt.pressBack; import android.app.ActionBar; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.UserHandle; import android.provider.Settings; import android.util.Log; import android.view.MenuItem; import android.widget.Switch; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProvider; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceGroup; import com.android.permissioncontroller.R; import com.android.permissioncontroller.permission.data.PackagePermissionsLiveData; import com.android.permissioncontroller.permission.model.AppPermissionGroup; import com.android.permissioncontroller.permission.model.Permission; import com.android.permissioncontroller.permission.ui.model.AllAppPermissionsViewModel; import com.android.permissioncontroller.permission.ui.model.AllAppPermissionsViewModelFactory; import com.android.permissioncontroller.permission.utils.ArrayUtils; import com.android.permissioncontroller.permission.utils.KotlinUtils; import com.android.permissioncontroller.permission.utils.Utils; import java.text.Collator; import java.util.List; import java.util.Map; /** * Show and manage individual permissions for an app. * *
Shows the list of individual runtime and non-runtime permissions the app has requested.
*/
public final class AllAppPermissionsFragment extends SettingsWithLargeHeader {
private static final String LOG_TAG = "AllAppPermissionsFragment";
private static final String KEY_OTHER = "other_perms";
private AllAppPermissionsViewModel mViewModel;
private Collator mCollator;
private String mPackageName;
private String mFilterGroup;
private UserHandle mUser;
public static AllAppPermissionsFragment newInstance(@NonNull String packageName,
@Nullable String filterGroup, @NonNull UserHandle userHandle) {
AllAppPermissionsFragment instance = new AllAppPermissionsFragment();
instance.setArguments(createArgs(packageName, filterGroup, userHandle));
return instance;
}
/**
* Create a bundle with the arguments needed by this fragment
*
* @param packageName The name of the package
* @param filterGroup An optional group to filter out permissions not in the group
* @param userHandle The user of this package
* @return A bundle with all of the args placed
*/
public static Bundle createArgs(@NonNull String packageName, @Nullable String filterGroup,
@NonNull UserHandle userHandle) {
Bundle arguments = new Bundle();
arguments.putString(Intent.EXTRA_PACKAGE_NAME, packageName);
arguments.putString(Intent.EXTRA_PERMISSION_GROUP_NAME, filterGroup);
arguments.putParcelable(Intent.EXTRA_USER, userHandle);
return arguments;
}
/**
* Create a bundle with the arguments needed by this fragment
*
* @param packageName The name of the package
* @param userHandle The user of this package
* @return A bundle with all of the args placed
*/
public static Bundle createArgs(@NonNull String packageName, @NonNull UserHandle userHandle) {
return createArgs(packageName, null, userHandle);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPackageName = getArguments().getString(Intent.EXTRA_PACKAGE_NAME);
mFilterGroup = getArguments().getString(Intent.EXTRA_PERMISSION_GROUP_NAME);
mUser = getArguments().getParcelable(Intent.EXTRA_USER);
if (mPackageName == null || mUser == null) {
Log.e(LOG_TAG, "Missing required argument EXTRA_PACKAGE_NAME or "
+ "EXTRA_USER");
pressBack(this);
}
AllAppPermissionsViewModelFactory factory = new AllAppPermissionsViewModelFactory(
mPackageName, mUser, mFilterGroup);
mViewModel = new ViewModelProvider(this, factory).get(AllAppPermissionsViewModel.class);
mViewModel.getAllPackagePermissionsLiveData().observe(this, this::updateUi);
mCollator = Collator.getInstance(
getContext().getResources().getConfiguration().getLocales().get(0));
}
@Override
public void onStart() {
super.onStart();
final ActionBar ab = getActivity().getActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
}
// If we target a group make this look like app permissions.
if (getArguments().getString(Intent.EXTRA_PERMISSION_GROUP_NAME) == null) {
getActivity().setTitle(R.string.all_permissions);
} else {
getActivity().setTitle(R.string.app_permissions);
}
setHasOptionsMenu(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
pressBack(this);
return true;
}
}
return super.onOptionsItemSelected(item);
}
private void updateUi(Map