1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package com.android.settings.applications.appinfo; 17 18 import android.app.Dialog; 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.content.DialogInterface; 22 import android.content.pm.PackageManager; 23 import android.os.Bundle; 24 import android.os.UserHandle; 25 26 import androidx.appcompat.app.AlertDialog; 27 28 import com.android.settings.R; 29 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 30 import com.android.settings.overlay.FeatureFactory; 31 32 /** 33 * Fragment to show the dialog for clearing the instant app. 34 */ 35 public class InstantAppButtonDialogFragment extends InstrumentedDialogFragment implements 36 DialogInterface.OnClickListener { 37 38 private static final String ARG_PACKAGE_NAME = "packageName"; 39 40 private String mPackageName; 41 newInstance(String packageName)42 public static InstantAppButtonDialogFragment newInstance(String packageName) { 43 final InstantAppButtonDialogFragment dialogFragment = new InstantAppButtonDialogFragment(); 44 final Bundle args = new Bundle(1); 45 args.putString(ARG_PACKAGE_NAME, packageName); 46 dialogFragment.setArguments(args); 47 return dialogFragment; 48 } 49 50 @Override getMetricsCategory()51 public int getMetricsCategory() { 52 return SettingsEnums.DIALOG_APP_INFO_ACTION; 53 } 54 55 @Override onCreateDialog(Bundle savedInstanceState)56 public Dialog onCreateDialog(Bundle savedInstanceState) { 57 final Bundle arguments = getArguments(); 58 mPackageName = arguments.getString(ARG_PACKAGE_NAME); 59 return createDialog(); 60 } 61 62 @Override onClick(DialogInterface dialog, int which)63 public void onClick(DialogInterface dialog, int which) { 64 final Context context = getContext(); 65 final PackageManager packageManager = context.getPackageManager(); 66 FeatureFactory.getFactory(context).getMetricsFeatureProvider() 67 .action(context, SettingsEnums.ACTION_SETTINGS_CLEAR_INSTANT_APP, mPackageName); 68 packageManager.deletePackageAsUser(mPackageName, null, 0, UserHandle.myUserId()); 69 } 70 createDialog()71 private AlertDialog createDialog() { 72 AlertDialog confirmDialog = new AlertDialog.Builder(getContext()) 73 .setPositiveButton(R.string.clear_instant_app_data, this) 74 .setNegativeButton(R.string.cancel, null) 75 .setTitle(R.string.clear_instant_app_data) 76 .setMessage(R.string.clear_instant_app_confirmation) 77 .create(); 78 return confirmDialog; 79 } 80 81 } 82 83