Add tests for android:lockTaskMode.

Android app to exercise the new attribute.

For bug 19995702.

Change-Id: I0794301a6b677ec6367dd3ad99a40b5d3f9f1d7c
This commit is contained in:
Craig Mautner
2015-04-08 15:43:26 -07:00
parent 15df08abd8
commit 2ad0bb46a4
20 changed files with 435 additions and 0 deletions

View File

@@ -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))

View File

@@ -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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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);
}
}