Skip to content

Commit 50f86c6

Browse files
committed
docs: a few style adjustments to admin doc
Change-Id: I1ea2416f1f26835b1111aad65cc519dd8d56e099
1 parent 2e5a22a commit 50f86c6

File tree

1 file changed

+81
-43
lines changed

1 file changed

+81
-43
lines changed

docs/html/guide/topics/admin/device-admin.jd

Lines changed: 81 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
page.title=Android Device Administration API
1+
page.title=Device Administration
22
@jd:body
3+
34
<div id="qv-wrapper">
45
<div id="qv">
56
<h2>In this document</h2>
67
<ol>
78
<li><a href="#overview">Device Administration API Overview</a>
89
<ol>
10+
<li><a href="#how">How does it work?</a></li>
911
<li><a href="#policies">Policies</a></li>
1012
</ol>
1113
</li>
12-
<li><a href="#how">How Does It Work?</a></li>
1314
<li><a href="#sample">Sample Application</a></li>
1415
<li><a href="#developing">Developing a Device Administration Application</a>
1516
<ol>
16-
<li><a href="#manifest">Creating the Manifest</a></li>
17-
<li><a href="#code">Implementing the Code</a>
18-
</li>
17+
<li><a href="#manifest">Creating the manifest</a></li>
18+
<li><a href="#code">Implementing the code</a></li>
1919
</ol>
20+
</li>
21+
22+
</ol>
23+
24+
<h2>Key classes</h2>
25+
<ol>
26+
<li>{@link android.app.admin.DeviceAdminReceiver}</li>
27+
<li>{@link android.app.admin.DevicePolicyManager}</li>
28+
<li>{@link android.app.admin.DeviceAdminInfo}</li>
2029
</ol>
21-
</div>
30+
</div>
2231
</div>
2332

2433
<p>Android 2.2 introduces support for enterprise applications by offering the
@@ -37,22 +46,25 @@ their email and calendar data.</p>
3746
solutions for Android-powered devices. It discusses the various features
3847
provided by the Device Administration API to provide stronger security for
3948
employee devices that are powered by Android.</p>
49+
50+
4051
<h2 id="overview">Device Administration API Overview</h2>
52+
4153
<p>Here are examples of the types of applications that might use the Device Administration API:</p>
4254
<ul>
4355
<li>Email clients.</li>
4456
<li>Security applications that do remote wipe.</li>
4557
<li>Device management services and applications.</li>
4658
</ul>
4759

48-
<h3 id="how">How Does it Work?</h3>
60+
<h3 id="how">How does it work?</h3>
4961
<p>You use the Device Administration API to write device admin applications that users
5062
install on their devices. The device admin application enforces the desired
5163
policies. Here's how it works:</p> <ul>
5264
<li>A system administrator writes a device admin application that enforces
5365
remote/local device security policies. These policies could be hard-coded into
5466
the app, or the application could dynamically fetch policies from a third-party
55-
server. </li>
67+
server. </li>
5668
<li>The application is installed on users' devices. Android does
5769
not currently have an automated provisioning solution. Some of the ways a sysadmin might
5870
distribute the application to users are as follows:
@@ -68,7 +80,7 @@ distribute the application to users are as follows:
6880
<li>The system prompts the user to enable the device admin application. How
6981
and when this happens depends on how the application is implemented.</li>
7082
<li>Once users enable the device admin application, they are subject to
71-
its policies. Complying with those policies typically confers benefits, such as
83+
its policies. Complying with those policies typically confers benefits, such as
7284
access to sensitive systems and data.</li>
7385
</ul>
7486
<p>If users do not enable the device admin app, it remains on the device, but in an inactive state. Users will not be subject to its policies, and they will conversely not get any of the application's benefits&mdash;for example, they may not be able to sync data.</p>
@@ -88,12 +100,14 @@ application.</p>
88100
<p>To uninstall an existing device admin application, users need to
89101
first unregister the application as an administrator. </p>
90102

