Add support messages to device admin pages.
Add support message to device admin settings pages. Show policy information for device owners and profile owners. Allow a user to remove profile from profile owners admin page. Bug: 26416662 Change-Id: I95424da50067b7c0ba1618a083a31448d406188f
This commit is contained in:
@@ -17,24 +17,57 @@
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AppGlobals;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ShowAdminSupportDetailsDialog extends Activity
|
||||
implements DialogInterface.OnDismissListener {
|
||||
|
||||
private final String TAG = "AdminSupportDialog";
|
||||
|
||||
private DevicePolicyManager mDpm;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mDpm = getSystemService(DevicePolicyManager.class);
|
||||
ComponentName admin = null;
|
||||
int userId = UserHandle.myUserId();
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
IActivityManager am = ActivityManagerNative.getDefault();
|
||||
try {
|
||||
int uid = am.getLaunchedFromUid(getActivityToken());
|
||||
// Only allow system to specify admin and user.
|
||||
if (UserHandle.isSameApp(uid, android.os.Process.myUid())) {
|
||||
admin = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
||||
userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Could not talk to activity manager.", e);
|
||||
}
|
||||
}
|
||||
|
||||
View rootView = LayoutInflater.from(this).inflate(
|
||||
R.layout.admin_support_details_dialog, null);
|
||||
setAdminSupportDetails(rootView);
|
||||
setAdminSupportDetails(rootView, admin, userId);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setView(rootView)
|
||||
@@ -43,24 +76,47 @@ public class ShowAdminSupportDetailsDialog extends Activity
|
||||
.show();
|
||||
}
|
||||
|
||||
private void setAdminSupportDetails(View root) {
|
||||
CharSequence adminDisabledMsg = getString(R.string.disabled_by_admin_msg,
|
||||
getString(R.string.default_organisation_name));
|
||||
TextView textView = (TextView) root.findViewById(R.id.disabled_by_admin_msg);
|
||||
textView.setText(adminDisabledMsg);
|
||||
private void setAdminSupportDetails(View root, final ComponentName admin, final int userId) {
|
||||
if (admin != null) {
|
||||
CharSequence supportMessage = mDpm.getShortSupportMessageForUser(admin, userId);
|
||||
if (supportMessage != null) {
|
||||
TextView textView = (TextView) root.findViewById(R.id.admin_support_msg);
|
||||
textView.setText(supportMessage);
|
||||
}
|
||||
|
||||
CharSequence adminSupportDetails = getString(R.string.default_admin_support_msg);
|
||||
textView = (TextView) root.findViewById(R.id.admin_support_msg);
|
||||
textView.setText(adminSupportDetails);
|
||||
ActivityInfo ai = null;
|
||||
try {
|
||||
ai = AppGlobals.getPackageManager().getReceiverInfo(admin, 0 /* flags */, userId);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "Missing reciever info" , e);
|
||||
}
|
||||
if (ai != null) {
|
||||
Drawable icon = ai.loadIcon(getPackageManager());
|
||||
Drawable badgedIcon = getPackageManager().getUserBadgedIcon(
|
||||
icon, new UserHandle(userId));
|
||||
((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(
|
||||
badgedIcon);
|
||||
}
|
||||
}
|
||||
|
||||
root.findViewById(R.id.admins_policies_list).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(ShowAdminSupportDetailsDialog.this,
|
||||
Settings.DeviceAdminSettingsActivity.class);
|
||||
startActivity(intent);
|
||||
if (admin != null) {
|
||||
intent.setClass(ShowAdminSupportDetailsDialog.this,
|
||||
DeviceAdminAdd.class);
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin);
|
||||
// DeviceAdminAdd class may need to run as managed profile.
|
||||
startActivityAsUser(intent, new UserHandle(userId));
|
||||
} else {
|
||||
intent.setClass(ShowAdminSupportDetailsDialog.this,
|
||||
Settings.DeviceAdminSettingsActivity.class);
|
||||
// Activity merges both managed profile and parent users
|
||||
// admins so show as same user as this activity.
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -70,4 +126,4 @@ public class ShowAdminSupportDetailsDialog extends Activity
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user