blob: f32787fdb35e9aac603e15a15f3e5df72254c1ed [file] [log] [blame]
package com.android.managedprovisioning;
/*
* Copyright 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.
*/
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.managedprovisioning.Utils.MdmPackageInfo;
/**
* Displays information about an existing managed profile and asks the user if it should be deleted.
*
* <p>Expects parent component to implement {@link DeleteManagedProfileCallback} for user-response
* handling.
*/
public class DeleteManagedProfileDialog extends DialogFragment {
private static final String KEY_USER_PROFILE_CALLBACK_ID = "user_profile_callback_id";
private static final String KEY_MDM_PACKAGE_NAME = "mdm_package_name";
private static final String KEY_PROFILE_OWNER_DOMAIN = "profile_owner_domain";
/**
* @param managedProfileUserId user-id for the managed profile which will be passed back to the
* parent component in the {@link DeleteManagedProfileCallback#onRemoveProfileApproval(int)}
* call
* @param mdmPackagename package name of the MDM application for the current managed profile
* @param profileOwnerDomain domain name of the organization which owns the managed profile, or
* null if not known
* @return initialized dialog
*/
public static DeleteManagedProfileDialog newInstance(
int managedProfileUserId, ComponentName mdmPackagename, String profileOwnerDomain) {
Bundle args = new Bundle();
args.putInt(KEY_USER_PROFILE_CALLBACK_ID, managedProfileUserId);
args.putString(KEY_MDM_PACKAGE_NAME, mdmPackagename.getPackageName());
args.putString(KEY_PROFILE_OWNER_DOMAIN, profileOwnerDomain);
DeleteManagedProfileDialog dialog = new DeleteManagedProfileDialog();
dialog.setArguments(args);
return dialog;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (!(getActivity() instanceof DeleteManagedProfileCallback)) {
throw new IllegalStateException("Calling activity must implement " +
"DeleteManagedProfileCallback, found: " + getActivity().getLocalClassName());
}
Bundle arguments = getArguments();
final int callbackUserProfileId = arguments.getInt(KEY_USER_PROFILE_CALLBACK_ID);
String mdmPackageName = arguments.getString(KEY_MDM_PACKAGE_NAME);
MdmPackageInfo mdmPackageInfo = Utils.getMdmPackageInfo(
getActivity().getPackageManager(), mdmPackageName);
final Dialog dialog = new Dialog(getActivity(), R.style.ManagedProvisioningDialogTheme);
dialog.setTitle(R.string.delete_profile_title);
dialog.setContentView(R.layout.delete_managed_profile_dialog);
dialog.setCanceledOnTouchOutside(false);
ImageView imageView = (ImageView) dialog.findViewById(
R.id.delete_managed_profile_mdm_icon_view);
imageView.setImageDrawable(mdmPackageInfo.getPackageIcon());
TextView deviceManagerName = (TextView) dialog.findViewById(
R.id.delete_managed_profile_device_manager_name);
deviceManagerName.setText(mdmPackageInfo.getAppLabel());
Button positiveButton = (Button) dialog.findViewById(
R.id.delete_managed_profile_positive_button);
positiveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
((DeleteManagedProfileCallback) getActivity())
.onRemoveProfileApproval(callbackUserProfileId);
}
});
Button negativeButton = (Button) dialog.findViewById(
R.id.delete_managed_profile_negative_button);
negativeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
((DeleteManagedProfileCallback) getActivity()).onRemoveProfileCancel();
}
});
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
return dialog;
}
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
((DeleteManagedProfileCallback) getActivity()).onRemoveProfileCancel();
}
/**
* Callback interface for outcome of {@link DeleteManagedProfileDialog} presentation.
*/
public interface DeleteManagedProfileCallback {
/**
* Invoked if the user hits the positive response (perform removal) button.
*
* @param managedProfileUserId user-id of the managed-profile that the dialog was presented
* for
*/
public abstract void onRemoveProfileApproval(int managedProfileUserId);
/**
* Invoked if the user hits the negative response (DO NOT perform removal) button, or the
* dialog was otherwise dismissed.
*/
public abstract void onRemoveProfileCancel();
}
}