OSDN Git Service

Fix issue #2396296: An admin is already set
authorDianne Hackborn <hackbod@google.com>
Mon, 22 Feb 2010 20:51:42 +0000 (12:51 -0800)
committerDianne Hackborn <hackbod@google.com>
Tue, 23 Feb 2010 04:39:17 +0000 (20:39 -0800)
src/com/android/settings/DeviceAdminAdd.java

index 126af6b..26ad70c 100644 (file)
@@ -137,8 +137,18 @@ public class DeviceAdminAdd extends Activity {
         mActionButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 if (mAdding) {
-                    mDPM.setActiveAdmin(mDeviceAdmin.getComponent());
-                    setResult(Activity.RESULT_OK);
+                    try {
+                        mDPM.setActiveAdmin(mDeviceAdmin.getComponent());
+                        setResult(Activity.RESULT_OK);
+                    } catch (RuntimeException e) {
+                        // Something bad happened...  could be that it was
+                        // already set, though.
+                        Log.w(TAG, "Exception trying to activate admin "
+                                + mDeviceAdmin.getComponent(), e);
+                        if (mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
+                            setResult(Activity.RESULT_OK);
+                        }
+                    }
                     finish();
                 } else {
                     mDPM.getRemoveWarning(mDeviceAdmin.getComponent(),