91-
<h3 id ="policies">Policies</h3>
103+
104+
<h3 id="policies">Policies</h3>
105+
92106
<p>In an enterprise setting, it's often the case that employee devices must
93107
adhere to a strict set of policies that govern the use of the device. The
94108
Device Administration API supports the policies listed in Table 1.
95109
Note that the Device Administration API currently only supports passwords for screen
96-
lock:</p>
110+
lock:</p>
97111
<p class="table-caption"><strong>Table 1.</strong> Policies supported by the Device Administration API.</p>
98112
<table border="1">
99113
<tr>
@@ -109,7 +123,7 @@ lock:</p>
109123
<td>Set the required number of characters for the password. For example, you
110124
can require PIN or passwords to have at least six characters. </td> </tr>
111125
<tr>
112-
<td>Alphanumeric password required</td>
126+
<td>Alphanumeric password required</td>
113127
<td>Requires that passwords have a
114128
combination of letters and numbers. They may include symbolic characters.
115129
</td>
@@ -128,7 +142,9 @@ pressed a button before the device locks the screen. When this happens, users
128142
need to enter their PIN or passwords again before they can use their devices and
129143
access data. The value can be between 1 and 60 minutes.</td> </tr>
130144
</table>
131-
<h4>Other Features</h4>
145+
146+
<h4>Other features</h4>
147+
132148
<p>In addition to supporting the policies listed in the above table, the Device
133149
Administration API lets you do the following:</p> <ul>
134150
<li>Prompt user to set a new password.</li>
@@ -138,6 +154,7 @@ Administration API lets you do the following:</p> <ul>
138154

139155

140156
<h2 id="sample">Sample Application</h2>
157+
141158
<p>The examples used in this document are based on the <a
142159
href="{@docRoot}resources/samples/ApiDemos/src/com/example/
143160
android/apis/app/DeviceAdminSample.html">Device Administration API
@@ -147,7 +164,7 @@ href="{@docRoot}resources/samples/get.html">
147164
Getting the Samples</a>. Here is the <a
148165
href="{@docRoot}resources/samples/ApiDemos/src/com/example/
149166
android/apis/app/DeviceAdminSample.html">complete code</a> for
150-
the sample. </p>
167+
the sample. </p>
151168
<p>The
152169
sample application offers a demo of device admin features. It presents users
153170
with a user interface that lets them enable the device admin application. Once
@@ -169,13 +186,17 @@ locks.</li>
169186
<img src="{@docRoot}images/admin/device-admin-app.png"/>
170187
<p class="img-caption"><strong>Figure 1.</strong> Screenshot of the Sample Application</p>
171188

189+
190+
172191
<h2 id="developing">Developing a Device Administration Application</h2>
173192

174193
<p>System administrators can use the Device Administration API to write an application
175194
that enforces remote/local device security policy enforcement. This section
176195
summarizes the steps involved in creating a device administration
177196
application.</p>
178-
<h3 id="manifest">Creating the Manifest</h3>
197+
198+
<h3 id="manifest">Creating the manifest</h3>
199+
179200
<p>To use the Device Administration API, the application's
180201
manifest must include the following:</p>
181202
<ul>
@@ -207,7 +228,7 @@ intent, expressed in the manifest as an intent filter.</li>
207228
       &lt;action android:name=&quot;android.app.action.DEVICE_ADMIN_ENABLED&quot; /&gt;
208229
   &lt;/intent-filter&gt;
209230
&lt;/receiver&gt;</pre>
210-
231+
211232
<p>Note that:</p>
212233
<ul>
213234
<li>The activity in the sample application is an {@link android.app.Activity}
@@ -218,7 +239,7 @@ subclass called <code>Controller</code>. The syntax
218239
an inner class; it just is in this example.</li>
219240

