diff options
author | Craig Mautner <cmautner@google.com> | 2015-04-08 15:43:26 -0700 |
---|---|---|
committer | Craig Mautner <cmautner@google.com> | 2015-04-15 14:27:56 -0700 |
commit | 2ad0bb46a42476f91b63baa95f0bcf97a337a4fc (patch) | |
tree | 038cec3cde560e9d898ef8c3aa0f1d5cff58fa14 /tests/LockTaskTests | |
parent | 15df08abd8190353e1430f88c2ed6462d72a5b25 (diff) | |
download | frameworks_base-2ad0bb46a42476f91b63baa95f0bcf97a337a4fc.zip frameworks_base-2ad0bb46a42476f91b63baa95f0bcf97a337a4fc.tar.gz frameworks_base-2ad0bb46a42476f91b63baa95f0bcf97a337a4fc.tar.bz2 |
Add tests for android:lockTaskMode.
Android app to exercise the new attribute.
For bug 19995702.
Change-Id: I0794301a6b677ec6367dd3ad99a40b5d3f9f1d7c
Diffstat (limited to 'tests/LockTaskTests')
20 files changed, 435 insertions, 0 deletions
diff --git a/tests/LockTaskTests/Android.mk b/tests/LockTaskTests/Android.mk new file mode 100644 index 0000000..ed58643 --- /dev/null +++ b/tests/LockTaskTests/Android.mk @@ -0,0 +1,15 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/system/priv-app + +LOCAL_PACKAGE_NAME := LockTaskTests +LOCAL_CERTIFICATE := platform + +LOCAL_SRC_FILES := $(call all-Iaidl-files-under, src) $(call all-java-files-under, src) + +include $(BUILD_PACKAGE) + +# Use the following include to make our test apk. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/tests/LockTaskTests/AndroidManifest.xml b/tests/LockTaskTests/AndroidManifest.xml new file mode 100644 index 0000000..f88744e --- /dev/null +++ b/tests/LockTaskTests/AndroidManifest.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.google.android.example.locktasktests" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk + android:minSdkVersion="22" + android:targetSdkVersion="22" /> + <uses-permission android:name="android.permission.INTERNET"/> + + <application + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme" + android:allowBackup="true" > + <activity + android:name="com.google.android.example.locktasktests.MainActivity" + android:label="@string/app_name" + android:screenOrientation="portrait" + android:theme="@style/AppTheme" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity + android:name="com.google.android.example.locktasktests.LockDefaultActivity" + android:label="@string/title_activity_default" + android:taskAffinity="" + android:documentLaunchMode="always" + android:lockTaskMode="lockTaskModeDefault" > + </activity> + <activity + android:name="com.google.android.example.locktasktests.LockTaskNeverActivity" + android:label="@string/title_activity_never" + android:taskAffinity="" + android:documentLaunchMode="always" + android:lockTaskMode="lockTaskModeNever" > + </activity> + <activity + android:name="com.google.android.example.locktasktests.LockWhitelistedActivity" + android:label="@string/title_activity_whitelist" + android:taskAffinity="" + android:documentLaunchMode="always" + android:lockTaskMode="lockTaskModeIfWhitelisted" > + </activity> + <activity + android:name="com.google.android.example.locktasktests.LockAtLaunchActivity" + android:label="@string/title_activity_always" + android:taskAffinity="" + android:documentLaunchMode="always" + android:lockTaskMode="lockTaskModeAlways" > + </activity> + </application> + +</manifest> diff --git a/tests/LockTaskTests/res/drawable-hdpi/ic_launcher.png b/tests/LockTaskTests/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..288b665 --- /dev/null +++ b/tests/LockTaskTests/res/drawable-hdpi/ic_launcher.png diff --git a/tests/LockTaskTests/res/drawable-mdpi/ic_launcher.png b/tests/LockTaskTests/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..6ae570b --- /dev/null +++ b/tests/LockTaskTests/res/drawable-mdpi/ic_launcher.png diff --git a/tests/LockTaskTests/res/drawable-xhdpi/ic_launcher.png b/tests/LockTaskTests/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..d4fb7cd --- /dev/null +++ b/tests/LockTaskTests/res/drawable-xhdpi/ic_launcher.png diff --git a/tests/LockTaskTests/res/drawable-xxhdpi/ic_launcher.png b/tests/LockTaskTests/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..85a6081 --- /dev/null +++ b/tests/LockTaskTests/res/drawable-xxhdpi/ic_launcher.png diff --git a/tests/LockTaskTests/res/layout/activity_launch.xml b/tests/LockTaskTests/res/layout/activity_launch.xml new file mode 100644 index 0000000..b619743 --- /dev/null +++ b/tests/LockTaskTests/res/layout/activity_launch.xml @@ -0,0 +1,32 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/root_launch" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context="com.google.android.example.locktasktests.LaunchActivity" > + + <Button + android:id="@+id/button_try_lock" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:onClick="onTryLock" + android:text="@string/try_lock" /> + <Button + android:id="@+id/button_try_unlock" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:onClick="onTryUnlock" + android:text="@string/try_unlock" /> + <Button + android:id="@+id/button_launch_main" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:onClick="onLaunchMain" + android:text="@string/launch_main" /> + +</LinearLayout> diff --git a/tests/LockTaskTests/res/layout/activity_main.xml b/tests/LockTaskTests/res/layout/activity_main.xml new file mode 100644 index 0000000..c2e93c4 --- /dev/null +++ b/tests/LockTaskTests/res/layout/activity_main.xml @@ -0,0 +1,41 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/root_launch" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context="com.google.android.example.locktasktests.MainActivity" > + <Button + android:id="@+id/button_default" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:onClick="onButtonPressed" + android:text="@string/launch_default" /> + <Button + android:id="@+id/button_never" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:onClick="onButtonPressed" + android:text="@string/launch_never" /> + <Button + android:id="@+id/button_whitelist" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:onClick="onButtonPressed" + android:text="@string/launch_whitelist" /> + <Button + android:id="@+id/button_always" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:onClick="onButtonPressed" + android:text="@string/launch_always" /> + +</LinearLayout> diff --git a/tests/LockTaskTests/res/values-v11/styles.xml b/tests/LockTaskTests/res/values-v11/styles.xml new file mode 100644 index 0000000..3c02242 --- /dev/null +++ b/tests/LockTaskTests/res/values-v11/styles.xml @@ -0,0 +1,11 @@ +<resources> + + <!-- + Base application theme for API 11+. This theme completely replaces + AppBaseTheme from res/values/styles.xml on API 11+ devices. + --> + <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> + <!-- API 11 theme customizations can go here. --> + </style> + +</resources> diff --git a/tests/LockTaskTests/res/values-v14/styles.xml b/tests/LockTaskTests/res/values-v14/styles.xml new file mode 100644 index 0000000..a91fd03 --- /dev/null +++ b/tests/LockTaskTests/res/values-v14/styles.xml @@ -0,0 +1,12 @@ +<resources> + + <!-- + Base application theme for API 14+. This theme completely replaces + AppBaseTheme from BOTH res/values/styles.xml and + res/values-v11/styles.xml on API 14+ devices. + --> + <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> + <!-- API 14 theme customizations can go here. --> + </style> + +</resources> diff --git a/tests/LockTaskTests/res/values-w820dp/dimens.xml b/tests/LockTaskTests/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..f3e7020 --- /dev/null +++ b/tests/LockTaskTests/res/values-w820dp/dimens.xml @@ -0,0 +1,10 @@ +<resources> + + <!-- + Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). + --> + <dimen name="activity_horizontal_margin">64dp</dimen> + +</resources> diff --git a/tests/LockTaskTests/res/values/dimens.xml b/tests/LockTaskTests/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/tests/LockTaskTests/res/values/dimens.xml @@ -0,0 +1,7 @@ +<resources> + + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> + +</resources> diff --git a/tests/LockTaskTests/res/values/strings.xml b/tests/LockTaskTests/res/values/strings.xml new file mode 100644 index 0000000..ae7768e --- /dev/null +++ b/tests/LockTaskTests/res/values/strings.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="app_name">Lock Task Tests</string> + <string name="title_activity_default">LockDefaultActivity</string> + <string name="title_activity_never">LockTaskNeverActivity</string> + <string name="title_activity_whitelist">LockWhitelistedActivity</string> + <string name="title_activity_always">LockAtLaunchActivity</string> + <string name="launch_default">android:lockTaskMode=\n + \"lockTaskModeDefault\"\n + Pinnable from Overview.</string> + <string name="launch_never">android:lockTaskMode=\n + \"lockTaskModeNever\"\n + Not Lockable or Pinnable.</string> + <string name="launch_whitelist">android:lockTaskMode=\n\"lockTaskModeIfWhitelisted\"\n + Lockable if whitelisted, Pinnable.\n + Use SampleDeviceOwner app to set whitelist.</string> + <string name="launch_always">android:lockTaskMode=\n + \"lockTaskModeAlways\"\n + Launches into lock mode.</string> + <string name="launch_main">launch MainActivity (as activity)"</string> + <string name="try_lock">Call startLockMode()</string> + <string name="try_unlock">Call stopLockMode()</string> + +</resources> diff --git a/tests/LockTaskTests/res/values/styles.xml b/tests/LockTaskTests/res/values/styles.xml new file mode 100644 index 0000000..6ce89c7 --- /dev/null +++ b/tests/LockTaskTests/res/values/styles.xml @@ -0,0 +1,20 @@ +<resources> + + <!-- + Base application theme, dependent on API level. This theme is replaced + by AppBaseTheme from res/values-vXX/styles.xml on newer devices. + --> + <style name="AppBaseTheme" parent="android:Theme.Light"> + <!-- + Theme customizations available in newer API levels can go in + res/values-vXX/styles.xml, while customizations related to + backward-compatibility can go here. + --> + </style> + + <!-- Application theme. --> + <style name="AppTheme" parent="AppBaseTheme"> + <!-- All customizations that are NOT specific to a particular API-level can go here. --> + </style> + +</resources> diff --git a/tests/LockTaskTests/src/com/google/android/example/locktasktests/LaunchActivity.java b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LaunchActivity.java new file mode 100644 index 0000000..1fc53cb --- /dev/null +++ b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LaunchActivity.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2015 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.google.android.example.locktasktests; + +import android.app.Activity; +import android.app.ActivityManager; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; + +public class LaunchActivity extends Activity { + + EditText mEditText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_launch); + setBackgroundOnLockTaskMode(); + } + + @Override + public void onResume() { + super.onResume(); + setBackgroundOnLockTaskMode(); + } + + public void onTryLock(View view) { + startLockTask(); + setBackgroundOnLockTaskMode(); + } + + public void onTryUnlock(View view) { + stopLockTask(); + setBackgroundOnLockTaskMode(); + } + + public void onLaunchMain(View view) { + Intent intent = new Intent(this, MainActivity.class); + startActivity(intent); + } + + private void setBackgroundOnLockTaskMode() { + ActivityManager activityManager = + (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + final int color = + activityManager.getLockTaskModeState() != ActivityManager.LOCK_TASK_MODE_NONE ? + 0xFFFFC0C0 : 0xFFFFFFFF; + findViewById(R.id.root_launch).setBackgroundColor(color); + } +} diff --git a/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockAtLaunchActivity.java b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockAtLaunchActivity.java new file mode 100644 index 0000000..4390c94 --- /dev/null +++ b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockAtLaunchActivity.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 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.google.android.example.locktasktests; + +public class LockAtLaunchActivity extends LaunchActivity { +} diff --git a/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockDefaultActivity.java b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockDefaultActivity.java new file mode 100644 index 0000000..7e57ab7 --- /dev/null +++ b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockDefaultActivity.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 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.google.android.example.locktasktests; + +public class LockDefaultActivity extends LaunchActivity { +} diff --git a/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockTaskNeverActivity.java b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockTaskNeverActivity.java new file mode 100644 index 0000000..69c2cbc --- /dev/null +++ b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockTaskNeverActivity.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 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.google.android.example.locktasktests; + +public class LockTaskNeverActivity extends LaunchActivity { +} diff --git a/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockWhitelistedActivity.java b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockWhitelistedActivity.java new file mode 100644 index 0000000..387baa2 --- /dev/null +++ b/tests/LockTaskTests/src/com/google/android/example/locktasktests/LockWhitelistedActivity.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 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.google.android.example.locktasktests; + +public class LockWhitelistedActivity extends LaunchActivity { +} diff --git a/tests/LockTaskTests/src/com/google/android/example/locktasktests/MainActivity.java b/tests/LockTaskTests/src/com/google/android/example/locktasktests/MainActivity.java new file mode 100644 index 0000000..82fac03 --- /dev/null +++ b/tests/LockTaskTests/src/com/google/android/example/locktasktests/MainActivity.java @@ -0,0 +1,58 @@ + +package com.google.android.example.locktasktests; + +import android.app.Activity; +import android.app.ActivityManager; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; + +public class MainActivity extends Activity { + + private final static String TAG = "LockTaskTests"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + setBackgroundOnLockTaskMode(); + } + + @Override + public void onResume() { + super.onResume(); + setBackgroundOnLockTaskMode(); + } + + public void onButtonPressed(View v) { + Class activity = null; + switch (v.getId()) { + case R.id.button_default: + activity = LockDefaultActivity.class; + break; + case R.id.button_never: + activity = LockTaskNeverActivity.class; + break; + case R.id.button_whitelist: + activity = LockWhitelistedActivity.class; + break; + case R.id.button_always: + activity = LockAtLaunchActivity.class; + break; + } + Intent intent = new Intent(this, activity); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + + private void setBackgroundOnLockTaskMode() { + ActivityManager activityManager = + (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); + final int color = + activityManager.getLockTaskModeState() != ActivityManager.LOCK_TASK_MODE_NONE ? + 0xFFFFC0C0 : 0xFFFFFFFF; + findViewById(R.id.root_launch).setBackgroundColor(color); + } +} |