Add event logging for device admin.
This allows us to gather metrics about unwanted device admin apps. User consent from Verify Apps is required. Bug: 11253927 Change-Id: I449929772f63f426426f7726d3d21e7c1512e6ce
This commit is contained in:
@@ -38,6 +38,7 @@ import android.os.Handler;
|
|||||||
import android.os.RemoteCallback;
|
import android.os.RemoteCallback;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.text.TextUtils.TruncateAt;
|
import android.text.TextUtils.TruncateAt;
|
||||||
|
import android.util.EventLog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -55,19 +56,19 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceAdminAdd extends Activity {
|
public class DeviceAdminAdd extends Activity {
|
||||||
static final String TAG = "DeviceAdminAdd";
|
static final String TAG = "DeviceAdminAdd";
|
||||||
|
|
||||||
static final int DIALOG_WARNING = 1;
|
static final int DIALOG_WARNING = 1;
|
||||||
|
|
||||||
private static final int MAX_ADD_MSG_LINES_PORTRAIT = 5;
|
private static final int MAX_ADD_MSG_LINES_PORTRAIT = 5;
|
||||||
private static final int MAX_ADD_MSG_LINES_LANDSCAPE = 2;
|
private static final int MAX_ADD_MSG_LINES_LANDSCAPE = 2;
|
||||||
private static final int MAX_ADD_MSG_LINES = 15;
|
private static final int MAX_ADD_MSG_LINES = 15;
|
||||||
|
|
||||||
Handler mHandler;
|
Handler mHandler;
|
||||||
|
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
DeviceAdminInfo mDeviceAdmin;
|
DeviceAdminInfo mDeviceAdmin;
|
||||||
CharSequence mAddMsgText;
|
CharSequence mAddMsgText;
|
||||||
|
|
||||||
ImageView mAdminIcon;
|
ImageView mAdminIcon;
|
||||||
TextView mAdminName;
|
TextView mAdminName;
|
||||||
TextView mAdminDescription;
|
TextView mAdminDescription;
|
||||||
@@ -78,19 +79,19 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
ViewGroup mAdminPolicies;
|
ViewGroup mAdminPolicies;
|
||||||
Button mActionButton;
|
Button mActionButton;
|
||||||
Button mCancelButton;
|
Button mCancelButton;
|
||||||
|
|
||||||
final ArrayList<View> mAddingPolicies = new ArrayList<View>();
|
final ArrayList<View> mAddingPolicies = new ArrayList<View>();
|
||||||
final ArrayList<View> mActivePolicies = new ArrayList<View>();
|
final ArrayList<View> mActivePolicies = new ArrayList<View>();
|
||||||
|
|
||||||
boolean mAdding;
|
boolean mAdding;
|
||||||
boolean mRefreshing;
|
boolean mRefreshing;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle icicle) {
|
protected void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
mHandler = new Handler(getMainLooper());
|
mHandler = new Handler(getMainLooper());
|
||||||
|
|
||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
|
||||||
if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
|
||||||
@@ -98,7 +99,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentName cn = (ComponentName)getIntent().getParcelableExtra(
|
ComponentName cn = (ComponentName)getIntent().getParcelableExtra(
|
||||||
DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
||||||
if (cn == null) {
|
if (cn == null) {
|
||||||
@@ -163,7 +164,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This admin already exists, an we have two options at this point. If new policy
|
// This admin already exists, an we have two options at this point. If new policy
|
||||||
// bits are set, show the user the new list. If nothing has changed, simply return
|
// bits are set, show the user the new list. If nothing has changed, simply return
|
||||||
// "OK" immediately.
|
// "OK" immediately.
|
||||||
@@ -189,7 +190,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION);
|
mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION);
|
||||||
|
|
||||||
setContentView(R.layout.device_admin_add);
|
setContentView(R.layout.device_admin_add);
|
||||||
|
|
||||||
mAdminIcon = (ImageView)findViewById(R.id.admin_icon);
|
mAdminIcon = (ImageView)findViewById(R.id.admin_icon);
|
||||||
mAdminName = (TextView)findViewById(R.id.admin_name);
|
mAdminName = (TextView)findViewById(R.id.admin_name);
|
||||||
mAdminDescription = (TextView)findViewById(R.id.admin_description);
|
mAdminDescription = (TextView)findViewById(R.id.admin_description);
|
||||||
@@ -210,6 +211,8 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
||||||
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_DECLINED_BY_USER,
|
||||||
|
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -220,6 +223,8 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
try {
|
try {
|
||||||
mDPM.setActiveAdmin(mDeviceAdmin.getComponent(), mRefreshing);
|
mDPM.setActiveAdmin(mDeviceAdmin.getComponent(), mRefreshing);
|
||||||
setResult(Activity.RESULT_OK);
|
setResult(Activity.RESULT_OK);
|
||||||
|
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_ACTIVATED_BY_USER,
|
||||||
|
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
// Something bad happened... could be that it was
|
// Something bad happened... could be that it was
|
||||||
// already set, though.
|
// already set, though.
|
||||||
@@ -264,13 +269,13 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
updateInterface();
|
updateInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id, Bundle args) {
|
protected Dialog onCreateDialog(int id, Bundle args) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
@@ -291,17 +296,17 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return super.onCreateDialog(id, args);
|
return super.onCreateDialog(id, args);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setViewVisibility(ArrayList<View> views, int visibility) {
|
static void setViewVisibility(ArrayList<View> views, int visibility) {
|
||||||
final int N = views.size();
|
final int N = views.size();
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
views.get(i).setVisibility(visibility);
|
views.get(i).setVisibility(visibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateInterface() {
|
void updateInterface() {
|
||||||
mAdminIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
|
mAdminIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
|
||||||
mAdminName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
|
mAdminName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
|
||||||
|
@@ -4,3 +4,9 @@ option java_package com.android.settings
|
|||||||
|
|
||||||
# log the type of screen lock when user sets lock screen
|
# log the type of screen lock when user sets lock screen
|
||||||
90200 lock_screen_type (type|3)
|
90200 lock_screen_type (type|3)
|
||||||
|
|
||||||
|
# log whether user accepted and activated device admin
|
||||||
|
90201 exp_det_device_admin_activated_by_user (app_signature|3)
|
||||||
|
|
||||||
|
# log whether user declined activation of device admin
|
||||||
|
90202 exp_det_device_admin_declined_by_user (app_signature|3)
|
||||||
|
Reference in New Issue
Block a user