220241
<li>The following attributes refer to string resources that for the sample application reside in
221-
<code>ApiDemos/res/values/strings.xml</code>. For more information about resources, see
242+
<code>ApiDemos/res/values/strings.xml</code>. For more information about resources, see
222243
<a
223244
href="{@docRoot}guide/topics/resources/index.html">Application Resources</a>.
224245
<ul>
@@ -234,8 +255,8 @@ informative than
234255
a label.</li>
235256
</ul>
236257

237-
238-
<li><code>android:permission=&quot;android.permission.BIND_DEVICE_ADMIN&quot;
258+
259+
<li><code>android:permission=&quot;android.permission.BIND_DEVICE_ADMIN&quot;
239260
</code> is a permission that a {@link android.app.admin.DeviceAdminReceiver} subclass must
240261
have, to ensure that only the system can interact with the receiver (no application can be granted this permission). This
241262
prevents other applications from abusing your device admin app.</li>
@@ -273,11 +294,15 @@ android.app.admin.DeviceAdminInfo} class. Here are the contents of
273294
include all of the policies, just the ones that are relevant for your app.
274295
</p>
275296
For more discussion of the manifest file, see the <a
276-
href="{@docRoot}guide/topics/manifest/manifest-intro.html">Android Developers Guide</a>.
277-
<h2 id="code">Implementing the Code</h2>
297+
href="{@docRoot}guide/topics/manifest/manifest-intro.html">Android Developers Guide</a>.
298+
299+
300+
301+
<h3 id="code">Implementing the code</h3>
302+
278303
<p>The Device Administration API includes the following classes:</p>
279304
<dl>
280-
<dt>{@link android.app.admin.DeviceAdminReceiver}</dt>
305+
<dt>{@link android.app.admin.DeviceAdminReceiver}</dt>
281306
<dd>Base class for implementing a device administration component. This class provides
282307
a convenience for interpreting the raw intent actions that are sent by the
283308
system. Your Device Administration application must include a
@@ -287,14 +312,15 @@ system. Your Device Administration application must include a
287312
this class must have published a {@link android.app.admin.DeviceAdminReceiver} that the user
288313
has currently enabled. The {@link android.app.admin.DevicePolicyManager} manages policies for
289314
one or more {@link android.app.admin.DeviceAdminReceiver} instances</dd>
290-
<dt>{@link android.app.admin.DeviceAdminInfo}</dt>
315+
<dt>{@link android.app.admin.DeviceAdminInfo}</dt>
291316
<dd>This class is used to specify metadata
292317
for a device administrator component.</dd>
293318
</dl>
294319
<p>These classes provide the foundation for a fully functional device administration application.
295320
The rest of this section describes how you use the {@link
296321
android.app.admin.DeviceAdminReceiver} and
297322
{@link android.app.admin.DevicePolicyManager} APIs to write a device admin application.</p>
323+
298324
<h4 id="receiver">Subclassing DeviceAdminReceiver</h4>
299325
<p>To create a device admin application, you must subclass
300326
{@link android.app.admin.DeviceAdminReceiver}. The {@link android.app.admin.DeviceAdminReceiver} class
@@ -305,7 +331,7 @@ simply displays a {@link android.widget.Toast} notification in response to parti
305331
events. For example:</p>
306332
<pre>public class DeviceAdminSample extends DeviceAdminReceiver {
307333

308-
...
334+
...
309335
&#64;Override
310336
    public void onEnabled(Context context, Intent intent) {
311337
        showToast(context, &quot;Sample Device Admin: enabled&quot;);
@@ -331,30 +357,32 @@ events. For example:</p>
331357
}
332358
...
333359
}</pre>
334-
<h4 id="enabling">Enabling the Application</h4>
360+
361+
<h4 id="enabling">Enabling the application</h4>
335362
<p>One of the major events a device admin application has to handle is the user
336363
enabling the application. The user must explicitly enable the application for
337364
the policies to be enforced. If the user chooses not to enable the application
338365
it will still be present on the device, but its policies will not be enforced, and the user will not
339366
get any of the application's benefits.</p>
340367
<p>The process of enabling the application begins when the user performs an
341-
action that triggers the {@link android.app.admin.DevicePolicyManager#ACTION_ADD_DEVICE_ADMIN}
368+
action that triggers the {@link android.app.admin.DevicePolicyManager#ACTION_ADD_DEVICE_ADMIN}
342369
intent. In the
343370
sample application, this happens when the user clicks the <strong>Enable
344371
Admin</strong> button. </p>
345372
<p>When the user clicks the <strong>Enable Admin</strong> button, the display
346-
changes to prompt the user to enable the device admin application, as shown in <strong>Figure 2</strong>.</p>
373+
changes to prompt the user to enable the device admin application, as shown in figure
374+
2.</p>
347375

348376
<img src="{@docRoot}images/admin/device-admin-activate-prompt.png"/>
349377
<p class="img-caption"><strong>Figure 2.</strong> Sample Application: Activating the Application</p>
350378
<p>Below is the code that gets executed when the user clicks the <strong>Enable
351-
Admin</strong> button shown in <strong>Figure 1</strong>. </p>
379+
Admin</strong> button shown in figure 1. </p>
352380

353381
<pre> private OnClickListener mEnableListener = new OnClickListener() {
354382
public void onClick(View v) {
355383
// Launch the activity to have the user enable our admin.
356384
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
357-
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
385+
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
358386
mDeviceAdminSample);
359387
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
360388
               &quot;Additional text explaining why this needs to be added.&quot;);
@@ -379,10 +407,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
379407
}</pre>
380408

381409
<p>The line
382-
<code>intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
410+
<code>intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
383411
mDeviceAdminSample)</code> states that <code>mDeviceAdminSample</code> (which is
384412
a {@link android.app.admin.DeviceAdminReceiver} component) is the target policy.
385-
This line invokes the user interface shown in <strong>Figure 2</strong>, which guides users through
413+
This line invokes the user interface shown in figure 2, which guides users through
386414
adding the device administrator to the system (or allows them to reject it).</p>
387415

