• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

修订版36a3d06181c35f0f5ff42338b2995bd764deddd1 (tree)
时间2011-01-13 14:19:06
作者Andy Stadler <stadler@goog...>
CommiterAndroid Git Automerger

Log Message

am 3eb48a06: Add encryption status controls

* commit '3eb48a061aa2d6aafe7493bb3d83ea8f8d53a33d':

Add encryption status controls

更改概述

差异

--- a/samples/ApiDemos/res/layout/device_admin_sample.xml
+++ b/samples/ApiDemos/res/layout/device_admin_sample.xml
@@ -272,6 +272,48 @@
272272
273273 </LinearLayout>
274274
275+ <!-- Encryption Status Controls -->
276+ <LinearLayout
277+ android:orientation="horizontal"
278+ android:gravity="center"
279+ android:layout_width="match_parent"
280+ android:layout_height="wrap_content" >
281+
282+ <Button android:id="@+id/encryption_enable_button"
283+ android:layout_width="wrap_content"
284+ android:layout_height="wrap_content"
285+ android:text="@string/encryption_enable_label" />
286+
287+ <Button android:id="@+id/encryption_disable_button"
288+ android:layout_width="wrap_content"
289+ android:layout_height="wrap_content"
290+ android:text="@string/encryption_disable_label" />
291+
292+ <Button android:id="@+id/encryption_activate_button"
293+ android:layout_width="wrap_content"
294+ android:layout_height="wrap_content"
295+ android:text="@string/encryption_activate_label" />
296+
297+ </LinearLayout>
298+
299+ <LinearLayout
300+ android:orientation="horizontal"
301+ android:gravity="center"
302+ android:layout_width="match_parent"
303+ android:layout_height="wrap_content" >
304+
305+ <TextView android:id="@+id/encryption_status"
306+ android:layout_width="wrap_content"
307+ android:layout_height="wrap_content" />
308+
309+ <Button android:id="@+id/encryption_update_status_button"
310+ android:layout_width="wrap_content"
311+ android:layout_height="wrap_content"
312+ android_layout_gravity="east|center_vertical"
313+ android:text="@string/update_encryption_status_label" />
314+
315+ </LinearLayout>
316+
275317 </LinearLayout>
276318
277319 </ScrollView>
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -614,6 +614,11 @@
614614 <string name="proxylist_hint">No proxy for domain1,domain2</string>
615615 <string name="set_proxy_label">Set Global Proxy</string>
616616
617+ <string name="encryption_enable_label">Enable Encryption</string>
618+ <string name="encryption_disable_label">Disable Encryption</string>
619+ <string name="encryption_activate_label">Activate Encryption</string>
620+ <string name="update_encryption_status_label">Update Status</string>
621+
617622 <!-- ============================== -->
618623 <!-- app/voice recognition examples strings -->
619624 <!-- ============================== -->
--- a/samples/ApiDemos/res/xml/device_admin_sample.xml
+++ b/samples/ApiDemos/res/xml/device_admin_sample.xml
@@ -24,6 +24,7 @@
2424 <wipe-data />
2525 <set-global-proxy />
2626 <expire-password />
27+ <encrypted-storage />
2728 </uses-policies>
2829 </device-admin>
2930 <!-- END_INCLUDE(meta_data) -->
--- a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
@@ -141,7 +141,10 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
141141 * all together; typically this code would appear in some separate class.
142142 */
143143 public static class Controller extends Activity {
144- static final int RESULT_ENABLE = 1;
144+
145+ static final int REQUEST_CODE_ENABLE_ADMIN = 1;
146+ static final int REQUEST_CODE_START_ENCRYPTION = 2;
147+
145148 private static final long MS_PER_MINUTE = 60*1000;
146149
147150 DevicePolicyManager mDPM;
@@ -195,6 +198,12 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
195198 private TextView mPasswordExpirationStatus;
196199 private Button mPasswordExpirationStatusButton;
197200
201+ private Button mEnableEncryptionButton;
202+ private Button mDisableEncryptionButton;
203+ private Button mActivateEncryptionButton;
204+ private Button mEncryptionStatusButton;
205+ private TextView mEncryptionStatus;
206+
198207 @Override
199208 protected void onCreate(Bundle savedInstanceState) {
200209 super.onCreate(savedInstanceState);
@@ -395,6 +404,16 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
395404 mProxyList = (EditText) findViewById(R.id.proxylist);
396405 mProxyButton = (Button) findViewById(R.id.set_proxy);
397406 mProxyButton.setOnClickListener(mSetProxyListener);
407+
408+ mEnableEncryptionButton = (Button) findViewById(R.id.encryption_enable_button);
409+ mEnableEncryptionButton.setOnClickListener(mEncryptionButtonListener);
410+ mDisableEncryptionButton = (Button) findViewById(R.id.encryption_disable_button);
411+ mDisableEncryptionButton.setOnClickListener(mEncryptionButtonListener);
412+ mActivateEncryptionButton = (Button) findViewById(R.id.encryption_activate_button);
413+ mActivateEncryptionButton.setOnClickListener(mEncryptionButtonListener);
414+ mEncryptionStatusButton = (Button) findViewById(R.id.encryption_update_status_button);
415+ mEncryptionStatusButton.setOnClickListener(mEncryptionButtonListener);
416+ mEncryptionStatus = (TextView) findViewById(R.id.encryption_status);
398417 }
399418
400419 void updateButtonStates() {
@@ -417,6 +436,10 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
417436 mForceLockButton.setEnabled(true);
418437 mWipeDataButton.setEnabled(true);
419438 mWipeAllDataButton.setEnabled(true);
439+ mEnableEncryptionButton.setEnabled(true);
440+ mDisableEncryptionButton.setEnabled(true);
441+ mActivateEncryptionButton.setEnabled(true);
442+ mEncryptionStatusButton.setEnabled(true);
420443 } else {
421444 mEnableButton.setEnabled(true);
422445 mDisableButton.setEnabled(false);
@@ -435,6 +458,10 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
435458 mForceLockButton.setEnabled(false);
436459 mWipeDataButton.setEnabled(false);
437460 mWipeAllDataButton.setEnabled(false);
461+ mEnableEncryptionButton.setEnabled(false);
462+ mDisableEncryptionButton.setEnabled(false);
463+ mActivateEncryptionButton.setEnabled(false);
464+ mEncryptionStatusButton.setEnabled(false);
438465 }
439466 }
440467
@@ -622,13 +649,16 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
622649 @Override
623650 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
624651 switch (requestCode) {
625- case RESULT_ENABLE:
652+ case REQUEST_CODE_ENABLE_ADMIN:
626653 if (resultCode == Activity.RESULT_OK) {
627654 Log.i(TAG, "Admin enabled!");
628655 } else {
629656 Log.i(TAG, "Admin enable FAILED!");
630657 }
631658 return;
659+ case REQUEST_CODE_START_ENCRYPTION:
660+ updateEncryptionStatus();
661+ return;
632662 }
633663
634664 super.onActivityResult(requestCode, resultCode, data);
@@ -642,7 +672,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
642672 mDeviceAdminSample);
643673 intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
644674 "Additional text explaining why this needs to be added.");
645- startActivityForResult(intent, RESULT_ENABLE);
675+ startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
646676 }
647677 };
648678
@@ -801,5 +831,62 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
801831 }
802832 };
803833
834+ private OnClickListener mEncryptionButtonListener = new OnClickListener() {
835+ public void onClick(View v) {
836+ int buttonId = v.getId();
837+ if (buttonId == R.id.encryption_enable_button) {
838+ mDPM.setStorageEncryption(mDeviceAdminSample, true);
839+ } else if (buttonId == R.id.encryption_disable_button) {
840+ mDPM.setStorageEncryption(mDeviceAdminSample, false);
841+ } else if (buttonId == R.id.encryption_activate_button) {
842+ if (ActivityManager.isUserAMonkey()) {
843+ // Don't trust monkeys to do the right thing!
844+ AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
845+ builder.setMessage("You can't activate encryption, you're a monkey!");
846+ builder.setPositiveButton("I admit defeat", null);
847+ builder.show();
848+ return;
849+ }
850+ if (mDPM.getStorageEncryption(mDeviceAdminSample) ==
851+ DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
852+ AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
853+ builder.setMessage("Encryption is unsupported on this device.");
854+ builder.setPositiveButton("OK", null);
855+ builder.show();
856+ return;
857+ }
858+ // Launch the activity to activate encryption. May or may not return!
859+ Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);
860+ startActivityForResult(intent, REQUEST_CODE_START_ENCRYPTION);
861+ }
862+
863+ // In all cases, fall through to update status
864+ updateEncryptionStatus();
865+ }
866+ };
867+
868+ private void updateEncryptionStatus() {
869+ String newStatus = "unknown";
870+ int newStatusCode = mDPM.getStorageEncryption(mDeviceAdminSample);
871+ switch (newStatusCode) {
872+ case DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED:
873+ newStatus = "unsupported";
874+ break;
875+ case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
876+ newStatus = "inactive";
877+ break;
878+ case DevicePolicyManager.ENCRYPTION_STATUS_REQUESTED:
879+ newStatus = "requested";
880+ break;
881+ case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVATING:
882+ newStatus = "activating";
883+ break;
884+ case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
885+ newStatus = "active";
886+ break;
887+ }
888+ mEncryptionStatus.setText(newStatus);
889+ }
804890 }
805891 }
892+