Home | History | Annotate | Download | only in enterprise
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy 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,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.settings.enterprise;
     18 
     19 import android.app.Activity;
     20 import android.app.admin.DevicePolicyManager;
     21 import android.content.DialogInterface;
     22 import android.content.Intent;
     23 import android.os.Bundle;
     24 import android.os.UserHandle;
     25 
     26 import com.android.settingslib.RestrictedLockUtils;
     27 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
     28 
     29 public class ActionDisabledByAdminDialog extends Activity
     30         implements DialogInterface.OnDismissListener {
     31 
     32     private ActionDisabledByAdminDialogHelper mDialogHelper;
     33 
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37         final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
     38                 getAdminDetailsFromIntent(getIntent());
     39         final String restriction = getRestrictionFromIntent(getIntent());
     40         mDialogHelper = new ActionDisabledByAdminDialogHelper(this);
     41         mDialogHelper.prepareDialogBuilder(restriction, enforcedAdmin)
     42                 .setOnDismissListener(this)
     43                 .show();
     44     }
     45 
     46     @Override
     47     public void onNewIntent(Intent intent) {
     48         super.onNewIntent(intent);
     49         final EnforcedAdmin admin = getAdminDetailsFromIntent(intent);
     50         final String restriction = getRestrictionFromIntent(intent);
     51         mDialogHelper.updateDialog(restriction, admin);
     52     }
     53 
     54     @android.support.annotation.VisibleForTesting
     55     EnforcedAdmin getAdminDetailsFromIntent(Intent intent) {
     56         final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.myUserId());
     57         if (intent == null) {
     58             return admin;
     59         }
     60         admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
     61         admin.userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
     62         return admin;
     63     }
     64 
     65     @android.support.annotation.VisibleForTesting
     66     String getRestrictionFromIntent(Intent intent) {
     67         if (intent == null) return null;
     68         return intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION);
     69     }
     70 
     71     @Override
     72     public void onDismiss(DialogInterface dialog) {
     73         finish();
     74     }
     75 }
     76