388416
<p>When the application needs to perform an operation that is contingent on the
@@ -402,41 +430,46 @@ if (active) {
402430
// do something else
403431
}
404432
</pre>
405-
<h3 id="admin_ops">Managing Policies</h3>
433+
434+
<h3 id="admin_ops">Managing policies</h3>
406435
<p>{@link android.app.admin.DevicePolicyManager} is a public class for managing policies
407436
enforced on a device. {@link android.app.admin.DevicePolicyManager} manages policies for one
408437
or more {@link android.app.admin.DeviceAdminReceiver} instances. </p>
409438
<p>You get a handle to the {@link android.app.admin.DevicePolicyManager} as follows: </p>
410-
<pre>DevicePolicyManager mDPM =
411-
(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);<br
412-
/></pre>
439+
<pre>
440+
DevicePolicyManager mDPM =
441+
(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
442+
</pre>
413443
<p>This section describes how to use {@link android.app.admin.DevicePolicyManager} to perform
414444
administrative tasks:</p>
415445
<ul>
416446
<li><a href="#pwd">Set password policies</a></li>
417447
<li><a href="#lock">Set device lock</a></li>
418448
<li><a href="#wipe">Perform data wipe</a></li>
419449
</ul>
450+
420451
<h4 id="pwd">Set password policies</h4>
421452
<p>{@link android.app.admin.DevicePolicyManager} includes APIs for setting and enforcing the
422453
device password policy. In the Device Administration API, the password only applies to
423454
screen lock. This section describes common password-related tasks.</p>
455+
424456
<h5>Set a password for the device</h5>
425457
<p>This code displays a user interface prompting the user to set a password:</p>
426458
<pre>Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
427459
startActivity(intent);
428460
</pre>
461+
429462
<h5>Set the password quality</h5>
430463
<p>The password quality can be one of the following {@link android.app.admin.DevicePolicyManager} constants: </p>
431464
<dl>
432-
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_ALPHABETIC}</dt><dd>The user must enter a
465+
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_ALPHABETIC}</dt><dd>The user must enter a
433466
password containing at least alphabetic (or other symbol) characters.</dd>
434-
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_ALPHANUMERIC}</dt><dd>The user must enter a
467+
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_ALPHANUMERIC}</dt><dd>The user must enter a
435468
password containing at least <em>both</em> numeric <em>and</em> alphabetic (or
436469
other symbol) characters.</dd>
437470
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_NUMERIC}</dt><dd>The user must enter a password
438471
containing at least numeric characters.</dd>
439-
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_SOMETHING}</dt><dd>The policy requires some kind
472+
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_SOMETHING}</dt><dd>The policy requires some kind
440473
of password, but doesn't care what it is.</dd>
441474
<dt>{@link android.app.admin.DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}</dt><dd>
442475
The policy has no requirements for the password. </dd>
@@ -448,6 +481,7 @@ ComponentName mDeviceAdminSample;
448481
...
449482
mDPM.setPasswordQuality(mDeviceAdminSample, DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
450483
</pre>
484+
451485
<h5>Set the minimum password length</h5>
452486
<p>You can specify that a password must be at least the specified minimum
453487
length. For example:</p>
@@ -457,29 +491,33 @@ int pwLength;
457491
...
458492
mDPM.setPasswordMinimumLength(mDeviceAdminSample, pwLength);
459493
</pre>
494+
460495
<h5>Set maximum failed password attempts</h5>
461496
<p>You can set the maximum number of allowed failed password attempts before the
462497
device is wiped (that is, reset to factory settings). For example:</p>
463-
<pre>DevicePolicyManager mDPM;
464-
ComponentName mDeviceAdminSample;
498+
<pre>DevicePolicyManager mDPM;
499+
ComponentName mDeviceAdminSample;
465500
int maxFailedPw;
466501
...
467502
mDPM.setMaximumFailedPasswordsForWipe(mDeviceAdminSample, maxFailedPw);</pre>
503+
468504
<h4 id="lock">Set device lock</h4>
469505
<p>You can set the maximum period of user inactivity that can occur before the
470506
device locks. For example:</p>
471507
<pre>
472-
DevicePolicyManager mDPM;
508+
DevicePolicyManager mDPM;
473509
ComponentName mDeviceAdminSample;
474510
...
475511
long timeMs = 1000L*Long.parseLong(mTimeout.getText().toString());
476512
mDPM.setMaximumTimeToLock(mDeviceAdminSample, timeMs);
477513
</pre>
478514
<p>You can also programmatically tell the device to lock immediately:</p>
479515
<pre>
480-
DevicePolicyManager mDPM;
516+
DevicePolicyManager mDPM;
481517
mDPM.lockNow();</pre>
518+
482519
<h4 id="wipe">Perform data wipe</h4>
520+
483521
<p>You can use the {@link android.app.admin.DevicePolicyManager} method
484522
{@link android.app.admin.DevicePolicyManager#wipeData wipeData()} to reset the device to factory settings. This is useful
485523
if the device is lost or stolen. Often the decision to wipe the device is the
@@ -488,7 +526,7 @@ result of certain conditions being met. For example, you can use
488526
wiped after a specific number of failed password attempts.</p>
489527
<p>You wipe data as follows:</p>
490528
<pre>
491-
DevicePolicyManager mDPM;
529+
DevicePolicyManager mDPM;
492530
mDPM.wipeData(0);</pre>
493531
<p>The {@link android.app.admin.DevicePolicyManager#wipeData wipeData()} method takes as its parameter a bit mask of
494532
additional options. Currently the value must be 0. </p>

0 commit comments

Comments
 (0)