diff options
author | Jinhui Wang <jinhuiw@google.com> | 2016-06-09 17:33:43 -0700 |
---|---|---|
committer | Jinhui Wang <jinhuiw@google.com> | 2016-06-10 09:54:25 -0700 |
commit | aa2ab41e04862169a365a62facefc57a2ccdd736 (patch) | |
tree | a11aff72de4244a5d16fec26684c0e9ee0268494 | |
parent | dc65dc058699a68bfa8f5f0fc1b031125137db43 (diff) | |
download | AfwTestHarness-aa2ab41e04862169a365a62facefc57a2ccdd736.tar.gz |
Import AfwThDeviceAdmin app
This app helps to factory reset device.
Change-Id: Ic44c77fc1433ce563972fb01ffc24a2881c07b48
-rw-r--r-- | apps/DeviceAdmin/Android.mk | 33 | ||||
-rw-r--r-- | apps/DeviceAdmin/AndroidManifest.xml | 43 | ||||
-rw-r--r-- | apps/DeviceAdmin/README | 13 | ||||
-rw-r--r-- | apps/DeviceAdmin/res/xml/device_admin.xml | 21 | ||||
-rw-r--r-- | apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/AdminReceiver.java | 25 | ||||
-rw-r--r-- | apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/FactoryResetActivity.java | 65 |
6 files changed, 200 insertions, 0 deletions
diff --git a/apps/DeviceAdmin/Android.mk b/apps/DeviceAdmin/Android.mk new file mode 100644 index 0000000..8a154d9 --- /dev/null +++ b/apps/DeviceAdmin/Android.mk @@ -0,0 +1,33 @@ +# +# Copyright (C) 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) + +LOCAL_STATIC_JAVA_LIBRARIES := AfwTestCommonLib + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := AfwThDeviceAdmin + +LOCAL_SDK_VERSION := 22 + +include $(BUILD_AFW_TEST_SUPPORT_PACKAGE) diff --git a/apps/DeviceAdmin/AndroidManifest.xml b/apps/DeviceAdmin/AndroidManifest.xml new file mode 100644 index 0000000..aca9832 --- /dev/null +++ b/apps/DeviceAdmin/AndroidManifest.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.afwtest.deviceadmin" > + + <uses-sdk android:minSdkVersion="22"/> + + <application> + <receiver + android:name=".AdminReceiver" + android:permission="android.permission.BIND_DEVICE_ADMIN"> + <meta-data android:name="android.app.device_admin" + android:resource="@xml/device_admin" /> + <intent-filter> + <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> + </intent-filter> + </receiver> + + <activity + android:name="com.android.afwtest.deviceadmin.FactoryResetActivity" + android:label="Factory Reset" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/apps/DeviceAdmin/README b/apps/DeviceAdmin/README new file mode 100644 index 0000000..c618be6 --- /dev/null +++ b/apps/DeviceAdmin/README @@ -0,0 +1,13 @@ +- About + + An admin app that helps factory resetting a device. + +- Build & Install: + + make AfwThDeviceAdmin + adb install -d -r AfwThDeviceAdmin.apk + +- Factory reset a device + + adb shell dpm set-active-admin com.android.afwtest.deviceadmin/com.android.afwtest.deviceadmin.AdminReceiver + adb shell am start -n com.android.afwtest.deviceadmin/.FactoryResetActivity diff --git a/apps/DeviceAdmin/res/xml/device_admin.xml b/apps/DeviceAdmin/res/xml/device_admin.xml new file mode 100644 index 0000000..4ecda10 --- /dev/null +++ b/apps/DeviceAdmin/res/xml/device_admin.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<device-admin xmlns:android="http://schemas.android.com/apk/res/android" android:visible="false"> + <uses-policies> + <wipe-data /> + </uses-policies> +</device-admin> diff --git a/apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/AdminReceiver.java b/apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/AdminReceiver.java new file mode 100644 index 0000000..c0215bf --- /dev/null +++ b/apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/AdminReceiver.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.afwtest.deviceadmin; + +import android.app.admin.DeviceAdminReceiver; + +/** + * Admin receiver. + */ +public class AdminReceiver extends DeviceAdminReceiver { +} diff --git a/apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/FactoryResetActivity.java b/apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/FactoryResetActivity.java new file mode 100644 index 0000000..b5e56b8 --- /dev/null +++ b/apps/DeviceAdmin/src/com/android/afwtest/deviceadmin/FactoryResetActivity.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.afwtest.deviceadmin; + +import android.app.Activity; +import android.app.admin.DevicePolicyManager; +import android.content.ComponentName; +import android.content.Context; +import android.os.Bundle; +import android.util.Log; + + +/** + * Activity to handle factory reset intent. + */ +public class FactoryResetActivity extends Activity { + + private static final String TAG = "afwtest.FactoryResetActivity"; + + private static final String EXTRA_WIPE_PROTECTION_DATA = "afwtest.wipe.protection.data"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + ComponentName admin = new ComponentName(getApplicationContext().getPackageName(), + AdminReceiver.class.getName()); + + DevicePolicyManager devicePolicyManager = + (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); + + boolean wipeReset = getIntent().getBooleanExtra(EXTRA_WIPE_PROTECTION_DATA, false); + + String adminName = admin.flattenToString(); + if (!devicePolicyManager.isAdminActive(admin)) { + Log.e(TAG, adminName + " is not active admin"); + Log.e(TAG, "Please run command: adb shell dpm set-active-admin " + adminName); + } else if (wipeReset && !devicePolicyManager.isDeviceOwnerApp(getPackageName())) { + Log.e(TAG, getPackageName() + " is not device-owner"); + Log.e(TAG, "Please run command: adb shell dpm set-device-owner " + adminName); + } else { + Log.d(TAG, "Active admin: " + adminName); + if (wipeReset) { + devicePolicyManager.wipeData(DevicePolicyManager.WIPE_RESET_PROTECTION_DATA); + } else { + devicePolicyManager.wipeData(0); + } + } + finish(); + } +} |