• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 package com.android.cts.managedprofile;
17 
18 import android.app.Activity;
19 import android.content.ComponentName;
20 import android.content.pm.PackageManager;
21 import android.os.Bundle;
22 import android.os.Process;
23 import android.util.Log;
24 
25 /**
26  * Class that disables a given component for the user it's running in.
27  */
28 public class ComponentDisablingActivity extends Activity {
29 
30     private static final String TAG = ComponentDisablingActivity.class.getName();
31     public static final String EXTRA_PACKAGE = "extra-package";
32     public static final String EXTRA_CLASS_NAME = "extra-class-name";
33 
34     @Override
onCreate(Bundle savedInstanceState)35     public void onCreate(Bundle savedInstanceState) {
36         super.onCreate(savedInstanceState);
37         String extraClassName = getIntent().getStringExtra(EXTRA_CLASS_NAME);
38         String extraPackage = getIntent().getStringExtra(EXTRA_PACKAGE);
39 
40         Log.i(TAG, "Disabling: " + extraPackage + "/" + extraClassName + " for user "
41                 + Process.myUserHandle());
42         PackageManager packageManager = getPackageManager();
43         packageManager.setComponentEnabledSetting(new ComponentName(extraPackage, extraClassName),
44                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
45                 PackageManager.DONT_KILL_APP);
46     }
47 }